Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(158)

Side by Side Diff: runtime/vm/json_stream.h

Issue 2481873005: clang-format runtime/vm (Closed)
Patch Set: Merge Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « runtime/vm/jit_optimizer.cc ('k') | runtime/vm/json_stream.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 RUNTIME_VM_JSON_STREAM_H_ 5 #ifndef RUNTIME_VM_JSON_STREAM_H_
6 #define RUNTIME_VM_JSON_STREAM_H_ 6 #define RUNTIME_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/text_buffer.h" 9 #include "platform/text_buffer.h"
10 #include "vm/allocation.h" 10 #include "vm/allocation.h"
(...skipping 21 matching lines...) Expand all
32 class TimelineEventBlock; 32 class TimelineEventBlock;
33 class Zone; 33 class Zone;
34 34
35 35
36 // Keep this enum in sync with: 36 // Keep this enum in sync with:
37 // 37 //
38 // - runtime/vm/service/vmservice.dart 38 // - runtime/vm/service/vmservice.dart
39 // - runtime/observatory/lib/src/service/object.dart 39 // - runtime/observatory/lib/src/service/object.dart
40 // 40 //
41 enum JSONRpcErrorCode { 41 enum JSONRpcErrorCode {
42 kParseError = -32700, 42 kParseError = -32700,
43 kInvalidRequest = -32600, 43 kInvalidRequest = -32600,
44 kMethodNotFound = -32601, 44 kMethodNotFound = -32601,
45 kInvalidParams = -32602, 45 kInvalidParams = -32602,
46 kInternalError = -32603, 46 kInternalError = -32603,
47 47
48 kExtensionError = -32000, 48 kExtensionError = -32000,
49 49
50 kFeatureDisabled = 100, 50 kFeatureDisabled = 100,
51 kCannotAddBreakpoint = 102, 51 kCannotAddBreakpoint = 102,
52 kStreamAlreadySubscribed = 103, 52 kStreamAlreadySubscribed = 103,
53 kStreamNotSubscribed = 104, 53 kStreamNotSubscribed = 104,
54 kIsolateMustBeRunnable = 105, 54 kIsolateMustBeRunnable = 105,
55 kIsolateMustBePaused = 106, 55 kIsolateMustBePaused = 106,
56 56
57 // Experimental (used in private rpcs). 57 // Experimental (used in private rpcs).
58 kIsolateIsReloading = 1000, 58 kIsolateIsReloading = 1000,
59 kFileSystemAlreadyExists = 1001, 59 kFileSystemAlreadyExists = 1001,
60 kFileSystemDoesNotExist = 1002, 60 kFileSystemDoesNotExist = 1002,
61 kFileDoesNotExist = 1003, 61 kFileDoesNotExist = 1003,
62 kIsolateReloadFailed = 1004, 62 kIsolateReloadFailed = 1004,
63 kIsolateReloadBarred = 1005, 63 kIsolateReloadBarred = 1005,
64 }; 64 };
65 65
66 // Expected that user_data is a JSONStream*. 66 // Expected that user_data is a JSONStream*.
67 void AppendJSONStreamConsumer(Dart_StreamConsumer_State state, 67 void AppendJSONStreamConsumer(Dart_StreamConsumer_State state,
68 const char* stream_name, 68 const char* stream_name,
69 const uint8_t* buffer, 69 const uint8_t* buffer,
70 intptr_t buffer_length, 70 intptr_t buffer_length,
71 void* user_data); 71 void* user_data);
72 72
73 class JSONStream : ValueObject { 73 class JSONStream : ValueObject {
74 public: 74 public:
75 explicit JSONStream(intptr_t buf_size = 256); 75 explicit JSONStream(intptr_t buf_size = 256);
76 ~JSONStream(); 76 ~JSONStream();
77 77
78 void Setup(Zone* zone, 78 void Setup(Zone* zone,
79 Dart_Port reply_port, 79 Dart_Port reply_port,
80 const Instance& seq, 80 const Instance& seq,
81 const String& method, 81 const String& method,
82 const Array& param_keys, 82 const Array& param_keys,
83 const Array& param_values, 83 const Array& param_values,
84 bool parameters_are_dart_objects = false); 84 bool parameters_are_dart_objects = false);
85 void SetupError(); 85 void SetupError();
86 86
87 void PrintError(intptr_t code, const char* details_format, ...); 87 void PrintError(intptr_t code, const char* details_format, ...);
88 88
89 void PostReply(); 89 void PostReply();
90 90
91 void set_id_zone(ServiceIdZone* id_zone) { 91 void set_id_zone(ServiceIdZone* id_zone) { id_zone_ = id_zone; }
92 id_zone_ = id_zone; 92 ServiceIdZone* id_zone() { return id_zone_; }
93 }
94 ServiceIdZone* id_zone() {
95 return id_zone_;
96 }
97 93
98 TextBuffer* buffer() { return &buffer_; } 94 TextBuffer* buffer() { return &buffer_; }
99 const char* ToCString() { return buffer_.buf(); } 95 const char* ToCString() { return buffer_.buf(); }
100 96
101 void Steal(char** buffer, intptr_t* buffer_length); 97 void Steal(char** buffer, intptr_t* buffer_length);
102 98
103 void set_reply_port(Dart_Port port); 99 void set_reply_port(Dart_Port port);
104 100
105 void SetParams(const char** param_keys, const char** param_values, 101 void SetParams(const char** param_keys,
102 const char** param_values,
106 intptr_t num_params); 103 intptr_t num_params);
107 104
108 Dart_Port reply_port() const { return reply_port_; } 105 Dart_Port reply_port() const { return reply_port_; }
109 106
110 intptr_t NumObjectParameters() const; 107 intptr_t NumObjectParameters() const;
111 RawObject* GetObjectParameterKey(intptr_t i) const; 108 RawObject* GetObjectParameterKey(intptr_t i) const;
112 RawObject* GetObjectParameterValue(intptr_t i) const; 109 RawObject* GetObjectParameterValue(intptr_t i) const;
113 RawObject* LookupObjectParam(const char* key) const; 110 RawObject* LookupObjectParam(const char* key) const;
114 111
115 intptr_t num_params() const { return num_params_; } 112 intptr_t num_params() const { return num_params_; }
116 const char* GetParamKey(intptr_t i) const { 113 const char* GetParamKey(intptr_t i) const { return param_keys_[i]; }
117 return param_keys_[i]; 114 const char* GetParamValue(intptr_t i) const { return param_values_[i]; }
118 }
119 const char* GetParamValue(intptr_t i) const {
120 return param_values_[i];
121 }
122 115
123 const char* LookupParam(const char* key) const; 116 const char* LookupParam(const char* key) const;
124 117
125 bool HasParam(const char* key) const; 118 bool HasParam(const char* key) const;
126 119
127 // Returns true if there is an param with key and value, false 120 // Returns true if there is an param with key and value, false
128 // otherwise. 121 // otherwise.
129 bool ParamIs(const char* key, const char* value) const; 122 bool ParamIs(const char* key, const char* value) const;
130 123
131 const char* method() const { return method_; } 124 const char* method() const { return method_; }
(...skipping 13 matching lines...) Expand all
145 void ComputeOffsetAndCount(intptr_t length, 138 void ComputeOffsetAndCount(intptr_t length,
146 intptr_t* offset, 139 intptr_t* offset,
147 intptr_t* count); 140 intptr_t* count);
148 141
149 // Append |serialized_object| to the stream. 142 // Append |serialized_object| to the stream.
150 void AppendSerializedObject(const char* serialized_object); 143 void AppendSerializedObject(const char* serialized_object);
151 144
152 void PrintCommaIfNeeded(); 145 void PrintCommaIfNeeded();
153 146
154 // Append |buffer| to the stream. 147 // Append |buffer| to the stream.
155 void AppendSerializedObject(const uint8_t* buffer, 148 void AppendSerializedObject(const uint8_t* buffer, intptr_t buffer_length);
156 intptr_t buffer_length);
157 149
158 // Append |serialized_object| to the stream with |property_name|. 150 // Append |serialized_object| to the stream with |property_name|.
159 void AppendSerializedObject(const char* property_name, 151 void AppendSerializedObject(const char* property_name,
160 const char* serialized_object); 152 const char* serialized_object);
161 153
162 private: 154 private:
163 void Clear(); 155 void Clear();
164 void PostNullReply(Dart_Port port); 156 void PostNullReply(Dart_Port port);
165 157
166 void OpenObject(const char* property_name = NULL); 158 void OpenObject(const char* property_name = NULL);
(...skipping 30 matching lines...) Expand all
197 void PrintPropertyBool(const char* name, bool b); 189 void PrintPropertyBool(const char* name, bool b);
198 void PrintProperty(const char* name, intptr_t i); 190 void PrintProperty(const char* name, intptr_t i);
199 void PrintProperty64(const char* name, int64_t i); 191 void PrintProperty64(const char* name, int64_t i);
200 void PrintPropertyTimeMillis(const char* name, int64_t millis); 192 void PrintPropertyTimeMillis(const char* name, int64_t millis);
201 void PrintPropertyTimeMicros(const char* name, int64_t micros); 193 void PrintPropertyTimeMicros(const char* name, int64_t micros);
202 void PrintProperty(const char* name, double d); 194 void PrintProperty(const char* name, double d);
203 void PrintPropertyBase64(const char* name, 195 void PrintPropertyBase64(const char* name,
204 const uint8_t* bytes, 196 const uint8_t* bytes,
205 intptr_t length); 197 intptr_t length);
206 void PrintProperty(const char* name, const char* s); 198 void PrintProperty(const char* name, const char* s);
207 bool PrintPropertyStr(const char* name, const String& s, 199 bool PrintPropertyStr(const char* name,
208 intptr_t offset, intptr_t count); 200 const String& s,
201 intptr_t offset,
202 intptr_t count);
209 void PrintPropertyNoEscape(const char* name, const char* s); 203 void PrintPropertyNoEscape(const char* name, const char* s);
210 void PrintfProperty(const char* name, const char* format, ...) 204 void PrintfProperty(const char* name, const char* format, ...)
211 PRINTF_ATTRIBUTE(3, 4); 205 PRINTF_ATTRIBUTE(3, 4);
212 void PrintProperty(const char* name, const Object& o, bool ref = true); 206 void PrintProperty(const char* name, const Object& o, bool ref = true);
213 207
214 void PrintProperty(const char* name, const ServiceEvent* event); 208 void PrintProperty(const char* name, const ServiceEvent* event);
215 void PrintProperty(const char* name, Breakpoint* bpt); 209 void PrintProperty(const char* name, Breakpoint* bpt);
216 void PrintProperty(const char* name, TokenPosition tp); 210 void PrintProperty(const char* name, TokenPosition tp);
217 void PrintProperty(const char* name, Metric* metric); 211 void PrintProperty(const char* name, Metric* metric);
218 void PrintProperty(const char* name, MessageQueue* queue); 212 void PrintProperty(const char* name, MessageQueue* queue);
219 void PrintProperty(const char* name, Isolate* isolate); 213 void PrintProperty(const char* name, Isolate* isolate);
220 void PrintProperty(const char* name, const TimelineEvent* timeline_event); 214 void PrintProperty(const char* name, const TimelineEvent* timeline_event);
221 void PrintProperty(const char* name, 215 void PrintProperty(const char* name,
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 class JSONObject : public ValueObject { 252 class JSONObject : public ValueObject {
259 public: 253 public:
260 explicit JSONObject(JSONStream* stream) : stream_(stream) { 254 explicit JSONObject(JSONStream* stream) : stream_(stream) {
261 stream_->OpenObject(); 255 stream_->OpenObject();
262 } 256 }
263 JSONObject(const JSONObject* obj, const char* name) : stream_(obj->stream_) { 257 JSONObject(const JSONObject* obj, const char* name) : stream_(obj->stream_) {
264 stream_->OpenObject(name); 258 stream_->OpenObject(name);
265 } 259 }
266 explicit JSONObject(const JSONArray* arr); 260 explicit JSONObject(const JSONArray* arr);
267 261
268 ~JSONObject() { 262 ~JSONObject() { stream_->CloseObject(); }
269 stream_->CloseObject();
270 }
271 263
272 void AddServiceId(const Object& o) const { 264 void AddServiceId(const Object& o) const { stream_->PrintServiceId(o); }
273 stream_->PrintServiceId(o);
274 }
275 265
276 void AddFixedServiceId(const char* format, ...) const PRINTF_ATTRIBUTE(2, 3); 266 void AddFixedServiceId(const char* format, ...) const PRINTF_ATTRIBUTE(2, 3);
277 267
278 void AddLocation( 268 void AddLocation(
279 const Script& script, 269 const Script& script,
280 TokenPosition token_pos, 270 TokenPosition token_pos,
281 TokenPosition end_token_pos = TokenPosition::kNoSource) const; 271 TokenPosition end_token_pos = TokenPosition::kNoSource) const;
282 272
283 void AddLocation(const BreakpointLocation* bpt_loc) const; 273 void AddLocation(const BreakpointLocation* bpt_loc) const;
284 274
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
368 public: 358 public:
369 explicit JSONArray(JSONStream* stream) : stream_(stream) { 359 explicit JSONArray(JSONStream* stream) : stream_(stream) {
370 stream_->OpenArray(); 360 stream_->OpenArray();
371 } 361 }
372 JSONArray(const JSONObject* obj, const char* name) : stream_(obj->stream_) { 362 JSONArray(const JSONObject* obj, const char* name) : stream_(obj->stream_) {
373 stream_->OpenArray(name); 363 stream_->OpenArray(name);
374 } 364 }
375 explicit JSONArray(const JSONArray* arr) : stream_(arr->stream_) { 365 explicit JSONArray(const JSONArray* arr) : stream_(arr->stream_) {
376 stream_->OpenArray(); 366 stream_->OpenArray();
377 } 367 }
378 ~JSONArray() { 368 ~JSONArray() { stream_->CloseArray(); }
379 stream_->CloseArray();
380 }
381 369
382 void AddValueNull() const { stream_->PrintValueNull(); } 370 void AddValueNull() const { stream_->PrintValueNull(); }
383 void AddValue(bool b) const { stream_->PrintValueBool(b); } 371 void AddValue(bool b) const { stream_->PrintValueBool(b); }
384 void AddValue(intptr_t i) const { stream_->PrintValue(i); } 372 void AddValue(intptr_t i) const { stream_->PrintValue(i); }
385 void AddValue64(int64_t i) const { stream_->PrintValue64(i); } 373 void AddValue64(int64_t i) const { stream_->PrintValue64(i); }
386 void AddValueTimeMillis(int64_t millis) const { 374 void AddValueTimeMillis(int64_t millis) const {
387 stream_->PrintValueTimeMillis(millis); 375 stream_->PrintValueTimeMillis(millis);
388 } 376 }
389 void AddValueTimeMicros(int64_t micros) const { 377 void AddValueTimeMicros(int64_t micros) const {
390 stream_->PrintValueTimeMicros(micros); 378 stream_->PrintValueTimeMicros(micros);
391 } 379 }
392 void AddValue(double d) const { stream_->PrintValue(d); } 380 void AddValue(double d) const { stream_->PrintValue(d); }
393 void AddValue(const char* s) const { stream_->PrintValue(s); } 381 void AddValue(const char* s) const { stream_->PrintValue(s); }
394 void AddValue(const Object& obj, bool ref = true) const { 382 void AddValue(const Object& obj, bool ref = true) const {
395 stream_->PrintValue(obj, ref); 383 stream_->PrintValue(obj, ref);
396 } 384 }
397 void AddValue(Isolate* isolate, bool ref = true) const { 385 void AddValue(Isolate* isolate, bool ref = true) const {
398 stream_->PrintValue(isolate, ref); 386 stream_->PrintValue(isolate, ref);
399 } 387 }
400 void AddValue(Breakpoint* bpt) const { 388 void AddValue(Breakpoint* bpt) const { stream_->PrintValue(bpt); }
401 stream_->PrintValue(bpt); 389 void AddValue(TokenPosition tp) const { stream_->PrintValue(tp); }
402 } 390 void AddValue(const ServiceEvent* event) const { stream_->PrintValue(event); }
403 void AddValue(TokenPosition tp) const { 391 void AddValue(Metric* metric) const { stream_->PrintValue(metric); }
404 stream_->PrintValue(tp); 392 void AddValue(MessageQueue* queue) const { stream_->PrintValue(queue); }
405 }
406 void AddValue(const ServiceEvent* event) const {
407 stream_->PrintValue(event);
408 }
409 void AddValue(Metric* metric) const {
410 stream_->PrintValue(metric);
411 }
412 void AddValue(MessageQueue* queue) const {
413 stream_->PrintValue(queue);
414 }
415 void AddValue(const TimelineEvent* timeline_event) const { 393 void AddValue(const TimelineEvent* timeline_event) const {
416 stream_->PrintValue(timeline_event); 394 stream_->PrintValue(timeline_event);
417 } 395 }
418 void AddValue(const TimelineEventBlock* timeline_event_block) const { 396 void AddValue(const TimelineEventBlock* timeline_event_block) const {
419 stream_->PrintValue(timeline_event_block); 397 stream_->PrintValue(timeline_event_block);
420 } 398 }
421 void AddValueVM(bool ref = true) const { 399 void AddValueVM(bool ref = true) const { stream_->PrintValueVM(ref); }
422 stream_->PrintValueVM(ref);
423 }
424 void AddValueF(const char* format, ...) const PRINTF_ATTRIBUTE(2, 3); 400 void AddValueF(const char* format, ...) const PRINTF_ATTRIBUTE(2, 3);
425 401
426 private: 402 private:
427 JSONStream* stream_; 403 JSONStream* stream_;
428 404
429 friend class JSONObject; 405 friend class JSONObject;
430 406
431 DISALLOW_ALLOCATION(); 407 DISALLOW_ALLOCATION();
432 DISALLOW_COPY_AND_ASSIGN(JSONArray); 408 DISALLOW_COPY_AND_ASSIGN(JSONArray);
433 }; 409 };
434 410
435 } // namespace dart 411 } // namespace dart
436 412
437 #endif // RUNTIME_VM_JSON_STREAM_H_ 413 #endif // RUNTIME_VM_JSON_STREAM_H_
OLDNEW
« no previous file with comments | « runtime/vm/jit_optimizer.cc ('k') | runtime/vm/json_stream.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698