Merge pull request #2306 from mitza-oci/warnings
[ACE_TAO.git] / TAO / examples / RTScheduling / Fixed_Priority_Scheduler / FP_Scheduler.cpp
blob3cd0d02ed687da1d9a671ea7bff7f46dcb418e60
1 #include "FP_Scheduler.h"
2 #include "tao/RTScheduling/Request_Interceptor.h"
3 #include "test.h"
4 #include <atomic>
6 std::atomic<long> server_guid_counter;
8 RTCORBA::Priority
9 Segment_Sched_Param_Policy::value ()
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 ()
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 ()
36 return 0;
39 void
40 Segment_Sched_Param_Policy::destroy ()
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 ()
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;
82 void
83 Fixed_Priority_Scheduler::begin_new_scheduling_segment (const RTScheduling::Current::IdType &,
84 const char *,
85 CORBA::Policy_ptr /*sched_policy*/,
86 CORBA::Policy_ptr)
90 void
91 Fixed_Priority_Scheduler::begin_nested_scheduling_segment (const RTScheduling::Current::IdType &guid,
92 const char *name,
93 CORBA::Policy_ptr sched_param,
94 CORBA::Policy_ptr implicit_sched_param)
96 this->begin_new_scheduling_segment (guid,
97 name,
98 sched_param,
99 implicit_sched_param);
102 void
103 Fixed_Priority_Scheduler::update_scheduling_segment (const RTScheduling::Current::IdType &guid,
104 const char *name,
105 CORBA::Policy_ptr sched_param,
106 CORBA::Policy_ptr implicit_sched_param)
108 this->begin_new_scheduling_segment (guid,
109 name,
110 sched_param,
111 implicit_sched_param);
114 void
115 Fixed_Priority_Scheduler::end_scheduling_segment (const RTScheduling::Current::IdType &,
116 const char *)
120 void
121 Fixed_Priority_Scheduler::end_nested_scheduling_segment (const RTScheduling::Current::IdType &,
122 const char *,
123 CORBA::Policy_ptr)
128 void
129 Fixed_Priority_Scheduler::send_request (PortableInterceptor::ClientRequestInfo_ptr request_info)
131 int priority;
132 ACE_hthread_t current;
133 ACE_Thread::self (current);
134 if (ACE_Thread::getprio (current, priority) == -1)
135 return;
137 ACE_DEBUG ((LM_DEBUG,
138 "Request thread priority is %d %d\n",
139 priority,
140 ACE_DEFAULT_THREAD_PRIORITY));
143 RTScheduling::Current::IdType_var guid = this->current_->id ();
144 IOP::ServiceContext* srv_con = new IOP::ServiceContext;
145 srv_con->context_id = Client_Interceptor::SchedulingInfo;
146 srv_con->context_data.length (sizeof (size_t));
147 ACE_OS::memcpy (srv_con->context_data.get_buffer (),
148 guid->get_buffer (),
149 sizeof (size_t));
150 request_info->add_request_service_context (*srv_con,
154 void
155 Fixed_Priority_Scheduler::receive_request (PortableInterceptor::ServerRequestInfo_ptr request_info,
156 RTScheduling::Current::IdType_out guid_out,
157 CORBA::String_out /*name*/,
158 CORBA::Policy_out /*sched_param*/,
159 CORBA::Policy_out /*implicit_sched_param*/)
161 IOP::ServiceContext* serv_cxt =
162 request_info->get_request_service_context (Server_Interceptor::SchedulingInfo);
164 if (serv_cxt != 0)
166 size_t gu_id;
167 ACE_OS::memcpy (&gu_id,
168 serv_cxt->context_data.get_buffer (),
169 serv_cxt->context_data.length ());
171 ACE_TCHAR msg [BUFSIZ];
172 ACE_OS::sprintf (msg,
173 ACE_TEXT("The Guid is ")
174 ACE_SIZE_T_FORMAT_SPECIFIER
175 ACE_TEXT("\n"), gu_id);
177 DT_TEST::instance ()->dt_creator ()->log_msg (ACE_TEXT_ALWAYS_CHAR(msg));
179 RTScheduling::Current::IdType* guid = 0;
180 ACE_NEW (guid,
181 RTScheduling::Current::IdType);
184 // Generate GUID.
185 guid->length (sizeof(size_t));
187 ACE_OS::memcpy (guid->get_buffer (),
188 &gu_id,
189 sizeof(size_t));
191 if (TAO_debug_level > 0)
192 ACE_DEBUG ((LM_DEBUG,
193 "Receive request The Guid is %d\n",
194 gu_id));
196 guid_out.ptr () = guid;
201 void
202 Fixed_Priority_Scheduler::send_reply (PortableInterceptor::ServerRequestInfo_ptr)
206 void
207 Fixed_Priority_Scheduler::send_exception (PortableInterceptor::ServerRequestInfo_ptr)
211 void
212 Fixed_Priority_Scheduler::send_other (PortableInterceptor::ServerRequestInfo_ptr)
216 void
217 Fixed_Priority_Scheduler::send_poll (PortableInterceptor::ClientRequestInfo_ptr)
221 void
222 Fixed_Priority_Scheduler::receive_reply (PortableInterceptor::ClientRequestInfo_ptr)
226 void
227 Fixed_Priority_Scheduler::receive_exception (PortableInterceptor::ClientRequestInfo_ptr)
231 void
232 Fixed_Priority_Scheduler::receive_other (PortableInterceptor::ClientRequestInfo_ptr)
236 void
237 Fixed_Priority_Scheduler::cancel (const RTScheduling::Current::IdType &)
241 CORBA::PolicyList*
242 Fixed_Priority_Scheduler::scheduling_policies ()
244 return 0;
247 void
248 Fixed_Priority_Scheduler::scheduling_policies (const CORBA::PolicyList &)
252 CORBA::PolicyList*
253 Fixed_Priority_Scheduler::poa_policies ()
255 return 0;
258 char *
259 Fixed_Priority_Scheduler::scheduling_discipline_name ()
261 return 0;
264 RTScheduling::ResourceManager_ptr
265 Fixed_Priority_Scheduler::create_resource_manager (const char *,
266 CORBA::Policy_ptr)
268 return 0;
271 void
272 Fixed_Priority_Scheduler::set_scheduling_parameter (PortableServer::Servant &,
273 const char *,
274 CORBA::Policy_ptr)