Index: pkg/fletch_agent/lib/agent_connection.dart |
diff --git a/pkg/fletch_agent/lib/agent_connection.dart b/pkg/fletch_agent/lib/agent_connection.dart |
deleted file mode 100644 |
index ecf7f9c9cc2361fd6fbbb9ad7c69446e1a6f0b12..0000000000000000000000000000000000000000 |
--- a/pkg/fletch_agent/lib/agent_connection.dart |
+++ /dev/null |
@@ -1,108 +0,0 @@ |
-// Copyright (c) 2015, the Dartino project authors. Please see the AUTHORS file |
-// for details. All rights reserved. Use of this source code is governed by a |
-// BSD-style license that can be found in the LICENSE.md file. |
- |
-library fletch_agent.agent_connection; |
- |
-import 'dart:async'; |
-import 'dart:io'; |
-import 'dart:typed_data'; |
- |
-import 'messages.dart'; |
- |
-/// This class is used to connect to the Fletch Agent from Dart code. Ie. it |
-/// cannot be used from Fletch code as it is depending on the dart:io Socket |
-/// class. |
-/// The class is only for making a one-shot request/reply. The peer socket is |
-/// closed after handling the request. This is similar to HTTP without |
-/// keep-alive. |
-/// The caller/user of this class must handle any errors occurring on the |
-/// socket.done future as this class is not handling that. |
-class AgentConnection { |
- final Socket socket; |
- |
- AgentConnection(this.socket); |
- |
- Future<VmData> startVm() async { |
- var request = new StartVmRequest(); |
- var replyBuffer = await sendRequest(request); |
- var reply = new StartVmReply.fromBuffer(replyBuffer); |
- if (reply.result == ReplyHeader.START_VM_FAILED) { |
- throw new AgentException('Failed to start new Fletch VM.'); |
- } else if (reply.result != ReplyHeader.SUCCESS) { |
- throw new AgentException( |
- 'Failed to spawn new VM with unexpected error: ${reply.result}'); |
- } |
- return new VmData(reply.vmId, reply.vmPort); |
- } |
- |
- Future stopVm(int vmId) async { |
- var request = new StopVmRequest(vmId); |
- var replyBuffer = await sendRequest(request); |
- var reply = new StopVmReply.fromBuffer(replyBuffer); |
- if (reply.result == ReplyHeader.UNKNOWN_VM_ID) { |
- throw new AgentException('Could not stop VM. Unknown vm id: $vmId'); |
- } else if (reply.result != ReplyHeader.SUCCESS) { |
- throw new AgentException( |
- 'Failed to stop VM with unexpected error: ${reply.result}'); |
- } |
- } |
- |
- Future signalVm(int vmId, int signal) async { |
- var request = new SignalVmRequest(vmId, signal); |
- var replyBuffer = await sendRequest(request); |
- var reply = new SignalVmReply.fromBuffer(replyBuffer); |
- if (reply.result == ReplyHeader.UNKNOWN_VM_ID) { |
- throw new AgentException('Could not signal VM. Unknown vm id: $vmId'); |
- } else if (reply.result != ReplyHeader.SUCCESS) { |
- throw new AgentException( |
- 'Failed to signal VM with unexpected error: ${reply.result}'); |
- } |
- } |
- |
- Future<List<int>> listVms() async { |
- throw new AgentException('Not implemented'); |
- } |
- |
- Future upgradeAgent(String version, List<int> binary) async { |
- // TODO(karlklose): also send the version string. |
- var request = new UpgradeAgentRequest(binary); |
- var replyBuffer = await sendRequest(request); |
- var reply = new UpgradeAgentReply.fromBuffer(replyBuffer); |
- if (reply.result != ReplyHeader.SUCCESS) { |
- throw new AgentException('Failed to upgrade fletch-agent package ' |
- 'with unexpected error: ${reply.result}'); |
- } |
- } |
- |
- Future<String> fletchVersion() async { |
- var request = new FletchVersionRequest(); |
- var replyBuffer = await sendRequest(request); |
- var reply = new FletchVersionReply.fromBuffer(replyBuffer); |
- if (reply.result != ReplyHeader.SUCCESS) { |
- throw new AgentException('Failed to retrive Fletch version ' |
- 'with unexpected error: ${reply.result}'); |
- } |
- return reply.fletchVersion; |
- } |
- |
- Future<ByteBuffer> sendRequest(RequestHeader request) async { |
- socket.add(request.toBuffer().asUint8List()); |
- var replyBytes = await socket.fold([], (p, e) => p..addAll(e)); |
- return new Uint8List.fromList(replyBytes).buffer; |
- } |
-} |
- |
-class VmData { |
- final int id; |
- final int port; |
- |
- VmData(this.id, this.port); |
-} |
- |
-class AgentException implements Exception { |
- String message; |
- String toString() => 'AgentException($message)'; |
- |
- AgentException(this.message); |
-} |