| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2015, the Dartino project authors. Please see the AUTHORS file | |
| 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.md file. | |
| 4 | |
| 5 library fletchc.verbs.attach_verb; | |
| 6 | |
| 7 import 'infrastructure.dart'; | |
| 8 | |
| 9 import 'documentation.dart' show | |
| 10 attachDocumentation; | |
| 11 | |
| 12 import '../worker/developer.dart' show | |
| 13 Address, | |
| 14 attachToVm, | |
| 15 parseAddress; | |
| 16 | |
| 17 const Action attachAction = const Action( | |
| 18 attach, attachDocumentation, requiresSession: true, | |
| 19 requiredTarget: TargetKind.TCP_SOCKET); | |
| 20 | |
| 21 Future<int> attach(AnalyzedSentence sentence, VerbContext context) { | |
| 22 Address address = parseAddress(sentence.targetName); | |
| 23 return context.performTaskInWorker( | |
| 24 new AttachTask(address.host, address.port)); | |
| 25 } | |
| 26 | |
| 27 class AttachTask extends SharedTask { | |
| 28 // Keep this class simple, see note in superclass. | |
| 29 | |
| 30 final String host; | |
| 31 | |
| 32 final int port; | |
| 33 | |
| 34 const AttachTask(this.host, this.port); | |
| 35 | |
| 36 Future<int> call( | |
| 37 CommandSender commandSender, | |
| 38 StreamIterator<ClientCommand> commandIterator) { | |
| 39 return attachTask(host, port); | |
| 40 } | |
| 41 } | |
| 42 | |
| 43 Future<int> attachTask(String host, int port) async { | |
| 44 SessionState state = SessionState.current; | |
| 45 | |
| 46 // Cleanup previous session if any. | |
| 47 await state.terminateSession(); | |
| 48 | |
| 49 state.explicitAttach = true; | |
| 50 await attachToVm(host, port, state); | |
| 51 return 0; | |
| 52 } | |
| OLD | NEW |