1 // -*- Mode: C++; -*- 2 // Package : omniORB 3 // omniCurrent.h Created on: 2001/06/01 4 // Author : Duncan Grisby (dpg1) 5 // 6 // Copyright (C) 2002-2011 Apasphere Ltd 7 // Copyright (C) 2001 AT&T Research Cambridge 8 // 9 // This file is part of the omniORB library. 10 // 11 // The omniORB library is free software; you can redistribute it and/or 12 // modify it under the terms of the GNU Lesser General Public 13 // License as published by the Free Software Foundation; either 14 // version 2.1 of the License, or (at your option) any later version. 15 // 16 // This library is distributed in the hope that it will be useful, 17 // but WITHOUT ANY WARRANTY; without even the implied warranty of 18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 19 // Lesser General Public License for more details. 20 // 21 // You should have received a copy of the GNU Lesser General Public 22 // License along with this library. If not, see http://www.gnu.org/licenses/ 23 // 24 // 25 // Description: 26 // Generic support for the kinds of Current interface. 27 // 28 29 #ifndef __OMNICURRENT_H__ 30 #define __OMNICURRENT_H__ 31 32 #include <omnithread.h> 33 #include <omniORB4/omniORB.h> 34 #include <omniORB4/omniInternal.h> 35 #include <omniORB4/callDescriptor.h> 36 #include <orbParameters.h> 37 38 #if !defined(_core_attr) 39 # define _core_attr_defined 40 # if defined(_OMNIORB_LIBRARY) 41 # define _core_attr 42 # else 43 # define _core_attr _OMNIORB_NTDLL_IMPORT 44 # endif 45 #endif 46 47 48 class omniCurrent : public omni_thread::value_t { 49 public: 50 omniCurrent(omni_thread* thread); 51 // Should really be private but some compilers warn about a class 52 // with only a private constructor and no friends. 53 54 virtual ~omniCurrent(); 55 56 static void init(); 57 get()58 static inline omniCurrent* get() 59 { 60 if (!_OMNI_NS(orbParameters)::supportCurrent) return 0; 61 62 omni_thread* thr = omni_thread::self(); 63 if (!thr || !thread_key) return 0; 64 65 omniCurrent* current = (omniCurrent*)(thr->get_value(thread_key)); 66 if (!current) 67 current = new omniCurrent(thr); 68 return current; 69 } 70 get(omni_thread * thr)71 static inline omniCurrent* get(omni_thread* thr) 72 { 73 if (!thread_key) return 0; 74 omniCurrent* current = (omniCurrent*)(thr->get_value(thread_key)); 75 if (!current) 76 current = new omniCurrent(thr); 77 return current; 78 } 79 80 // Accessors callDescriptor()81 inline omniCallDescriptor* callDescriptor() { return pd_callDescriptor; } timeout()82 inline const omni_time_t& timeout() { return pd_timeout; } timeout_absolute()83 inline CORBA::Boolean timeout_absolute() { return pd_timeout_absolute; } 84 85 // Stack manipulation setCallDescriptor(omniCallDescriptor * desc)86 inline void setCallDescriptor(omniCallDescriptor* desc) 87 { 88 pd_callDescriptor = desc; 89 } 90 91 // Timeout setting setTimeout(unsigned long secs,unsigned long ns)92 inline void setTimeout(unsigned long secs, unsigned long ns) 93 { 94 pd_timeout.assign(secs, ns); 95 pd_timeout_absolute = 0; 96 } setTimeout(const omni_time_t & t)97 inline void setTimeout(const omni_time_t& t) 98 { 99 pd_timeout = t; 100 pd_timeout_absolute = 0; 101 } 102 setDeadline(unsigned long secs,unsigned long ns)103 inline void setDeadline(unsigned long secs, unsigned long ns) 104 { 105 pd_timeout.assign(secs, ns); 106 pd_timeout_absolute = 1; 107 } setDeadline(const omni_time_t & t)108 inline void setDeadline(const omni_time_t& t) 109 { 110 pd_timeout = t; 111 pd_timeout_absolute = 1; 112 } 113 114 private: 115 static _core_attr omni_thread::key_t thread_key; 116 117 omniCallDescriptor* pd_callDescriptor; 118 // Stack of call descriptors 119 120 omni_time_t pd_timeout; 121 // Per-thread timeout 122 123 CORBA::Boolean pd_timeout_absolute; 124 // If true, timeout is an absolute completion time, otherwise it's a 125 // time per call. 126 127 // Not implemented: 128 omniCurrent(const omniCurrent&); 129 omniCurrent& operator=(const omniCurrent&); 130 }; 131 132 #ifdef _core_attr_defined 133 # undef _core_attr 134 # undef _core_attr_defined 135 #endif 136 137 #endif // __OMNICURRENT_H__ 138