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

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

Issue 10786016: Moved all pipe functionality into a self-containing Communication::Pipe class (Closed)
Patch Set: Created June 3, 2013, 2:07 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 | « no previous file | src/shared/Communication.cpp » ('j') | 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;
16 15
17 enum ProcType : uint32_t { 16 enum ProcType : uint32_t {
18 PROC_MATCHES, 17 PROC_MATCHES,
19 PROC_GET_ELEMHIDE_SELECTORS, 18 PROC_GET_ELEMHIDE_SELECTORS,
20 PROC_AVAILABLE_SUBSCRIPTIONS, 19 PROC_AVAILABLE_SUBSCRIPTIONS,
21 PROC_LISTED_SUBSCRIPTIONS, 20 PROC_LISTED_SUBSCRIPTIONS,
22 PROC_SET_SUBSCRIPTION, 21 PROC_SET_SUBSCRIPTION,
23 PROC_UPDATE_ALL_SUBSCRIPTIONS, 22 PROC_UPDATE_ALL_SUBSCRIPTIONS,
24 PROC_GET_EXCEPTION_DOMAINS, 23 PROC_GET_EXCEPTION_DOMAINS,
25 PROC_ADD_FILTER, 24 PROC_ADD_FILTER,
(...skipping 11 matching lines...) Expand all
37 InputBuffer& operator>>(std::string& value) { return ReadString(value, TYPE_ STRING); } 36 InputBuffer& operator>>(std::string& value) { return ReadString(value, TYPE_ STRING); }
38 InputBuffer& operator>>(std::wstring& value) { return ReadString(value, TYPE _WSTRING); } 37 InputBuffer& operator>>(std::wstring& value) { return ReadString(value, TYPE _WSTRING); }
39 InputBuffer& operator>>(int64_t& value) { return Read(value, TYPE_INT64); } 38 InputBuffer& operator>>(int64_t& value) { return Read(value, TYPE_INT64); }
40 InputBuffer& operator>>(int32_t& value) { return Read(value, TYPE_INT32); } 39 InputBuffer& operator>>(int32_t& value) { return Read(value, TYPE_INT32); }
41 InputBuffer& operator>>(bool& value) { return Read(value, TYPE_BOOL); } 40 InputBuffer& operator>>(bool& value) { return Read(value, TYPE_BOOL); }
42 private: 41 private:
43 std::istringstream buffer; 42 std::istringstream buffer;
44 ValueType currentType; 43 ValueType currentType;
45 bool hasType; 44 bool hasType;
46 45
47 void CheckType(ValueType expectedType) 46 void CheckType(ValueType expectedType);
48 {
49 if (!hasType)
50 ReadBinary(currentType);
51
52 if (currentType != expectedType)
53 {
54 // Make sure we don't attempt to read the type again
55 hasType = true;
56 throw new std::runtime_error("Unexpected type found in input buffer");
57 }
58 else
59 hasType = false;
60 }
61 47
62 template<class T> 48 template<class T>
63 InputBuffer& ReadString(T& value, ValueType expectedType) 49 InputBuffer& ReadString(T& value, ValueType expectedType)
64 { 50 {
65 CheckType(expectedType); 51 CheckType(expectedType);
66 52
67 SizeType length; 53 SizeType length;
68 ReadBinary(length); 54 ReadBinary(length);
69 55
70 std::auto_ptr<T::value_type> data(new T::value_type[length]); 56 std::auto_ptr<T::value_type> data(new T::value_type[length]);
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 151
166 InputBuffer ReadMessage(); 152 InputBuffer ReadMessage();
167 void WriteMessage(OutputBuffer& message); 153 void WriteMessage(OutputBuffer& message);
168 154
169 protected: 155 protected:
170 HANDLE pipe; 156 HANDLE pipe;
171 }; 157 };
172 } 158 }
173 159
174 #endif 160 #endif
OLDNEW
« no previous file with comments | « no previous file | src/shared/Communication.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld