![]() |
MAK RTIspy API Documentation for HLA 1.3
|
00001 /****************************************************************************** 00002 ** Copyright (c) 2005 MAK Technologies, Inc. 00003 ** All rights reserved. 00004 ******************************************************************************/ 00005 /****************************************************************************** 00006 ** $RCSfile: vlThreadedObject.h,v $ $Revision: 1.3 $ $State: Exp $ 00007 ******************************************************************************/ 00008 00012 00013 00014 #ifndef vlThreadedObject_H__ 00015 #define vlThreadedObject_H__ 00016 00017 #include "rtiMsConfig.h" 00018 #include <vlutil/vlSmartPointers.h> 00019 #include <vlutil/vlThread.h> 00020 #include <vlutil/vlRunnable.h> 00021 #include <vlutil/vlMutex.h> 00022 #include <vlutil/vlExceptions.h> 00023 #include <vlutil/vlMachineTypes.h> 00024 00025 typedef DtBoost::shared_ptr<MAKRti::DtRunnable> DtRunnableSP; 00026 00027 namespace vrlmod 00028 { 00029 00030 00031 00032 00033 00035 #define typedefException(Name,Value) \ 00036 const int Name##Number = Value;\ 00037 typedef MAKRti::DtTemplatedException<Name##Number> Name; 00038 const int ThreadExceptionBase = 1000; 00039 typedefException(DtThreadAlreadyRunning,ThreadExceptionBase + 1) 00040 typedefException(DtThreadNotStarted, ThreadExceptionBase + 2) 00041 typedefException(DtThreadCreationError, ThreadExceptionBase + 3) 00042 typedefException(DtThreadWouldDeadlock, ThreadExceptionBase + 4) 00043 00044 00045 class DT_DLL_RTIUTIL DtThreadedObject 00046 { 00047 public: 00050 DtThreadedObject(); 00051 00054 DtThreadedObject(DtRunnableSP ptr); 00055 00057 virtual ~DtThreadedObject(); 00058 00064 void start(); 00065 00068 void join(); 00069 00073 void stop(bool block); 00074 00076 bool running() const; 00077 00080 void setRunnableObject(DtRunnableSP newObject); 00081 00083 DtRunnableSP runnableObject() const; 00084 00085 protected: 00086 00088 DtThreadedObject(const DtThreadedObject&); 00089 DtThreadedObject& operator=(const DtThreadedObject&); 00090 00092 void setRunning(bool value); 00093 00094 bool myRunningFlag; 00095 DtRunnableSP myObject; 00096 MAKRti::DtThread* myThread; 00097 mutable MAKRti::DtMutex myMutex; 00098 }; 00099 00100 00101 00102 00103 } 00104 00105 00106 00107 #endif