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

Side by Side Diff: pkg/dartino_agent/tool/client.dart

Issue 1659163007: Rename fletch -> dartino (Closed) Base URL: https://github.com/dartino/sdk.git@master
Patch Set: address comments Created 4 years, 10 months 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 | « pkg/dartino_agent/lib/messages.dart ('k') | pkg/dartino_compiler/.packages » ('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) 2015, the Dartino project authors. Please see the AUTHORS file 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 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. 3 // BSD-style license that can be found in the LICENSE.md file.
4 4
5 library fletch_agent.client; 5 library dartino_agent.client;
6 6
7 import 'dart:io'; 7 import 'dart:io';
8 import 'dart:typed_data'; 8 import 'dart:typed_data';
9 9
10 import '../lib/messages.dart'; 10 import '../lib/messages.dart';
11 import '../lib/agent_connection.dart'; 11 import '../lib/agent_connection.dart';
12 12
13 void printUsage() { 13 void printUsage() {
14 print(''' 14 print('''
15 Usage: 15 Usage:
16 The Fletch agent command line client supports the following flags: 16 The Dartino agent command line client supports the following flags:
17 17
18 --port: the port on which to connect, default: 12121 18 --port: the port on which to connect, default: 12121
19 --host: the ip address on which to connect, default: 127.0.0.1 19 --host: the ip address on which to connect, default: 127.0.0.1
20 --cmd: the command to send to the Fletch agent, default: 0 (START_VM) 20 --cmd: the command to send to the Dartino agent, default: 0 (START_VM)
21 --pid: the pid of the vm to stop, only used when --cmd=1 (STOP_VM) 21 --pid: the pid of the vm to stop, only used when --cmd=1 (STOP_VM)
22 --signal: which signal to send to the vm. Requires the --pid option to 22 --signal: which signal to send to the vm. Requires the --pid option to
23 be specified 23 be specified
24 --pkg: path to the package file to be used with --cmd=3 (UPGRADE_PKG) 24 --pkg: path to the package file to be used with --cmd=3 (UPGRADE_PKG)
25 25
26 Example: Get the version of the agent running on 192.168.1.1: 26 Example: Get the version of the agent running on 192.168.1.1:
27 dart client.dart --cmd=4 --host=192.168.1.1.'''); 27 dart client.dart --cmd=4 --host=192.168.1.1.''');
28 exit(1); 28 exit(1);
29 } 29 }
30 30
31 /// Small dart program to issue commands to the fletch agent. 31 /// Small dart program to issue commands to the dartino agent.
32 void main(List<String> arguments) async { 32 void main(List<String> arguments) async {
33 // Startup the agent listening on specified port. 33 // Startup the agent listening on specified port.
34 int port = 12121; 34 int port = 12121;
35 String host = '127.0.0.1'; 35 String host = '127.0.0.1';
36 int cmd = RequestHeader.START_VM; 36 int cmd = RequestHeader.START_VM;
37 int id = 1; // The default id used. 37 int id = 1; // The default id used.
38 int pid; 38 int pid;
39 int signal; 39 int signal;
40 Socket socket; 40 Socket socket;
41 String packageFile; 41 String packageFile;
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 if (parts.length != 2) { 96 if (parts.length != 2) {
97 printUsage(); 97 printUsage();
98 } 98 }
99 packageFile = parts[1]; 99 packageFile = parts[1];
100 } 100 }
101 } 101 }
102 102
103 try { 103 try {
104 socket = await Socket.connect(host, port); 104 socket = await Socket.connect(host, port);
105 } on SocketException catch (error) { 105 } on SocketException catch (error) {
106 print('Could not connect to Fletch Agent on \'$host:$port\'. ' 106 print('Could not connect to Dartino Agent on \'$host:$port\'. '
107 'Received error: $error'); 107 'Received error: $error');
108 printUsage(); 108 printUsage();
109 } 109 }
110 110
111 var connection = new AgentConnection(socket); 111 var connection = new AgentConnection(socket);
112 switch (cmd) { 112 switch (cmd) {
113 case RequestHeader.START_VM: 113 case RequestHeader.START_VM:
114 VmData vmData = await connection.startVm(); 114 VmData vmData = await connection.startVm();
115 print('Started VM: id=${vmData.id}, port=${vmData.port}'); 115 print('Started VM: id=${vmData.id}, port=${vmData.port}');
116 break; 116 break;
117 case RequestHeader.STOP_VM: 117 case RequestHeader.STOP_VM:
118 if (pid == null) { 118 if (pid == null) {
119 print('Please specify which pid to stop with --pid=<pid>'); 119 print('Please specify which pid to stop with --pid=<pid>');
120 exit(1); 120 exit(1);
121 } 121 }
122 await connection.stopVm(pid); 122 await connection.stopVm(pid);
123 print('Stopped VM: id=$pid'); 123 print('Stopped VM: id=$pid');
124 break; 124 break;
125 case RequestHeader.LIST_VMS: 125 case RequestHeader.LIST_VMS:
126 await connection.listVms(); 126 await connection.listVms();
127 break; 127 break;
128 case RequestHeader.UPGRADE_AGENT: 128 case RequestHeader.UPGRADE_AGENT:
129 if (packageFile == null) { 129 if (packageFile == null) {
130 print('Please specify the path to the package with --pkg=<path>'); 130 print('Please specify the path to the package with --pkg=<path>');
131 exit(1); 131 exit(1);
132 } 132 }
133 Uri packageUri = new Uri.file(packageFile); 133 Uri packageUri = new Uri.file(packageFile);
134 List<String> nameParts = packageUri.pathSegments.last.split('_'); 134 List<String> nameParts = packageUri.pathSegments.last.split('_');
135 if (nameParts.length != 3 || nameParts[0] != 'fletch-agent') { 135 if (nameParts.length != 3 || nameParts[0] != 'dartino-agent') {
136 print('A fletch-agent package must have a name of the form\n' 136 print('A dartino-agent package must have a name of the form\n'
137 ' fletch-agent_<version>_<platform>'); 137 ' dartino-agent_<version>_<platform>');
138 exit(1); 138 exit(1);
139 } 139 }
140 String version = nameParts[1]; 140 String version = nameParts[1];
141 List<int> data = await new File(packageFile).readAsBytes(); 141 List<int> data = await new File(packageFile).readAsBytes();
142 print('Sending package for version $version' 142 print('Sending package for version $version'
143 ' (length: ${data.length} bytes).'); 143 ' (length: ${data.length} bytes).');
144 await connection.upgradeAgent(version, data); 144 await connection.upgradeAgent(version, data);
145 print('Update finished'); 145 print('Update finished');
146 break; 146 break;
147 case RequestHeader.FLETCH_VERSION: 147 case RequestHeader.DARTINO_VERSION:
148 String version = await connection.fletchVersion(); 148 String version = await connection.dartinoVersion();
149 print('Fletch Agent Version $version'); 149 print('Dartino Agent Version $version');
150 break; 150 break;
151 case RequestHeader.SIGNAL_VM: 151 case RequestHeader.SIGNAL_VM:
152 if (pid == null) { 152 if (pid == null) {
153 print('Please specify which pid to stop with --pid=<pid>'); 153 print('Please specify which pid to stop with --pid=<pid>');
154 printUsage(); 154 printUsage();
155 exit(1); 155 exit(1);
156 } 156 }
157 if (signal == null) { 157 if (signal == null) {
158 print('Please specify the signal to send to pid.'); 158 print('Please specify the signal to send to pid.');
159 printUsage(); 159 printUsage();
160 exit(1); 160 exit(1);
161 } 161 }
162 await connection.signalVm(pid, signal); 162 await connection.signalVm(pid, signal);
163 print('Send signal $signal to VM: id=$pid'); 163 print('Send signal $signal to VM: id=$pid');
164 break; 164 break;
165 default: 165 default:
166 print('Invalid command: $cmd'); 166 print('Invalid command: $cmd');
167 exit(1); 167 exit(1);
168 } 168 }
169 socket.close(); 169 socket.close();
170 } 170 }
OLDNEW
« no previous file with comments | « pkg/dartino_agent/lib/messages.dart ('k') | pkg/dartino_compiler/.packages » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698