Merge pull request #1844 from jrw972/monterey
[ACE_TAO.git] / TAO / tests / RTScheduling / Scheduling_Interceptor / test_client.cpp
blob292b1e7ba73c4173b3cc6813903afa498e52692d
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
49 orb = CORBA::ORB_init (argc, argv);
51 if (parse_args (argc, argv) == -1)
52 return (-1);
54 CORBA::Object_var manager_obj = orb->resolve_initial_references ("RTSchedulerManager");
56 TAO_RTScheduler_Manager_var manager = TAO_RTScheduler_Manager::_narrow (manager_obj.in ());
58 TAO_Scheduler* scheduler = 0;
59 ACE_NEW_RETURN (scheduler,
60 TAO_Scheduler (orb.in ()),
61 -1);
62 safe_scheduler = scheduler;
64 manager->rtscheduler (scheduler);
67 CORBA::Object_var object =
68 orb->string_to_object (ior.c_str ());
70 server = test::_narrow (object.in ());
72 if (CORBA::is_nil (server.in ()))
74 ACE_ERROR_RETURN ((LM_ERROR,
75 "ERROR: Object reference <%s> is nil\n",
76 ior.c_str ()),
77 1);
80 CORBA::Object_var current_obj = orb->resolve_initial_references ("RTScheduler_Current");
82 RTScheduling::Current_var current = RTScheduling::Current::_narrow (current_obj.in ());
84 const char * name = 0;
85 CORBA::Policy_ptr sched_param = 0;
86 CORBA::Policy_ptr implicit_sched_param = 0;
88 current->begin_scheduling_segment (name,
89 sched_param,
90 implicit_sched_param);
92 ACE_DEBUG ((LM_DEBUG,
93 "Making a one-way request\n"));
94 server->one_way (ACE_TEXT_ALWAYS_CHAR(ior.c_str ()));
96 ACE_DEBUG ((LM_DEBUG,
97 "Making a two-way request\n"));
98 server->two_way (ACE_TEXT_ALWAYS_CHAR(ior.c_str ()));
100 current->end_scheduling_segment (name);
103 catch (const CORBA::THREAD_CANCELLED& )
105 ACE_DEBUG ((LM_DEBUG,
106 "Distributable Thread Cancelled - Expected Exception\n"));
107 server->shutdown ();
109 catch (const CORBA::Exception& ex)
111 ex._tao_print_exception ("Caught exception:");
113 return 0;
116 orb->destroy ();
118 catch (const CORBA::Exception& ex)
120 ex._tao_print_exception ("Caught unexpected exception:");
122 return 1;
125 return 0;