Merge pull request #2309 from mitza-oci/warnings
[ACE_TAO.git] / ACE / Kokyu / tests / EDF / test.cpp
blob46fa980f0fdfc595d05b8bf0ba4a49b9da9a9d40
1 #include "Kokyu.h"
2 #include "ace/Task.h"
3 #include "ace/Sched_Params.h"
4 #include "ace/SString.h"
5 #include "ace/Get_Opt.h"
6 #include "ace/OS_NS_strings.h"
7 #include "ace/OS_NS_sys_time.h"
8 #include <memory>
10 ACE_CString sched_policy_str = "fifo";
12 int parse_args (int argc, ACE_TCHAR *argv[]);
14 class MyCommand : public Kokyu::Dispatch_Command
16 public:
17 MyCommand(int i)
18 :Kokyu::Dispatch_Command(1),id_(i)
21 int execute();
23 private:
24 int id_;
27 int MyCommand::execute()
29 ACE_hthread_t thr_handle;
30 ACE_Thread::self (thr_handle);
31 int prio;
33 if (ACE_Thread::getprio (thr_handle, prio) == -1)
35 if (errno == ENOTSUP)
37 ACE_DEBUG((LM_DEBUG,
38 ACE_TEXT ("getprior not supported on this platform\n")
39 ));
40 return 0;
42 ACE_ERROR_RETURN ((LM_ERROR,
43 ACE_TEXT ("%p\n"),
44 ACE_TEXT ("getprio failed")),
45 -1);
48 ACE_DEBUG ((LM_DEBUG,
49 ACE_TEXT ("(%t|prio=%d) | command %d executed\n"),
50 prio, id_));
51 return 0;
54 int ACE_TMAIN (int argc, ACE_TCHAR** argv)
56 Kokyu::ConfigInfoSet config_info(3);
58 int sched_policy=ACE_SCHED_FIFO;
60 Kokyu::Dispatcher_Attributes attrs;
62 if (parse_args (argc, argv) == -1)
63 return 0;
65 if (ACE_OS::strcasecmp(sched_policy_str.c_str(), "fifo") == 0)
67 sched_policy = ACE_SCHED_FIFO;
69 else if (ACE_OS::strcasecmp(sched_policy_str.c_str(), "other") == 0)
71 sched_policy = ACE_SCHED_OTHER;
73 else if (ACE_OS::strcasecmp(sched_policy_str.c_str(), "rr") == 0)
75 sched_policy = ACE_SCHED_RR;
78 attrs.sched_policy (sched_policy);
80 Kokyu::Priority_t min_prio =
81 ACE_Sched_Params::priority_min (sched_policy);
83 config_info[0].preemption_priority_ = 1;
84 config_info[0].thread_priority_ = min_prio;
85 config_info[0].dispatching_type_ = Kokyu::DEADLINE_DISPATCHING;
87 ACE_DEBUG ((LM_DEBUG, "before create_dispatcher\n" ));
89 attrs.config_info_set_ = config_info;
90 std::unique_ptr<Kokyu::Dispatcher>
91 disp (Kokyu::Dispatcher_Factory::create_dispatcher (attrs));
93 ACE_ASSERT (disp.get() != 0);
95 MyCommand cmd1(1), cmd2(2), cmd3(3);
97 Kokyu::QoSDescriptor qos1, qos2, qos3;
99 // Get the current time.
100 ACE_Time_Value current_time = ACE_OS::gettimeofday ();
102 ACE_Time_Value deadline1, deadline2, deadline3;
104 deadline1 = current_time + ACE_Time_Value(150,0);
105 deadline2 = current_time + ACE_Time_Value(200,0);
106 deadline3 = current_time + ACE_Time_Value(100,0);
108 qos1.preemption_priority_ = 1;
109 qos1.deadline_ = deadline1;
110 qos2.preemption_priority_ = 1;
111 qos2.deadline_ = deadline2;
112 qos3.preemption_priority_ = 1;
113 qos3.deadline_ = deadline3;
115 ACE_DEBUG ((LM_DEBUG, "Deadline of command1 is %d\n",
116 qos1.deadline_.sec ()));
117 disp->dispatch (&cmd1, qos1);
119 ACE_DEBUG ((LM_DEBUG, "Deadline of command2 is %d\n",
120 qos2.deadline_.sec ()));
121 disp->dispatch (&cmd2, qos2);
123 ACE_DEBUG ((LM_DEBUG, "Deadline of command3 is %d\n",
124 qos3.deadline_.sec ()));
125 disp->dispatch (&cmd3, qos3);
127 disp->activate ();
129 disp->shutdown ();
131 ACE_DEBUG ((LM_DEBUG, "after shutdown\n"));
133 return 0;
136 int parse_args (int argc, ACE_TCHAR *argv[])
138 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("p:"));
139 int c;
141 while ((c = get_opts ()) != -1)
142 switch (c)
144 case 'p':
145 sched_policy_str = ACE_TEXT_ALWAYS_CHAR(get_opts.opt_arg ());
146 break;
148 case '?':
149 default:
150 ACE_ERROR_RETURN ((LM_ERROR,
151 "usage: %s %s"
152 "\n",
153 argv [0],
154 "-p <fifo|rr|other>"),
155 -1);
157 // Indicates successful parsing of the command line
158 return 0;