📄 event_sup.cpp
字号:
ACE_TRY_NEW_ENV
{
Schedule_Viewer_Data **sched_data;
if ((schedule_iter.next (sched_data)) && (sched_data) && (*sched_data))
{
if ((ACE_OS::strcmp((*sched_data)->operation_name, "high_20") == 0) ||
(ACE_OS::strcmp((*sched_data)->operation_name, "low_20") == 0) ||
(ACE_OS::strcmp((*sched_data)->operation_name, "high_1") == 0) ||
(ACE_OS::strcmp((*sched_data)->operation_name, "low_1") == 0))
{
if ((ACE_OS::strcmp((*sched_data)->operation_name, "high_20") == 0) ||
(ACE_OS::strcmp((*sched_data)->operation_name, "high_1") == 0))
{
navigation_.criticality = 1;
}
else
{
navigation_.criticality = 0;
}
navigation_.position_latitude = ACE_OS::rand() % 90;
navigation_.position_longitude = ACE_OS::rand() % 180;
navigation_.altitude = ACE_OS::rand() % 100;
navigation_.heading = ACE_OS::rand() % 180;
navigation_.roll = (navigation_.roll >= 180) ? -180 : navigation_.roll + 1;
navigation_.pitch = (navigation_.pitch >= 90) ? -90 : navigation_.pitch + 1;
navigation_.utilization = (*sched_data)->utilitzation;
navigation_.overhead = (*sched_data)->overhead;
navigation_.arrival_time = (*sched_data)->arrival_time;
navigation_.deadline_time = (*sched_data)->deadline_time;
navigation_.completion_time = (*sched_data)->completion_time;
navigation_.computation_time = (*sched_data)->computation_time;
navigation_.update_data = 0;
// because the scheduler data does not supply these values
navigation_.utilization = (double) (20.0 + ACE_OS::rand() % 10);
navigation_.overhead = (double) (ACE_OS::rand() % 10);
data <<= navigation_;
}
else if ((ACE_OS::strcmp((*sched_data)->operation_name, "high_10") == 0) ||
(ACE_OS::strcmp((*sched_data)->operation_name, "low_10") == 0) ||
(ACE_OS::strcmp((*sched_data)->operation_name, "high_5") == 0) ||
(ACE_OS::strcmp((*sched_data)->operation_name, "low_5") == 0))
{
if ((ACE_OS::strcmp((*sched_data)->operation_name, "high_10") == 0) ||
(ACE_OS::strcmp((*sched_data)->operation_name, "high_5") == 0))
{
weapons_.criticality = 1;
}
else
{
weapons_.criticality = 0;
}
weapons_.number_of_weapons = 2;
weapons_.weapon1_identifier = CORBA::string_alloc (30);
ACE_OS::strcpy (weapons_.weapon1_identifier.inout (),"Photon Torpedoes");
weapons_.weapon1_status =(ACE_OS::rand() % 4) == 0 ? 0 : 1 ;
weapons_.weapon2_identifier = CORBA::string_alloc (30);
ACE_OS::strcpy (weapons_.weapon2_identifier.inout (),"Quantum Torpedoes");
weapons_.weapon2_status = (ACE_OS::rand() % 4) == 0 ? 0 : 1;
weapons_.weapon3_identifier = CORBA::string_alloc (1);
ACE_OS::strcpy (weapons_.weapon3_identifier.inout (), "");
weapons_.weapon3_status = 0;
weapons_.weapon4_identifier = CORBA::string_alloc (1);
ACE_OS::strcpy (weapons_.weapon4_identifier.inout (), "");
weapons_.weapon4_status = 0;
weapons_.weapon5_identifier = CORBA::string_alloc (1);
ACE_OS::strcpy (weapons_.weapon5_identifier.inout (), "");
weapons_.weapon5_status = 0;
weapons_.utilization = (*sched_data)->utilitzation;
weapons_.overhead = (*sched_data)->overhead;
weapons_.arrival_time = (*sched_data)->arrival_time;
weapons_.deadline_time = (*sched_data)->deadline_time;
weapons_.completion_time = (*sched_data)->completion_time;
weapons_.computation_time = (*sched_data)->computation_time;
weapons_.update_data = 0;
// because the scheduler data does not supply these values
weapons_.utilization = (double) (20.0 + ACE_OS::rand() % 10);
weapons_.overhead = (double) (ACE_OS::rand() % 10);
data <<= weapons_;
}
else {
ACE_ERROR ((LM_ERROR,
"Event_Supplier::insert_event_data:"
"unrecognized operation name [%s]",
(*sched_data)->operation_name));
}
ACE_TRY_CHECK;
if (last_completion > (*sched_data)->completion_time)
last_completion = 0;
if ((*sched_data)->completion_time >= last_completion)
{
ACE_Time_Value pause (0,
(*sched_data)->completion_time -
last_completion);
ACE_OS::sleep (pause);
last_completion = (*sched_data)->completion_time;
}
}
else
ACE_ERROR ((LM_ERROR,
"Event_Supplier::insert_event_data:"
"Could Not access scheduling data"));
schedule_iter.advance ();
if (schedule_iter.done ())
schedule_iter.first ();
}
ACE_CATCHANY
{
ACE_ERROR ((LM_ERROR,
"(%t)Error in Event_Supplier::insert_event_data.\n"));
}
ACE_ENDTRY;
}
// Function get_options.
unsigned int
Event_Supplier::get_options (int argc, char *argv [])
{
ACE_Get_Opt get_opt (argc, argv, "f:m:");
int opt;
int temp;
while ((opt = get_opt ()) != -1)
{
switch (opt)
{
case 'm':
temp = ACE_OS::atoi (get_opt.opt_arg ());
if (temp > 0)
{
this->total_messages_ = (u_int) temp;
ACE_DEBUG ((LM_DEBUG,
"Messages to send: %d\n",
this->total_messages_));
}
else
ACE_ERROR_RETURN ((LM_ERROR,
"%s: count must be > 0",
argv[0]),
1);
break;
case 'f':
this->input_file_name_ = get_opt.opt_arg ();
if (!this->input_file_name_ || ACE_OS::strlen (this->input_file_name_) > 0)
ACE_DEBUG ((LM_DEBUG,"Reading file!\n"));
else
{
this->input_file_name_ = 0;
ACE_ERROR_RETURN ((LM_ERROR,
"%s: file name must be specified with -f option",
argv[0]),
1);
}
break;
default:
case '?':
ACE_DEBUG ((LM_DEBUG,
"Usage: %s %s\n",
argv[0], usage));
ACE_OS::exit (0);
break;
}
}
if (argc != get_opt.opt_ind ())
ACE_ERROR_RETURN ((LM_ERROR,
"%s: too many arguments\n"
"Usage: %s %s\n",
argv[0],
argv[0],
usage),
1);
return 0;
}
// function main
int
main (int argc, char *argv [])
{
ACE_TRY_NEW_ENV
{
// Initialize ORB.
TAO_ORB_Manager orb_Manager;
orb_Manager.init (argc,
argv
ACE_ENV_ARG_PARAMETER);
ACE_TRY_CHECK;
// Create the demo supplier.
Event_Supplier *event_Supplier_ptr;
ACE_NEW_RETURN (event_Supplier_ptr,
Event_Supplier(argc, argv),
-1);
// Initialize everthing
if (event_Supplier_ptr->init () == -1)
exit (1);
// now we can go ahead
event_Supplier_ptr->start_generating_events ();
// when done, we clean up
delete event_Supplier_ptr;
ACE_TRY_CHECK;
}
ACE_CATCHANY
{
ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION, "SYS_EX");
}
ACE_ENDTRY;
return 0;
}
#if defined (ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION)
template class ACE_Node<Schedule_Viewer_Data *>;
template class ACE_Unbounded_Queue<Schedule_Viewer_Data *>;
template class ACE_Unbounded_Queue_Iterator<Schedule_Viewer_Data *>;
#elif defined (ACE_HAS_TEMPLATE_INSTANTIATION_PRAGMA)
#pragma instantiate ACE_Node<Schedule_Viewer_Data *>
#pragma instantiate ACE_Unbounded_Queue<Schedule_Viewer_Data *>
#pragma instantiate ACE_Unbounded_Queue_Iterator<Schedule_Viewer_Data *>
#endif /* ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -