Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: src/shared/Communication.h

Issue 10874009: Use a proper enum type for procedures that can be called (Closed)
Patch Set: Created June 3, 2013, 1:53 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/plugin/AdblockPlusClient.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 const int bufferSize = 1024; 15 const int bufferSize = 1024;
16 16
17 enum {TYPE_STRING, TYPE_WSTRING, TYPE_INT64, TYPE_INT32, TYPE_BOOL}; 17 enum ProcType : uint32_t {
Felix Dahlke 2013/06/04 06:47:32 I can't find anything about this, but I think you
Wladimir Palant 2013/06/04 09:26:13 It is a standard feature, see http://en.wikipedia.
Felix Dahlke 2013/06/04 11:55:21 Didn't know it's a new standard feature, in this c
18 typedef int32_t ValueType; 18 PROC_MATCHES,
19 PROC_GET_ELEMHIDE_SELECTORS,
20 PROC_AVAILABLE_SUBSCRIPTIONS,
21 PROC_LISTED_SUBSCRIPTIONS,
22 PROC_SET_SUBSCRIPTION,
23 PROC_UPDATE_ALL_SUBSCRIPTIONS,
24 PROC_GET_EXCEPTION_DOMAINS,
25 PROC_ADD_FILTER,
26 };
27 enum ValueType : uint32_t {
28 TYPE_PROC, TYPE_STRING, TYPE_WSTRING, TYPE_INT64, TYPE_INT32, TYPE_BOOL
29 };
19 typedef uint32_t SizeType; 30 typedef uint32_t SizeType;
20 31
21 class InputBuffer 32 class InputBuffer
22 { 33 {
23 public: 34 public:
24 InputBuffer(const std::string& data) : buffer(data), hasType(false) {} 35 InputBuffer(const std::string& data) : buffer(data), hasType(false) {}
36 InputBuffer& operator>>(ProcType& value) { return Read(value, TYPE_PROC); }
25 InputBuffer& operator>>(std::string& value) { return ReadString(value, TYPE_ STRING); } 37 InputBuffer& operator>>(std::string& value) { return ReadString(value, TYPE_ STRING); }
26 InputBuffer& operator>>(std::wstring& value) { return ReadString(value, TYPE _WSTRING); } 38 InputBuffer& operator>>(std::wstring& value) { return ReadString(value, TYPE _WSTRING); }
27 InputBuffer& operator>>(int64_t& value) { return Read(value, TYPE_INT64); } 39 InputBuffer& operator>>(int64_t& value) { return Read(value, TYPE_INT64); }
28 InputBuffer& operator>>(int32_t& value) { return Read(value, TYPE_INT32); } 40 InputBuffer& operator>>(int32_t& value) { return Read(value, TYPE_INT32); }
29 InputBuffer& operator>>(bool& value) { return Read(value, TYPE_BOOL); } 41 InputBuffer& operator>>(bool& value) { return Read(value, TYPE_BOOL); }
30 private: 42 private:
31 std::istringstream buffer; 43 std::istringstream buffer;
32 ValueType currentType; 44 ValueType currentType;
33 bool hasType; 45 bool hasType;
34 46
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 public: 98 public:
87 OutputBuffer() {} 99 OutputBuffer() {}
88 100
89 // Explicit copy constructor to allow returning OutputBuffer by value 101 // Explicit copy constructor to allow returning OutputBuffer by value
90 OutputBuffer(const OutputBuffer& copy) : buffer(copy.buffer.str()) {} 102 OutputBuffer(const OutputBuffer& copy) : buffer(copy.buffer.str()) {}
91 103
92 std::string Get() 104 std::string Get()
93 { 105 {
94 return buffer.str(); 106 return buffer.str();
95 } 107 }
108 OutputBuffer& operator<<(ProcType value) { return Write(value, TYPE_PROC); }
96 OutputBuffer& operator<<(const std::string& value) { return WriteString(valu e, TYPE_STRING); } 109 OutputBuffer& operator<<(const std::string& value) { return WriteString(valu e, TYPE_STRING); }
97 OutputBuffer& operator<<(const std::wstring& value) { return WriteString(val ue, TYPE_WSTRING); } 110 OutputBuffer& operator<<(const std::wstring& value) { return WriteString(val ue, TYPE_WSTRING); }
98 OutputBuffer& operator<<(int64_t value) { return Write(value, TYPE_INT64); } 111 OutputBuffer& operator<<(int64_t value) { return Write(value, TYPE_INT64); }
99 OutputBuffer& operator<<(int32_t value) { return Write(value, TYPE_INT32); } 112 OutputBuffer& operator<<(int32_t value) { return Write(value, TYPE_INT32); }
100 OutputBuffer& operator<<(bool value) { return Write(value, TYPE_BOOL); } 113 OutputBuffer& operator<<(bool value) { return Write(value, TYPE_BOOL); }
101 private: 114 private:
102 std::ostringstream buffer; 115 std::ostringstream buffer;
103 116
104 // Disallow copying 117 // Disallow copying
105 const OutputBuffer& operator=(const OutputBuffer&); 118 const OutputBuffer& operator=(const OutputBuffer&);
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 165
153 InputBuffer ReadMessage(); 166 InputBuffer ReadMessage();
154 void WriteMessage(OutputBuffer& message); 167 void WriteMessage(OutputBuffer& message);
155 168
156 protected: 169 protected:
157 HANDLE pipe; 170 HANDLE pipe;
158 }; 171 };
159 } 172 }
160 173
161 #endif 174 #endif
OLDNEW
« no previous file with comments | « src/plugin/AdblockPlusClient.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld