Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

acsQoStimeout.h

Go to the documentation of this file.
00001 #ifndef _acsQoS_TimeOut_H_ 00002 #define _acsQoS_TimeOut_H_ 00003 /******************************************************************************* 00004 * ALMA - Atacama Large Millimiter Array 00005 * (c) European Southern Observatory, 2004 00006 * 00007 *This library is free software; you can redistribute it and/or 00008 *modify it under the terms of the GNU Lesser General Public 00009 *License as published by the Free Software Foundation; either 00010 *version 2.1 of the License, or (at your option) any later version. 00011 * 00012 *This library is distributed in the hope that it will be useful, 00013 *but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 *MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00015 *Lesser General Public License for more details. 00016 * 00017 *You should have received a copy of the GNU Lesser General Public 00018 *License along with this library; if not, write to the Free Software 00019 *Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00020 * 00021 * "@(#) $Id: acsQoStimeout.h,v 1.7 2006/02/10 20:41:03 sharring Exp $" 00022 * 00023 * who when what 00024 * -------- -------- ---------------------------------------------- 00025 * bjeram 2004-08-24 created 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" // error stuff 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 //convert to 100's of nsecs (needed by TimeT). This calculation may seem 00098 // confusing at first, but think about it this way: one millisecond equals how many 00099 // "hundreds of nanoseconds". The answer is: ten thousand milliseconds is equivalent 00100 // to a single hundred of nanosecs, so we multiply by 10000 to convert from milliseconds to 100 of ns. 00101 // Still confused? Then grab a pencil and paper to convince yourself. 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 // we will set timeout at object level 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; // policy list for setting timeout 00158 00159 CORBA::PolicyCurrent_var policyCurrent_m; 00160 00161 CORBA::PolicyList previousPolicy_m; // here we'll store previously set timeout 00162 00163 static CORBA::ORB_var orb_m; 00164 static bool initialized_m; 00165 };//class Timeout 00166 00167 };//namespace acsQoS 00168 00169 #endif

Generated on Thu Apr 30 02:30:49 2009 for ACS C++ API by doxygen 1.3.8