[cion] Add a missing disconnect on dart client 69/291369/2
authorChanggyu Choi <changyu.choi@samsung.com>
Fri, 14 Apr 2023 01:58:37 +0000 (10:58 +0900)
committerChanggyu Choi <changyu.choi@samsung.com>
Fri, 14 Apr 2023 06:30:20 +0000 (15:30 +0900)
Change-Id: I4a455c94f8fbb69ce617f22313a060d4bfbdb546
Signed-off-by: Changgyu Choi <changyu.choi@samsung.com>
idlc/gen_cion/dart_cion_proxy_gen_cb.h

index 6f94856..8fb37a7 100644 (file)
@@ -49,15 +49,18 @@ class _<DELEGATE_NAME> extends _Delegate {
  */
 constexpr const char CB_INTERFACE_BASE[] =
 R"__dart_cb(
+typedef OnDisconnected = Future<void> Function(PeerInfo);
+
 /// [<INTERFACE_NAME>] class for Cion.
 class <INTERFACE_NAME> {
   /// Constructor for this class.
-  <INTERFACE_NAME>(this.serverDisplayName) : _client = Client('<INTERFACE_NAME>');
+  <INTERFACE_NAME>(this.serverDisplayName, {SecurityInfo? security}) : _client = Client('<INTERFACE_NAME>', security: security);
 
   final List<_Delegate> _delegates = <_Delegate>[];
 
   Future<void> _onDisconnectedEvent(PeerInfo peer) async {
     _isConnected = false;
+    _onDisconnected?.call(peer);
   }
 
   Future<void> _onDiscoveredEvent(PeerInfo peer) async {
@@ -106,7 +109,7 @@ class <INTERFACE_NAME> {
   }
 
   /// Connects with the server.
-  Future<bool> connect() async {
+  Future<bool> connect({required OnDisconnected onDisconnected}) async {
     if (_isConnected) {
       return true;
     }
@@ -115,11 +118,21 @@ class <INTERFACE_NAME> {
       throw StateError('Already try to connect');
     }
 
+    _onDisconnected = onDisconnected;
     await _client.tryDiscovery(onDiscovered: _onDiscoveredEvent);
     _connectCompleter = Completer<bool>();
     return _connectCompleter!.future;
   }
 
+  /// Disconnects with the server.
+  void disconnect() {
+    if (!_isConnected) {
+      return;
+    }
+
+    _client.disconnect();
+  }
+
   /// Disposes of registered delegate interface.
   void disposeCallback(Function callback) {
     _delegates
@@ -131,6 +144,7 @@ class <INTERFACE_NAME> {
   final Client _client;
   final String serverDisplayName;
   bool _isConnected = false;
+  OnDisconnected? _onDisconnected;
   Completer<bool>? _connectCompleter;
 }
 )__dart_cb";