26 #error C++ is required
29 #include <yateclass.h>
54 explicit Configuration(
const char* filename,
bool warn =
true);
67 {
return m_sections.length(); }
73 inline unsigned int count()
const
74 {
return m_sections.count(); }
81 NamedList* getSection(
unsigned int index)
const;
105 const char* getValue(
const String& sect,
const String& key,
const char* defvalue = 0)
const;
118 int getIntValue(
const String& sect,
const String& key,
int defvalue = 0,
119 int minvalue = INT_MIN,
int maxvalue = INT_MAX,
bool clamp =
true)
const;
129 int getIntValue(
const String& sect,
const String& key,
const TokenDict* tokens,
int defvalue = 0)
const;
142 int64_t getInt64Value(
const String& sect,
const String& key, int64_t defvalue = 0,
143 int64_t minvalue = LLONG_MIN, int64_t maxvalue = LLONG_MAX,
bool clamp =
true)
const;
152 double getDoubleValue(
const String& sect,
const String& key,
double defvalue = 0.0)
const;
161 bool getBoolValue(
const String& sect,
const String& key,
bool defvalue =
false)
const;
167 void clearSection(
const char* sect = 0);
189 void addValue(
const String& sect,
const char* key,
const char* value = 0);
197 void setValue(
const String& sect,
const char* key,
const char* value = 0);
205 void setValue(
const String& sect,
const char* key,
int value);
213 void setValue(
const String& sect,
const char* key,
bool value);
220 bool load(
bool warn =
true);
231 bool loadFile(
const char* file,
String sect,
unsigned int depth,
bool warn);
246 :
Mutex(false,
"SharedVars"), m_vars(
"")
261 void set(
const String& name,
const char* val);
269 bool create(
const String& name,
const char* val = 0);
275 void clear(
const String& name);
282 bool exists(
const String& name);
290 unsigned int inc(
const String& name,
unsigned int wrap = 0);
298 unsigned int dec(
const String& name,
unsigned int wrap = 0);
304 class MessageDispatcher;
323 explicit Message(
const char* name,
const char* retval = 0,
bool broadcast =
false);
350 virtual void* getObject(
const String& name)
const;
387 {
return m_data ? m_data->getObject(name) : 0; }
396 { m_notify = notify; }
403 {
return m_broadcast; }
430 String encode(
const char*
id)
const;
438 String encode(
bool received,
const char*
id)
const;
448 int decode(
const char* str,
String&
id);
459 int decode(
const char* str,
bool& received,
const char*
id);
468 virtual void dispatched(
bool accepted);
478 void commonEncode(
String& str)
const;
479 int commonDecode(
const char* str,
int offs);
500 explicit MessageHandler(
const char* name,
unsigned priority = 100,
501 const char* trackName = 0,
bool addPriority =
true);
518 virtual bool received(
Message& msg) = 0;
525 {
return m_priority; }
532 {
return m_trackName; }
540 {
if (!m_dispatcher) m_trackName = name; }
547 {
return m_counter; }
567 inline void setFilter(
const char* name,
const char* value)
587 virtual bool receivedInternal(
Message& msg);
592 void safeNowInternal();
616 virtual bool received(
Message& msg,
int id) = 0;
637 int priority = 100,
const char* trackName = 0,
bool addPriority =
true)
639 m_receiver(receiver), m_id(id)
649 {
return m_receiver && m_receiver->received(msg,m_id); }
655 inline int id()
const
663 virtual bool receivedInternal(
Message& msg);
689 virtual void dispatched(
const Message& msg,
bool handled) = 0;
729 {
return m_trackParam; }
784 { m_warnTime = usec; }
790 { m_handlers.clear(); m_hookAppend = &m_hooks; m_hooks.clear(); }
796 unsigned int messageCount();
802 unsigned int handlerCount();
808 unsigned int postHookCount();
815 {
return m_enqueueCount; }
822 {
return m_dequeueCount; }
829 {
return m_dispatchCount; }
836 {
return m_queuedMax; }
844 {
return usec ? m_msgAvgAge : ((m_msgAvgAge + 500) / 1000); }
853 void getStats(u_int64_t& enqueued, u_int64_t& dequeued, u_int64_t& dispatched, u_int64_t& queueMax);
868 { m_trackParam = paramName; }
878 unsigned int m_changes;
879 u_int64_t m_warnTime;
880 u_int64_t m_enqueueCount;
881 u_int64_t m_dequeueCount;
882 u_int64_t m_dispatchCount;
883 u_int64_t m_queuedMax;
884 u_int64_t m_msgAvgAge;
901 virtual bool enqueue(
Message* msg) = 0;
906 virtual void clear() = 0;
913 virtual bool matchesFilter(
const Message& msg) = 0;
943 virtual bool enqueue(
Message* msg);
956 void addFilter(
const char* name,
const char* value);
962 void removeFilter(
const String& name);
967 virtual void clear();
973 void removeThread(
Thread* thread);
987 {
return m_filters; }
994 virtual bool matchesFilter(
const Message& msg);
1002 virtual void received(
Message& msg);
1009 unsigned int m_count;
1031 explicit Plugin(
const char* name,
bool earlyInit =
false);
1052 virtual void* getObject(
const String& name)
const;
1057 virtual void initialize() = 0;
1078 {
return m_counter; }
1109 #define INIT_PLUGIN(pclass) static pclass __plugin
1110 #ifdef DISABLE_UNLOAD
1111 #define UNLOAD_PLUGIN(arg) static bool _unused_unload(bool arg)
1114 #define UNLOAD_PLUGIN(arg) extern "C" __declspec(dllexport) bool _unload(bool arg)
1116 #define UNLOAD_PLUGIN(arg) extern "C" bool _unload(bool arg)
1141 virtual bool check(
const ObjList* cmds) = 0;
1163 friend class EnginePrivate;
1164 friend class EngineCommand;
1207 static int main(
int argc,
const char** argv,
const char** env,
1208 RunMode mode = Console,
EngineLoop loop = 0,
bool fail =
false);
1215 static void help(
bool client,
bool errout =
false);
1227 int engineCleanup();
1253 return (s_congestion && (s_accept < Congestion)) ? Congestion : s_accept;
1269 return s_callAccept;
1276 static void setCongestion(
const char* reason = 0);
1283 {
return s_congestion; }
1290 {
return (s_mode ==
Client) || (s_mode == ClientProxy); }
1298 static bool Register(
const Plugin* plugin,
bool reg =
true);
1312 {
return s_shrpath; }
1320 static String configFile(
const char* name,
bool user =
false);
1327 static const String& configPath(
bool user =
false);
1334 {
return s_cfgsuffix; }
1340 {
return s_modpath; }
1347 static void extraPath(
const String& path);
1355 static void userPath(
const String& path);
1362 {
return s_modsuffix; }
1368 static const char* pathSeparator();
1383 static unsigned int runId();
1390 {
return s_params; }
1402 static bool init(
const String& name);
1408 static void halt(
unsigned int code);
1416 static bool restart(
unsigned int code,
bool gracefull =
false);
1423 {
return s_started; }
1430 {
return (s_haltcode != -1); }
1452 static bool enqueue(
Message* msg,
bool skipHooks =
false);
1461 inline static bool enqueue(
const char* name,
bool broadcast =
false)
1462 {
return name && *name && enqueue(
new Message(name,0,broadcast)); }
1469 static bool dispatch(
Message* msg);
1476 static bool dispatch(
Message& msg);
1485 static bool dispatch(
const char* name,
bool broadcast =
false);
1493 { m_dispatcher.setHook(hook,
remove); }
1500 {
return s_self ? s_self->m_dispatcher.trackParam() :
String::empty(); }
1526 {
return m_dispatcher.messageCount(); }
1533 {
return m_dispatcher.handlerCount(); }
1540 {
return m_dispatcher.postHookCount(); }
1547 {
return m_messageRate; }
1554 {
return m_maxMsgRate; }
1562 {
return (
unsigned int)m_dispatcher.messageAge(usec); }
1571 inline void getStats(u_int64_t& enqueued, u_int64_t& dequeued, u_int64_t& dispatched, u_int64_t& queueMax)
1572 { m_dispatcher.getStats(enqueued,dequeued,dispatched,queueMax); }
1579 bool loadPluginDir(
const String& relPath);
1585 static void pluginMode(PluginMode mode);
1598 static void clearEvents(
const String& type);
1612 static void buildCmdLine(
String& line);
1622 static void initLibrary(
const String& line,
String* output = 0);
1629 static int cleanupLibrary();
1645 bool loadPlugin(
const char* file,
bool local =
false,
bool nounload =
false);
1659 void internalStatisticsStart();
1660 void tryPluginFile(
const String& name,
const String& path,
bool defload);
1663 uint64_t m_dispatchedLast;
1664 unsigned int m_messageRate;
1665 unsigned int m_maxMsgRate;
1666 bool m_rateCongested;
1667 bool m_queueCongested;
1668 bool m_ageCongested;
1672 static String s_cfgsuffix;
1674 static String s_modsuffix;
1677 static int s_haltcode;
1678 static RunMode s_mode;
1679 static bool s_started;
1680 static unsigned int s_congestion;
1681 static CallAccept s_accept;
unsigned int messageAge(bool usec=false) const
Definition: yatengine.h:1561
virtual bool received(Message &msg)
Definition: yatengine.h:648
static bool enqueue(const char *name, bool broadcast=false)
Definition: yatengine.h:1461
unsigned int messageMaxRate() const
Definition: yatengine.h:1553
static RunMode mode()
Definition: yatengine.h:1245
Engine checker interface.
Definition: yatengine.h:1126
Post-dispatching message hook that can be added to a list.
Definition: yatengine.h:698
Definition: yateclass.h:949
u_int64_t enqueueCount() const
Definition: yatengine.h:814
Post-dispatching message hook.
Definition: yatengine.h:676
unsigned int messageRate() const
Definition: yatengine.h:1546
unsigned int count() const
Definition: yatengine.h:979
Thread support class.
Definition: yateclass.h:5529
const String & trackParam() const
Definition: yatengine.h:728
unsigned priority() const
Definition: yatengine.h:524
String & retValue()
Definition: yatengine.h:356
static const String & nodeName()
Definition: yatengine.h:1304
static CallAccept accept()
Definition: yatengine.h:1252
const Time & msgTime() const
Definition: yatengine.h:416
void * userObject(const String &name) const
Definition: yatengine.h:386
unsigned int postHookCount()
Definition: yatengine.h:1539
static const TokenDict * getCallAcceptStates()
Definition: yatengine.h:1268
Configuration file handling.
Definition: yatengine.h:40
NamedCounter * objectsCounter() const
Definition: yatengine.h:546
unsigned int sections() const
Definition: yatengine.h:66
A multiple message receiver.
Definition: yatengine.h:607
MessageRelay(const char *name, MessageReceiver *receiver, int id, int priority=100, const char *trackName=0, bool addPriority=true)
Definition: yatengine.h:636
int(* EngineLoop)()
Definition: yatengine.h:1153
static void setAccept(CallAccept ca)
Definition: yatengine.h:1260
A message dispatching hub.
Definition: yatengine.h:708
A message handler relay.
Definition: yatengine.h:623
static const String & sharedPath()
Definition: yatengine.h:1311
Configuration & operator=(const String &value)
Definition: yatengine.h:59
Time & msgTime()
Definition: yatengine.h:409
void warnTime(u_int64_t usec)
Definition: yatengine.h:783
int id() const
Definition: yatengine.h:655
String & operator=(const String &value)
Definition: yateclass.h:2225
PluginMode
Definition: yatengine.h:1191
A message queue.
Definition: yatengine.h:922
void destruct(GenObject *obj)
Definition: yateclass.h:933
static bool exiting()
Definition: yatengine.h:1429
static const String & configSuffix()
Definition: yatengine.h:1333
static const NamedList & runParams()
Definition: yatengine.h:1389
static const String & trackParam()
Definition: yatengine.h:1499
A time holding class.
Definition: yateclass.h:3536
const String & retValue() const
Definition: yatengine.h:363
A holder for a debug level.
Definition: yateclass.h:309
A message container class.
Definition: yatengine.h:312
static const String & modulePath()
Definition: yatengine.h:1339
void getStats(u_int64_t &enqueued, u_int64_t &dequeued, u_int64_t &dispatched, u_int64_t &queueMax)
Definition: yatengine.h:1571
Atomic access and operations to shared variables.
Definition: yatengine.h:239
void setHook(MessagePostHook *hook, bool remove=false)
Definition: yatengine.h:1492
u_int64_t messageAge(bool usec=false) const
Definition: yatengine.h:843
RefObject * userData() const
Definition: yatengine.h:370
static bool clientMode()
Definition: yatengine.h:1289
virtual const String & toString() const
Definition: yatengine.h:1044
void setFilter(const char *name, const char *value)
Definition: yatengine.h:567
A named string class.
Definition: yateclass.h:3111
unsigned int handlerCount()
Definition: yatengine.h:1532
const NamedString * filter() const
Definition: yatengine.h:552
void trackParam(const char *paramName)
Definition: yatengine.h:867
u_int64_t queuedMax() const
Definition: yatengine.h:835
SharedVars()
Definition: yatengine.h:245
A named string container class.
Definition: yateclass.h:4553
void INIT_PLUGIN(class pclass)
A message handler.
Definition: yatengine.h:488
u_int64_t dequeueCount() const
Definition: yatengine.h:821
void clear()
Definition: yatengine.h:789
unsigned int count() const
Definition: yatengine.h:73
u_int64_t dispatchCount() const
Definition: yatengine.h:828
Definition: yateclass.h:217
bool broadcast() const
Definition: yatengine.h:402
A C-style string handling class.
Definition: yateclass.h:1832
Definition: yateclass.h:683
void setNotify(bool notify=true)
Definition: yatengine.h:395
const String & name() const
Definition: yatengine.h:1070
static const String & moduleSuffix()
Definition: yatengine.h:1361
An object list class.
Definition: yateclass.h:1229
bool UNLOAD_PLUGIN(bool unloadNow)
static unsigned int getCongestion()
Definition: yatengine.h:1282
const NamedList & getFilters() const
Definition: yatengine.h:986
static const String & empty()
virtual bool isBusy() const
Definition: yatengine.h:1063
const String & trackName() const
Definition: yatengine.h:531
Message & operator=(const char *value)
Definition: yatengine.h:422
Plugin support.
Definition: yatengine.h:1023
RunMode
Definition: yatengine.h:1170
Mutex support.
Definition: yateclass.h:5131
Engine globals.
Definition: yatengine.h:1161
Definition: yateclass.h:830
void trackName(const char *name)
Definition: yatengine.h:539
static bool started()
Definition: yatengine.h:1422
unsigned int messageCount()
Definition: yatengine.h:1525
virtual ~EngineCheck()
Definition: yatengine.h:1132
bool earlyInit() const
Definition: yatengine.h:1084
Abstract message hook.
Definition: yatengine.h:893
NamedCounter * objectsCounter() const
Definition: yatengine.h:1077
Class that runs the User Interface.
Definition: yatecbase.h:993
Atomic counter with name.
Definition: yateclass.h:3232