1 #include "SharedIntf_i.h"
6 #include "ace/SString.h"
7 #include "ace/Get_Opt.h"
9 const ACE_TCHAR
*ior_output_file
= ACE_TEXT ("server.ior");
13 parse_args (int argc
, ACE_TCHAR
*argv
[])
15 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("t:"));
18 while ((c
= get_opts ()) != -1)
22 nr_threads
= ACE_OS::atoi(get_opts
.opt_arg ());
27 ACE_ERROR_RETURN ((LM_ERROR
,
34 // Indicates successful parsing of the command line
39 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
46 ACE_DEBUG((LM_INFO
,"(%P|%t) START OF SERVER TEST\n"));
48 orb_
= CORBA::ORB_init (argc
, argv
, "myorb-server");
50 if (parse_args (argc
, argv
) != 0)
53 CORBA::Object_var poa_object
=
54 orb_
->resolve_initial_references("RootPOA");
56 PortableServer::POA_var root_poa
=
57 PortableServer::POA::_narrow (poa_object
.in());
59 PortableServer::POAManager_var poa_manager
=
60 root_poa
->the_POAManager ();
61 PortableServer::POA_var poa
= root_poa
;
63 poa_manager
->activate ();
65 ACE_DEBUG((LM_INFO
,"(%P|%t) ORB initialized\n"));
67 // Creating the servant and activating it
69 Test_Idl_SharedIntf_i
* intf_i
= new Test_Idl_SharedIntf_i(orb_
.in());
71 PortableServer::ServantBase_var base_var
= intf_i
;
72 PortableServer::ObjectId_var intfId_var
=
73 poa
->activate_object(base_var
.in());
75 CORBA::Object_var obj_var
=
76 poa
->id_to_reference(intfId_var
.in());
78 Test_Idl::SharedIntf_var intf_var
=
79 Test_Idl::SharedIntf::_narrow(obj_var
.in());
81 // Creating stringified IOR of the servant and writing it to a file.
83 CORBA::String_var intfString_var
=
84 orb_
->object_to_string(intf_var
.in());
86 // Output the IOR to the <ior_output_file>
87 FILE *output_file
= ACE_OS::fopen (ior_output_file
, "w");
89 ACE_ERROR_RETURN ((LM_ERROR
,
90 "Cannot open output file for writing IOR: %s\n",
93 ACE_OS::fprintf (output_file
, "%s", intfString_var
.in ());
94 ACE_OS::fclose (output_file
);
96 ACE_DEBUG((LM_INFO
,"(%P|%t) server IOR to %s\n",
99 // Running ORB in separate thread
100 Worker
worker (orb_
.in ());
101 if (worker
.activate (THR_NEW_LWP
| THR_JOINABLE
, nr_threads
) != 0)
102 ACE_ERROR_RETURN ((LM_ERROR
, "(%P|%t) %p\n", "Cannot activate server thread(s)"), -1);
104 ACE_DEBUG((LM_INFO
,"(%P|%t) Await client initialization\n"));
105 poll ("./client.ior");
106 ACE_DEBUG((LM_INFO
,"(%P|%t) Client IOR file was detected\n"));
109 ACE_Condition
<ACE_Mutex
> stop_condition (mutex
);
111 ACE_GUARD_RETURN (ACE_Mutex
, guard
, mutex
, -1);
113 Chatter
worker2 (orb_
.in (), ACE_TEXT("file://client.ior"), stop_condition
);
114 if (worker2
.activate (THR_NEW_LWP
| THR_JOINABLE
, 1) != 0)
116 ACE_ERROR_RETURN ((LM_ERROR
, "(%P|%t) %p\n", "Cannot activate chatty client threads"), -1);
120 stop_condition
.wait ();
121 ACE_DEBUG((LM_INFO
,"(%P|%t) So far, %d/%d requests/replies have been processed\n",
122 worker2
.nrequests (), worker2
.nreplies ()));
123 } while (worker2
.nrequests () < 1);
125 worker
.thr_mgr()->wait ();
127 root_poa
->destroy(1, 1);
131 ACE_DEBUG((LM_INFO
,"(%P|%t) Server Test %C\n",
132 (worker2
.nrequests() == worker2
.nreplies())?"succeeded":"failed"));
133 result
= (worker2
.nrequests() == worker2
.nreplies())? 0 : -1;
136 catch (const CORBA::Exception
& ex
)
138 ex
._tao_print_exception ("Error: Exception caught:");
141 ACE_OS::unlink ("server.ior");