OLD | NEW |
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> |
11 | 11 |
12 namespace Communication | 12 namespace Communication |
13 { | 13 { |
14 extern const std::wstring pipeName; | 14 extern const std::wstring pipeName; |
15 | 15 |
16 enum ProcType : uint32_t { | 16 enum ProcType : uint32_t { |
17 PROC_MATCHES, | 17 PROC_MATCHES, |
18 PROC_GET_ELEMHIDE_SELECTORS, | 18 PROC_GET_ELEMHIDE_SELECTORS, |
19 PROC_AVAILABLE_SUBSCRIPTIONS, | 19 PROC_AVAILABLE_SUBSCRIPTIONS, |
20 PROC_LISTED_SUBSCRIPTIONS, | 20 PROC_LISTED_SUBSCRIPTIONS, |
21 PROC_SET_SUBSCRIPTION, | 21 PROC_SET_SUBSCRIPTION, |
22 PROC_UPDATE_ALL_SUBSCRIPTIONS, | 22 PROC_UPDATE_ALL_SUBSCRIPTIONS, |
23 PROC_GET_EXCEPTION_DOMAINS, | 23 PROC_GET_EXCEPTION_DOMAINS, |
24 PROC_IS_WHITELISTED_URL, | 24 PROC_IS_WHITELISTED_URL, |
25 PROC_ADD_FILTER, | 25 PROC_ADD_FILTER, |
26 PROC_REMOVE_FILTER, | 26 PROC_REMOVE_FILTER, |
| 27 PROC_SET_PREF, |
| 28 PROC_GET_PREF |
27 }; | 29 }; |
28 enum ValueType : uint32_t { | 30 enum ValueType : uint32_t { |
29 TYPE_PROC, TYPE_STRING, TYPE_WSTRING, TYPE_INT64, TYPE_INT32, TYPE_BOOL | 31 TYPE_PROC, TYPE_STRING, TYPE_WSTRING, TYPE_INT64, TYPE_INT32, TYPE_BOOL |
30 }; | 32 }; |
31 typedef uint32_t SizeType; | 33 typedef uint32_t SizeType; |
32 | 34 |
33 class InputBuffer | 35 class InputBuffer |
34 { | 36 { |
35 public: | 37 public: |
| 38 InputBuffer() : buffer(), hasType(false) {} |
36 InputBuffer(const std::string& data) : buffer(data), hasType(false) {} | 39 InputBuffer(const std::string& data) : buffer(data), hasType(false) {} |
| 40 InputBuffer(const InputBuffer& copy) { hasType = copy.hasType; buffer = std:
:istringstream(copy.buffer.str()); currentType = copy.currentType; } |
37 InputBuffer& operator>>(ProcType& value) { return Read(value, TYPE_PROC); } | 41 InputBuffer& operator>>(ProcType& value) { return Read(value, TYPE_PROC); } |
38 InputBuffer& operator>>(std::string& value) { return ReadString(value, TYPE_
STRING); } | 42 InputBuffer& operator>>(std::string& value) { return ReadString(value, TYPE_
STRING); } |
39 InputBuffer& operator>>(std::wstring& value) { return ReadString(value, TYPE
_WSTRING); } | 43 InputBuffer& operator>>(std::wstring& value) { return ReadString(value, TYPE
_WSTRING); } |
40 InputBuffer& operator>>(int64_t& value) { return Read(value, TYPE_INT64); } | 44 InputBuffer& operator>>(int64_t& value) { return Read(value, TYPE_INT64); } |
41 InputBuffer& operator>>(int32_t& value) { return Read(value, TYPE_INT32); } | 45 InputBuffer& operator>>(int32_t& value) { return Read(value, TYPE_INT32); } |
42 InputBuffer& operator>>(bool& value) { return Read(value, TYPE_BOOL); } | 46 InputBuffer& operator>>(bool& value) { return Read(value, TYPE_BOOL); } |
| 47 InputBuffer& operator=(const InputBuffer& copy) { hasType = copy.hasType; bu
ffer = std::istringstream(copy.buffer.str()); |
| 48 currentType = copy.current
Type; return *this; } |
| 49 ValueType GetType(); |
43 private: | 50 private: |
44 std::istringstream buffer; | 51 std::istringstream buffer; |
45 ValueType currentType; | 52 ValueType currentType; |
46 bool hasType; | 53 bool hasType; |
47 | 54 |
48 void CheckType(ValueType expectedType); | 55 void CheckType(ValueType expectedType); |
49 | 56 |
50 template<class T> | 57 template<class T> |
51 InputBuffer& ReadString(T& value, ValueType expectedType) | 58 InputBuffer& ReadString(T& value, ValueType expectedType) |
52 { | 59 { |
(...skipping 18 matching lines...) Expand all Loading... |
71 ReadBinary(value); | 78 ReadBinary(value); |
72 return *this; | 79 return *this; |
73 } | 80 } |
74 | 81 |
75 template<class T> | 82 template<class T> |
76 void ReadBinary(T& value) | 83 void ReadBinary(T& value) |
77 { | 84 { |
78 buffer.read(reinterpret_cast<char*>(&value), sizeof(T)); | 85 buffer.read(reinterpret_cast<char*>(&value), sizeof(T)); |
79 if (buffer.fail()) | 86 if (buffer.fail()) |
80 throw new std::runtime_error("Unexpected end of input buffer"); | 87 throw new std::runtime_error("Unexpected end of input buffer"); |
| 88 hasType = false; |
81 } | 89 } |
82 }; | 90 }; |
83 | 91 |
84 class OutputBuffer | 92 class OutputBuffer |
85 { | 93 { |
86 public: | 94 public: |
87 OutputBuffer() {} | 95 OutputBuffer() {} |
88 | 96 |
89 // Explicit copy constructor to allow returning OutputBuffer by value | 97 // Explicit copy constructor to allow returning OutputBuffer by value |
90 OutputBuffer(const OutputBuffer& copy) : buffer(copy.buffer.str()) {} | 98 OutputBuffer(const OutputBuffer& copy) : buffer(copy.buffer.str()) {} |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 | 167 |
160 InputBuffer ReadMessage(); | 168 InputBuffer ReadMessage(); |
161 void WriteMessage(OutputBuffer& message); | 169 void WriteMessage(OutputBuffer& message); |
162 | 170 |
163 protected: | 171 protected: |
164 HANDLE pipe; | 172 HANDLE pipe; |
165 }; | 173 }; |
166 } | 174 } |
167 | 175 |
168 #endif | 176 #endif |
OLD | NEW |