Merge pull request #2301 from sonndinh/remove-dup-reactor-functions
[ACE_TAO.git] / TAO / tests / SHMIOP / shmiop_test.cpp
blobff0942d6a0e9bef64c6dc756e50c05347c736ca7
1 #include "TestS.h"
3 #include "tao/Strategies/advanced_resource.h"
5 #include "ace/Get_Opt.h"
6 #include "ace/OS_NS_stdio.h"
7 #include "ace/SString.h"
8 #include "ace/Task.h"
10 struct Servant : virtual POA_Test::Hello
12 explicit Servant (const CORBA::ORB_var &orb)
13 : orb_ (orb)
16 char *get_string ()
18 CORBA::String_var str ("hello");
19 return str._retn ();
22 void shutdown ()
24 this->orb_->shutdown (false);
27 CORBA::ORB_var orb_;
30 struct ORBTask : ACE_Task_Base
32 explicit ORBTask (const CORBA::ORB_var &orb)
33 : orb_ (orb)
36 int svc ()
38 try
40 this->orb_->run ();
41 return 0;
43 catch (const CORBA::Exception &e)
45 e._tao_print_exception ("Exception caught from ORB::run:");
47 catch (...)
49 ACE_ERROR ((LM_ERROR, ACE_TEXT ("ERROR unknown exception caught ")
50 ACE_TEXT ("from ORB::run\n")));
52 return 1;
55 CORBA::ORB_var orb_;
58 int ACE_TMAIN (int argc, ACE_TCHAR *argv[])
60 try
62 CORBA::ORB_var orb = CORBA::ORB_init (argc, argv);
64 ACE_Get_Opt opts (argc, argv, ACE_TEXT ("s:c:"));
65 const ACE_TCHAR *server = 0, *client = 0;
66 for (int o; (o = opts ()) != -1;)
68 switch (o)
70 case 's':
71 server = opts.opt_arg ();
72 break;
73 case 'c':
74 client = opts.opt_arg ();
75 break;
79 Servant srv (orb);
80 ORBTask task (orb);
82 if (server)
84 CORBA::Object_var obj = orb->resolve_initial_references ("RootPOA");
85 PortableServer::POA_var poa = PortableServer::POA::_narrow (obj);
86 PortableServer::POAManager_var pm = poa->the_POAManager ();
87 pm->activate ();
88 Test::Hello_var srv_obj = srv._this ();
89 CORBA::String_var srv_str = orb->object_to_string (srv_obj);
90 FILE *f = ACE_OS::fopen (server, "w");
91 ACE_OS::fputs (srv_str, f);
92 ACE_OS::fclose (f);
93 if (!client)
94 task.activate();
97 if (client)
99 ACE_CString ior ("file://");
100 ior += ACE_TEXT_ALWAYS_CHAR (client);
101 CORBA::Object_var obj = orb->string_to_object (ior.c_str ());
102 Test::Hello_var hello = Test::Hello::_narrow (obj);
103 CORBA::String_var str = hello->get_string ();
104 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("(%P|%t) - returned <%C>\n"),
105 str.in ()));
106 hello->shutdown ();
108 else if (server)
110 task.wait ();
113 orb->destroy ();
114 return 0;
116 catch (const CORBA::Exception &e)
118 e._tao_print_exception ("Exception caught:");
120 catch (...)
122 ACE_ERROR ((LM_ERROR, ACE_TEXT ("ERROR unknown exception ")
123 ACE_TEXT ("caught in main\n")));
125 return 1;