9 #ifndef __PDG_SERVICE_H__
10 #define __PDG_SERVICE_H__
35 class PDGN_PollingClientNNG;
51 bool internal_service);
65 {
return myIsInternal; }
72 { myIsPersistent = persistent; }
74 {
return myIsPersistent; }
79 { myIsAutoStart = auto_start; }
81 {
return myIsAutoStart; }
85 { myData = new_data; }
99 { myMqLogLevel = log_level; }
101 {
return myMqLogLevel; }
105 { myMqPort = mq_port; }
112 { myClientLogDir = log_dir; }
114 {
return myClientLogDir; }
118 { myMqLogDir = log_dir; }
120 {
return myMqLogDir; }
124 { myClientLogType = log_type; }
126 {
return myClientLogType; }
132 { myEnvVarNames = env_var_names; }
134 {
return myEnvVarNames; }
140 { myEnvVarValues = env_var_values; }
142 {
return myEnvVarValues; }
146 { myExtraArguments =
args; }
148 {
return myExtraArguments; }
157 void setServiceSchedulerType(
161 void setSchedulerTypeName(
172 void clearScheduler();
177 {
return myServiceSchedulerType; }
182 {
return mySchedulerTypeName; }
187 {
return mySchedulerName; }
192 {
return mySchedulerContextName; }
197 { myServiceOwner = owner; }
199 {
return myServiceOwner; }
210 { myPoolSize = pool_size; }
212 {
return myPoolSize; }
222 { myConnectionTimeout = ms; }
224 {
return myConnectionTimeout; }
230 myMemoryResetType = memory_reset_type;
235 myMemoryLimit = memory_limit;
238 {
return myMemoryResetType; }
240 {
return myMemoryLimit; }
243 bool isStartingOrRunning()
const;
246 bool isStoppingOrStopped()
const;
249 bool isRunningOnScheduler(
314 bool ignore_stopped);
320 bool ignore_stopped);
335 bool wait_for_clients);
339 PDGN::PDGN_Message* executeWorkItem(
350 PDGN::PDGN_Message* executeWorkItem(
362 void startPollingClient(
368 void stopPollingClient(
bool wait);
375 {
return (myPollingClient !=
nullptr); }
378 PDGN::PDGN_PollingClientNNG*
380 {
return myPollingClient.get(); }
385 const char* server_address,
387 int client_num)
const;
393 const char* server_address,
395 int client_num)
const;
406 friend class PDG_ServiceScheduler;
409 enum ClientCleanupType
416 static void* runSpawnSessionService(
void*
param);
417 static void* runPollingThread(
void*
param);
418 static void* runCleanupThread(
void*
param);
420 bool getClientNameFromMessage(
421 PDGN::PDGN_Message* msg,
424 bool startSessionService(
428 bool spawnSessionServiceClients(
437 ClientCleanupType cleanup_type,
438 bool ignore_stopped);
452 ClientCleanupType cleanup_type,
453 bool stop_mq_server);
469 bool killClientProcess(
472 bool restartClientProcess(
483 static constexpr
int theMaxConcurrentStartup = 24;
484 static constexpr
int theSleepTime = 10;
485 static constexpr
int theMQSleepTime = 100;
513 PollingClientPtr myPollingClient;
525 int myConnectionTimeout;
533 myServiceSchedulerType;
exint PDG_WorkItemID
Type defs for unique work item IDs.
void setState(PDG_ServiceState state)
Sets/gets the current state of the service.
const UT_StringArray & envVarValues() const
void setOwner(PDG_ServiceOwner owner)
void setExtraArguments(const UT_StringArray &args)
Sets/gets the extra args array for the service.
void setName(const UT_StringHolder &name)
void setMqUrl(const UT_StringHolder &url)
void setMemoryLimit(exint memory_limit)
void setMqLogLevel(int log_level)
void setEnvVarNames(const UT_StringArray &env_var_names)
PDG_ServiceAcquireResult
Enumeration of return codes when acquiring a service client.
bool isPersistent() const
void setAutoStart(bool auto_start)
const UT_StringHolder & schedulerName() const
const UT_StringHolder & mqLogDir() const
void setClientLogType(PDG_ServiceLogType log_type)
Sets how the service itself should log output.
std::unique_ptr< T, Deleter > UT_UniquePtr
A smart pointer for unique ownership of dynamically allocated objects.
void setConnectionTimeout(int ms)
Sets the service connection timeout in milliseconds.
GLint GLint GLsizei GLint GLenum GLenum type
void setClientLogDir(const UT_StringHolder &log_dir)
const UT_StringArray & envVarNames() const
void setEnvVarValues(const UT_StringArray &env_var_values)
static const UT_StringHolder theEmptyString
constexpr std::enable_if< I< type_count_base< T >::value, int >::type tuple_type_size(){return subtype_count< typename std::tuple_element< I, T >::type >::value+tuple_type_size< T, I+1 >);}template< typename T > struct type_count< T, typename std::enable_if< is_tuple_like< T >::value >::type >{static constexpr int value{tuple_type_size< T, 0 >)};};template< typename T > struct subtype_count{static constexpr int value{is_mutable_container< T >::value?expected_max_vector_size:type_count< T >::value};};template< typename T, typename Enable=void > struct type_count_min{static const int value{0};};template< typename T >struct type_count_min< T, typename std::enable_if<!is_mutable_container< T >::value &&!is_tuple_like< T >::value &&!is_wrapper< T >::value &&!is_complex< T >::value &&!std::is_void< T >::value >::type >{static constexpr int value{type_count< T >::value};};template< typename T > struct type_count_min< T, typename std::enable_if< is_complex< T >::value >::type >{static constexpr int value{1};};template< typename T >struct type_count_min< T, typename std::enable_if< is_wrapper< T >::value &&!is_complex< T >::value &&!is_tuple_like< T >::value >::type >{static constexpr int value{subtype_count_min< typename T::value_type >::value};};template< typename T, std::size_t I >constexpr typename std::enable_if< I==type_count_base< T >::value, int >::type tuple_type_size_min(){return 0;}template< typename T, std::size_t I > constexpr typename std::enable_if< I< type_count_base< T >::value, int >::type tuple_type_size_min(){return subtype_count_min< typename std::tuple_element< I, T >::type >::value+tuple_type_size_min< T, I+1 >);}template< typename T > struct type_count_min< T, typename std::enable_if< is_tuple_like< T >::value >::type >{static constexpr int value{tuple_type_size_min< T, 0 >)};};template< typename T > struct subtype_count_min{static constexpr int value{is_mutable_container< T >::value?((type_count< T >::value< expected_max_vector_size)?type_count< T >::value:0):type_count_min< T >::value};};template< typename T, typename Enable=void > struct expected_count{static const int value{0};};template< typename T >struct expected_count< T, typename std::enable_if<!is_mutable_container< T >::value &&!is_wrapper< T >::value &&!std::is_void< T >::value >::type >{static constexpr int value{1};};template< typename T > struct expected_count< T, typename std::enable_if< is_mutable_container< T >::value >::type >{static constexpr int value{expected_max_vector_size};};template< typename T >struct expected_count< T, typename std::enable_if<!is_mutable_container< T >::value &&is_wrapper< T >::value >::type >{static constexpr int value{expected_count< typename T::value_type >::value};};enum class object_category:int{char_value=1, integral_value=2, unsigned_integral=4, enumeration=6, boolean_value=8, floating_point=10, number_constructible=12, double_constructible=14, integer_constructible=16, string_assignable=23, string_constructible=24, other=45, wrapper_value=50, complex_number=60, tuple_value=70, container_value=80,};template< typename T, typename Enable=void > struct classify_object{static constexpr object_category value{object_category::other};};template< typename T >struct classify_object< T, typename std::enable_if< std::is_integral< T >::value &&!std::is_same< T, char >::value &&std::is_signed< T >::value &&!is_bool< T >::value &&!std::is_enum< T >::value >::type >{static constexpr object_category value{object_category::integral_value};};template< typename T >struct classify_object< T, typename std::enable_if< std::is_integral< T >::value &&std::is_unsigned< T >::value &&!std::is_same< T, char >::value &&!is_bool< T >::value >::type >{static constexpr object_category value{object_category::unsigned_integral};};template< typename T >struct classify_object< T, typename std::enable_if< std::is_same< T, char >::value &&!std::is_enum< T >::value >::type >{static constexpr object_category value{object_category::char_value};};template< typename T > struct classify_object< T, typename std::enable_if< is_bool< T >::value >::type >{static constexpr object_category value{object_category::boolean_value};};template< typename T > struct classify_object< T, typename std::enable_if< std::is_floating_point< T >::value >::type >{static constexpr object_category value{object_category::floating_point};};template< typename T >struct classify_object< T, typename std::enable_if<!std::is_floating_point< T >::value &&!std::is_integral< T >::value &&std::is_assignable< T &, std::string >::value >::type >{static constexpr object_category value{object_category::string_assignable};};template< typename T >struct classify_object< T, typename std::enable_if<!std::is_floating_point< T >::value &&!std::is_integral< T >::value &&!std::is_assignable< T &, std::string >::value &&(type_count< T >::value==1)&&std::is_constructible< T, std::string >::value >::type >{static constexpr object_category value{object_category::string_constructible};};template< typename T > struct classify_object< T, typename std::enable_if< std::is_enum< T >::value >::type >{static constexpr object_category value{object_category::enumeration};};template< typename T > struct classify_object< T, typename std::enable_if< is_complex< T >::value >::type >{static constexpr object_category value{object_category::complex_number};};template< typename T > struct uncommon_type{using type=typename std::conditional<!std::is_floating_point< T >::value &&!std::is_integral< T >::value &&!std::is_assignable< T &, std::string >::value &&!std::is_constructible< T, std::string >::value &&!is_complex< T >::value &&!is_mutable_container< T >::value &&!std::is_enum< T >::value, std::true_type, std::false_type >::type;static constexpr bool value=type::value;};template< typename T >struct classify_object< T, typename std::enable_if<(!is_mutable_container< T >::value &&is_wrapper< T >::value &&!is_tuple_like< T >::value &&uncommon_type< T >::value)>::type >{static constexpr object_category value{object_category::wrapper_value};};template< typename T >struct classify_object< T, typename std::enable_if< uncommon_type< T >::value &&type_count< T >::value==1 &&!is_wrapper< T >::value &&is_direct_constructible< T, double >::value &&is_direct_constructible< T, int >::value >::type >{static constexpr object_category value{object_category::number_constructible};};template< typename T >struct classify_object< T, typename std::enable_if< uncommon_type< T >::value &&type_count< T >::value==1 &&!is_wrapper< T >::value &&!is_direct_constructible< T, double >::value &&is_direct_constructible< T, int >::value >::type >{static constexpr object_category value{object_category::integer_constructible};};template< typename T >struct classify_object< T, typename std::enable_if< uncommon_type< T >::value &&type_count< T >::value==1 &&!is_wrapper< T >::value &&is_direct_constructible< T, double >::value &&!is_direct_constructible< T, int >::value >::type >{static constexpr object_category value{object_category::double_constructible};};template< typename T >struct classify_object< T, typename std::enable_if< is_tuple_like< T >::value &&((type_count< T >::value >=2 &&!is_wrapper< T >::value)||(uncommon_type< T >::value &&!is_direct_constructible< T, double >::value &&!is_direct_constructible< T, int >::value)||(uncommon_type< T >::value &&type_count< T >::value >=2))>::type >{static constexpr object_category value{object_category::tuple_value};};template< typename T > struct classify_object< T, typename std::enable_if< is_mutable_container< T >::value >::type >{static constexpr object_category value{object_category::container_value};};template< typename T, enable_if_t< classify_object< T >::value==object_category::char_value, detail::enabler >=detail::dummy >constexpr const char *type_name(){return"CHAR";}template< typename T, enable_if_t< classify_object< T >::value==object_category::integral_value||classify_object< T >::value==object_category::integer_constructible, detail::enabler >=detail::dummy >constexpr const char *type_name(){return"INT";}template< typename T, enable_if_t< classify_object< T >::value==object_category::unsigned_integral, detail::enabler >=detail::dummy >constexpr const char *type_name(){return"UINT";}template< typename T, enable_if_t< classify_object< T >::value==object_category::floating_point||classify_object< T >::value==object_category::number_constructible||classify_object< T >::value==object_category::double_constructible, detail::enabler >=detail::dummy >constexpr const char *type_name(){return"FLOAT";}template< typename T, enable_if_t< classify_object< T >::value==object_category::enumeration, detail::enabler >=detail::dummy >constexpr const char *type_name(){return"ENUM";}template< typename T, enable_if_t< classify_object< T >::value==object_category::boolean_value, detail::enabler >=detail::dummy >constexpr const char *type_name(){return"BOOLEAN";}template< typename T, enable_if_t< classify_object< T >::value==object_category::complex_number, detail::enabler >=detail::dummy >constexpr const char *type_name(){return"COMPLEX";}template< typename T, enable_if_t< classify_object< T >::value >=object_category::string_assignable &&classify_object< T >::value<=object_category::other, detail::enabler >=detail::dummy >constexpr const char *type_name(){return"TEXT";}template< typename T, enable_if_t< classify_object< T >::value==object_category::tuple_value &&type_count_base< T >::value >=2, detail::enabler >=detail::dummy >std::string type_name();template< typename T, enable_if_t< classify_object< T >::value==object_category::container_value||classify_object< T >::value==object_category::wrapper_value, detail::enabler >=detail::dummy >std::string type_name();template< typename T, enable_if_t< classify_object< T >::value==object_category::tuple_value &&type_count_base< T >::value==1, detail::enabler >=detail::dummy >inline std::string type_name(){return type_name< typename std::decay< typename std::tuple_element< 0, T >::type >::type >);}template< typename T, std::size_t I >inline typename std::enable_if< I==type_count_base< T >::value, std::string >::type tuple_name(){return std::string{};}template< typename T, std::size_t I >inline typename std::enable_if<(I< type_count_base< T >::value), std::string >::type tuple_name(){auto str=std::string{type_name< typename std::decay< typename std::tuple_element< I, T >::type >::type >)}+ ','+tuple_name< T, I+1 >);if(str.back()== ',') str.pop_back();return str;}template< typename T, enable_if_t< classify_object< T >::value==object_category::tuple_value &&type_count_base< T >::value >=2, detail::enabler > > std::string type_name()
Recursively generate the tuple type name.
PDG_ServiceResetWhen
When service clients should be reset.
PDG_ServiceSchedulerType serviceSchedulerType() const
Returns the type of scheduler service in use.
void setMqPort(int mq_port)
Sets/gets the port used by the MQ relay.
PDG_ServiceResetType memoryResetType() const
GLuint const GLchar * name
void setData(const UT_OptionsHolder &new_data)
Sets/gets the custom data dictionary on the service.
const UT_OptionsHolder & data()
void setMemoryResetType(PDG_ServiceResetType memory_reset_type)
Sets the memory limit and reset type for the service.
PDGN::PDGN_PollingClientNNG * getPollingClient() const
PDG_ServiceLogType
Enumeration of service log types.
void setPersistent(bool persistent)
PDG_ServiceOwner owner() const
bool stopClient(UT_WorkBuffer &errors, const UT_StringHolder &service_name, const UT_StringHolder &client_name=UT_StringHolder::theEmptyString)
const UT_StringArray & extraArguments() const
const UT_StringHolder & schedulerTypeName() const
const UT_StringHolder & mqUrl() const
const UT_StringHolder & name() const
const UT_StringHolder & schedulerContextName() const
bool resetClient(UT_WorkBuffer &errors, const UT_StringHolder &service_name, const UT_StringHolder &client_name=UT_StringHolder::theEmptyString)
const UT_StringHolder & clientLogDir() const
PDG_ServiceOwner
Enumeration of the different types of service owner.
PDG_ServiceStartResult
Enumeration of possible result values from starting a service.
PDG_ServiceState
Enumeration of the different states that a service can be in.
bool stopService(UT_WorkBuffer &errors, const UT_StringHolder &name, bool ignore_stopped)
exint memoryLimit() const
**If you just want to fire and args
int connectionTimeout() const
bool hasPollingClient() const
Returns true if the service has an active polling client.
void setMqLogDir(const UT_StringHolder &log_dir)
Sets/gets the directory that the MQ relay writes its logs to.
void setPoolSize(int pool_size)
PDG_ServiceState state() const
PDG_ServiceLogType clientLogType() const
bool killClient(UT_WorkBuffer &errors, const UT_StringHolder &service_name, const UT_StringHolder &client_name=UT_StringHolder::theEmptyString)
void setPort(int port)
Sets/gets the connection port for the service itself.