Merge pull request #2303 from jwillemsen/jwi-803
[ACE_TAO.git] / TAO / tests / RTScheduling / Scheduling_Interceptor / test_server.cpp
blob0f42bfcc6f7e40b5a878aea003355e9a774ec1e9
1 #include "../Scheduler.h"
2 #include "tao/RTScheduling/RTScheduler_Manager.h"
3 #include "testS.h"
4 #include "ace/Get_Opt.h"
5 #include "ace/OS_NS_stdio.h"
7 const ACE_TCHAR* filename = ACE_TEXT("test.ior");
9 class test_impl : public POA_test
11 public:
12 test_impl (CORBA::ORB_ptr orb,
13 RTScheduling::Current_ptr current)
14 : orb_ (orb),
15 current_ (RTScheduling::Current::_duplicate (current))
19 virtual void one_way (const char * message)
21 ACE_DEBUG ((LM_DEBUG,
22 "One-Way Message = %s\n",
23 message));
26 virtual char * two_way (const char * message)
28 ACE_DEBUG ((LM_DEBUG,
29 "Two-Way Message = %s\n",
30 message));
32 RTScheduling::Current::IdType_var id = this->current_->id ();
33 RTScheduling::DistributableThread_var DT =
34 this->current_->lookup (id.in ());
36 DT->cancel ();
38 return CORBA::string_dup (message);
41 //FUZZ: disable check_for_lack_ACE_OS
42 virtual void shutdown ()
44 orb_->shutdown ();
46 //FUZZ: enable check_for_lack_ACE_OS
48 private:
49 CORBA::ORB_ptr orb_;
50 RTScheduling::Current_var current_;
53 int
54 parse_args (int argc,
55 ACE_TCHAR* argv [])
57 // Parse command line arguments
58 ACE_Get_Opt opts (argc, argv, ACE_TEXT("f:"));
60 int c;
61 while ((c= opts ()) != -1)
63 switch (c)
65 case 'f':
66 filename = opts.opt_arg ();
67 break;
68 default:
69 ACE_DEBUG ((LM_DEBUG, "Unknown Option\n"));
70 return -1;
73 return 0;
76 int
77 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
79 try
81 CORBA::ORB_var orb =
82 CORBA::ORB_init (argc,
83 argv);
85 parse_args (argc, argv);
87 CORBA::Object_var object =
88 orb->resolve_initial_references ("RootPOA");
90 PortableServer::POA_var root_poa =
91 PortableServer::POA::_narrow (object.in ());
93 PortableServer::POAManager_var poa_manager =
94 root_poa->the_POAManager ();
96 poa_manager->activate ();
98 CORBA::Object_var current_obj = orb->resolve_initial_references ("RTScheduler_Current");
100 RTScheduling::Current_var current = RTScheduling::Current::_narrow (current_obj.in ());
102 test_impl* test_i;
103 ACE_NEW_RETURN (test_i,
104 test_impl (orb.in (),
105 current.in ()),
106 -1);
107 PortableServer::ServantBase_var safe (test_i);
109 PortableServer::ObjectId_var id;
111 id = root_poa->activate_object (test_i);
113 CORBA::Object_var server =
114 root_poa->id_to_reference (id.in ());
116 CORBA::String_var ior;
117 if (!CORBA::is_nil (server.in ()))
119 ior = orb->object_to_string (server.in ());
121 else
123 ACE_ERROR_RETURN ((LM_ERROR,
124 "Failed to activate test object\n"),
125 -1);
128 ACE_DEBUG ((LM_DEBUG,
129 "IOR = %s\n",
130 ior.in ()));
132 CORBA::Object_var manager_obj = orb->resolve_initial_references ("RTSchedulerManager");
134 TAO_RTScheduler_Manager_var manager = TAO_RTScheduler_Manager::_narrow (manager_obj.in ());
136 TAO_Scheduler scheduler (orb.in ());
137 manager->rtscheduler (&scheduler);
139 // Print ior to the file.
140 if (filename != 0)
142 FILE* output_file = ACE_OS::fopen (filename, "w");
143 if (output_file == 0)
144 ACE_ERROR_RETURN ((LM_ERROR,
145 "Cannot open output file for writing IOR: %s",
146 filename),
147 -1);
148 ACE_OS::fprintf (output_file, "%s", ior.in ());
149 ACE_OS::fclose (output_file);
152 orb->run ();
154 orb->destroy ();
156 catch (const CORBA::Exception& ex)
158 ex._tao_print_exception ("Caught exception:");
159 return 1;
162 return 0;