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
00040 namespace acsQoS
00041 {
00042
00043 class Timeout
00044 {
00045 public:
00046
00052 Timeout(unsigned long timeout);
00053
00057 ~Timeout();
00058
00064 unsigned long get() { return timeout_m; }
00065
00071 void set(unsigned long timeout) { timeout_m = timeout; set(); }
00072
00080 static void setORBTimeout(unsigned long timeout, CORBA::ORB_ptr _orb = CORBA::ORB::_nil());
00081
00092 template <class T>
00093 static T* setObjectTimeout(unsigned long timeout, T *obj)
00094 {
00095 try
00096 {
00097
00098
00099
00100
00101
00102 TimeBase::TimeT to = timeout * 10000;
00103 CORBA::Any anyTimeOut;
00104 anyTimeOut <<= to;
00105
00106 CORBA::PolicyList policyList;
00107 policyList.length (1);
00108 policyList[0] = orb_m->create_policy (Messaging::RELATIVE_RT_TIMEOUT_POLICY_TYPE, anyTimeOut);
00109
00110
00111 CORBA::Object_var newObj = obj->_set_policy_overrides (policyList, CORBA::SET_OVERRIDE);
00112
00113 policyList[0]->destroy();
00114 return T::_narrow(newObj.in());
00115 }
00116 catch (CORBA::Exception &cex)
00117 {
00118 acsQoSErrType::CanNotSetTimeoutExImpl ex(__FILE__, __LINE__, "Timeout::setObjectTimeout");
00119 ex.addData("Caused by CORBA exception", cex._name());
00120 throw ex;
00121 }
00122 }
00123
00132 static void init(CORBA::ORB_ptr _orb);
00133
00139 static bool isInitialized();
00140
00149 static void done();
00150
00151 private:
00152
00153 void set();
00154
00155 unsigned long timeout_m;
00156
00157 CORBA::PolicyList policyList_m;
00158
00159 CORBA::PolicyCurrent_var policyCurrent_m;
00160
00161 CORBA::PolicyList previousPolicy_m;
00162
00163 static CORBA::ORB_var orb_m;
00164 static bool initialized_m;
00165 };
00166
00167 };
00168
00169 #endif