1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
|
// $Id$
#include "ace/Get_Opt.h"
#include "Logging_Service.h"
#include "orbsvcs/Log/BasicLogFactory_i.h"
Logging_Service::Logging_Service (void)
: basic_log_factory_name_ ("BasicLogFactory")
{
// No-Op.
}
Logging_Service::~Logging_Service (void)
{
// No-Op.
}
void
Logging_Service::init_ORB (int& argc, char *argv [],
CORBA::Environment &ACE_TRY_ENV)
{
this->orb_ = CORBA::ORB_init (argc,
argv,
"",
ACE_TRY_ENV);
ACE_CHECK;
CORBA::Object_var poa_object =
this->orb_->resolve_initial_references("RootPOA",
ACE_TRY_ENV);
ACE_CHECK;
this->poa_ =
PortableServer::POA::_narrow (poa_object.in (),
ACE_TRY_ENV);
ACE_CHECK;
PortableServer::POAManager_var poa_manager =
this->poa_->the_POAManager (ACE_TRY_ENV);
ACE_CHECK;
poa_manager->activate (ACE_TRY_ENV);
ACE_CHECK;
}
void
Logging_Service::startup (int argc, char *argv[],
CORBA::Environment &ACE_TRY_ENV)
{
ACE_DEBUG ((LM_DEBUG,
"\nStarting up the Telecom Log Service...\n"));
// initalize the ORB.
this->init_ORB (argc, argv,
ACE_TRY_ENV);
ACE_CHECK;
// Resolve the naming service.
this->resolve_naming_service (ACE_TRY_ENV);
ACE_CHECK;
// Activate the basic log factory
// CORBA::Object_var obj =
DsLogAdmin::BasicLogFactory_var obj =
this->basic_log_factory_.activate (this->poa_.in (),
ACE_TRY_ENV);
ACE_CHECK;
ACE_ASSERT (!CORBA::is_nil (obj.in ()));
CORBA::String_var str =
this->orb_->object_to_string (obj.in (), ACE_TRY_ENV);
ACE_DEBUG ((LM_DEBUG,
"The Basic Log Factory IOR is <%s>\n", str.in ()));
// Register the Basic Log Factory
ACE_ASSERT(!CORBA::is_nil (this->naming_.in ()));
CosNaming::Name name (1);
name.length (1);
name[0].id = CORBA::string_dup (this->basic_log_factory_name_);
this->naming_->rebind (name,
obj.in (),
ACE_TRY_ENV);
ACE_CHECK;
ACE_DEBUG ((LM_DEBUG,
"Registered with the naming service as: %s\n",
this->basic_log_factory_name_));
}
void
Logging_Service::resolve_naming_service (CORBA::Environment &ACE_TRY_ENV)
{
CORBA::Object_var naming_obj =
this->orb_->resolve_initial_references ("NameService",
ACE_TRY_ENV);
ACE_CHECK;
// Need to check return value for errors.
if (CORBA::is_nil (naming_obj.in ()))
ACE_THROW (CORBA::UNKNOWN ());
this->naming_ =
CosNaming::NamingContext::_narrow (naming_obj.in (),
ACE_TRY_ENV);
ACE_CHECK;
}
int
Logging_Service::run (void)
{
ACE_DEBUG ((LM_DEBUG, "%s: Running the Telecom Log Service\n", __FILE__));
if (this->orb_->run () == -1)
ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "run"), 1);
return 0;
}
void
Logging_Service::shutdown (CORBA::Environment &ACE_TRY_ENV)
{
// Deactivate.
PortableServer::ObjectId_var oid =
this->poa_->servant_to_id (&this->basic_log_factory_,
ACE_TRY_ENV);
ACE_CHECK;
// deactivate from the poa.
this->poa_->deactivate_object (oid.in (),
ACE_TRY_ENV);
ACE_CHECK;
// Unbind from the naming service.
CosNaming::Name name (1);
name.length (1);
name[0].id = CORBA::string_dup (this->basic_log_factory_name_);
this->naming_->unbind (name,
ACE_TRY_ENV);
// shutdown the ORB.
if (!CORBA::is_nil (this->orb_.in ()))
this->orb_->shutdown ();
}
int
main (int argc, char *argv[])
{
Logging_Service service;
ACE_TRY_NEW_ENV
{
service.startup (argc,
argv,
ACE_TRY_ENV);
ACE_TRY_CHECK;
if (service.run () == -1)
{
service.shutdown ();
ACE_ERROR_RETURN ((LM_ERROR,
"Failed to run the Telecom Log Service.\n"),
1);
}
}
ACE_CATCHANY
{
ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION,
"Failed to start the Telecom Log Service\n");
return 1;
}
ACE_ENDTRY;
service.shutdown ();
return 0;
}
|