• Classes
  • Modules
  • Namespaces
  • Files
  • Related Pages
  • File List
  • File Members

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.9 2012/02/29 12:50:09 tstaig 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 #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                                 //convert to 100's of nsecs (needed by TimeT). This calculation may seem 
00099                                 // confusing at first, but think about it this way: one millisecond equals how many
00100                                 // "hundreds of nanoseconds". The answer is: ten thousand milliseconds is equivalent
00101                                 // to a single hundred of nanosecs, so we multiply by 10000 to convert from milliseconds to 100 of ns.
00102                                 // Still confused? Then grab a pencil and paper to convince yourself.
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                                 // we will set timeout at object level
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;    // policy list for setting timeout
00159 
00160                 CORBA::PolicyCurrent_var policyCurrent_m;
00161 
00162                 CORBA::PolicyList previousPolicy_m;    // here we'll store previously set timeout
00163     
00164                 static CORBA::ORB_var orb_m;
00165                 static bool initialized_m;
00166 };//class Timeout
00167 
00168 };//namespace acsQoS 
00169 
00170 #endif 

Generated on Mon May 4 2015 08:27:41 for ACS-2015.4 C++ API by  doxygen 1.7.0