OLD | NEW |
| (Empty) |
1 // rsp_console.cpp : Defines the entry point for the console application. | |
2 // | |
3 #include <conio.h> | |
4 #include "debugger/base/debug_socket.h" | |
5 #include "debugger/rsp/rsp_packetizer.h" | |
6 #include "debugger/rsp/rsp_packet_util.h" | |
7 | |
8 const int kReadBufferSize = 1024; | |
9 debug::Socket connection; | |
10 | |
11 class RspConsolePacketConsumer : public rsp::PacketConsumer { | |
12 public: | |
13 void OnPacket(const debug::Blob& body, bool valid_checksum); | |
14 void OnUnexpectedChar(char unexpected_char); | |
15 void OnBreak(); | |
16 }; | |
17 | |
18 void RspConsolePacketConsumer::OnPacket(const debug::Blob& body, bool valid_chec
ksum) { | |
19 printf("\nR%s>%s\n", (valid_checksum ? "" : "-checksum-error"), body.ToString(
).c_str()); | |
20 printf(">"); | |
21 connection.WriteAll("+", 1); | |
22 } | |
23 | |
24 void RspConsolePacketConsumer::OnUnexpectedChar(char unexpected_char) { | |
25 printf("\nR>unexpected [%c]\n", unexpected_char); | |
26 printf(">"); | |
27 } | |
28 | |
29 void RspConsolePacketConsumer::OnBreak() { | |
30 printf("\nR>Ctrl-C\n"); | |
31 printf(">"); | |
32 } | |
33 | |
34 int main(int argc, char* argv[]) { | |
35 int port = 2345; // TODO: read theam from command line | |
36 const char* host_name = "172.29.216.11"; | |
37 | |
38 port = 4014; | |
39 host_name = "localhost"; | |
40 | |
41 rsp::Packetizer rsp_packetizer; | |
42 RspConsolePacketConsumer consm; | |
43 rsp_packetizer.SetPacketConsumer(&consm); | |
44 printf(">"); | |
45 | |
46 while (true) { | |
47 if (!connection.IsConnected()) { | |
48 printf("\nConnecting to %s:%d ...", host_name, port); | |
49 connection.ConnectTo(host_name, port); | |
50 printf("%s\n>", connection.IsConnected() ? "Ok" : "Failed"); | |
51 } | |
52 else { | |
53 char buff[kReadBufferSize]; | |
54 for (int i = 0; i < 100; i++) { | |
55 size_t read_bytes = connection.Read(buff, | |
56 sizeof(buff) - 1, | |
57 0); | |
58 if (read_bytes > 0) { | |
59 buff[read_bytes] = 0; | |
60 printf("\nr>[%s]\n", buff); | |
61 rsp_packetizer.OnData(buff, read_bytes); | |
62 } else { | |
63 break; | |
64 } | |
65 } | |
66 } | |
67 | |
68 if (!_kbhit()) | |
69 continue; | |
70 | |
71 char cmd[300] = {0}; | |
72 gets_s(cmd, sizeof(cmd)); | |
73 if (0 == strcmp(cmd, "quit")) | |
74 break; | |
75 else { | |
76 debug::Blob msg; | |
77 rsp::PacketUtil::AddEnvelope(cmd, &msg); | |
78 //printf("s>%s\n", msg.ToString().c_str()); | |
79 if (connection.IsConnected()) | |
80 connection.WriteAll(msg); | |
81 } | |
82 } | |
83 return 0; | |
84 } | |
85 | |
OLD | NEW |