From: jusung son Date: Tue, 18 Apr 2023 05:37:59 +0000 (+0900) Subject: [cion] Fix file transfer logic X-Git-Tag: accepted/tizen/unified/20230420.153149~4 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=3f03ef442d52025312935e53ccb5e7b6ac6e605c;p=platform%2Fcore%2Fappfw%2Ftidl.git [cion] Fix file transfer logic Change-Id: I40035e859a92b23265ed8d4387d033dff09ba463 Signed-off-by: jusung son --- diff --git a/idlc/gen_cion/dart_cion_gen_base.cc b/idlc/gen_cion/dart_cion_gen_base.cc index 5c3b4403..3d820329 100644 --- a/idlc/gen_cion/dart_cion_gen_base.cc +++ b/idlc/gen_cion/dart_cion_gen_base.cc @@ -363,7 +363,7 @@ std::string DartCionGeneratorBase::GenBaseParcelWrite(const Elements& elms) { } if (has_file) - code = GetFileSharing(code, "this"); + code = GetFileSharing(code, "this.send(payload);"); return code; } @@ -591,6 +591,19 @@ std::string DartCionGeneratorBase::GetClassName(std::string name) { return name; } +std::string DartCionGeneratorBase::GetFullNameFromType(const BaseType& type) { + std::string str; + + str += type.ToString(); + + if (type.GetMetaType() != nullptr) { + str += "_"; + str += GetFullNameFromType(*type.GetMetaType()); + } + + return str; +} + std::string DartCionGeneratorBase::GetFullNameFromType(const BaseType& type, const Interface& iface) { std::string str; @@ -612,23 +625,86 @@ std::string DartCionGeneratorBase::GetFullNameFromType(const BaseType& type, return str; } -bool DartCionGeneratorBase::HasFile(const Interface& iface) { +bool DartCionGeneratorBase::HasFile(const Interface& iface, const BaseType& type) { + if (type.ToString() == "list" || type.ToString() == "array") { + std::string name = GetFullNameFromType(type, iface); + if (name == "array_file" || name == "list_file" || name == "file") + return true; + } else if (type.ToString() == "file") { + return true; + } + + return false; +} + +bool DartCionGeneratorBase::HasFile(const BaseType& type) { + if (type.ToString() == "list" || type.ToString() == "array") { + std::string name = GetFullNameFromType(type); + if (name == "array_file" || name == "list_file" || name == "file") + return true; + } else if (type.ToString() == "file") { + return true; + } + + return false; +} + +bool DartCionGeneratorBase::HasFile(const Declaration& decl) { + for (const auto& p : decl.GetParameters()) { + auto& param_type = p->GetParameterType(); + auto& type = param_type.GetBaseType(); + + if (type.ToString() == "file") + return true; + + if (type.ToString() == "list" || type.ToString() == "array") { + if (type.GetMetaType() != nullptr && + type.GetMetaType()->ToString() == "file") + return true; + + } + } + return false; +} + +bool DartCionGeneratorBase::HasFile(const Interface& iface, bool is_proxy) { for (const auto& d : iface.GetDeclarations()) { + if (is_proxy) { + if (HasFile(iface, d->GetType()) == true) + return true; + } + for (const auto& p : d->GetParameters()) { auto& param_type = p->GetParameterType(); - auto& type = param_type.GetBaseType(); - auto name = GetFullNameFromType(type, iface); - if (name == "file" || name == "list_file" || name == "array_file") - return true; + if (is_proxy) { + if (d->GetMethodType() == Declaration::MethodType::DELEGATE) { + if (param_type.GetDirection() != ParameterType::Direction::IN) + continue; + } else { + if (param_type.GetDirection() == ParameterType::Direction::IN) + continue; + } + if (HasFile(iface, param_type.GetBaseType()) == true) + return true; + } else { + if (d->GetMethodType() == Declaration::MethodType::DELEGATE) { + if (param_type.GetDirection() == ParameterType::Direction::IN) + continue; + } else { + if (param_type.GetDirection() != ParameterType::Direction::IN) + continue; + } + if (HasFile(iface, param_type.GetBaseType()) == true) + return true; + } } } - return false; } std::string DartCionGeneratorBase::GetFileSharing(std::string src, std::string sender) { std::string file_send; - file_send += ReplaceAll(CB_FILE_SEND, "", sender); + file_send += ReplaceAll(CB_FILE_SEND, "", sender); return CB_FILE_LIST + NLine(1) + src + NLine(1) + file_send + NLine(1); } diff --git a/idlc/gen_cion/dart_cion_gen_base.h b/idlc/gen_cion/dart_cion_gen_base.h index 8e13591f..077d2c38 100644 --- a/idlc/gen_cion/dart_cion_gen_base.h +++ b/idlc/gen_cion/dart_cion_gen_base.h @@ -54,7 +54,10 @@ class DartCionGeneratorBase : public CionPluginBase { std::string Tab(int cnt); std::string Trim(const std::string& str); - bool HasFile(const Interface& iface); + bool HasFile(const Interface& iface, bool is_proxy); + bool HasFile(const BaseType& type); + bool HasFile(const Interface& iface, const BaseType& type); + bool HasFile(const Declaration& decl); std::string GetFileSharing(std::string src, std::string sender); private: @@ -70,6 +73,7 @@ class DartCionGeneratorBase : public CionPluginBase { void GenMethodId(std::ofstream& stream, const Interface& iface); std::string GetFullNameFromType(const BaseType& type, const Interface& iface); + std::string GetFullNameFromType(const BaseType& type); protected: const int TAB_SIZE = 2; diff --git a/idlc/gen_cion/dart_cion_gen_base_cb.h b/idlc/gen_cion/dart_cion_gen_base_cb.h index eab8f77a..77f7c211 100644 --- a/idlc/gen_cion/dart_cion_gen_base_cb.h +++ b/idlc/gen_cion/dart_cion_gen_base_cb.h @@ -234,7 +234,7 @@ constexpr const char CB_FILE_SEND[] = R"__dart_cb( for (final String file in fileList) { final Payload payload = FilePayload(file); - .send(payload); + } )__dart_cb"; diff --git a/idlc/gen_cion/dart_cion_proxy_gen.cc b/idlc/gen_cion/dart_cion_proxy_gen.cc index a88d9334..ce62622d 100644 --- a/idlc/gen_cion/dart_cion_proxy_gen.cc +++ b/idlc/gen_cion/dart_cion_proxy_gen.cc @@ -64,9 +64,14 @@ void DartCionProxyGen::GenInterfaceBase(std::ofstream& stream, const Interface& iface) { std::string name = iface.GetID(); name[0] = ::toupper(name[0]); + + bool has_file = HasFile(iface, true); + ReplaceAll(CB_INTERFACE_BASE, { { "", name }, - { "", GenInterfaceMethods(iface) } + { "", GenInterfaceMethods(iface) }, + { "", has_file ? ", required OnFileReceived onFileReceived" : "" }, + { "", has_file ? "_onFileReceived = onFileReceived;" : "" } }) .Transform([&](std::string str) { return SmartIndent(std::move(str)); @@ -100,6 +105,7 @@ std::string DartCionProxyGen::GenInterfaceMethods(const Interface& iface) { { "", args }, { "", GenAsync(*d) }, { "", GenMethodParcelWrite(*d) }, + { "", "_client.send(payload);" }, }); } @@ -176,7 +182,7 @@ std::string DartCionProxyGen::GenMethodParcelWrite(const Declaration& decl) { {{"", code}, {"", method_id}}); if (has_file) - code = GetFileSharing(code, "_client"); + code = GetFileSharing(code,"_client.send(payload);"); } else { std::string read_code = std::move(GenMethodResultParcelRead(decl)); read_code += GenMethodOutParamParcelRead(decl); @@ -190,7 +196,7 @@ std::string DartCionProxyGen::GenMethodParcelWrite(const Declaration& decl) { {"", CB_FILE_SEND}, }); code = ReplaceAll(code, { - {"", "_client"}, + {"", "_client.send(payload);"}, }); } else { code = ReplaceAll(code, { diff --git a/idlc/gen_cion/dart_cion_proxy_gen_cb.h b/idlc/gen_cion/dart_cion_proxy_gen_cb.h index 8fb37a7b..f96a881f 100644 --- a/idlc/gen_cion/dart_cion_proxy_gen_cb.h +++ b/idlc/gen_cion/dart_cion_proxy_gen_cb.h @@ -50,6 +50,7 @@ class _ extends _Delegate { constexpr const char CB_INTERFACE_BASE[] = R"__dart_cb( typedef OnDisconnected = Future Function(PeerInfo); +typedef OnFileReceived = Future Function(PeerInfo, Payload, PayloadTransferStatus); /// [] class for Cion. class { @@ -85,6 +86,12 @@ class { Future _onReceivedEvent( PeerInfo peer, Payload payload, PayloadTransferStatus status) async { + + if (payload.type == PayloadType.file) { + _onFileReceived?.call(peer, payload as FilePayload, status); + return; + } + final Uint8List raw = (payload as DataPayload).data; final Parcel parcel = Parcel.fromRaw(raw); @@ -109,7 +116,7 @@ class { } /// Connects with the server. - Future connect({required OnDisconnected onDisconnected}) async { + Future connect({required OnDisconnected onDisconnected}) async { if (_isConnected) { return true; } @@ -118,6 +125,8 @@ class { throw StateError('Already try to connect'); } + + _onDisconnected = onDisconnected; await _client.tryDiscovery(onDiscovered: _onDiscoveredEvent); _connectCompleter = Completer(); @@ -145,6 +154,7 @@ class { final String serverDisplayName; bool _isConnected = false; OnDisconnected? _onDisconnected; + OnFileReceived? _onFileReceived; Completer? _connectCompleter; } )__dart_cb"; diff --git a/idlc/gen_cion/dart_cion_stub_gen.cc b/idlc/gen_cion/dart_cion_stub_gen.cc index fa63a351..bb7afd7f 100644 --- a/idlc/gen_cion/dart_cion_stub_gen.cc +++ b/idlc/gen_cion/dart_cion_stub_gen.cc @@ -67,7 +67,7 @@ void DartCionStubGen::GenInterfaceBase(std::ofstream& stream, { "", GenInterfaceCtor(iface) }, { "", GetTransportable().Dart().GenStubExtend() }, { "", - HasFile(iface) ? GetTransportable().Dart().GenFileRecive() : "" }, + HasFile(iface, false) ? GetTransportable().Dart().GenFileRecive() : "" }, { "", GetTransportable().Dart().GenStubParamDef() }, { "", GetTransportable().Dart().GenStubSuperParam() }, { "", name }, @@ -143,6 +143,10 @@ std::string DartCionStubGen::GenInterfaceMethodHandlers(const Interface& iface) std::string DartCionStubGen::GenMethodHandlerParcelRead(const Declaration& decl) { std::string code; + + if (HasFile(decl.GetType())) + code += CB_FILE_LIST + NLine(1); + for (const auto& p : decl.GetParameters()) { auto& param_type = p->GetParameterType(); if (param_type.GetDirection() != ParameterType::Direction::IN) @@ -225,10 +229,12 @@ std::string DartCionStubGen::GenMethodHandlerParcelWrite(const Declaration& decl std::string code = std::move(GenMethodHandlerResultParcelWrite(decl)); code += GenMethodHandlerOutParamParcelWrite(decl); - code = ReplaceAll(CB_METHOD_HANDLER_PARCEL_WRITE, { - { "", code }, - { "", GetTransportable().Dart().GenSendAsync( - "result", "service._serverBase", "service.peer") }}); + + if (HasFile(decl.GetType())) + code += ReplaceAll(CB_FILE_SEND, "", + "service._serverBase!.send(service.peer!, payload);"); + + code = ReplaceAll(CB_METHOD_HANDLER_PARCEL_WRITE, "", code); return code; } @@ -254,6 +260,9 @@ std::string DartCionStubGen::GenMethodHandlerResultParcelWrite( { "", ConvertTypeToParcelType(type.ToString()) }, { "" , "ret" } }); + + if (HasFile(type)) + code += ReplaceAll(CB_FILE_ADD, "", "ret"); code += NLine(1); } @@ -299,7 +308,7 @@ void DartCionStubGen::GenServiceBase(std::ofstream& stream, ReplaceAll(CB_SERVICE_BASE, { { "", GetTransportable().Dart().GenPeerInfo() }, { "", - HasFile(iface) ? GetTransportable().Dart().GenFileReciveDef() : "" }, + HasFile(iface, false) ? GetTransportable().Dart().GenFileReciveDef() : "" }, { "", GenServiceBaseMethodDecls(iface) } }) .Transform([&](std::string str) { @@ -347,7 +356,9 @@ void DartCionStubGen::GenDelegateBase(std::ofstream& stream, { "", GetClassName(decl.GetID()) }, { "", id }, { "", GenDelegateParams(decl) }, - { "", GetTransportable().Dart().GenSendAsync("parcel", + { "", HasFile(decl) ? CB_FILE_SEND : "" }, + { "", "service._serverBase!.send(service.peer!, payload);" }, + { "", GetTransportable().Dart().GenStubSendAsync("parcel", "service._serverBase", "service.peer" ) }, { "", GenDelegateParcelWrite(decl) } }) @@ -415,7 +426,8 @@ std::string DartCionStubGen::GenDelegateParcelWrite(const Declaration& decl) { } if (has_file) - code = GetFileSharing(code, "this"); + code = CB_FILE_LIST + NLine(1) + code; + return code; } diff --git a/idlc/gen_cion/dart_cion_stub_gen_cb.h b/idlc/gen_cion/dart_cion_stub_gen_cb.h index 3d4b995e..59ae4b25 100644 --- a/idlc/gen_cion/dart_cion_stub_gen_cb.h +++ b/idlc/gen_cion/dart_cion_stub_gen_cb.h @@ -81,6 +81,7 @@ R"__dart_cb( /// This abstract method will be called when the '' request is delivered. Future<> on();)__dart_cb"; + /** * The name of the delegate. * The ID of the delegate. @@ -115,7 +116,9 @@ class extends _Delegate { - + + + _wasInvoked = true; } @@ -182,7 +185,6 @@ class extends { if (service == null) { return returnData; } - final Parcel parcel = Parcel.fromRaw(data); diff --git a/idlc/gen_cion/dart_transportable.h b/idlc/gen_cion/dart_transportable.h index 5939ad0c..4040e023 100644 --- a/idlc/gen_cion/dart_transportable.h +++ b/idlc/gen_cion/dart_transportable.h @@ -27,7 +27,7 @@ class DartTransportable { virtual ~DartTransportable() = default; virtual std::string GenImport() const = 0; virtual std::string GenPeerInfo() const = 0; - virtual std::string GenSendAsync(std::string parcel, + virtual std::string GenStubSendAsync(std::string parcel, std::string server, std::string peer) const = 0; virtual std::string GenFileReciveDef() const = 0; virtual std::string GenFileRecive() const = 0; diff --git a/idlc/gen_cion/default_dart_transportable.cc b/idlc/gen_cion/default_dart_transportable.cc index da892828..b82e4b46 100644 --- a/idlc/gen_cion/default_dart_transportable.cc +++ b/idlc/gen_cion/default_dart_transportable.cc @@ -21,7 +21,7 @@ #include "idlc/gen/replace_all.h" namespace { -constexpr const char ___SEND_ASYNC[] = +constexpr const char ___STUB_SEND_ASYNC[] = R"__c_cb( final DataPayload dp = DataPayload(.asRaw()); !.send(!, dp); @@ -44,9 +44,9 @@ std::string DefaultDartTransportable::GenPeerInfo() const { return "PeerInfo"; } -std::string DefaultDartTransportable::GenSendAsync(std::string parcel, +std::string DefaultDartTransportable::GenStubSendAsync(std::string parcel, std::string server, std::string peer) const { - return std::string(ReplaceAll(___SEND_ASYNC, { + return std::string(ReplaceAll(___STUB_SEND_ASYNC, { { "", parcel }, { "", peer }, { "", server } })); diff --git a/idlc/gen_cion/default_dart_transportable.h b/idlc/gen_cion/default_dart_transportable.h index 407f3926..df557581 100644 --- a/idlc/gen_cion/default_dart_transportable.h +++ b/idlc/gen_cion/default_dart_transportable.h @@ -28,7 +28,7 @@ class DefaultDartTransportable : public DartTransportable { virtual ~DefaultDartTransportable() = default; std::string GenImport() const override; std::string GenPeerInfo() const override; - std::string GenSendAsync(std::string parcel, + std::string GenStubSendAsync(std::string parcel, std::string server, std::string peer) const override; std::string GenFileReciveDef() const override; std::string GenFileRecive() const override;