1 #include "TimeModuleS.h"
2 #include "tao/BiDir_GIOP/BiDirGIOP.h"
3 #include "tao/AnyTypeCode/Any.h"
4 #include "tao/Utils/PolicyList_Destroyer.h"
5 #include "orbsvcs/CosNamingC.h"
6 #include "tao/AnyTypeCode/Any.h"
7 #include "ace/OS_NS_time.h"
10 public POA_TimeModule::Time
13 virtual TimeModule::TimeOfDay
20 TimeModule::TimeOfDay
Time_impl::get_gmt ()
22 time_t time_now
= ACE_OS::time(0);
23 struct tm
*time_p
= ACE_OS::gmtime(&time_now
);
25 TimeModule::TimeOfDay tod
;
27 tod
.hour
= time_p
->tm_hour
;
28 tod
.minute
= time_p
->tm_min
;
29 tod
.second
= time_p
->tm_sec
;
35 Time_impl::Shutdown ()
41 ACE_TMAIN (int argc
, ACE_TCHAR
*argv
[])
47 CORBA::ORB_init (argc
, argv
);
49 // Get reference to Root POA.
50 CORBA::Object_var obj
=
51 orb
->resolve_initial_references ("RootPOA");
53 PortableServer::POA_var rootpoa
=
54 PortableServer::POA::_narrow (obj
.in ());
56 // Activate POA manager
57 PortableServer::POAManager_var mgr
=
58 rootpoa
->the_POAManager ();
62 PortableServer::POA_var poa
;
64 TAO::Utils::PolicyList_Destroyer
PolicyList (3);
65 PolicyList
.length (3);
68 rootpoa
->create_lifespan_policy (PortableServer::PERSISTENT
);
71 rootpoa
->create_id_assignment_policy (PortableServer::USER_ID
);
73 CORBA::Any CallbackPolicy
;
74 CallbackPolicy
<<= BiDirPolicy::BOTH
;
75 const char* sServerPoaName
= "TelemetryServer";
78 orb
->create_policy (BiDirPolicy::BIDIRECTIONAL_POLICY_TYPE
,
81 poa
= rootpoa
->create_POA (sServerPoaName
,
86 PortableServer::ObjectId_var ServerId
=
87 PortableServer::string_to_ObjectId ("TimeServer");
90 Time_impl
*time_servant
= new Time_impl
;
91 PortableServer::ServantBase_var
self_manage (time_servant
);
93 poa
->activate_object_with_id (ServerId
.in (),
96 // Get a reference after activating the object
97 CORBA::Object_var object
= poa
->id_to_reference (ServerId
.in ());
98 TimeModule::Time_var tm
= TimeModule::Time::_narrow (object
.in ());
100 // Get reference to initial naming context
101 CORBA::Object_var name_obj
=
102 orb
->resolve_initial_references ("NameService");
104 CosNaming::NamingContext_var inc
=
105 CosNaming::NamingContext::_narrow (name_obj
.in ());
107 if (CORBA::is_nil (inc
.in ()))
109 ACE_ERROR ((LM_ERROR
,
110 "(%P|%t) Error fetching naming context\n"));
113 CosNaming::Name service_name
;
114 service_name
.length(1);
116 CORBA::string_dup ("Time");
118 inc
->rebind (service_name
,
121 // Run the event loop for fun
122 ACE_Time_Value
tv (3, 0);
127 rootpoa
->destroy (0 , 0);
131 catch (const CORBA::Exception
& ex
)
133 ex
._tao_print_exception ("Caught an exception\n");