-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathCursorCmds.h
executable file
·203 lines (173 loc) · 5.26 KB
/
CursorCmds.h
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
#ifndef _CURSORCMDS_H_
#define _CURSORCMDS_H_
#include "Command.h"
#include "ServiceThread.h"
#include "comdefs.h"
#include "server_operators.h"
#include "QAccessControl.h"
#include "Log.h"
namespace safmq {
extern const char* EC_Decode(ErrorCode);
class AdvanceCursorCmd : public Command {
protected:
CLOSE_CURSOR_ADVANCE_CURSOR_TEST_CURSOR_PARAMS params;
ErrorCode response;
public:
AdvanceCursorCmd(ServiceThread* pservice) : Command(pservice), response(EC_ERROR) { }
virtual ~AdvanceCursorCmd() {}
static Command* allocate(ServiceThread* pservice) { return new AdvanceCursorCmd(pservice); }
virtual void readRequest(std::istream& i) {
i >> params;
}
virtual void writeResponse(std::ostream& o) {
o << RESPONSE_RESPONSE(response) << std::flush;
}
virtual int perform() {
if (service->loggedIn()) {
QStorage* pqueue = service->getOpenQueue(params.queueID);
if (pqueue) {
response = pqueue->AdvanceCursor(params.cursorID);
} else {
response = EC_NOTOPEN;
}
return 0;
}
return -1;
}
};
class OpenCursorCmd : public Command {
protected:
QUEUE_CLOSE_OPEN_CURSOR_PARAMS params;
QStorage::CursorHandle cursor;
ErrorCode response;
public:
OpenCursorCmd(ServiceThread* pservice) : Command(pservice) {}
virtual ~OpenCursorCmd() {}
static Command* allocate(ServiceThread* pservice) { return new OpenCursorCmd(pservice); }
virtual void readRequest(std::istream& i) {
i >> params;
}
virtual void writeResponse(std::ostream& o) {
if (response == EC_NOERROR)
o << OPEN_CURSOR_RESPONSE(cursor) << std::flush;
else
o << RESPONSE_RESPONSE(response) << std::flush;
}
virtual int perform() {
if (service->loggedIn()) {
QStorage* pqueue = service->getOpenQueue(params.queueID);
if (pqueue) {
if (SecurityControl::getSecurityControl()->testQueueOperation(service->getUsername(), pqueue->getName(), SecurityControl::READ) == SecurityControl::GRANTED) {
// Open the cursor
response = pqueue->OpenCursor(cursor);
if (response == EC_NOERROR) {
// Add the cursor to the list of open cursors
service->addCursor(params.queueID, cursor);
Log::getLog()->Info("Opened cursor %ld for queue:%s", (int)cursor, pqueue->getName().c_str());
}
} else {
response = EC_NOTAUTHORIZED;
}
} else {
response = EC_NOTOPEN;
}
return 0;
}
return -1;
}
};
class CloseCursorCmd : public Command {
protected:
CLOSE_CURSOR_ADVANCE_CURSOR_TEST_CURSOR_PARAMS params;
ErrorCode response;
public:
CloseCursorCmd(ServiceThread* pservice) : Command(pservice) {}
virtual ~CloseCursorCmd() {}
static Command* allocate(ServiceThread* pservice) { return new CloseCursorCmd(pservice); }
virtual void readRequest(std::istream& i) {
i >> params;
}
virtual void writeResponse(std::ostream& o) {
o << RESPONSE_RESPONSE(response) << std::flush;
}
virtual int perform() {
if (service->loggedIn()) {
QStorage* pqueue = service->getOpenQueue(params.queueID);
if (pqueue) {
// Close the cursor
response = pqueue->CloseCursor(params.cursorID);
service->removeCursor(params.queueID, params.cursorID);
} else {
response = EC_NOTOPEN;
}
return 0;
}
return -1;
}
};
class SeekIDCmd : public Command {
protected:
SEEK_ID_PARAMS params;
ErrorCode response;
public:
SeekIDCmd(ServiceThread* pservice) : Command(pservice) {}
virtual ~SeekIDCmd() {}
static Command* allocate(ServiceThread* pservice) { return new SeekIDCmd(pservice); }
virtual void readRequest(std::istream& i) {
i >> params;
}
virtual void writeResponse(std::ostream& o) {
o << RESPONSE_RESPONSE(response) << std::flush;
}
virtual int perform() {
// TODO: If the queue becomes is completely empty when
// TODO: The ID being waited for returns, the cursor waited on
// TODO: Can become invalidated, this can be a serious error
// TODO: when using two queues for two way communicaiton and the
// TODO: return queue is usually empty. Or becomes empty while in
// TODO: a call for WaitForID(), possibly
if (service->loggedIn()) {
QStorage* pqueue = service->getOpenQueue(params.queueID);
if (pqueue) {
QStorage::CursorHandle h;
response = pqueue->WaitForID(params.reciptID, params.timeoutseconds, h);
pqueue->CloseCursor(h);
if (response == EC_NOERROR)
response = pqueue->SeekID(params.reciptID, params.cursorID);
} else {
response = EC_NOTOPEN;
}
return 0;
}
return -1;
}
};
class TestCursorCmd : public Command {
protected:
CLOSE_CURSOR_ADVANCE_CURSOR_TEST_CURSOR_PARAMS params;
ErrorCode response;
public:
TestCursorCmd(ServiceThread* pservice) : Command(pservice) {}
virtual ~TestCursorCmd() {}
static Command* allocate(ServiceThread* pservice) { return new TestCursorCmd(pservice); }
virtual void readRequest(std::istream& i) {
i >> params;
}
virtual void writeResponse(std::ostream& o) {
o << RESPONSE_RESPONSE(response) << std::flush;
}
virtual int perform() {
if (service->loggedIn()) {
QStorage* pqueue = service->getOpenQueue(params.queueID);
if (pqueue) {
response = pqueue->TestCursor(params.cursorID);
} else {
response = EC_NOTOPEN;
}
return 0;
}
return -1;
}
};
}
#endif