1 #include "tao/Time_Policy_Manager.h"
2 #include "tao/ORB_Time_Policy.h"
5 #include "ace/Dynamic_Service.h"
6 #include "ace/OS_NS_string.h"
7 #include "ace/OS_NS_strings.h"
9 #if (TAO_HAS_TIME_POLICY == 1)
11 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
13 TAO_Time_Policy_Manager::TAO_Time_Policy_Manager ()
14 : time_policy_strategy_ (nullptr)
15 #if defined(TAO_USE_HR_TIME_POLICY_STRATEGY)
16 , time_policy_setting_ (TAO_HR_TIME_POLICY
)
18 , time_policy_setting_ (TAO_OS_TIME_POLICY
)
23 TAO_Time_Policy_Manager::~TAO_Time_Policy_Manager ()
25 TAO::ORB_Time_Policy::reset_time_policy ();
28 // = Service Configurator hooks.
29 /// Dynamic linking hook
31 TAO_Time_Policy_Manager::init (int argc
, ACE_TCHAR
* argv
[])
33 return this->parse_args (argc
, argv
);
36 /// Parse svc.conf arguments
38 TAO_Time_Policy_Manager::parse_args (int argc
, ACE_TCHAR
* argv
[])
40 ACE_TRACE ("TAO_Time_Policy_Manager::parse_args");
44 for (curarg
= 0; curarg
< argc
&& argv
[curarg
]; ++curarg
)
46 if (ACE_OS::strcasecmp (argv
[curarg
],
47 ACE_TEXT("-ORBTimePolicyStrategy")) == 0)
52 ACE_TCHAR
* name
= argv
[curarg
];
54 if (ACE_OS::strcasecmp (name
,
56 this->time_policy_setting_
= TAO_OS_TIME_POLICY
;
57 else if (ACE_OS::strcasecmp (name
,
59 this->time_policy_setting_
= TAO_HR_TIME_POLICY
;
62 this->time_policy_setting_
= TAO_DYN_TIME_POLICY
;
63 this->time_policy_name_
= ACE_TEXT_ALWAYS_CHAR (name
);
71 ACE_Timer_Queue
* TAO_Time_Policy_Manager::create_timer_queue ()
75 ACE_GUARD_RETURN (TAO_SYNCH_MUTEX
,
80 // check if time policy strategy has already been initialized
81 if (this->time_policy_strategy_
== nullptr)
84 if (this->time_policy_setting_
== TAO_OS_TIME_POLICY
)
86 this->time_policy_name_
= "TAO_SYSTEM_TIME_POLICY";
88 else if (this->time_policy_setting_
== TAO_HR_TIME_POLICY
)
90 this->time_policy_name_
= "TAO_HR_TIME_POLICY";
92 this->time_policy_strategy_
=
93 ACE_Dynamic_Service
<TAO_Time_Policy_Strategy
>::instance (
94 this->time_policy_name_
.c_str ());
95 if (this->time_policy_strategy_
== nullptr)
97 TAOLIB_ERROR ((LM_ERROR
,
98 ACE_TEXT ("TAO (%P|%t) - TAO_Time_Policy_Manager: ")
99 ACE_TEXT ("FAILED to load time policy strategy '%C'\n"),
100 this->time_policy_name_
.c_str ()));
104 if (TAO_debug_level
> 1)
106 TAOLIB_DEBUG ((LM_INFO
,
107 ACE_TEXT ("TAO (%P|%t) - TAO_Time_Policy_Manager: ")
108 ACE_TEXT ("loaded time policy strategy '%C'\n"),
109 this->time_policy_name_
.c_str ()));
112 // handle one time initialization of ORB_Time_Policy
113 TAO::ORB_Time_Policy::set_time_policy (
114 this->time_policy_strategy_
->get_time_policy ());
118 return this->time_policy_strategy_
->create_timer_queue ();
122 TAO_Time_Policy_Manager::destroy_timer_queue (ACE_Timer_Queue
*tmq
)
126 ACE_GUARD (TAO_SYNCH_MUTEX
,
130 // check if time policy strategy has been initialized
131 if (this->time_policy_strategy_
== nullptr)
137 this->time_policy_strategy_
->destroy_timer_queue (tmq
);
141 ACE_STATIC_SVC_DEFINE (TAO_Time_Policy_Manager
,
142 ACE_TEXT ("Time_Policy_Manager"),
144 &ACE_SVC_NAME (TAO_Time_Policy_Manager
),
145 ACE_Service_Type::DELETE_THIS
|
146 ACE_Service_Type::DELETE_OBJ
,
149 ACE_FACTORY_DEFINE (TAO
, TAO_Time_Policy_Manager
)
151 TAO_END_VERSIONED_NAMESPACE_DECL
153 #endif /* TAO_HAS_TIME_POLICY */