00001 // -*- C++ -*- 00002 00003 //============================================================================= 00004 /** 00005 * @file ORB_Manager.h 00006 * 00007 * $Id: ORB_Manager.h 82875 2008-09-29 14:17:15Z johnnyw $ 00008 * 00009 * @author Chris Cleeland <cleeland@cs.wustl.edu> 00010 */ 00011 //============================================================================= 00012 00013 #ifndef TAO_ORB_MANAGER_H 00014 #define TAO_ORB_MANAGER_H 00015 #include /**/ "ace/pre.h" 00016 00017 #include "tao/Utils/utils_export.h" 00018 #include "tao/PortableServer/PortableServer.h" 00019 00020 #if !defined (ACE_LACKS_PRAGMA_ONCE) 00021 # pragma once 00022 #endif /* ACE_LACKS_PRAGMA_ONCE */ 00023 00024 #include "tao/ORB.h" 00025 00026 TAO_BEGIN_VERSIONED_NAMESPACE_DECL 00027 00028 /** 00029 * @class TAO_ORB_Manager 00030 * 00031 * @brief Helper class for simple ORB/POA initialization and 00032 * registering servants with the POA. 00033 * 00034 * This class is a TAO extension that makes it easier to write 00035 * CORBA applications. It's just a wrapper and doesn't do 00036 * anything special within the ORB itself. 00037 */ 00038 class TAO_UTILS_Export TAO_ORB_Manager 00039 { 00040 public: 00041 // = Initialization and termination methods. 00042 /** Constructor. 00043 * 00044 * @param orb pointer to an ORB which is duplicated an stored 00045 * internally in an ORB_var. If pointer is 0, 00046 * a new ORB pointer is created internally in the init() 00047 * call. 00048 * 00049 * @param poa pointer to a POA which is duplicated and stored 00050 * internally in a POA_var. If pointer is 0, 00051 * a pointer to the Root POA is obtained from the ORB. 00052 * 00053 * @param poa_manager pointer to a POA Manager which is duplicated 00054 * and stored internally in a POAManager_var. 00055 * If pointer is 0, a new POAManager is created 00056 * internally in the init() call. 00057 */ 00058 TAO_ORB_Manager (CORBA::ORB_ptr orb = CORBA::ORB::_nil(), 00059 PortableServer::POA_ptr poa = PortableServer::POA::_nil(), 00060 PortableServer::POAManager_ptr poa_manager = 00061 PortableServer::POAManager::_nil()); 00062 00063 /** 00064 * Initialize the ORB/root POA, using the supplied command line 00065 * arguments or the default ORB components. 00066 * 00067 * @retval -1 Failure 00068 * @retval 0 Success 00069 */ 00070 int init (int &argc, 00071 ACE_TCHAR *argv[], 00072 const char *orb_name = 0); 00073 00074 #if !defined (CORBA_E_MICRO) 00075 /** 00076 * Creates a child poa under the root poa with PERSISTENT and 00077 * USER_ID policies. Call this if you want a @a child_poa with the 00078 * above policies, otherwise call init. 00079 * 00080 * @retval -1 Failure 00081 * @retval 0 Success 00082 */ 00083 int init_child_poa (int &argc, 00084 ACE_TCHAR *argv[], 00085 const char *poa_name, 00086 const char *orb_name = 0); 00087 #endif /* CORBA_E_MICRO */ 00088 00089 /** 00090 * Shut down. Invoke the destroy() methods on the orb and poa. 00091 * 00092 * @retval -1 Failure 00093 * @retval 0 Success 00094 */ 00095 int fini (void); 00096 00097 /// Destructor. 00098 ~TAO_ORB_Manager (void); 00099 00100 // = Accessor methods. 00101 00102 /** 00103 * Put POA manager into the <Active> state, so that incoming corba 00104 * requests are processed. This method is useful for clients, 00105 * which are not going to enter "orb->run" loop, yet may want to 00106 * service incoming requests while waiting for a result of CORBA 00107 * call on a server. 00108 * 00109 * @retval -1 Failure 00110 * @retval 0 Success 00111 */ 00112 int activate_poa_manager (void); 00113 00114 /** 00115 * Activate <servant>, using the POA <activate_object> call. Users 00116 * can call this method multiple times to activate multiple objects. 00117 * 00118 * @return 0 on failure, a string representation of the object ID if 00119 * successful. Caller of this method is responsible for 00120 * memory deallocation of the string. 00121 */ 00122 char *activate (PortableServer::Servant servant); 00123 00124 /** Deactivate object in RootPOA. 00125 * 00126 * @param id A string representation of the Object ID 00127 * of the servant to deactivate in the POA 00128 */ 00129 void deactivate (const char *id); 00130 00131 #if !defined (CORBA_E_MICRO) 00132 /** 00133 * Precondition: init_child_poa has been called. Activate <servant> 00134 * using the POA <activate_object_with_id> created from the string 00135 * <object_name>. Users should call this to activate objects under 00136 * the child_poa. 00137 * 00138 * @param object_name String name which will be used to create 00139 * an Object ID for the servant. 00140 * @param servant The servant to activate under the child POA. 00141 * 00142 * @return 0 on failure, a string representation of the object ID if 00143 * successful. Caller of this method is responsible for 00144 * memory deallocation of the string. 00145 */ 00146 char *activate_under_child_poa (const char *object_name, 00147 PortableServer::Servant servant); 00148 00149 /** 00150 * Deactivate object in child POA. 00151 * 00152 * @param id string representation of the object ID, which represents 00153 * the object to deactivate in the POA 00154 */ 00155 void deactivate_under_child_poa (const char *id); 00156 #endif /* CORBA_E_MICRO */ 00157 00158 /** 00159 * Run the ORB event loop with the specified @a tv time value. 00160 * 00161 * @param tv the time interval for how long to run the ORB event loop. 00162 * @retval -1 Failure 00163 * @retval 0 Success 00164 */ 00165 int run (ACE_Time_Value &tv); 00166 00167 /** 00168 * Run the ORB event loop. 00169 */ 00170 int run (void); 00171 00172 /** 00173 * Accessor which returns the ORB pointer. Following the normal 00174 * CORBA memory management rules of return values from functions, 00175 * this function duplicates the orb return value before returning 00176 * it. 00177 * 00178 * @return ORB pointer which has been duplicated, so caller 00179 * must release pointer when done. 00180 */ 00181 CORBA::ORB_ptr orb (void); 00182 00183 /** 00184 * Accessor which returns the root poa. Following the normal CORBA 00185 * memory management rules of return values from functions, this 00186 * function duplicates the poa return value before returning it. 00187 * 00188 * @return Root POA pointer which has been duplicated. Caller 00189 * must release pointer when done. 00190 */ 00191 PortableServer::POA_ptr root_poa (void); 00192 00193 /** 00194 * Accessor which returns the child poa. Following the normal CORBA 00195 * memory management rules of return values from functions, this 00196 * function duplicates the poa return value before returning it. 00197 * 00198 * @return Child POA pointer which has been duplicated. Caller 00199 * must release pointer when done. 00200 */ 00201 PortableServer::POA_ptr child_poa (void); 00202 00203 /** 00204 * Accessor which returns the poa manager. Following the normal 00205 * CORBA memory management rules of return values from functions, 00206 * this function duplicates the poa manager return value before 00207 * returning it. 00208 * 00209 * @return POAManager pointer which has been duplicated. Caller 00210 * must release pointer when done. 00211 */ 00212 PortableServer::POAManager_ptr poa_manager (void); 00213 00214 protected: 00215 /// The ORB. 00216 CORBA::ORB_var orb_; 00217 00218 /// The POA for this ORB. 00219 PortableServer::POA_var poa_; 00220 00221 /// Child poa under the root POA. 00222 PortableServer::POA_var child_poa_; 00223 00224 /// The POA manager of poa_. 00225 PortableServer::POAManager_var poa_manager_; 00226 }; 00227 00228 TAO_END_VERSIONED_NAMESPACE_DECL 00229 00230 #include /**/ "ace/post.h" 00231 #endif /* TAO_ORB_MANAGER_H */