3 #ifndef CARMA_UTIL_ORB_H
4 #define CARMA_UTIL_ORB_H
15 #include "carma/corba/corba.h"
16 #include <orbsvcs/CosNamingC.h>
17 #include <tao/PortableServer/PortableServer.h>
19 #include <tao/TimeBaseC.h>
20 #include <orbsvcs/CosNotifyFilterC.h>
21 #include <orbsvcs/NotifyExtC.h>
24 #include "carma/util/Program.h"
39 } NilInputDisposition;
42 FAIL_ON_INCOMPATIBLE_TYPES,
43 INCOMPATIBLE_TYPES_OKAY
44 } IncompatibleTypesDisposition;
58 bool set(
int argc,
char** argv,
const std::string& imrhost);
60 bool shutdown(
bool waitForCompletion);
64 CORBA::ORB_var duplicateOrb();
65 CORBA::ORB_var getORB();
67 void setName(std::string name);
68 std::string getName();
70 void setImrName(std::string imrName);
71 std::string getImrName();
73 void allowRegistrationWithImr(
bool allow);
85 bool hasUniqueImrName_;
87 bool allowRegistrationWithImr_;
90 std::vector<std::string> lArgvVec_;
92 ::pthread_mutex_t notifyChannelGuard_;
93 ::pthread_mutex_t proxyPushSupplierMapGuard_;
94 ::pthread_mutex_t proxyConsumerMapGuard_;
96 typedef std::map<std::string, CosNotifyChannelAdmin::StructuredProxyPushSupplier_var> ProxyPushSupplierMap;
97 ProxyPushSupplierMap proxyPushSuppliers_;
99 typedef std::map<std::string, CosNotifyChannelAdmin::StructuredProxyPushConsumer_var > ProxyConsumerMap;
100 ProxyConsumerMap proxyConsumers_;
104 std::string getPersistentPOAName(
const std::string& poaName);
105 PortableServer::POA_var getRootPOA();
106 PortableServer::POA_var getPOA(
const std::string& poaNameString =
"RootPOA");
107 PortableServer::POAManager_var getPOAManager(
const std::string& poaString =
"RootPOA");
109 void addObject(
const std::string& hierarchicalName, CORBA::Object_ptr objectPtr);
110 void addObject(
const std::string& hierarchicalName,
const std::string& kind, CORBA::Object_ptr objectPtr);
111 void removeObject(
const std::string& hierarchicalName);
113 void run(
const std::string& poaString =
"RootPOA");
118 void activatePOA(
const std::string& poaString);
119 void deactivatePOA(
bool etherealize,
bool wait,
const std::string& poaString);
120 void holdPOA(
bool wait,
const std::string& poaString);
121 void discardPOA(
bool wait,
const std::string& poaString);
123 CORBA::Object_var resolve(
const std::string& hierarchicalName,
const std::string& kind);
124 CORBA::Object_var resolveInit(
const char * idName );
125 CORBA::Object_var resolveName(
const std::string & hierarchicalName,
const std::string& kind);
126 CORBA::Object_var waitToResolveName(
const std::string& hierarchicalName,
const std::string& kind);
127 CORBA::Object_var resolveFromString(
const std::string& objectString);
128 CORBA::Object_var resolveFromFile(
const std::string& fileName,
const std::string& directory);
130 std::vector<std::string> getHierarchyIds(
const std::string& hierarchicalName);
132 void unbind(
const std::string& hierarchicalName,
const std::string& kind =
"");
133 void bind(
const std::string& hierarchicalName, CORBA::Object_ptr objectPtr);
134 void bind(
const std::string& hierarchicalName,
const std::string& kind, CORBA::Object_ptr objectPtr);
135 void rebind(
const std::string& hierarchicalName,
const std::string& kind, CORBA::Object_ptr objectPtr);
136 void rebind(
const std::string& hierarchicalName, CORBA::Object_ptr objectPtr);
138 CosNaming::NamingContext_var getRootNamingContext();
139 CosNaming::NamingContext_var getNamingContext(
const std::vector<std::string>& ids);
140 CosNaming::NamingContext_var getNamingContext(
const std::vector<std::string>& ids,
const std::string& kind);
148 CosNotifyChannelAdmin::ConsumerAdmin_var
149 getNotifyConsumerAdmin(
const std::string & channelName);
151 CosNotifyChannelAdmin::SupplierAdmin_var
152 getNotifySupplierAdmin(
const std::string& channelName);
154 CosNotifyChannelAdmin::EventChannel_var
155 getNotifyChannel(
const std::string & channelName);
157 CosNotifyChannelAdmin::StructuredProxyPushSupplier_var
158 getNotifyProxyPushSupplier(
const std::string & channelName);
160 CosNotifyChannelAdmin::StructuredProxyPushSupplier_var
161 getNotifyProxyPushSupplier(
const std::string & channelName,
162 const std::string & proxyName,
163 CosNotifyFilter::ConstraintExpSeq* constraints = 0);
165 CosNotifyChannelAdmin::StructuredProxyPushConsumer_var
166 getNotifyProxyPushConsumer(
const std::string& channelName,
167 const std::string& proxyName);
169 CosNotification::StructuredEvent_var
170 createEventForm(
const std::string& typeName,
171 const std::string& eventName,
172 const std::string& domainName =
"CARMA");
174 bool sendNotification(
const std::string& channelName,
175 const std::string& proxyName,
176 CosNotification::StructuredEvent_var event);
182 template<
typename T,
typename S>
183 typename T::_var_type getNarrowedVar(
const S& s,
184 const NilInputDisposition nilInputDisposition= FAIL_ON_NIL_INPUT,
185 const IncompatibleTypesDisposition incompatibleTypesDisposition= FAIL_ON_INCOMPATIBLE_TYPES)
187 typename T::_var_type tVar;
189 if(CORBA::is_nil(s)) {
190 if(nilInputDisposition == FAIL_ON_NIL_INPUT) {
191 ThrowCarmaError(
"Input is NIL.");
195 tVar = T::_narrow(s);
197 if((incompatibleTypesDisposition == FAIL_ON_INCOMPATIBLE_TYPES) &&
198 CORBA::is_nil(tVar)) {
199 ThrowCarmaError(
"Actual type incompatible with target type.");
202 }
catch (
const CORBA::SystemException& e) {
204 "Orb::getNarrowedVar< T >( ) failed: "
207 }
catch (
const CORBA::Exception& e) {
209 "Orb::getNarrowedVar< T >( ) failed: "
214 "Orb::getNarrowedVar< T >( ) failed: "
224 typename T::_var_type resolveInit(
const char* idName)
226 CORBA::Object_var objectVar = resolveInit(idName);
227 typename T::_var_type typedVar = getNarrowedVar<T>(objectVar);
228 return typedVar._retn( );
232 typename T::_var_type resolveName(
const std::string& hierarchicalName,
const std::string& kind =
"")
234 CORBA::Object_var objectVar = resolveName(hierarchicalName, kind);
235 typename T::_var_type typedVar = getNarrowedVar<T>(objectVar);
236 return typedVar._retn();
240 typename T::_var_type waitToResolveName(
const std::string& hierarchicalName,
const std::string& kind =
"")
242 CORBA::Object_var objectVar = waitToResolveName(hierarchicalName, kind);
243 typename T::_var_type typedVar = getNarrowedVar<T>(objectVar);
244 return typedVar._retn( );
248 typename T::_var_type resolveFromString(
const std::string& objectString)
250 CORBA::Object_var objectVar = resolveFromString(objectString);
251 typename T::_var_type typedVar = getNarrowedVar<T>(objectVar);
252 return typedVar._retn( );
256 typename T::_var_type resolveFromFile(
const std::string& fileName,
const std::string& directory)
258 CORBA::Object_var objectVar = resolveFromFile(fileName, directory);
259 typename T::_var_type typedVar = getNarrowedVar<T>(objectVar);
260 return typedVar._retn( );
271 #endif // End #ifndef CARMA_UTIL_ORB_H
#define CARMA_CPTRACE(priorityLevel, message)
Macro for people who just want to use the Trace object created for them in carma::util::Program.
bool orbInit(Orb *orb)
Set ORB parameters.
Exception class for errors.
Interface file for the carma::util::Trace class and related macros.