Merge pull request #1844 from jrw972/monterey
[ACE_TAO.git] / TAO / tests / Strategies / client.cpp
blob1ef663928e2850989e1071688f4bc4772df829a6
1 #include "ace/Get_Opt.h"
2 #include "ace/Task.h"
3 #include "simple_testC.h"
5 const ACE_TCHAR *ior = ACE_TEXT("file://test.ior");
6 int server_shutdown = 0;
8 int
9 parse_args (int argc, ACE_TCHAR *argv[])
11 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("k:x"));
12 int c;
14 while ((c = get_opts ()) != -1)
15 switch (c)
17 case 'k':
18 ior = get_opts.opt_arg ();
19 break;
20 case 'x':
21 server_shutdown = 1;
22 break;
24 case '?':
25 default:
26 ACE_ERROR_RETURN ((LM_ERROR,
27 "usage: %s "
28 "-k <ior> "
29 "\n",
30 argv [0]),
31 -1);
33 // Indicates successful parsing of the command line
34 return 0;
37 class Client
39 // = TITLE
40 // Defines a class that is used to test and understand the
41 // different ways of loading the default and advanced TAO
42 // strategies.
44 // = DESCRIPTION
45 // A simple client which receives the CORBA boolean variabel
46 // from the server to indicate that everything went on good.
48 public:
49 Client ();
50 // ctor
54 // ****************************************************************
56 Client::Client ()
60 int
61 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
63 try
65 CORBA::ORB_var orb =
66 CORBA::ORB_init (argc, argv);
68 if (parse_args (argc, argv) != 0)
69 return 1;
71 CORBA::Object_var object =
72 orb->string_to_object (ior);
74 Simple_Server_var server =
75 Simple_Server::_narrow (object.in ());
77 if (CORBA::is_nil (server.in ()))
79 ACE_ERROR_RETURN ((LM_ERROR,
80 "Object reference <%s> is nil.\n",
81 ior),
82 1);
85 // Invoke a request on the server
86 CORBA::Boolean ret_value =
87 server->print_status ();
89 if (ret_value == 0)
91 ACE_DEBUG ((LM_DEBUG,
92 "The server has been contacted !!\n",
93 0));
96 if (server_shutdown)
98 server->shutdown ();
101 orb->destroy ();
103 catch (const CORBA::Exception& ex)
105 ex._tao_print_exception ("Caught exception:");
106 return 1;
109 return 0;