OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #ifndef VM_JSON_STREAM_H_ | 5 #ifndef VM_JSON_STREAM_H_ |
6 #define VM_JSON_STREAM_H_ | 6 #define VM_JSON_STREAM_H_ |
7 | 7 |
8 #include "include/dart_api.h" // for Dart_Port | 8 #include "include/dart_api.h" // for Dart_Port |
9 #include "platform/json.h" | 9 #include "platform/json.h" |
10 #include "vm/allocation.h" | 10 #include "vm/allocation.h" |
(...skipping 13 matching lines...) Expand all Loading... |
24 class Metric; | 24 class Metric; |
25 class Zone; | 25 class Zone; |
26 | 26 |
27 class JSONStream : ValueObject { | 27 class JSONStream : ValueObject { |
28 public: | 28 public: |
29 explicit JSONStream(intptr_t buf_size = 256); | 29 explicit JSONStream(intptr_t buf_size = 256); |
30 ~JSONStream(); | 30 ~JSONStream(); |
31 | 31 |
32 void Setup(Zone* zone, | 32 void Setup(Zone* zone, |
33 Dart_Port reply_port, | 33 Dart_Port reply_port, |
34 const GrowableObjectArray& path, | 34 const String& method, |
35 const Array& option_keys, | 35 const Array& param_keys, |
36 const Array& option_values); | 36 const Array& param_values); |
37 | |
38 void SetupNew(Zone* zone, | |
39 Dart_Port reply_port, | |
40 const String& method, | |
41 const Array& param_keys, | |
42 const Array& param_values); | |
43 | 37 |
44 void PostReply(); | 38 void PostReply(); |
45 | 39 |
46 TextBuffer* buffer() { return &buffer_; } | 40 TextBuffer* buffer() { return &buffer_; } |
47 const char* ToCString() { return buffer_.buf(); } | 41 const char* ToCString() { return buffer_.buf(); } |
48 | 42 |
49 void set_reply_port(Dart_Port port); | 43 void set_reply_port(Dart_Port port); |
50 void SetArguments(const char** arguments, intptr_t num_arguments); | 44 |
51 void SetOptions(const char** option_keys, const char** option_values, | 45 void SetParams(const char** param_keys, const char** param_values, |
52 intptr_t num_options); | 46 intptr_t num_params); |
53 | 47 |
54 Dart_Port reply_port() const { return reply_port_; } | 48 Dart_Port reply_port() const { return reply_port_; } |
55 | 49 |
56 intptr_t num_arguments() const { return num_arguments_; } | 50 intptr_t num_params() const { return num_params_; } |
57 const char* GetArgument(intptr_t i) const { | 51 const char* GetParamKey(intptr_t i) const { |
58 return arguments_[i]; | 52 return param_keys_[i]; |
| 53 } |
| 54 const char* GetParamValue(intptr_t i) const { |
| 55 return param_values_[i]; |
59 } | 56 } |
60 | 57 |
61 // TODO(turnidge): Rename "options" to "params". That is the more | 58 const char* LookupParam(const char* key) const; |
62 // appropriate name for json rpc. | |
63 intptr_t num_options() const { return num_options_; } | |
64 const char* GetOptionKey(intptr_t i) const { | |
65 return option_keys_[i]; | |
66 } | |
67 const char* GetOptionValue(intptr_t i) const { | |
68 return option_values_[i]; | |
69 } | |
70 | 59 |
71 const char* LookupOption(const char* key) const; | 60 bool HasParam(const char* key) const; |
72 | 61 |
73 bool HasOption(const char* key) const; | 62 // Returns true if there is an param with key and value, false |
| 63 // otherwise. |
| 64 bool ParamIs(const char* key, const char* value) const; |
74 | 65 |
75 // Returns true if there is an option with key and value, false | 66 const char* method() const { return method_; } |
76 // otherwise. | 67 const char** param_keys() const { return param_keys_; } |
77 bool OptionIs(const char* key, const char* value) const; | 68 const char** param_values() const { return param_values_; } |
78 | |
79 // TODO(turnidge): Rename "command" to "method". Better name for json rpc. | |
80 const char* command() const { return command_; } | |
81 const char** arguments() const { return arguments_; } | |
82 const char** option_keys() const { return option_keys_; } | |
83 const char** option_values() const { return option_values_; } | |
84 | 69 |
85 private: | 70 private: |
86 void Clear(); | 71 void Clear(); |
87 | 72 |
88 void OpenObject(const char* property_name = NULL); | 73 void OpenObject(const char* property_name = NULL); |
89 void CloseObject(); | 74 void CloseObject(); |
90 | 75 |
91 void OpenArray(const char* property_name = NULL); | 76 void OpenArray(const char* property_name = NULL); |
92 void CloseArray(); | 77 void CloseArray(); |
93 | 78 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 | 112 |
128 bool AddDartString(const String& s, intptr_t limit); | 113 bool AddDartString(const String& s, intptr_t limit); |
129 void AddEscapedUTF8String(const char* s); | 114 void AddEscapedUTF8String(const char* s); |
130 void AddEscapedUTF8String(const char* s, intptr_t len); | 115 void AddEscapedUTF8String(const char* s, intptr_t len); |
131 | 116 |
132 intptr_t nesting_level() const { return open_objects_; } | 117 intptr_t nesting_level() const { return open_objects_; } |
133 | 118 |
134 intptr_t open_objects_; | 119 intptr_t open_objects_; |
135 TextBuffer buffer_; | 120 TextBuffer buffer_; |
136 Dart_Port reply_port_; | 121 Dart_Port reply_port_; |
137 const char* command_; | 122 const char* method_; |
138 const char** arguments_; | 123 const char** param_keys_; |
139 intptr_t num_arguments_; | 124 const char** param_values_; |
140 const char** option_keys_; | 125 intptr_t num_params_; |
141 const char** option_values_; | |
142 intptr_t num_options_; | |
143 int64_t setup_time_micros_; | 126 int64_t setup_time_micros_; |
144 | 127 |
145 friend class JSONObject; | 128 friend class JSONObject; |
146 friend class JSONArray; | 129 friend class JSONArray; |
147 }; | 130 }; |
148 | 131 |
149 | 132 |
150 class JSONObject : public ValueObject { | 133 class JSONObject : public ValueObject { |
151 public: | 134 public: |
152 explicit JSONObject(JSONStream* stream) : stream_(stream) { | 135 explicit JSONObject(JSONStream* stream) : stream_(stream) { |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
254 | 237 |
255 friend class JSONObject; | 238 friend class JSONObject; |
256 | 239 |
257 DISALLOW_ALLOCATION(); | 240 DISALLOW_ALLOCATION(); |
258 DISALLOW_COPY_AND_ASSIGN(JSONArray); | 241 DISALLOW_COPY_AND_ASSIGN(JSONArray); |
259 }; | 242 }; |
260 | 243 |
261 } // namespace dart | 244 } // namespace dart |
262 | 245 |
263 #endif // VM_JSON_STREAM_H_ | 246 #endif // VM_JSON_STREAM_H_ |
OLD | NEW |