1 #include "MessengerTask.h"
2 #include "Messenger_i.h"
3 #include "orbsvcs/CosNamingC.h"
6 MessengerTask::MessengerTask()
8 // cast away constness to make Sun CC family of compilers happy.
9 char* argv
[] = {const_cast<char *>("Messenger"), 0 };
11 orb_
= CORBA::ORB_init(argc
, argv
, "ServerORB");
14 void MessengerTask::end()
20 int MessengerTask::svc()
23 // Get reference to Root POA
24 CORBA::Object_var obj
= orb_
->resolve_initial_references("RootPOA");
25 PortableServer::POA_var poa
= PortableServer::POA::_narrow(obj
.in());
27 // Activate POA Manager
28 PortableServer::POAManager_var mgr
= poa
->the_POAManager();
31 // Find the Naming Service
32 obj
= orb_
->resolve_initial_references("NameService");
33 CosNaming::NamingContext_var root
=
34 CosNaming::NamingContext::_narrow(obj
.in());
36 if (CORBA::is_nil(root
.in())) {
37 std::cerr
<< "Nil Naming Context reference" << std::endl
;
40 // Bind the example Naming Context, if necessary
43 name
[0].id
= CORBA::string_dup("example");
47 catch(const CosNaming::NamingContext::NotFound
&) {
48 root
->bind_new_context(name
);
51 // Bind the Messenger object
53 name
[1].id
= CORBA::string_dup("Messenger");
56 PortableServer::Servant_var
<Messenger_i
> servant
= new Messenger_i
;
57 PortableServer::ObjectId_var oid
= poa
->activate_object(servant
.in());
58 obj
= poa
->id_to_reference(oid
.in());
59 root
->rebind(name
, obj
.in());
61 std::cout
<< "Messenger object bound in Naming Service" << std::endl
;
63 // Normally we run the orb and the orb is shutdown by
64 // calling MessengerTask::end(). To simplify the coordination
65 // between the main thread and this Messenger thread, specify
66 // the time period to let the Messenger thread finish by itself.
74 catch(const CORBA::Exception
& ex
) {
75 std::cerr
<< "CORBA exception: " << ex
<< std::endl
;