Go to the documentation of this file.00001 #ifndef _acsQoS_TimeOut_H_
00002 #define _acsQoS_TimeOut_H_
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #ifndef __cplusplus
00034 #error This is a C++ include file and cannot be used from plain C
00035 #endif
00036
00037 #include "tao/Messaging/Messaging.h"
00038 #include "acsQoSErrType.h"
00039 #include "acsQoSExport.h"
00040
00041 namespace acsQoS
00042 {
00043
00044 class acsQoS_EXPORT Timeout
00045 {
00046 public:
00047
00053 Timeout(unsigned long timeout);
00054
00058 ~Timeout();
00059
00065 unsigned long get() { return timeout_m; }
00066
00072 void set(unsigned long timeout) { timeout_m = timeout; set(); }
00073
00081 static void setORBTimeout(unsigned long timeout, CORBA::ORB_ptr _orb = CORBA::ORB::_nil());
00082
00093 template <class T>
00094 static T* setObjectTimeout(unsigned long timeout, T *obj)
00095 {
00096 try
00097 {
00098
00099
00100
00101
00102
00103 TimeBase::TimeT to = timeout * 10000;
00104 CORBA::Any anyTimeOut;
00105 anyTimeOut <<= to;
00106
00107 CORBA::PolicyList policyList;
00108 policyList.length (1);
00109 policyList[0] = orb_m->create_policy (Messaging::RELATIVE_RT_TIMEOUT_POLICY_TYPE, anyTimeOut);
00110
00111
00112 CORBA::Object_var newObj = obj->_set_policy_overrides (policyList, CORBA::SET_OVERRIDE);
00113
00114 policyList[0]->destroy();
00115 return T::_narrow(newObj.in());
00116 }
00117 catch (CORBA::Exception &cex)
00118 {
00119 acsQoSErrType::CanNotSetTimeoutExImpl ex(__FILE__, __LINE__, "Timeout::setObjectTimeout");
00120 ex.addData("Caused by CORBA exception", cex._name());
00121 throw ex;
00122 }
00123 }
00124
00133 static void init(CORBA::ORB_ptr _orb);
00134
00140 static bool isInitialized();
00141
00150 static void done();
00151
00152 private:
00153
00154 void set();
00155
00156 unsigned long timeout_m;
00157
00158 CORBA::PolicyList policyList_m;
00159
00160 CORBA::PolicyCurrent_var policyCurrent_m;
00161
00162 CORBA::PolicyList previousPolicy_m;
00163
00164 static CORBA::ORB_var orb_m;
00165 static bool initialized_m;
00166 };
00167
00168 };
00169
00170 #endif