Rev 1986 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed
| Rev 1986 | Rev 1987 | ||
|---|---|---|---|
| Line 39... | Line 39... | ||
| 39 | #include "net/Manager.h" |
39 | #include "net/Manager.h" |
| 40 | #include "net/Subscriber.h" |
40 | #include "net/Subscriber.h" |
| 41 | #include "net/types.h" |
41 | #include "net/types.h" |
| 42 | 42 | ||
| 43 | #include "common/common.h" |
43 | #include "common/common.h" |
| - | 44 | #include "common/log.h" |
|
| 44 | 45 | ||
| 45 | #include <readline/readline.h> |
46 | #include <readline/readline.h> |
| 46 | #include <readline/history.h> |
47 | #include <readline/history.h> |
| 47 | 48 | ||
| 48 | using namespace atom; |
49 | using namespace atom; |
| Line 91... | Line 92... | ||
| 91 | { |
92 | { |
| 92 | std::string packet = "RESP"; |
93 | std::string packet = "RESP"; |
| 93 | packet += common::PadNumber(payload.length() + 1, 4); |
94 | packet += common::PadNumber(payload.length() + 1, 4); |
| 94 | packet += payload; |
95 | packet += payload; |
| 95 | 96 | ||
| 96 | net::Manager::Instance()->SendTo(this->client_id_, packet); |
97 | net::Manager::Instance()->SendTo(this->client_id_, common::Byteset(packet.begin(), packet.end())); |
| 97 | } |
98 | } |
| 98 | 99 | ||
| 99 | void AutoCompleteRequest(unsigned int arg_index, std::string commandline) |
100 | void AutoCompleteRequest(unsigned int arg_index, std::string commandline) |
| 100 | { |
101 | { |
| 101 | std::string payload = common::PadNumber(arg_index, 4); |
102 | std::string payload = common::PadNumber(arg_index, 4); |
| Line 103... | Line 104... | ||
| 103 | 104 | ||
| 104 | std::string packet = "COMP"; |
105 | std::string packet = "COMP"; |
| 105 | packet += common::PadNumber(payload.length() + 1, 4); |
106 | packet += common::PadNumber(payload.length() + 1, 4); |
| 106 | packet += payload; |
107 | packet += payload; |
| 107 | 108 | ||
| 108 | net::Manager::Instance()->SendTo(this->client_id_, packet); |
109 | net::Manager::Instance()->SendTo(this->client_id_, common::Byteset(packet.begin(), packet.end())); |
| 109 | } |
110 | } |
| 110 | 111 | ||
| 111 | private: |
112 | private: |
| 112 | net::SocketId client_id_; |
113 | net::SocketId client_id_; |
| 113 | std::string prompt_; |
114 | std::string prompt_; |
| Line 129... | Line 130... | ||
| 129 | { |
130 | { |
| 130 | } |
131 | } |
| 131 | 132 | ||
| 132 | void SlotOnNewDataHandler(net::SocketId client_id, common::Byteset data) |
133 | void SlotOnNewDataHandler(net::SocketId client_id, common::Byteset data) |
| 133 | { |
134 | { |
| 134 | for (unsigned int n = 0; n < data. |
135 | for (unsigned int n = 0; n < data.size(); n++) |
| 135 | { |
136 | { |
| 136 | this->buffer_.push_back(data[n]); |
137 | this->buffer_.push_back(data[n]); |
| 137 | } |
138 | } |
| 138 | 139 | ||
| 139 | while (this->buffer_.size() >= 8) |
140 | while (this->buffer_.size() >= 8) |
| Line 148... | Line 149... | ||
| 148 | payload_length_str += (char)this->buffer_[4]; |
149 | payload_length_str += (char)this->buffer_[4]; |
| 149 | payload_length_str += (char)this->buffer_[5]; |
150 | payload_length_str += (char)this->buffer_[5]; |
| 150 | payload_length_str += (char)this->buffer_[6]; |
151 | payload_length_str += (char)this->buffer_[6]; |
| 151 | payload_length_str += (char)this->buffer_[7]; |
152 | payload_length_str += (char)this->buffer_[7]; |
| 152 | 153 | ||
| 153 | unsigned int payload_length = boost::lexical_cast<unsigned int>(payload_length_str); |
154 | unsigned int payload_length = boost::lexical_cast<unsigned int>(payload_length_str) - 1; |
| 154 | 155 | ||
| 155 | if (this->buffer_.size() - 8 < payload_length) |
156 | if (this->buffer_.size() - 8 < payload_length) |
| 156 | { |
157 | { |
| 157 | return; |
158 | return; |
| 158 | } |
159 | } |
| Line 220... | Line 221... | ||
| 220 | tcgetattr(fileno(stdin), &original_flags); |
221 | tcgetattr(fileno(stdin), &original_flags); |
| 221 | 222 | ||
| 222 | // Parse commandline |
223 | // Parse commandline |
| 223 | boost::program_options::options_description command_line; |
224 | boost::program_options::options_description command_line; |
| 224 | boost::program_options::variables_map variable_map; |
225 | boost::program_options::variables_map variable_map; |
| - | 226 | ||
| - | 227 | //log::SetLevel(log::LOG_LEVEL_ALL); |
|
| 225 | 228 | ||
| 226 | command_line.add_options() |
229 | command_line.add_options() |
| 227 | ("help,h", "produce help message") |
230 | ("help,h", "produce help message") |
| 228 | ("command,c", boost::program_options::value<std::string>()->default_value(""), "command") |
231 | ("command,c", boost::program_options::value<std::string>()->default_value(""), "command") |
| 229 | ("server,s", boost::program_options::value<std::string>()->default_value("localhost"), "server address") |
232 | ("server,s", boost::program_options::value<std::string>()->default_value("localhost"), "server address") |