From c517c87a6b608a85cc8d90c2febbce0745b09911 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Fri, 3 Sep 2021 11:42:12 +0900 Subject: [PATCH] Fix C Generator The implemenation that the callback port check is separated. If the interface doesn't have the delegate, the callback port check is not needed. Change-Id: I04aaf8c0d5a00347901afbbebda75f85744bf442 Signed-off-by: Hwankyu Jhun --- idlc/gen/c_stub_body_gen.cc | 31 ++++++++++++++++ idlc/gen/c_stub_body_gen.h | 4 +++ idlc/gen/c_stub_body_gen_cb.h | 83 +++++++++++++++++++++++++------------------ 3 files changed, 83 insertions(+), 35 deletions(-) diff --git a/idlc/gen/c_stub_body_gen.cc b/idlc/gen/c_stub_body_gen.cc index 9175243..c0d6826 100644 --- a/idlc/gen/c_stub_body_gen.cc +++ b/idlc/gen/c_stub_body_gen.cc @@ -172,13 +172,18 @@ void CStubBodyGen::GenInterfaceDefs(std::ofstream& stream) { void CStubBodyGen::GenInterfaceDef(std::ofstream& stream, const Interface& iface) { + bool has_delegate = false; for (auto& d : iface.GetDeclarations().GetDecls()) { if (d->GetMethodType() != Declaration::MethodType::DELEGATE) continue; GenInterfaceDelegateDef(stream, iface, *d); + has_delegate = true; } + if (has_delegate) + GenInterfaceCallbackPortCheckDef(stream, iface); + GenInterfaceContextDef(stream, iface); GenInterfaceBaseDef(stream, iface); } @@ -194,6 +199,16 @@ void CStubBodyGen::GenInterfaceDelegateDef(std::ofstream& stream, stream << SmartIndent(code); } +// @see #CB_INTERFACE_CALLBACK_PORT_CHECK_DEF +void CStubBodyGen::GenInterfaceCallbackPortCheckDef(std::ofstream& stream, + const Interface& iface) { + std::string code = ReplaceAll(CB_INTERFACE_CALLBACK_PORT_CHECK_DEF, + "", GetHandlePrefix()); + code = ReplaceAll(code, "", iface.GetID()); + + stream << SmartIndent(code); +} + // @see #CB_INTERFACE_CONTEXT_DEF void CStubBodyGen::GenInterfaceContextDef(std::ofstream& stream, const Interface& iface) { @@ -225,11 +240,13 @@ void CStubBodyGen::GenInterfaces(std::ofstream& stream) { } void CStubBodyGen::GenInterface(std::ofstream& stream, const Interface& iface) { + bool has_delegate = false; for (auto& d : iface.GetDeclarations().GetDecls()) { if (d->GetMethodType() != Declaration::MethodType::DELEGATE) continue; GenInterfaceDelegateBase(stream, iface, *d); + has_delegate = true; } for (auto& d : iface.GetDeclarations().GetDecls()) { @@ -241,6 +258,10 @@ void CStubBodyGen::GenInterface(std::ofstream& stream, const Interface& iface) { GenInterfaceMethodTable(stream, iface); GenInterfaceContextBase(stream, iface); + + if (has_delegate) + GenInterfaceCallbackPortCheck(stream, iface); + GenInterfaceBase(stream, iface); } @@ -638,6 +659,16 @@ void CStubBodyGen::GenInterfaceMethodTable(std::ofstream& stream, stream << SmartIndent(code); } +// @see #CB_INTERFACE_CALLBACK_PORT_CHECK +void CStubBodyGen::GenInterfaceCallbackPortCheck(std::ofstream& stream, + const Interface& iface) { + std::string code = ReplaceAll(CB_INTERFACE_CALLBACK_PORT_CHECK, "", + GetHandlePrefix()); + code = ReplaceAll(code, "", iface.GetID()); + + stream << SmartIndent(code); +} + // @see #CB_INTERFACE_PRIVILEGE_ADD // @see #CB_INTERFACE_TRUSTED_SET std::string CStubBodyGen::GenAccessControlSet(const Interface& iface) { diff --git a/idlc/gen/c_stub_body_gen.h b/idlc/gen/c_stub_body_gen.h index 14169f2..b8358e8 100644 --- a/idlc/gen/c_stub_body_gen.h +++ b/idlc/gen/c_stub_body_gen.h @@ -49,6 +49,8 @@ class CStubBodyGen : public CBodyGeneratorBase { void GenInterfaceContextDef(std::ofstream& stream, const Interface& iface); void GenInterfaceDelegateDef(std::ofstream& stream, const Interface& iface, const Declaration& decl); + void GenInterfaceCallbackPortCheckDef(std::ofstream& stream, + const Interface& iface); void GenInterfaceBaseDef(std::ofstream& stream, const Interface& iface); void GenInterfaces(std::ofstream& stream); @@ -59,6 +61,8 @@ class CStubBodyGen : public CBodyGeneratorBase { void GenInterfaceMethodHandlerBase(std::ofstream& stream, const Interface& iface, const Declaration& decl); void GenInterfaceMethodTable(std::ofstream& stream, const Interface& iface); + void GenInterfaceCallbackPortCheck(std::ofstream& stream, + const Interface& iface); void GenInterfaceBase(std::ofstream& stream, const Interface& iface); std::string GenMethodEnums(const Interface& iface); diff --git a/idlc/gen/c_stub_body_gen_cb.h b/idlc/gen/c_stub_body_gen_cb.h index d073959..b732a66 100644 --- a/idlc/gen/c_stub_body_gen_cb.h +++ b/idlc/gen/c_stub_body_gen_cb.h @@ -115,7 +115,13 @@ typedef struct __context_s { bool done; #endif /* TIDL_THREAD_ENABLE */ } __context_t; +)__c_cb"; +/** + * + */ +constexpr const char CB_INTERFACE_CALLBACK_PORT_CHECK_DEF[] = +R"__c_cb( static bool ____exist_callback_port(rpc_port_h callback_port); )__c_cb"; @@ -399,41 +405,6 @@ static void ____remove_context(__context_h context) __.contexts = g_list_remove(__.contexts, context); g_rec_mutex_unlock(&__.mutex); } - -static bool ____exist_callback_port(rpc_port_h callback_port) -{ - rpc_port_h port; - GList *iter; - - g_rec_mutex_lock(&__.mutex); - iter = __.callback_ports; - while (iter) { - port = iter->data; - if (port == callback_port) { - g_rec_mutex_unlock(&__.mutex); - return true; - } - - iter = g_list_next(iter); - } - g_rec_mutex_unlock(&__.mutex); - - return false; -} - -static void ____add_callback_port(rpc_port_h callback_port) -{ - g_rec_mutex_lock(&__.mutex); - __.callback_ports = g_list_append(__.callback_ports, callback_port); - g_rec_mutex_unlock(&__.mutex); -} - -static void ____remove_callback_port(rpc_port_h callback_port) -{ - g_rec_mutex_lock(&__.mutex); - __.callback_ports = g_list_remove(__.callback_ports, callback_port); - g_rec_mutex_unlock(&__.mutex); -} )__c_cb"; /** @@ -932,6 +903,20 @@ R"__c_cb( */ constexpr const char CB_INTERFACE_BASE[] = R"__c_cb( +static void ____add_callback_port(rpc_port_h callback_port) +{ + g_rec_mutex_lock(&__.mutex); + __.callback_ports = g_list_append(__.callback_ports, callback_port); + g_rec_mutex_unlock(&__.mutex); +} + +static void ____remove_callback_port(rpc_port_h callback_port) +{ + g_rec_mutex_lock(&__.mutex); + __.callback_ports = g_list_remove(__.callback_ports, callback_port); + g_rec_mutex_unlock(&__.mutex); +} + static void ____connected_event_cb(const char *sender, const char *instance, void *user_data) { __context_h context; @@ -1136,6 +1121,34 @@ int __get_client_number(unsigned int *client_number) )__c_cb"; /** + * The prefix of the interface. + * The name of the interface. + */ +constexpr const char CB_INTERFACE_CALLBACK_PORT_CHECK[] = +R"__c_cb( +static bool ____exist_callback_port(rpc_port_h callback_port) +{ + rpc_port_h port; + GList *iter; + + g_rec_mutex_lock(&__.mutex); + iter = __.callback_ports; + while (iter) { + port = iter->data; + if (port == callback_port) { + g_rec_mutex_unlock(&__.mutex); + return true; + } + + iter = g_list_next(iter); + } + g_rec_mutex_unlock(&__.mutex); + + return false; +} +)__c_cb"; + +/** * The name of the interface. * The privilege name. */ -- 2.7.4