-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
23 changed files
with
3,372 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
library services; | ||
|
||
export 'src/grpc/client_channel.dart'; | ||
export 'src/rpc_client/client_channel.dart'; | ||
export 'src/rpc_client/refresh.dart'; | ||
export 'src/enum_const.dart'; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
// type AppPlatformType string | ||
// | ||
// //命名使用 rustup target list中的名字 | ||
// const ( | ||
// AppPlatformType_any AppPlatformType = "any" | ||
// AppPlatformType_aarch64_linux_android AppPlatformType = "aarch64-linux-android" | ||
// AppPlatformType_armv7_linux_androideabi AppPlatformType = "armv7-linux-androideabi" | ||
// AppPlatformType_i686_linux_android AppPlatformType = "i686-linux-android" | ||
// AppPlatformType_x86_64_linux_android AppPlatformType = "x86_64-linux-android" | ||
// AppPlatformType_x86_64_pc_windows_gnu AppPlatformType = "x86_64-pc-windows-gnu" | ||
// AppPlatformType_x86_64_unknown_linux_gnu AppPlatformType = "x86_64-unknown-linux-gnu" | ||
// ) | ||
|
||
enum AppPlatformType { | ||
any, | ||
aarch64_linux_android, | ||
armv7_linux_androideabi, | ||
i686_linux_android, | ||
x86_64_linux_android, | ||
x86_64_pc_windows_gnu, | ||
x86_64_unknown_linux_gnu | ||
} | ||
|
||
extension AppPlatformTypeEx on AppPlatformType { | ||
|
||
static AppPlatformType from(String chainType) { | ||
AppPlatformType re; | ||
switch (chainType) { | ||
case "any": | ||
re = AppPlatformType.any; | ||
break; | ||
case "aarch64_linux_android": | ||
re = AppPlatformType.aarch64_linux_android; | ||
break; | ||
case "armv7_linux_androideabi": | ||
re = AppPlatformType.armv7_linux_androideabi; | ||
break; | ||
case "i686_linux_android": | ||
re = AppPlatformType.i686_linux_android; | ||
break; | ||
case "x86_64_linux_android": | ||
re = AppPlatformType.x86_64_linux_android; | ||
break; | ||
case "x86_64_pc_windows_gnu": | ||
re = AppPlatformType.x86_64_pc_windows_gnu; | ||
break; | ||
case "x86_64_unknown_linux_gnu": | ||
re = AppPlatformType.x86_64_unknown_linux_gnu; | ||
break; | ||
default: | ||
{ | ||
//todo log | ||
// let err = format!("the str:{} can not be ChainType", chain_type); | ||
// log.error!("{}", err); | ||
re = null; | ||
} | ||
} | ||
return re; | ||
} | ||
|
||
String toEnumString() { | ||
String re; | ||
switch (this) { | ||
case AppPlatformType.any: | ||
re = "any";break; | ||
case AppPlatformType.aarch64_linux_android: | ||
re = "aarch64_linux_android"; | ||
break; | ||
case AppPlatformType.armv7_linux_androideabi: | ||
re = "armv7_linux_androideabi"; | ||
break; | ||
case AppPlatformType.i686_linux_android: | ||
re = "i686_linux_android"; | ||
break; | ||
case AppPlatformType.x86_64_linux_android: | ||
re = "x86_64_linux_android"; | ||
break; | ||
case AppPlatformType.x86_64_pc_windows_gnu: | ||
re = "x86_64_pc_windows_gnu"; | ||
break; | ||
case AppPlatformType.x86_64_unknown_linux_gnu: | ||
re = "x86_64_unknown_linux_gnu"; | ||
break; | ||
} | ||
return re; | ||
} | ||
} | ||
|
||
extension StringEx on String { | ||
AppPlatformType toAppPlatformType() { | ||
return AppPlatformTypeEx.from(this); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
|
||
import 'package:grpc/grpc.dart'; | ||
import 'package:meta/meta.dart'; | ||
import 'package:services/services.dart'; | ||
import 'package:services/src/rpc_face/refresh.pbgrpc.dart'; | ||
|
||
class Refresh { | ||
ClientChannel _channel; | ||
RefreshFaceClient _client; | ||
Refresh_RefreshReq _req; | ||
static Refresh _instance; | ||
Refresh._internal(); | ||
factory Refresh.get(ConnectParameter parameter, String version, AppPlatformType platformType){ | ||
if(_instance == null) { | ||
_instance = Refresh._internal(); | ||
_instance._channel = new ClientChannel( | ||
parameter.host, | ||
port: parameter.port, | ||
options: const ChannelOptions(credentials: ChannelCredentials.insecure(), connectionTimeout: Duration(minutes: 1)), | ||
); | ||
_instance._client = new RefreshFaceClient(_instance._channel); | ||
_instance._req = Refresh_RefreshReq(version:version,appPlatformType: platformType.toEnumString()); | ||
} | ||
return _instance; | ||
} | ||
|
||
@visibleForTesting | ||
set version(String v) => _req.version = v; | ||
|
||
Future<ConnectParameter> refreshCall() async { | ||
var res = await _client.refresh(_req); | ||
if(res.hasErr()){ | ||
return null; | ||
} | ||
ConnectParameter parameter = new ConnectParameter(res.serviceMeta.host, res.serviceMeta.port.toInt()); | ||
return parameter; | ||
} | ||
|
||
shutDown() { | ||
_client = null; | ||
_channel.shutdown(); | ||
_channel = null; | ||
} | ||
} | ||
|
Oops, something went wrong.