| LEFT | RIGHT |
| 1 #ifndef COMMUNICATION_H | 1 #ifndef COMMUNICATION_H |
| 2 #define COMMUNICATION_H | 2 #define COMMUNICATION_H |
| 3 | 3 |
| 4 #include <memory> | 4 #include <memory> |
| 5 #include <sstream> | 5 #include <sstream> |
| 6 #include <stdexcept> | 6 #include <stdexcept> |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 #include <Windows.h> | 10 #include <Windows.h> |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 PROC_IS_FIRST_RUN_ACTION_NEEDED | 29 PROC_IS_FIRST_RUN_ACTION_NEEDED |
| 30 }; | 30 }; |
| 31 enum ValueType : uint32_t { | 31 enum ValueType : uint32_t { |
| 32 TYPE_PROC, TYPE_STRING, TYPE_WSTRING, TYPE_INT64, TYPE_INT32, TYPE_BOOL | 32 TYPE_PROC, TYPE_STRING, TYPE_WSTRING, TYPE_INT64, TYPE_INT32, TYPE_BOOL |
| 33 }; | 33 }; |
| 34 typedef uint32_t SizeType; | 34 typedef uint32_t SizeType; |
| 35 | 35 |
| 36 class InputBuffer | 36 class InputBuffer |
| 37 { | 37 { |
| 38 public: | 38 public: |
| 39 InputBuffer() : buffer(), hasType(false) {} |
| 39 InputBuffer(const std::string& data) : buffer(data), hasType(false) {} | 40 InputBuffer(const std::string& data) : buffer(data), hasType(false) {} |
| 41 InputBuffer(const InputBuffer& copy) { hasType = copy.hasType; buffer = std:
:istringstream(copy.buffer.str()); currentType = copy.currentType; } |
| 40 InputBuffer& operator>>(ProcType& value) { return Read(value, TYPE_PROC); } | 42 InputBuffer& operator>>(ProcType& value) { return Read(value, TYPE_PROC); } |
| 41 InputBuffer& operator>>(std::string& value) { return ReadString(value, TYPE_
STRING); } | 43 InputBuffer& operator>>(std::string& value) { return ReadString(value, TYPE_
STRING); } |
| 42 InputBuffer& operator>>(std::wstring& value) { return ReadString(value, TYPE
_WSTRING); } | 44 InputBuffer& operator>>(std::wstring& value) { return ReadString(value, TYPE
_WSTRING); } |
| 43 InputBuffer& operator>>(int64_t& value) { return Read(value, TYPE_INT64); } | 45 InputBuffer& operator>>(int64_t& value) { return Read(value, TYPE_INT64); } |
| 44 InputBuffer& operator>>(int32_t& value) { return Read(value, TYPE_INT32); } | 46 InputBuffer& operator>>(int32_t& value) { return Read(value, TYPE_INT32); } |
| 45 InputBuffer& operator>>(bool& value) { return Read(value, TYPE_BOOL); } | 47 InputBuffer& operator>>(bool& value) { return Read(value, TYPE_BOOL); } |
| 48 InputBuffer& operator=(const InputBuffer& copy) { hasType = copy.hasType; bu
ffer = std::istringstream(copy.buffer.str()); |
| 49 currentType = copy.current
Type; return *this; } |
| 50 ValueType GetType(); |
| 46 private: | 51 private: |
| 47 std::istringstream buffer; | 52 std::istringstream buffer; |
| 48 ValueType currentType; | 53 ValueType currentType; |
| 49 bool hasType; | 54 bool hasType; |
| 50 | 55 |
| 51 void CheckType(ValueType expectedType); | 56 void CheckType(ValueType expectedType); |
| 52 | 57 |
| 53 template<class T> | 58 template<class T> |
| 54 InputBuffer& ReadString(T& value, ValueType expectedType) | 59 InputBuffer& ReadString(T& value, ValueType expectedType) |
| 55 { | 60 { |
| (...skipping 18 matching lines...) Expand all Loading... |
| 74 ReadBinary(value); | 79 ReadBinary(value); |
| 75 return *this; | 80 return *this; |
| 76 } | 81 } |
| 77 | 82 |
| 78 template<class T> | 83 template<class T> |
| 79 void ReadBinary(T& value) | 84 void ReadBinary(T& value) |
| 80 { | 85 { |
| 81 buffer.read(reinterpret_cast<char*>(&value), sizeof(T)); | 86 buffer.read(reinterpret_cast<char*>(&value), sizeof(T)); |
| 82 if (buffer.fail()) | 87 if (buffer.fail()) |
| 83 throw new std::runtime_error("Unexpected end of input buffer"); | 88 throw new std::runtime_error("Unexpected end of input buffer"); |
| 89 hasType = false; |
| 84 } | 90 } |
| 85 }; | 91 }; |
| 86 | 92 |
| 87 class OutputBuffer | 93 class OutputBuffer |
| 88 { | 94 { |
| 89 public: | 95 public: |
| 90 OutputBuffer() {} | 96 OutputBuffer() {} |
| 91 | 97 |
| 92 // Explicit copy constructor to allow returning OutputBuffer by value | 98 // Explicit copy constructor to allow returning OutputBuffer by value |
| 93 OutputBuffer(const OutputBuffer& copy) : buffer(copy.buffer.str()) {} | 99 OutputBuffer(const OutputBuffer& copy) : buffer(copy.buffer.str()) {} |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 162 | 168 |
| 163 InputBuffer ReadMessage(); | 169 InputBuffer ReadMessage(); |
| 164 void WriteMessage(OutputBuffer& message); | 170 void WriteMessage(OutputBuffer& message); |
| 165 | 171 |
| 166 protected: | 172 protected: |
| 167 HANDLE pipe; | 173 HANDLE pipe; |
| 168 }; | 174 }; |
| 169 } | 175 } |
| 170 | 176 |
| 171 #endif | 177 #endif |
| LEFT | RIGHT |