Chromium Code Reviews| 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" |
| 11 #include "vm/service.h" | |
| 11 | 12 |
| 12 namespace dart { | 13 namespace dart { |
| 13 | 14 |
| 14 class Array; | 15 class Array; |
| 15 class Field; | 16 class Field; |
| 16 class GrowableObjectArray; | 17 class GrowableObjectArray; |
| 17 class Instance; | 18 class Instance; |
| 18 class JSONArray; | 19 class JSONArray; |
| 19 class JSONObject; | 20 class JSONObject; |
| 20 class MessageQueue; | 21 class MessageQueue; |
| 21 class Metric; | 22 class Metric; |
| 22 class Object; | 23 class Object; |
| 24 class RingIdZone; | |
| 23 class ServiceEvent; | 25 class ServiceEvent; |
| 26 class ServiceIdZone; | |
| 24 class SourceBreakpoint; | 27 class SourceBreakpoint; |
| 25 class String; | 28 class String; |
| 26 class Zone; | 29 class Zone; |
| 27 | 30 |
| 28 class JSONStream : ValueObject { | 31 class JSONStream : ValueObject { |
| 29 public: | 32 public: |
| 30 explicit JSONStream(intptr_t buf_size = 256); | 33 explicit JSONStream(intptr_t buf_size = 256); |
| 31 ~JSONStream(); | 34 ~JSONStream(); |
| 32 | 35 |
| 33 void Setup(Zone* zone, | 36 void Setup(Zone* zone, |
| 34 Dart_Port reply_port, | 37 Dart_Port reply_port, |
| 35 const String& seq, | 38 const String& seq, |
| 36 const String& method, | 39 const String& method, |
| 37 const Array& param_keys, | 40 const Array& param_keys, |
| 38 const Array& param_values); | 41 const Array& param_values); |
| 39 void SetupError(); | 42 void SetupError(); |
| 40 | 43 |
| 41 void PostReply(); | 44 void PostReply(); |
| 42 | 45 |
| 46 void set_service_id_zone(ServiceIdZone* service_id_zone) { | |
| 47 service_id_zone_ = service_id_zone; | |
| 48 } | |
| 49 ServiceIdZone* service_id_zone() { | |
| 50 return service_id_zone_; | |
| 51 } | |
| 52 | |
| 43 TextBuffer* buffer() { return &buffer_; } | 53 TextBuffer* buffer() { return &buffer_; } |
| 44 const char* ToCString() { return buffer_.buf(); } | 54 const char* ToCString() { return buffer_.buf(); } |
| 45 | 55 |
| 46 void set_reply_port(Dart_Port port); | 56 void set_reply_port(Dart_Port port); |
| 47 | 57 |
| 48 void SetParams(const char** param_keys, const char** param_values, | 58 void SetParams(const char** param_keys, const char** param_values, |
| 49 intptr_t num_params); | 59 intptr_t num_params); |
| 50 | 60 |
| 51 Dart_Port reply_port() const { return reply_port_; } | 61 Dart_Port reply_port() const { return reply_port_; } |
| 52 | 62 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 89 void PrintValueNoEscape(const char* s); | 99 void PrintValueNoEscape(const char* s); |
| 90 void PrintfValue(const char* format, ...) PRINTF_ATTRIBUTE(2, 3); | 100 void PrintfValue(const char* format, ...) PRINTF_ATTRIBUTE(2, 3); |
| 91 void PrintValue(const Object& o, bool ref = true); | 101 void PrintValue(const Object& o, bool ref = true); |
| 92 void PrintValue(SourceBreakpoint* bpt); | 102 void PrintValue(SourceBreakpoint* bpt); |
| 93 void PrintValue(const ServiceEvent* event); | 103 void PrintValue(const ServiceEvent* event); |
| 94 void PrintValue(Metric* metric); | 104 void PrintValue(Metric* metric); |
| 95 void PrintValue(MessageQueue* queue); | 105 void PrintValue(MessageQueue* queue); |
| 96 void PrintValue(Isolate* isolate, bool ref = true); | 106 void PrintValue(Isolate* isolate, bool ref = true); |
| 97 bool PrintValueStr(const String& s, intptr_t limit); | 107 bool PrintValueStr(const String& s, intptr_t limit); |
| 98 | 108 |
| 109 void PrintServiceId(const char* name, const Object& o); | |
| 99 void PrintPropertyBool(const char* name, bool b); | 110 void PrintPropertyBool(const char* name, bool b); |
| 100 void PrintProperty(const char* name, intptr_t i); | 111 void PrintProperty(const char* name, intptr_t i); |
| 101 void PrintProperty64(const char* name, int64_t i); | 112 void PrintProperty64(const char* name, int64_t i); |
| 102 void PrintProperty(const char* name, double d); | 113 void PrintProperty(const char* name, double d); |
| 103 void PrintProperty(const char* name, const char* s); | 114 void PrintProperty(const char* name, const char* s); |
| 104 bool PrintPropertyStr(const char* name, const String& s, intptr_t limit); | 115 bool PrintPropertyStr(const char* name, const String& s, intptr_t limit); |
| 105 void PrintPropertyNoEscape(const char* name, const char* s); | 116 void PrintPropertyNoEscape(const char* name, const char* s); |
| 106 void PrintfProperty(const char* name, const char* format, ...) | 117 void PrintfProperty(const char* name, const char* format, ...) |
| 107 PRINTF_ATTRIBUTE(3, 4); | 118 PRINTF_ATTRIBUTE(3, 4); |
| 108 void PrintProperty(const char* name, const Object& o, bool ref = true); | 119 void PrintProperty(const char* name, const Object& o, bool ref = true); |
| 109 | 120 |
| 110 void PrintProperty(const char* name, const ServiceEvent* event); | 121 void PrintProperty(const char* name, const ServiceEvent* event); |
| 111 void PrintProperty(const char* name, SourceBreakpoint* bpt); | 122 void PrintProperty(const char* name, SourceBreakpoint* bpt); |
| 112 void PrintProperty(const char* name, Metric* metric); | 123 void PrintProperty(const char* name, Metric* metric); |
| 113 void PrintProperty(const char* name, MessageQueue* queue); | 124 void PrintProperty(const char* name, MessageQueue* queue); |
| 114 void PrintProperty(const char* name, Isolate* isolate); | 125 void PrintProperty(const char* name, Isolate* isolate); |
| 115 void PrintPropertyName(const char* name); | 126 void PrintPropertyName(const char* name); |
| 116 void PrintCommaIfNeeded(); | 127 void PrintCommaIfNeeded(); |
| 117 bool NeedComma(); | 128 bool NeedComma(); |
| 118 | 129 |
| 119 bool AddDartString(const String& s, intptr_t limit); | 130 bool AddDartString(const String& s, intptr_t limit); |
| 120 void AddEscapedUTF8String(const char* s); | 131 void AddEscapedUTF8String(const char* s); |
| 121 void AddEscapedUTF8String(const char* s, intptr_t len); | 132 void AddEscapedUTF8String(const char* s, intptr_t len); |
| 122 | 133 |
| 123 intptr_t nesting_level() const { return open_objects_; } | 134 intptr_t nesting_level() const { return open_objects_; } |
| 124 | 135 |
| 125 intptr_t open_objects_; | 136 intptr_t open_objects_; |
| 126 TextBuffer buffer_; | 137 TextBuffer buffer_; |
| 138 // Default service id zone. | |
| 139 RingServiceIdZone ring_service_id_zone_; | |
|
turnidge
2015/05/11 19:48:45
Call this default_service_id_zone? Also, stray sp
turnidge
2015/05/11 20:01:04
Or default_id_zone.
Cutch
2015/05/12 14:59:56
Done.
| |
| 140 ServiceIdZone* service_id_zone_; | |
| 127 Dart_Port reply_port_; | 141 Dart_Port reply_port_; |
| 128 const char* seq_; | 142 const char* seq_; |
| 129 const char* method_; | 143 const char* method_; |
| 130 const char** param_keys_; | 144 const char** param_keys_; |
| 131 const char** param_values_; | 145 const char** param_values_; |
| 132 intptr_t num_params_; | 146 intptr_t num_params_; |
| 133 int64_t setup_time_micros_; | 147 int64_t setup_time_micros_; |
| 134 | 148 |
| 135 friend class JSONObject; | 149 friend class JSONObject; |
| 136 friend class JSONArray; | 150 friend class JSONArray; |
| 137 }; | 151 }; |
| 138 | 152 |
| 139 | 153 |
| 140 class JSONObject : public ValueObject { | 154 class JSONObject : public ValueObject { |
| 141 public: | 155 public: |
| 142 explicit JSONObject(JSONStream* stream) : stream_(stream) { | 156 explicit JSONObject(JSONStream* stream) : stream_(stream) { |
| 143 stream_->OpenObject(); | 157 stream_->OpenObject(); |
| 144 } | 158 } |
| 145 JSONObject(const JSONObject* obj, const char* name) : stream_(obj->stream_) { | 159 JSONObject(const JSONObject* obj, const char* name) : stream_(obj->stream_) { |
| 146 stream_->OpenObject(name); | 160 stream_->OpenObject(name); |
| 147 } | 161 } |
| 148 explicit JSONObject(const JSONArray* arr); | 162 explicit JSONObject(const JSONArray* arr); |
| 149 | 163 |
| 150 ~JSONObject() { | 164 ~JSONObject() { |
| 151 stream_->CloseObject(); | 165 stream_->CloseObject(); |
| 152 } | 166 } |
| 153 | 167 |
| 168 void AddServiceId(const char* name, const Object& o) const { | |
| 169 stream_->PrintServiceId(name, o); | |
| 170 } | |
| 171 | |
| 154 void AddProperty(const char* name, bool b) const { | 172 void AddProperty(const char* name, bool b) const { |
| 155 stream_->PrintPropertyBool(name, b); | 173 stream_->PrintPropertyBool(name, b); |
| 156 } | 174 } |
| 157 void AddProperty(const char* name, intptr_t i) const { | 175 void AddProperty(const char* name, intptr_t i) const { |
| 158 stream_->PrintProperty(name, i); | 176 stream_->PrintProperty(name, i); |
| 159 } | 177 } |
| 160 void AddProperty64(const char* name, int64_t i) const { | 178 void AddProperty64(const char* name, int64_t i) const { |
| 161 stream_->PrintProperty64(name, i); | 179 stream_->PrintProperty64(name, i); |
| 162 } | 180 } |
| 163 void AddProperty(const char* name, double d) const { | 181 void AddProperty(const char* name, double d) const { |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 250 | 268 |
| 251 friend class JSONObject; | 269 friend class JSONObject; |
| 252 | 270 |
| 253 DISALLOW_ALLOCATION(); | 271 DISALLOW_ALLOCATION(); |
| 254 DISALLOW_COPY_AND_ASSIGN(JSONArray); | 272 DISALLOW_COPY_AND_ASSIGN(JSONArray); |
| 255 }; | 273 }; |
| 256 | 274 |
| 257 } // namespace dart | 275 } // namespace dart |
| 258 | 276 |
| 259 #endif // VM_JSON_STREAM_H_ | 277 #endif // VM_JSON_STREAM_H_ |
| OLD | NEW |