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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
|
// -*- C++ -*-
//=============================================================================
/**
* @file Service_Config_DLL.cpp
*
* This file is related to, and used with, Service_Config_Test. It's
* used when testing the reentrance/thread-safety of the
* Service Configurator, in addition to testing the Service
* Configurator's ability to handle nested processing of Service
* Configurator directives.
*
* @author Ossama Othman <ossama@uci.edu>
*/
//=============================================================================
#include "Service_Config_DLL.h"
#include "ace/Service_Config.h"
#include "ace/OS_NS_stdio.h"
#include "ace/OS_NS_string.h"
static ACE_THR_FUNC_RETURN
invoke_service_config (void *arg)
{
const ACE_TCHAR *directive = reinterpret_cast<const ACE_TCHAR *> (arg);
// Process a Service Configurator directive in the current thread.
if (ACE_Service_Config::process_directive (directive) != 0)
ACE_ERROR ((LM_ERROR,
ACE_TEXT ("(%P|%t) Service_Config_DLL::svc() - ")
ACE_TEXT ("process_directive() failed for:\n")
ACE_TEXT ("\"%s\"\n"),
directive));
return 0;
}
Service_Config_DLL::Service_Config_DLL (void)
{
ACE_OS::memset (this->directive_[0], 0, BUFSIZ * sizeof (ACE_TCHAR));
ACE_OS::memset (this->directive_[1], 0, BUFSIZ * sizeof (ACE_TCHAR));
}
int
Service_Config_DLL::init (int argc, ACE_TCHAR *argv[])
{
if (argc == 2)
{
ACE_DEBUG ((LM_DEBUG,
ACE_TEXT ("Loading Test_Object_%s and Test_Object_%s\n"),
argv[0],
argv[1]));
ACE_OS::sprintf (this->directive_[0],
#if (ACE_USES_CLASSIC_SVC_CONF == 1)
ACE_TEXT ("dynamic Test_Object_%s Service_Object * Service_Config_DLL:_make_Service_Config_DLL() \"Test_Object_%s\""),
#else
ACE_TEXT ("<?xml version='1.0'?> <dynamic id='Test_Object_%s' type='service_object'> <initializer init='_make_Service_Config_DLL' path='Service_Config_DLL' params='Test_Object_%s'/> </dynamic>"),
#endif
argv[0],
argv[0]);
ACE_OS::sprintf (this->directive_[1],
#if (ACE_USES_CLASSIC_SVC_CONF == 1)
ACE_TEXT ("dynamic Test_Object_%s Service_Object * Service_Config_DLL:_make_Service_Config_DLL() \"Test_Object_%s\""),
#else
ACE_TEXT ("<?xml version='1.0'?> <dynamic id='Test_Object_%s' type='service_object'> <initializer init='_make_Service_Config_DLL' path='Service_Config_DLL' params='Test_Object_%s'/> </dynamic>"),
#endif
argv[1],
argv[1]);
if (ACE_Service_Config::process_directive (this->directive_[0]) != 0)
ACE_ERROR ((LM_ERROR,
ACE_TEXT ("(%P|%t) Service_Config_DLL::init() - ")
ACE_TEXT ("process_directive() failed for:\n")
ACE_TEXT ("\"%s\": %m\n"),
this->directive_[0]));
#if defined (ACE_HAS_THREADS)
// Become an Active Object if more than one argument passed.
// Two arguments indicate two "test objects" to be dynamically
// loaded.
return this->activate ();
#endif /* ACE_HAS_THREADS */
}
else if (argc == 1)
{
ACE_DEBUG ((LM_DEBUG,
ACE_TEXT ("Service_Config_DLL::init () %@ - %s\n"),
this,
argv[0]));
}
else
{
ACE_ERROR_RETURN ((LM_ERROR,
ACE_TEXT ("(%P|%t) Incorrect number of arguments ")
ACE_TEXT ("(%d) passed to Service_Config_DLL::init ()"),
argc),
-1);
}
return 0;
}
int
Service_Config_DLL::fini (void)
{
return 0;
}
int
Service_Config_DLL::svc (void)
{
if (ACE_Thread_Manager::instance ()->spawn (invoke_service_config,
this->directive_[1]) == -1)
ACE_ERROR_RETURN ((LM_ERROR,
ACE_TEXT ("(%P|%t) Unable to spawn thread to ")
ACE_TEXT ("invoke Service Configurator.\n")),
-1);
return 0;
}
// The same class (Service_Config_DLL) is used to implement each of the
// Service Objects whose service descriptors are defined below.
// -----------------------------------------------------------------
ACE_STATIC_SVC_DEFINE (Test_Object_1,
ACE_TEXT ("Test_Object_1"),
ACE_SVC_OBJ_T,
&ACE_SVC_NAME (Service_Config_DLL),
ACE_Service_Type::DELETE_THIS
| ACE_Service_Type::DELETE_OBJ,
0)
// -----------------------------------------------------------------
ACE_STATIC_SVC_DEFINE (Test_Object_2,
ACE_TEXT ("Test_Object_2"),
ACE_SVC_OBJ_T,
&ACE_SVC_NAME (Service_Config_DLL),
ACE_Service_Type::DELETE_THIS
| ACE_Service_Type::DELETE_OBJ,
0)
// -----------------------------------------------------------------
ACE_STATIC_SVC_DEFINE (Test_Object_3,
ACE_TEXT ("Test_Object_3"),
ACE_SVC_OBJ_T,
&ACE_SVC_NAME (Service_Config_DLL),
ACE_Service_Type::DELETE_THIS
| ACE_Service_Type::DELETE_OBJ,
0)
// -----------------------------------------------------------------
ACE_STATIC_SVC_DEFINE (Test_Object_4,
ACE_TEXT ("Test_Object_4"),
ACE_SVC_OBJ_T,
&ACE_SVC_NAME (Service_Config_DLL),
ACE_Service_Type::DELETE_THIS
| ACE_Service_Type::DELETE_OBJ,
0)
// -----------------------------------------------------------------
ACE_STATIC_SVC_DEFINE (Test_Object_5,
ACE_TEXT ("Test_Object_5"),
ACE_SVC_OBJ_T,
&ACE_SVC_NAME (Service_Config_DLL),
ACE_Service_Type::DELETE_THIS
| ACE_Service_Type::DELETE_OBJ,
0)
// -----------------------------------------------------------------
ACE_STATIC_SVC_DEFINE (Test_Object_6,
ACE_TEXT ("Test_Object_6"),
ACE_SVC_OBJ_T,
&ACE_SVC_NAME (Service_Config_DLL),
ACE_Service_Type::DELETE_THIS
| ACE_Service_Type::DELETE_OBJ,
0)
// -----------------------------------------------------------------
ACE_STATIC_SVC_DEFINE (Final_Object,
ACE_TEXT ("Final_Object"),
ACE_SVC_OBJ_T,
&ACE_SVC_NAME (Service_Config_DLL),
ACE_Service_Type::DELETE_THIS
| ACE_Service_Type::DELETE_OBJ,
0)
// -----------------------------------------------------------------
ACE_STATIC_SVC_DEFINE (Test_Object_1_More,
ACE_TEXT ("Test_Object_1_More"),
ACE_SVC_OBJ_T,
&ACE_SVC_NAME (Service_Config_DLL),
ACE_Service_Type::DELETE_THIS
| ACE_Service_Type::DELETE_OBJ,
0)
// -----------------------------------------------------------------
ACE_STATIC_SVC_DEFINE (Test_Object_2_More,
ACE_TEXT ("Test_Object_2_More"),
ACE_SVC_OBJ_T,
&ACE_SVC_NAME (Service_Config_DLL),
ACE_Service_Type::DELETE_THIS
| ACE_Service_Type::DELETE_OBJ,
0)
// -----------------------------------------------------------------
// Same factory is used for all service descriptors defined above.
ACE_FACTORY_DEFINE (Service_Config_DLL, Service_Config_DLL)
/*
** Simple service which will refuse to load/initialize correctly.
** The main program should do:
** 1. Try to load this service (which should fail)
** 2. Try to look up this service and call its info() hook; if info()
** can be called, the test has failed.
** Similarly, if fini() is called later, something is very wrong.
*/
/// Initializes object when dynamic linking occurs.
int
Refuses_Init::init (int, ACE_TCHAR *[])
{
ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Refuses_Init::init - refusing to init\n")));
return -1;
}
/// Terminates object when dynamic unlinking occurs.
int
Refuses_Init::fini (void)
{
ACE_ERROR ((LM_ERROR,
ACE_TEXT ("Refuses_Init::fini should not be called!\n")));
return 0;
}
/// Returns information on a service object.
int
Refuses_Init::info (ACE_TCHAR **info_string, size_t length) const
{
ACE_TCHAR const *msg =
ACE_TEXT ("Refuses_Init service, shouldn't be here!\n");
if (*info_string == 0)
*info_string = ACE_OS::strdup (msg);
else
ACE_OS::strncpy (*info_string, msg, length);
ACE_ERROR ((LM_ERROR,
ACE_TEXT ("Refuses_Init::info() called - shouldn't be\n")));
return ACE_OS::strlen (*info_string);
}
ACE_FACTORY_DEFINE (Service_Config_DLL, Refuses_Init)
|