-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDispatcher.cpp
More file actions
61 lines (50 loc) · 1.08 KB
/
Dispatcher.cpp
File metadata and controls
61 lines (50 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include "Queue.h"
#include "HandlerFactory.h"
#include "Dispatcher.h"
using namespace MQ;
Dispatcher::Dispatcher()
{
dqs.resize(INTERFACEID_COUNT);
bqs.resize(INTERFACEID_COUNT);
}
Dispatcher::~Dispatcher()
{
dqs.clear();
bqs.clear();
}
int Dispatcher::dispatchDq(const Message& message_) const
{
return dqs[message_.msgType] ? dqs[message_.msgType]->push(message_) : -1;
}
int Dispatcher::dispatchBq(const Message& message_) const
{
return bqs[message_.msgType] ? bqs[message_.msgType]->push(message_) : -1;
}
int Dispatcher::registerDq(int message_type, const std::shared_ptr<DQueue>& mq)
{
if (dqs[message_type])
return -1;
dqs[message_type] = mq;
return 0;
}
int Dispatcher::registerBq(int message_type, const std::shared_ptr<BQueue>& bq)
{
if (bqs[message_type])
return -1;
bqs[message_type] = bq;
return 0;
}
void Dispatcher::shutdownDq()
{
for (auto& dq : dqs) {
if (!dq)
dq->shutdown();
}
}
void Dispatcher::shutdownBq()
{
for (auto& bq : bqs) {
if (!bq)
bq->shutdown();
}
}