Fix C Stub Generator 61/171261/1
authorHwankyu Jhun <h.jhun@samsung.com>
Wed, 28 Feb 2018 02:44:16 +0000 (11:44 +0900)
committerHwankyu Jhun <h.jhun@samsung.com>
Wed, 28 Feb 2018 02:44:16 +0000 (11:44 +0900)
- Seperates adding privileges function from registering function

Change-Id: I5ca9710f0c5de4fd353fb9b26807ad292edb6751
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
idlc/c_gen/c_stub_body_gen.cc
idlc/c_gen/c_stub_body_gen.h

index f685801..b74f3b4 100644 (file)
@@ -54,6 +54,7 @@ void CStubBodyGen::GenInterface(std::ofstream& stream, const Interface& inf) {
   GenInterfaceOnConnectedEventCB(stream, inf);
   GenInterfaceOnDisconnectedEventCB(stream, inf);
   GenInterfaceOnReceivedEventCB(stream, inf);
+  GenInterfaceAddPrivileges(stream, inf);
   GenInterfaceRegister(stream, inf);
   GenInterfaceUnregister(stream, inf);
 }
@@ -265,7 +266,13 @@ void CStubBodyGen::GenInterfaceRegister(std::ofstream& stream,
       "        return r;\n" \
       "    }\n" \
       "\n" \
-      "$$" \
+      "    r = __##_add_privileges();\n" \
+      "    if (r != 0) {\n" \
+      "        LOGE(\"Failed to add privileges\");\n" \
+      "        rpc_port_stub_destroy(__##_stub);\n" \
+      "        __##_stub = NULL;\n" \
+      "        return r;\n" \
+      "    }\n" \
       "\n" \
       "    r = rpc_port_stub_listen(__##_stub);\n" \
       "    if (r != 0) {\n" \
@@ -279,20 +286,7 @@ void CStubBodyGen::GenInterfaceRegister(std::ofstream& stream,
       "}\n";
 
   stream << NLine(1);
-  stream << SmartIndent(GenTemplateString(
-        ReplaceAll(block, "##", inf.GetID()),
-        [&]()->std::string {
-          std::string str;
-          for (auto& a : inf.GetAttributes().GetAttrs()) {
-            if (a->GetKey() != "privilege")
-              continue;
-            str += NLine(1);
-            str += GetAddPrivilegeString(inf.GetID(), *a);
-          }
-          return str;
-        }
-        )
-      );
+  stream << SmartIndent(ReplaceAll(block, "##", inf.GetID()));
 }
 
 void CStubBodyGen::GenInterfaceUnregister(std::ofstream& stream,
@@ -463,10 +457,8 @@ std::string CStubBodyGen::GetAddPrivilegeString(const std::string& id,
                                                 const Attribute& attr) {
   const char format[] =
       "r = $$;\n" \
-       "if (r != 0) {\n" \
-      "    LOGE(\"$$\");\n" \
-      "    rpc_port_stub_destroy(__$$_stub);\n" \
-      "    __$$_stub = NULL;\n" \
+      "if (r != 0) {\n" \
+      "    LOGE(\"Failed to add privilege($$)\");\n" \
       "    return r;\n" \
       "}\n";
   std::string str;
@@ -477,13 +469,7 @@ std::string CStubBodyGen::GetAddPrivilegeString(const std::string& id,
             "_stub, \"" + attr.GetValue() + "\")";
       },
       [&]()->std::string {
-        return "Failed to add privilege";
-      },
-      [&]()->std::string {
-        return id;
-      },
-      [&]()->std::string {
-        return id;
+        return attr.GetValue();
       }
       );
   return str;
@@ -957,4 +943,31 @@ void CStubBodyGen::GenTypedefStubMethod(std::ofstream& stream) {
   stream << std::string(format);
 }
 
+void CStubBodyGen::GenInterfaceAddPrivileges(std::ofstream& stream,
+                                             const Interface& inf) {
+  const char block[] =
+      "static int __$$_add_privileges(void)\n" \
+      "{\n" \
+      "$$" \
+      "    return 0;\n" \
+      "}\n";
+  stream << NLine(1);
+  stream << SmartIndent(GenTemplateString(block,
+        [&]()->std::string {
+          return inf.GetID();
+        },
+        [&]()->std::string {
+          std::string str;
+          for (auto& a : inf.GetAttributes().GetAttrs()) {
+            if (a->GetKey() != "privilege")
+              continue;
+            str += GetAddPrivilegeString(inf.GetID(), *a);
+            str += NLine(1);
+          }
+          return str;
+        }
+        )
+      );
+}
+
 }  // namespace tidl
index 88f3b76..f69da6b 100644 (file)
@@ -49,6 +49,7 @@ class CStubBodyGen : public CBodyGeneratorBase {
   void GenInterfaceGlobalVariables(std::ofstream& stream, const Interface& inf);
   void GenInterfaceDelegators(std::ofstream& stream, const Interface& inf);
   void GenInterfaceContext(std::ofstream& stream, const Interface& inf);
+  void GenInterfaceAddPrivileges(std::ofstream& stream, const Interface& inf);
 
  private:
   void GenInterfaceContextDeclaration(std::ofstream& stream,