Doxygen changes
[ACE_TAO.git] / ACE / tests / Service_Config_DLL.cpp
blob7befdeb437c2f246cf45618c0b890f60e45fb809
1 // -*- C++ -*-
2 //=============================================================================
3 /**
4 * @file Service_Config_DLL.cpp
6 * This file is related to, and used with, Service_Config_Test. It's
7 * used when testing the reentrance/thread-safety of the
8 * Service Configurator, in addition to testing the Service
9 * Configurator's ability to handle nested processing of Service
10 * Configurator directives.
12 * @author Ossama Othman <ossama@uci.edu>
14 //=============================================================================
16 #include "Service_Config_DLL.h"
17 #include "ace/Service_Config.h"
18 #include "ace/OS_NS_stdio.h"
19 #include "ace/OS_NS_string.h"
21 static ACE_THR_FUNC_RETURN
22 invoke_service_config (void *arg)
24 const ACE_TCHAR *directive = reinterpret_cast<const ACE_TCHAR *> (arg);
27 // Process a Service Configurator directive in the current thread.
28 if (ACE_Service_Config::process_directive (directive) != 0)
29 ACE_ERROR ((LM_ERROR,
30 ACE_TEXT ("(%P|%t) Service_Config_DLL::svc() - ")
31 ACE_TEXT ("process_directive() failed for:\n")
32 ACE_TEXT ("\"%s\"\n"),
33 directive));
35 return 0;
38 Service_Config_DLL::Service_Config_DLL (void)
40 ACE_OS::memset (this->directive_[0], 0, BUFSIZ * sizeof (ACE_TCHAR));
41 ACE_OS::memset (this->directive_[1], 0, BUFSIZ * sizeof (ACE_TCHAR));
44 int
45 Service_Config_DLL::init (int argc, ACE_TCHAR *argv[])
47 if (argc == 2)
49 ACE_DEBUG ((LM_DEBUG,
50 ACE_TEXT ("Loading Test_Object_%s and Test_Object_%s\n"),
51 argv[0],
52 argv[1]));
54 ACE_OS::snprintf (this->directive_[0], BUFSIZ,
55 #if (ACE_USES_CLASSIC_SVC_CONF == 1)
56 ACE_TEXT ("dynamic Test_Object_%s Service_Object * Service_Config_DLL:_make_Service_Config_DLL() \"Test_Object_%s\""),
57 #else
58 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>"),
59 #endif
60 argv[0],
61 argv[0]);
63 ACE_OS::snprintf (this->directive_[1], BUFSIZ,
64 #if (ACE_USES_CLASSIC_SVC_CONF == 1)
65 ACE_TEXT ("dynamic Test_Object_%s Service_Object * Service_Config_DLL:_make_Service_Config_DLL() \"Test_Object_%s\""),
66 #else
67 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>"),
68 #endif
70 argv[1],
71 argv[1]);
73 if (ACE_Service_Config::process_directive (this->directive_[0]) != 0)
74 ACE_ERROR ((LM_ERROR,
75 ACE_TEXT ("(%P|%t) Service_Config_DLL::init() - ")
76 ACE_TEXT ("process_directive() failed for:\n")
77 ACE_TEXT ("\"%s\": %m\n"),
78 this->directive_[0]));
80 #if defined (ACE_HAS_THREADS)
82 // Become an Active Object if more than one argument passed.
83 // Two arguments indicate two "test objects" to be dynamically
84 // loaded.
85 return this->activate ();
87 #endif /* ACE_HAS_THREADS */
90 else if (argc == 1)
92 ACE_DEBUG ((LM_DEBUG,
93 ACE_TEXT ("Service_Config_DLL::init () %@ - %s\n"),
94 this,
95 argv[0]));
97 else
99 ACE_ERROR_RETURN ((LM_ERROR,
100 ACE_TEXT ("(%P|%t) Incorrect number of arguments ")
101 ACE_TEXT ("(%d) passed to Service_Config_DLL::init ()"),
102 argc),
103 -1);
106 return 0;
110 Service_Config_DLL::fini (void)
112 return 0;
116 Service_Config_DLL::svc (void)
118 if (ACE_Thread_Manager::instance ()->spawn (invoke_service_config,
119 this->directive_[1]) == -1)
120 ACE_ERROR_RETURN ((LM_ERROR,
121 ACE_TEXT ("(%P|%t) Unable to spawn thread to ")
122 ACE_TEXT ("invoke Service Configurator.\n")),
123 -1);
125 return 0;
128 // The same class (Service_Config_DLL) is used to implement each of the
129 // Service Objects whose service descriptors are defined below.
131 // -----------------------------------------------------------------
133 ACE_STATIC_SVC_DEFINE (Test_Object_1,
134 ACE_TEXT ("Test_Object_1"),
135 ACE_SVC_OBJ_T,
136 &ACE_SVC_NAME (Service_Config_DLL),
137 ACE_Service_Type::DELETE_THIS
138 | ACE_Service_Type::DELETE_OBJ,
141 // -----------------------------------------------------------------
143 ACE_STATIC_SVC_DEFINE (Test_Object_2,
144 ACE_TEXT ("Test_Object_2"),
145 ACE_SVC_OBJ_T,
146 &ACE_SVC_NAME (Service_Config_DLL),
147 ACE_Service_Type::DELETE_THIS
148 | ACE_Service_Type::DELETE_OBJ,
151 // -----------------------------------------------------------------
153 ACE_STATIC_SVC_DEFINE (Test_Object_3,
154 ACE_TEXT ("Test_Object_3"),
155 ACE_SVC_OBJ_T,
156 &ACE_SVC_NAME (Service_Config_DLL),
157 ACE_Service_Type::DELETE_THIS
158 | ACE_Service_Type::DELETE_OBJ,
161 // -----------------------------------------------------------------
163 ACE_STATIC_SVC_DEFINE (Test_Object_4,
164 ACE_TEXT ("Test_Object_4"),
165 ACE_SVC_OBJ_T,
166 &ACE_SVC_NAME (Service_Config_DLL),
167 ACE_Service_Type::DELETE_THIS
168 | ACE_Service_Type::DELETE_OBJ,
171 // -----------------------------------------------------------------
173 ACE_STATIC_SVC_DEFINE (Test_Object_5,
174 ACE_TEXT ("Test_Object_5"),
175 ACE_SVC_OBJ_T,
176 &ACE_SVC_NAME (Service_Config_DLL),
177 ACE_Service_Type::DELETE_THIS
178 | ACE_Service_Type::DELETE_OBJ,
181 // -----------------------------------------------------------------
183 ACE_STATIC_SVC_DEFINE (Test_Object_6,
184 ACE_TEXT ("Test_Object_6"),
185 ACE_SVC_OBJ_T,
186 &ACE_SVC_NAME (Service_Config_DLL),
187 ACE_Service_Type::DELETE_THIS
188 | ACE_Service_Type::DELETE_OBJ,
191 // -----------------------------------------------------------------
193 ACE_STATIC_SVC_DEFINE (Final_Object,
194 ACE_TEXT ("Final_Object"),
195 ACE_SVC_OBJ_T,
196 &ACE_SVC_NAME (Service_Config_DLL),
197 ACE_Service_Type::DELETE_THIS
198 | ACE_Service_Type::DELETE_OBJ,
201 // -----------------------------------------------------------------
203 ACE_STATIC_SVC_DEFINE (Test_Object_1_More,
204 ACE_TEXT ("Test_Object_1_More"),
205 ACE_SVC_OBJ_T,
206 &ACE_SVC_NAME (Service_Config_DLL),
207 ACE_Service_Type::DELETE_THIS
208 | ACE_Service_Type::DELETE_OBJ,
211 // -----------------------------------------------------------------
213 ACE_STATIC_SVC_DEFINE (Test_Object_2_More,
214 ACE_TEXT ("Test_Object_2_More"),
215 ACE_SVC_OBJ_T,
216 &ACE_SVC_NAME (Service_Config_DLL),
217 ACE_Service_Type::DELETE_THIS
218 | ACE_Service_Type::DELETE_OBJ,
222 // -----------------------------------------------------------------
224 // Same factory is used for all service descriptors defined above.
225 ACE_FACTORY_DEFINE (Service_Config_DLL, Service_Config_DLL)
228 ** Simple service which will refuse to load/initialize correctly.
229 ** The main program should do:
230 ** 1. Try to load this service (which should fail)
231 ** 2. Try to look up this service and call its info() hook; if info()
232 ** can be called, the test has failed.
233 ** Similarly, if fini() is called later, something is very wrong.
236 /// Initializes object when dynamic linking occurs.
238 Refuses_Init::init (int, ACE_TCHAR *[])
240 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Refuses_Init::init - refusing to init\n")));
241 return -1;
244 /// Terminates object when dynamic unlinking occurs.
246 Refuses_Init::fini (void)
248 ACE_ERROR ((LM_ERROR,
249 ACE_TEXT ("Refuses_Init::fini should not be called!\n")));
250 return 0;
253 /// Returns information on a service object.
255 Refuses_Init::info (ACE_TCHAR **info_string, size_t length) const
257 ACE_TCHAR const *msg =
258 ACE_TEXT ("Refuses_Init service, shouldn't be here!\n");
259 if (*info_string == 0)
260 *info_string = ACE_OS::strdup (msg);
261 else
262 ACE_OS::strncpy (*info_string, msg, length);
263 ACE_ERROR ((LM_ERROR,
264 ACE_TEXT ("Refuses_Init::info() called - shouldn't be\n")));
265 return ACE_OS::strlen (*info_string);
268 ACE_FACTORY_DEFINE (Service_Config_DLL, Refuses_Init)