Merge pull request #2303 from jwillemsen/jwi-803
[ACE_TAO.git] / TAO / tests / RTScheduling / Scheduling_Interceptor / test_client.cpp
blob346fb25315e0e3c3c1cc1ba1d811616f91457d91
1 #include "../Scheduler.h"
2 #include "tao/RTScheduling/RTScheduler_Manager.h"
3 #include "testC.h"
4 #include "ace/Get_Opt.h"
5 #include "ace/SString.h"
7 ACE_TString ior = ACE_TEXT("file://test.ior");
9 int
10 parse_args (int argc,
11 ACE_TCHAR* argv [])
13 // Parse command line arguments
14 ACE_Get_Opt opts (argc, argv, ACE_TEXT("f:"));
16 int c;
17 while ((c= opts ()) != -1)
19 switch (c)
21 case 'f':
22 ior = ACE_TEXT("file://");
23 ior += opts.opt_arg ();
24 break;
25 default:
26 ACE_DEBUG ((LM_DEBUG, "Unknown Option\n"));
27 return -1;
30 return 0;
33 #if defined (THREAD_CANCELLED)
34 #undef THREAD_CANCELLED
35 #endif /* THREAD_CANCELLED */
37 int
38 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
40 CORBA::ORB_var orb;
41 test_var server;
42 RTScheduling::Scheduler_var safe_scheduler;
44 try
46 try
48 orb = CORBA::ORB_init (argc, argv);
50 if (parse_args (argc, argv) == -1)
51 return (-1);
53 CORBA::Object_var manager_obj = orb->resolve_initial_references ("RTSchedulerManager");
55 TAO_RTScheduler_Manager_var manager = TAO_RTScheduler_Manager::_narrow (manager_obj.in ());
57 TAO_Scheduler* scheduler = 0;
58 ACE_NEW_RETURN (scheduler,
59 TAO_Scheduler (orb.in ()),
60 -1);
61 safe_scheduler = scheduler;
63 manager->rtscheduler (scheduler);
66 CORBA::Object_var object =
67 orb->string_to_object (ior.c_str ());
69 server = test::_narrow (object.in ());
71 if (CORBA::is_nil (server.in ()))
73 ACE_ERROR_RETURN ((LM_ERROR,
74 "ERROR: Object reference <%s> is nil\n",
75 ior.c_str ()),
76 1);
79 CORBA::Object_var current_obj = orb->resolve_initial_references ("RTScheduler_Current");
81 RTScheduling::Current_var current = RTScheduling::Current::_narrow (current_obj.in ());
83 const char * name = 0;
84 CORBA::Policy_ptr sched_param = 0;
85 CORBA::Policy_ptr implicit_sched_param = 0;
87 current->begin_scheduling_segment (name,
88 sched_param,
89 implicit_sched_param);
91 ACE_DEBUG ((LM_DEBUG,
92 "Making a one-way request\n"));
93 server->one_way (ACE_TEXT_ALWAYS_CHAR(ior.c_str ()));
95 ACE_DEBUG ((LM_DEBUG,
96 "Making a two-way request\n"));
97 server->two_way (ACE_TEXT_ALWAYS_CHAR(ior.c_str ()));
99 current->end_scheduling_segment (name);
101 catch (const CORBA::THREAD_CANCELLED& )
103 ACE_DEBUG ((LM_DEBUG,
104 "Distributable Thread Cancelled - Expected Exception\n"));
105 server->shutdown ();
107 catch (const CORBA::Exception& ex)
109 ex._tao_print_exception ("Caught exception:");
111 return 0;
114 orb->destroy ();
116 catch (const CORBA::Exception& ex)
118 ex._tao_print_exception ("Caught unexpected exception:");
120 return 1;
123 return 0;