From: Junghoon Park Date: Thu, 29 Mar 2018 11:29:40 +0000 (+0900) Subject: Generate APIs for disposing delegates X-Git-Tag: submit/tizen/20180330.040628~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F65%2F174265%2F2;p=platform%2Fcore%2Fappfw%2Ftidl.git Generate APIs for disposing delegates Change-Id: I52bc2af8b9b9a47737fb3bcfdf0c0eb8e7abed5c Signed-off-by: Junghoon Park --- diff --git a/idlc/c_gen/c_proxy_body_gen.cc b/idlc/c_gen/c_proxy_body_gen.cc index 2dacb43..1efde50 100644 --- a/idlc/c_gen/c_proxy_body_gen.cc +++ b/idlc/c_gen/c_proxy_body_gen.cc @@ -95,6 +95,7 @@ void CProxyBodyGen::GenInterfaceDelegator(std::ofstream& stream, GenInterfaceDelegatorSerializer(stream, id, decl); GenInterfaceDelegatorDeserializer(stream, id, decl); GenInterfaceDelegatorConstructor(stream, id, decl); + GenInterfaceDelegatorDisposer(stream, id, decl); GenInterfaceDelegatorInvoker(stream, id, decl); } @@ -130,6 +131,15 @@ void CProxyBodyGen::GenInterfaceDelegatorConstructor( ); } +void CProxyBodyGen::GenInterfaceDelegatorDisposer( + std::ofstream& stream, const std::string& id, const Declaration& decl) { + stream << SmartIndent(GenTemplateString( + ReplaceAll(CB_DELEGATE_DISPOSER, "##", id + "_" + decl.GetID()), + [&]()->std::string { + return id; + })); +} + void CProxyBodyGen::GenInterfaceDelegatorInvoker( std::ofstream& stream, const std::string& id, const Declaration& decl) { const char parcel[] = "$$(parcel, $$);\n"; diff --git a/idlc/c_gen/c_proxy_body_gen.h b/idlc/c_gen/c_proxy_body_gen.h index 0874853..a37d4fd 100644 --- a/idlc/c_gen/c_proxy_body_gen.h +++ b/idlc/c_gen/c_proxy_body_gen.h @@ -74,6 +74,9 @@ class CProxyBodyGen : public CBodyGeneratorBase { void GenInterfaceDelegatorConstructor(std::ofstream& stream, const std::string& id, const Declaration& decl); + void GenInterfaceDelegatorDisposer(std::ofstream& stream, + const std::string& id, + const Declaration& decl); void GenInterfaceDelegatorInvoker(std::ofstream& stream, const std::string& id, const Declaration& decl); diff --git a/idlc/c_gen/c_proxy_body_gen_cb.h b/idlc/c_gen/c_proxy_body_gen_cb.h index 2a4bb8f..6331217 100644 --- a/idlc/c_gen/c_proxy_body_gen_cb.h +++ b/idlc/c_gen/c_proxy_body_gen_cb.h @@ -97,6 +97,34 @@ rpc_port_##_h rpc_port_##_create(## callback, bool once, void *user_data) } )__c_cb"; +const char CB_DELEGATE_DISPOSER[] = +R"__c_cb( +int rpc_port_proxy_##_dispose(rpc_port_proxy_$$_h proxy, rpc_port_##_h delegate) +{ + struct ##_s *handle; + GList *iter; + + if (!proxy || !delegate) { + dlog_print(DLOG_ERROR, LOG_TAG, "Invalid handle %p %p", proxy, delegate); + return -1; + } + + iter = proxy->delegates; + while (iter) { + handle = (struct ##_s *)iter->data; + if (handle == delegate) { + proxy->delegates = g_list_remove_link(proxy->delegates, iter); + free(handle); + g_list_free(iter); + return 0; + } + iter = g_list_next(iter); + } + + return -1; +} +)__c_cb"; + const char CB_DELEGATE_INVOKER[] = R"__c_cb( static void __$$_delegate_$$(GList **list, rpc_port_parcel_h parcel, int seq_id) diff --git a/idlc/c_gen/c_proxy_header_gen.cc b/idlc/c_gen/c_proxy_header_gen.cc index 7da766b..5548963 100644 --- a/idlc/c_gen/c_proxy_header_gen.cc +++ b/idlc/c_gen/c_proxy_header_gen.cc @@ -50,8 +50,8 @@ void CProxyHeaderGen::GenInterfaces(std::ofstream& stream) { void CProxyHeaderGen::GenInterface(std::ofstream& stream, const Interface& inf) { - GenInterfaceDelegators(stream, inf); GenInterfaceDeclaration(stream, inf); + GenInterfaceDelegators(stream, inf); GenInterfaceConnect(stream, inf); GenInterfaceDisconnect(stream, inf); GenInterfaceMethods(stream, inf); @@ -99,6 +99,11 @@ void CProxyHeaderGen::GenInterfaceDelegator(std::ofstream& stream, ); stream << ReplaceAll(CB_DELEGATE_CTOR, "##", id + "_" + decl.GetID()); + stream << GenTemplateString( + ReplaceAll(CB_DELEGATE_DISPOSER, "##", id + "_" + decl.GetID()), + [&]()->std::string { + return id; + }); } void CProxyHeaderGen::GenInterfaceDeclaration(std::ofstream& stream, diff --git a/idlc/c_gen/c_proxy_header_gen_cb.h b/idlc/c_gen/c_proxy_header_gen_cb.h index e8a5609..b743b7f 100644 --- a/idlc/c_gen/c_proxy_header_gen_cb.h +++ b/idlc/c_gen/c_proxy_header_gen_cb.h @@ -51,3 +51,8 @@ const char CB_DELEGATE_CTOR[] = R"__c_cb( rpc_port_##_h rpc_port_##_create(## callback, bool once, void *user_data); )__c_cb"; + +const char CB_DELEGATE_DISPOSER[] = +R"__c_cb( +int rpc_port_proxy_##_dispose(rpc_port_proxy_$$_h proxy, rpc_port_##_h delegate); +)__c_cb"; diff --git a/idlc/cpp_gen/cpp_gen_base.cc b/idlc/cpp_gen/cpp_gen_base.cc index 7fe000b..698189e 100644 --- a/idlc/cpp_gen/cpp_gen_base.cc +++ b/idlc/cpp_gen/cpp_gen_base.cc @@ -573,6 +573,7 @@ void CppGeneratorBase::GenBodyCallbacks(std::ofstream& stream, [&]()->std::string { return iface.GetID(); }, [&]()->std::string { return iface.GetID(); }, [&]()->std::string { return iface.GetID(); }, + [&]()->std::string { return iface.GetID(); }, [&]()->std::string { return iface.GetID(); } ); diff --git a/idlc/cpp_gen/cpp_gen_base_cb.h b/idlc/cpp_gen/cpp_gen_base_cb.h index 6bbf937..3b0e28a 100644 --- a/idlc/cpp_gen/cpp_gen_base_cb.h +++ b/idlc/cpp_gen/cpp_gen_base_cb.h @@ -77,6 +77,10 @@ bool $$::CallbackBase::IsOnce() const { return once_; } +std::string $$::CallbackBase::GetTag() const { + return std::to_string(id_) + "::" + std::to_string(seq_id_); +} + rpc_port_parcel_h operator << (rpc_port_parcel_h h, const $$::CallbackBase& cb) { rpc_port_parcel_write_int32(h, cb.id_); rpc_port_parcel_write_int32(h, cb.seq_id_); @@ -127,6 +131,7 @@ R"__cpp_cb( int GetId() const; int GetSeqId() const; bool IsOnce() const; + std::string GetTag() const; private: friend rpc_port_parcel_h operator << (rpc_port_parcel_h h, const CallbackBase& cb); diff --git a/idlc/cpp_gen/cpp_proxy_body_gen.cc b/idlc/cpp_gen/cpp_proxy_body_gen.cc index 97b9f04..fa6b827 100644 --- a/idlc/cpp_gen/cpp_proxy_body_gen.cc +++ b/idlc/cpp_gen/cpp_proxy_body_gen.cc @@ -124,6 +124,7 @@ void CppProxyBodyGen::GenHelperMethods(std::ofstream& stream, [&]()->std::string { return iface.GetID(); }, [&]()->std::string { return iface.GetID(); }, [&]()->std::string { return iface.GetID(); }, + [&]()->std::string { return iface.GetID(); }, [&]()->std::string { return iface.GetID(); } ); stream << NLine(1); diff --git a/idlc/cpp_gen/cpp_proxy_body_gen_cb.h b/idlc/cpp_gen/cpp_proxy_body_gen_cb.h index 3248ea6..0a68ea0 100644 --- a/idlc/cpp_gen/cpp_proxy_body_gen_cb.h +++ b/idlc/cpp_gen/cpp_proxy_body_gen_cb.h @@ -68,6 +68,15 @@ void $$::Connect() { } } +void $$::DisposeCallback(const std::string& tag) { + for (auto& i : delegate_list_) { + if (i->GetTag() == tag) { + delegate_list_.remove(i); + return; + } + } +} + void $$::ProcessReceivedEvent(rpc_port_parcel_h parcel) { int id = 0; int seq_id = 0; diff --git a/idlc/cpp_gen/cpp_proxy_header_gen_cb.h b/idlc/cpp_gen/cpp_proxy_header_gen_cb.h index ee2f6d4..0f88387 100644 --- a/idlc/cpp_gen/cpp_proxy_header_gen_cb.h +++ b/idlc/cpp_gen/cpp_proxy_header_gen_cb.h @@ -72,6 +72,12 @@ R"__cpp_cb( class IEventListener { /// If you want to use this method, you must add privileges. void Connect(); + /// + /// Disposes delegate objects in this interface + /// + /// The tag string from delegate object + void DisposeCallback(const std::string& tag); + )__cpp_cb"; const char CB_PRIVATE_MEMBERS[] = diff --git a/idlc/cs_gen/cs_gen_base_cb.h b/idlc/cs_gen/cs_gen_base_cb.h index f9cd9e9..83fab1b 100644 --- a/idlc/cs_gen/cs_gen_base_cb.h +++ b/idlc/cs_gen/cs_gen_base_cb.h @@ -33,6 +33,14 @@ R"__cs_cb( internal bool Once; private static int _seqNum = 0; + public string Tag + { + get + { + return Id.ToString() + "::" + SeqId.ToString(); + } + } + public CallbackBase(int delegateId, bool once) { Id = delegateId; diff --git a/idlc/cs_gen/cs_proxy_gen_cb.h b/idlc/cs_gen/cs_proxy_gen_cb.h index 08c61ef..f9c420e 100644 --- a/idlc/cs_gen/cs_proxy_gen_cb.h +++ b/idlc/cs_gen/cs_proxy_gen_cb.h @@ -152,6 +152,22 @@ R"__cs_cb( throw new InvalidIOException(); } } + + /// + /// Disposes delegate objects in this interface + /// + /// The tag string from delegate object + void DisposeCallback(string tag) + { + foreach (var i in _delegateList) + { + if (i.Tag.Equals(tag)) + { + _delegateList.Remove(i); + return; + } + } + } )__cs_cb"; const char CB_DISPOSABLE[] =