Jira connector migrated to new NXCSession API
[public/netxms.git] / include / nxmbapi.h
CommitLineData
ccc34207
VK
1/*
2** NetXMS - Network Management System
3** NetXMS Message Bus API
4** Copyright (C) 2009 Victor Kirhenshtein
5**
6** This program is free software; you can redistribute it and/or modify
7** it under the terms of the GNU General Public License as published by
8** the Free Software Foundation; either version 2 of the License, or
9** (at your option) any later version.
10**
11** This program is distributed in the hope that it will be useful,
12** but WITHOUT ANY WARRANTY; without even the implied warranty of
13** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14** GNU General Public License for more details.
15**
16** You should have received a copy of the GNU General Public License
17** along with this program; if not, write to the Free Software
18** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19**
20** File: nxmbapi.h
21**
22**/
23
24#ifndef _nxmbapi_h_
25#define _nxmbapi_h_
26
27#ifdef _WIN32
28#ifdef LIBNXMB_EXPORTS
29#define LIBNXMB_EXPORTABLE __declspec(dllexport)
30#else
31#define LIBNXMB_EXPORTABLE __declspec(dllimport)
32#endif
33#else /* _WIN32 */
34#define LIBNXMB_EXPORTABLE
35#endif
36
37#include <nms_common.h>
38#include <nms_util.h>
39#include <nms_threads.h>
40#include <nxqueue.h>
41
42
43//
44// Message class
45//
46
47class LIBNXMB_EXPORTABLE NXMBMessage
48{
49protected:
50 TCHAR *m_type;
51 TCHAR *m_senderId;
52
53public:
54 NXMBMessage();
55 NXMBMessage(const TCHAR *type, const TCHAR *senderId);
56 virtual ~NXMBMessage();
57
9069da06
AK
58 const TCHAR *getType() const { return m_type; }
59 const TCHAR *getSenderId() const { return m_senderId; }
ccc34207
VK
60};
61
62
63//
64// Subscriber class
65//
66
67class LIBNXMB_EXPORTABLE NXMBSubscriber
68{
69protected:
70 TCHAR *m_id;
71
72public:
73 NXMBSubscriber(const TCHAR *id);
74 virtual ~NXMBSubscriber();
75
76 const TCHAR *getId() { return CHECK_NULL(m_id); }
77
78 virtual void messageHandler(NXMBMessage &msg);
79 virtual bool isOwnedByDispatcher();
80};
81
82
83//
84// Abstract message filter class
85//
86
87class LIBNXMB_EXPORTABLE NXMBFilter
88{
89public:
90 NXMBFilter();
91 virtual ~NXMBFilter();
92
93 virtual bool isAllowed(NXMBMessage &msg);
94 virtual bool isOwnedByDispatcher();
95};
96
97
98//
99// Message filter which accept messages of specific type(s)
100//
101
102class LIBNXMB_EXPORTABLE NXMBTypeFilter : public NXMBFilter
103{
104protected:
105 StringMap m_types;
106
107public:
108 NXMBTypeFilter();
109 virtual ~NXMBTypeFilter();
110
111 virtual bool isAllowed(NXMBMessage &msg);
112
113 void addMessageType(const TCHAR *type);
114 void removeMessageType(const TCHAR *type);
115};
116
117
118//
119// Message dispatcher class
120//
121
122class LIBNXMB_EXPORTABLE NXMBDispatcher
123{
124 friend THREAD_RESULT THREAD_CALL WorkerThreadStarter(void *);
125
126private:
127 static NXMBDispatcher *m_instance;
128
129protected:
130 Queue *m_queue;
131 int m_numSubscribers;
132 NXMBSubscriber **m_subscribers;
133 NXMBFilter **m_filters;
134 MUTEX m_subscriberListAccess;
135 THREAD m_workerThreadHandle;
136
137 void workerThread();
138
139public:
140 NXMBDispatcher();
141 virtual ~NXMBDispatcher();
142
143 void postMessage(NXMBMessage *msg);
144
145 void addSubscriber(NXMBSubscriber *subscriber, NXMBFilter *filter);
146 void removeSubscriber(const TCHAR *id);
147
148 static NXMBDispatcher *getInstance();
149};
150
151
152#endif /* _nxmbapi_h_ */