Merge pull request #2309 from mitza-oci/warnings
[ACE_TAO.git] / ACE / Kokyu / tests / FIFO / test.cpp
blobb0e5dd5f7a27f3cbdbe6fd4e778fde7460cd3ebf
1 #include "Kokyu.h"
2 #include "ace/Task.h"
3 #include "ace/SString.h"
4 #include "ace/Get_Opt.h"
5 #include "ace/OS_NS_strings.h"
6 #include <memory>
8 ACE_CString sched_policy_str = "fifo";
10 int parse_args (int argc, ACE_TCHAR *argv[]);
12 class MyCommand : public Kokyu::Dispatch_Command
14 public:
15 MyCommand(int i)
16 :Kokyu::Dispatch_Command(1),id_(i)
19 int execute ();
21 private:
22 int id_;
25 int MyCommand::execute()
27 ACE_hthread_t thr_handle;
28 ACE_Thread::self (thr_handle);
29 int prio;
31 if (ACE_Thread::getprio (thr_handle, prio) == -1)
33 if (errno == ENOTSUP)
35 ACE_DEBUG((LM_DEBUG,
36 ACE_TEXT ("getprior not supported on this platform\n")
37 ));
38 return 0;
40 ACE_ERROR_RETURN ((LM_ERROR,
41 ACE_TEXT ("%p\n"),
42 ACE_TEXT ("getprio failed")),
43 -1);
46 ACE_DEBUG ((LM_DEBUG,
47 ACE_TEXT ("(%t|prio=%d) | command %d executed\n"),
48 prio, id_));
49 return 0;
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)
62 return 0;
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,
81 hi_prio);
82 lo_prio = ACE_Sched_Params::previous_priority (sched_policy,
83 me_prio);
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);
134 disp->shutdown ();
136 ACE_DEBUG ((LM_DEBUG, "after shutdown\n"));
137 return 0;
140 int parse_args (int argc, ACE_TCHAR *argv[])
142 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("p:"));
143 int c;
145 while ((c = get_opts ()) != -1)
146 switch (c)
148 case 'p':
149 sched_policy_str = ACE_TEXT_ALWAYS_CHAR(get_opts.opt_arg ());
150 break;
152 case '?':
153 default:
154 ACE_ERROR_RETURN ((LM_ERROR,
155 "usage: %s %s"
156 "\n",
157 argv [0],
158 "-p <fifo|rr|other>"),
159 -1);
161 // Indicates successful parsing of the command line
162 return 0;