Yate
yatengine.h
1
22#ifndef __YATENGINE_H
23#define __YATENGINE_H
24
25#ifndef __cplusplus
26#error C++ is required
27#endif
28
29#include <yateclass.h>
30
34namespace TelEngine {
35
40class YATE_API Configuration : public String
41{
42 friend class Engine;
43 YNOCOPY(Configuration); // no automatic copies please
44public:
49
55 explicit Configuration(const char* filename, bool warn = true);
56
60 inline Configuration& operator=(const String& value)
61 { String::operator=(value); return *this; }
62
67 inline unsigned int sections() const
68 { return m_sections.length(); }
69
74 inline unsigned int count() const
75 { return m_sections.count(); }
76
82 NamedList* getSection(unsigned int index) const;
83
89 NamedList* getSection(const String& sect) const;
90
97 NamedString* getKey(const String& sect, const String& key) const;
98
106 const char* getValue(const String& sect, const String& key, const char* defvalue = 0) const;
107
119 int getIntValue(const String& sect, const String& key, int defvalue = 0,
120 int minvalue = INT_MIN, int maxvalue = INT_MAX, bool clamp = true) const;
121
130 int getIntValue(const String& sect, const String& key, const TokenDict* tokens, int defvalue = 0) const;
131
143 int64_t getInt64Value(const String& sect, const String& key, int64_t defvalue = 0,
144 int64_t minvalue = LLONG_MIN, int64_t maxvalue = LLONG_MAX, bool clamp = true) const;
145
153 double getDoubleValue(const String& sect, const String& key, double defvalue = 0.0) const;
154
162 bool getBoolValue(const String& sect, const String& key, bool defvalue = false) const;
163
168 void clearSection(const char* sect = 0);
169
176
182 void clearKey(const String& sect, const String& key);
183
190 void addValue(const String& sect, const char* key, const char* value = 0);
191
198 void setValue(const String& sect, const char* key, const char* value = 0);
199
206 void setValue(const String& sect, const char* key, int value);
207
214 void setValue(const String& sect, const char* key, bool value);
215
221 bool load(bool warn = true);
222
227 bool save() const;
228
229private:
235 inline bool loadMain(bool warn = true) {
236 m_main = true;
237 return load(warn);
238 }
239
240 ObjList *getSectHolder(const String& sect) const;
241 ObjList *makeSectHolder(const String& sect);
242 bool loadFile(const char* file, String sect, unsigned int depth, bool warn, void* priv);
243 ObjList m_sections;
244 bool m_main;
245};
246
251class YATE_API SharedVars : public Mutex, public RefObject
252{
253public:
258 inline SharedVars(const char* name = 0)
259 : Mutex(false,"SharedVars"), m_vars(name)
260 { }
261
267 void get(const String& name, String& rval);
268
274 void set(const String& name, const char* val);
275
282 bool create(const String& name, const char* val = 0);
283
288 void clear(const String& name);
289
293 void clearAll();
294
300 bool exists(const String& name);
301
308 uint64_t inc(const String& name, uint64_t wrap = 0);
309
316 uint64_t dec(const String& name, uint64_t wrap = 0);
317
325 uint64_t add(const String& name, uint64_t val, uint64_t wrap = 0);
326
334 uint64_t sub(const String& name, uint64_t val, uint64_t wrap = 0);
335
343 inline void copy(NamedList& dest, const String& prefix = String::empty(),
344 bool skipPrefix = true, bool replace = false) {
345 Lock lck(this);
346 if (prefix)
347 dest.copySubParams(m_vars,prefix,skipPrefix,replace);
348 else
349 dest.copyParams(m_vars);
350 }
351
356 virtual const String& toString() const
357 { return m_vars; }
358
365 static bool getList(RefPointer<SharedVars>& dest, const String& name);
366
367private:
368 NamedList m_vars;
369};
370
372class MessageRelay;
373class Engine;
374
379class YATE_API Message : public NamedList
380{
381 friend class MessageDispatcher;
382public:
390 explicit Message(const char* name, const char* retval = 0, bool broadcast = false);
391
397 Message(const Message& original);
398
405 Message(const Message& original, bool broadcast);
406
411
417 virtual void* getObject(const String& name) const;
418
423 inline String& retValue()
424 { return m_return; }
425
430 inline const String& retValue() const
431 { return m_return; }
432
437 inline RefObject* userData() const
438 { return m_data; }
439
446 void userData(RefObject* data);
447
453 inline void* userObject(const String& name) const
454 { return m_data ? m_data->getObject(name) : 0; }
455
456
462 inline void setNotify(bool notify = true)
463 { m_notify = notify; }
464
469 inline bool broadcast() const
470 { return m_broadcast; }
471
477 void resetMsg(Time tm = Time::now());
478
483 inline Time& msgTime()
484 { return m_time; }
485
490 inline const Time& msgTime() const
491 { return m_time; }
492
499 { return m_timeEnqueue; }
500
506 inline const Time& msgTimeEnqueue() const
507 { return m_timeEnqueue; }
508
515 { return m_timeDispatch; }
516
522 inline const Time& msgTimeDispatch() const
523 { return m_timeDispatch; }
524
528 inline Message& operator=(const char* value)
529 { String::operator=(value); return *this; }
530
536 String encode(const char* id) const;
537
544 String encode(bool received, const char* id) const;
545
554 int decode(const char* str, String& id);
555
565 int decode(const char* str, bool& received, const char* id);
566
567protected:
574 virtual void dispatched(bool accepted);
575
576private:
577 Message(); // no default constructor please
578 Message& operator=(const Message& value); // no assignment please
579 String m_return;
580 Time m_time;
581 Time m_timeEnqueue;
582 Time m_timeDispatch;
583 RefObject* m_data;
584 bool m_notify;
585 bool m_broadcast;
586 void commonEncode(String& str) const;
587 int commonDecode(const char* str, int offs);
588};
589
594class YATE_API MessageFilter
595{
596public:
601 : m_filter(0), m_msgFilter(0)
602 {}
603
608 { set(m_filter); set(m_msgFilter); }
609
614 inline bool matchesMsg(const Message& msg) const {
615 return (!m_msgFilter || m_msgFilter->matchString(msg))
616 && (!m_filter || m_filter->matchListParam(msg));
617 }
618
623 inline const MatchingItemBase* getFilter() const
624 { return m_filter; }
625
630 inline const MatchingItemBase* getMsgFilter() const
631 { return m_msgFilter; }
632
638 inline void setFilter(MatchingItemBase* filter)
639 { set(m_filter,filter); }
640
646 inline void setMsgFilter(MatchingItemBase* filter)
647 { set(m_msgFilter,filter); }
648
652 inline void clearFilter()
653 { set(m_filter); }
654
658 inline void clearMsgFilter()
659 { set(m_msgFilter); }
660
666 void setFilter(NamedString* filter);
667
673 inline void setFilter(const char* name, const char* value)
674 { setFilter(new MatchingItemString(name,value)); }
675
676private:
677 void set(MatchingItemBase*& dest, MatchingItemBase* src = 0);
678
679 MatchingItemBase* m_filter;
680 MatchingItemBase* m_msgFilter;
681};
682
689class YATE_API MessageHandler : public String, public MessageFilter
690{
691 friend class MessageDispatcher;
692 YNOCOPY(MessageHandler); // no automatic copies please
693public:
701 explicit MessageHandler(const char* name, unsigned priority = 100,
702 const char* trackName = 0, bool addPriority = true);
703
708
712 virtual void destruct();
713
719 virtual bool received(Message& msg) = 0;
720
725 inline unsigned priority() const
726 { return m_priority; }
727
732 inline const String& trackName() const
733 { return m_trackName; }
734
739 inline const String& trackNameOnly() const
740 { return m_trackNameOnly; }
741
747 inline void trackName(const char* name) {
748 if (m_dispatcher)
749 return;
750 m_trackName = name;
751 String tmp;
752 tmp << ':' << priority();
753 if (m_trackName.endsWith(tmp))
754 m_trackNameOnly = m_trackName.substr(0,m_trackName.length() - tmp.length());
755 else
756 m_trackNameOnly = m_trackName;
757 }
758
764 { return m_counter; }
765
770 inline const MatchingItemBase* filter() const
771 { return getFilter(); }
772
773protected:
778 void cleanup();
779
785 virtual bool receivedInternal(Message& msg);
786
791
792private:
793 String m_trackName;
794 String m_trackNameOnly;
795 unsigned m_priority;
796 AtomicInt m_unsafe;
797 MessageDispatcher* m_dispatcher;
798 NamedCounter* m_counter;
799};
800
805class YATE_API MessageReceiver : public GenObject
806{
807public:
814 virtual bool received(Message& msg, int id) = 0;
815};
816
821class YATE_API MessageRelay : public MessageHandler
822{
823 YNOCOPY(MessageRelay); // no automatic copies please
824public:
834 inline MessageRelay(const char* name, MessageReceiver* receiver, int id,
835 int priority = 100, const char* trackName = 0, bool addPriority = true)
836 : MessageHandler(name,priority,trackName,addPriority),
837 m_receiver(receiver), m_id(id)
838 { }
839
846 virtual bool received(Message& msg)
847 { return m_receiver && m_receiver->received(msg,m_id); }
848
853 inline int id() const
854 { return m_id; }
855
861 virtual bool receivedInternal(Message& msg);
862
863private:
864 MessageReceiver* m_receiver;
865 int m_id;
866};
867
874class YATE_API MessageNotifier
875{
876public:
881
887 virtual void dispatched(const Message& msg, bool handled) = 0;
888};
889
896class YATE_API MessagePostHook : public RefObject, public MessageNotifier, public MessageFilter
897{
898};
899
906class YATE_API MessageDispatcher : public GenObject
907{
908 friend class Engine;
909 YNOCOPY(MessageDispatcher); // no automatic copies please
910public:
915 MessageDispatcher(const char* trackParam = 0);
916
921
926 inline const String& trackParam() const
927 { return m_trackParam; }
928
937 bool install(MessageHandler* handler);
938
944 bool uninstall(MessageHandler* handler);
945
957 bool dispatch(Message& msg);
958
964 bool enqueue(Message* msg);
965
969 void dequeue();
970
976
981 inline void warnTime(u_int64_t usec)
982 { m_warnTime = usec; }
983
988 inline void traceTime(bool on = false)
989 { m_traceTime = on; }
990
995 inline void traceHandlerTime(bool on = false)
996 { m_traceHandlerTime = on; }
997
1001 void clear();
1002
1007 inline bool hasMessages() const
1008 { return m_messages.get() || m_messages.next(); }
1009
1014 inline bool hasHandlers() const
1015 { return m_handlers.get() || m_handlers.next(); }
1016
1021 inline bool hasHooks() const
1022 { return m_hooks.get() || m_hooks.next(); }
1023
1028 unsigned int messageCount();
1029
1034 unsigned int handlerCount();
1035
1040 unsigned int postHookCount();
1041
1046 u_int64_t enqueueCount() const
1047 { return m_enqueueCount; }
1048
1053 u_int64_t dequeueCount() const
1054 { return m_dequeueCount; }
1055
1060 u_int64_t dispatchCount() const
1061 { return m_dispatchCount; }
1062
1067 u_int64_t queuedMax() const
1068 { return m_queuedMax; }
1069
1075 u_int64_t messageAge(bool usec = false) const
1076 { return usec ? m_msgAvgAge : ((m_msgAvgAge + 500) / 1000); }
1077
1083 { return m_handlersLock; }
1084
1092 void getStats(u_int64_t& enqueued, u_int64_t& dequeued, u_int64_t& dispatched, u_int64_t& queueMax);
1093
1100 bool setHook(MessagePostHook* hook, bool remove = false);
1101
1110 unsigned int fillHandlersInfo(bool matchName, const String& match, String* details = 0,
1111 unsigned int* total = 0);
1112
1113protected:
1118 inline void trackParam(const char* paramName)
1119 { m_trackParam = paramName; }
1120
1121private:
1122 ObjList m_handlers;
1123 ObjList m_messages;
1124 ObjList m_hooks;
1125 RWLock m_handlersLock;
1126 RWLock m_messagesLock;
1127 RWLock m_hooksLock;
1128 ObjList* m_msgAppend;
1129 ObjList* m_hookAppend;
1130 String m_trackParam;
1131 unsigned int m_changes;
1132 u_int64_t m_warnTime;
1133 u_int64_t m_enqueueCount;
1134 u_int64_t m_dequeueCount;
1135 u_int64_t m_dispatchCount;
1136 u_int64_t m_queuedMax;
1137 u_int64_t m_msgAvgAge;
1138 bool m_traceTime;
1139 bool m_traceHandlerTime;
1140 int m_hookCount;
1141 bool m_hookHole;
1142};
1143
1148class YATE_API MessageHook : public RefObject
1149{
1150public:
1156 virtual bool enqueue(Message* msg) = 0;
1157
1161 virtual void clear() = 0;
1162
1168 virtual bool matchesFilter(const Message& msg) = 0;
1169};
1170
1171
1177class YATE_API MessageQueue : public MessageHook, public Mutex
1178{
1179 friend class Engine;
1180public:
1186 MessageQueue(const char* hookName, int numWorkers = 0);
1187
1192
1198 virtual bool enqueue(Message* msg);
1199
1204 bool dequeue();
1205
1211 void addFilter(const char* name, const char* value);
1212
1217 void removeFilter(const String& name);
1218
1222 virtual void clear();
1223
1228 void removeThread(Thread* thread);
1229
1234 inline unsigned int count() const
1235 { return m_count; }
1236
1241 inline const NamedList& getFilters() const
1242 { return m_filters; }
1243
1249 virtual bool matchesFilter(const Message& msg);
1250protected:
1251
1257 virtual void received(Message& msg);
1258
1259private:
1260 NamedList m_filters;
1261 ObjList m_messages;
1262 ObjList m_workers;
1263 ObjList* m_append;
1264 unsigned int m_count;
1265};
1266
1267
1278class YATE_API Plugin : public GenObject, public DebugEnabler
1279{
1280public:
1286 explicit Plugin(const char* name, bool earlyInit = false);
1287
1293 virtual ~Plugin();
1294
1299 virtual const String& toString() const
1300 { return m_name; }
1301
1307 virtual void* getObject(const String& name) const;
1308
1312 virtual void initialize() = 0;
1313
1318 virtual bool isBusy() const
1319 { return false; }
1320
1325 inline const String& name() const
1326 { return m_name; }
1327
1333 { return m_counter; }
1334
1339 bool earlyInit() const
1340 { return m_early; }
1341
1342private:
1343 Plugin(); // no default constructor please
1344 String m_name;
1345 NamedCounter* m_counter;
1346 bool m_early;
1347};
1348
1349#if 0 /* for documentation generator */
1354void INIT_PLUGIN(class pclass);
1355
1361bool UNLOAD_PLUGIN(bool unloadNow);
1362#endif
1363
1364#define INIT_PLUGIN(pclass) static pclass __plugin
1365#ifdef DISABLE_UNLOAD
1366#define UNLOAD_PLUGIN(arg) static bool _unused_unload(bool arg)
1367#else
1368#ifdef _WINDOWS
1369#define UNLOAD_PLUGIN(arg) extern "C" __declspec(dllexport) bool _unload(bool arg)
1370#else
1371#define UNLOAD_PLUGIN(arg) extern "C" bool _unload(bool arg)
1372#endif
1373#endif
1374
1381class YATE_API EngineCheck
1382{
1383public:
1388 { }
1389
1396 virtual bool check(const ObjList* cmds) = 0;
1397
1402 static void setChecker(EngineCheck* ptr = 0);
1403};
1404
1408typedef int (*EngineLoop)();
1409
1416class YATE_API Engine
1417{
1418 friend class EnginePrivate;
1419 friend class EngineCommand;
1420 YNOCOPY(Engine); // no automatic copies please
1421public:
1425 enum RunMode {
1426 Stopped = 0,
1427 Console = 1,
1428 Server = 2,
1429 Client = 3,
1430 ClientProxy = 4,
1431 };
1432
1433 enum CallAccept {
1434 Accept = 0,
1435 Partial = 1,
1436 Congestion = 2,
1437 Reject = 3,
1438 };
1439
1447 LoadFail = 0,
1448 LoadLate,
1449 LoadEarly
1450 };
1451
1462 static int main(int argc, const char** argv, const char** env,
1463 RunMode mode = Console, EngineLoop loop = 0, bool fail = false);
1464
1470 static void help(bool client, bool errout = false);
1471
1477
1483
1488 int run();
1489
1494 static Engine* self();
1495
1500 static RunMode mode()
1501 { return s_mode; }
1502
1507 inline static CallAccept accept() {
1508 return (s_congestion && (s_accept < Congestion)) ? Congestion : s_accept;
1509 }
1510
1515 inline static void setAccept(CallAccept ca) {
1516 s_accept = ca;
1517 }
1518
1523 inline static const TokenDict* getCallAcceptStates() {
1524 return s_callAccept;
1525 }
1526
1531 static void setCongestion(const char* reason = 0);
1532
1537 static unsigned int getCongestion()
1538 { return s_congestion; }
1539
1544 inline static bool clientMode()
1545 { return (s_mode == Client) || (s_mode == ClientProxy); }
1546
1553 static bool Register(const Plugin* plugin, bool reg = true);
1554
1559 inline static const String& nodeName()
1560 { return s_node; }
1561
1566 inline static const String& sharedPath()
1567 { return s_shrpath; }
1568
1575 static String configFile(const char* name, bool user = false);
1576
1582 static const String& configPath(bool user = false);
1583
1588 inline static const String& configSuffix()
1589 { return s_cfgsuffix; }
1590
1594 inline static const String& modulePath()
1595 { return s_modpath; }
1596
1602 static void extraPath(const String& path);
1603
1610 static void userPath(const String& path);
1611
1616 inline static const String& moduleSuffix()
1617 { return s_modsuffix; }
1618
1623 static const char* pathSeparator();
1624
1632 static const Configuration& config();
1633
1638 static unsigned int runId();
1639
1644 inline static const NamedList& runParams()
1645 { return s_params; }
1646
1650 static void init();
1651
1657 static bool init(const String& name);
1658
1663 static void halt(unsigned int code);
1664
1671 static bool restart(unsigned int code, bool gracefull = false);
1672
1677 static bool started()
1678 { return s_started; }
1679
1684 static bool exiting()
1685 { return (s_haltcode != -1); }
1686
1692 static bool install(MessageHandler* handler);
1693
1699 static bool uninstall(MessageHandler* handler);
1700
1707 static bool enqueue(Message* msg, bool skipHooks = false);
1708
1716 inline static bool enqueue(const char* name, bool broadcast = false)
1717 { return name && *name && enqueue(new Message(name,0,broadcast)); }
1718
1724 static bool dispatch(Message* msg);
1725
1731 static bool dispatch(Message& msg);
1732
1740 static bool dispatch(const char* name, bool broadcast = false);
1741
1748 inline bool setHook(MessagePostHook* hook, bool remove = false)
1749 { return m_dispatcher.setHook(hook,remove); }
1750
1755 inline static const String& trackParam()
1756 { return s_self ? s_self->m_dispatcher.trackParam() : String::empty(); }
1757
1763 static bool installHook(MessageHook* hook);
1764
1769 static void uninstallHook(MessageHook* hook);
1770
1776
1781 inline unsigned int messageCount()
1782 { return m_dispatcher.messageCount(); }
1783
1788 inline unsigned int handlerCount()
1789 { return m_dispatcher.handlerCount(); }
1790
1795 inline unsigned int postHookCount()
1796 { return m_dispatcher.postHookCount(); }
1797
1802 inline unsigned int messageRate() const
1803 { return m_messageRate; }
1804
1809 inline unsigned int messageMaxRate() const
1810 { return m_maxMsgRate; }
1811
1817 unsigned int messageAge(bool usec = false) const
1818 { return (unsigned int)m_dispatcher.messageAge(usec); }
1819
1827 inline void getStats(u_int64_t& enqueued, u_int64_t& dequeued, u_int64_t& dispatched, u_int64_t& queueMax)
1828 { m_dispatcher.getStats(enqueued,dequeued,dispatched,queueMax); }
1829
1833 inline void resetMax()
1834 { m_maxMsgRate = m_messageRate; m_dispatcher.m_queuedMax = m_dispatcher.messageCount(); }
1835
1841 inline bool pluginLoaded(const String& name) const
1842 { return !!m_libs[name]; }
1843
1849 bool loadPluginDir(const String& relPath);
1850
1855 static void pluginMode(PluginMode mode);
1856
1862 static const ObjList* events(const String& type);
1863
1868 static void clearEvents(const String& type);
1869
1875
1882 static void buildCmdLine(String& line);
1883
1892 static void initLibrary(const String& line, String* output = 0);
1893
1899 static int cleanupLibrary();
1900
1906 { return s_self ? &(s_self->m_dispatcher) : 0; }
1907
1908protected:
1914
1922 bool loadPlugin(const char* file, bool local = false, bool nounload = false);
1923
1928
1933
1934private:
1935 Engine();
1936 void internalStatisticsStart();
1937 void tryPluginFile(const String& name, const String& path, bool defload);
1938 ObjList m_libs;
1939 MessageDispatcher m_dispatcher;
1940 uint64_t m_dispatchedLast;
1941 unsigned int m_messageRate;
1942 unsigned int m_maxMsgRate;
1943 bool m_rateCongested;
1944 bool m_queueCongested;
1945 bool m_ageCongested;
1946 static Engine* s_self;
1947 static String s_node;
1948 static String s_shrpath;
1949 static String s_cfgsuffix;
1950 static String s_modpath;
1951 static String s_modsuffix;
1952 static ObjList s_extramod;
1953 static NamedList s_params;
1954 static int s_haltcode;
1955 static RunMode s_mode;
1956 static bool s_started;
1957 static unsigned int s_congestion;
1958 static CallAccept s_accept;
1959 static const TokenDict s_callAccept[];
1960};
1961
1962}; // namespace TelEngine
1963
1964#endif /* __YATENGINE_H */
1965
1966/* vi: set ts=8 sw=4 sts=4 noet: */
A holder for a debug level.
Definition yateclass.h:329
Definition yateclass.h:1627
Ephemeral mutex, semaphore or rw-lock locking object.
Definition yateclass.h:10000
Matching item common interface.
Definition yateclass.h:8704
bool matchListParam(const NamedList &list, MatchingParams *params=0) const
Definition yateclass.h:8747
bool matchString(const String &str, MatchingParams *params=0) const
Definition yateclass.h:8738
String comparison matching item.
Definition yateclass.h:8864
Mutex support.
Definition yateclass.h:9403
Atomic counter with name.
Definition yateclass.h:5428
A named string container class.
Definition yateclass.h:7690
NamedList & copySubParams(const NamedList &original, const String &prefix, bool skipPrefix=true, bool replace=false)
NamedList & copyParams(bool replace, const NamedList &original, bool copyUserData=false)
A named string class.
Definition yateclass.h:5304
An object list class.
Definition yateclass.h:2032
ObjList * next() const
Definition yateclass.h:2083
GenObject * get() const
Definition yateclass.h:2068
unsigned int count() const
unsigned int length() const
Read/write lock support.
Definition yateclass.h:9720
Definition yateclass.h:1752
virtual void * getObject(const String &name) const
Templated smart pointer class.
Definition yateclass.h:1884
A C-style string handling class.
Definition yateclass.h:3055
bool endsWith(const char *what, bool wordBreak=false, bool caseInsensitive=false) const
String & operator=(const String &value)
Definition yateclass.h:3518
static const String & empty()
unsigned int length() const
Definition yateclass.h:3182
String substr(int offs, int len=-1) const
Class that runs the User Interface.
Definition yatecbase.h:994
Configuration file handling.
Definition yatengine.h:41
bool load(bool warn=true)
NamedString * getKey(const String &sect, const String &key) const
void clearSection(const char *sect=0)
int getIntValue(const String &sect, const String &key, int defvalue=0, int minvalue=INT_MIN, int maxvalue=INT_MAX, bool clamp=true) const
double getDoubleValue(const String &sect, const String &key, double defvalue=0.0) const
int64_t getInt64Value(const String &sect, const String &key, int64_t defvalue=0, int64_t minvalue=LLONG_MIN, int64_t maxvalue=LLONG_MAX, bool clamp=true) const
int getIntValue(const String &sect, const String &key, const TokenDict *tokens, int defvalue=0) const
NamedList * getSection(unsigned int index) const
NamedList * getSection(const String &sect) const
void clearKey(const String &sect, const String &key)
void addValue(const String &sect, const char *key, const char *value=0)
bool getBoolValue(const String &sect, const String &key, bool defvalue=false) const
Configuration & operator=(const String &value)
Definition yatengine.h:60
void setValue(const String &sect, const char *key, int value)
NamedList * createSection(const String &sect)
void setValue(const String &sect, const char *key, const char *value=0)
unsigned int sections() const
Definition yatengine.h:67
Configuration(const char *filename, bool warn=true)
void setValue(const String &sect, const char *key, bool value)
unsigned int count() const
Definition yatengine.h:74
const char * getValue(const String &sect, const String &key, const char *defvalue=0) const
Engine checker interface.
Definition yatengine.h:1382
virtual bool check(const ObjList *cmds)=0
virtual ~EngineCheck()
Definition yatengine.h:1387
static void setChecker(EngineCheck *ptr=0)
Engine globals.
Definition yatengine.h:1417
static bool clientMode()
Definition yatengine.h:1544
static RunMode mode()
Definition yatengine.h:1500
static void halt(unsigned int code)
bool loadPluginDir(const String &relPath)
static const Configuration & config()
static void clearEvents(const String &type)
void resetMax()
Definition yatengine.h:1833
static const String & nodeName()
Definition yatengine.h:1559
static const String & sharedPath()
Definition yatengine.h:1566
bool loadPlugin(const char *file, bool local=false, bool nounload=false)
RunMode
Definition yatengine.h:1425
static void help(bool client, bool errout=false)
static const String & moduleSuffix()
Definition yatengine.h:1616
static const char * pathSeparator()
unsigned int handlerCount()
Definition yatengine.h:1788
static const TokenDict * getCallAcceptStates()
Definition yatengine.h:1523
static bool uninstall(MessageHandler *handler)
unsigned int messageRate() const
Definition yatengine.h:1802
static void uninstallHook(MessageHook *hook)
static const ObjList * events(const String &type)
static int main(int argc, const char **argv, const char **env, RunMode mode=Console, EngineLoop loop=0, bool fail=false)
static bool restart(unsigned int code, bool gracefull=false)
static void pluginMode(PluginMode mode)
static bool init(const String &name)
static bool install(MessageHandler *handler)
static bool installHook(MessageHook *hook)
PluginMode
Definition yatengine.h:1446
static CallAccept accept()
Definition yatengine.h:1507
static void extraPath(const String &path)
static bool dispatch(const char *name, bool broadcast=false)
static void userPath(const String &path)
void getStats(u_int64_t &enqueued, u_int64_t &dequeued, u_int64_t &dispatched, u_int64_t &queueMax)
Definition yatengine.h:1827
bool pluginLoaded(const String &name) const
Definition yatengine.h:1841
bool setHook(MessagePostHook *hook, bool remove=false)
Definition yatengine.h:1748
static bool dispatch(Message &msg)
static MessageDispatcher * dispatcher()
Definition yatengine.h:1905
static const String & trackParam()
Definition yatengine.h:1755
unsigned int postHookCount()
Definition yatengine.h:1795
unsigned int messageAge(bool usec=false) const
Definition yatengine.h:1817
static void buildCmdLine(String &line)
static bool dispatch(Message *msg)
static const String & configSuffix()
Definition yatengine.h:1588
static void initLibrary(const String &line, String *output=0)
unsigned int messageMaxRate() const
Definition yatengine.h:1809
static const String & configPath(bool user=false)
static const String & modulePath()
Definition yatengine.h:1594
static unsigned int getCongestion()
Definition yatengine.h:1537
static int cleanupLibrary()
unsigned int messageCount()
Definition yatengine.h:1781
static SharedVars & sharedVars()
static String configFile(const char *name, bool user=false)
static void setAccept(CallAccept ca)
Definition yatengine.h:1515
static bool enqueue(const char *name, bool broadcast=false)
Definition yatengine.h:1716
static void init()
static bool started()
Definition yatengine.h:1677
static void setCongestion(const char *reason=0)
static bool exiting()
Definition yatengine.h:1684
static bool Register(const Plugin *plugin, bool reg=true)
static Engine * self()
static unsigned int runId()
static bool enqueue(Message *msg, bool skipHooks=false)
static const NamedList & runParams()
Definition yatengine.h:1644
A message dispatching hub.
Definition yatengine.h:907
bool hasMessages() const
Definition yatengine.h:1007
void warnTime(u_int64_t usec)
Definition yatengine.h:981
const String & trackParam() const
Definition yatengine.h:926
bool enqueue(Message *msg)
u_int64_t messageAge(bool usec=false) const
Definition yatengine.h:1075
bool install(MessageHandler *handler)
u_int64_t queuedMax() const
Definition yatengine.h:1067
RWLock & handlersLock()
Definition yatengine.h:1082
u_int64_t dequeueCount() const
Definition yatengine.h:1053
void traceHandlerTime(bool on=false)
Definition yatengine.h:995
u_int64_t enqueueCount() const
Definition yatengine.h:1046
void trackParam(const char *paramName)
Definition yatengine.h:1118
MessageDispatcher(const char *trackParam=0)
bool uninstall(MessageHandler *handler)
void getStats(u_int64_t &enqueued, u_int64_t &dequeued, u_int64_t &dispatched, u_int64_t &queueMax)
bool setHook(MessagePostHook *hook, bool remove=false)
bool hasHooks() const
Definition yatengine.h:1021
bool hasHandlers() const
Definition yatengine.h:1014
bool dispatch(Message &msg)
unsigned int fillHandlersInfo(bool matchName, const String &match, String *details=0, unsigned int *total=0)
u_int64_t dispatchCount() const
Definition yatengine.h:1060
void traceTime(bool on=false)
Definition yatengine.h:988
A message filter.
Definition yatengine.h:595
bool matchesMsg(const Message &msg) const
Definition yatengine.h:614
void setFilter(NamedString *filter)
MessageFilter()
Definition yatengine.h:600
const MatchingItemBase * getMsgFilter() const
Definition yatengine.h:630
void clearFilter()
Definition yatengine.h:652
void setFilter(const char *name, const char *value)
Definition yatengine.h:673
void setFilter(MatchingItemBase *filter)
Definition yatengine.h:638
void setMsgFilter(MatchingItemBase *filter)
Definition yatengine.h:646
~MessageFilter()
Definition yatengine.h:607
void clearMsgFilter()
Definition yatengine.h:658
const MatchingItemBase * getFilter() const
Definition yatengine.h:623
A message handler.
Definition yatengine.h:690
const String & trackNameOnly() const
Definition yatengine.h:739
const MatchingItemBase * filter() const
Definition yatengine.h:770
virtual bool received(Message &msg)=0
const String & trackName() const
Definition yatengine.h:732
unsigned priority() const
Definition yatengine.h:725
void trackName(const char *name)
Definition yatengine.h:747
MessageHandler(const char *name, unsigned priority=100, const char *trackName=0, bool addPriority=true)
virtual bool receivedInternal(Message &msg)
NamedCounter * objectsCounter() const
Definition yatengine.h:763
Abstract message hook.
Definition yatengine.h:1149
virtual bool enqueue(Message *msg)=0
virtual void clear()=0
virtual bool matchesFilter(const Message &msg)=0
Post-dispatching message hook.
Definition yatengine.h:875
virtual void dispatched(const Message &msg, bool handled)=0
Post-dispatching message hook that can be added to a list.
Definition yatengine.h:897
A message queue.
Definition yatengine.h:1178
virtual void received(Message &msg)
void addFilter(const char *name, const char *value)
void removeFilter(const String &name)
virtual bool enqueue(Message *msg)
MessageQueue(const char *hookName, int numWorkers=0)
void removeThread(Thread *thread)
virtual bool matchesFilter(const Message &msg)
const NamedList & getFilters() const
Definition yatengine.h:1241
virtual void clear()
unsigned int count() const
Definition yatengine.h:1234
A multiple message receiver.
Definition yatengine.h:806
virtual bool received(Message &msg, int id)=0
A message handler relay.
Definition yatengine.h:822
virtual bool received(Message &msg)
Definition yatengine.h:846
int id() const
Definition yatengine.h:853
virtual bool receivedInternal(Message &msg)
MessageRelay(const char *name, MessageReceiver *receiver, int id, int priority=100, const char *trackName=0, bool addPriority=true)
Definition yatengine.h:834
A message container class.
Definition yatengine.h:380
virtual void * getObject(const String &name) const
Time & msgTime()
Definition yatengine.h:483
int decode(const char *str, bool &received, const char *id)
void setNotify(bool notify=true)
Definition yatengine.h:462
RefObject * userData() const
Definition yatengine.h:437
void resetMsg(Time tm=Time::now())
const Time & msgTime() const
Definition yatengine.h:490
virtual void dispatched(bool accepted)
const Time & msgTimeEnqueue() const
Definition yatengine.h:506
Message & operator=(const char *value)
Definition yatengine.h:528
void userData(RefObject *data)
Message(const Message &original)
Time & msgTimeDispatch()
Definition yatengine.h:514
bool broadcast() const
Definition yatengine.h:469
String & retValue()
Definition yatengine.h:423
Time & msgTimeEnqueue()
Definition yatengine.h:498
const String & retValue() const
Definition yatengine.h:430
void * userObject(const String &name) const
Definition yatengine.h:453
int decode(const char *str, String &id)
const Time & msgTimeDispatch() const
Definition yatengine.h:522
String encode(const char *id) const
Message(const char *name, const char *retval=0, bool broadcast=false)
String encode(bool received, const char *id) const
Message(const Message &original, bool broadcast)
Plugin support.
Definition yatengine.h:1279
virtual void * getObject(const String &name) const
virtual const String & toString() const
Definition yatengine.h:1299
bool earlyInit() const
Definition yatengine.h:1339
virtual void initialize()=0
const String & name() const
Definition yatengine.h:1325
Plugin(const char *name, bool earlyInit=false)
virtual bool isBusy() const
Definition yatengine.h:1318
NamedCounter * objectsCounter() const
Definition yatengine.h:1332
Atomic access and operations to shared variables.
Definition yatengine.h:252
void clear(const String &name)
uint64_t dec(const String &name, uint64_t wrap=0)
SharedVars(const char *name=0)
Definition yatengine.h:258
bool create(const String &name, const char *val=0)
void set(const String &name, const char *val)
static bool getList(RefPointer< SharedVars > &dest, const String &name)
uint64_t add(const String &name, uint64_t val, uint64_t wrap=0)
void get(const String &name, String &rval)
bool exists(const String &name)
virtual const String & toString() const
Definition yatengine.h:356
uint64_t inc(const String &name, uint64_t wrap=0)
void copy(NamedList &dest, const String &prefix=String::empty(), bool skipPrefix=true, bool replace=false)
Definition yatengine.h:343
uint64_t sub(const String &name, uint64_t val, uint64_t wrap=0)
Thread support class.
Definition yateclass.h:10192
A time holding class.
Definition yateclass.h:5764
static u_int64_t now()
Definition yatemime.h:34
int(* EngineLoop)()
Definition yatengine.h:1408
bool UNLOAD_PLUGIN(bool unloadNow)
void INIT_PLUGIN(class pclass)
Definition yateclass.h:891