Implement trusted-mode 45/172945/1
authorJunghoon Park <jh9216.park@samsung.com>
Mon, 19 Mar 2018 04:58:08 +0000 (13:58 +0900)
committerJunghoon Park <jh9216.park@samsung.com>
Mon, 19 Mar 2018 04:58:08 +0000 (13:58 +0900)
- Call rpc_port_stub_set_trusted() function at generated code

Change-Id: If9f113abb381aab00076f4772fea5f656133a855
Signed-off-by: Junghoon Park <jh9216.park@samsung.com>
idlc/c_gen/c_stub_body_gen.cc
idlc/c_gen/c_stub_body_gen.h
idlc/c_gen/c_stub_body_gen_cb.h
idlc/cpp_gen/cpp_stub_body_gen.cc
idlc/cs_gen/cs_cb_stub_interop.h
idlc/cs_gen/cs_stub_gen.cc

index 480dbf0..26c4d03 100644 (file)
@@ -324,6 +324,22 @@ std::string CStubBodyGen::GetAddPrivilegeString(const std::string& id,
   return str;
 }
 
+std::string CStubBodyGen::GetTrustedModeString(const std::string& id,
+                                               const Attribute& attr) {
+  std::string str;
+
+  str += GenTemplateString(CB_INTERFACE_TRUSTED_MODE_BLOCK,
+      [&]()->std::string {
+        return "rpc_port_stub_set_trusted(__" + id +
+            "_stub, " + attr.GetValue() + ")";
+      },
+      [&]()->std::string {
+        return attr.GetValue();
+      }
+      );
+  return str;
+}
+
 void CStubBodyGen::GenInterfaceDelegators(std::ofstream& stream,
                                           const Interface& inf) {
   for (auto& i : inf.GetDeclarations().GetDecls()) {
@@ -527,10 +543,13 @@ void CStubBodyGen::GenInterfaceAddPrivileges(std::ofstream& stream,
         [&]()->std::string {
           std::string str;
           for (auto& a : inf.GetAttributes().GetAttrs()) {
-            if (a->GetKey() != "privilege")
-              continue;
-            str += GetAddPrivilegeString(inf.GetID(), *a);
-            str += NLine(1);
+            if (a->GetKey() == "privilege") {
+              str += GetAddPrivilegeString(inf.GetID(), *a);
+              str += NLine(1);
+            } else if (a->GetKey() == "trusted" && a->GetValue() == "true") {
+              str += GetTrustedModeString(inf.GetID(), *a);
+              str += NLine(1);
+            }
           }
 
           if (!str.empty())
index f69da6b..80356f7 100644 (file)
@@ -102,6 +102,8 @@ class CStubBodyGen : public CBodyGeneratorBase {
   std::string GetAddEventCBString(const std::string& id);
   std::string GetAddPrivilegeString(const std::string& id,
                                     const Attribute& attr);
+  std::string GetTrustedModeString(const std::string& id,
+                                   const Attribute& attr);
 };
 
 }  // namespace tidl
index e21cf05..4e9b7b4 100644 (file)
@@ -536,3 +536,11 @@ if (r != 0) {
     return r;
 }
 )__c_cb";
+
+const char CB_INTERFACE_TRUSTED_MODE_BLOCK[] =
+R"__c_cb(r = $$;
+if (r != 0) {
+    dlog_print(DLOG_ERROR, LOG_TAG, "Failed to set trusted mode($$)");
+    return r;
+}
+)__c_cb";
index 833827f..76c4303 100644 (file)
@@ -102,6 +102,9 @@ void CppStubBodyGen::GenConstructor(std::ofstream& stream,
     if (i->GetKey() == "privilege") {
       stream << Tab(1) << "rpc_port_stub_add_privilege(stub_, \""
              << i->GetValue() << "\");" << NLine(1);
+    } else if (i->GetKey() == "trusted" && i->GetValue() == "true") {
+      stream << Tab(1) << "rpc_port_stub_set_trusted(stub_, "
+             << i->GetValue() << ");" << NLine(1);
     }
   }
 
index c931c59..07d54dd 100644 (file)
@@ -57,5 +57,9 @@ R"__cs_cb(
             //int rpc_port_stub_add_privilege(rpc_port_stub_h h, const char *privilege);
             [DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_stub_add_privilege")]
             internal static extern int AddPrivilege(IntPtr handle, string privilege);
+
+            //int rpc_port_stub_set_trusted(rpc_port_stub_h h, const bool trusted);
+            [DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_stub_set_trusted")]
+            internal static extern int SetTrusted(IntPtr handle, bool trusted);
         }
 )__cs_cb";
index 28f8139..0d78686 100644 (file)
@@ -222,6 +222,9 @@ void CsStubGen::GenCtor(std::ofstream& stream, const Interface& iface) {
     if (i->GetKey() == "privilege") {
       stream << Tab(4) << "Interop.LibRPCPort.Stub.AddPrivilege(_stub, \""
              << i->GetValue() << "\");" << NLine(1);
+    } else if (i->GetKey() == "trusted" && i->GetValue() == "true") {
+      stream << Tab(4) << "Interop.LibRPCPort.Stub.SetTrusted(_stub, "
+             << i->GetValue() << ");" << NLine(1);
     }
   }
   stream << Tab(3) << "}" << NLine(1);