-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRequestCommandHandler.cpp
More file actions
53 lines (42 loc) · 1.42 KB
/
RequestCommandHandler.cpp
File metadata and controls
53 lines (42 loc) · 1.42 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
/*
* File: MessageCommandHandler.cpp
* Author: kmcqueen
*
* Created on September 13, 2013, 12:31 AM
*/
#include "RequestCommandHandler.h"
#include <iostream>
#include "Request.h"
#include "main.h"
RequestCommandHandler::~RequestCommandHandler() {
}
void RequestCommandHandler::doHandleCommand(string commandLine) {
Request* msg = this->prepareRequest(commandLine);
if (NULL == msg) {
return;
}
debug("RequestCommandHandler::doHandle -- prepared message:\n" + msg->toString());
// send request to server
debug("RequestCommandHandler::doHandle -- send the request to the server");
ServerProxy* server = ServerProxy::instance();
server->sendRequest(msg);
// delete the request (recover memory)
delete msg;
// get response (line) from server
string response = server->getResponseLine();
debug("RequestCommandHandler::doHandleCommand -- server response (line) is: " + response);
// if the response starts with "OK" then we can just quit now
if (response.find("OK") == 0) {
return;
}
// if the response starts with "error", then output the error and quit now
if (response.find("error") == 0) {
cout << response;
return;
}
// perform further processing (as necessary) on the response
this->doHandleResponse(response);
}
void RequestCommandHandler::doHandleResponse(string response) {
// no op
}