Skip to content

Commit 13b1af4

Browse files
devoncarewcommit-bot@chromium.org
authored andcommitted
[pkg/dds] refactor parts into private libraries
Change-Id: Ic104627b676119742606f7b34b025c6f0d093db0 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/176600 Reviewed-by: Ben Konyi <[email protected]> Commit-Queue: Devon Carew <[email protected]>
1 parent df7473e commit 13b1af4

14 files changed

+261
-201
lines changed

pkg/dds/analysis_options.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
include: package:pedantic/analysis_options.1.7.0.yaml
1+
include: package:pedantic/analysis_options.1.8.0.yaml
22

33
linter:
44
rules:

pkg/dds/lib/dds.dart

+7-33
Original file line numberDiff line numberDiff line change
@@ -7,35 +7,9 @@
77
library dds;
88

99
import 'dart:async';
10-
import 'dart:collection';
11-
import 'dart:convert';
1210
import 'dart:io';
13-
import 'dart:math';
14-
import 'dart:typed_data';
15-
16-
import 'package:async/async.dart';
17-
import 'package:json_rpc_2/json_rpc_2.dart' as json_rpc;
18-
import 'package:meta/meta.dart';
19-
import 'package:pedantic/pedantic.dart';
20-
import 'package:shelf/shelf.dart';
21-
import 'package:shelf/shelf_io.dart' as io;
22-
import 'package:shelf_proxy/shelf_proxy.dart';
23-
import 'package:shelf_web_socket/shelf_web_socket.dart';
24-
import 'package:sse/server/sse_handler.dart';
25-
import 'package:stream_channel/stream_channel.dart';
26-
import 'package:web_socket_channel/web_socket_channel.dart';
27-
28-
part 'src/binary_compatible_peer.dart';
29-
part 'src/client.dart';
30-
part 'src/client_manager.dart';
31-
part 'src/constants.dart';
32-
part 'src/dds_impl.dart';
33-
part 'src/expression_evaluator.dart';
34-
part 'src/logging_repository.dart';
35-
part 'src/isolate_manager.dart';
36-
part 'src/named_lookup.dart';
37-
part 'src/rpc_error_codes.dart';
38-
part 'src/stream_manager.dart';
11+
12+
import 'src/dds_impl.dart';
3913

4014
/// An intermediary between a Dart VM service and its clients that offers
4115
/// additional functionality on top of the standard VM service protocol.
@@ -99,7 +73,7 @@ abstract class DartDevelopmentService {
9973
}
10074
}
10175

102-
final service = _DartDevelopmentService(
76+
final service = DartDevelopmentServiceImpl(
10377
remoteVmServiceUri,
10478
serviceUri,
10579
enableAuthCodes,
@@ -171,22 +145,22 @@ class DartDevelopmentServiceException implements Exception {
171145
/// Set when a connection error has occurred after startup.
172146
static const int connectionError = 3;
173147

174-
factory DartDevelopmentServiceException._existingDdsInstanceError(
175-
String message) {
148+
factory DartDevelopmentServiceException.existingDdsInstance(String message) {
176149
return DartDevelopmentServiceException._(existingDdsInstanceError, message);
177150
}
178151

179-
factory DartDevelopmentServiceException._failedToStartError() {
152+
factory DartDevelopmentServiceException.failedToStart() {
180153
return DartDevelopmentServiceException._(
181154
failedToStartError, 'Failed to start Dart Development Service');
182155
}
183156

184-
factory DartDevelopmentServiceException._connectionError(String message) {
157+
factory DartDevelopmentServiceException.connectionIssue(String message) {
185158
return DartDevelopmentServiceException._(connectionError, message);
186159
}
187160

188161
DartDevelopmentServiceException._(this.errorCode, this.message);
189162

163+
@override
190164
String toString() => 'DartDevelopmentServiceException: $message';
191165

192166
final int errorCode;

pkg/dds/lib/src/binary_compatible_peer.dart

+14-5
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,16 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
part of dds;
5+
import 'dart:async';
6+
import 'dart:convert';
7+
import 'dart:typed_data';
8+
9+
import 'package:async/async.dart';
10+
import 'package:json_rpc_2/json_rpc_2.dart' as json_rpc;
11+
import 'package:stream_channel/stream_channel.dart';
12+
import 'package:web_socket_channel/web_socket_channel.dart';
13+
14+
import 'stream_manager.dart';
615

716
/// Adds support for binary events send from the VM service, which are not part
817
/// of the official JSON RPC 2.0 specification.
@@ -17,10 +26,10 @@ part of dds;
1726
/// ```
1827
/// where `metadata` is the JSON body of the event.
1928
///
20-
/// [_BinaryCompatiblePeer] assumes that only stream events can contain a
29+
/// [BinaryCompatiblePeer] assumes that only stream events can contain a
2130
/// binary payload (e.g., clients cannot send a `BinaryEvent` to the VM service).
22-
class _BinaryCompatiblePeer extends json_rpc.Peer {
23-
_BinaryCompatiblePeer(WebSocketChannel ws, _StreamManager streamManager)
31+
class BinaryCompatiblePeer extends json_rpc.Peer {
32+
BinaryCompatiblePeer(WebSocketChannel ws, StreamManager streamManager)
2433
: super(
2534
ws.transform<String>(
2635
StreamChannelTransformer(
@@ -39,7 +48,7 @@ class _BinaryCompatiblePeer extends json_rpc.Peer {
3948
);
4049

4150
static void _transformStream(
42-
_StreamManager streamManager, dynamic data, EventSink<String> sink) {
51+
StreamManager streamManager, dynamic data, EventSink<String> sink) {
4352
if (data is String) {
4453
// Non-binary messages come in as Strings. Simply forward to the sink.
4554
sink.add(data);

pkg/dds/lib/src/client.dart

+37-26
Original file line numberDiff line numberDiff line change
@@ -2,34 +2,46 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
part of dds;
5+
import 'dart:async';
6+
7+
import 'package:json_rpc_2/json_rpc_2.dart' as json_rpc;
8+
import 'package:meta/meta.dart';
9+
import 'package:sse/server/sse_handler.dart';
10+
import 'package:stream_channel/stream_channel.dart';
11+
import 'package:web_socket_channel/web_socket_channel.dart';
12+
13+
import '../dds.dart';
14+
import 'constants.dart';
15+
import 'dds_impl.dart';
16+
import 'rpc_error_codes.dart';
17+
import 'stream_manager.dart';
618

719
/// Representation of a single DDS client which manages the connection and
820
/// DDS request intercepting / forwarding.
9-
class _DartDevelopmentServiceClient {
10-
factory _DartDevelopmentServiceClient.fromWebSocket(
21+
class DartDevelopmentServiceClient {
22+
factory DartDevelopmentServiceClient.fromWebSocket(
1123
DartDevelopmentService dds,
1224
WebSocketChannel ws,
1325
json_rpc.Peer vmServicePeer,
1426
) =>
15-
_DartDevelopmentServiceClient._(
27+
DartDevelopmentServiceClient._(
1628
dds,
1729
ws,
1830
vmServicePeer,
1931
);
2032

21-
factory _DartDevelopmentServiceClient.fromSSEConnection(
33+
factory DartDevelopmentServiceClient.fromSSEConnection(
2234
DartDevelopmentService dds,
2335
SseConnection sse,
2436
json_rpc.Peer vmServicePeer,
2537
) =>
26-
_DartDevelopmentServiceClient._(
38+
DartDevelopmentServiceClient._(
2739
dds,
2840
sse,
2941
vmServicePeer,
3042
);
3143

32-
_DartDevelopmentServiceClient._(
44+
DartDevelopmentServiceClient._(
3345
this.dds,
3446
this.connection,
3547
json_rpc.Peer vmServicePeer,
@@ -39,7 +51,7 @@ class _DartDevelopmentServiceClient {
3951
// .cast<String>() as cast() results in addStream() being called,
4052
// binding the underlying sink. This results in a StateError being thrown
4153
// if we try and add directly to the sink, which we do for binary events
42-
// in _StreamManager's streamNotify().
54+
// in StreamManager's streamNotify().
4355
StreamChannel<String>(
4456
connection.stream.cast(),
4557
StreamController(sync: true)
@@ -88,21 +100,21 @@ class _DartDevelopmentServiceClient {
88100
_clientPeer.registerMethod('streamListen', (parameters) async {
89101
final streamId = parameters['streamId'].asString;
90102
await dds.streamManager.streamListen(this, streamId);
91-
return _RPCResponses.success;
103+
return RPCResponses.success;
92104
});
93105

94106
_clientPeer.registerMethod('streamCancel', (parameters) async {
95107
final streamId = parameters['streamId'].asString;
96108
await dds.streamManager.streamCancel(this, streamId);
97-
return _RPCResponses.success;
109+
return RPCResponses.success;
98110
});
99111

100112
_clientPeer.registerMethod('registerService', (parameters) async {
101113
final serviceId = parameters['service'].asString;
102114
final alias = parameters['alias'].asString;
103115
if (services.containsKey(serviceId)) {
104-
throw _RpcErrorCodes.buildRpcException(
105-
_RpcErrorCodes.kServiceAlreadyRegistered,
116+
throw RpcErrorCodes.buildRpcException(
117+
RpcErrorCodes.kServiceAlreadyRegistered,
106118
);
107119
}
108120
services[serviceId] = alias;
@@ -112,7 +124,7 @@ class _DartDevelopmentServiceClient {
112124
serviceId,
113125
alias,
114126
);
115-
return _RPCResponses.success;
127+
return RPCResponses.success;
116128
});
117129

118130
_clientPeer.registerMethod(
@@ -140,9 +152,8 @@ class _DartDevelopmentServiceClient {
140152
'getLogHistorySize',
141153
(parameters) => {
142154
'type': 'Size',
143-
'size': _StreamManager
144-
.loggingRepositories[_StreamManager.kLoggingStream]
145-
.bufferSize,
155+
'size': StreamManager
156+
.loggingRepositories[StreamManager.kLoggingStream].bufferSize,
146157
});
147158

148159
_clientPeer.registerMethod('setLogHistorySize', (parameters) {
@@ -152,9 +163,9 @@ class _DartDevelopmentServiceClient {
152163
"'size' must be greater or equal to zero",
153164
);
154165
}
155-
_StreamManager.loggingRepositories[_StreamManager.kLoggingStream]
166+
StreamManager.loggingRepositories[StreamManager.kLoggingStream]
156167
.resize(size);
157-
return _RPCResponses.success;
168+
return RPCResponses.success;
158169
});
159170

160171
_clientPeer.registerMethod('getDartDevelopmentServiceVersion',
@@ -219,21 +230,21 @@ class _DartDevelopmentServiceClient {
219230
[
220231
// Forward the request to the service client or...
221232
serviceClient.sendRequest(method, parameters.asMap).catchError((_) {
222-
throw _RpcErrorCodes.buildRpcException(
223-
_RpcErrorCodes.kServiceDisappeared,
233+
throw RpcErrorCodes.buildRpcException(
234+
RpcErrorCodes.kServiceDisappeared,
224235
);
225236
}, test: (error) => error is StateError),
226237
// if the service client closes, return an error response.
227238
serviceClient._clientPeer.done.then(
228-
(_) => throw _RpcErrorCodes.buildRpcException(
229-
_RpcErrorCodes.kServiceDisappeared,
239+
(_) => throw RpcErrorCodes.buildRpcException(
240+
RpcErrorCodes.kServiceDisappeared,
230241
),
231242
),
232243
],
233244
);
234245
}
235246
throw json_rpc.RpcException(
236-
_RpcErrorCodes.kMethodNotFound,
247+
RpcErrorCodes.kMethodNotFound,
237248
'Unknown service: ${parameters.method}',
238249
);
239250
});
@@ -260,12 +271,12 @@ class _DartDevelopmentServiceClient {
260271
String get name => _name;
261272

262273
// NOTE: this should not be called directly except from:
263-
// - `_ClientManager._clearClientName`
264-
// - `_ClientManager._setClientNameHelper`
274+
// - `ClientManager._clearClientName`
275+
// - `ClientManager._setClientNameHelper`
265276
set name(String n) => _name = n ?? defaultClientName;
266277
String _name;
267278

268-
final _DartDevelopmentService dds;
279+
final DartDevelopmentServiceImpl dds;
269280
final StreamChannel connection;
270281
final Map<String, String> services = {};
271282
final json_rpc.Peer _vmServicePeer;

0 commit comments

Comments
 (0)