Merge pull request #1551 from DOCGroup/plm_jira_333
[ACE_TAO.git] / TAO / examples / Advanced / ch_3 / server.cpp
blobb59b38df1c29a2629d9c03de782f01f06b2b34d6
2 //=============================================================================
3 /**
4 * @file server.cpp
6 * @author Source code used in TAO has been modified and adapted from thecode provided in the book
7 * @author "Advanced CORBA Programming with C++"by Michi Henning and Steve Vinoski. Copyright1999. Addison-Wesley
8 * @author Reading
9 * @author MA. Used with permission ofAddison-Wesley.Modified for TAO by Mike Moran <mm4@cs.wustl.edu>
11 //=============================================================================
14 #include "server.h"
15 #include <ace/streams.h>
16 #include <ace/OS_NS_time.h>
18 // The following headers are #included automatically by ACE+TAO.
19 // Therefore, they don't need to be included explicitly.
20 //#include <time.h>
21 //#include <iostream.h>
23 TimeOfDay
24 Time_impl::
25 get_gmt (void)
27 time_t time_now = ACE_OS::time (0);
28 struct tm *time_p = ACE_OS::gmtime (&time_now);
30 TimeOfDay tod;
31 tod.hour = time_p->tm_hour;
32 tod.minute = time_p->tm_min;
33 tod.second = time_p->tm_sec;
35 return tod;
38 // Changelog for Henning and Vinoski's chapter 18 example
39 // ______________________________________________________
41 int
42 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
44 try
46 // Initialize orb
47 CORBA::ORB_var orb = CORBA::ORB_init (argc, argv);
49 // Get reference to Root POA.
50 CORBA::Object_var obj
51 = orb->resolve_initial_references ("RootPOA");
52 PortableServer::POA_var poa
53 = PortableServer::POA::_narrow (obj.in ());
55 // Activate POA manager
56 PortableServer::POAManager_var mgr
57 = poa->the_POAManager ();
58 mgr->activate ();
60 // Create an object
61 Time_impl time_servant;
63 // Write its stringified reference to stdout
64 Time_var tm = time_servant._this ();
65 CORBA::String_var str = orb->object_to_string (tm.in ());
66 cout << str.in () << endl;
68 // Accept requests
69 orb->run ();
71 catch (const CORBA::Exception &)
73 cerr << "Uncaught CORBA exception" << endl;
74 return 1;
76 return 0;