Merge pull request #1844 from jrw972/monterey
[ACE_TAO.git] / TAO / tests / RTScheduling / Scheduling_Interceptor / test_server.cpp
blob689176c7dc210ed8aff45755bb64148a5e689f27
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:
13 test_impl (CORBA::ORB_ptr orb,
14 RTScheduling::Current_ptr current)
15 : orb_ (orb),
16 current_ (RTScheduling::Current::_duplicate (current))
20 virtual void one_way (const char * message)
22 ACE_DEBUG ((LM_DEBUG,
23 "One-Way Message = %s\n",
24 message));
27 virtual char * two_way (const char * message)
29 ACE_DEBUG ((LM_DEBUG,
30 "Two-Way Message = %s\n",
31 message));
33 RTScheduling::Current::IdType_var id = this->current_->id ();
34 RTScheduling::DistributableThread_var DT =
35 this->current_->lookup (id.in ());
37 DT->cancel ();
39 return CORBA::string_dup (message);
42 //FUZZ: disable check_for_lack_ACE_OS
43 virtual void shutdown (void)
45 orb_->shutdown ();
47 //FUZZ: enable check_for_lack_ACE_OS
49 private:
50 CORBA::ORB_ptr orb_;
51 RTScheduling::Current_var current_;
54 int
55 parse_args (int argc,
56 ACE_TCHAR* argv [])
58 // Parse command line arguments
59 ACE_Get_Opt opts (argc, argv, ACE_TEXT("f:"));
61 int c;
62 while ((c= opts ()) != -1)
64 switch (c)
66 case 'f':
67 filename = opts.opt_arg ();
68 break;
69 default:
70 ACE_DEBUG ((LM_DEBUG, "Unknown Option\n"));
71 return -1;
74 return 0;
77 int
78 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
80 try
82 CORBA::ORB_var orb =
83 CORBA::ORB_init (argc,
84 argv);
86 parse_args (argc, argv);
88 CORBA::Object_var object =
89 orb->resolve_initial_references ("RootPOA");
91 PortableServer::POA_var root_poa =
92 PortableServer::POA::_narrow (object.in ());
94 PortableServer::POAManager_var poa_manager =
95 root_poa->the_POAManager ();
97 poa_manager->activate ();
99 CORBA::Object_var current_obj = orb->resolve_initial_references ("RTScheduler_Current");
101 RTScheduling::Current_var current = RTScheduling::Current::_narrow (current_obj.in ());
103 test_impl* test_i;
104 ACE_NEW_RETURN (test_i,
105 test_impl (orb.in (),
106 current.in ()),
107 -1);
108 PortableServer::ServantBase_var safe (test_i);
110 PortableServer::ObjectId_var id;
112 id = root_poa->activate_object (test_i);
114 CORBA::Object_var server =
115 root_poa->id_to_reference (id.in ());
117 CORBA::String_var ior;
118 if (!CORBA::is_nil (server.in ()))
120 ior = orb->object_to_string (server.in ());
122 else
124 ACE_ERROR_RETURN ((LM_ERROR,
125 "Failed to activate test object\n"),
126 -1);
129 ACE_DEBUG ((LM_DEBUG,
130 "IOR = %s\n",
131 ior.in ()));
133 CORBA::Object_var manager_obj = orb->resolve_initial_references ("RTSchedulerManager");
135 TAO_RTScheduler_Manager_var manager = TAO_RTScheduler_Manager::_narrow (manager_obj.in ());
137 TAO_Scheduler scheduler (orb.in ());
138 manager->rtscheduler (&scheduler);
140 // Print ior to the file.
141 if (filename != 0)
143 FILE* output_file = ACE_OS::fopen (filename, "w");
144 if (output_file == 0)
145 ACE_ERROR_RETURN ((LM_ERROR,
146 "Cannot open output file for writing IOR: %s",
147 filename),
148 -1);
149 ACE_OS::fprintf (output_file, "%s", ior.in ());
150 ACE_OS::fclose (output_file);
153 orb->run ();
155 orb->destroy ();
157 catch (const CORBA::Exception& ex)
159 ex._tao_print_exception ("Caught exception:");
160 return 1;
163 return 0;