-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathAWSMain.pas
More file actions
78 lines (63 loc) · 1.66 KB
/
AWSMain.pas
File metadata and controls
78 lines (63 loc) · 1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
unit AWSMain;
interface
uses
IdHTTPServer, System.SysUtils, IdContext, IdCustomHTTPServer, System.Types;
type
TAWSMain = class(TObject)
procedure httpServerCommandGet(AContext: TIdContext; ARequestInfo:
TIdHTTPRequestInfo; AResponseInfo: TIdHTTPResponseInfo);
private
FAdbPath: string;
FServer: TIdHTTPServer;
public
constructor Create;
destructor Destroy; override;
procedure start(APort: Integer; AdbPath: string);
end;
implementation
uses
System.StrUtils, Winapi.Windows;
constructor TAWSMain.Create;
begin
inherited;
FServer := TIdHTTPServer.Create(nil);
FServer.OnCommandGet := httpServerCommandGet;
end;
destructor TAWSMain.Destroy;
begin
FreeAndNil(FServer);
inherited;
end;
procedure TAWSMain.httpServerCommandGet(AContext: TIdContext; ARequestInfo:
TIdHTTPRequestInfo; AResponseInfo: TIdHTTPResponseInfo);
var
Uri: TStringDynArray;
Cmd, Ip: string;
begin
Uri := SplitString(ARequestInfo.URI, '/');
if Length(Uri)<>3 then
Exit;
Cmd := Uri[1];
Ip := Uri[2];
if Cmd='c' then
begin
Writeln(Format('%s is ready, try to connect', [Ip]));
WinExec(PAnsiChar(AnsiString(FAdbPath + ' connect '+Ip)), SW_NORMAL);
end else if Cmd='d' then
begin
Writeln(Format('%s is offline!', [Ip]));
WinExec(PAnsiChar(AnsiString(FAdbPath + ' disconnect '+Ip)), SW_NORMAL);
end;
///connect is async£¬so wait
Sleep(1000);
WinExec(PAnsiChar(AnsiString(FAdbPath + ' devices')), SW_NORMAL);
end;
procedure TAWSMain.start(APort: Integer; AdbPath: string);
begin
FServer.DefaultPort := APort;
FServer.Active := true;
FAdbPath := AdbPath;
if FAdbPath = '' then
FAdbPath := 'adb';
end;
end.