=default for generated implementation copy ctor
[ACE_TAO.git] / TAO / tests / Bug_3171_Regression / server.cpp
blob5acca9c4bfe86954d74fdfdd71ed09447c456143
1 #include "ace/Get_Opt.h"
2 #include "ace/Task.h"
3 #include "tao/corba.h"
4 #include "tao/Utils/ORB_Manager.h"
5 #include "tao/AnyTypeCode/Any.h"
6 #include "tao/Messaging/Messaging.h"
7 #include "tao/ORBInitializer_Registry.h"
8 #include "tao/PI/PI.h"
9 #include "tao/LocalObject.h"
11 int g_nthreads = 1;
12 bool g_setTimeout = true;
13 bool g_registerORBinitializer = true;
14 bool g_initInMain = false;
15 int g_argc;
16 ACE_TCHAR ** g_argv;
18 int initORB(int threadID);
20 int
21 parse_args (int argc, ACE_TCHAR *argv[])
23 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("min:"));
24 int c;
26 while ((c = get_opts ()) != -1)
27 switch (c)
29 case 'm':
30 g_initInMain = true;
31 break;
33 case 'i':
34 g_registerORBinitializer = false;
35 break;
37 case 'n':
38 g_nthreads = ACE_OS::atoi (get_opts.opt_arg ());
39 break;
41 case '?':
42 default:
43 ACE_ERROR_RETURN ((LM_ERROR,
44 "usage: %s "
45 "-m (Initialize an ORB from the main thread first) "
46 "-i (Do not register ORB initializer) "
47 "-n <numberOfThreads>"
48 "\n",
49 argv [0]),
50 -1);
52 // Indicates successful parsing of the command line
53 return 0;
56 class Worker : public ACE_Task_Base
58 public:
59 Worker ();
61 virtual int svc ();
63 private:
66 class MyORBinitializer
67 : public virtual PortableInterceptor::ORBInitializer
68 , public virtual CORBA::LocalObject
70 public:
71 MyORBinitializer( ACE_CString orbID )
72 : orbID_(orbID) {};
74 virtual
75 void
76 pre_init( PortableInterceptor::ORBInitInfo_ptr )
78 ACE_DEBUG ((LM_DEBUG,
79 "MyORBinitializer::pre_init() called for ORB \"%C\"\n",
80 orbID_.c_str()));
83 virtual
84 void
85 post_init( PortableInterceptor::ORBInitInfo_ptr )
87 ACE_DEBUG ((LM_DEBUG,
88 "MyORBinitializer::post_init() called for ORB \"%C\"\n",
89 orbID_.c_str()));
92 private:
93 ACE_CString orbID_;
96 int
97 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
99 g_argc = argc;
100 g_argv = argv;
104 if (parse_args (argc, argv) != 0)
105 return 1;
107 if (g_initInMain)
109 initORB(0);
111 // Run in both main and background thread
112 // else
114 Worker worker;
115 if (worker.activate (THR_NEW_LWP | THR_JOINABLE,
116 g_nthreads) != 0)
117 ACE_ERROR_RETURN ((LM_ERROR,
118 "Cannot activate ORB thread(s)\n"),
121 worker.thr_mgr ()->wait ();
123 ACE_DEBUG ((LM_DEBUG, "Event loop finished\n"));
125 catch (const CORBA::Exception& ex)
127 ex._tao_print_exception ("Exception caught:");
128 return 1;
131 return 0;
134 // ****************************************************************
136 Worker::Worker ()
141 Worker::svc ()
143 static int threadID = 0;
145 initORB(++threadID);
147 return 0;
151 initORB(int threadID)
155 char ORBid[10];
156 ACE_OS::sprintf (ORBid, "ORB_%d", threadID);
158 ACE_DEBUG ((LM_DEBUG, "Initializing ORB \"%C\"\n", ORBid));
160 if (g_registerORBinitializer)
162 ACE_DEBUG ((LM_DEBUG, "Creating ORB initializer\n"));
163 PortableInterceptor::ORBInitializer_var rCOI(
164 new MyORBinitializer(ORBid));
165 PortableInterceptor::register_orb_initializer( rCOI.in());
168 ACE_DEBUG ((LM_DEBUG, "Creating TAO_ORB_Manager\n"));
169 TAO_ORB_Manager* pORBmgr = new TAO_ORB_Manager;
171 if (-1 == pORBmgr->init(g_argc, g_argv, ORBid))
173 ACE_DEBUG ((LM_DEBUG, "Failed to initialize ORB \"%C\"\n", ORBid));
174 throw CORBA::INTERNAL();
177 ACE_DEBUG ((LM_DEBUG, "ORB \"%C\" initialized\n", ORBid));
179 if (g_setTimeout)
181 ACE_DEBUG ((LM_DEBUG,
182 "Setting connection timeout policy for ORB \"%C\"\n",
183 ORBid));
185 CORBA::PolicyList policyList;
187 CORBA::ORB_var orb = pORBmgr->orb();
189 TimeBase::TimeT connectionTimeout = 100*10000;
190 CORBA::Any any;
191 any <<= connectionTimeout;
193 CORBA::ULong l( policyList.length());
194 policyList.length(l+1);
196 policyList[l] = orb->create_policy(TAO::CONNECTION_TIMEOUT_POLICY_TYPE, any);
198 ACE_DEBUG ((LM_DEBUG, "Connection timeout policy set for ORB \"%C\"\n",
199 ORBid));
202 pORBmgr->fini();
204 delete pORBmgr;
206 catch (const CORBA::Exception& ex)
208 ACE_ERROR ((LM_ERROR, "Caught exception: %C\n", ex._info().c_str()));
209 return 1;
212 return 0;