From ff247755ceb7e78bc6dd8d057adab4358991c1e5 Mon Sep 17 00:00:00 2001 From: Ilho Kim Date: Thu, 24 Feb 2022 13:43:38 +0900 Subject: [PATCH] Adjust plugin structure for type c Change-Id: I1d11cd59b6bd63d9986719e786146fc0f1612470 Signed-off-by: Ilho Kim --- idlc/gen_cion/c_cion_body_gen_base.cc | 27 +- idlc/gen_cion/c_cion_body_gen_base_cb.h | 60 +-- idlc/gen_cion/c_cion_gen_base.cc | 9 +- idlc/gen_cion/c_cion_gen_base.h | 4 +- idlc/gen_cion/c_cion_gen_base_cb.h | 4 +- idlc/gen_cion/c_cion_group_body_gen.cc | 23 +- idlc/gen_cion/c_cion_group_body_gen_cb.h | 110 +---- idlc/gen_cion/c_cion_group_header_gen.cc | 4 +- idlc/gen_cion/c_cion_group_header_gen_cb.h | 6 +- idlc/gen_cion/c_cion_proxy_body_gen.cc | 37 +- idlc/gen_cion/c_cion_proxy_body_gen_cb.h | 135 ++---- idlc/gen_cion/c_cion_proxy_header_gen.cc | 6 +- idlc/gen_cion/c_cion_proxy_header_gen_cb.h | 14 +- idlc/gen_cion/c_cion_stub_body_gen.cc | 53 ++- idlc/gen_cion/c_cion_stub_body_gen_cb.h | 157 ++----- idlc/gen_cion/c_cion_stub_header_gen.cc | 12 +- idlc/gen_cion/c_cion_stub_header_gen_cb.h | 24 +- idlc/gen_cion/c_transportable.h | 21 + idlc/gen_cion/default_c_transportable.cc | 657 +++++++++++++++++++++++++++++ idlc/gen_cion/default_c_transportable.h | 85 ++++ idlc/gen_cion/plugin_loader.cc | 4 +- 21 files changed, 1017 insertions(+), 435 deletions(-) create mode 100644 idlc/gen_cion/default_c_transportable.cc create mode 100644 idlc/gen_cion/default_c_transportable.h diff --git a/idlc/gen_cion/c_cion_body_gen_base.cc b/idlc/gen_cion/c_cion_body_gen_base.cc index b634d9c..bf67087 100644 --- a/idlc/gen_cion/c_cion_body_gen_base.cc +++ b/idlc/gen_cion/c_cion_body_gen_base.cc @@ -755,11 +755,21 @@ void CCionBodyGeneratorBase::GenFilePayloadSend(std::ofstream& stream, bool is_p std::string code = CB_INTERFACE_METHOD_FILE_PAYLOAD_SENDER_DEF; if (is_proxy) { - code = ReplaceAll(code, "", CB_INTERFACE_METHOD_FILE_PAYLOAD_SENDER_CLIENT_DEF); - code = ReplaceAll(code, "", CB_INTERFACE_METHOD_FILE_PAYLOAD_SENDER_CLIENT); + std::string def( + ReplaceAll(CB_INTERFACE_METHOD_FILE_PAYLOAD_SENDER_CLIENT_DEF, + "", GetTransportable().C().GenClientType())); + code = ReplaceAll(code, "", def); + code = ReplaceAll(code, "", + GetTransportable().C().GenClientFileSend("value", "client")); } else { - code = ReplaceAll(code, "", CB_INTERFACE_METHOD_FILE_PAYLOAD_SENDER_SERVER_DEF); - code = ReplaceAll(code, "", CB_INTERFACE_METHOD_FILE_PAYLOAD_SENDER_SERVER); + std::string def( + ReplaceAll(CB_INTERFACE_METHOD_FILE_PAYLOAD_SENDER_SERVER_DEF, + "", GetTransportable().C().GenServerType())); + def = ReplaceAll(def, "", GetTransportable().C().GenPeerInfoType()); + code = ReplaceAll(code, "", def); + code = ReplaceAll(code, "", + GetTransportable().C().GenServerFileSend("value", + "server", "peer_info")); } stream << SmartIndent(code); } @@ -848,11 +858,14 @@ std::string CCionBodyGeneratorBase::GenSecurityString(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().C().GenSetSecurityCA(attr->GetValue()); else if (attr->GetKey() == "cert_path") - security_path += ReplaceAll(CB_INTERFACE_SECURITY_CERT, "", attr->GetValue()); + security_path += + GetTransportable().C().GenSetSecurityCert(attr->GetValue()); else if (attr->GetKey() == "private_key") - security_path += ReplaceAll(CB_INTERFACE_SECURITY_PRIVATE_KEY, "", attr->GetValue()); + security_path += + GetTransportable().C().GenSetSecurityPrivateKey(attr->GetValue()); } return RemoveLine(security_path); diff --git a/idlc/gen_cion/c_cion_body_gen_base_cb.h b/idlc/gen_cion/c_cion_body_gen_base_cb.h index 3b4448c..4da6d3a 100644 --- a/idlc/gen_cion/c_cion_body_gen_base_cb.h +++ b/idlc/gen_cion/c_cion_body_gen_base_cb.h @@ -526,16 +526,10 @@ return CION_ERROR_NONE; constexpr const char CB_INTERFACE_METHOD_FILE_PAYLOAD_SENDER_CLIENT_DEF[] = -R"__c_cb(static int __cion_file_payload_send(cion_client_h client, GList *list))__c_cb"; - -constexpr const char CB_INTERFACE_METHOD_FILE_PAYLOAD_SENDER_CLIENT[] = -R"__c_cb(ret = cion_client_send_payload_async(client, pl, NULL, NULL);)__c_cb"; +R"__c_cb(static int __cion_file_payload_send( client, GList *list))__c_cb"; constexpr const char CB_INTERFACE_METHOD_FILE_PAYLOAD_SENDER_SERVER_DEF[] = -R"__c_cb(static int __cion_file_payload_send(cion_server_h server, const cion_peer_info_h peer_info, GList *list))__c_cb"; - -constexpr const char CB_INTERFACE_METHOD_FILE_PAYLOAD_SENDER_SERVER[] = -R"__c_cb(ret = cion_server_send_payload_async(server, peer_info, pl, NULL, NULL);)__c_cb"; +R"__c_cb(static int __cion_file_payload_send( server, const peer_info, GList *list))__c_cb"; constexpr const char CB_INTERFACE_METHOD_FILE_PAYLOAD_SENDER_DEF[] = R"__c_cb( @@ -543,40 +537,16 @@ R"__c_cb( const char *value; GList *iter; int ret = CION_ERROR_NONE; - cion_payload_h pl; if (g_list_length(list) == 0) { _E("Invalid parameter"); return CION_ERROR_INVALID_PARAMETER; } - iter = list; while (iter) { value = iter->data; - - ret = cion_payload_create(&pl, CION_PAYLOAD_TYPE_FILE); - if (ret != CION_ERROR_NONE) { - _E("Failed to cion_payload_create : %d", ret); - return ret; - } - - ret = cion_payload_set_file_path(pl, value); - if (ret != CION_ERROR_NONE) { - _E("Failed to cion_payload_set_file_path : %d - %s", ret, value); - cion_payload_destroy(pl); - return ret; - } - - - if (ret != CION_ERROR_NONE) { - _E("Failed to cion_client_send_payload_async : %d - %s", ret, value); - cion_payload_destroy(pl); - return ret; - } - - cion_payload_destroy(pl); - + iter = g_list_next(iter); } @@ -705,28 +675,4 @@ R"__c_cb( payload_files_ = g_list_append(payload_files_, (void *)); )__c_cb"; -/** - * The argument. - */ -constexpr const char CB_INTERFACE_SECURITY_CA[] = -R"__c_cb( -cion_security_set_ca_path(security, ""); -)__c_cb"; - -/** - * The argument. - */ -constexpr const char CB_INTERFACE_SECURITY_CERT[] = -R"__c_cb( -cion_security_set_cert_path(security, ""); -)__c_cb"; - -/** - * The argument. - */ -constexpr const char CB_INTERFACE_SECURITY_PRIVATE_KEY[] = -R"__c_cb( -cion_security_set_private_key_path(security, ""); -)__c_cb"; - #endif // IDLC_C_CION_GEN_C_BODY_GEN_BASE_CB_H_ diff --git a/idlc/gen_cion/c_cion_gen_base.cc b/idlc/gen_cion/c_cion_gen_base.cc index a639349..e806157 100644 --- a/idlc/gen_cion/c_cion_gen_base.cc +++ b/idlc/gen_cion/c_cion_gen_base.cc @@ -35,7 +35,7 @@ constexpr const char PREFIX_CION_GROUP[] = "cion_group"; namespace tidl { CCionGeneratorBase::CCionGeneratorBase(std::shared_ptr doc) - : Generator(doc) { + : CionPluginBase(std::move(doc)) { structures_.clear(); type_map_ = { {"char", "char "}, @@ -360,11 +360,14 @@ void CCionGeneratorBase::GenVersion(std::ofstream& stream) { void CCionGeneratorBase::GenIncludeDefaultHeaders(std::ofstream& stream, bool body) { + std::string str; if (body) { - stream << CB_BODY_HEADER; + str = CB_BODY_HEADER; } else { - stream << CB_HEADER; + str = CB_HEADER; } + + stream << ReplaceAll(str, "", GetTransportable().C().GenInclude()); } void CCionGeneratorBase::GenGNUSourceDefinition(std::ofstream& stream) { diff --git a/idlc/gen_cion/c_cion_gen_base.h b/idlc/gen_cion/c_cion_gen_base.h index 3b76d41..4bd0a14 100644 --- a/idlc/gen_cion/c_cion_gen_base.h +++ b/idlc/gen_cion/c_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 CCionGeneratorBase : public Generator { +class CCionGeneratorBase : public CionPluginBase { public: explicit CCionGeneratorBase(std::shared_ptr doc); virtual ~CCionGeneratorBase() = default; diff --git a/idlc/gen_cion/c_cion_gen_base_cb.h b/idlc/gen_cion/c_cion_gen_base_cb.h index 2918072..bd6aeed 100644 --- a/idlc/gen_cion/c_cion_gen_base_cb.h +++ b/idlc/gen_cion/c_cion_gen_base_cb.h @@ -37,7 +37,7 @@ constexpr const char CB_HEADER[] = R"__c_cb( #include #include -#include + )__c_cb"; constexpr const char CB_BODY_HEADER[] = @@ -49,7 +49,7 @@ R"__c_cb( #include #include #include -#include + #include )__c_cb"; diff --git a/idlc/gen_cion/c_cion_group_body_gen.cc b/idlc/gen_cion/c_cion_group_body_gen.cc index e6f8b4f..e8bc72f 100644 --- a/idlc/gen_cion/c_cion_group_body_gen.cc +++ b/idlc/gen_cion/c_cion_group_body_gen.cc @@ -60,6 +60,8 @@ void CCionGroupBodyGen::GenInterfaceDef(std::ofstream& stream, ReplaceAll(CB_INTERFACE_BASE_DEF) .Change("", GetHandlePrefix()) .Change("", iface.GetID()) + .Change("", GetTransportable().C().GenSecurityType()) + .Change("", GetTransportable().C().GenGroupType()) .Transform([&](std::string code) { return SmartIndent(code); }) @@ -113,7 +115,9 @@ void CCionGroupBodyGen::GenInterfaceEnum(std::ofstream& stream, // @see #CB_INTERFACE_METHOD_HANDLER_TYPE void CCionGroupBodyGen::GenInterfaceMethodHandlerType(std::ofstream& stream) { - stream << SmartIndent(CB_INTERFACE_METHOD_HANDLER_TYPE); + std::string code(ReplaceAll(CB_INTERFACE_METHOD_HANDLER_TYPE, + "", GetTransportable().C().GenPeerInfoType())); + stream << SmartIndent(code); } void CCionGroupBodyGen::GenInterfaces(std::ofstream& stream) { @@ -190,11 +194,21 @@ void CCionGroupBodyGen::GenInterfaceBase(std::ofstream& stream, std::string prefix = GetHandlePrefix(); std::string name = iface.GetID(); ReplaceAll(CB_INTERFACE_BASE) + .Change("", GetTransportable().C().GenGroupCreate()) .Change("", prefix) .Change("", name) .ChangeToUpper("", prefix) .ChangeToUpper("", name) .Change("", GenSecurityString(iface)) + .Change("", GetTransportable().C().GenPeerInfoType()) + .Change("", GetTransportable().C().GenSecurityType()) + .Change("", GetTransportable().C().GenPayloadType()) + .Change("", GetTransportable().C().GenPayloadTypeEnum()) + .Change("", GetTransportable().C().GenPayloadGetType()) + .Change("", GetTransportable().C().GenErrorNone()) + .Change("", GetTransportable().C().GenPayloadTypeData()) + .Change("", GetTransportable().C().GenPayloadGetData()) + .Change("", GetTransportable().C().GenGroupDestroy()) .Transform([&](std::string str) { return SmartIndent(str); }) @@ -213,7 +227,8 @@ void CCionGroupBodyGen::GenInterfaceMethodHandlerBase(std::ofstream& stream, GenMethodHandlerParcelRead(iface, decl) }, { "", GenMethodHandlerCallbackInvoke(decl) }, - { "", GenMethodHandlerArgsFree(iface, decl) } + { "", GenMethodHandlerArgsFree(iface, decl) }, + { "", GetTransportable().C().GenPeerInfoType() } }) .Transform([&](std::string str){ return SmartIndent(str); @@ -437,7 +452,9 @@ std::string CCionGroupBodyGen::GenMethodAsyncBase(const Interface& iface, .ChangeToUpper("", prefix) .ChangeToUpper("", name) .ChangeToUpper("", method_name) - .Change("", GenMethodParcelWrite(iface, decl))); + .Change("", GenMethodParcelWrite(iface, decl)) + .Change("", GetTransportable().C().GenPayloadType()) + .Change("", GetTransportable().C().GenGroupPublish())); return code; } diff --git a/idlc/gen_cion/c_cion_group_body_gen_cb.h b/idlc/gen_cion/c_cion_group_body_gen_cb.h index 5aca04f..d1c8a94 100644 --- a/idlc/gen_cion/c_cion_group_body_gen_cb.h +++ b/idlc/gen_cion/c_cion_group_body_gen_cb.h @@ -20,7 +20,7 @@ constexpr const char CB_INTERFACE_METHOD_HANDLER_TYPE[] = R"__c_cb( -typedef int (*cion_group_method_handler)(const cion_peer_info_h peer_info, rpc_port_parcel_h parcel, void *data); +typedef int (*cion_group_method_handler)(const peer_info, rpc_port_parcel_h parcel, void *data); )__c_cb"; /** @@ -84,8 +84,8 @@ constexpr const char CB_INTERFACE_BASE_DEF[] = R"__c_cb( typedef struct __s { char *topic_name; - cion_group_h group; - cion_security_h security; + group; + security; __callback_s callback; GRecMutex mutex; void *user_data; @@ -104,7 +104,7 @@ typedef struct __s { */ constexpr const char CB_INTERFACE_METHOD_HANDLER_BASE[] = R"__c_cb( -static int ____method__handler(const cion_peer_info_h peer_info, rpc_port_parcel_h parcel, void *user_data) +static int ____method__handler(const peer_info, rpc_port_parcel_h parcel, void *user_data) { __t *h = user_data; int ret_ = CION_ERROR_NONE; @@ -133,7 +133,7 @@ static int ____method__handler(const cion_peer_info_h */ constexpr const char CB_INTERFACE_BASE[] = R"__c_cb( -static int ____process_received_event(__t *h, const cion_peer_info_h peer_info, rpc_port_parcel_h parcel) +static int ____process_received_event(__t *h, const peer_info, rpc_port_parcel_h parcel) { int ret = CION_ERROR_NONE; int cmd = -1; @@ -151,7 +151,7 @@ static int ____process_received_event(__t *h, const } static void ____joined_cb(const char *topic_name, - const cion_peer_info_h peer_info, void *user_data) + const peer_info, void *user_data) { __h h = user_data; @@ -160,7 +160,7 @@ static void ____joined_cb(const char *topic_name, } static void ____left_cb(const char *topic_name, - const cion_peer_info_h peer_info, void *user_data) + const peer_info, void *user_data) { __h h = user_data; @@ -170,25 +170,25 @@ static void ____left_cb(const char *topic_name, } static void ____received(const char *topic_name, - const cion_peer_info_h peer_info, cion_payload_h payload, void *user_data) + const peer_info, payload, void *user_data) { __h h = user_data; rpc_port_parcel_h parcel; unsigned char *data; - cion_payload_type_e type; + type; int ret; unsigned int data_len; _W("topic_name(%s)", topic_name); - ret = cion_payload_get_type(payload, &type); - if (ret != CION_ERROR_NONE || type != CION_PAYLOAD_TYPE_DATA) { + + if (ret != || type != ) { _E("Faled to cion_payload_get_type : [%d][%d]", ret, type); return; } - ret = cion_payload_get_data(payload, &data, &data_len); - if (ret != CION_ERROR_NONE) { + + if (ret != ) { _E("Faled to cion_payload_get_data : %d", ret); return; } @@ -209,7 +209,7 @@ int __create(const char *topic_name, __callback_s *c { __t *handle; int ret; - cion_security_h security; + security; if (topic_name == nullptr || callback == nullptr || h == nullptr) { _E("Invalid parameter"); @@ -235,56 +235,7 @@ int __create(const char *topic_name, __callback_s *c __destroy(handle); return CION_ERROR_OUT_OF_MEMORY; } - - ret = cion_security_create(&security); - if (ret != CION_ERROR_NONE) { - _E("Failed to create security handle. error(%d)", ret); - __destroy(handle); - return ret; - } - - - handle->security = security; - - ret = cion_group_create(&handle->group, topic_name, handle->security); - if (ret != CION_ERROR_NONE) { - _E("Failed to create group handle. error(%d)", ret); - __destroy(handle); - return ret; - } - - handle->callback = *callback; - handle->user_data = user_data; - - ret = cion_group_add_joined_cb(handle->group, ____joined_cb, handle); - if (ret != CION_ERROR_NONE) { - _E("Failed to add connection result cb. error(%d)", ret); - __destroy(handle); - return ret; - } - - ret = cion_group_add_left_cb(handle->group, ____left_cb, handle); - if (ret != CION_ERROR_NONE) { - _E("Failed to add disconnected event cb. error(%d)", ret); - __destroy(handle); - return ret; - } - - ret = cion_group_add_payload_received_cb(handle->group, ____received, handle); - if (ret != CION_ERROR_NONE) { - _E("Failed to add received event cb. error(%d)", ret); - __destroy(handle); - return ret; - } - - ret = cion_group_subscribe(handle->group); - if (ret != CION_ERROR_NONE) { - _E("Failed to subscribe event. error(%d)", ret); - __destroy(handle); - return ret; - } - - *h = handle; + return CION_ERROR_NONE; } @@ -300,13 +251,7 @@ int __destroy(__h h) g_rec_mutex_unlock(&h->mutex); g_rec_mutex_clear(&h->mutex); - if (h->group) { - cion_group_unsubscribe(h->group); - cion_group_destroy(h->group); - } - - if (h->security) - cion_security_destroy(h->security); + if (h->topic_name) free(h->topic_name); @@ -337,7 +282,7 @@ void __invoke_(__h h) int res_; unsigned int data_size_; unsigned char *data_; - cion_payload_h pl_ = nullptr; + pl_ = nullptr; if (h == nullptr) { _E("Invalid parameter"); @@ -370,27 +315,8 @@ void __invoke_(__h h) _E("Failed to get raw. error(%d)", res_); goto out; } - - res_ = cion_payload_create(&pl_, CION_PAYLOAD_TYPE_DATA); - if (res_ != CION_ERROR_NONE) { - _E("Failed to cion_payload_create : %d", res_); - goto out; - } - - res_ = cion_payload_set_data(pl_, (const unsigned char*)data_, data_size_); - if (res_ != CION_ERROR_NONE) { - _E("Failed to cion_payload_set_data : %d", res_); - goto out; - } - - res_ = cion_group_publish(h->group, pl_); - if (res_ != CION_ERROR_NONE) { - _E("Failed to cion_group_publish : %d", res_); - goto out; - } - + out: - cion_payload_destroy(pl_); set_last_result(res_); g_rec_mutex_unlock(&h->mutex); diff --git a/idlc/gen_cion/c_cion_group_header_gen.cc b/idlc/gen_cion/c_cion_group_header_gen.cc index a80cf4e..6aaedbf 100644 --- a/idlc/gen_cion/c_cion_group_header_gen.cc +++ b/idlc/gen_cion/c_cion_group_header_gen.cc @@ -73,6 +73,7 @@ void CCionGroupHeaderGen::GenInterfaceCallbackBase(std::ofstream& stream, ReplaceAll(CB_INTERFACE_CALLBACK_BASE) .Change("", GetHandlePrefix()) .Change("", iface.GetID()) + .Change("", GetTransportable().C().GenPeerInfoType()) .Transform([&](std::string code) { return SmartIndent(code); }) @@ -87,7 +88,8 @@ void CCionGroupHeaderGen::GenInterfaceMethodCallbackBase(std::ofstream& stream, { "", GetHandlePrefix() }, { "", iface.GetID() }, { "", decl.GetID() }, - { "", GenMethodParams(iface, decl) } + { "", GenMethodParams(iface, decl) }, + { "", GetTransportable().C().GenPeerInfoType() } }) .Transform([&](std::string code) { return SmartIndent(code); diff --git a/idlc/gen_cion/c_cion_group_header_gen_cb.h b/idlc/gen_cion/c_cion_group_header_gen_cb.h index f8b3859..6dfbc52 100644 --- a/idlc/gen_cion/c_cion_group_header_gen_cb.h +++ b/idlc/gen_cion/c_cion_group_header_gen_cb.h @@ -46,7 +46,7 @@ R"__c_cb( * @see #__callback_s */ typedef void (*__joined_cb)(__h h, - const cion_peer_info_h peer_info, void *user_data); + const peer_info, void *user_data); /** * @brief Called when a peer leaves a topic. @@ -59,7 +59,7 @@ typedef void (*__joined_cb)(__h h, * @see #__callback_s */ typedef void (*__left_cb)(__h h, - const cion_peer_info_h peer_info, void *user_data); + const peer_info, void *user_data); )__c_cb"; @@ -141,7 +141,7 @@ R"__c_cb( * @see cion_peer_info_clone() * @see #__callback_s; */ -typedef (*___cb)(const cion_peer_info_h peer_info, void *user_data); +typedef (*___cb)(const peer_info, void *user_data); )__c_cb"; /** diff --git a/idlc/gen_cion/c_cion_proxy_body_gen.cc b/idlc/gen_cion/c_cion_proxy_body_gen.cc index b3472f8..d11de20 100644 --- a/idlc/gen_cion/c_cion_proxy_body_gen.cc +++ b/idlc/gen_cion/c_cion_proxy_body_gen.cc @@ -92,7 +92,10 @@ void CCionProxyBodyGen::GenInterfaceBaseDef(std::ofstream& stream, const Interface& iface) { ReplaceAll(CB_INTERFACE_BASE_DEF, { { "", GetHandlePrefix() }, - { "", iface.GetID() } + { "", iface.GetID() }, + { "", GetTransportable().C().GenPeerInfoType() }, + { "", GetTransportable().C().GenClientType() }, + { "", GetTransportable().C().GenSecurityType() } }) .Transform([&](std::string code) { return SmartIndent(code); @@ -139,11 +142,32 @@ void CCionProxyBodyGen::GenInterfaceBase(std::ofstream& stream, std::string name = iface.GetID(); ReplaceAll(CB_INTERFACE_BASE) + .Change("", + GetTransportable().C().GenClientTryConnect("h->client", "peer_info")) + .Change("", + GetTransportable().C().GenClientDisconnect("h->client")) + .Change("", + GetTransportable().C().GenClientTryDiscovery("h->client")) + .Change("", + GetTransportable().C().GenClientStopDiscovery("h->client")) + .Change("", GetTransportable().C().GenClientCreate()) .Change("", prefix) .Change("", name) .ChangeToUpper("", prefix) .ChangeToUpper("", name) .Change("", GenSecurityString(iface)) + .Change("", GetTransportable().C().GenPeerInfoType()) + .Change("", GetTransportable().C().GenPayloadType()) + .Change("", + GetTransportable().C().GenPayloadTransferStatusType()) + .Change("", GetTransportable().C().GenSecurityType()) + .Change("", GetTransportable().C().GenPayloadTypeEnum()) + .Change("", GetTransportable().C().GenPayloadGetType()) + .Change("", GetTransportable().C().GenErrorNone()) + .Change("", GetTransportable().C().GenPayloadTypeData()) + .Change("", GetTransportable().C().GenPayloadTypeFile()) + .Change("", GetTransportable().C().GenPayloadGetData()) + .Change("", GetTransportable().C().GenClientDestroy()) .Transform([&](std::string code) { return SmartIndent(code); }) @@ -493,7 +517,11 @@ std::string CCionProxyBodyGen::GenMethodAsyncBase(const Interface& iface, .ChangeToUpper("", method_name) .Change("", GenMethodParcelWrite(iface, decl)) .Change("", GenMethodDelegateAppend(iface, - decl))); + decl)) + .Change("", GetTransportable().C().GenPayloadType()) + .Change("", + GetTransportable().C().GenClientSendAsync( + "h->client", "pl_", "data_size_"))); return code; } @@ -594,7 +622,10 @@ std::string CCionProxyBodyGen::GenMethodBase(const Interface& iface, .Change("", GenMethodParcelWrite(iface, decl)) .Change("", GenMethodParcelRead(iface, decl)) .Change("", GenMethodDelegateAppend(iface, - decl))); + decl)) + .Change("", GetTransportable().C().GenClientSend( + "h->client", "data_", "data_size_", + "return_data_", "return_data_size_"))); return code; } diff --git a/idlc/gen_cion/c_cion_proxy_body_gen_cb.h b/idlc/gen_cion/c_cion_proxy_body_gen_cb.h index 2eab657..40f6fa1 100644 --- a/idlc/gen_cion/c_cion_proxy_body_gen_cb.h +++ b/idlc/gen_cion/c_cion_proxy_body_gen_cb.h @@ -451,8 +451,8 @@ constexpr const char CB_INTERFACE_BASE_DEF[] = R"__c_cb( typedef struct __s { char *service_name; - cion_client_h client; - cion_security_h security; + client; + security; __callback_s callback; void *user_data; GList *delegates; @@ -511,7 +511,7 @@ static void ____consume_command(unsigned char *data, unsigned int *p = nullptr; } -static void ____connection_result(const char *service_name, const cion_peer_info_h peer_info, +static void ____connection_result(const char *service_name, const peer_info, const cion_connection_result_h result, void *user_data) { __h h = user_data; @@ -521,7 +521,7 @@ static void ____connection_result(const char *service_name, const } static void ____disconnected(const char *service_name, - const cion_peer_info_h peer_info, void *user_data) + const peer_info, void *user_data) { __h h = user_data; @@ -531,7 +531,7 @@ static void ____disconnected(const char *service_name, } static void ____discovered(const char *service_name, - const cion_peer_info_h peer_info, void *user_data) + const peer_info, void *user_data) { __h h = user_data; @@ -540,29 +540,29 @@ static void ____discovered(const char *service_name, } static void ____received(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) { __h h = user_data; rpc_port_parcel_h parcel; unsigned char *data; - cion_payload_type_e type; + type; int cmd = -1; int ret; unsigned int data_len; _W("service_name(%s)", service_name); - ret = cion_payload_get_type(payload, &type); - if (ret != CION_ERROR_NONE) { + + if (ret != ) { _E("Faled to cion_payload_get_type : %d", ret); return; } - if (type == CION_PAYLOAD_TYPE_DATA) { - ret = cion_payload_get_data(payload, &data, &data_len); - if (ret != CION_ERROR_NONE) { + if (type == ) { + + if (ret != ) { _E("Faled to cion_payload_get_data : %d", ret); return; } @@ -585,7 +585,7 @@ static void ____received(const char *service_name, ____process_received_event(&h->delegates, parcel); rpc_port_parcel_destroy(parcel); - } else if (type == CION_PAYLOAD_TYPE_FILE) { + } else if (type == ) { if (h->callback.file_received) h->callback.file_received(peer_info, payload, status, h->user_data); } @@ -596,7 +596,7 @@ int __create(const char *service_name, __callback_s { __t *handle; int ret; - cion_security_h security; + security; if (service_name == nullptr || callback == nullptr || h == nullptr) { _E("Invalid parameter"); @@ -622,47 +622,7 @@ int __create(const char *service_name, __callback_s __destroy(handle); return CION_ERROR_OUT_OF_MEMORY; } - - ret = cion_security_create(&security); - if (ret != CION_ERROR_NONE) { - _E("Failed to create security handle. error(%d)", ret); - __destroy(handle); - return ret; - } - - - handle->security = security; - - ret = cion_client_create(&handle->client, service_name, handle->security); - if (ret != CION_ERROR_NONE) { - _E("Failed to create proxy handle. error(%d)", ret); - __destroy(handle); - return ret; - } - - handle->callback = *callback; - handle->user_data = user_data; - - ret = cion_client_add_connection_result_cb(handle->client, ____connection_result, handle); - if (ret != CION_ERROR_NONE) { - _E("Failed to add connection result cb. error(%d)", ret); - __destroy(handle); - return ret; - } - - ret = cion_client_add_disconnected_cb(handle->client, ____disconnected, handle); - if (ret != CION_ERROR_NONE) { - _E("Failed to add disconnected event cb. error(%d)", ret); - __destroy(handle); - return ret; - } - - ret = cion_client_add_payload_received_cb(handle->client, ____received, handle); - if (ret != CION_ERROR_NONE) { - _E("Failed to add received event cb. error(%d)", ret); - __destroy(handle); - return ret; - } + *h = handle; @@ -682,13 +642,7 @@ int __destroy(__h h) if (h->delegates) g_list_free_full(h->delegates, free); - - if (h->client) - cion_client_destroy(h->client); - - if (h->security) - cion_security_destroy(h->security); - + if (h->service_name) free(h->service_name); @@ -697,7 +651,7 @@ int __destroy(__h h) return CION_ERROR_NONE; } -int __try_connect(__h h, const cion_peer_info_h peer_info) +int __try_connect(__h h, const peer_info) { int ret; @@ -706,11 +660,7 @@ int __try_connect(__h h, const cion_peer_info_h peer return CION_ERROR_INVALID_PARAMETER; } - ret = cion_client_connect(h->client, peer_info); - if (ret != CION_ERROR_NONE) { - _E("Failed to connect to stub. error(%d)", ret); - return ret; - } + return CION_ERROR_NONE; } @@ -725,11 +675,7 @@ int __disconnect(__h h) return CION_ERROR_INVALID_PARAMETER; } - ret = cion_client_disconnect(h->client); - if (ret != CION_ERROR_NONE) { - _E("Failed to disconnect to stub. error(%d)", ret); - return ret; - } + return CION_ERROR_NONE; } @@ -743,11 +689,7 @@ int __try_discovery(__h h) return CION_ERROR_INVALID_PARAMETER; } - ret = cion_client_try_discovery(h->client, ____discovered, h); - if (ret != CION_ERROR_NONE) { - _E("Failed to discovery to stub. error(%d)", ret); - return ret; - } + return CION_ERROR_NONE; } @@ -761,11 +703,7 @@ int __stop_discovery(__h h) return CION_ERROR_INVALID_PARAMETER; } - ret = cion_client_stop_discovery(h->client); - if (ret != CION_ERROR_NONE) { - _E("Failed to stop discovery to stub. error(%d)", ret); - return ret; - } + return CION_ERROR_NONE; } @@ -791,7 +729,7 @@ void __invoke_(__h h) int res_; unsigned int data_size_; unsigned char *data_; - cion_payload_h pl_ = nullptr; + pl_ = nullptr; if (h == nullptr) { @@ -827,28 +765,10 @@ void __invoke_(__h h) goto out; } - res_ = cion_payload_create(&pl_, CION_PAYLOAD_TYPE_DATA); - if (res_ != CION_ERROR_NONE) { - _E("Failed to cion_payload_create : %d", res_); - goto out; - } - - res_ = cion_payload_set_data(pl_, (const unsigned char*)data_, data_size_); - if (res_ != CION_ERROR_NONE) { - _E("Failed to cion_payload_set_data : %d", res_); - goto out; - } - - res_ = cion_client_send_payload_async(h->client, pl_, NULL, NULL); - if (res_ != CION_ERROR_NONE) { - _E("Failed to cion_client_send_payload_async : %d", res_); - goto out; - } - + out: - cion_payload_destroy(pl_); rpc_port_parcel_destroy(parcel_); @@ -920,12 +840,7 @@ R"__c_cb( goto out; } - res_ = cion_client_send_data(h->client, data_, data_size_ , 5 * 1000, &return_data_, &return_data_size_); - - if (res_ != CION_ERROR_NONE) { - _E("Failed to send parcel. error(%d)", res_); - goto out; - } + rpc_port_parcel_destroy(parcel_); parcel_ = nullptr; diff --git a/idlc/gen_cion/c_cion_proxy_header_gen.cc b/idlc/gen_cion/c_cion_proxy_header_gen.cc index 4e9c4f4..528af9b 100644 --- a/idlc/gen_cion/c_cion_proxy_header_gen.cc +++ b/idlc/gen_cion/c_cion_proxy_header_gen.cc @@ -114,7 +114,11 @@ void CCionProxyHeaderGen::GenInterfaceBase(std::ofstream& stream, const Interface& iface) { std::string code(ReplaceAll(CB_INTERFACE_BASE, { { "", GetHandlePrefix() }, - { "", iface.GetID() } + { "", iface.GetID() }, + { "", GetTransportable().C().GenPeerInfoType() }, + { "", GetTransportable().C().GenPayloadType() }, + { "", + GetTransportable().C().GenPayloadTransferStatusType() } })); stream << SmartIndent(code); diff --git a/idlc/gen_cion/c_cion_proxy_header_gen_cb.h b/idlc/gen_cion/c_cion_proxy_header_gen_cb.h index 352ff08..969fe40 100644 --- a/idlc/gen_cion/c_cion_proxy_header_gen_cb.h +++ b/idlc/gen_cion/c_cion_proxy_header_gen_cb.h @@ -233,7 +233,7 @@ typedef void (*__disconnected_cb)(__h h, void *user_ * @par Sample code: * @code -void __stub_discovered_cb(const cion_peer_info_h peer_info, void *user_data) +void __stub_discovered_cb(const peer_info, void *user_data) { __h handle = user_data; char *app_id = NULL; @@ -247,7 +247,7 @@ void __stub_discovered_cb(const cion_peer_info_h peer_info, void * } * @endcode */ -typedef void (*__stub_discovered_cb)(const cion_peer_info_h peer_info, void *user_data); +typedef void (*__stub_discovered_cb)(const peer_info, void *user_data); /** @@ -266,8 +266,8 @@ typedef void (*__stub_discovered_cb)(const cion_peer_info_h peer_i * @par Sample code: * @code -void ___file_received_cb(const cion_peer_info_h peer_info, const cion_payload_h payload, - cion_payload_transfer_status_e status, void *user_data) +void ___file_received_cb(const peer_info, const payload, + status, void *user_data) { __h handle = user_data; @@ -305,8 +305,8 @@ end: } * @endcode */ -typedef void (*__file_received_cb)(const cion_peer_info_h peer_info, const cion_payload_h payload, - cion_payload_transfer_status_e status, void *user_data); +typedef void (*__file_received_cb)(const peer_info, const payload, + status, void *user_data); /** * @brief The structure type containing the set of callback functions for handling proxy events. @@ -369,7 +369,7 @@ int __destroy(__h h); * @retval #CION_ERROR_INVALID_OPERATION Invalid operation * @retval #CION_ERROR_IO_ERROR IO error */ -int __try_connect(__h h, const cion_peer_info_h peer_info); +int __try_connect(__h h, const peer_info); /** * @brief Disconnects from a server. diff --git a/idlc/gen_cion/c_cion_stub_body_gen.cc b/idlc/gen_cion/c_cion_stub_body_gen.cc index 7e09b51..c6bccc5 100644 --- a/idlc/gen_cion/c_cion_stub_body_gen.cc +++ b/idlc/gen_cion/c_cion_stub_body_gen.cc @@ -57,7 +57,10 @@ void CCionStubBodyGen::GenThreadEnableDefinition(std::ofstream& stream) { // @see #CB_INTERFACE_METHOD_HANDLER_TYPE void CCionStubBodyGen::GenInterfaceMethodHandlerType(std::ofstream& stream) { - stream << SmartIndent(CB_INTERFACE_METHOD_HANDLER_TYPE); + std::string code(ReplaceAll(CB_INTERFACE_METHOD_HANDLER_TYPE, + "", GetTransportable().C().GenPeerInfoType())); + + stream << SmartIndent(code); } void CCionStubBodyGen::GenInterfaceEnums(std::ofstream& stream) { @@ -185,7 +188,8 @@ void CCionStubBodyGen::GenInterfaceDelegateDef(std::ofstream& stream, std::string code(ReplaceAll(CB_INTERFACE_DELEGATE_DEF, { { "", GetHandlePrefix() }, { "", iface.GetID() }, - { "", decl.GetID() } + { "", decl.GetID() }, + { "", GetTransportable().C().GenPeerInfoType() } })); stream << SmartIndent(code); @@ -196,7 +200,9 @@ void CCionStubBodyGen::GenInterfaceBaseDef(std::ofstream& stream, const Interface& iface) { std::string code(ReplaceAll(CB_INTERFACE_BASE_DEF, { { "", GetHandlePrefix() }, - { "", iface.GetID() } + { "", iface.GetID() }, + { "", GetTransportable().C().GenServerType() }, + { "", GetTransportable().C().GenSecurityType() } })); stream << SmartIndent(code); @@ -237,7 +243,8 @@ void CCionStubBodyGen::GenInterfaceContextBase(std::ofstream& stream, const Interface& iface) { std::string code(ReplaceAll(CB_INTERFACE_CONTEXT_BASE, { { "", GetHandlePrefix() }, - { "", iface.GetID() } + { "", iface.GetID() }, + { "", GetTransportable().C().GenPeerInfoType() } })); stream << SmartIndent(code); @@ -334,13 +341,25 @@ void CCionStubBodyGen::GenInterfaceDelegateBase(std::ofstream& stream, { "", GetHandlePrefix() }, { "", file_send }, { "", file_free }, + { "", GetTransportable().C().GenServerSendAsync( + "__.stub", "", "pl_", "data_size_") }, { "", iface.GetID() }, { "", decl.GetID() }, { "", GenDelegateParams(iface, decl) }, { "", file_def }, { "", GenDelegateParamsCheck(iface, decl) }, { "", enum_value }, - { "", GenDelegateParcelWrite(iface, decl) } + { "", GenDelegateParcelWrite(iface, decl) }, + { "", GetTransportable().C().GenPeerInfoType() }, + { "", GetTransportable().C().GenPayloadType() }, + { "", + GetTransportable().C().GenPeerInfoDestroy("h->peer_info") }, + { "", + GetTransportable().C() + .GenPeerInfoClone("h->peer_info", "&handle->peer_info") }, + { "", + GetTransportable().C() + .GenPeerInfoClone("peer_info", "&h->peer_info") } })); stream << SmartIndent(code); @@ -602,7 +621,8 @@ void CCionStubBodyGen::GenInterfaceMethodHandlerBase(std::ofstream& stream, { "", GenMethodHandlerCallbackInvoke(decl) }, { "", GenMethodHandlerParcelWrite(iface, decl) }, { "", file_free }, - { "", GenMethodHandlerArgsFree(iface, decl) } + { "", GenMethodHandlerArgsFree(iface, decl) }, + { "", GetTransportable().C().GenPeerInfoType() } })); stream << SmartIndent(code); @@ -647,9 +667,28 @@ void CCionStubBodyGen::GenInterfaceMethodTable(std::ofstream& stream, void CCionStubBodyGen::GenInterfaceBase(std::ofstream& stream, const Interface& iface) { std::string code(ReplaceAll(CB_INTERFACE_BASE, { + { "", GetTransportable().C().GenServerRegister() }, + { "", GetTransportable().C().GenServerUnregister() }, + { "", GetTransportable().C().GenServerAccept() }, + { "", GetTransportable().C().GenServerReject() }, + { "", + GetTransportable().C().GenServerSetDisplayName() }, { "", GetHandlePrefix() }, { "", iface.GetID() }, - { "", GenSecurityString(iface) } + { "", GenSecurityString(iface) }, + { "", GetTransportable().C().GenPeerInfoType() }, + { "", GetTransportable().C().GenPayloadType() }, + { "", + GetTransportable().C().GenPayloadTransferStatusType() }, + { "", GetTransportable().C().GenSecurityType() }, + { "", GetTransportable().C().GenPayloadTypeEnum() }, + { "", GetTransportable().C().GenPayloadGetType() }, + { "", GetTransportable().C().GenErrorNone() }, + { "", GetTransportable().C().GenPayloadTypeData() }, + { "", GetTransportable().C().GenPayloadTypeFile() }, + { "", GetTransportable().C().GenPayloadGetData() }, + { "", GetTransportable().C().GenServerForeachConnectedPeerInfo(iface.GetID()) }, + { "", GetTransportable().C().GenServerSetOnDemandLaunchEnabled(iface.GetID()) } })); stream << SmartIndent(code); diff --git a/idlc/gen_cion/c_cion_stub_body_gen_cb.h b/idlc/gen_cion/c_cion_stub_body_gen_cb.h index 80414e3..b28eaee 100644 --- a/idlc/gen_cion/c_cion_stub_body_gen_cb.h +++ b/idlc/gen_cion/c_cion_stub_body_gen_cb.h @@ -27,7 +27,7 @@ R"__c_cb( */ constexpr const char CB_INTERFACE_METHOD_HANDLER_TYPE[] = R"__c_cb( -typedef int (*cion_stub_method_handler)(const cion_peer_info_h peer_info, rpc_port_parcel_h parcel, rpc_port_parcel_h return_parcel, void *data); +typedef int (*cion_stub_method_handler)(const peer_info, rpc_port_parcel_h parcel, rpc_port_parcel_h return_parcel, void *data); )__c_cb"; /** @@ -82,8 +82,8 @@ R"__c_cb( constexpr const char CB_INTERFACE_BASE_DEF[] = R"__c_cb( typedef struct __s { - cion_server_h stub; - cion_security_h security; + stub; + security; __callback_s callback; void *user_data; GRecMutex mutex; @@ -101,7 +101,7 @@ constexpr const char CB_INTERFACE_DELEGATE_DEF[] = R"__c_cb( typedef struct ___s { rpc_port_parcelable_t parcelable; - cion_peer_info_h peer_info; + peer_info; int id; int seq_id; bool once; @@ -115,7 +115,7 @@ typedef struct ___s { */ constexpr const char CB_INTERFACE_CONTEXT_BASE[] = R"__c_cb( -static int ____process_received_event(__t *h, const cion_peer_info_h peer_info, rpc_port_parcel_h parcel, rpc_port_parcel_h return_parcel) +static int ____process_received_event(__t *h, const peer_info, rpc_port_parcel_h parcel, rpc_port_parcel_h return_parcel) { int ret = CION_ERROR_NONE; int cmd = -1; @@ -220,7 +220,7 @@ int ___destroy(___h h) _W("id(%d), seq_id(%d), once(%s)", h->id, h->seq_id, h->once ? "true" : "false"); if (h->peer_info) - cion_peer_info_destroy(h->peer_info); + free(h); @@ -243,7 +243,7 @@ int ___clone(___h h, < return ret; } - cion_peer_info_clone(h->peer_info, &handle->peer_info); + handle->seq_id = h->seq_id; handle->once = h->once; handle->valid = h->valid; @@ -311,14 +311,14 @@ int ___get_tag(___h h, return CION_ERROR_NONE; } -static int _____set_peerInfo(___h h, const cion_peer_info_h peer_info) +static int _____set_peerInfo(___h h, const peer_info) { if (h == nullptr || peer_info == nullptr) { _E("Invalid parameter"); return CION_ERROR_INVALID_PARAMETER; } - return cion_peer_info_clone(peer_info, &h->peer_info); + return } int ___invoke(___h h) @@ -327,8 +327,8 @@ int ___invoke(___h h pl_ = nullptr; + peer_info; @@ -365,30 +365,13 @@ int ___invoke(___h h.stub, peer_info, pl_, NULL, NULL); - if (ret_ != CION_ERROR_NONE) { - _E("Failed to cion_client_send_payload_async : %d", ret_); - goto out; - } + h->valid = false; out: - cion_payload_destroy(pl_); rpc_port_parcel_destroy(parcel_); g_rec_mutex_unlock(&__.mutex); @@ -442,7 +425,7 @@ rpc_port_parcel_write_(parcel_, ); */ constexpr const char CB_INTERFACE_METHOD_HANDLER_BASE[] = R"__c_cb( -static int ____method__handler(const cion_peer_info_h peer_info, rpc_port_parcel_h parcel, rpc_port_parcel_h return_parcel, void *user_data) +static int ____method__handler(const peer_info, rpc_port_parcel_h parcel, rpc_port_parcel_h return_parcel, void *user_data) { __t *h = user_data; int ret_ = CION_ERROR_NONE; @@ -662,7 +645,7 @@ R"__c_cb( constexpr const char CB_INTERFACE_BASE[] = R"__c_cb( static void ____disconnected_cb(const char *service_name, - const cion_peer_info_h peer_info, void *user_data) + const peer_info, void *user_data) { __t *h = user_data; @@ -670,7 +653,7 @@ static void ____disconnected_cb(const char *service_name, h->callback.disconnected(peer_info, h->user_data); } -static void ____connection_result_cb(const char *service_name, const cion_peer_info_h peer_info, +static void ____connection_result_cb(const char *service_name, const peer_info, const cion_connection_result_h result, void *user_data) { __t *h = user_data; @@ -680,28 +663,28 @@ static void ____connection_result_cb(const char *service_name, con } static void ____payload_received_cb(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) { __t* h = user_data; rpc_port_parcel_h parcel; unsigned char *data; - cion_payload_type_e type; + type; int ret; unsigned int data_len; _W("service_name(%s)", service_name); - ret = cion_payload_get_type(payload, &type); - if (ret != CION_ERROR_NONE) { + + if (ret != ) { _E("Faled to cion_payload_get_type : %d", ret); return; } - if (type == CION_PAYLOAD_TYPE_DATA) { - ret = cion_payload_get_data(payload, &data, &data_len); - if (ret != CION_ERROR_NONE) { + if (type == ) { + + if (ret != ) { _E("Faled to cion_payload_get_data : %d", ret); return; } @@ -716,7 +699,7 @@ static void ____payload_received_cb(const char *service_name, ____process_received_event(h, peer_info, parcel, NULL); rpc_port_parcel_destroy(parcel); - } else if (type == CION_PAYLOAD_TYPE_FILE) { + } else if (type == ) { if (h->callback.file_received) h->callback.file_received(peer_info, payload, status, h->user_data); } @@ -724,7 +707,7 @@ static void ____payload_received_cb(const char *service_name, } static void ____data_received_cb(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) { @@ -768,7 +751,7 @@ static void ____data_received_cb(const char *service_name, } static void ____connection_request_cb(const char *service_name, - const cion_peer_info_h peer_info, void *user_data) + const peer_info, void *user_data) { __t *h = user_data; @@ -780,7 +763,7 @@ static void ____connection_request_cb(const char *service_name, int __register(const char *service_name, const char *display_name, __callback_s *callback, void *user_data) { int ret; - cion_security_h security; + security; if (callback == nullptr || callback->connection_result == nullptr || callback->disconnected == nullptr || callback->connection_request == nullptr) { _E("Invalid parameter"); @@ -796,56 +779,7 @@ int __register(const char *service_name, const char *display_name, __.callback = *callback; __.user_data = user_data; - ret = cion_security_create(&security); - if (ret != CION_ERROR_NONE) { - _E("Failed to create security handle. error(%d)", ret); - return ret; - } - - - __.security = security; - - ret = cion_server_create(&__.stub, service_name, display_name, __.security); - if (ret != CION_ERROR_NONE) { - _E("Failed to create stub handle. error(%d)", ret); - __unregister(); - return ret; - } - - ret = cion_server_add_connection_result_cb(__.stub, ____connection_result_cb, &__); - if (ret != CION_ERROR_NONE) { - _E("Failed to add connection result event callback"); - __unregister(); - return ret; - } - - ret = cion_server_add_payload_received_cb(__.stub, ____payload_received_cb, &__); - if (ret != CION_ERROR_NONE) { - _E("Failed to add payload recieved event callback"); - __unregister(); - return ret; - } - - ret = cion_server_add_disconnected_cb(__.stub, ____disconnected_cb, &__); - if (ret != CION_ERROR_NONE) { - _E("Failed to add disconnected event callback"); - __unregister(); - return ret; - } - - ret = cion_server_set_data_received_cb(__.stub, ____data_received_cb, &__); - if (ret != CION_ERROR_NONE) { - _E("Failed to add data recieved event callback"); - __unregister(); - return ret; - } - - ret = cion_server_listen(__.stub, ____connection_request_cb, &__); - if (ret != CION_ERROR_NONE) { - _E("Failed to listen events. error(%d)", ret); - __unregister(); - return ret; - } + return CION_ERROR_NONE; } @@ -856,13 +790,7 @@ int __unregister(void) g_rec_mutex_unlock(&__.mutex); g_rec_mutex_clear(&__.mutex); - if (__.security) - cion_security_destroy(__.security); - - if (__.stub) { - cion_server_destroy(__.stub); - __.stub = nullptr; - } + return CION_ERROR_NONE; } @@ -875,13 +803,13 @@ int __foreach_peer_info(__peer_info_cb callback, voi } g_rec_mutex_lock(&__.mutex); - cion_server_foreach_connected_peer_info(__.stub, callback, user_data); + g_rec_mutex_unlock(&__.mutex); return CION_ERROR_NONE; } -int __accept(const cion_peer_info_h peer_info) +int __accept(const peer_info) { int ret; @@ -889,15 +817,12 @@ int __accept(const cion_peer_info_h peer_info) _E("Invalid parameter"); return CION_ERROR_INVALID_PARAMETER; } - - ret = cion_server_accept(__.stub, peer_info); - if (ret != CION_ERROR_NONE) - _E("Failed to accept. error(%d)", ret); + return ret; } -int __reject(const cion_peer_info_h peer_info, const char *reason) +int __reject(const peer_info, const char *reason) { int ret; @@ -906,9 +831,7 @@ int __reject(const cion_peer_info_h peer_info, const char *reason) return CION_ERROR_INVALID_PARAMETER; } - ret = cion_server_reject(__.stub, peer_info, reason); - if (ret != CION_ERROR_NONE) - _E("Failed to reject. error(%d)", ret); + return ret; } @@ -922,22 +845,14 @@ int __set_display_name(const char *display_name) return CION_ERROR_INVALID_PARAMETER; } - ret = cion_server_set_display_name(__.stub, display_name); - if (ret != CION_ERROR_NONE) - _E("Failed to set display name. error(%d)", ret); + return ret; } int __set_ondemand_launch_enabled(bool enable) { - int ret; - - ret = cion_server_set_on_demand_launch_enabled(__.stub, enable); - if (ret != CION_ERROR_NONE) - _E("Failed to set ondemand launch enable. error(%d)", ret); - - return ret; + } )__c_cb"; diff --git a/idlc/gen_cion/c_cion_stub_header_gen.cc b/idlc/gen_cion/c_cion_stub_header_gen.cc index 9a6c485..c1fc7eb 100644 --- a/idlc/gen_cion/c_cion_stub_header_gen.cc +++ b/idlc/gen_cion/c_cion_stub_header_gen.cc @@ -87,7 +87,11 @@ void CCionStubHeaderGen::GenInterfaceCallbackBase(std::ofstream& stream, const Interface& iface) { std::string code(ReplaceAll(CB_INTERFACE_CALLBACK_BASE, { { "", GetHandlePrefix() }, - { "", iface.GetID() } + { "", iface.GetID() }, + { "", GetTransportable().C().GenPeerInfoType() }, + { "", GetTransportable().C().GenPayloadType() }, + { "", + GetTransportable().C().GenPayloadTransferStatusType() } })); stream << SmartIndent(code); @@ -115,7 +119,8 @@ void CCionStubHeaderGen::GenInterfaceMethodCallbackBase(std::ofstream& stream, { "", GetHandlePrefix() }, { "", iface.GetID() }, { "", decl.GetID() }, - { "", GenMethodParams(iface, decl) } + { "", GenMethodParams(iface, decl) }, + { "", GetTransportable().C().GenPeerInfoType() } })); stream << SmartIndent(code); @@ -196,7 +201,8 @@ void CCionStubHeaderGen::GenInterfaceBase(std::ofstream& stream, std::string code(ReplaceAll(CB_INTERFACE_BASE, { { "", GetHandlePrefix() }, { "", iface.GetID() }, - { "", GenMethodCallbackDecls(iface) } + { "", GenMethodCallbackDecls(iface) }, + { "", GetTransportable().C().GenPeerInfoType() } })); stream << SmartIndent(code); diff --git a/idlc/gen_cion/c_cion_stub_header_gen_cb.h b/idlc/gen_cion/c_cion_stub_header_gen_cb.h index 80c8607..44a80da 100644 --- a/idlc/gen_cion/c_cion_stub_header_gen_cb.h +++ b/idlc/gen_cion/c_cion_stub_header_gen_cb.h @@ -161,7 +161,7 @@ R"__c_cb( * @see #__callback_s * @see #cion_peer_info_clone() */ -typedef void (*__connection_result_cb)(const cion_peer_info_h peer_info, +typedef void (*__connection_result_cb)(const peer_info, const cion_connection_result_h result, void *user_data); /** @@ -174,7 +174,7 @@ typedef void (*__connection_result_cb)(const cion_peer_info_h peer * @see #__callback_s * @see #cion_peer_info_clone() */ -typedef void (*__disconnected_cb)(const cion_peer_info_h peer_info, void *user_data); +typedef void (*__disconnected_cb)(const peer_info, void *user_data); /** * @brief Called to get the proxy once for each connected proxy. @@ -186,7 +186,7 @@ typedef void (*__disconnected_cb)(const cion_peer_info_h peer_info * @pre __foreach_peer_info_cb() will invoke this callback. * @see __foreach_peer_info_cb() */ -typedef bool (*__peer_info_cb)(const cion_peer_info_h peer_info, void *user_data); +typedef bool (*__peer_info_cb)(const peer_info, void *user_data); /** * @brief Called when the payload is received. @@ -204,8 +204,8 @@ typedef bool (*__peer_info_cb)(const cion_peer_info_h peer_info, v * @par Sample code: * @code -void ___file_received_cb(const cion_peer_info_h peer_info, const cion_payload_h payload, - cion_payload_transfer_status_e status, void *user_data) +void ___file_received_cb(const peer_info, const payload, + status, void *user_data) { __h handle = user_data; @@ -243,8 +243,8 @@ end: * @endcode */ -typedef void (*__file_received_cb)(const cion_peer_info_h peer_info, const cion_payload_h payload, - cion_payload_transfer_status_e status, void *user_data); +typedef void (*__file_received_cb)(const peer_info, const payload, + status, void *user_data); /** * @brief Called when a connection is requested. @@ -258,7 +258,7 @@ typedef void (*__file_received_cb)(const cion_peer_info_h peer_inf * @par Sample code: * @code -void __connection_request_cb(const cion_peer_info_h peer_info, void *user_data) +void __connection_request_cb(const peer_info, void *user_data) { char *app_version = NULL; @@ -275,7 +275,7 @@ void __connection_request_cb(const cion_peer_info_h peer_info, voi } * @endcode */ -typedef void (*__connection_request_cb)(const cion_peer_info_h peer_info, void *user_data); +typedef void (*__connection_request_cb)(const peer_info, void *user_data); )__c_cb"; @@ -295,7 +295,7 @@ R"__c_cb( * @param[in] user_data The user data passed from the registration function * @see #__callback_s; */ -typedef (*___cb)(const cion_peer_info_h peer_info, void *user_data); +typedef (*___cb)(const peer_info, void *user_data); )__c_cb"; /** @@ -374,7 +374,7 @@ int __foreach_peer_info(__peer_info_cb callback, voi * @see __register() * @see __connection_request_cb() */ -int __accept(const cion_peer_info_h peer_info); +int __accept(const peer_info); /** * @brief Rejects the connection request from a peer. @@ -388,7 +388,7 @@ int __accept(const cion_peer_info_h peer_info); * @see __register() * @see __connection_request_cb() */ -int __reject(const cion_peer_info_h peer_info, const char *reason); +int __reject(const peer_info, const char *reason); /** * @brief Sets the stub display name. diff --git a/idlc/gen_cion/c_transportable.h b/idlc/gen_cion/c_transportable.h index 83f9335..c8a3d83 100644 --- a/idlc/gen_cion/c_transportable.h +++ b/idlc/gen_cion/c_transportable.h @@ -17,6 +17,7 @@ #ifndef IDLC_GEN_CION_C_TRANSPORTABLE_H_ #define IDLC_GEN_CION_C_TRANSPORTABLE_H_ +#include #include namespace tidl { @@ -36,8 +37,10 @@ class CTransportable { 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 +59,24 @@ class CTransportable { 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 GenServerForeachConnectedPeerInfo(std::string name) const = 0; + virtual std::string GenServerSetOnDemandLaunchEnabled(std::string name) const = 0; }; } // namespace tidl diff --git a/idlc/gen_cion/default_c_transportable.cc b/idlc/gen_cion/default_c_transportable.cc new file mode 100644 index 0000000..a858a97 --- /dev/null +++ b/idlc/gen_cion/default_c_transportable.cc @@ -0,0 +1,657 @@ +/* + * 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_c_transportable.h" + +#include + +#include "idlc/gen/replace_all.h" + +namespace { + +constexpr const char __CLINET_FILE_SEND[] = +R"__c_cb( + 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; + } + + ret = cion_payload_set_file_path(pl, ); + if (ret != CION_ERROR_NONE) { + _E("Failed to cion_payload_set_file_path : %d - %s", ret, value); + cion_payload_destroy(pl); + return ret; + } + + ret = cion_client_send_payload_async(, pl, NULL, NULL); + if (ret != CION_ERROR_NONE) { + _E("Failed to cion_client_send_payload_async : %d - %s", ret, value); + cion_payload_destroy(pl); + return ret; + } + + cion_payload_destroy(pl); +)__c_cb"; + +constexpr const char __SERVER_FILE_SEND[] = +R"__c_cb( + cion_payload_h pl; + int r = cion_payload_create(&pl, CION_PAYLOAD_TYPE_FILE); + + if (r != CION_ERROR_NONE) { + _E("Failed to cion_payload_create : %d", r); + return r; + } + + r = cion_payload_set_file_path(pl, ); + if (r != CION_ERROR_NONE) { + _E("Failed to cion_payload_set_file_path : %d - %s", r, value); + cion_payload_destroy(pl); + return r; + } + + r = cion_server_send_payload_async(, , pl, NULL, NULL); + if (r != CION_ERROR_NONE) { + _E("Failed to cion_server_send_payload_async : %d - %s", r, value); + cion_payload_destroy(pl); + return r; + } + + cion_payload_destroy(pl); +)__c_cb"; + +constexpr const char __SERVER_REGISTER[] = +R"__c_cb( + ret = cion_security_create(&security); + if (ret != CION_ERROR_NONE) { + _E("Failed to create security handle. error(%d)", ret); + return ret; + } + + + __.security = security; + + ret = cion_server_create(&__.stub, service_name, display_name, __.security); + if (ret != CION_ERROR_NONE) { + _E("Failed to create stub handle. error(%d)", ret); + __unregister(); + return ret; + } + + ret = cion_server_add_connection_result_cb(__.stub, ____connection_result_cb, &__); + if (ret != CION_ERROR_NONE) { + _E("Failed to add connection result event callback"); + __unregister(); + return ret; + } + + ret = cion_server_add_payload_received_cb(__.stub, ____payload_received_cb, &__); + if (ret != CION_ERROR_NONE) { + _E("Failed to add payload recieved event callback"); + __unregister(); + return ret; + } + + ret = cion_server_add_disconnected_cb(__.stub, ____disconnected_cb, &__); + if (ret != CION_ERROR_NONE) { + _E("Failed to add disconnected event callback"); + __unregister(); + return ret; + } + + ret = cion_server_set_data_received_cb(__.stub, ____data_received_cb, &__); + if (ret != CION_ERROR_NONE) { + _E("Failed to add data recieved event callback"); + __unregister(); + return ret; + } + + ret = cion_server_listen(__.stub, ____connection_request_cb, &__); + if (ret != CION_ERROR_NONE) { + _E("Failed to listen events. error(%d)", ret); + __unregister(); + return ret; + } +)__c_cb"; + + + +constexpr const char __SERVER_UNREGISTER[] = +R"__c_cb( + if (__.security) + cion_security_destroy(__.security); + + if (__.stub) { + cion_server_destroy(__.stub); + __.stub = nullptr; + } +)__c_cb"; + +constexpr const char __SERVER_ACCEPT[] = +R"__c_cb( + ret = cion_server_accept(__.stub, peer_info); + if (ret != CION_ERROR_NONE) + _E("Failed to accept. error(%d)", ret); +)__c_cb"; + +constexpr const char __SERVER_REJECT[] = +R"__c_cb( + ret = cion_server_reject(__.stub, peer_info, reason); + if (ret != CION_ERROR_NONE) + _E("Failed to reject. error(%d)", ret); +)__c_cb"; + +constexpr const char __SERVER_SET_DISPLAY_NAME[] = +R"__c_cb( + ret = cion_server_set_display_name(__.stub, display_name); + if (ret != CION_ERROR_NONE) + _E("Failed to set display name. error(%d)", ret); +)__c_cb"; + +constexpr const char __CLIENT_TRY_CONNECT[] = +R"__c_cb( + ret = cion_client_connect(, ); + if (ret != CION_ERROR_NONE) { + _E("Failed to connect to stub. error(%d)", ret); + return ret; + } +)__c_cb"; + +constexpr const char __CLIENT_DISCONNECT[] = +R"__c_cb( + ret = cion_client_disconnect(); + if (ret != CION_ERROR_NONE) { + _E("Failed to disconnect to stub. error(%d)", ret); + return ret; + } +)__c_cb"; + +constexpr const char __CLIENT_TRY_DISCOVERY[] = +R"__c_cb( + ret = cion_client_try_discovery(, ____discovered, h); + if (ret != CION_ERROR_NONE) { + _E("Failed to discovery to stub. error(%d)", ret); + return ret; + } +)__c_cb"; + +constexpr const char __CLIENT_STOP_DISCOVERY[] = +R"__c_cb( + ret = cion_client_stop_discovery(); + if (ret != CION_ERROR_NONE) { + _E("Failed to stop discovery to stub. error(%d)", ret); + return ret; + } +)__c_cb"; + +constexpr const char __CLIENT_SEND_ASYNC[] = +R"__c_cb( + res_ = cion_payload_create(&, CION_PAYLOAD_TYPE_DATA); + if (res_ != CION_ERROR_NONE) { + _E("Failed to cion_payload_create : %d", res_); + cion_payload_destroy(); + goto out; + } + + res_ = cion_payload_set_data(, (const unsigned char*)data_, ); + if (res_ != CION_ERROR_NONE) { + _E("Failed to cion_payload_set_data : %d", res_); + cion_payload_destroy(); + goto out; + } + + res_ = cion_client_send_payload_async(, , NULL, NULL); + cion_payload_destroy(); + if (res_ != CION_ERROR_NONE) { + _E("Failed to cion_client_send_payload_async : %d", res_); + goto out; + } +)__c_cb"; + +constexpr const char __CLIENT_SEND[] = +R"__c_cb( + res_ = cion_client_send_data(, , , 5 * 1000, &, &); + + if (res_ != CION_ERROR_NONE) { + _E("Failed to send parcel. error(%d)", res_); + goto out; + } +)__c_cb"; + +constexpr const char __SERVER_SEND_ASYNC[] = +R"__c_cb( + ret_ = cion_payload_create(&, CION_PAYLOAD_TYPE_DATA); + if (ret_ != CION_ERROR_NONE) { + _E("Failed to cion_payload_create : %d", ret_); + cion_payload_destroy(); + goto out; + } + + ret_ = cion_payload_set_data(, (const unsigned char*)data_, ); + if (ret_ != CION_ERROR_NONE) { + _E("Failed to cion_payload_set_data : %d", ret_); + cion_payload_destroy(); + goto out; + } + + ret_ = cion_server_send_payload_async(, peer_info, , NULL, NULL); + cion_payload_destroy(); + if (ret_ != CION_ERROR_NONE) { + _E("Failed to cion_client_send_payload_async : %d", ret_); + goto out; + } +)__c_cb"; + +constexpr const char __GROUP_PUBLISH[] = +R"__c_cb( + res_ = cion_payload_create(&pl_, CION_PAYLOAD_TYPE_DATA); + if (res_ != CION_ERROR_NONE) { + _E("Failed to cion_payload_create : %d", res_); + cion_payload_destroy(pl_); + goto out; + } + + res_ = cion_payload_set_data(pl_, (const unsigned char*)data_, data_size_); + if (res_ != CION_ERROR_NONE) { + _E("Failed to cion_payload_set_data : %d", res_); + cion_payload_destroy(pl_); + goto out; + } + + res_ = cion_group_publish(h->group, pl_); + cion_payload_destroy(pl_); + if (res_ != CION_ERROR_NONE) { + _E("Failed to cion_group_publish : %d", res_); + goto out; + } +)__c_cb"; + +constexpr const char __CLIENT_CREATE[] = +R"__c_cb( + ret = cion_security_create(&security); + if (ret != CION_ERROR_NONE) { + _E("Failed to create security handle. error(%d)", ret); + __destroy(handle); + return ret; + } + + + handle->security = security; + + ret = cion_client_create(&handle->client, service_name, handle->security); + if (ret != CION_ERROR_NONE) { + _E("Failed to create proxy handle. error(%d)", ret); + __destroy(handle); + return ret; + } + + handle->callback = *callback; + handle->user_data = user_data; + + ret = cion_client_add_connection_result_cb(handle->client, ____connection_result, handle); + if (ret != CION_ERROR_NONE) { + _E("Failed to add connection result cb. error(%d)", ret); + __destroy(handle); + return ret; + } + + ret = cion_client_add_disconnected_cb(handle->client, ____disconnected, handle); + if (ret != CION_ERROR_NONE) { + _E("Failed to add disconnected event cb. error(%d)", ret); + __destroy(handle); + return ret; + } + + ret = cion_client_add_payload_received_cb(handle->client, ____received, handle); + if (ret != CION_ERROR_NONE) { + _E("Failed to add received event cb. error(%d)", ret); + __destroy(handle); + return ret; + } +)__c_cb"; + +constexpr const char __GROUP_CREATE[] = +R"__c_cb( + ret = cion_security_create(&security); + if (ret != CION_ERROR_NONE) { + _E("Failed to create security handle. error(%d)", ret); + __destroy(handle); + return ret; + } + + + handle->security = security; + + ret = cion_group_create(&handle->group, topic_name, handle->security); + if (ret != CION_ERROR_NONE) { + _E("Failed to create group handle. error(%d)", ret); + __destroy(handle); + return ret; + } + + handle->callback = *callback; + handle->user_data = user_data; + + ret = cion_group_add_joined_cb(handle->group, ____joined_cb, handle); + if (ret != CION_ERROR_NONE) { + _E("Failed to add connection result cb. error(%d)", ret); + __destroy(handle); + return ret; + } + + ret = cion_group_add_left_cb(handle->group, ____left_cb, handle); + if (ret != CION_ERROR_NONE) { + _E("Failed to add disconnected event cb. error(%d)", ret); + __destroy(handle); + return ret; + } + + ret = cion_group_add_payload_received_cb(handle->group, ____received, handle); + if (ret != CION_ERROR_NONE) { + _E("Failed to add received event cb. error(%d)", ret); + __destroy(handle); + return ret; + } + + ret = cion_group_subscribe(handle->group); + if (ret != CION_ERROR_NONE) { + _E("Failed to subscribe event. error(%d)", ret); + __destroy(handle); + return ret; + } + + *h = handle; +)__c_cb"; + +constexpr const char __GROUP_DESTROY[] = +R"__c_cb( + if (h->group) { + cion_group_unsubscribe(h->group); + cion_group_destroy(h->group); + } + + if (h->security) + cion_security_destroy(h->security); +)__c_cb"; + +constexpr const char __CLIENT_DESTROY[] = +R"__c_cb( + if (h->client) + cion_client_destroy(h->client); + + if (h->security) + cion_security_destroy(h->security); +)__c_cb"; + +constexpr const char __SET_SECURITY_CA[] = +R"__c_cb( +cion_security_set_ca_path(security, ""); +)__c_cb"; + +constexpr const char __SET_SECURITY_CERT[] = +R"__c_cb( +cion_security_set_cert_path(security, ""); +)__c_cb"; + +constexpr const char __SET_SECURITY_PRIVATE_KEY[] = +R"__c_cb( +cion_security_set_private_key_path(security, ""); +)__c_cb"; + +constexpr const char __PEER_INFO_CLONE[] = + "cion_peer_info_clone(, );"; + +constexpr const char __SERVER_FOREACH_CONNECTED_PEER_INFO[] = + "cion_server_foreach_connected_peer_info(__.stub, callback, user_data);"; + +constexpr const char __SERVER_SET_ONDEMAND_LAUNCH_ENABLED[] = +R"__c_cb( + int ret; + + ret = cion_server_set_on_demand_launch_enabled(__.stub, enable); + if (ret != CION_ERROR_NONE) + _E("Failed to set ondemand launch enable. error(%d)", ret); + + return ret; +)__c_cb"; + +} // namespace + +namespace tidl { + +std::string DefaultCTransportable::GenInclude() const { + return "#include "; +} + +std::string DefaultCTransportable::GenClientSendAsync(std::string client, + std::string payload, std::string size) const { + return std::string(ReplaceAll(__CLIENT_SEND_ASYNC, { + { "", client }, + { "", payload}, + { "", size} })); +} + +std::string DefaultCTransportable::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 DefaultCTransportable::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 DefaultCTransportable::GenServerFileSend(std::string path, + std::string server, std::string peer) const { + return std::string(ReplaceAll(__SERVER_FILE_SEND, { + { "", path }, + { "", server }, + { "", peer } })); +} + +std::string DefaultCTransportable::GenClientFileSend(std::string path, + std::string client) const { + return std::string(ReplaceAll(__CLINET_FILE_SEND, { + { "", path }, + { "", client } })); +} + +std::string DefaultCTransportable::GenGroupType() const { + return "cion_group_h"; +} + +std::string DefaultCTransportable::GenPayloadTransferStatusType() const { + return "cion_payload_transfer_status_e"; +} + +std::string DefaultCTransportable::GenPeerInfoType() const { + return "cion_peer_info_h"; +} + +std::string DefaultCTransportable::GenPeerInfoDestroy(std::string peer) const { + return std::string(ReplaceAll("cion_peer_info_destroy();", { + { "", peer } })); +} + +std::string DefaultCTransportable::GenPayloadType() const { + return "cion_payload_h"; +} + +std::string DefaultCTransportable::GenClientType() const { + return "cion_client_h"; +} + +std::string DefaultCTransportable::GenSecurityType() const { + return "cion_security_h"; +} + +std::string DefaultCTransportable::GenServerType() const { + return "cion_server_h"; +} + +std::string DefaultCTransportable::GenClientTryConnect(std::string client, + std::string peer) const { + return std::string(ReplaceAll(__CLIENT_TRY_CONNECT, { + { "", client }, + { "", peer } })); +} + +std::string DefaultCTransportable::GenClientDisconnect( + std::string client) const { + return std::string(ReplaceAll(__CLIENT_DISCONNECT, { + { "", client } })); +} + +std::string DefaultCTransportable::GenClientTryDiscovery( + std::string client) const { + return std::string(ReplaceAll(__CLIENT_TRY_DISCOVERY, { + { "", client } })); +} + +std::string DefaultCTransportable::GenClientStopDiscovery( + std::string client) const { + return std::string(ReplaceAll(__CLIENT_STOP_DISCOVERY, { + { "", client } })); +} + +std::string DefaultCTransportable::GenServerRegister() const { + return __SERVER_REGISTER; +} + +std::string DefaultCTransportable::GenServerUnregister() const { + return __SERVER_UNREGISTER; +} + +std::string DefaultCTransportable::GenClientExtraHeader() const { + return ""; +} + +std::string DefaultCTransportable::GenClientExtraBody() const { + return ""; +} + +std::string DefaultCTransportable::GenServerExtraHeader() const { + return ""; +} + +std::string DefaultCTransportable::GenServerExtraBody() const { + return ""; +} + +std::string DefaultCTransportable::GenServerAccept() const { + return __SERVER_ACCEPT; +} + +std::string DefaultCTransportable::GenServerReject() const { + return __SERVER_REJECT; +} + +std::string DefaultCTransportable::GenServerSetDisplayName() const { + return __SERVER_SET_DISPLAY_NAME; +} + +std::string DefaultCTransportable::GenGroupPublish() const { + return __GROUP_PUBLISH; +} + +std::string DefaultCTransportable::GenPayloadTypeEnum() const { + return "cion_payload_type_e"; +} + +std::string DefaultCTransportable::GenPayloadTypeData() const { + return "CION_PAYLOAD_TYPE_DATA"; +} + +std::string DefaultCTransportable::GenPayloadTypeFile() const { + return "CION_PAYLOAD_TYPE_FILE"; +} + +std::string DefaultCTransportable::GenPayloadGetType() const { + return "ret = cion_payload_get_type(payload, &type);"; +} + +std::string DefaultCTransportable::GenErrorNone() const { + return "CION_ERROR_NONE"; +} + +std::string DefaultCTransportable::GenPayloadGetData() const { + return "ret = cion_payload_get_data(payload, &data, &data_len);"; +} + +std::string DefaultCTransportable::GenClientCreate() const { + return __CLIENT_CREATE; +} + +std::string DefaultCTransportable::GenGroupCreate() const { + return __GROUP_CREATE; +} + +std::string DefaultCTransportable::GenGroupDestroy() const { + return __GROUP_DESTROY; +} + +std::string DefaultCTransportable::GenClientDestroy() const { + return __CLIENT_DESTROY; +} + +std::string DefaultCTransportable::GenSetSecurityCA(std::string arg) const { + return std::string(ReplaceAll(__SET_SECURITY_CA, { + { "", arg } })); +} + +std::string DefaultCTransportable::GenSetSecurityCert(std::string arg) const { + return std::string(ReplaceAll(__SET_SECURITY_CERT, { + { "", arg } })); +} + +std::string DefaultCTransportable::GenSetSecurityPrivateKey(std::string arg) const { + return std::string(ReplaceAll(__SET_SECURITY_PRIVATE_KEY, { + { "", arg } })); +} + +std::string DefaultCTransportable::GenPeerInfoClone(std::string src_peer, + std::string dest_peer) const { + return std::string(ReplaceAll(__PEER_INFO_CLONE, { + { "", src_peer }, + { "", dest_peer } })); +} + +std::string DefaultCTransportable::GenServerForeachConnectedPeerInfo( + std::string name) const { + return std::string(ReplaceAll(__SERVER_FOREACH_CONNECTED_PEER_INFO, { + { "", name } })); +} + +std::string DefaultCTransportable::GenServerSetOnDemandLaunchEnabled(std::string name) const { + return std::string(ReplaceAll(__SERVER_SET_ONDEMAND_LAUNCH_ENABLED, { + { "", name } })); +} + +} // namespace tidl diff --git a/idlc/gen_cion/default_c_transportable.h b/idlc/gen_cion/default_c_transportable.h new file mode 100644 index 0000000..4c1983c --- /dev/null +++ b/idlc/gen_cion/default_c_transportable.h @@ -0,0 +1,85 @@ +/* + * 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_C_TRANSPORTABLE_H_ +#define IDLC_GEN_CION_DEFAULT_C_TRANSPORTABLE_H_ + +#include + +#include "idlc/gen_cion/c_transportable.h" + +namespace tidl { + +class DefaultCTransportable : public CTransportable { + public: + virtual ~DefaultCTransportable() = 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 GenServerForeachConnectedPeerInfo(std::string name) const override; + std::string GenServerSetOnDemandLaunchEnabled(std::string name) const override; +}; + +} // namespace tidl + +#endif // IDLC_GEN_CION_DEFAULT_C_TRANSPORTABLE_H_ diff --git a/idlc/gen_cion/plugin_loader.cc b/idlc/gen_cion/plugin_loader.cc index e71d783..21812ff 100644 --- a/idlc/gen_cion/plugin_loader.cc +++ b/idlc/gen_cion/plugin_loader.cc @@ -16,11 +16,13 @@ #include "idlc/gen_cion/plugin_loader.h" +#include "idlc/gen_cion/default_c_transportable.h" + namespace tidl { PluginLoader::PluginLoader(const std::string& plugin_path) { if (plugin_path.empty()) { - // C_.reset(new DefaultCTransportable()); + C_.reset(new DefaultCTransportable()); // Cpp_.reset(new DefaultCppTransportable()); // Cs_.reset(new DefaultCsTransportable()); // Java_.reset(new DefaultJavaTransportable()); -- 2.7.4