UniSetObject.h
См. документацию.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00025
00026 #ifndef UniSetObject_H_
00027 #define UniSetObject_H_
00028
00029 #include <unistd.h>
00030 #include <sys/time.h>
00031 #include <queue>
00032 #include <ostream>
00033 #include <string>
00034 #include <list>
00035
00036 #include "UniSetTypes.h"
00037 #include "MessageType.h"
00038 #include "PassiveTimer.h"
00039 #include "Exceptions.h"
00040 #include "UniversalInterface.h"
00041 #include "UniSetObject_i.hh"
00042 #include "ThreadCreator.h"
00043
00044
00045
00046
00047 class ObjectsActivator;
00048 class ObjectsManager;
00049
00050
00051 class UniSetObject;
00052 typedef std::list<UniSetObject *> ObjectsList;
00053
00064 class UniSetObject:
00065 public POA_UniSetObject_i
00066 {
00067 public:
00068 UniSetObject(const std::string name, const std::string section);
00069 UniSetObject(UniSetTypes::ObjectId id);
00070 UniSetObject();
00071 virtual ~UniSetObject();
00072
00073
00074 virtual CORBA::Boolean exist();
00075 virtual char* getName(){return (char*)myname.c_str();}
00076 virtual UniSetTypes::ObjectId getId(){ return myid; }
00077 virtual UniSetTypes::ObjectType getType() { return UniSetTypes::getObjectType("UniSetObject"); }
00078 virtual UniSetTypes::SimpleInfo* getInfo();
00079 friend std::ostream& operator<<(std::ostream& os, UniSetObject& obj );
00080
00082 virtual void push(const UniSetTypes::TransportMessage& msg);
00083
00085 inline UniSetTypes::ObjectPtr getRef()
00086 {
00087 UniSetTypes::uniset_mutex_lock lock(refmutex, 300);
00088 return (UniSetTypes::ObjectPtr)CORBA::Object::_duplicate(oref);
00089 }
00090
00091 protected:
00093 virtual void processingMessage(UniSetTypes::VoidMessage *msg);
00094
00096 bool receiveMessage(UniSetTypes::VoidMessage& vm);
00097
00099 unsigned int countMessages();
00100
00102 void termWaiting();
00103
00104 UniversalInterface ui;
00105 std::string myname;
00106 std::string section;
00107
00109 virtual bool disactivateObject(){return true;}
00111 virtual bool activateObject(){return true;}
00112
00114 inline void thread(bool create){ threadcreate = create; }
00116 inline void offThread(){ threadcreate = false; }
00118 inline void onThread(){ threadcreate = true; }
00119
00121 virtual void callback();
00122
00128 virtual void sigterm( int signo ){};
00129
00130 inline void terminate(){ disactivate(); }
00131
00133 virtual bool waitMessage(UniSetTypes::VoidMessage& msg, timeout_t timeMS=UniSetTimer::WaitUpTime);
00134
00135 void setID(UniSetTypes::ObjectId id);
00136
00137
00138 void setMaxSizeOfMessageQueue( unsigned int s )
00139 {
00140 if( s>=0 )
00141 SizeOfMessageQueue = s;
00142 }
00143
00144 inline unsigned int getMaxSizeOfMessageQueue()
00145 { return SizeOfMessageQueue; }
00146
00147 void setMaxCountRemoveOfMessage( unsigned int m )
00148 {
00149 if( m >=0 )
00150 MaxCountRemoveOfMessage = m;
00151 }
00152
00153 inline unsigned int getMaxCountRemoveOfMessage()
00154 { return MaxCountRemoveOfMessage; }
00155
00156
00157
00158 struct PriorVMsgCompare:
00159 public std::binary_function<UniSetTypes::VoidMessage, UniSetTypes::VoidMessage, bool>
00160 {
00161 bool operator()(const UniSetTypes::VoidMessage& lhs,
00162 const UniSetTypes::VoidMessage& rhs) const;
00163 };
00164 typedef std::priority_queue<UniSetTypes::VoidMessage,std::vector<UniSetTypes::VoidMessage>,PriorVMsgCompare> MessagesQueue;
00165
00166
00180 virtual void cleanMsgQueue( MessagesQueue& q );
00181
00182
00183 void setRecvMutexTimeout( unsigned long msec );
00184 inline unsigned long getRecvMutexTimeout(){ return recvMutexTimeout; }
00185
00186 void setPushMutexTimeout( unsigned long msec );
00187 unsigned long getPushMutexTimeout(){ return pushMutexTimeout; }
00188
00189 bool isActive();
00190 void setActive( bool set );
00191
00192 UniSetTypes::VoidMessage msg;
00193 ObjectsManager* mymngr;
00194
00195 void setThreadPriority( int p );
00196
00197 private:
00198
00199 friend class ObjectsManager;
00200 friend class ObjectsActivator;
00201 friend class ThreadCreator<UniSetObject>;
00202 inline pid_t getMsgPID()
00203 {
00204 return msgpid;
00205 }
00206
00208 void work();
00210 bool init(ObjectsManager* om);
00212 bool disactivate();
00214 bool activate();
00215
00216 void registered();
00217
00218 void unregister();
00219
00220 void init_object();
00221
00222 pid_t msgpid;
00223 bool reg;
00224 bool active;
00225 UniSetTypes::uniset_mutex act_mutex;
00226 bool threadcreate;
00227 UniSetTimer* tmr;
00228 UniSetTypes::ObjectId myid;
00229 CORBA::Object_var oref;
00230 ThreadCreator<UniSetObject>* thr;
00231
00233 MessagesQueue queueMsg;
00234
00236 UniSetTypes::uniset_mutex qmutex;
00237
00239 UniSetTypes::uniset_mutex refmutex;
00240
00242 unsigned int SizeOfMessageQueue;
00244 unsigned int MaxCountRemoveOfMessage;
00245 unsigned long recvMutexTimeout;
00246 unsigned long pushMutexTimeout;
00248
00249 unsigned long stMaxQueueMessages;
00250 unsigned long stCountOfQueueFull;
00251 };
00252
00253 #endif
00254