3 #include "ace/SString.h"
4 #include "ace/Get_Opt.h"
5 #include "ace/OS_NS_strings.h"
8 ACE_CString sched_policy_str
= "fifo";
10 int parse_args (int argc
, ACE_TCHAR
*argv
[]);
12 class MyCommand
: public Kokyu::Dispatch_Command
16 :Kokyu::Dispatch_Command(1),id_(i
)
25 int MyCommand::execute()
27 ACE_hthread_t thr_handle
;
28 ACE_Thread::self (thr_handle
);
31 if (ACE_Thread::getprio (thr_handle
, prio
) == -1)
36 ACE_TEXT ("getprior not supported on this platform\n")
40 ACE_ERROR_RETURN ((LM_ERROR
,
42 ACE_TEXT ("getprio failed")),
47 ACE_TEXT ("(%t|prio=%d) | command %d executed\n"),
52 int ACE_TMAIN (int argc
, ACE_TCHAR
** argv
)
54 Kokyu::ConfigInfoSet
config_info(3);
56 int hi_prio
, me_prio
, lo_prio
;
57 int sched_policy
=ACE_SCHED_FIFO
;
59 Kokyu::Dispatcher_Attributes attrs
;
61 if (parse_args (argc
, argv
) == -1)
64 if (ACE_OS::strcasecmp(sched_policy_str
.c_str(), "fifo") == 0)
66 sched_policy
= ACE_SCHED_FIFO
;
68 else if (ACE_OS::strcasecmp(sched_policy_str
.c_str(), "other") == 0)
70 sched_policy
= ACE_SCHED_OTHER
;
72 else if (ACE_OS::strcasecmp(sched_policy_str
.c_str(), "rr") == 0)
74 sched_policy
= ACE_SCHED_RR
;
77 attrs
.sched_policy (sched_policy
);
79 hi_prio
= ACE_Sched_Params::priority_max (sched_policy
);
80 me_prio
= ACE_Sched_Params::previous_priority (sched_policy
,
82 lo_prio
= ACE_Sched_Params::previous_priority (sched_policy
,
85 config_info
[0].preemption_priority_
= 1;
86 config_info
[0].thread_priority_
= hi_prio
;
87 config_info
[0].dispatching_type_
= Kokyu::FIFO_DISPATCHING
;
89 config_info
[1].preemption_priority_
= 2;
90 config_info
[1].thread_priority_
= me_prio
;
91 config_info
[1].dispatching_type_
= Kokyu::FIFO_DISPATCHING
;
93 config_info
[2].preemption_priority_
= 3;
94 config_info
[2].thread_priority_
= lo_prio
;
95 config_info
[2].dispatching_type_
= Kokyu::FIFO_DISPATCHING
;
97 attrs
.config_info_set_
= config_info
;
99 ACE_DEBUG ((LM_DEBUG
, "before create_dispatcher\n" ));
100 std::unique_ptr
<Kokyu::Dispatcher
>
101 disp (Kokyu::Dispatcher_Factory::create_dispatcher (attrs
));
103 ACE_ASSERT (disp
.get() != 0);
105 MyCommand
cmd1(1), cmd2(2), cmd3(3);
107 Kokyu::QoSDescriptor qos1
, qos2
, qos3
;
109 qos1
.preemption_priority_
= 2;
110 ACE_DEBUG ((LM_DEBUG
, "Priority of command1 is %d\n",
111 qos1
.preemption_priority_
));
113 qos2
.preemption_priority_
= 3;
114 ACE_DEBUG ((LM_DEBUG
, "Priority of command2 is %d\n",
115 qos2
.preemption_priority_
));
117 qos3
.preemption_priority_
= 1;
118 ACE_DEBUG ((LM_DEBUG
, "Priority of command3 is %d\n",
119 qos3
.preemption_priority_
));
121 if (disp
->dispatch (&cmd1
, qos1
) == -1 ||
122 disp
->dispatch (&cmd2
, qos2
) == -1 ||
123 disp
->dispatch (&cmd3
, qos3
) == -1)
124 ACE_ERROR_RETURN ((LM_ERROR
, "Error in dispatching command object\n"), -1);
126 if (disp
->activate () == -1)
128 ACE_ERROR_RETURN ((LM_ERROR
,
129 ACE_TEXT ("Error activating dispatcher. ")
130 ACE_TEXT ("You might not have superuser privileges ")
131 ACE_TEXT ("to run FIFO class. Try \"-p other\"\n")), -1);
136 ACE_DEBUG ((LM_DEBUG
, "after shutdown\n"));
140 int parse_args (int argc
, ACE_TCHAR
*argv
[])
142 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("p:"));
145 while ((c
= get_opts ()) != -1)
149 sched_policy_str
= ACE_TEXT_ALWAYS_CHAR(get_opts
.opt_arg ());
154 ACE_ERROR_RETURN ((LM_ERROR
,
158 "-p <fifo|rr|other>"),
161 // Indicates successful parsing of the command line