From: Ilho Kim Date: Thu, 24 Feb 2022 04:51:23 +0000 (+0900) Subject: Adjust plugin structure for type cpp X-Git-Tag: submit/tizen/20220729.020211~11 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=8b5284f41175a71b5357c4f6e36f2e32162751dd;p=platform%2Fcore%2Fappfw%2Ftidl.git Adjust plugin structure for type cpp Change-Id: Icc369ebdc7bbf0a57ea22190ef27724adf54625b Signed-off-by: Ilho Kim --- diff --git a/idlc/gen_cion/cpp_cion_gen_base.cc b/idlc/gen_cion/cpp_cion_gen_base.cc index 1e4346e..c9c3ec3 100644 --- a/idlc/gen_cion/cpp_cion_gen_base.cc +++ b/idlc/gen_cion/cpp_cion_gen_base.cc @@ -27,7 +27,7 @@ namespace { namespace tidl { CppCionGeneratorBase::CppCionGeneratorBase(std::shared_ptr doc) - : Generator(doc) { + : CionPluginBase(doc) { type_map_ = { {"char", "char"}, {"int", "int"}, {"short", "short"}, {"long", "long long"}, {"string", "std::string"}, {"bool", "bool"}, @@ -628,15 +628,24 @@ void CppCionGeneratorBase::GenBodyCallbacks(std::ofstream& stream, void CppCionGeneratorBase::GenBodyCallback(std::ofstream& stream, const Interface& iface, const Declaration& decl, bool is_proxy) { if (!is_proxy) { - GenTemplate(CB_CALLBACK_FILE_PAYLOAD_SEND, stream, + GenTemplate(std::string(ReplaceAll(CB_CALLBACK_FILE_PAYLOAD_SEND, { + { "", GetTransportable().Cpp().GenPeerInfoType() }, + { "", GetTransportable().Cpp() + .GenServerFileSend("path", "cion_server_", "peer") }, + { "", GetTransportable().Cpp().GenPayloadType() } + })), + stream, [&]()->std::string { return iface.GetID(); }, [&]()->std::string { return decl.GetID(); }); - - GenTemplate(CB_CALLBACK_INVOKE_METHOD, stream, + GenTemplate(std::string(ReplaceAll(CB_CALLBACK_INVOKE_METHOD, { + { "", GetTransportable().Cpp().GenPayloadType() }, + { "", GetTransportable().Cpp() + .GenServerSendAsync("cion_server_", "", "pl", "size") } + })), stream, [&]()->std::string { return iface.GetID(); }, @@ -739,6 +748,8 @@ void CppCionGeneratorBase::GenHeaderCallback(std::ofstream& stream, .Change("", [&]() { return is_proxy ? CB_CALLBACK_PRIVATE_PROXY : CB_CALLBACK_PRIVATE_STUB; }) + .Change("", GetTransportable().Cpp().GenPeerInfoType()) + .Change("", GetTransportable().Cpp().GenServerType()) .Out(stream); } @@ -747,14 +758,14 @@ std::string CppCionGeneratorBase::GenSecurity(const Interface& iface) { for (const auto& attr : iface.GetAttributes()) { if (attr->GetKey() == "ca_path") - security_path += ReplaceAll(CB_INTERFACE_SECURITY_CA, "", - attr->GetValue()); + security_path += + GetTransportable().Cpp().GenSetSecurityCA(attr->GetValue()); else if (attr->GetKey() == "cert_path") - security_path += ReplaceAll(CB_INTERFACE_SECURITY_CERT, "", - attr->GetValue()); + security_path += + GetTransportable().Cpp().GenSetSecurityCert(attr->GetValue()); else if (attr->GetKey() == "private_key") - security_path += ReplaceAll(CB_INTERFACE_SECURITY_PRIVATE_KEY, "", - attr->GetValue()); + security_path += + GetTransportable().Cpp().GenSetSecurityPrivateKey(attr->GetValue()); } return security_path; diff --git a/idlc/gen_cion/cpp_cion_gen_base.h b/idlc/gen_cion/cpp_cion_gen_base.h index b7570fe..c9f3daf 100644 --- a/idlc/gen_cion/cpp_cion_gen_base.h +++ b/idlc/gen_cion/cpp_cion_gen_base.h @@ -23,11 +23,11 @@ #include "idlc/ast/type.h" #include "idlc/ast/structure.h" -#include "idlc/gen/generator.h" +#include "idlc/gen_cion/cion_plugin_base.h" namespace tidl { -class CppCionGeneratorBase : public Generator { +class CppCionGeneratorBase : public CionPluginBase { public: explicit CppCionGeneratorBase(std::shared_ptr doc); virtual ~CppCionGeneratorBase() = default; diff --git a/idlc/gen_cion/cpp_cion_gen_base_cb.h b/idlc/gen_cion/cpp_cion_gen_base_cb.h index fa946be..160eac3 100644 --- a/idlc/gen_cion/cpp_cion_gen_base_cb.h +++ b/idlc/gen_cion/cpp_cion_gen_base_cb.h @@ -173,7 +173,7 @@ R"__cpp_cb( const char CB_CALLBACK_CTOR_STUB[] = R"__cpp_cb( - (std::weak_ptr service, cion_server_h cion_server) + (std::weak_ptr service, cion_server) : CallbackBase(static_cast(DelegateId::), false) { service_ = std::move(service); cion_server_ = cion_server; @@ -193,38 +193,17 @@ R"__cpp_cb( const char CB_CALLBACK_PRIVATE_STUB[] = R"__cpp_cb( - void FilePayloadSend(std::string path, cion_peer_info_h peer); + void FilePayloadSend(std::string path, peer); std::weak_ptr service_; bool valid_ = true; - cion_server_h cion_server_; + cion_server_; )__cpp_cb"; const char CB_CALLBACK_FILE_PAYLOAD_SEND[] = R"__cpp_cb( -void $$::$$::FilePayloadSend(std::string path, cion_peer_info_h peer) +void $$::$$::FilePayloadSend(std::string path, peer) { - cion_payload_h pl; - int ret = cion_payload_create(&pl, CION_PAYLOAD_TYPE_FILE); - if (ret != CION_ERROR_NONE) { - _E("Failed to cion_payload_create : %d", ret); - return; - } - - ret = cion_payload_set_file_path(pl, path.c_str()); - if (ret != CION_ERROR_NONE) { - _E("Failed to cion_payload_set_file_path : %d - %s", ret, path.c_str()); - cion_payload_destroy(pl); - return; - } - - ret = cion_server_send_payload_async(cion_server_, peer, pl, nullptr, nullptr); - if (ret != CION_ERROR_NONE) { - _E("Failed to cion_server_send_payload_async : %d", ret); - cion_payload_destroy(pl); - return; - } - - cion_payload_destroy(pl); + } )__cpp_cb"; @@ -253,32 +232,9 @@ $$ throw InvalidIOException(); } - cion_payload_h pl; - cion_ret_ = cion_payload_create(&pl, CION_PAYLOAD_TYPE_DATA); - if (cion_ret_ != CION_ERROR_NONE) { - _E("Failed to cion_payload_create : %d", cion_ret_); - rpc_port_parcel_destroy(p); - return; - } - - cion_ret_ = cion_payload_set_data(pl, (const unsigned char*)data, size); - if (cion_ret_ != CION_ERROR_NONE) { - _E("Failed to cion_payload_set_data : %d", cion_ret_); - rpc_port_parcel_destroy(p); - cion_payload_destroy(pl); - return; - } - - cion_ret_ = cion_server_send_payload_async(cion_server_, service_.lock()->GetPeer(), pl, nullptr, nullptr); - if (cion_ret_ != CION_ERROR_NONE) { - _E("Failed to cion_client_send_payload_async : %d", cion_ret_); - rpc_port_parcel_destroy(p); - cion_payload_destroy(pl); - return; - } - + pl; + rpc_port_parcel_destroy(p); - cion_payload_destroy(pl); valid_ = false; } )__cpp_cb"; @@ -290,30 +246,6 @@ $$ } )__cpp_cb"; -const char CB_INTERFACE_SECURITY_CA[] = -R"__cpp_cb( - if (cion_security_set_ca_path(security, "") != CION_ERROR_NONE) { - _E("Failed to set ca path."); - throw InvalidIOException(); - } -)__cpp_cb"; - -const char CB_INTERFACE_SECURITY_CERT[] = -R"__cpp_cb( - if (cion_security_set_cert_path(security, "") != CION_ERROR_NONE) { - _E("Failed to set cert path."); - throw InvalidIOException(); - } -)__cpp_cb"; - -const char CB_INTERFACE_SECURITY_PRIVATE_KEY[] = -R"__cpp_cb( - if (cion_security_set_private_key_path(security, "") != CION_ERROR_NONE) { - _E("Failed to set private key path."); - throw InvalidIOException(); - } -)__cpp_cb"; - const char CB_LOG_TAG[] = R"__cpp_cb( #ifdef LOG_TAG diff --git a/idlc/gen_cion/cpp_cion_group_body_gen.cc b/idlc/gen_cion/cpp_cion_group_body_gen.cc index 8bd51f2..0c2748b 100644 --- a/idlc/gen_cion/cpp_cion_group_body_gen.cc +++ b/idlc/gen_cion/cpp_cion_group_body_gen.cc @@ -91,20 +91,38 @@ void CppCionGroupBodyGen::GenInterface(std::ofstream& stream, void CppCionGroupBodyGen::GenConstructor(std::ofstream& stream, const Interface& iface) { ReplaceAll(CB_GROUP_INTERFACE_CTOR) + .Change("", GetTransportable().Cpp().GenGroupCreate()) .Change("", iface.GetID()) .Change("", GenSecurity(iface)) + .Change("", GetTransportable().Cpp().GenPeerInfoType()) + .Change("", GetTransportable().Cpp().GenPayloadType()) + .Change("", GetTransportable().Cpp().GenSecurityType()) + .Change("", GetTransportable().Cpp().GenGroupType()) .Out(stream); } void CppCionGroupBodyGen::GenDestructor(std::ofstream& stream, const Interface& iface) { - stream << ReplaceAll(CB_DTOR, "", iface.GetID()) << NLine(1); + stream << ReplaceAll(CB_DTOR, { + { "", iface.GetID() }, + { "", GetTransportable().Cpp().GenGroupDestroy() } + }) << NLine(1); } void CppCionGroupBodyGen::GenCionPayloadReceivedEvent(std::ofstream& stream, const Interface& iface) { - stream << ReplaceAll(CB_GROUP_ON_PAYLOAD_RECEIVED_CB_FRONT, "", - iface.GetID()); + stream << ReplaceAll(CB_GROUP_ON_PAYLOAD_RECEIVED_CB_FRONT, { + { "", iface.GetID() }, + { "", GetTransportable().Cpp().GenPeerInfoType() }, + { "", GetTransportable().Cpp().GenPayloadType() }, + { "", GetTransportable().Cpp().GenPayloadTypeEnum() }, + { "", + GetTransportable().Cpp().GenPayloadGetType() }, + { "", GetTransportable().Cpp().GenErrorNone() }, + { "", + GetTransportable().Cpp().GenPayloadTypeData() }, + { "", GetTransportable().Cpp().GenPayloadGetData() } + }); for (const auto& i : iface.GetDeclarations()) { if (i->GetMethodType() == Declaration::MethodType::DELEGATE || @@ -189,7 +207,10 @@ void CppCionGroupBodyGen::GenInvocation(std::ofstream& stream, if (!l.empty()) stream << AddIndent(TAB_SIZE * 2, l); else if (decl.GetMethodType() == Declaration::MethodType::ASYNC) - stream << CB_INVOCATION_ASYNC_MID << NLine(1); + stream << ReplaceAll(CB_INVOCATION_ASYNC_MID, { + { "", GetTransportable().Cpp().GenPayloadType() }, + { "", GetTransportable().Cpp().GenGroupPublish() } + }) << NLine(1); }, false, false); stream << " while (false);" << NLine(1); diff --git a/idlc/gen_cion/cpp_cion_group_body_gen_cb.h b/idlc/gen_cion/cpp_cion_group_body_gen_cb.h index adf535b..deb92ed 100644 --- a/idlc/gen_cion/cpp_cion_group_body_gen_cb.h +++ b/idlc/gen_cion/cpp_cion_group_body_gen_cb.h @@ -20,15 +20,7 @@ const char CB_DTOR[] = R"__cpp_cb( ::~() { - if (cion_group_ != nullptr) { - int ret = cion_group_unsubscribe(cion_group_); - if (ret != CION_ERROR_NONE) - _E("Failed to unsubscribe. error(%d)", ret); - cion_group_destroy(cion_group_); - } - - if (cion_security_ != nullptr) - cion_security_destroy(cion_security_); + } )__cpp_cb"; @@ -50,31 +42,8 @@ R"__cpp_cb( throw InvalidIOException(); } - cion_payload_h pl; - ret = cion_payload_create(&pl, CION_PAYLOAD_TYPE_DATA); - if (ret != CION_ERROR_NONE) { - _E("Failed to cion_payload_create : %d", ret); - rpc_port_parcel_destroy(p); - throw InvalidIOException(); - } - - ret = cion_payload_set_data(pl, (const unsigned char*)data, size); - if (ret != CION_ERROR_NONE) { - _E("Failed to cion_payload_set_data : %d", ret); - rpc_port_parcel_destroy(p); - cion_payload_destroy(pl); - throw InvalidIOException(); - } - - ret = cion_group_publish(cion_group_, pl); - if (ret != CION_ERROR_NONE) { - _E("Failed to cion_group_publish : %d", ret); - rpc_port_parcel_destroy(p); - cion_payload_destroy(pl); - throw InvalidIOException(); - } - - cion_payload_destroy(pl); + pl; + )__cpp_cb"; const char CB_INVOCATION_END[] = @@ -86,24 +55,25 @@ R"__cpp_cb( const char CB_GROUP_ON_PAYLOAD_RECEIVED_CB_FRONT[] = R"__cpp_cb( -void ::OnPayloadReceivedCB(const cion_peer_info_h peer_info, - const cion_payload_h payload) { - cion_payload_type_e type; - int ret = cion_payload_get_type(payload, &type); - if (ret != CION_ERROR_NONE) { +void ::OnPayloadReceivedCB(const peer_info, + const payload) { + type; + int ret; + + if (ret != ) { _E("Failed to cion_payload_get_type. error(%d)", ret); return; } - if (type != CION_PAYLOAD_TYPE_DATA) { + if (type != ) { _E("Wrong payload type, only data payload is available"); return; } unsigned char *data; unsigned int size; - ret = cion_payload_get_data(payload, &data, &size); - if (ret != CION_ERROR_NONE) { + + if (ret != ) { _E("Failed to cion_payload_get_data. error(%d)", ret); return; } @@ -131,80 +101,7 @@ R"__cpp_cb( const char CB_GROUP_INTERFACE_CTOR[] = R"__cpp_cb( ::(std::string topic) : topic_name_(std::move(topic)) { - cion_security_h security; - int ret = cion_security_create(&security); - if (ret != CION_ERROR_NONE) { - _E("Failed to create security handle. error(%d)", ret); - throw InvalidIOException(); - } - - auto security_auto = std::unique_ptr< - std::remove_pointer::type, decltype(cion_security_destroy)*>( - security, cion_security_destroy); - - cion_group_h group = nullptr; - ret = cion_group_create(&group, topic_name_.c_str(), security); - if (ret != CION_ERROR_NONE) { - _E("Failed to create handle. error(%d)", ret); - throw InvalidIOException(); - } - auto group_auto = std::unique_ptr< - std::remove_pointer::type, decltype(cion_group_destroy)*>( - group, cion_group_destroy); - - ret = cion_group_add_joined_cb(group, - [](const char *topic_name, const cion_peer_info_h peer_info, - void *user_data) { - *gr = static_cast<*>(user_data); - gr->OnJoined(peer_info); - }, - this); - if (ret != CION_ERROR_NONE) { - _E("Failed to cion_group_add_joined_cb. error(%d)", ret); - throw InvalidIOException(); - } - - ret = cion_group_add_left_cb(group, - [](const char *topic_name, const cion_peer_info_h peer_info, - void *user_data) { - *gr = static_cast<*>(user_data); - gr->OnLeft(peer_info); - }, - this); - if (ret != CION_ERROR_NONE) { - _E("Failed to cion_group_add_left_cb. error(%d)", ret); - throw InvalidIOException(); - } - - ret = cion_group_add_payload_received_cb(group, - [](const char *topic_name, const cion_peer_info_h peer_info, - const cion_payload_h payload, void *user_data) { - *gr = static_cast<*>(user_data); - gr->OnPayloadReceivedCB(peer_info, payload); - }, - this); - if (ret != CION_ERROR_NONE) { - _E("Failed to cion_group_add_payload_received_cb. error(%d)", ret); - throw InvalidIOException(); - } - - ret = cion_group_subscribe(group); - if (ret != CION_ERROR_NONE) { - _E("Failed to subscribe. error(%d)", ret); - switch (ret) { - case CION_ERROR_PERMISSION_DENIED : - throw UnauthorizedAccessException(); - break; - case CION_ERROR_INVALID_PARAMETER : - throw NotConnectedSocketException(); - break; - default : - throw InvalidIOException(); - } - } - - cion_security_ = security_auto.release(); - cion_group_ = group_auto.release(); + } )__cpp_cb"; diff --git a/idlc/gen_cion/cpp_cion_group_header_gen.cc b/idlc/gen_cion/cpp_cion_group_header_gen.cc index 572b3bb..3f5d894 100644 --- a/idlc/gen_cion/cpp_cion_group_header_gen.cc +++ b/idlc/gen_cion/cpp_cion_group_header_gen.cc @@ -72,13 +72,21 @@ void CppCionGroupHeaderGen::GenInterface(std::ofstream& stream, stream << NLine(1) << "class " << iface.GetID() << " "; GenBrace(stream, 0, [&]() { stream << " public:" << NLine(1); - stream << ReplaceAll(CB_PUBLIC_MEMBERS, "", iface.GetID()) + stream << ReplaceAll(CB_PUBLIC_MEMBERS, { + { "", iface.GetID() }, + { "", GetTransportable().Cpp().GenPeerInfoType() } + }) << NLine(1); GenMethods(stream, iface); GenMethodHandlers(stream, iface); stream << NLine(1) << " private:" << NLine(1); GenMethodId(stream, iface, true); - stream << CB_PRIVATE_MEMBERS; + stream << ReplaceAll(CB_PRIVATE_MEMBERS, { + { "", GetTransportable().Cpp().GenPeerInfoType() }, + { "", GetTransportable().Cpp().GenPayloadType() }, + { "", GetTransportable().Cpp().GenClientType() }, + { "", GetTransportable().Cpp().GenSecurityType() } + }); }, false, false); stream << ";" << NLine(1); } @@ -101,7 +109,8 @@ void CppCionGroupHeaderGen::GenMethodHandlers(std::ofstream& stream, for (const auto& i : decls) { stream << Tab(1) << "virtual " << ConvertTypeToString(i->GetType()) << " On" - << i->GetID() << "(const cion_peer_info_h peer_info, "; + << i->GetID() << ReplaceAll("(const peer_info, ", + "", GetTransportable().Cpp().GenPeerInfoType()); GenParameters(stream, i->GetParameters()); stream << ") = 0;" << NLine(1); } diff --git a/idlc/gen_cion/cpp_cion_group_header_gen_cb.h b/idlc/gen_cion/cpp_cion_group_header_gen_cb.h index aed0e24..7382e6d 100644 --- a/idlc/gen_cion/cpp_cion_group_header_gen_cb.h +++ b/idlc/gen_cion/cpp_cion_group_header_gen_cb.h @@ -49,20 +49,20 @@ R"__cpp_cb( /// /// /// This method will be invoked when the peer group app is joined to the topic. /// - virtual void OnJoined(const cion_peer_info_h peer_info) = 0; + virtual void OnJoined(const peer_info) = 0; /// /// This method will be invoked after the peer group app was left from the topic. /// - virtual void OnLeft(const cion_peer_info_h peer_info) = 0; + virtual void OnLeft(const peer_info) = 0; )__cpp_cb"; const char CB_PRIVATE_MEMBERS[] = -R"__cpp_cb( void OnPayloadReceivedCB(const cion_peer_info_h peer_info, - const cion_payload_h payload); - cion_client_h cion_group_ = nullptr; - cion_security_h cion_security_ = nullptr; +R"__cpp_cb( void OnPayloadReceivedCB(const peer_info, + const payload); + cion_group_ = nullptr; + cion_security_ = nullptr; std::string topic_name_; std::recursive_mutex mutex_; )__cpp_cb"; diff --git a/idlc/gen_cion/cpp_cion_proxy_body_gen.cc b/idlc/gen_cion/cpp_cion_proxy_body_gen.cc index 1be3e02..e630eaf 100644 --- a/idlc/gen_cion/cpp_cion_proxy_body_gen.cc +++ b/idlc/gen_cion/cpp_cion_proxy_body_gen.cc @@ -94,13 +94,20 @@ void CppCionProxyBodyGen::GenConstructor(std::ofstream& stream, const Interface& iface) { ReplaceAll(CB_PROXY_INTERFACE_CTOR) .Change("$$", iface.GetID()) + .Change("", GetTransportable().Cpp().GenClientCreate()) .Change("", GenSecurity(iface)) + .Change("", GetTransportable().Cpp().GenClientType()) + .Change("", GetTransportable().Cpp().GenSecurityType()) .Out(stream); } void CppCionProxyBodyGen::GenDestructor(std::ofstream& stream, const Interface& iface) { - GenTemplate(CB_DTOR, stream, + GenTemplate(std::string(ReplaceAll(CB_DTOR, { + { "", + GetTransportable().Cpp().GenPeerInfoDestroy("peer_") }, + { "", GetTransportable().Cpp().GenClientDestroy() } + })), stream, [&]()->std::string { return iface.GetID(); }, @@ -111,8 +118,36 @@ void CppCionProxyBodyGen::GenDestructor(std::ofstream& stream, void CppCionProxyBodyGen::GenHelperMethods(std::ofstream& stream, const Interface& iface) { - stream << ReplaceAll(CB_PROXY_HELPER_METHODS, "##", iface.GetID()) - << NLine(1); + stream << ReplaceAll(CB_PROXY_HELPER_METHODS, { + { "##", iface.GetID() }, + { "", GetTransportable().Cpp().GenPeerInfoType() }, + { "", GetTransportable().Cpp().GenPayloadType() }, + { "", + GetTransportable().Cpp().GenPayloadTransferStatusType() }, + { "", + GetTransportable().Cpp().GenClientTryConnect( + "cion_client_", "peer_") }, + { "", GetTransportable().Cpp() + .GenClientDisconnect("cion_client_") }, + { "", GetTransportable().Cpp() + .GenClientTryDiscovery("cion_client_") }, + { "", GetTransportable().Cpp() + .GenClientStopDiscovery("cion_client_") }, + { "", GetTransportable().Cpp().GenPayloadTypeEnum() }, + { "", + GetTransportable().Cpp().GenPayloadGetType() }, + { "", GetTransportable().Cpp().GenErrorNone() }, + { "", + GetTransportable().Cpp().GenPayloadTypeData() }, + { "", + GetTransportable().Cpp().GenPayloadTypeFile() }, + { "", + GetTransportable().Cpp().GenPayloadGetData() }, + { "", GetTransportable().Cpp() + .GenPeerInfoClone("peer_info", "&cl->peer_") }, + { "", GetTransportable().Cpp() + .GenPeerInfoGetAppID("peer_info", "&app_id") } + }) << NLine(1); } void CppCionProxyBodyGen::GenMethods(std::ofstream& stream, @@ -148,7 +183,11 @@ std::string CppCionProxyBodyGen::GenPrivateSharingRequestProxy(const BaseType& t void CppCionProxyBodyGen::GenFilePayloadSend(std::ofstream& stream, const Interface& iface) { - GenTemplate(CB_PROXY_FILE_PAYLOAD_SEND, stream, + GenTemplate(std::string(ReplaceAll(CB_PROXY_FILE_PAYLOAD_SEND, { + { "", GetTransportable().Cpp() + .GenClientFileSend("path", "cion_client_") }, + { "", GetTransportable().Cpp().GenPayloadType() } + })), stream, [&]()->std::string { return iface.GetID(); }); @@ -186,9 +225,16 @@ void CppCionProxyBodyGen::GenInvocation(std::ofstream& stream, if (!l.empty()) stream << AddIndent(TAB_SIZE * 2, l); if (decl.GetMethodType() == Declaration::MethodType::SYNC) - stream << CB_INVOCATION_SYNC_MID << NLine(1); + stream << ReplaceAll(CB_INVOCATION_SYNC_MID, "", + GetTransportable().Cpp().GenClientSend("cion_client_", "data", + "size", "return_data", "return_data_size")) << NLine(1); else if (decl.GetMethodType() == Declaration::MethodType::ASYNC) - stream << CB_INVOCATION_ASYNC_MID << NLine(1); + stream << ReplaceAll(CB_INVOCATION_ASYNC_MID, { + { "", GetTransportable().Cpp().GenPayloadType() }, + { "", + GetTransportable().Cpp().GenClientSendAsync( + "cion_client_", "pl", "size") } + }) << NLine(1); }, false, false); stream << " while (false);" << NLine(1); diff --git a/idlc/gen_cion/cpp_cion_proxy_body_gen_cb.h b/idlc/gen_cion/cpp_cion_proxy_body_gen_cb.h index 84df8bc..c3fd274 100644 --- a/idlc/gen_cion/cpp_cion_proxy_body_gen_cb.h +++ b/idlc/gen_cion/cpp_cion_proxy_body_gen_cb.h @@ -21,13 +21,8 @@ const char CB_DTOR[] = R"__cpp_cb( $$::~$$() { if (peer_ != nullptr) - cion_peer_info_destroy(peer_); - - if (cion_client_ != nullptr) - cion_client_destroy(cion_client_); - - if (cion_security_ != nullptr) - cion_security_destroy(cion_security_); + + } )__cpp_cb"; @@ -48,14 +43,7 @@ R"__cpp_cb( rpc_port_parcel_destroy(p); throw InvalidIOException(); } - - ret = cion_client_send_data(cion_client_, (unsigned char *)data, size, - 100, &return_data, &return_data_size); - if (ret != RPC_PORT_ERROR_NONE) { - _E("Failed to cion_client_send_data : error(%d)", ret); - rpc_port_parcel_destroy(p); - throw InvalidIOException(); - } + )__cpp_cb"; @@ -72,31 +60,8 @@ R"__cpp_cb( throw InvalidIOException(); } - cion_payload_h pl; - ret = cion_payload_create(&pl, CION_PAYLOAD_TYPE_DATA); - if (ret != CION_ERROR_NONE) { - _E("Failed to cion_payload_create : %d", ret); - rpc_port_parcel_destroy(p); - throw InvalidIOException(); - } - - ret = cion_payload_set_data(pl, (const unsigned char*)data, size); - if (ret != CION_ERROR_NONE) { - _E("Failed to cion_payload_set_data : %d", ret); - rpc_port_parcel_destroy(p); - cion_payload_destroy(pl); - throw InvalidIOException(); - } - - ret = cion_client_send_payload_async(cion_client_, pl, nullptr, nullptr); - if (ret != CION_ERROR_NONE) { - _E("Failed to cion_client_send_payload_async : %d", ret); - rpc_port_parcel_destroy(p); - cion_payload_destroy(pl); - throw InvalidIOException(); - } - - cion_payload_destroy(pl); + pl; + )__cpp_cb"; const char CB_INVOCATION_RECEIVE[] = @@ -132,28 +97,7 @@ R"__cpp_cb( const char CB_PROXY_FILE_PAYLOAD_SEND[] = R"__cpp_cb( void $$::FilePayloadSend(std::string path) { - cion_payload_h pl; - int ret = cion_payload_create(&pl, CION_PAYLOAD_TYPE_FILE); - if (ret != CION_ERROR_NONE) { - _E("Failed to cion_payload_create : %d", ret); - return; - } - - ret = cion_payload_set_file_path(pl, path.c_str()); - if (ret != CION_ERROR_NONE) { - _E("Failed to cion_payload_set_file_path : %d - %s", ret, path.c_str()); - cion_payload_destroy(pl); - return; - } - - ret = cion_client_send_payload_async(cion_client_, pl, nullptr, nullptr); - if (ret != CION_ERROR_NONE) { - _E("Failed to cion_client_send_payload_async : %d", ret); - cion_payload_destroy(pl); - return; - } - - cion_payload_destroy(pl); + } )__cpp_cb"; @@ -161,20 +105,7 @@ const char CB_PROXY_HELPER_METHODS[] = R"__cpp_cb( void ##::Connect() { if (peer_) { - int ret = cion_client_connect(cion_client_, peer_); - if (ret != CION_ERROR_NONE) { - _E("Failed to connect to stub. error(%d)", ret); - switch(ret) { - case CION_ERROR_PERMISSION_DENIED : - throw UnauthorizedAccessException(); - break; - case CION_ERROR_INVALID_PARAMETER : - throw NotConnectedSocketException(); - break; - default : - throw InvalidIOException(); - } - } + } else { _E("Not discovered"); } @@ -209,37 +140,19 @@ void ##::ProcessReceivedEvent(rpc_port_parcel_h parcel) { } void ##::Disconnect() { - int ret = cion_client_disconnect(cion_client_); - if (ret != CION_ERROR_NONE) { - _E("Failed to disconnect to stub. error(%d)", ret); - throw NotConnectedSocketException(); - } + } void ##::Discovery() { - int ret = cion_client_try_discovery(cion_client_, OnDiscoveredCB, this); - if (ret != CION_ERROR_NONE) { - _E("Failed to discovery to stub. error(%d)", ret); - switch(ret) { - case CION_ERROR_PERMISSION_DENIED : - throw UnauthorizedAccessException(); - break; - default : - throw InvalidIOException(); - } - } + } void ##::StopDiscovery() { - int ret = cion_client_stop_discovery(cion_client_); - if (ret != CION_ERROR_NONE) { - _E("Failed to stop discovery. error(%d)", ret); - return; - } + } void ##::OnConnectionResultCB(const char *service_name, - const cion_peer_info_h peer_info, const cion_connection_result_h result, + const peer_info, const cion_connection_result_h result, void *user_data) { ## *cl = static_cast<##*>(user_data); cion_connection_status_e status; @@ -256,17 +169,17 @@ void ##::OnConnectionResultCB(const char *service_name, } void ##::OnDisconnectedCB(const char *service_name, - const cion_peer_info_h peer_info, void *user_data) { + const peer_info, void *user_data) { ## *cl = static_cast<##*>(user_data); cl->delegate_list_.clear(); cl->listener_->OnDisconnected(); } void ##::OnDiscoveredCB(const char *service_name, - const cion_peer_info_h peer_info, void *user_data) { + const peer_info, void *user_data) { ## *cl = static_cast<##*>(user_data); char *app_id; - int ret = cion_peer_info_get_app_id(peer_info, &app_id); + int ret = if (ret != CION_ERROR_NONE) { _E("Failed to cion_peer_info_get_app_id. error(%d)", ret); return; @@ -275,7 +188,7 @@ void ##::OnDiscoveredCB(const char *service_name, auto app_id_auto = std::unique_ptr( app_id, std::free); if (std::string(app_id) == cl->target_appid_) { - ret = cion_peer_info_clone(peer_info, &cl->peer_); + ret = if (ret != CION_ERROR_NONE) { _E("Failed to cion_peer_info_clone. error(%d)", ret); return; @@ -290,12 +203,12 @@ void ##::OnPayloadAsyncResultCB(const cion_payload_async_result_h result, } void ##::OnPayloadReceivedCB(const char *service_name, - const cion_peer_info_h peer_info, const cion_payload_h payload, - cion_payload_transfer_status_e status, + const peer_info, const payload, + status, void *user_data) { ## *cl = static_cast<##*>(user_data); char *app_id; - int ret = cion_peer_info_get_app_id(peer_info, &app_id); + int ret = if (ret != CION_ERROR_NONE) { _E("Failed to cion_peer_info_get_app_id. error(%d)", ret); return; @@ -308,22 +221,22 @@ void ##::OnPayloadReceivedCB(const char *service_name, return; } - cion_payload_type_e type; - ret = cion_payload_get_type(payload, &type); - if (ret != CION_ERROR_NONE) { + type; + + if (ret != ) { _E("Failed to cion_payload_get_type. error(%d)", ret); return; } - if (type == CION_PAYLOAD_TYPE_FILE) { + if (type == ) { cl->listener_->OnFileReceived(peer_info, payload, status); return; } unsigned char *data; unsigned int size; - ret = cion_payload_get_data(payload, &data, &size); - if (ret != CION_ERROR_NONE) { + + if (ret != ) { _E("Failed to cion_payload_get_data. error(%d)", ret); return; } @@ -349,51 +262,7 @@ $$::$$(IEventListener* listener, const std::string& service_name, const std::string& target_appid) : listener_(listener), service_name_(service_name), target_appid_(target_appid) { - cion_security_h security; - int ret = cion_security_create(&security); - if (ret != CION_ERROR_NONE) { - _E("Failed to create security handle. error(%d)", ret); - throw InvalidIOException(); - } - - auto security_auto = std::unique_ptr< - std::remove_pointer::type, decltype(cion_security_destroy)*>( - security, cion_security_destroy); - - cion_client_h client = nullptr; - ret = cion_client_create(&client, service_name.c_str(), security); - if (ret != CION_ERROR_NONE) { - _E("Failed to create handle. error(%d)", ret); - throw InvalidIOException(); - } - auto client_auto = std::unique_ptr< - std::remove_pointer::type, decltype(cion_client_destroy)*>( - client, cion_client_destroy); - - ret = cion_client_add_disconnected_cb(client, OnDisconnectedCB, - this); - if (ret != CION_ERROR_NONE) { - _E("Failed to cion_client_add_disconnected_cb. error(%d)", ret); - throw InvalidIOException(); - } - - - ret = cion_client_add_connection_result_cb(client, OnConnectionResultCB, - this); - if (ret != CION_ERROR_NONE) { - _E("Failed to cion_client_add_connection_result_cb. error(%d)", ret); - throw InvalidIOException(); - } - - ret = cion_client_add_payload_received_cb(client, OnPayloadReceivedCB, - this); - if (ret != CION_ERROR_NONE) { - _E("Failed to cion_client_add_payload_received_cb. error(%d)", ret); - throw InvalidIOException(); - } - - cion_security_ = security_auto.release(); - cion_client_ = client_auto.release(); + } )__cpp_cb"; diff --git a/idlc/gen_cion/cpp_cion_proxy_header_gen.cc b/idlc/gen_cion/cpp_cion_proxy_header_gen.cc index b0b11db..d57b9c8 100644 --- a/idlc/gen_cion/cpp_cion_proxy_header_gen.cc +++ b/idlc/gen_cion/cpp_cion_proxy_header_gen.cc @@ -72,7 +72,12 @@ void CppCionProxyHeaderGen::GenInterface(std::ofstream& stream, GenBrace(stream, 0, [&]() { stream << " public:" << NLine(1); GenHeaderCallbacks(stream, iface, true); - GenTemplate(CB_PUBLIC_MEMBERS, stream, + GenTemplate(std::string(ReplaceAll(CB_PUBLIC_MEMBERS, { + { "", GetTransportable().Cpp().GenPeerInfoType() }, + { "", GetTransportable().Cpp().GenPayloadType() }, + { "", + GetTransportable().Cpp().GenPayloadTransferStatusType() } + })), stream, [&]()->std::string { return iface.GetID(); }, @@ -83,7 +88,14 @@ void CppCionProxyHeaderGen::GenInterface(std::ofstream& stream, GenDelegateId(stream, iface); stream << NLine(1) << " private:" << NLine(1); GenMethodId(stream, iface); - stream << CB_PRIVATE_MEMBERS; + stream << ReplaceAll(CB_PRIVATE_MEMBERS, { + { "", GetTransportable().Cpp().GenPeerInfoType() }, + { "", GetTransportable().Cpp().GenPayloadType() }, + { "", GetTransportable().Cpp().GenClientType() }, + { "", + GetTransportable().Cpp().GenPayloadTransferStatusType() }, + { "", GetTransportable().Cpp().GenSecurityType() } + }); }, false, false); stream << ";" << NLine(1); } diff --git a/idlc/gen_cion/cpp_cion_proxy_header_gen_cb.h b/idlc/gen_cion/cpp_cion_proxy_header_gen_cb.h index 683f5b9..02281ab 100644 --- a/idlc/gen_cion/cpp_cion_proxy_header_gen_cb.h +++ b/idlc/gen_cion/cpp_cion_proxy_header_gen_cb.h @@ -53,8 +53,8 @@ R"__cpp_cb( /// /// This method will be invoked when file receieved from service. /// - virtual void OnFileReceived(cion_peer_info_h peer_info, - cion_payload_h file_payload, cion_payload_transfer_status_e status) = 0; + virtual void OnFileReceived( peer_info, + file_payload, status) = 0; }; /// @@ -128,22 +128,22 @@ R"__cpp_cb( void ProcessReceivedEvent(rpc_port_parcel_h parcel); void FilePayloadSend(std::string path); static void OnConnectionResultCB(const char *service_name, - const cion_peer_info_h peer_info, const cion_connection_result_h result, + const peer_info, const cion_connection_result_h result, void *user_data); static void OnDisconnectedCB(const char *service_name, - const cion_peer_info_h peer_info, void *user_data); + const peer_info, void *user_data); static void OnDiscoveredCB(const char *service_name, - const cion_peer_info_h peer_info, void *user_data); + const peer_info, void *user_data); static void OnPayloadAsyncResultCB(const cion_payload_async_result_h result, void *user_data); static void OnPayloadReceivedCB(const char *service_name, - const cion_peer_info_h peer_info, const cion_payload_h payload, - cion_payload_transfer_status_e status, + const peer_info, const payload, + status, void *user_data); - cion_client_h cion_client_ = nullptr; - cion_security_h cion_security_ = nullptr; - cion_peer_info_h peer_ = nullptr; + cion_client_ = nullptr; + cion_security_ = nullptr; + peer_ = nullptr; IEventListener* listener_; std::string service_name_; std::string target_appid_; diff --git a/idlc/gen_cion/cpp_cion_stub_body_gen.cc b/idlc/gen_cion/cpp_cion_stub_body_gen.cc index 2d10b92..14a2250 100644 --- a/idlc/gen_cion/cpp_cion_stub_body_gen.cc +++ b/idlc/gen_cion/cpp_cion_stub_body_gen.cc @@ -93,7 +93,11 @@ void CppCionStubBodyGen::GenInterface(std::ofstream& stream, void CppCionStubBodyGen::GenServiceBase(std::ofstream& stream, const Interface& iface) { - GenTemplate(CB_CTOR_SERVICE_BASE, stream, + GenTemplate(std::string(ReplaceAll(CB_CTOR_SERVICE_BASE, { + { "", GetTransportable().Cpp().GenPeerInfoType() }, + { "", GetTransportable().Cpp() + .GenPeerInfoClone("peer", "&peer_") } + })), stream, [&]()->std::string { return iface.GetID(); }); @@ -104,7 +108,10 @@ void CppCionStubBodyGen::GenConstructor(std::ofstream& stream, const Interface& iface) { ReplaceAll(CB_CTOR_FRONT) .Change("##", iface.GetID()) + .Change("", GetTransportable().Cpp().GenServerRegister()) .Change("", GenSecurity(iface)) + .Change("", GetTransportable().Cpp().GenServerType()) + .Change("", GetTransportable().Cpp().GenSecurityType()) .Out(stream); } @@ -114,7 +121,32 @@ void CppCionStubBodyGen::GenDefaultMethods(std::ofstream& stream, if (options_->IsThreadEnabled()) stream << ReplaceAll(CB_DEFAULT_THREAD_METHODS, "##", iface.GetID()); - stream << ReplaceAll(CB_DEFAULT_METHODS, "##", iface.GetID()); + stream << ReplaceAll(CB_DEFAULT_METHODS, { + { "##", iface.GetID() }, + { "", GetTransportable().Cpp().GenPeerInfoType() }, + { "", + GetTransportable().Cpp().GenServerUnregister() }, + { "", + GetTransportable().Cpp().GenServerAccept() }, + { "", + GetTransportable().Cpp().GenServerReject() }, + { "", + GetTransportable().Cpp().GenServerSetDisplayName() }, + { "", + GetTransportable().Cpp().GenServerSetOnDemandLaunchEnabled() }, + { "", + GetTransportable().Cpp().GenServerListen() }, + { "", GetTransportable().Cpp() + .GenServerDisconnect("cion_server_", "p") }, + { "", GetTransportable().Cpp() + .GenPeerInfoGetAppID("peer_info", "&peer_app_id") }, + { "", GetTransportable().Cpp() + .GenPeerInfoGetAppID("s->get()->GetPeer()", "&service_app_id") }, + { "", GetTransportable().Cpp() + .GenPeerInfoGetUUID("peer_info", "&peer_uuid") }, + { "", GetTransportable().Cpp() + .GenPeerInfoGetUUID("s->get()->GetPeer()", "&service_uuid") } + }); } void CppCionStubBodyGen::GenCionDataReceivedEvent(std::ofstream& stream, @@ -125,7 +157,17 @@ void CppCionStubBodyGen::GenCionDataReceivedEvent(std::ofstream& stream, return iface.GetID(); }); } else { - GenTemplate(CB_CION_ON_DATA_RECEIVED_CB_FRONT, stream, + GenTemplate(std::string(ReplaceAll(CB_CION_ON_DATA_RECEIVED_CB_FRONT, { + { "", GetTransportable().Cpp().GenPeerInfoType() }, + { "", GetTransportable().Cpp() + .GenPeerInfoGetAppID("peer_info", "&peer_app_id") }, + { "", GetTransportable().Cpp() + .GenPeerInfoGetAppID("s->GetPeer()", "&service_app_id") }, + { "", GetTransportable().Cpp() + .GenPeerInfoGetUUID("peer_info", "&peer_uuid") }, + { "", GetTransportable().Cpp() + .GenPeerInfoGetUUID("s->GetPeer()", "&service_uuid") } + })), stream, [&]()->std::string { return iface.GetID(); }, @@ -167,7 +209,30 @@ void CppCionStubBodyGen::GenCionDataReceivedEvent(std::ofstream& stream, void CppCionStubBodyGen::GenCionPayloadReceivedEvent(std::ofstream& stream, const Interface& iface) { - GenTemplate(CB_CION_ON_PAYLOAD_RECEIVED_CB_FRONT, stream, + GenTemplate(std::string(ReplaceAll(CB_CION_ON_PAYLOAD_RECEIVED_CB_FRONT, { + { "", GetTransportable().Cpp().GenPeerInfoType() }, + { "", GetTransportable().Cpp().GenPayloadType() }, + { "", + GetTransportable().Cpp().GenPayloadTransferStatusType() }, + { "", GetTransportable().Cpp().GenPayloadTypeEnum() }, + { "", + GetTransportable().Cpp().GenPayloadGetType() }, + { "", GetTransportable().Cpp().GenErrorNone() }, + { "", + GetTransportable().Cpp().GenPayloadTypeData() }, + { "", + GetTransportable().Cpp().GenPayloadTypeFile() }, + { "", + GetTransportable().Cpp().GenPayloadGetData() }, + { "", GetTransportable().Cpp() + .GenPeerInfoGetAppID("peer_info", "&peer_app_id") }, + { "", GetTransportable().Cpp() + .GenPeerInfoGetAppID("s->GetPeer()", "&service_app_id") }, + { "", GetTransportable().Cpp() + .GenPeerInfoGetUUID("peer_info", "&peer_uuid") }, + { "", GetTransportable().Cpp() + .GenPeerInfoGetUUID("s->GetPeer()", "&service_uuid") } + })), stream, [&]()->std::string { return iface.GetID(); }, @@ -291,7 +356,12 @@ void CppCionStubBodyGen::GenInvocation(std::ofstream& stream, void CppCionStubBodyGen::GenFilePayloadSend(std::ofstream& stream, const Interface& iface) { - GenTemplate(CB_FILE_PAYLOAD_SEND, stream, + GenTemplate(std::string(ReplaceAll(CB_FILE_PAYLOAD_SEND, { + { "", GetTransportable().Cpp().GenPeerInfoType() }, + { "", GetTransportable().Cpp() + .GenServerFileSend("path", "cion_server_", "peer") }, + { "", GetTransportable().Cpp().GenPayloadType() } + })), stream, [&]()->std::string { return iface.GetID(); }); diff --git a/idlc/gen_cion/cpp_cion_stub_body_gen_cb.h b/idlc/gen_cion/cpp_cion_stub_body_gen_cb.h index b6c6712..1874821 100644 --- a/idlc/gen_cion/cpp_cion_stub_body_gen_cb.h +++ b/idlc/gen_cion/cpp_cion_stub_body_gen_cb.h @@ -20,56 +20,7 @@ const char CB_CTOR_FRONT[] = R"__cpp_cb( ##::##(const std::string& service_name, const std::string& display_name) { - cion_security_h security; - int ret = cion_security_create(&security); - if (ret != CION_ERROR_NONE) { - _E("Failed to create security handle. error(%d)", ret); - throw InvalidIOException(); - } - - auto security_auto = std::unique_ptr< - std::remove_pointer::type, decltype(cion_security_destroy)*>( - security, cion_security_destroy); - - cion_server_h server; - ret = cion_server_create(&server, service_name.c_str(), - display_name.c_str(), security); - if (ret != CION_ERROR_NONE) { - _E("Failed to create handle. error(%d)", ret); - throw InvalidIOException(); - } - auto server_auto = std::unique_ptr< - std::remove_pointer::type, decltype(cion_server_destroy)*>( - server, cion_server_destroy); - - ret = cion_server_add_connection_result_cb(server, OnConnectionResultCB, - this); - if (ret != CION_ERROR_NONE) { - _E("Failed to cion_server_add_connection_result_cb. error(%d)", ret); - throw InvalidIOException(); - } - - ret = cion_server_add_payload_received_cb(server, OnPayloadReceivedCB, - this); - if (ret != CION_ERROR_NONE) { - _E("Failed to cion_server_add_payload_received_cb. error(%d)", ret); - throw InvalidIOException(); - } - - ret = cion_server_set_data_received_cb(server, OnDataReceivedCB, this); - if (ret != CION_ERROR_NONE) { - _E("Failed to cion_server_set_data_received_cb. error(%d)", ret); - throw InvalidIOException(); - } - - ret = cion_server_add_disconnected_cb(server, OnDisconnectedCB, this); - if (ret != CION_ERROR_NONE) { - _E("Failed to cion_server_add_disconnected_cb. error(%d)", ret); - throw InvalidIOException(); - } - - cion_security_ = security_auto.release(); - cion_server_ = server_auto.release(); + } )__cpp_cb"; @@ -79,91 +30,45 @@ R"__cpp_cb( for (auto& i : services_) { i->OnTerminate(); } - - if (cion_server_ != nullptr) - cion_server_destroy(cion_server_); - - if (cion_security_ != nullptr) - cion_security_destroy(cion_security_); + } void ##::Listen(std::shared_ptr<##::ServiceBase::Factory> service_factory) { service_factory_ = std::move(service_factory); - int ret = cion_server_listen(cion_server_, OnConnectionRequestCB, this); - if (ret != CION_ERROR_NONE) { - _E("Failed to cion_server_listen. error(%d)", ret); - switch(ret) { - case CION_ERROR_PERMISSION_DENIED : - throw UnauthorizedAccessException(); - break; - default : - throw InvalidIOException(); - } - } + } void ##::Accept(std::shared_ptr service) { - auto p = service->GetPeer(); - int ret = cion_server_accept(cion_server_, p); - if (ret != CION_ERROR_NONE) { - _E("Failed to cion_server_accept. error(%d)", ret); - throw InvalidIOException(); - } - - service->OnCreate(); - services_.emplace_back(std::move(service)); + } void ##::Reject(std::shared_ptr service, std::string reason) { - auto p = service->GetPeer(); - int ret = cion_server_reject(cion_server_, p, reason.c_str()); - if (ret != CION_ERROR_NONE) { - _E("Failed to cion_server_reject. error(%d)", ret); - throw InvalidIOException(); - } + } void ##::Disconnect(std::shared_ptr service) { auto p = service->GetPeer(); - int ret = cion_server_disconnect(cion_server_, p); - if (ret != CION_ERROR_NONE) { - _E("Failed to cion_server_disconnect. error(%d)", ret); - throw InvalidIOException(); - } + } void ##::SetDisplayName(std::string display_name) { - int ret = cion_server_set_display_name(cion_server_, display_name.c_str()); - if (ret != CION_ERROR_NONE) { - _E("Failed to cion_server_set_display_name. error(%d)", ret); - InvalidIOException(); - } + } void ##::SetOndemandLaunchEnable(bool enabled) { - int ret = cion_server_set_on_demand_launch_enabled(cion_server_, enabled); - if (ret != CION_ERROR_NONE) { - _E("Failed to cion_server_set_on_demand_launch_enabled. error(%d)", ret); - switch(ret) { - case CION_ERROR_PERMISSION_DENIED : - throw UnauthorizedAccessException(); - break; - default : - throw InvalidIOException(); - } - } + } void ##::OnConnectionResultCB(const char *service_name, - const cion_peer_info_h peer_info, const cion_connection_result_h result, + const peer_info, const cion_connection_result_h result, void *user_data) { } void ##::OnDisconnectedCB(const char *service_name, - const cion_peer_info_h peer_info, void *user_data) { + const peer_info, void *user_data) { ##* stub = static_cast<##*>(user_data); char* peer_app_id = nullptr; - int ret = cion_peer_info_get_app_id(peer_info, &peer_app_id); + int ret = if (ret != CION_ERROR_NONE) { _E("cion_peer_info_get_app_id() is failed. error(%d)", ret); return; @@ -171,7 +76,7 @@ void ##::OnDisconnectedCB(const char *service_name, auto perr_app_id_auto = std::unique_ptr(peer_app_id, std::free); char* peer_uuid = nullptr; - ret = cion_peer_info_get_uuid(peer_info, &peer_uuid); + ret = if (ret != CION_ERROR_NONE) { _E("cion_peer_info_get_uuid() is failed. error(%d)", ret); return; @@ -180,7 +85,7 @@ void ##::OnDisconnectedCB(const char *service_name, for (auto s = stub->services_.begin(); s != stub->services_.end(); s++) { char* service_app_id = nullptr; - ret = cion_peer_info_get_app_id(s->get()->GetPeer(), &service_app_id); + ret = if (ret != CION_ERROR_NONE) { _E("cion_peer_info_get_app_id() is failed. error(%d)", ret); return; @@ -188,7 +93,7 @@ void ##::OnDisconnectedCB(const char *service_name, auto service_app_id_auto = std::unique_ptr(service_app_id, std::free); char* service_uuid = nullptr;; - ret = cion_peer_info_get_uuid(s->get()->GetPeer(), &service_uuid); + ret = if (ret != CION_ERROR_NONE) { _E("cion_peeer_info_get_uuid() is failed. error(%d)", ret); return; @@ -204,7 +109,7 @@ void ##::OnDisconnectedCB(const char *service_name, } void ##::OnConnectionRequestCB(const char *service_name, - const cion_peer_info_h peer_info, void *user_data) { + const peer_info, void *user_data) { ##* stub = static_cast<##*>(user_data); auto s = stub->service_factory_->CreateService(peer_info); s->OnRequested(s); @@ -305,9 +210,9 @@ int $$::OnReceivedCB(const char* sender, const char* instance, rpc_port_h port, )__cpp_cb"; const char CB_CTOR_SERVICE_BASE[] = -R"__cpp_cb($$::ServiceBase::ServiceBase(cion_peer_info_h peer) +R"__cpp_cb($$::ServiceBase::ServiceBase( peer) : active_object_(new ActiveObject()) { - int ret = cion_peer_info_clone(peer, &peer_); + int ret = if (ret != CION_ERROR_NONE) { _E("Failed to cion_peer_info_clone. error(%d)", ret); return; @@ -316,44 +221,23 @@ R"__cpp_cb($$::ServiceBase::ServiceBase(cion_peer_info_h peer) const char CB_FILE_PAYLOAD_SEND[] = R"__cpp_cb( -void $$::FilePayloadSend(std::string path, cion_peer_info_h peer) +void $$::FilePayloadSend(std::string path, peer) { - cion_payload_h pl; - int ret = cion_payload_create(&pl, CION_PAYLOAD_TYPE_FILE); - if (ret != CION_ERROR_NONE) { - _E("Failed to cion_payload_create : %d", ret); - return; - } - - ret = cion_payload_set_file_path(pl, path.c_str()); - if (ret != CION_ERROR_NONE) { - _E("Failed to cion_payload_set_file_path : %d - %s", ret, path.c_str()); - cion_payload_destroy(pl); - return; - } - - ret = cion_server_send_payload_async(cion_server_, peer, pl, nullptr, nullptr); - if (ret != CION_ERROR_NONE) { - _E("Failed to cion_server_send_payload_async : %d", ret); - cion_payload_destroy(pl); - return; - } - - cion_payload_destroy(pl); + } )__cpp_cb"; const char CB_CION_ON_PAYLOAD_RECEIVED_CB_FRONT[] = R"__cpp_cb( void $$::OnPayloadReceivedCB(const char *service_name, - const cion_peer_info_h peer_info, const cion_payload_h payload, - cion_payload_transfer_status_e status, + const peer_info, const payload, + status, void *user_data) { $$* stub = static_cast<$$*>(user_data); std::shared_ptr b; rpc_port_parcel_h p; char* peer_app_id = nullptr; - int ret = cion_peer_info_get_app_id(peer_info, &peer_app_id); + int ret = if (ret != CION_ERROR_NONE) { _E("cion_peer_info_get_app_id() is failed. error(%d)", ret); return; @@ -361,7 +245,7 @@ void $$::OnPayloadReceivedCB(const char *service_name, auto peer_app_id_auto = std::unique_ptr(peer_app_id, std::free); char* peer_uuid = nullptr;; - ret = cion_peer_info_get_uuid(peer_info, &peer_uuid); + ret = if (ret != CION_ERROR_NONE) { _E("cion_peer_info_get_uuid() is failed. error(%d)", ret); return; @@ -370,7 +254,7 @@ void $$::OnPayloadReceivedCB(const char *service_name, for (auto& s : stub->services_) { char* service_app_id = nullptr; - ret = cion_peer_info_get_app_id(s->GetPeer(), &service_app_id); + ret = if (ret != CION_ERROR_NONE) { _E("cion_peer_info_get_app_id() is failed. error(%d)", ret); return; @@ -378,7 +262,7 @@ void $$::OnPayloadReceivedCB(const char *service_name, auto service_app_id_auto = std::unique_ptr(service_app_id, std::free); char* service_uuid = nullptr; - ret = cion_peer_info_get_uuid(s->GetPeer(), &service_uuid); + ret = if (ret != CION_ERROR_NONE) { _E("cion_peer_info_get_uuid() is failed. error(%d)", ret); return; @@ -397,22 +281,22 @@ void $$::OnPayloadReceivedCB(const char *service_name, return; } - cion_payload_type_e type; - ret = cion_payload_get_type(payload, &type); - if (ret != CION_ERROR_NONE) { + type; + + if (ret != ) { _E("Failed to cion_payload_get_type. error(%d)", ret); return; } - if (type == CION_PAYLOAD_TYPE_FILE) { + if (type == ) { b->OnFileReceived(peer_info, payload, status); return; } unsigned char *data; unsigned int size; - ret = cion_payload_get_data(payload, &data, &size); - if (ret != CION_ERROR_NONE) { + + if (ret != ) { _E("Failed to cion_payload_get_data. error(%d)", ret); return; } @@ -443,14 +327,14 @@ R"__cpp_cb( default: const char CB_CION_ON_DATA_RECEIVED_CB_FRONT[] = R"__cpp_cb( void $$::OnDataReceivedCB(const char *service_name, - const cion_peer_info_h peer_info, const unsigned char *data, + const peer_info, const unsigned char *data, unsigned int data_size, unsigned char **return_data, unsigned int *return_data_size, void *user_data) { $$* stub = static_cast<$$*>(user_data); std::shared_ptr b; rpc_port_parcel_h p; char* peer_app_id = nullptr; - int ret = cion_peer_info_get_app_id(peer_info, &peer_app_id); + int ret = if (ret != CION_ERROR_NONE) { _E("cion_peer_info_get_app_id() is failed. error(%d)", ret); return; @@ -458,7 +342,7 @@ void $$::OnDataReceivedCB(const char *service_name, auto peer_app_id_auto = std::unique_ptr(peer_app_id, std::free); char* peer_uuid = nullptr; - ret = cion_peer_info_get_uuid(peer_info, &peer_uuid); + ret = if (ret != CION_ERROR_NONE) { _E("cion_peer_info_get_uuid() is failed. error(%d)", ret); return; @@ -467,7 +351,7 @@ void $$::OnDataReceivedCB(const char *service_name, for (auto& s : stub->services_) { char* service_app_id = nullptr; - ret = cion_peer_info_get_app_id(s->GetPeer(), &service_app_id); + ret = if (ret != CION_ERROR_NONE) { _E("cion_peer_info_get_app_id() is failed. error(%d)", ret); return; @@ -475,7 +359,7 @@ void $$::OnDataReceivedCB(const char *service_name, auto service_app_id_auto = std::unique_ptr(service_app_id, std::free); char* service_uuid = nullptr; - ret = cion_peer_info_get_uuid(s->GetPeer(), &service_uuid); + ret = if (ret != CION_ERROR_NONE) { _E("cion_peer_info_get_uuid() is failed. error(%d)", ret); return; diff --git a/idlc/gen_cion/cpp_cion_stub_header_gen.cc b/idlc/gen_cion/cpp_cion_stub_header_gen.cc index 4877d80..e6353d1 100644 --- a/idlc/gen_cion/cpp_cion_stub_header_gen.cc +++ b/idlc/gen_cion/cpp_cion_stub_header_gen.cc @@ -96,12 +96,24 @@ void CppCionStubHeaderGen::GenPrivate(std::ofstream& stream, stream << " private:" << NLine(1); GenMethodId(stream, iface); GenDelegateId(stream, iface); - stream << CB_PRIVATE_MEMBERS; + stream << ReplaceAll(CB_PRIVATE_MEMBERS, { + { "", GetTransportable().Cpp().GenPeerInfoType() }, + { "", GetTransportable().Cpp().GenPayloadType() }, + { "", GetTransportable().Cpp().GenServerType() }, + { "", + GetTransportable().Cpp().GenPayloadTransferStatusType() }, + { "", GetTransportable().Cpp().GenSecurityType() } + }); } void CppCionStubHeaderGen::GenServiceBase(std::ofstream& stream, const Interface& iface) { - stream << CB_SERVICE_BASE_FRONT; + stream << ReplaceAll(CB_SERVICE_BASE_FRONT, { + { "", GetTransportable().Cpp().GenPeerInfoType() }, + { "", GetTransportable().Cpp().GenPayloadType() }, + { "", + GetTransportable().Cpp().GenPayloadTransferStatusType() } + }); auto& decls = iface.GetDeclarations(); for (const auto& i : decls) { @@ -115,7 +127,8 @@ void CppCionStubHeaderGen::GenServiceBase(std::ofstream& stream, stream << ") = 0;" << NLine(1); } - stream << CB_SERVICE_BASE_BACK << NLine(2); + stream << ReplaceAll(CB_SERVICE_BASE_BACK, "", + GetTransportable().Cpp().GenPeerInfoType()) << NLine(2); } void CppCionStubHeaderGen::GenPublicMethods(std::ofstream& stream, diff --git a/idlc/gen_cion/cpp_cion_stub_header_gen_cb.h b/idlc/gen_cion/cpp_cion_stub_header_gen_cb.h index 814cc68..b594577 100644 --- a/idlc/gen_cion/cpp_cion_stub_header_gen_cb.h +++ b/idlc/gen_cion/cpp_cion_stub_header_gen_cb.h @@ -29,28 +29,28 @@ class InvalidCallbackException : public Exception {}; const char CB_PRIVATE_MEMBERS[] = R"__cpp_cb( - void FilePayloadSend(std::string path, cion_peer_info_h peer); + void FilePayloadSend(std::string path, peer); static void OnConnectionResultCB(const char *service_name, - const cion_peer_info_h peer_info, const cion_connection_result_h result, + const peer_info, const cion_connection_result_h result, void *user_data); static void OnDisconnectedCB(const char *service_name, - const cion_peer_info_h peer_info, void *user_data); + const peer_info, void *user_data); static void OnConnectionRequestCB(const char *service_name, - const cion_peer_info_h peer_info, void *user_data); + const peer_info, void *user_data); static void OnDataReceivedCB(const char *service_name, - const cion_peer_info_h peer_info, const unsigned char *data, + const peer_info, const unsigned char *data, unsigned int data_size, unsigned char **return_data, unsigned int *return_data_size, void *user_data); static void OnPayloadReceivedCB(const char *service_name, - const cion_peer_info_h peer_info, const cion_payload_h payload, - cion_payload_transfer_status_e status, + const peer_info, const payload, + status, void *user_data); std::shared_ptr service_factory_; std::list> services_; - cion_security_h cion_security_ = nullptr; - cion_server_h cion_server_ = nullptr; + cion_security_ = nullptr; + cion_server_ = nullptr; )__cpp_cb"; const char CB_SERVICE_BASE_FRONT[] = @@ -65,7 +65,7 @@ R"__cpp_cb( /// The method for making service instances /// /// The client peer info - virtual std::shared_ptr CreateService(cion_peer_info_h peer) = 0; + virtual std::shared_ptr CreateService( peer) = 0; }; virtual ~ServiceBase() = default; @@ -73,15 +73,15 @@ R"__cpp_cb( /// /// Gets peer info /// - const cion_peer_info_h GetPeer() const { + const GetPeer() const { return peer_; } /// /// This method will be called when file receieved from client app /// - virtual void OnFileReceived(cion_peer_info_h peer_info, - cion_payload_h file_payload, cion_payload_transfer_status_e status) = 0; + virtual void OnFileReceived( peer_info, + file_payload, status) = 0; /// /// This method will be called when the client is connection requested @@ -106,10 +106,10 @@ R"__cpp_cb( const char CB_SERVICE_BASE_BACK[] = R"__cpp_cb( protected: - ServiceBase(cion_peer_info_h peer); + ServiceBase( peer); private: - cion_peer_info_h peer_; + peer_; std::unique_ptr active_object_; };)__cpp_cb"; diff --git a/idlc/gen_cion/cpp_transportable.h b/idlc/gen_cion/cpp_transportable.h index a602df9..20e4911 100644 --- a/idlc/gen_cion/cpp_transportable.h +++ b/idlc/gen_cion/cpp_transportable.h @@ -36,8 +36,10 @@ class CppTransportable { std::string peer) const = 0; virtual std::string GenClientFileSend(std::string path, std::string client) const = 0; + virtual std::string GenGroupType() const = 0; virtual std::string GenPayloadTransferStatusType() const = 0; virtual std::string GenPeerInfoType() const = 0; + virtual std::string GenPeerInfoDestroy(std::string peer) const = 0; virtual std::string GenPayloadType() const = 0; virtual std::string GenClientType() const = 0; virtual std::string GenSecurityType() const = 0; @@ -56,6 +58,30 @@ class CppTransportable { virtual std::string GenServerAccept() const = 0; virtual std::string GenServerReject() const = 0; virtual std::string GenServerSetDisplayName() const = 0; + virtual std::string GenGroupPublish() const = 0; + virtual std::string GenPayloadTypeEnum() const = 0; + virtual std::string GenPayloadTypeData() const = 0; + virtual std::string GenPayloadTypeFile() const = 0; + virtual std::string GenPayloadGetType() const = 0; + virtual std::string GenErrorNone() const = 0; + virtual std::string GenPayloadGetData() const = 0; + virtual std::string GenClientCreate() const = 0; + virtual std::string GenGroupCreate() const = 0; + virtual std::string GenGroupDestroy() const = 0; + virtual std::string GenClientDestroy() const = 0; + virtual std::string GenSetSecurityCA(std::string arg) const = 0; + virtual std::string GenSetSecurityCert(std::string arg) const = 0; + virtual std::string GenSetSecurityPrivateKey(std::string arg) const = 0; + virtual std::string GenPeerInfoClone(std::string src_peer, + std::string dest_peer) const = 0; + virtual std::string GenServerSetOnDemandLaunchEnabled() const = 0; + virtual std::string GenServerListen() const = 0; + virtual std::string GenServerDisconnect(std::string server, + std::string peer) const = 0; + virtual std::string GenPeerInfoGetAppID(std::string peer, + std::string appid) const = 0; + virtual std::string GenPeerInfoGetUUID(std::string peer, + std::string uuid) const = 0; }; } // namespace tidl diff --git a/idlc/gen_cion/default_cpp_transportable.cc b/idlc/gen_cion/default_cpp_transportable.cc new file mode 100644 index 0000000..302036a --- /dev/null +++ b/idlc/gen_cion/default_cpp_transportable.cc @@ -0,0 +1,762 @@ +/* + * Copyright (c) 2022 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "idlc/gen_cion/default_cpp_transportable.h" + +#include + +#include "idlc/gen/replace_all.h" + +namespace { + +constexpr const char __CLINET_FILE_SEND[] = +R"__cpp_cb( pl; + int ret = cion_payload_create(&pl, CION_PAYLOAD_TYPE_FILE); + if (ret != CION_ERROR_NONE) { + _E("Failed to cion_payload_create : %d", ret); + return; + } + + ret = cion_payload_set_file_path(pl, .c_str()); + if (ret != CION_ERROR_NONE) { + _E("Failed to cion_payload_set_file_path : %d - %s", ret, .c_str()); + cion_payload_destroy(pl); + return; + } + + ret = cion_client_send_payload_async(, pl, nullptr, nullptr); + if (ret != CION_ERROR_NONE) { + _E("Failed to cion_client_send_payload_async : %d", ret); + cion_payload_destroy(pl); + return; + } + + cion_payload_destroy(pl); +)__cpp_cb"; + +constexpr const char __SERVER_FILE_SEND[] = +R"__cpp_cb( pl; + int ret = cion_payload_create(&pl, CION_PAYLOAD_TYPE_FILE); + if (ret != CION_ERROR_NONE) { + _E("Failed to cion_payload_create : %d", ret); + return; + } + + ret = cion_payload_set_file_path(pl, .c_str()); + if (ret != CION_ERROR_NONE) { + _E("Failed to cion_payload_set_file_path : %d - %s", ret, .c_str()); + cion_payload_destroy(pl); + return; + } + + ret = cion_server_send_payload_async(, , pl, nullptr, nullptr); + if (ret != CION_ERROR_NONE) { + _E("Failed to cion_server_send_payload_async : %d", ret); + cion_payload_destroy(pl); + return; + } + + cion_payload_destroy(pl); +)__cpp_cb"; + +constexpr const char __SERVER_REGISTER[] = +R"__cpp_cb( security; + int ret = cion_security_create(&security); + if (ret != CION_ERROR_NONE) { + _E("Failed to create security handle. error(%d)", ret); + throw InvalidIOException(); + } + + auto security_auto = std::unique_ptr< + std::remove_pointer<>::type, decltype(cion_security_destroy)*>( + security, cion_security_destroy); + + server; + ret = cion_server_create(&server, service_name.c_str(), + display_name.c_str(), security); + if (ret != CION_ERROR_NONE) { + _E("Failed to create handle. error(%d)", ret); + throw InvalidIOException(); + } + auto server_auto = std::unique_ptr< + std::remove_pointer<>::type, decltype(cion_server_destroy)*>( + server, cion_server_destroy); + + ret = cion_server_add_connection_result_cb(server, OnConnectionResultCB, + this); + if (ret != CION_ERROR_NONE) { + _E("Failed to cion_server_add_connection_result_cb. error(%d)", ret); + throw InvalidIOException(); + } + + ret = cion_server_add_payload_received_cb(server, OnPayloadReceivedCB, + this); + if (ret != CION_ERROR_NONE) { + _E("Failed to cion_server_add_payload_received_cb. error(%d)", ret); + throw InvalidIOException(); + } + + ret = cion_server_set_data_received_cb(server, OnDataReceivedCB, this); + if (ret != CION_ERROR_NONE) { + _E("Failed to cion_server_set_data_received_cb. error(%d)", ret); + throw InvalidIOException(); + } + + ret = cion_server_add_disconnected_cb(server, OnDisconnectedCB, this); + if (ret != CION_ERROR_NONE) { + _E("Failed to cion_server_add_disconnected_cb. error(%d)", ret); + throw InvalidIOException(); + } + + cion_security_ = security_auto.release(); + cion_server_ = server_auto.release(); +)__cpp_cb"; + + + +constexpr const char __SERVER_UNREGISTER[] = +R"__cpp_cb( + if (cion_server_ != nullptr) + cion_server_destroy(cion_server_); + + if (cion_security_ != nullptr) + cion_security_destroy(cion_security_); +)__cpp_cb"; + +constexpr const char __SERVER_ACCEPT[] = +R"__cpp_cb(auto p = service->GetPeer(); + int ret = cion_server_accept(cion_server_, p); + if (ret != CION_ERROR_NONE) { + _E("Failed to cion_server_accept. error(%d)", ret); + throw InvalidIOException(); + } + + service->OnCreate(); + services_.emplace_back(std::move(service)); +)__cpp_cb"; + +constexpr const char __SERVER_REJECT[] = +R"__cpp_cb(auto p = service->GetPeer(); + int ret = cion_server_reject(cion_server_, p, reason.c_str()); + if (ret != CION_ERROR_NONE) { + _E("Failed to cion_server_reject. error(%d)", ret); + throw InvalidIOException(); + } +)__cpp_cb"; + +constexpr const char __SERVER_SET_DISPLAY_NAME[] = +R"__cpp_cb(int ret = cion_server_set_display_name(cion_server_, display_name.c_str()); + if (ret != CION_ERROR_NONE) { + _E("Failed to cion_server_set_display_name. error(%d)", ret); + InvalidIOException(); + } +)__cpp_cb"; + +constexpr const char __CLIENT_TRY_CONNECT[] = +R"__cpp_cb(int ret = cion_client_connect(, ); + if (ret != CION_ERROR_NONE) { + _E("Failed to connect to stub. error(%d)", ret); + switch(ret) { + case CION_ERROR_PERMISSION_DENIED : + throw UnauthorizedAccessException(); + break; + case CION_ERROR_INVALID_PARAMETER : + throw NotConnectedSocketException(); + break; + default : + throw InvalidIOException(); + } + } +)__cpp_cb"; + +constexpr const char __CLIENT_DISCONNECT[] = +R"__cpp_cb(int ret = cion_client_disconnect(); + if (ret != CION_ERROR_NONE) { + _E("Failed to disconnect to stub. error(%d)", ret); + throw NotConnectedSocketException(); + } +)__cpp_cb"; + +constexpr const char __CLIENT_TRY_DISCOVERY[] = +R"__cpp_cb(int ret = cion_client_try_discovery(, OnDiscoveredCB, this); + if (ret != CION_ERROR_NONE) { + _E("Failed to discovery to stub. error(%d)", ret); + switch(ret) { + case CION_ERROR_PERMISSION_DENIED : + throw UnauthorizedAccessException(); + break; + default : + throw InvalidIOException(); + } + } +)__cpp_cb"; + +constexpr const char __CLIENT_STOP_DISCOVERY[] = +R"__cpp_cb(int ret = cion_client_stop_discovery(); + if (ret != CION_ERROR_NONE) { + _E("Failed to stop discovery. error(%d)", ret); + return; + } +)__cpp_cb"; + +constexpr const char __CLIENT_SEND_ASYNC[] = +R"__cpp_cb( + ret = cion_payload_create(&, CION_PAYLOAD_TYPE_DATA); + if (ret != CION_ERROR_NONE) { + _E("Failed to cion_payload_create : %d", ret); + rpc_port_parcel_destroy(p); + throw InvalidIOException(); + } + + ret = cion_payload_set_data(, (const unsigned char*)data, ); + if (ret != CION_ERROR_NONE) { + _E("Failed to cion_payload_set_data : %d", ret); + rpc_port_parcel_destroy(p); + cion_payload_destroy(); + throw InvalidIOException(); + } + + ret = cion_client_send_payload_async(, , nullptr, nullptr); + if (ret != CION_ERROR_NONE) { + _E("Failed to cion_client_send_payload_async : %d", ret); + rpc_port_parcel_destroy(p); + cion_payload_destroy(); + throw InvalidIOException(); + } + + cion_payload_destroy(); +)__cpp_cb"; + +constexpr const char __CLIENT_SEND[] = +R"__cpp_cb( + ret = cion_client_send_data(, (unsigned char *), , + 100, &, &); + if (ret != RPC_PORT_ERROR_NONE) { + _E("Failed to cion_client_send_data : error(%d)", ret); + rpc_port_parcel_destroy(p); + throw InvalidIOException(); + } +)__cpp_cb"; + +constexpr const char __SERVER_SEND_ASYNC[] = +R"__cpp_cb(cion_ret_ = cion_payload_create(&, CION_PAYLOAD_TYPE_DATA); + if (cion_ret_ != CION_ERROR_NONE) { + _E("Failed to cion_payload_create : %d", cion_ret_); + rpc_port_parcel_destroy(p); + return; + } + + cion_ret_ = cion_payload_set_data(, (const unsigned char*)data, ); + if (cion_ret_ != CION_ERROR_NONE) { + _E("Failed to cion_payload_set_data : %d", cion_ret_); + rpc_port_parcel_destroy(p); + cion_payload_destroy(); + return; + } + + cion_ret_ = cion_server_send_payload_async(, service_.lock()->GetPeer(), , nullptr, nullptr); + cion_payload_destroy(); + if (cion_ret_ != CION_ERROR_NONE) { + _E("Failed to cion_client_send_payload_async : %d", cion_ret_); + rpc_port_parcel_destroy(p); + return; + } +)__cpp_cb"; + +constexpr const char __GROUP_PUBLISH[] = +R"__c_cb(ret = cion_payload_create(&pl, CION_PAYLOAD_TYPE_DATA); + if (ret != CION_ERROR_NONE) { + _E("Failed to cion_payload_create : %d", ret); + rpc_port_parcel_destroy(p); + throw InvalidIOException(); + } + + ret = cion_payload_set_data(pl, (const unsigned char*)data, size); + if (ret != CION_ERROR_NONE) { + _E("Failed to cion_payload_set_data : %d", ret); + rpc_port_parcel_destroy(p); + cion_payload_destroy(pl); + throw InvalidIOException(); + } + + ret = cion_group_publish(cion_group_, pl); + cion_payload_destroy(pl); + if (ret != CION_ERROR_NONE) { + _E("Failed to cion_group_publish : %d", ret); + rpc_port_parcel_destroy(p); + throw InvalidIOException(); + } +)__c_cb"; + +constexpr const char __CLIENT_CREATE[] = +R"__c_cb( security; + int ret = cion_security_create(&security); + if (ret != CION_ERROR_NONE) { + _E("Failed to create security handle. error(%d)", ret); + throw InvalidIOException(); + } + + auto security_auto = std::unique_ptr< + std::remove_pointer<>::type, decltype(cion_security_destroy)*>( + security, cion_security_destroy); + + client = nullptr; + ret = cion_client_create(&client, service_name.c_str(), security); + if (ret != CION_ERROR_NONE) { + _E("Failed to create handle. error(%d)", ret); + throw InvalidIOException(); + } + auto client_auto = std::unique_ptr< + std::remove_pointer<>::type, decltype(cion_client_destroy)*>( + client, cion_client_destroy); + + ret = cion_client_add_disconnected_cb(client, OnDisconnectedCB, + this); + if (ret != CION_ERROR_NONE) { + _E("Failed to cion_client_add_disconnected_cb. error(%d)", ret); + throw InvalidIOException(); + } + + + ret = cion_client_add_connection_result_cb(client, OnConnectionResultCB, + this); + if (ret != CION_ERROR_NONE) { + _E("Failed to cion_client_add_connection_result_cb. error(%d)", ret); + throw InvalidIOException(); + } + + ret = cion_client_add_payload_received_cb(client, OnPayloadReceivedCB, + this); + if (ret != CION_ERROR_NONE) { + _E("Failed to cion_client_add_payload_received_cb. error(%d)", ret); + throw InvalidIOException(); + } + + cion_security_ = security_auto.release(); + cion_client_ = client_auto.release(); +)__c_cb"; + +constexpr const char __GROUP_CREATE[] = +R"__c_cb( security; + int ret = cion_security_create(&security); + if (ret != CION_ERROR_NONE) { + _E("Failed to create security handle. error(%d)", ret); + throw InvalidIOException(); + } + + auto security_auto = std::unique_ptr< + std::remove_pointer<>::type, decltype(cion_security_destroy)*>( + security, cion_security_destroy); + + group = nullptr; + ret = cion_group_create(&group, topic_name_.c_str(), security); + if (ret != CION_ERROR_NONE) { + _E("Failed to create handle. error(%d)", ret); + throw InvalidIOException(); + } + auto group_auto = std::unique_ptr< + std::remove_pointer<>::type, decltype(cion_group_destroy)*>( + group, cion_group_destroy); + + ret = cion_group_add_joined_cb(group, + [](const char *topic_name, const peer_info, + void *user_data) { + *gr = static_cast<*>(user_data); + gr->OnJoined(peer_info); + }, + this); + if (ret != CION_ERROR_NONE) { + _E("Failed to cion_group_add_joined_cb. error(%d)", ret); + throw InvalidIOException(); + } + + ret = cion_group_add_left_cb(group, + [](const char *topic_name, const peer_info, + void *user_data) { + *gr = static_cast<*>(user_data); + gr->OnLeft(peer_info); + }, + this); + if (ret != CION_ERROR_NONE) { + _E("Failed to cion_group_add_left_cb. error(%d)", ret); + throw InvalidIOException(); + } + + ret = cion_group_add_payload_received_cb(group, + [](const char *topic_name, const peer_info, + const payload, void *user_data) { + *gr = static_cast<*>(user_data); + gr->OnPayloadReceivedCB(peer_info, payload); + }, + this); + if (ret != CION_ERROR_NONE) { + _E("Failed to cion_group_add_payload_received_cb. error(%d)", ret); + throw InvalidIOException(); + } + + ret = cion_group_subscribe(group); + if (ret != CION_ERROR_NONE) { + _E("Failed to subscribe. error(%d)", ret); + switch (ret) { + case CION_ERROR_PERMISSION_DENIED : + throw UnauthorizedAccessException(); + break; + case CION_ERROR_INVALID_PARAMETER : + throw NotConnectedSocketException(); + break; + default : + throw InvalidIOException(); + } + } + + cion_security_ = security_auto.release(); + cion_group_ = group_auto.release(); +)__c_cb"; + +constexpr const char __GROUP_DESTROY[] = +R"__c_cb(if (cion_group_ != nullptr) { + int ret = cion_group_unsubscribe(cion_group_); + if (ret != CION_ERROR_NONE) + _E("Failed to unsubscribe. error(%d)", ret); + cion_group_destroy(cion_group_); + } + + if (cion_security_ != nullptr) + cion_security_destroy(cion_security_); +)__c_cb"; + +constexpr const char __CLIENT_DESTROY[] = +R"__c_cb( + if (cion_client_ != nullptr) + cion_client_destroy(cion_client_); + + if (cion_security_ != nullptr) + cion_security_destroy(cion_security_); +)__c_cb"; + +const char __SET_SECURITY_CA[] = +R"__cpp_cb( + if (cion_security_set_ca_path(security, "") != CION_ERROR_NONE) { + _E("Failed to set ca path."); + throw InvalidIOException(); + } +)__cpp_cb"; + +const char __SET_SECURITY_CERT[] = +R"__cpp_cb( + if (cion_security_set_cert_path(security, "") != CION_ERROR_NONE) { + _E("Failed to set cert path."); + throw InvalidIOException(); + } +)__cpp_cb"; + +const char __SET_SECURITY_PRIVATE_KEY[] = +R"__cpp_cb( + if (cion_security_set_private_key_path(security, "") != CION_ERROR_NONE) { + _E("Failed to set private key path."); + throw InvalidIOException(); + } +)__cpp_cb"; + +const char __PEER_INFO_CLONE[] = + "cion_peer_info_clone(, );"; + +constexpr const char __SERVER_SET_ONDEMAND_LAUNCH_ENABLED[] = +R"__c_cb(int ret = cion_server_set_on_demand_launch_enabled(cion_server_, enabled); + if (ret != CION_ERROR_NONE) { + _E("Failed to cion_server_set_on_demand_launch_enabled. error(%d)", ret); + switch(ret) { + case CION_ERROR_PERMISSION_DENIED : + throw UnauthorizedAccessException(); + break; + default : + throw InvalidIOException(); + } + } +)__c_cb"; + +constexpr const char __SERVER_LISTEN[] = +R"__c_cb(int ret = cion_server_listen(cion_server_, OnConnectionRequestCB, this); + if (ret != CION_ERROR_NONE) { + _E("Failed to cion_server_listen. error(%d)", ret); + switch(ret) { + case CION_ERROR_PERMISSION_DENIED : + throw UnauthorizedAccessException(); + break; + default : + throw InvalidIOException(); + } + } +)__c_cb"; + +constexpr const char __SERVER_DISCONNECT[] = +R"__c_cb(int ret = cion_server_disconnect(, ); + if (ret != CION_ERROR_NONE) { + _E("Failed to cion_server_disconnect. error(%d)", ret); + throw InvalidIOException(); + } +)__c_cb"; + +constexpr const char __PEER_INFO_GET_APPID[] = + "cion_peer_info_get_app_id(, );"; + +constexpr const char __PEER_INFO_GET_UUID[] = + "cion_peer_info_get_uuid(, );"; + +} // namespace + +namespace tidl { + +std::string DefaultCppTransportable::GenInclude() const { + return "#include "; +} + +std::string DefaultCppTransportable::GenClientSendAsync(std::string client, + std::string payload, std::string size) const { + return std::string(ReplaceAll(__CLIENT_SEND_ASYNC, { + { "", client }, + { "", payload}, + { "", size} })); +} + +std::string DefaultCppTransportable::GenClientSend(std::string client, + std::string data, std::string data_size, + std::string ret_data, std::string ret_data_size) const { + return std::string(ReplaceAll(__CLIENT_SEND, { + { "", client }, + { "", data}, + { "", data_size}, + { "", ret_data}, + { "", ret_data_size} })); +} + +std::string DefaultCppTransportable::GenServerSendAsync(std::string server, + std::string client, + std::string payload, std::string size) const { + return std::string(ReplaceAll(__SERVER_SEND_ASYNC, { + { "", server }, + { "", client}, + { "", payload}, + { "", size} })); +} + +std::string DefaultCppTransportable::GenServerFileSend(std::string path, + std::string server, std::string peer) const { + return std::string(ReplaceAll(__SERVER_FILE_SEND, { + { "", path }, + { "", server }, + { "", peer } })); +} + +std::string DefaultCppTransportable::GenClientFileSend(std::string path, + std::string client) const { + return std::string(ReplaceAll(__CLINET_FILE_SEND, { + { "", path }, + { "", client } })); +} + +std::string DefaultCppTransportable::GenGroupType() const { + return "cion_group_h"; +} + +std::string DefaultCppTransportable::GenPayloadTransferStatusType() const { + return "cion_payload_transfer_status_e"; +} + +std::string DefaultCppTransportable::GenPeerInfoType() const { + return "cion_peer_info_h"; +} + +std::string DefaultCppTransportable::GenPeerInfoDestroy( + std::string peer) const { + return std::string(ReplaceAll("cion_peer_info_destroy();", { + { "", peer } })); +} + +std::string DefaultCppTransportable::GenPayloadType() const { + return "cion_payload_h"; +} + +std::string DefaultCppTransportable::GenClientType() const { + return "cion_client_h"; +} + +std::string DefaultCppTransportable::GenSecurityType() const { + return "cion_security_h"; +} + +std::string DefaultCppTransportable::GenServerType() const { + return "cion_server_h"; +} + +std::string DefaultCppTransportable::GenClientTryConnect(std::string client, + std::string peer) const { + return std::string(ReplaceAll(__CLIENT_TRY_CONNECT, { + { "", client }, + { "", peer } })); +} + +std::string DefaultCppTransportable::GenClientDisconnect( + std::string client) const { + return std::string(ReplaceAll(__CLIENT_DISCONNECT, { + { "", client } })); +} + +std::string DefaultCppTransportable::GenClientTryDiscovery( + std::string client) const { + return std::string(ReplaceAll(__CLIENT_TRY_DISCOVERY, { + { "", client } })); +} + +std::string DefaultCppTransportable::GenClientStopDiscovery( + std::string client) const { + return std::string(ReplaceAll(__CLIENT_STOP_DISCOVERY, { + { "", client } })); +} + +std::string DefaultCppTransportable::GenServerRegister() const { + return __SERVER_REGISTER; +} + +std::string DefaultCppTransportable::GenServerUnregister() const { + return __SERVER_UNREGISTER; +} + +std::string DefaultCppTransportable::GenClientExtraHeader() const { + return ""; +} + +std::string DefaultCppTransportable::GenClientExtraBody() const { + return ""; +} + +std::string DefaultCppTransportable::GenServerExtraHeader() const { + return ""; +} + +std::string DefaultCppTransportable::GenServerExtraBody() const { + return ""; +} + +std::string DefaultCppTransportable::GenServerAccept() const { + return __SERVER_ACCEPT; +} + +std::string DefaultCppTransportable::GenServerReject() const { + return __SERVER_REJECT; +} + +std::string DefaultCppTransportable::GenServerSetDisplayName() const { + return __SERVER_SET_DISPLAY_NAME; +} + +std::string DefaultCppTransportable::GenGroupPublish() const { + return __GROUP_PUBLISH; +} + +std::string DefaultCppTransportable::GenPayloadTypeEnum() const { + return "cion_payload_type_e"; +} + +std::string DefaultCppTransportable::GenPayloadTypeData() const { + return "CION_PAYLOAD_TYPE_DATA"; +} + +std::string DefaultCppTransportable::GenPayloadTypeFile() const { + return "CION_PAYLOAD_TYPE_FILE"; +} + +std::string DefaultCppTransportable::GenPayloadGetType() const { + return "ret = cion_payload_get_type(payload, &type);"; +} + +std::string DefaultCppTransportable::GenErrorNone() const { + return "CION_ERROR_NONE"; +} + +std::string DefaultCppTransportable::GenPayloadGetData() const { + return "ret = cion_payload_get_data(payload, &data, &size);"; +} + +std::string DefaultCppTransportable::GenClientCreate() const { + return __CLIENT_CREATE; +} + +std::string DefaultCppTransportable::GenGroupCreate() const { + return __GROUP_CREATE; +} + +std::string DefaultCppTransportable::GenGroupDestroy() const { + return __GROUP_DESTROY; +} + +std::string DefaultCppTransportable::GenClientDestroy() const { + return __CLIENT_DESTROY; +} + +std::string DefaultCppTransportable::GenSetSecurityCA(std::string arg) const { + return std::string(ReplaceAll(__SET_SECURITY_CA, { + { "", arg } })); +} + +std::string DefaultCppTransportable::GenSetSecurityCert(std::string arg) const { + return std::string(ReplaceAll(__SET_SECURITY_CERT, { + { "", arg } })); +} + +std::string DefaultCppTransportable::GenSetSecurityPrivateKey( + std::string arg) const { + return std::string(ReplaceAll(__SET_SECURITY_PRIVATE_KEY, { + { "", arg } })); +} + +std::string DefaultCppTransportable::GenPeerInfoClone(std::string src_peer, + std::string dest_peer) const { + return std::string(ReplaceAll(__PEER_INFO_CLONE, { + { "", src_peer }, + { "", dest_peer } })); +} + +std::string DefaultCppTransportable::GenServerSetOnDemandLaunchEnabled() const { + return __SERVER_SET_ONDEMAND_LAUNCH_ENABLED; +} + +std::string DefaultCppTransportable::GenServerListen() const { + return __SERVER_LISTEN; +} + +std::string DefaultCppTransportable::GenServerDisconnect(std::string server, + std::string peer) const { + return std::string(ReplaceAll(__SERVER_DISCONNECT, { + { "", server }, + { "", peer } })); +} + +std::string DefaultCppTransportable::GenPeerInfoGetAppID(std::string peer, + std::string appid) const { + return std::string(ReplaceAll(__PEER_INFO_GET_APPID, { + { "", peer}, + { "", appid} })); +} + +std::string DefaultCppTransportable::GenPeerInfoGetUUID(std::string peer, + std::string uuid) const { + return std::string(ReplaceAll(__PEER_INFO_GET_UUID, { + { "", peer}, + { "", uuid} })); +} + +} // namespace tidl diff --git a/idlc/gen_cion/default_cpp_transportable.h b/idlc/gen_cion/default_cpp_transportable.h new file mode 100644 index 0000000..56b0ba5 --- /dev/null +++ b/idlc/gen_cion/default_cpp_transportable.h @@ -0,0 +1,91 @@ +/* + * Copyright (c) 2022 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef IDLC_GEN_CION_DEFAULT_CPP_TRANSPORTABLE_H_ +#define IDLC_GEN_CION_DEFAULT_CPP_TRANSPORTABLE_H_ + +#include + +#include "idlc/gen_cion/cpp_transportable.h" + +namespace tidl { + +class DefaultCppTransportable : public CppTransportable { + public: + virtual ~DefaultCppTransportable() = default; + std::string GenInclude() const override; + std::string GenClientSendAsync(std::string client, + std::string payload, std::string size) const override; + std::string GenClientSend(std::string client, std::string data, + std::string data_size, std::string ret_data, + std::string ret_data_size) const override; + std::string GenServerSendAsync(std::string server, std::string client, + std::string payload, std::string size) const override; + std::string GenServerFileSend(std::string path, + std::string server, std::string peer) const override; + std::string GenClientFileSend(std::string path, + std::string client) const override; + std::string GenGroupType() const override; + std::string GenPayloadTransferStatusType() const override; + std::string GenPeerInfoType() const override; + std::string GenPeerInfoDestroy(std::string peer) const override; + std::string GenPayloadType() const override; + std::string GenClientType() const override; + std::string GenSecurityType() const override; + std::string GenServerType() const override; + std::string GenClientTryConnect(std::string client, + std::string peer) const override; + std::string GenClientDisconnect(std::string client) const override; + std::string GenClientTryDiscovery(std::string client) const override; + std::string GenClientStopDiscovery(std::string client) const override; + std::string GenServerRegister() const override; + std::string GenServerUnregister() const override; + std::string GenClientExtraHeader() const override; + std::string GenClientExtraBody() const override; + std::string GenServerExtraHeader() const override; + std::string GenServerExtraBody() const override; + std::string GenServerAccept() const override; + std::string GenServerReject() const override; + std::string GenServerSetDisplayName() const override; + std::string GenGroupPublish() const override; + std::string GenPayloadTypeEnum() const override; + std::string GenPayloadTypeData() const override; + std::string GenPayloadTypeFile() const override; + std::string GenPayloadGetType() const override; + std::string GenErrorNone() const override; + std::string GenPayloadGetData() const override; + std::string GenClientCreate() const override; + std::string GenGroupCreate() const override; + std::string GenGroupDestroy() const override; + std::string GenClientDestroy() const override; + std::string GenSetSecurityCA(std::string arg) const override; + std::string GenSetSecurityCert(std::string arg) const override; + std::string GenSetSecurityPrivateKey(std::string arg) const override; + std::string GenPeerInfoClone(std::string src_peer, + std::string dest_peer) const override; + std::string GenServerSetOnDemandLaunchEnabled() const override; + std::string GenServerListen() const override; + std::string GenServerDisconnect(std::string server, + std::string peer) const override; + std::string GenPeerInfoGetAppID(std::string peer, + std::string appid) const override; + std::string GenPeerInfoGetUUID(std::string peer, + std::string uuid) const override; +}; + +} // namespace tidl + +#endif // IDLC_GEN_CION_DEFAULT_CPP_TRANSPORTABLE_H_ diff --git a/idlc/gen_cion/plugin_loader.cc b/idlc/gen_cion/plugin_loader.cc index 21812ff..2372a70 100644 --- a/idlc/gen_cion/plugin_loader.cc +++ b/idlc/gen_cion/plugin_loader.cc @@ -17,13 +17,14 @@ #include "idlc/gen_cion/plugin_loader.h" #include "idlc/gen_cion/default_c_transportable.h" +#include "idlc/gen_cion/default_cpp_transportable.h" namespace tidl { PluginLoader::PluginLoader(const std::string& plugin_path) { if (plugin_path.empty()) { C_.reset(new DefaultCTransportable()); - // Cpp_.reset(new DefaultCppTransportable()); + Cpp_.reset(new DefaultCppTransportable()); // Cs_.reset(new DefaultCsTransportable()); // Java_.reset(new DefaultJavaTransportable()); } else {