00001 /** 00002 * @file Platform/Aperios1.3.2/SharedReceiver.h 00003 * This file contains a class for a receiver using shared memory. 00004 * @author Thomas Röfer 00005 */ 00006 #ifndef __SHAREDRECEIVER_H__ 00007 #define __SHAREDRECEIVER_H__ 00008 00009 #include "Tools/Streams/InStreams.h" 00010 #include "Platform/GTAssert.h" 00011 00012 /** 00013 * The class implements a receiver. 00014 * A receiver is an object that reads packages from an Aperios queue. 00015 */ 00016 template<class T> class SharedReceiver : public Receiver<T> 00017 { 00018 protected: 00019 T* data; 00020 00021 /** 00022 * The function is called when a new package arrived. 00023 * @param msg An Open-R message that contains the package. 00024 */ 00025 virtual void handleMessage(ONotifyMessage& msg) 00026 { 00027 ONotifyEvent event; 00028 event.SetIndex(eventId); 00029 NotifyHandler(msg,&event); 00030 data = (T*) event.RCData(0)->Base(); 00031 setEventId(eventId); 00032 } 00033 00034 public: 00035 /** 00036 * The constructor. 00037 * @param process The process this receiver is associated with. 00038 * @param receiverName The Aperios connection name of the receiver without the process name. 00039 * @param blocking Decides whether this receiver blocks the execution of the next frame 00040 * until it has received a package. 00041 */ 00042 SharedReceiver(PlatformProcess* process,const char* receiverName,bool blocking) 00043 : Receiver<T>(process,receiverName,blocking), 00044 data(0) 00045 { 00046 } 00047 00048 /** 00049 * The function returns a reference to the shared object. 00050 * @return A reference to the shared object. 00051 */ 00052 T& getShared() {return *data;} 00053 00054 /** 00055 * The function returns a constant reference to the shared object. 00056 * @return A constant reference to the shared object. 00057 */ 00058 const T& getShared() const {return *data;} 00059 }; 00060 00061 /** 00062 * The macro declares a shared received. 00063 * It must be used inside a declaration of a process, after the macro DEBUGGING. 00064 * @param type The type of the package. The variable actually declared has 00065 * a type compatible to "type" and is called "thetypeSender". 00066 */ 00067 #define SHARED_RECEIVER(type) \ 00068 SharedReceiver<type> the##type##Receiver 00069 00070 #endif
1.3.6