From da84f6229e612dbb68f11034f5f7dd06ec23aead Mon Sep 17 00:00:00 2001 From: "jh9216.park" Date: Tue, 19 Jul 2022 06:44:25 -0400 Subject: [PATCH] Remove the constructor - Remove the constructor to force it to use the sender apppid Change-Id: I19bd50e00ff98b37b6b8fb955a6d7dab93e09443 Signed-off-by: jh9216.park --- idlc/gen/c_group_body_gen_cb.h | 77 ++++++++++++++++++++++++-------------- idlc/gen/c_group_header_gen_cb.h | 7 +++- idlc/gen/cpp_group_body_gen_cb.h | 36 ++++-------------- idlc/gen/cpp_group_header_gen_cb.h | 10 ++--- idlc/gen/cs_group_gen_cb.h | 8 ++-- 5 files changed, 68 insertions(+), 70 deletions(-) diff --git a/idlc/gen/c_group_body_gen_cb.h b/idlc/gen/c_group_body_gen_cb.h index f52d3c4..b40a67e 100644 --- a/idlc/gen/c_group_body_gen_cb.h +++ b/idlc/gen/c_group_body_gen_cb.h @@ -84,6 +84,8 @@ R"__c_cb( typedef struct __s { __callback_s callback; event_handler_h event_handler; + char *sender_appid; + bool is_system; GRecMutex mutex; void *user_data; } __t; @@ -156,26 +158,22 @@ static bundle *__get_bundle_from_parcel(rpc_port_parcel_h p, bundle* b) return b; } -static const char *__get_appid() +static char *__get_event_name(const char *appid, bool is_system, const char *iface_name) { - static char *str = nullptr; - - if (str) - return str; - - char *id = nullptr; - int ret = app_get_id(&id); - if (ret != APP_ERROR_NONE) - id = strdup("system"); - - str = id; - return str; -} + size_t size; + char *buf; + + if (is_system) { + size = strlen("tizen.system.event.tidl_iface_") + strlen(iface_name) + 1; + buf = calloc(1, size); + if (!buf) + return nullptr; + snprintf(buf, size, "tizen.system.event.tidl_iface_%s", iface_name); + return buf; + } -static char *__get_event_name(const char *appid, const char *iface_name) -{ - size_t size = strlen(appid) + strlen(iface_name) + 19; - char *buf = calloc(1, size); + size = strlen(appid) + strlen(iface_name) + 19; + buf = calloc(1, size); if (!buf) return nullptr; snprintf(buf, size, "event.%s.tidl_iface_%s", appid, iface_name); @@ -217,7 +215,7 @@ static void ___event_system_cb(const char *event_name, bundle *event_data, rpc_port_parcel_destroy(p); } -int __create(const char *sender_appid, __callback_s *callback, void *user_data, __h *h) +int __create(const char *sender_appid, __callback_s *callback, void *user_data, bool is_system, __h *h) { __t *handle; int ret; @@ -234,32 +232,44 @@ int __create(const char *sender_appid, __callback_s return RPC_PORT_ERROR_OUT_OF_MEMORY; } - g_rec_mutex_init(&handle->mutex); - handle->callback = *callback; - handle->user_data = user_data; - - ev_name = __get_event_name(sender_appid, ""); - if (ev_name == nullptr) + ev_name = __get_event_name(sender_appid, is_system, ""); + if (ev_name == nullptr) { + free(handle); return RPC_PORT_ERROR_OUT_OF_MEMORY; + } ret = event_add_event_handler(ev_name, ___event_system_cb, handle, &handle->event_handler); free(ev_name); if (ret != EVENT_ERROR_NONE) { _E("Failed to register events. result(%d)", ret); + free(handle); return RPC_PORT_ERROR_INVALID_PARAMETER; } + handle->sender_appid = strdup(sender_appid); + if (handle->sender_appid == nullptr) { + _E("Out of memory"); + event_remove_event_handler(handle->event_handler); + free(handle); + return RPC_PORT_ERROR_OUT_OF_MEMORY; + } + + g_rec_mutex_init(&handle->mutex); + handle->callback = *callback; + handle->user_data = user_data; + handle->is_system = is_system; + *h = handle; return RPC_PORT_ERROR_NONE; } -int __create_for_sender(__h *h) +int __create_for_sender(const char *sender_appid, bool is_system, __h *h) { __t *handle; - if (h == nullptr) { + if (h == nullptr || sender_appid == nullptr) { _E("Invalid parameter"); return RPC_PORT_ERROR_INVALID_PARAMETER; } @@ -270,7 +280,15 @@ int __create_for_sender(__h *h) return RPC_PORT_ERROR_OUT_OF_MEMORY; } + handle->sender_appid = strdup(sender_appid); + if (handle->sender_appid == nullptr) { + _E("Out of memory"); + free(handle); + return RPC_PORT_ERROR_OUT_OF_MEMORY; + } + g_rec_mutex_init(&handle->mutex); + handle->is_system = is_system; *h = handle; return RPC_PORT_ERROR_NONE; @@ -289,6 +307,8 @@ int __destroy(__h h) if (h->event_handler) event_remove_event_handler(h->event_handler); + if (h->sender_appid) + free(h->sender_appid); free(h); @@ -349,7 +369,7 @@ void __invoke_(__h h) return; } - int ret = event_publish_app_event(__get_event_name(__get_appid(), ""), b); + int ret = event_publish_app_event(__get_event_name(h->sender_appid, h->is_system, ""), b); if (ret != EVENT_ERROR_NONE) { _E("Failed to publish event. result(%d)", ret); bundle_free(b); @@ -555,7 +575,6 @@ R"__c_cb( constexpr const char CB_INTERFACE_EXTRA_HEADER[] = R"__c_cb( -#include #include )__c_cb"; diff --git a/idlc/gen/c_group_header_gen_cb.h b/idlc/gen/c_group_header_gen_cb.h index 8305e95..d0211eb 100644 --- a/idlc/gen/c_group_header_gen_cb.h +++ b/idlc/gen/c_group_header_gen_cb.h @@ -54,6 +54,7 @@ typedef struct { * @param[in] sender_appid ID of app sending events * @param[in] callback The set of callback functions to handle events * @param[in] user_data The user data to be passed to the callback function + * @param[in] is_system True on system events * @param[out] h The _ handle * @return @c 0 on success, * otherwise a negative error value @@ -65,13 +66,15 @@ typedef struct { * @see __destroy() * @see #__callback_s */ -int __create(const char *sender_appid, __callback_s *callback, void *user_data, __h *h); +int __create(const char *sender_appid, __callback_s *callback, void *user_data, bool is_system, __h *h); /** * @brief Creates a _ handle for sending events. * @remarks The @a h handle should be released using * the __destroy() if it's no longer needed. * + * @param[in] sender_appid ID of app sending events + * @param[in] is_system True on system events * @param[out] h The _ handle * @return @c 0 on success, * otherwise a negative error value @@ -82,7 +85,7 @@ int __create(const char *sender_appid, __callback_s * @see __destroy() */ -int __create_for_sender(__h *h); +int __create_for_sender(const char *sender_appid, bool is_system, __h *h); /** * @brief Destroys the _ handle. diff --git a/idlc/gen/cpp_group_body_gen_cb.h b/idlc/gen/cpp_group_body_gen_cb.h index 4ae3efe..3526914 100644 --- a/idlc/gen/cpp_group_body_gen_cb.h +++ b/idlc/gen/cpp_group_body_gen_cb.h @@ -28,11 +28,9 @@ R"__cpp_cb( const char CB_INTERFACE_CTOR[] = R"__cpp_cb( -::() { -} - -::(const std::string& sender_appid) { - Subscribe(sender_appid); +::(std::string sender_appid, bool is_system) + : sender_appid_(std::move(sender_appid)), is_system_(is_system) { + Subscribe(); } )__cpp_cb"; @@ -78,9 +76,9 @@ R"__cpp_cb( const char CB_GROUP_HELPER_METHODS[] = R"__cpp_cb( -void ::Subscribe(const std::string& sender_appid) { +void ::Subscribe() { std::lock_guard lock(mutex_); - int ret = event_add_event_handler(GetEventName(sender_appid).c_str(), EventCb, this, &event_handler_); + int ret = event_add_event_handler(GetEventName().c_str(), EventCb, this, &event_handler_); if (ret != EVENT_ERROR_NONE) { _E("Failed to register events. result(%d)", ret); throw InvalidIOException(); @@ -126,28 +124,10 @@ rpc_port_parcel_h ::GetParcelFromBundle(bundle* b) { return p; } -std::string ::GetAppId() { - static std::string str; - - if (!str.empty()) - return str; - - char* id; - int ret = app_get_id(&id); - if (ret != APP_ERROR_NONE) - return "system"; - - str = id; - free(id); - return str; -} - std::string ::GetEventName() { - return "event." + GetAppId() + ".tidl_iface_"; -} - -std::string ::GetEventName(const std::string& sender_appid) { - return "event." + sender_appid + ".tidl_iface_"; + if (is_system_) + return "tizen.system.event.tidl_iface_"; + return "event." + sender_appid_ + ".tidl_iface_"; } void ::EventCb(const char* event_name, bundle* event_data, void* user_data) { diff --git a/idlc/gen/cpp_group_header_gen_cb.h b/idlc/gen/cpp_group_header_gen_cb.h index d1f3045..f685077 100644 --- a/idlc/gen/cpp_group_header_gen_cb.h +++ b/idlc/gen/cpp_group_header_gen_cb.h @@ -46,8 +46,7 @@ const char CB_CLASS_FULL[] = R"__cpp_cb( class { public: - (); - (const std::string& sender_appid); + (std::string sender_appid, bool is_system = false); virtual ~(); @@ -57,16 +56,16 @@ class { bundle* GetBundleFromParcel(rpc_port_parcel_h p, bundle* b); rpc_port_parcel_h GetParcelFromBundle(bundle* b); - std::string GetAppId(); std::string GetEventName(); - std::string GetEventName(const std::string& sender_appid); - void Subscribe(const std::string& sender_appid); + void Subscribe(); void Unsubscribe(); static void EventCb(const char* event_name, bundle* event_data, void* user_data); private: event_handler_h event_handler_ = nullptr; + std::string sender_appid_; std::recursive_mutex mutex_; + bool is_system_; }; )__cpp_cb"; @@ -82,7 +81,6 @@ const char CB_HEADER[] = R"__cpp_cb( #pragma once -#include #include #include #include diff --git a/idlc/gen/cs_group_gen_cb.h b/idlc/gen/cs_group_gen_cb.h index d5aaada..caaa1fc 100644 --- a/idlc/gen/cs_group_gen_cb.h +++ b/idlc/gen/cs_group_gen_cb.h @@ -33,6 +33,7 @@ R"__cs_cb( private EventReceiver _eventReceiver; private Object _lock = new Object(); private bool _disposedValue = false; + private string _senderAppid; private Bundle GetBundleFromParcel(Parcel p) { @@ -71,6 +72,7 @@ R"__cs_cb( public (string senderAppid) { string eventName = GetEventName(senderAppid, ""); + _senderAppid = senderAppid; _eventReceiver = new EventReceiver(eventName); _eventReceiver.Received += (obj, args) => { @@ -82,10 +84,6 @@ R"__cs_cb( }; } - public () - { - } - ~() { Dispose(false); @@ -131,7 +129,7 @@ R"__cs_cb( p.WriteInt((int)MethodId.); var bundle = GetBundleFromParcel(p); - string eventName = GetEventName(Application.Current.ApplicationInfo.ApplicationId, ""); + string eventName = GetEventName(_senderAppid, ""); ApplicationEventManager.Publish(eventName, bundle); } } -- 2.7.4