Merge pull request #1551 from DOCGroup/plm_jira_333
[ACE_TAO.git] / TAO / orbsvcs / tests / Notify / Bug_3252_Regression / server.cpp
blob7c80f15b44ced7721ed7175cb155f91563309b7a
1 #include "ace/ARGV.h"
2 #include "ace/Service_Config.h"
3 #include "ace/Log_Msg.h"
5 #include "tao/corba.h"
6 #include "tao/ORB.h"
7 #include "tao/PortableServer/PortableServer.h"
8 #include "orbsvcs/CosNotifyChannelAdminC.h"
9 #include "orbsvcs/Notify/CosNotify_Service.h"
11 #include "DllOrb.h"
13 #if defined (__BORLANDC__) && (__BORLANDC__ >= 0x660) && (__BORLANDC__ <= 0x750)
14 # pragma option push -w-8057
15 #endif
17 ACE_TCHAR const * const scpc_loadOrb = ACE_DYNAMIC_VERSIONED_SERVICE_DIRECTIVE(
18 "testDllOrb",
19 "Bug_3252",
20 TAO_VERSION,
21 "_make_DllOrb",
22 "testDllOrb -ORBDebugLevel 0 -ORBId testDllOrb -NumThreads 2 -ORBDottedDecimalAddresses 1 -ORBCollocationStrategy thru_poa"
25 ACE_TCHAR const * const scpc_unloadOrb = ACE_REMOVE_SERVICE_DIRECTIVE("testDllOrb");
27 ACE_TCHAR const * const scpc_loadNotifyService = ACE_DYNAMIC_VERSIONED_SERVICE_DIRECTIVE(
28 "testNotifyService",
29 "TAO_CosNotification_Serv",
30 TAO_VERSION,
31 "_make_TAO_CosNotify_Service",
32 "-UseSeparateDispatchingORB 1"
35 ACE_TCHAR const * const scpc_unloadNotifyService = ACE_REMOVE_SERVICE_DIRECTIVE("testNotifyService");
37 int
38 unloadNotify(ACE_Service_Config & service_config)
40 ACE_DEBUG ((LM_INFO, ACE_TEXT ("Unloading NotifyService ...\n")));
41 if(service_config.process_directive(scpc_unloadNotifyService) != 0)
43 ACE_ERROR ((LM_ERROR, ACE_TEXT ("Unloading NotifyService failed\n")));
44 return -1;
46 ACE_DEBUG ((LM_INFO, ACE_TEXT ("unloading NotifyService done.\n")));
47 return 0;
50 int
51 loadNotify(ACE_Service_Config & service_config)
53 try
55 DllOrb * p_orb = ACE_Dynamic_Service<DllOrb>::instance ("testDllOrb");
56 CORBA::ORB_var v_orb = p_orb->orb();
58 CORBA::Object_var v_poa = v_orb->resolve_initial_references("RootPOA");
59 PortableServer::POA_var v_rootPOA = PortableServer::POA::_narrow(v_poa.in ());
60 ACE_DEBUG ((LM_INFO, ACE_TEXT ("RootPOA OK.\n")));
62 ACE_DEBUG ((LM_INFO, ACE_TEXT ("Loading NotifyService ...\n")));
63 if(0 != service_config.process_directive(scpc_loadNotifyService))
65 ACE_ERROR ((LM_ERROR, ACE_TEXT ("Loading NotifyService failed\n")));
66 return -1;
68 ACE_DEBUG ((LM_INFO, ACE_TEXT ("Loading NotifyService done.\n")));
70 TAO_CosNotify_Service * p_notifyService =
71 ACE_Dynamic_Service<TAO_CosNotify_Service>::instance("testNotifyService");
73 p_notifyService->init_service(v_orb.in());
75 CosNotifyChannelAdmin::EventChannelFactory_var v_notifyFactory =
76 p_notifyService->create(
77 v_rootPOA.in()
79 ACE_DEBUG ((LM_INFO, ACE_TEXT ("got EventChannelFactory\n")));
81 // create an event channel
82 CosNotifyChannelAdmin::ChannelID id;
84 CosNotification::QoSProperties initialQos;
85 CosNotification::AdminProperties initialAdmin;
87 CosNotifyChannelAdmin::EventChannel_var v_eventChannel =
88 v_notifyFactory->create_channel(
89 initialQos,
90 initialAdmin,
93 ACE_DEBUG ((LM_INFO, ACE_TEXT ("got EventChannel\n")));
95 CosNotifyFilter::FilterFactory_var v_filterFactory =
96 v_eventChannel->default_filter_factory();
97 ACE_DEBUG ((LM_INFO, ACE_TEXT ("got FilterFactory\n")));
99 CosNotifyFilter::Filter_var v_filter =
100 v_filterFactory->create_filter("ETCL");
101 ACE_DEBUG ((LM_INFO, ACE_TEXT ("got Filter\n")));
103 catch(CORBA::Exception const & rc_ex)
105 rc_ex._tao_print_exception ("Unexpected CORBA Exception: ");
106 return -1;
108 catch(...)
110 ACE_ERROR ((LM_ERROR, ACE_TEXT ("Unexpected C++ Exception\n")));
111 return -1;
114 return 0;
118 int unloadOrb(ACE_Service_Config & service_config)
120 ACE_DEBUG ((LM_INFO, ACE_TEXT ("Unloading ORB ...\n")));
121 if(0 != service_config.process_directive(scpc_unloadOrb))
123 ACE_ERROR ((LM_ERROR, ACE_TEXT ("Unloading ORB failed\n")));
124 return -1;
126 ACE_DEBUG ((LM_INFO, ACE_TEXT ("unloading ORB done.\n")));
127 return 0;
130 int loadOrb(ACE_Service_Config & service_config)
132 ACE_DEBUG ((LM_INFO, ACE_TEXT ("Loading ORB ...\n")));
133 if(0 != service_config.process_directive(scpc_loadOrb))
135 ACE_ERROR ((LM_ERROR, ACE_TEXT ("Loading ORB failed\n")));
136 return -1;
138 ACE_DEBUG ((LM_INFO, ACE_TEXT ("Loading ORB done.\n")));
139 return 0;
145 ACE_TMAIN(int, ACE_TCHAR **argv)
147 int result = 0;
149 ACE_TCHAR signum[64];
150 ACE_OS::sprintf(signum, ACE_TEXT("%d"), SIGUSR1);
152 ACE_ARGV args;
153 args.add(argv[0]);
154 args.add(ACE_TEXT("-s"));
155 args.add(signum);
157 ACE_Service_Config &serviceConfig = *ACE_Service_Config::singleton ();
159 result = serviceConfig.open (args.argc(),
160 args.argv(),
161 ACE_DEFAULT_LOGGER_KEY,
162 true, // ignore_static_svcs = 1,
163 true, // ignore_default_svc_conf_file = 0,
164 false // ignore_debug_flag = 0
167 if(0 != result)
169 ACE_ERROR ((LM_ERROR, ACE_TEXT ("serviceConfig.open failed\n")));
170 return result;
172 ACE_DEBUG ((LM_INFO, ACE_TEXT ("serviceConfig.open done\n")));
174 for(int i = 0; i < 5; ++i)
176 ACE_DEBUG ((LM_INFO, ACE_TEXT ("loadOrb ...\n")));
177 result = loadOrb(serviceConfig);
178 if(0 != result)
180 ACE_ERROR ((LM_ERROR, ACE_TEXT ("loadOrb failed\n")));
181 return result;
183 ACE_DEBUG ((LM_INFO, ACE_TEXT ("loadOrb done\n")));
185 ACE_DEBUG ((LM_INFO, ACE_TEXT ("loadNotify ...\n")));
186 result = loadNotify(serviceConfig);
187 if(0 != result)
189 ACE_ERROR ((LM_ERROR, ACE_TEXT ("loadNotify failed\n")));
190 return result;
192 ACE_DEBUG ((LM_INFO, ACE_TEXT ("loadNotify done\n")));
194 ACE_DEBUG ((LM_INFO, ACE_TEXT ("unloadNotify ...\n")));
195 result = unloadNotify(serviceConfig);
196 if(0 != result)
198 ACE_ERROR ((LM_ERROR, ACE_TEXT ("unloadNotify failed\n")));
199 return result;
201 ACE_DEBUG ((LM_INFO, ACE_TEXT ("unloadNotify done\n")));
203 ACE_DEBUG ((LM_INFO, ACE_TEXT ("unloadOrb ...\n")));
204 result = unloadOrb(serviceConfig);
205 if(0 != result)
207 ACE_ERROR ((LM_ERROR, ACE_TEXT ("unloadOrb failed\n")));
208 return result;
210 ACE_DEBUG ((LM_INFO, ACE_TEXT ("unloadOrb done\n")));
213 ACE_DEBUG ((LM_INFO, ACE_TEXT ("serviceConfig.fini_svcs ...\n")));
214 result = serviceConfig.fini_svcs();
215 if(0 != result)
217 ACE_ERROR ((LM_ERROR, ACE_TEXT ("serviceConfig.fini_svcs failed\n")));
218 return result;
220 ACE_DEBUG ((LM_INFO, ACE_TEXT ("serviceConfig.fini_svcs done\n")));
222 ACE_DEBUG ((LM_INFO, ACE_TEXT ("serviceConfig.close ...\n")));
223 result = serviceConfig.close();
224 if(0 != result)
226 ACE_ERROR ((LM_ERROR, ACE_TEXT ("serviceConfig.close failed\n")));
227 return result;
229 ACE_DEBUG ((LM_INFO, ACE_TEXT ("serviceConfig.close done\n")));
231 return 0;
234 #if defined (__BORLANDC__) && (__BORLANDC__ >= 0x660) && (__BORLANDC__ <= 0x750)
235 # pragma option pop
236 #endif