Revert "Minor modernization of DynamicAny code"
[ACE_TAO.git] / TAO / tao / Time_Policy_Manager.cpp
blob2a4e674dfdb67b9d48b1bba54b110c381c142bd2
1 #include "tao/Time_Policy_Manager.h"
2 #include "tao/ORB_Time_Policy.h"
3 #include "tao/debug.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)
17 #else
18 , time_policy_setting_ (TAO_OS_TIME_POLICY)
19 #endif
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
30 int
31 TAO_Time_Policy_Manager::init (int argc, ACE_TCHAR* argv[])
33 return this->parse_args (argc, argv);
36 /// Parse svc.conf arguments
37 int
38 TAO_Time_Policy_Manager::parse_args (int argc, ACE_TCHAR* argv[])
40 ACE_TRACE ("TAO_Time_Policy_Manager::parse_args");
42 int curarg;
44 for (curarg = 0; curarg < argc && argv[curarg]; ++curarg)
46 if (ACE_OS::strcasecmp (argv[curarg],
47 ACE_TEXT("-ORBTimePolicyStrategy")) == 0)
49 curarg++;
50 if (curarg < argc)
52 ACE_TCHAR* name = argv[curarg];
54 if (ACE_OS::strcasecmp (name,
55 ACE_TEXT("OS")) == 0)
56 this->time_policy_setting_ = TAO_OS_TIME_POLICY;
57 else if (ACE_OS::strcasecmp (name,
58 ACE_TEXT("HR")) == 0)
59 this->time_policy_setting_ = TAO_HR_TIME_POLICY;
60 else
62 this->time_policy_setting_ = TAO_DYN_TIME_POLICY;
63 this->time_policy_name_ = ACE_TEXT_ALWAYS_CHAR (name);
68 return 0;
71 ACE_Timer_Queue * TAO_Time_Policy_Manager::create_timer_queue ()
73 // locking scope
75 ACE_GUARD_RETURN (TAO_SYNCH_MUTEX,
76 monitor,
77 this->lock_,
78 nullptr);
80 // check if time policy strategy has already been initialized
81 if (this->time_policy_strategy_ == nullptr)
83 // load strategy
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 ()));
101 return nullptr;
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 ();
121 void
122 TAO_Time_Policy_Manager::destroy_timer_queue (ACE_Timer_Queue *tmq)
124 // locking scope
126 ACE_GUARD (TAO_SYNCH_MUTEX,
127 monitor,
128 this->lock_);
130 // check if time policy strategy has been initialized
131 if (this->time_policy_strategy_ == nullptr)
133 return;
137 this->time_policy_strategy_->destroy_timer_queue (tmq);
141 ACE_STATIC_SVC_DEFINE (TAO_Time_Policy_Manager,
142 ACE_TEXT ("Time_Policy_Manager"),
143 ACE_SVC_OBJ_T,
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 */