1import * as path from 'path'; 2 3const profilerServicePath = path.join(__dirname,'../proto', 'profiler_service.proto'); 4 5export class ProfilerClient { 6 // proto filePaths 7 private _filePaths: Array<String> | undefined; 8 // client 9 private _client: any; 10 // profiler_proto 11 private _profiler_proto: any; 12 // ProfilerClient constructor 13 public constructor(address: Address) { 14 // load client port 15 let clientPort = this.loadAddress(address); 16 // load proto file 17 this.start(clientPort, profilerServicePath); 18 }; 19 20 get filePaths(): Array<String> | undefined { 21 return this._filePaths; 22 } 23 24 set filePaths(value: Array<String> | undefined) { 25 this._filePaths = value; 26 } 27 28 get client(): any { 29 return this._client; 30 } 31 32 set client(value: any) { 33 this._client = value; 34 } 35 36 get profiler_proto(): any { 37 return this._profiler_proto; 38 } 39 40 set profiler_proto(value: any) { 41 this._profiler_proto = value; 42 } 43 44 start(address: string, filePath: string){ 45 // let loadPackage = proto_load.loadSync( 46 // filePath, 47 // { 48 // keepCase: true, 49 // longs: String, 50 // enums: String, 51 // defaults: true, 52 // oneofs: true 53 // } 54 // ); 55 // // profiler Proto 56 // this._profiler_proto = rpc.loadPackageDefinition(loadPackage); 57 // // get profilerProto service 58 // let profilerProto = this._profiler_proto.profiler; 59 // // client 60 // this._client = new profilerProto.IProfilerService('127.0.0.1:5555', rpc.credentials.createInsecure()); 61 } 62 63 // Address 64 loadAddress(clientAddress: Address): string{ 65 return clientAddress.host + ':' + clientAddress.port; 66 }; 67 68 public getProfilerClient(callback: any): any{ 69 return this._client; 70 }; 71 72 public getCapabilities(callback: any) { 73 this._client. 74 this._client.getCapabilities(callback); 75 callback(); 76 }; 77 78 public createSession(callback: any) { 79 this._client.createSession(callback); 80 callback(); 81 }; 82 83 public startSession(callback: any) { 84 this._client.startSession(callback); 85 callback(); 86 }; 87 88 public stopSession(callback: any) { 89 this._client.stopSession(callback); 90 callback(); 91 }; 92 93 public destroySession(callback: any) { 94 this._client.destroySession(callback); 95 callback(); 96 }; 97 98 public keepSession(callback: any) { 99 this._client.keepSession(callback); 100 callback(); 101 }; 102 103 public shutdown(): void { 104 105 }; 106 107 public getChannel() { 108 return this._client.channelInterpretation; 109 }; 110 111} 112 113export interface Address { 114 // port 115 port: string | number; 116 117 // host 118 host?: string | number; 119} 120