Generate APIs for disposing delegates 65/174265/2
authorJunghoon Park <jh9216.park@samsung.com>
Thu, 29 Mar 2018 11:29:40 +0000 (20:29 +0900)
committerJunghoon Park <jh9216.park@samsung.com>
Thu, 29 Mar 2018 11:33:13 +0000 (20:33 +0900)
Change-Id: I52bc2af8b9b9a47737fb3bcfdf0c0eb8e7abed5c
Signed-off-by: Junghoon Park <jh9216.park@samsung.com>
12 files changed:
idlc/c_gen/c_proxy_body_gen.cc
idlc/c_gen/c_proxy_body_gen.h
idlc/c_gen/c_proxy_body_gen_cb.h
idlc/c_gen/c_proxy_header_gen.cc
idlc/c_gen/c_proxy_header_gen_cb.h
idlc/cpp_gen/cpp_gen_base.cc
idlc/cpp_gen/cpp_gen_base_cb.h
idlc/cpp_gen/cpp_proxy_body_gen.cc
idlc/cpp_gen/cpp_proxy_body_gen_cb.h
idlc/cpp_gen/cpp_proxy_header_gen_cb.h
idlc/cs_gen/cs_gen_base_cb.h
idlc/cs_gen/cs_proxy_gen_cb.h

index 2dacb43..1efde50 100644 (file)
@@ -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";
index 0874853..a37d4fd 100644 (file)
@@ -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);
index 2a4bb8f..6331217 100644 (file)
@@ -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)
index 7da766b..5548963 100644 (file)
@@ -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,
index e8a5609..b743b7f 100644 (file)
@@ -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";
index 7fe000b..698189e 100644 (file)
@@ -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(); }
   );
 
index 6bbf937..3b0e28a 100644 (file)
@@ -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);
index 97b9f04..fa6b827 100644 (file)
@@ -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);
index 3248ea6..0a68ea0 100644 (file)
@@ -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;
index ee2f6d4..0f88387 100644 (file)
@@ -72,6 +72,12 @@ R"__cpp_cb(  class IEventListener {
   /// <remark> If you want to use this method, you must add privileges.</remark>
   void Connect();
 
+  /// <summary>
+  /// Disposes delegate objects in this interface
+  /// </summary>
+  /// <param name="tag">The tag string from delegate object</param>
+  void DisposeCallback(const std::string& tag);
+
 )__cpp_cb";
 
 const char CB_PRIVATE_MEMBERS[] =
index f9cd9e9..83fab1b 100644 (file)
@@ -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;
index 08c61ef..f9c420e 100644 (file)
@@ -152,6 +152,22 @@ R"__cs_cb(
                         throw new InvalidIOException();
                 }
             }
+
+            /// <summary>
+            /// Disposes delegate objects in this interface
+            /// </summary>
+            /// <param name="tag">The tag string from delegate object</param>
+            void DisposeCallback(string tag)
+            {
+                foreach (var i in _delegateList)
+                {
+                    if (i.Tag.Equals(tag))
+                    {
+                        _delegateList.Remove(i);
+                        return;
+                    }
+                }
+            }
 )__cs_cb";
 
 const char CB_DISPOSABLE[] =