Merge pull request #1844 from jrw972/monterey
[ACE_TAO.git] / TAO / examples / Logging / Logging_Service_i.cpp
blob01068f6bfab283fc67fecda732c4a402ee3fdbda
1 #include "Logging_Service_i.h"
2 #include "tao/debug.h"
4 Logger_Server::Logger_Server (void)
5 :service_name_ (ACE_TEXT("LoggingService"))
7 // Do nothing
10 int
11 Logger_Server::parse_args (void)
13 ACE_Get_Opt get_opts (argc_, argv_, ACE_TEXT("dn:"));
14 int c;
16 while ((c = get_opts ()) != -1)
17 switch (c)
19 case 'd': // debug flag.
20 TAO_debug_level++;
21 break;
22 case 'n': // Set factory name to cmnd line arg
23 service_name_ = get_opts.opt_arg ();
24 break;
25 case '?':
26 default:
27 ACE_ERROR_RETURN ((LM_ERROR,
28 "usage: %s"
29 " [-d]"
30 " [-n service-name]"
31 "\n",
32 argv_ [0]),
33 -1);
36 // Indicates successful parsing of command line.
37 return 0;
40 int
41 Logger_Server::init (int argc,
42 ACE_TCHAR *argv[])
44 this->argc_ = argc;
45 this->argv_ = argv;
47 // Call the init of <TAO_ORB_Manager> to initialize the ORB and
48 // create a child POA under the root POA.
49 if (this->orb_manager_.init_child_poa (argc,
50 argv,
51 "child_poa") == -1)
52 ACE_ERROR_RETURN ((LM_ERROR,
53 "%p\n",
54 "init_child_poa"),
55 -1);
58 this->orb_manager_.activate_poa_manager ();
60 // Parse the command line arguments.
61 if (this->parse_args () != 0)
62 ACE_ERROR_RETURN ((LM_ERROR,
63 "%p\n",
64 "parse_args"),
65 -1);
67 // Activate the logger_factory.
68 CORBA::String_var str =
69 this->orb_manager_.activate_under_child_poa ("logger_factory",
70 &this->factory_impl_);
71 if (TAO_debug_level > 0)
72 ACE_DEBUG ((LM_DEBUG,
73 "The IOR is: <%s>\n",
74 str.in ()));
76 // Initialize the naming service
77 int ret = this->init_naming_service ();
78 if (ret != 0)
79 ACE_ERROR_RETURN ((LM_ERROR,
80 "%p\n",
81 "init_naming_service"),
82 -1);
83 else
84 return 0;
88 // Initialisation of Naming Service and register IDL_Logger Context
89 // and logger_factory object.
91 int
92 Logger_Server::init_naming_service ()
94 // Get pointers to the ORB and child POA
95 CORBA::ORB_var orb = this->orb_manager_.orb ();
97 // Initialize the naming service
98 if (this->my_name_server_.init (orb.in ()) == -1)
99 return -1;
101 // Create an instance of the Logger_Factory
102 Logger_Factory_var factory = this->factory_impl_._this ();
104 //Register the logger_factory
105 CosNaming::Name factory_name (1);
106 factory_name.length (1);
107 factory_name[0].id = CORBA::string_dup ("Logger_Factory");
108 this->my_name_server_->bind (factory_name,
109 factory.in ());
111 return 0;
115 Logger_Server::run (void)
117 int ret = this->orb_manager_.run ();
118 if (ret == -1)
119 ACE_ERROR_RETURN ((LM_ERROR,
120 "Logger_Server::run"),
121 -1);
122 return 0;
125 Logger_Server::~Logger_Server (void)
127 // Do nothing