Merge pull request #1551 from DOCGroup/plm_jira_333
[ACE_TAO.git] / TAO / examples / RTScheduling / Fixed_Priority_Scheduler / FP_Scheduler.cpp
blobf4707507c05da6802a2947c25596f53ebc2ad74e
1 #include "FP_Scheduler.h"
2 #include "ace/Atomic_Op.h"
3 #include "tao/RTScheduling/Request_Interceptor.h"
4 #include "test.h"
6 ACE_Atomic_Op<TAO_SYNCH_MUTEX, long> server_guid_counter;
8 RTCORBA::Priority
9 Segment_Sched_Param_Policy::value (void)
11 return this->value_;
14 void
15 Segment_Sched_Param_Policy::value (RTCORBA::Priority value)
17 this->value_ = value;
20 CORBA::Policy_ptr
21 Segment_Sched_Param_Policy::copy (void)
23 Segment_Sched_Param_Policy *copy = 0;
24 ACE_NEW_THROW_EX (copy,
25 Segment_Sched_Param_Policy,
26 CORBA::NO_MEMORY ());
28 copy->value (this->value_);
30 return copy;
33 CORBA::PolicyType
34 Segment_Sched_Param_Policy::policy_type (void)
36 return 0;
39 void
40 Segment_Sched_Param_Policy::destroy (void)
44 Fixed_Priority_Scheduler::Fixed_Priority_Scheduler (CORBA::ORB_ptr orb)
46 try
48 CORBA::Object_var object =
49 orb->resolve_initial_references ("RTScheduler_Current");
51 this->current_ =
52 RTScheduling::Current::_narrow (object.in ());
54 catch (const CORBA::Exception& ex)
56 ex._tao_print_exception ("Caught exception:");
60 Fixed_Priority_Scheduler::~Fixed_Priority_Scheduler (void)
64 FP_Scheduling::SegmentSchedulingParameterPolicy_ptr
65 Fixed_Priority_Scheduler::create_segment_scheduling_parameter (RTCORBA::Priority segment_priority)
67 FP_Scheduling::SegmentSchedulingParameterPolicy_ptr segment_policy;
68 ACE_NEW_THROW_EX (segment_policy,
69 Segment_Sched_Param_Policy,
70 CORBA::NO_MEMORY (
71 CORBA::SystemException::_tao_minor_code (
72 TAO::VMCID,
73 ENOMEM),
74 CORBA::COMPLETED_NO));
76 segment_policy->value (segment_priority);
78 return segment_policy;
83 void
84 Fixed_Priority_Scheduler::begin_new_scheduling_segment (const RTScheduling::Current::IdType &,
85 const char *,
86 CORBA::Policy_ptr /*sched_policy*/,
87 CORBA::Policy_ptr)
91 void
92 Fixed_Priority_Scheduler::begin_nested_scheduling_segment (const RTScheduling::Current::IdType &guid,
93 const char *name,
94 CORBA::Policy_ptr sched_param,
95 CORBA::Policy_ptr implicit_sched_param)
97 this->begin_new_scheduling_segment (guid,
98 name,
99 sched_param,
100 implicit_sched_param);
103 void
104 Fixed_Priority_Scheduler::update_scheduling_segment (const RTScheduling::Current::IdType &guid,
105 const char *name,
106 CORBA::Policy_ptr sched_param,
107 CORBA::Policy_ptr implicit_sched_param)
109 this->begin_new_scheduling_segment (guid,
110 name,
111 sched_param,
112 implicit_sched_param);
116 void
117 Fixed_Priority_Scheduler::end_scheduling_segment (const RTScheduling::Current::IdType &,
118 const char *)
122 void
123 Fixed_Priority_Scheduler::end_nested_scheduling_segment (const RTScheduling::Current::IdType &,
124 const char *,
125 CORBA::Policy_ptr)
130 void
131 Fixed_Priority_Scheduler::send_request (PortableInterceptor::ClientRequestInfo_ptr request_info)
134 int priority;
135 ACE_hthread_t current;
136 ACE_Thread::self (current);
137 if (ACE_Thread::getprio (current, priority) == -1)
138 return;
140 ACE_DEBUG ((LM_DEBUG,
141 "Request thread priority is %d %d\n",
142 priority,
143 ACE_DEFAULT_THREAD_PRIORITY));
146 RTScheduling::Current::IdType_var guid = this->current_->id ();
147 IOP::ServiceContext* srv_con = new IOP::ServiceContext;
148 srv_con->context_id = Client_Interceptor::SchedulingInfo;
149 srv_con->context_data.length (sizeof (size_t));
150 ACE_OS::memcpy (srv_con->context_data.get_buffer (),
151 guid->get_buffer (),
152 sizeof (size_t));
153 request_info->add_request_service_context (*srv_con,
158 void
159 Fixed_Priority_Scheduler::receive_request (PortableInterceptor::ServerRequestInfo_ptr request_info,
160 RTScheduling::Current::IdType_out guid_out,
161 CORBA::String_out /*name*/,
162 CORBA::Policy_out /*sched_param*/,
163 CORBA::Policy_out /*implicit_sched_param*/)
165 IOP::ServiceContext* serv_cxt =
166 request_info->get_request_service_context (Server_Interceptor::SchedulingInfo);
168 if (serv_cxt != 0)
170 size_t gu_id;
171 ACE_OS::memcpy (&gu_id,
172 serv_cxt->context_data.get_buffer (),
173 serv_cxt->context_data.length ());
175 ACE_TCHAR msg [BUFSIZ];
176 ACE_OS::sprintf (msg,
177 ACE_TEXT("The Guid is ")
178 ACE_SIZE_T_FORMAT_SPECIFIER
179 ACE_TEXT("\n"), gu_id);
181 DT_TEST::instance ()->dt_creator ()->log_msg (ACE_TEXT_ALWAYS_CHAR(msg));
183 RTScheduling::Current::IdType* guid = 0;
184 ACE_NEW (guid,
185 RTScheduling::Current::IdType);
188 // Generate GUID.
189 guid->length (sizeof(size_t));
191 ACE_OS::memcpy (guid->get_buffer (),
192 &gu_id,
193 sizeof(size_t));
195 if (TAO_debug_level > 0)
196 ACE_DEBUG ((LM_DEBUG,
197 "Receive request The Guid is %d\n",
198 gu_id));
200 guid_out.ptr () = guid;
205 void
206 Fixed_Priority_Scheduler::send_reply (PortableInterceptor::ServerRequestInfo_ptr)
210 void
211 Fixed_Priority_Scheduler::send_exception (PortableInterceptor::ServerRequestInfo_ptr)
215 void
216 Fixed_Priority_Scheduler::send_other (PortableInterceptor::ServerRequestInfo_ptr)
220 void
221 Fixed_Priority_Scheduler::send_poll (PortableInterceptor::ClientRequestInfo_ptr)
225 void
226 Fixed_Priority_Scheduler::receive_reply (PortableInterceptor::ClientRequestInfo_ptr)
230 void
231 Fixed_Priority_Scheduler::receive_exception (PortableInterceptor::ClientRequestInfo_ptr)
235 void
236 Fixed_Priority_Scheduler::receive_other (PortableInterceptor::ClientRequestInfo_ptr)
240 void
241 Fixed_Priority_Scheduler::cancel (const RTScheduling::Current::IdType &)
245 CORBA::PolicyList*
246 Fixed_Priority_Scheduler::scheduling_policies (void)
248 return 0;
251 void
252 Fixed_Priority_Scheduler::scheduling_policies (const CORBA::PolicyList &)
256 CORBA::PolicyList*
257 Fixed_Priority_Scheduler::poa_policies (void)
259 return 0;
262 char *
263 Fixed_Priority_Scheduler::scheduling_discipline_name (void)
265 return 0;
268 RTScheduling::ResourceManager_ptr
269 Fixed_Priority_Scheduler::create_resource_manager (const char *,
270 CORBA::Policy_ptr)
272 return 0;
275 void
276 Fixed_Priority_Scheduler::set_scheduling_parameter (PortableServer::Servant &,
277 const char *,
278 CORBA::Policy_ptr)