Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

Platform/Aperios1.3.2/SharedSender.h

Go to the documentation of this file.
00001 /**
00002  * @file Platform/Aperios1.3.2/SharedSender.h
00003  * This file contains a sender for sound data.
00004  */
00005 #ifndef __SHAREDSENDER_H__
00006 #define __SHAREDSENDER_H__
00007 
00008 #ifndef __ProcessFramework_h__
00009 #error Never include this file directly. Include ProcessFramework.h instead.
00010 #endif
00011 
00012 #include "Platform/ProcessFramework.h"
00013 
00014 /**
00015  * This class implements a sender for sound data.
00016  */
00017 template<class T> class SharedSender : public SenderBase<T>
00018 {
00019   private:
00020     RCRegion* package; /**< The shared memory. */
00021 
00022   protected:
00023     /**
00024     * No preparation.
00025     */
00026     void preparePackage() {}
00027 
00028     /**
00029      * The functions sets a package for a receiver.
00030      * @param receiver The receive the package will be sent to.
00031      */
00032     void setPackage(const ObserverID& receiver)
00033     {
00034       if(package->NumberOfReference() == 1)
00035         VERIFY(SetData(receiver,package) == oSUCCESS);
00036     }
00037 
00038     /**
00039      * The function does not free the package.
00040      * It is only freed in the destructor.
00041      */
00042     void freePackage() {}
00043 
00044   public:
00045     /**
00046      * The constructor.
00047      * @param process The process this sender is associated with.
00048      * @param senderName The Aperios connection name of the sender without the process name.
00049      * @param blocking Decides whether this sender blocks the execution of the next frame
00050      *                 until all connected receivers have requested a new package.
00051      */
00052     SharedSender(PlatformProcess* process,const char* senderName,bool blocking)
00053     : SenderBase<T>(process,senderName,blocking)
00054     {
00055       package = new RCRegion(sizeof(T));
00056       getShared() = T();
00057     }
00058 
00059     /**
00060      * Destructor.
00061      */
00062     ~SharedSender()
00063     {
00064       package->RemoveReference();
00065     }
00066 
00067     /**
00068      * The function returns a reference to the shared object.
00069      * @return A reference to the shared object.
00070      */
00071     T& getShared() {return *(T*) package->Base();}
00072 
00073     /**
00074      * The function returns a constant reference to the shared object.
00075      * @return A constant reference to the shared object.
00076      */
00077     const T& getShared() const {return *(T*) package->Base();}
00078 };
00079 
00080 /**
00081  * The macro declares a shared sender.
00082  * It must be used inside a declaration of a process, after the macro DEBUGGING.
00083  * @param type The type of the package. The variable actually declared has
00084  *             a type compatible to "type" and is called "thetypeSender".
00085  */
00086 #define SHARED_SENDER(type) \
00087   SharedSender<type> the##type##Sender
00088 
00089 #endif

Generated on Mon Mar 20 22:00:00 2006 for GT2005 by doxygen 1.3.6