Merge pull request #1844 from jrw972/monterey
[ACE_TAO.git] / TAO / tests / MT_Client / orb_creation.cpp
blob44ed8590e59beba872eb68aafe2be40c338bdfb1
1 #include "testC.h"
2 #include "tao/debug.h"
3 #include "ace/Get_Opt.h"
4 #include "ace/Task.h"
6 const ACE_TCHAR *ior = ACE_TEXT("file://test.ior");
7 int nthreads = 5;
8 int niterations = 5;
10 int
11 parse_args (int argc, ACE_TCHAR *argv[])
13 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("k:n:i:"));
14 int c;
16 while ((c = get_opts ()) != -1)
17 switch (c)
19 case 'k':
20 ior = get_opts.opt_arg ();
21 break;
22 case 'n':
23 nthreads = ACE_OS::atoi (get_opts.opt_arg ());
24 break;
25 case 'i':
26 niterations = ACE_OS::atoi (get_opts.opt_arg ());
27 break;
28 case '?':
29 default:
30 ACE_ERROR_RETURN ((LM_ERROR,
31 "usage: %s "
32 "-k <ior> "
33 "-n <nthreads> "
34 "-i <niterations> "
35 "\n",
36 argv [0]),
37 -1);
39 // Indicates successful parsing of the command line
40 return 0;
43 class Client : public ACE_Task_Base
45 // = TITLE
46 // Run the client thread
48 // = DESCRIPTION
49 // Use the ACE_Task_Base class to run the client threads.
51 public:
52 Client (int niterations,
53 const char* ior);
54 // ctor
56 virtual int svc (void);
57 // The thread entry point.
59 private:
60 int niterations_;
61 // The number of iterations on each client thread.
63 const char* ior_;
64 // The IOR that we should use.
67 int
68 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
70 try
72 CORBA::ORB_var orb =
73 CORBA::ORB_init (argc, argv);
75 if (parse_args (argc, argv) != 0)
76 return 1;
78 CORBA::Object_var object =
79 orb->string_to_object (ior);
81 Simple_Server_var server =
82 Simple_Server::_narrow (object.in ());
84 if (CORBA::is_nil (server.in ()))
86 ACE_ERROR_RETURN ((LM_ERROR,
87 "Object reference <%s> is nil.\n",
88 ior),
89 1);
92 Client client (niterations, ior);
93 if (client.activate (THR_NEW_LWP | THR_JOINABLE,
94 nthreads) != 0)
95 ACE_ERROR_RETURN ((LM_ERROR,
96 "Cannot activate client threads\n"),
97 1);
99 client.thr_mgr ()->wait ();
101 ACE_DEBUG ((LM_DEBUG, "threads finished\n"));
103 server->shutdown ();
105 catch (const CORBA::Exception& ex)
107 ex._tao_print_exception ("Exception caught:");
108 return 1;
111 return 0;
114 // ****************************************************************
116 Client::Client (int niterations,
117 const char* ior)
118 : niterations_ (niterations),
119 ior_ (ior)
124 Client::svc (void)
128 for (int i = 0; i < this->niterations_; ++i)
130 // If we are using a global ORB this is a nop, otherwise it
131 // initializes the ORB resources for this thread.
132 int argc = 0;
133 CORBA::String_var argv0 = CORBA::string_dup ("dummy_argv");
134 char* argv[1] = { argv0.inout () };
135 CORBA::ORB_var orb =
136 CORBA::ORB_init (argc, argv);
138 CORBA::Object_var object =
139 orb->string_to_object (this->ior_);
141 Simple_Server_var server =
142 Simple_Server::_narrow (object.in ());
144 if (CORBA::is_nil (server.in ()))
146 ACE_ERROR_RETURN ((LM_ERROR,
147 "(%P|%t) Object reference <%s> is nil\n",
148 ior),
152 server->test_method ();
153 if (TAO_debug_level > 0 && i % 100 == 0)
154 ACE_DEBUG ((LM_DEBUG, "(%P|%t) iteration = %d\n", i));
157 catch (const CORBA::Exception& ex)
159 ex._tao_print_exception ("MT_Client: exception raised");
161 return 0;