Add an option for adding prefix 10/174410/1
authorJunghoon Park <jh9216.park@samsung.com>
Mon, 2 Apr 2018 04:40:52 +0000 (13:40 +0900)
committerJunghoon Park <jh9216.park@samsung.com>
Mon, 2 Apr 2018 04:40:52 +0000 (13:40 +0900)
-n, --namespace
   Add the prefix in the funtion name as output file name (C language only).

Change-Id: Iaf99fd34736c78474c833ec5d6925eaac14ec1e3
Signed-off-by: Junghoon Park <jh9216.park@samsung.com>
idlc/c_gen/c_body_gen_base.cc
idlc/c_gen/c_gen_base.cc
idlc/c_gen/c_gen_base.h
idlc/c_gen/c_header_gen_base.cc
idlc/c_gen/c_proxy_body_gen.cc
idlc/c_gen/c_proxy_header_gen.cc
idlc/c_gen/c_stub_body_gen.cc
idlc/c_gen/c_stub_header_gen.cc
idlc/generator.h
idlc/main.cc

index 1312a9a..efdf2d5 100644 (file)
@@ -86,7 +86,7 @@ void CBodyGeneratorBase::GenStructureDeclaration(std::ofstream& stream,
           return st.GetComments();
         },
         [&]()->std::string {
-          return st.GetID();
+          return GetStructIdWithNamespace(st);
         },
         [&]()->std::string {
           std::string str;
@@ -105,7 +105,7 @@ void CBodyGeneratorBase::GenStructureDeclaration(std::ofstream& stream,
 void CBodyGeneratorBase::GenStructureParcelSerializer(std::ofstream& stream,
                                               const Structure& st) {
   stream << SmartIndent(GenTemplateString(
-        ReplaceAll(CB_STRUCT_SERIALIZER, "##", st.GetID()),
+        ReplaceAll(CB_STRUCT_SERIALIZER, "##", GetStructIdWithNamespace(st)),
         [&]()->std::string {
           std::string str;
           for (auto& i : st.GetElements().GetElms()) {
@@ -121,7 +121,7 @@ void CBodyGeneratorBase::GenStructureParcelSerializer(std::ofstream& stream,
 void CBodyGeneratorBase::GenStructureParcelDeserializer(std::ofstream& stream,
                                                 const Structure& st) {
   stream << SmartIndent(GenTemplateString(
-        ReplaceAll(CB_STRUCT_DESERIALIZER, "##", st.GetID()),
+        ReplaceAll(CB_STRUCT_DESERIALIZER, "##", GetStructIdWithNamespace(st)),
         [&]()->std::string {
           std::string str;
           for (auto& i : st.GetElements().GetElms()) {
@@ -136,13 +136,14 @@ void CBodyGeneratorBase::GenStructureParcelDeserializer(std::ofstream& stream,
 
 void CBodyGeneratorBase::GenStructureConstructor(std::ofstream& stream,
                                                  const Structure& st) {
-  stream << SmartIndent(ReplaceAll(CB_STRUCT_CTOR, "##", st.GetID()));
+  stream << SmartIndent(ReplaceAll(CB_STRUCT_CTOR, "##", GetStructIdWithNamespace(st)));
 }
 
 void CBodyGeneratorBase::GenStructureDestructor(std::ofstream& stream,
                                                 const Structure& st) {
   stream << SmartIndent(GenTemplateString(
-        ReplaceAll(CB_STRUCT_DTOR, "##", st.GetID()),
+        ReplaceAll(CB_STRUCT_DTOR, "##",
+            GetStructIdWithNamespace(st)),
         [&]()->std::string {
           std::string str;
           for (auto& i : st.GetElements().GetElms()) {
@@ -159,7 +160,7 @@ void CBodyGeneratorBase::GenStructureSetter(std::ofstream& stream,
   for (auto& i : st.GetElements().GetElms()) {
     stream << SmartIndent(GenTemplateString(CB_STRUCT_SETTER,
           [&]()->std::string {
-            return st.GetID();
+            return GetStructIdWithNamespace(st);
           },
           [&]()->std::string {
             if (i->GetType().ToString() == "list")
@@ -170,7 +171,7 @@ void CBodyGeneratorBase::GenStructureSetter(std::ofstream& stream,
             return i->GetID();
           },
           [&]()->std::string {
-            return st.GetID();
+            return GetStructIdWithNamespace(st);
           },
           [&]()->std::string {
             if (i->GetType().IsUserDefinedType())
@@ -238,13 +239,13 @@ void CBodyGeneratorBase::GenStructureGetter(std::ofstream& stream,
 
     stream << SmartIndent(GenTemplateString(CB_STRUCT_GETTER,
           [&]()->std::string {
-            return st.GetID();
+            return GetStructIdWithNamespace(st);
           },
           [&]()->std::string {
             return i->GetID();
           },
           [&]()->std::string {
-            return st.GetID();
+            return GetStructIdWithNamespace(st);
           },
           [&]()->std::string {
             if (i->GetType().IsUserDefinedType())
@@ -296,13 +297,13 @@ void CBodyGeneratorBase::GenStructureIterator(std::ofstream& stream,
 
     stream << SmartIndent(GenTemplateString(CB_STRUCT_ITERATOR,
           [&]()->std::string {
-            return st.GetID();
+            return GetStructIdWithNamespace(st);
           },
           [&]()->std::string {
             return i->GetID();
           },
           [&]()->std::string {
-            return st.GetID();
+            return GetStructIdWithNamespace(st);
           },
           [&]()->std::string {
             if (i->GetType().GetMetaType()->IsUserDefinedType() ||
@@ -330,7 +331,7 @@ void CBodyGeneratorBase::GenStructureIterator(std::ofstream& stream,
 void CBodyGeneratorBase::GenStructureCloner(std::ofstream& stream,
                                             const Structure& st) {
   stream << SmartIndent(GenTemplateString(
-        ReplaceAll(CB_STRUCT_CLONER, "##", st.GetID()),
+        ReplaceAll(CB_STRUCT_CLONER, "##", GetStructIdWithNamespace(st)),
         [&]()->std::string {
           std::string str;
           for (auto& i : st.GetElements().GetElms()) {
@@ -895,7 +896,7 @@ std::string CBodyGeneratorBase::GetClonerString(const std::string& id,
                 std::string ss;
                 ss += "dlog_print(DLOG_ERROR, LOG_TAG, \"Failed to duplicate h->" + id + "\");" +
                     NLine(1);
-                ss += "rpc_port_" + st.GetID() + "_destroy(handle);" +
+                ss += "rpc_port_" + GetStructIdWithNamespace(st) + "_destroy(handle);" +
                     NLine(1);
                 ss += "return -1;" + NLine(1);
                 return ss;
@@ -916,7 +917,7 @@ std::string CBodyGeneratorBase::GetClonerString(const std::string& id,
           return GetParcelParamTypeString(*type.GetMetaType());
         },
         [&]()->std::string {
-          return st.GetID();
+          return GetStructIdWithNamespace(st);
         },
         [&]()->std::string {
           std::string s;
@@ -935,7 +936,7 @@ std::string CBodyGeneratorBase::GetClonerString(const std::string& id,
                 std::string ss;
                 ss += "dlog_print(DLOG_ERROR, LOG_TAG, \"Failed to duplicate value\");" +
                     NLine(1);
-                ss += "rpc_port_" + st.GetID() + "_destroy(handle);" +
+                ss += "rpc_port_" + GetStructIdWithNamespace(st) + "_destroy(handle);" +
                       NLine(1);
                 ss += "return -1;" + NLine(1);
                 return ss;
@@ -950,7 +951,7 @@ std::string CBodyGeneratorBase::GetClonerString(const std::string& id,
                 [&]()->std::string {
                   std::string tmp;
                   tmp += "dlog_print(DLOG_ERROR, LOG_TAG, \"Out of memory\");" + NLine(1);
-                  tmp += "rpc_port_" + st.GetID() + "_destroy(handle);" +
+                  tmp += "rpc_port_" + GetStructIdWithNamespace(st) + "_destroy(handle);" +
                       NLine(1);
                   tmp += "return -1;" + NLine(1);
                   return tmp;
@@ -992,7 +993,7 @@ std::string CBodyGeneratorBase::GetDestructorString(const BaseType& type,
   if (type.IsUserDefinedType() ||
       type.ToString() == "list" ||
       type.ToString() == "array") {
-    str += "rpc_port_" + GetFullNameFromType(type) +
+    str += GetHandlePrefix() + GetFullNameFromType(type) +
         "_destroy(" + value + ");" + NLine(1);
   } else if (type.ToString() == "bundle") {
     str += "bundle_free(" + value + ");" + NLine(1);
@@ -1006,7 +1007,7 @@ std::string CBodyGeneratorBase::GetDestructorString(const BaseType& type,
 std::string CBodyGeneratorBase::GetConstructorString(const BaseType& type,
                                                      const std::string& value) {
   std::string str;
-  str += "rpc_port_" + GetFullNameFromType(type) +
+  str += GetHandlePrefix() + GetFullNameFromType(type) +
       "_create(&" + value + ");" + NLine(1);
   return str;
 }
@@ -1019,7 +1020,7 @@ std::string CBodyGeneratorBase::GetSetterString(const BaseType& type,
   if (type.IsUserDefinedType() ||
       type.ToString() == "list" ||
       type.ToString() == "array") {
-    str += "rpc_port_" + GetFullNameFromType(type) +
+    str += GetHandlePrefix() + GetFullNameFromType(type) +
         "_clone(" + rvalue + ", &" + lvalue +");" + NLine(1);
   } else if (type.ToString() == "string")  {
     str += lvalue + " = strdup(" + rvalue + ");" + NLine(1);
@@ -1083,7 +1084,7 @@ void CBodyGeneratorBase::GenInterfaceDelegateEnumeration(
 
   stream << SmartIndent(GenTemplateString(CB_DELEGATE_ENUM,
         [&]()->std::string {
-          return inf.GetID();
+          return GetInterfaceIdWithNamespace(inf);
         },
         [&]()->std::string {
           std::string str;
@@ -1093,7 +1094,7 @@ void CBodyGeneratorBase::GenInterfaceDelegateEnumeration(
 
             str += GenTemplateString(CB_DELEGATE_ENUM_FORMAT,
                 [&]()->std::string {
-                  return inf.GetID();
+                  return GetInterfaceIdWithNamespace(inf);
                 },
                 [&]()->std::string {
                   return i->GetID();
@@ -1113,13 +1114,13 @@ void CBodyGeneratorBase::GenInterfaceMethodEnumeration(
     std::ofstream& stream, const Interface& inf) {
   stream << SmartIndent(GenTemplateString(CB_METHOD_ENUM,
         [&]()->std::string {
-          return inf.GetID();
+          return GetInterfaceIdWithNamespace(inf);
         },
         [&]()->std::string {
-          return inf.GetID();
+          return GetInterfaceIdWithNamespace(inf);
         },
         [&]()->std::string {
-          return inf.GetID();
+          return GetInterfaceIdWithNamespace(inf);
         },
         [&]()->std::string {
           std::string str;
@@ -1128,7 +1129,7 @@ void CBodyGeneratorBase::GenInterfaceMethodEnumeration(
               continue;
             str += GenTemplateString(CB_METHOD_ENUM_FORMAT,
                 [&]()->std::string {
-                  return inf.GetID();
+                  return GetInterfaceIdWithNamespace(inf);
                 },
                 [&]()->std::string {
                   return i->GetID();
index 43a061a..bcaed46 100644 (file)
@@ -62,9 +62,9 @@ std::string CGeneratorBase::ConvertTypeToString(
     ParameterType::Direction direction, const BaseType& type) {
   if (type.IsUserDefinedType()) {
     if (direction == ParameterType::Direction::IN)
-      return "rpc_port_" + type.ToString() + "_h ";
+      return GetHandlePrefix() + type.ToString() + "_h ";
     else
-      return "rpc_port_" + type.ToString() + "_h *";
+      return GetHandlePrefix() + type.ToString() + "_h *";
   }
 
   if (type.ToString() == "array") {
@@ -102,11 +102,11 @@ std::string CGeneratorBase::GetFullNameFromType(const BaseType& type) {
 std::string CGeneratorBase::GetParcelParamTypeString(const BaseType& type,
                                                      bool is_pointer) {
   if (type.IsUserDefinedType())
-    return "rpc_port_" + type.ToString() + "_h ";
+    return GetHandlePrefix() + type.ToString() + "_h ";
 
   if (type.ToString() == "list" ||
       type.ToString() == "array")
-    return "rpc_port_" + GetFullNameFromType(type) + "_h ";
+    return GetHandlePrefix() + GetFullNameFromType(type) + "_h ";
 
   if (type.ToString() == "string")
     return "char *";
@@ -119,11 +119,11 @@ std::string CGeneratorBase::GetParcelParamTypeString(const BaseType& type,
 
 std::string CGeneratorBase::GetReturnTypeString(const BaseType& type) {
   if (type.IsUserDefinedType())
-    return "rpc_port_" + type.ToString() + "_h ";
+    return GetHandlePrefix() + type.ToString() + "_h ";
 
   if (type.ToString() == "list" ||
       type.ToString() == "array")
-    return "rpc_port_" + GetFullNameFromType(type) + "_h ";
+    return GetHandlePrefix() + GetFullNameFromType(type) + "_h ";
 
   return type_map_[type.ToString()];
 }
@@ -279,9 +279,9 @@ std::string CGeneratorBase::GetParamTypeString(
       type.ToString() == "list" ||
       type.ToString() == "array") {
     if (direction == ParameterType::Direction::IN)
-      return "rpc_port_" + GetFullNameFromType(type) + "_h ";
+      return GetHandlePrefix() + GetFullNameFromType(type) + "_h ";
     else
-      return "rpc_port_" + GetFullNameFromType(type) + "_h *";
+      return GetHandlePrefix() + GetFullNameFromType(type) + "_h *";
   }
 
   if (type.ToString() == "string") {
@@ -314,11 +314,29 @@ std::string CGeneratorBase::GetErrorValue(const BaseType& type)
 
 std::string CGeneratorBase::GetStringFromElementType(const BaseType& type) {
   if (type.IsUserDefinedType())
-    return "rpc_port_" + type.ToString() + "_h ";
+    return GetHandlePrefix() + type.ToString() + "_h ";
   if (type.ToString() == "array")
     return GetReturnTypeString(*type.GetMetaType()) + "*";
 
   return type_map_[type.ToString()];
 }
 
+std::string CGeneratorBase::GetStructIdWithNamespace(const Structure& st) {
+  if (!HasNamespace())
+    return st.GetID();
+  return GetFileNamespace() + "_" + st.GetID();
+}
+
+std::string CGeneratorBase::GetInterfaceIdWithNamespace(const Interface& inf) {
+  if (!HasNamespace())
+    return inf.GetID();
+  return GetFileNamespace() + "_" + inf.GetID();
+}
+
+std::string CGeneratorBase::GetHandlePrefix() {
+  if (!HasNamespace())
+    return "rpc_port_";
+  return "rpc_port_" + GetFileNamespace() + "_";
+}
+
 }  // namespace tidl
index c232050..9d1c16e 100644 (file)
@@ -71,6 +71,9 @@ class CGeneratorBase : public Generator {
   void GenLicenseDescription(std::ofstream& stream);
   void GenIncludeDefaultHeaders(std::ofstream& stream, bool body = true);
   void GenGNUSourceDefinition(std::ofstream& stream);
+  std::string GetStructIdWithNamespace(const Structure& st);
+  std::string GetInterfaceIdWithNamespace(const Interface& inf);
+  std::string GetHandlePrefix();
 
  private:
   bool StructureExist(const Structure& st);
index 1bbe5dd..0c0960e 100644 (file)
@@ -84,10 +84,10 @@ void CHeaderGeneratorBase::GenStructureDeclaration(std::ofstream& stream,
                                                    const Structure& st) {
   GenTemplate(CB_STRUCT_DECL, stream,
       [&]()->std::string {
-        return st.GetID();
+        return GetStructIdWithNamespace(st);
       },
       [&]()->std::string {
-        return st.GetID();
+        return GetStructIdWithNamespace(st);
       }
       );
 }
@@ -96,10 +96,10 @@ void CHeaderGeneratorBase::GenStructureConstructor(std::ofstream& stream,
                                                    const Structure& st) {
   GenTemplate(CB_STRUCT_CTOR, stream,
       [&]()->std::string {
-        return st.GetID();
+        return GetStructIdWithNamespace(st);
       },
       [&]()->std::string {
-        return st.GetID();
+        return GetStructIdWithNamespace(st);
       }
       );
 }
@@ -108,10 +108,10 @@ void CHeaderGeneratorBase::GenStructureDestructor(std::ofstream& stream,
                                                   const Structure& st) {
   GenTemplate(CB_STRUCT_DTOR, stream,
       [&]()->std::string {
-        return st.GetID();
+        return GetStructIdWithNamespace(st);
       },
       [&]()->std::string {
-        return st.GetID();
+        return GetStructIdWithNamespace(st);
       }
       );
 }
@@ -121,7 +121,7 @@ void CHeaderGeneratorBase::GenStructureSetter(std::ofstream& stream,
   for (auto& i : st.GetElements().GetElms()) {
     GenTemplate(CB_STRUCT_SETTER, stream,
           [&]()->std::string {
-            return st.GetID();
+            return GetStructIdWithNamespace(st);
           },
           [&]()->std::string {
             if (i->GetType().ToString() == "list")
@@ -132,7 +132,7 @@ void CHeaderGeneratorBase::GenStructureSetter(std::ofstream& stream,
             return i->GetID();
           },
           [&]()->std::string {
-            return st.GetID();
+            return GetStructIdWithNamespace(st);
           },
           [&]()->std::string {
             if (i->GetType().IsUserDefinedType())
@@ -178,13 +178,13 @@ void CHeaderGeneratorBase::GenStructureGetter(std::ofstream& stream,
 
     GenTemplate(CB_STRUCT_GETTER, stream,
         [&]()->std::string {
-          return st.GetID();
+          return GetStructIdWithNamespace(st);
         },
         [&]()->std::string {
           return i->GetID();
         },
         [&]()->std::string {
-          return st.GetID();
+          return GetStructIdWithNamespace(st);
         },
         [&]()->std::string {
           if (i->GetType().IsUserDefinedType())
@@ -218,13 +218,13 @@ void CHeaderGeneratorBase::GenStructureIterator(std::ofstream& stream,
 
     GenTemplate(CB_STRUCT_ITERATOR, stream,
         [&]()->std::string {
-          return st.GetID();
+          return GetStructIdWithNamespace(st);
         },
         [&]()->std::string {
           return i->GetID();
         },
         [&]()->std::string {
-          return st.GetID();
+          return GetStructIdWithNamespace(st);
         },
         [&]()->std::string {
           if (i->GetType().GetMetaType()->IsUserDefinedType() ||
@@ -246,13 +246,13 @@ void CHeaderGeneratorBase::GenStructureCloner(std::ofstream& stream,
                                               const Structure& st) {
   GenTemplate(CB_STRUCT_CLONER, stream,
       [&]()->std::string {
-        return st.GetID();
+        return GetStructIdWithNamespace(st);
       },
       [&]()->std::string {
-        return st.GetID();
+        return GetStructIdWithNamespace(st);
       },
       [&]()->std::string {
-        return st.GetID();
+        return GetStructIdWithNamespace(st);
       }
       );
 }
index 1efde50..25e5f90 100644 (file)
@@ -76,7 +76,7 @@ void CProxyBodyGen::GenInterface(std::ofstream& stream, const Interface& inf) {
 
 void CProxyBodyGen::GenInterfaceDeclaration(std::ofstream& stream,
                                             const Interface& inf) {
-  stream << SmartIndent(ReplaceAll(CB_INTERFACE_STRUCT, "##", inf.GetID()));
+  stream << SmartIndent(ReplaceAll(CB_INTERFACE_STRUCT, "##", GetInterfaceIdWithNamespace(inf)));
 }
 
 void CProxyBodyGen::GenInterfaceDelegators(std::ofstream& stream,
@@ -84,7 +84,7 @@ void CProxyBodyGen::GenInterfaceDelegators(std::ofstream& stream,
   for (auto& i : inf.GetDeclarations().GetDecls()) {
     if (i->GetMethodType() != Declaration::MethodType::DELEGATE)
       continue;
-    GenInterfaceDelegator(stream, inf.GetID(), *i);
+    GenInterfaceDelegator(stream, GetInterfaceIdWithNamespace(inf), *i);
   }
 }
 
@@ -222,10 +222,10 @@ void CProxyBodyGen::GenInterfaceDelegatorTable(std::ofstream& stream,
       continue;
     str += GenTemplateString(delegate_format,
         [&]()->std::string {
-          return inf.GetID() + "_DELEGATE_" + i->GetID();
+          return GetInterfaceIdWithNamespace(inf) + "_DELEGATE_" + i->GetID();
         },
         [&]()->std::string {
-          return "__" + inf.GetID() + "_delegate_" + i->GetID();
+          return "__" + GetInterfaceIdWithNamespace(inf) + "_delegate_" + i->GetID();
         }
         );
     cnt++;
@@ -236,7 +236,7 @@ void CProxyBodyGen::GenInterfaceDelegatorTable(std::ofstream& stream,
 
   stream << SmartIndent(GenTemplateString(block,
         [&]()->std::string {
-          return inf.GetID();
+          return GetInterfaceIdWithNamespace(inf);
         },
         [&]()->std::string {
           return str;
@@ -257,11 +257,11 @@ void CProxyBodyGen::GenInterfaceDelegatorHandler(std::ofstream& stream,
   }
 
   stream << SmartIndent(GenTemplateString(
-      ReplaceAll(CB_PROCESS_RECEIVED_EVENT, "##", inf.GetID()),
+      ReplaceAll(CB_PROCESS_RECEIVED_EVENT, "##", GetInterfaceIdWithNamespace(inf)),
         [&]()->std::string {
           if (cnt == 0)
             return str;
-          return ReplaceAll(CB_PROCESS_RECEIVED_EVENT_IMPL, "##", inf.GetID());
+          return ReplaceAll(CB_PROCESS_RECEIVED_EVENT_IMPL, "##", GetInterfaceIdWithNamespace(inf));
         }
         )
       );
@@ -269,27 +269,27 @@ void CProxyBodyGen::GenInterfaceDelegatorHandler(std::ofstream& stream,
 
 void CProxyBodyGen::GenInterfaceConsumeCommand(std::ofstream& stream,
                                                const Interface& inf) {
-  stream << SmartIndent(ReplaceAll(CB_CONSUME_COMMAND, "##", inf.GetID()));
+  stream << SmartIndent(ReplaceAll(CB_CONSUME_COMMAND, "##", GetInterfaceIdWithNamespace(inf)));
 }
 
 void CProxyBodyGen::GenInterfaceOnConnectedEventCB(std::ofstream& stream,
                                                    const Interface& inf) {
-  stream << SmartIndent(ReplaceAll(CB_ON_CONNECTED, "##", inf.GetID()));
+  stream << SmartIndent(ReplaceAll(CB_ON_CONNECTED, "##", GetInterfaceIdWithNamespace(inf)));
 }
 
 void CProxyBodyGen::GenInterfaceOnDisconnectedEventCB(std::ofstream& stream,
                                                       const Interface& inf) {
-  stream << SmartIndent(ReplaceAll(CB_ON_DISCONNECTED, "##", inf.GetID()));
+  stream << SmartIndent(ReplaceAll(CB_ON_DISCONNECTED, "##", GetInterfaceIdWithNamespace(inf)));
 }
 
 void CProxyBodyGen::GenInterfaceOnRejectedEventCB(std::ofstream& stream,
                                                   const Interface& inf) {
-  stream << SmartIndent(ReplaceAll(CB_ON_REJECTED, "##", inf.GetID()));
+  stream << SmartIndent(ReplaceAll(CB_ON_REJECTED, "##", GetInterfaceIdWithNamespace(inf)));
 }
 
 void CProxyBodyGen::GenInterfaceOnReceivedEventCB(std::ofstream& stream,
                                                   const Interface& inf) {
-  stream << SmartIndent(ReplaceAll(CB_ON_RECEIVED, "##", inf.GetID()));
+  stream << SmartIndent(ReplaceAll(CB_ON_RECEIVED, "##", GetInterfaceIdWithNamespace(inf)));
 }
 
 void CProxyBodyGen::GenInterfaceMethods(std::ofstream& stream,
@@ -298,7 +298,7 @@ void CProxyBodyGen::GenInterfaceMethods(std::ofstream& stream,
     if (i->GetMethodType() == Declaration::MethodType::DELEGATE)
       continue;
     stream << SmartIndent(GenTemplateString(
-        ReplaceAll(CB_INTERFACE_METHODS, "##", inf.GetID()),
+        ReplaceAll(CB_INTERFACE_METHODS, "##", GetInterfaceIdWithNamespace(inf)),
           [&]()->std::string {
             return GetReturnTypeString(i->GetType());
           },
@@ -310,7 +310,7 @@ void CProxyBodyGen::GenInterfaceMethods(std::ofstream& stream,
             for (auto& p : i->GetParameters().GetParams()) {
               str += ", ";
               if (TypeIsDelegator(inf, p->GetParameterType().GetBaseType())) {
-                str += "rpc_port_" + inf.GetID() + "_" +
+                str += "rpc_port_" + GetInterfaceIdWithNamespace(inf) + "_" +
                     p->GetParameterType().GetBaseType().ToString() +
                     "_h " + p->GetID();
               } else {
@@ -365,22 +365,22 @@ void CProxyBodyGen::GenInterfaceMethods(std::ofstream& stream,
 
 void CProxyBodyGen::GenInterfaceConstructor(std::ofstream& stream,
                                             const Interface& inf) {
-  stream << SmartIndent(ReplaceAll(CB_INTERFACE_CTOR, "##", inf.GetID()));
+  stream << SmartIndent(ReplaceAll(CB_INTERFACE_CTOR, "##", GetInterfaceIdWithNamespace(inf)));
 }
 
 void CProxyBodyGen::GenInterfaceDestructor(std::ofstream& stream,
                                            const Interface& inf) {
-  stream << SmartIndent(ReplaceAll(CB_INTERFACE_DTOR, "##", inf.GetID()));
+  stream << SmartIndent(ReplaceAll(CB_INTERFACE_DTOR, "##", GetInterfaceIdWithNamespace(inf)));
 }
 
 void CProxyBodyGen::GenInterfaceConnect(std::ofstream& stream,
                                         const Interface& inf) {
-  stream << SmartIndent(ReplaceAll(CB_INTERFACE_CONNECT, "##", inf.GetID()));
+  stream << SmartIndent(ReplaceAll(CB_INTERFACE_CONNECT, "##", GetInterfaceIdWithNamespace(inf)));
 }
 
 void CProxyBodyGen::GenInterfaceDisconnect(std::ofstream& stream,
                                            const Interface& inf) {
-  stream << SmartIndent(ReplaceAll(CB_INTERFACE_DISCONNECT, "##", inf.GetID()));
+  stream << SmartIndent(ReplaceAll(CB_INTERFACE_DISCONNECT, "##", GetInterfaceIdWithNamespace(inf)));
 }
 
 std::string CProxyBodyGen::GetMethodWriteString(const Interface& inf,
@@ -392,7 +392,7 @@ std::string CProxyBodyGen::GetMethodWriteString(const Interface& inf,
       continue;
     if (TypeIsDelegator(inf, p->GetParameterType().GetBaseType())) {
       str += GenTemplateString(ReplaceAll(CB_DELEGATE_BLOCK, "##",
-          inf.GetID() + "_" + p->GetParameterType().GetBaseType().ToString()),
+          GetInterfaceIdWithNamespace(inf) + "_" + p->GetParameterType().GetBaseType().ToString()),
           [&]()->std::string {
             return p->GetID();
           }
@@ -445,7 +445,7 @@ std::string CProxyBodyGen::GetMethodReadString(const Interface& inf,
         return s;
       },
       [&]()->std::string {
-        return inf.GetID();
+        return GetInterfaceIdWithNamespace(inf);
       },
       [&]()->std::string {
         std::string s;
index 5548963..13de012 100644 (file)
@@ -62,7 +62,7 @@ void CProxyHeaderGen::GenInterfaceDelegators(std::ofstream& stream,
   for (auto& i : inf.GetDeclarations().GetDecls()) {
     if (i->GetMethodType() != Declaration::MethodType::DELEGATE)
       continue;
-    GenInterfaceDelegator(stream, inf.GetID(), *i);
+    GenInterfaceDelegator(stream, GetInterfaceIdWithNamespace(inf), *i);
   }
 }
 
@@ -108,7 +108,7 @@ void CProxyHeaderGen::GenInterfaceDelegator(std::ofstream& stream,
 
 void CProxyHeaderGen::GenInterfaceDeclaration(std::ofstream& stream,
                                               const Interface& inf) {
-  stream << SmartIndent(ReplaceAll(CB_INTERFACE_DECL, "##", inf.GetID()));
+  stream << SmartIndent(ReplaceAll(CB_INTERFACE_DECL, "##", GetInterfaceIdWithNamespace(inf)));
 }
 
 void CProxyHeaderGen::GenInterfaceMethods(std::ofstream& stream,
@@ -117,7 +117,7 @@ void CProxyHeaderGen::GenInterfaceMethods(std::ofstream& stream,
     if (i->GetMethodType() == Declaration::MethodType::DELEGATE)
       continue;
     stream << GenTemplateString(
-        ReplaceAll(CB_INTERFACE_METHODS, "##", inf.GetID()),
+        ReplaceAll(CB_INTERFACE_METHODS, "##", GetInterfaceIdWithNamespace(inf)),
         [&]()->std::string {
           return GetReturnTypeString(i->GetType());
         },
@@ -129,7 +129,7 @@ void CProxyHeaderGen::GenInterfaceMethods(std::ofstream& stream,
           for (auto& p : i->GetParameters().GetParams()) {
             str += ", ";
             if (TypeIsDelegator(inf, p->GetParameterType().GetBaseType())) {
-              str += "rpc_port_" + inf.GetID() + "_" +
+              str += "rpc_port_" + GetInterfaceIdWithNamespace(inf) + "_" +
                   p->GetParameterType().GetBaseType().ToString() +
                   "_h " + p->GetID();
             } else {
@@ -145,12 +145,12 @@ void CProxyHeaderGen::GenInterfaceMethods(std::ofstream& stream,
 
 void CProxyHeaderGen::GenInterfaceConnect(std::ofstream& stream,
                                           const Interface& inf) {
-  stream << ReplaceAll(CB_INTERFACE_CONNECT, "##", inf.GetID());
+  stream << ReplaceAll(CB_INTERFACE_CONNECT, "##", GetInterfaceIdWithNamespace(inf));
 }
 
 void CProxyHeaderGen::GenInterfaceDisconnect(std::ofstream& stream,
                                              const Interface& inf) {
-  stream << ReplaceAll(CB_INTERFACE_DISCONNECT, "##", inf.GetID());
+  stream << ReplaceAll(CB_INTERFACE_DISCONNECT, "##", GetInterfaceIdWithNamespace(inf));
 }
 
 }  // namespace tidl
index 013b530..7e6d3fa 100644 (file)
@@ -71,13 +71,13 @@ void CStubBodyGen::GenInterfaceMethods(std::ofstream& stream,
 
     stream << SmartIndent(GenTemplateString(CB_INTERFACE_METHOD,
           [&]()->std::string {
-            return inf.GetID();
+            return GetInterfaceIdWithNamespace(inf);
           },
           [&]()->std::string {
             return i->GetID();
           },
           [&]()->std::string {
-            return inf.GetID();
+            return GetInterfaceIdWithNamespace(inf);
           },
           [&]()->std::string {
             return GetMethodString(inf, *i);
@@ -97,10 +97,10 @@ void CStubBodyGen::GenInterfaceMethodTable(std::ofstream& stream,
       continue;
     str += GenTemplateString(CB_INTERFACE_METHOD_FORMAT,
         [&]()->std::string {
-          return inf.GetID() + "_METHOD_" + i->GetID();
+          return GetInterfaceIdWithNamespace(inf) + "_METHOD_" + i->GetID();
         },
         [&]()->std::string {
-          return "__" + inf.GetID() + "_method_" + i->GetID();
+          return "__" + GetInterfaceIdWithNamespace(inf) + "_method_" + i->GetID();
         }
         );
     cnt++;
@@ -112,7 +112,7 @@ void CStubBodyGen::GenInterfaceMethodTable(std::ofstream& stream,
   stream << NLine(1);
   stream << SmartIndent(GenTemplateString(CB_INTERFACE_METHOD_TABLE,
         [&]()->std::string {
-          return inf.GetID();
+          return GetInterfaceIdWithNamespace(inf);
         },
         [&]()->std::string {
           return str;
@@ -124,34 +124,34 @@ void CStubBodyGen::GenInterfaceMethodTable(std::ofstream& stream,
 void CStubBodyGen::GenInterfaceOnConnectedEventCB(std::ofstream& stream,
                                                   const Interface& inf) {
   stream << SmartIndent(
-      ReplaceAll(CB_INTERFACE_ON_CONNECTED, "##", inf.GetID()));
+      ReplaceAll(CB_INTERFACE_ON_CONNECTED, "##", GetInterfaceIdWithNamespace(inf)));
 }
 
 void CStubBodyGen::GenInterfaceOnDisconnectedEventCB(std::ofstream& stream,
                                                      const Interface& inf) {
   stream << SmartIndent(
-      ReplaceAll(CB_INTERFACE_ON_DISCONNECTED, "##", inf.GetID()));
+      ReplaceAll(CB_INTERFACE_ON_DISCONNECTED, "##", GetInterfaceIdWithNamespace(inf)));
 }
 
 void CStubBodyGen::GenInterfaceOnReceivedEventCB(std::ofstream& stream,
                                                  const Interface& inf) {
   stream << SmartIndent(
-      ReplaceAll(CB_INTERFACE_ON_RECEIVED, "##", inf.GetID()));
+      ReplaceAll(CB_INTERFACE_ON_RECEIVED, "##", GetInterfaceIdWithNamespace(inf)));
 }
 
 void CStubBodyGen::GenInterfaceRegister(std::ofstream& stream,
                                         const Interface& inf) {
-  stream << SmartIndent(ReplaceAll(CB_INTERFACE_REGISTER, "##", inf.GetID()));
+  stream << SmartIndent(ReplaceAll(CB_INTERFACE_REGISTER, "##", GetInterfaceIdWithNamespace(inf)));
 }
 
 void CStubBodyGen::GenInterfaceUnregister(std::ofstream& stream,
                                           const Interface& inf) {
-  stream << SmartIndent(ReplaceAll(CB_INTERFACE_UNREGISTER, "##", inf.GetID()));
+  stream << SmartIndent(ReplaceAll(CB_INTERFACE_UNREGISTER, "##", GetInterfaceIdWithNamespace(inf)));
 }
 
 void CStubBodyGen::GenInterfaceGlobalVariables(std::ofstream& stream,
                                                const Interface& inf) {
-  stream << SmartIndent(ReplaceAll(CB_GLOBALS, "##", inf.GetID()));
+  stream << SmartIndent(ReplaceAll(CB_GLOBALS, "##", GetInterfaceIdWithNamespace(inf)));
 }
 
 std::string CStubBodyGen::GetMethodString(const Interface& inf,
@@ -172,7 +172,7 @@ std::string CStubBodyGen::GetMethodString(const Interface& inf,
   int cnt = 0;
   for (auto& i : decl.GetParameters().GetParams()) {
     if (TypeIsDelegator(inf, i->GetParameterType().GetBaseType())) {
-      str += "rpc_port_" + inf.GetID() + "_" +
+      str += "rpc_port_" + GetInterfaceIdWithNamespace(inf) + "_" +
           i->GetParameterType().GetBaseType().ToString() + "_h " +
           i->GetID() + ";" + NLine(1);
     } else {
@@ -192,12 +192,12 @@ std::string CStubBodyGen::GetMethodString(const Interface& inf,
         i->GetParameterType().GetBaseType().ToString() == "list" ||
         i->GetParameterType().GetBaseType().ToString() == "array") {
       if (TypeIsDelegator(inf, i->GetParameterType().GetBaseType())) {
-        str += "rpc_port_" + inf.GetID() + "_" +
+        str += "rpc_port_" + GetInterfaceIdWithNamespace(inf) + "_" +
             i->GetParameterType().GetBaseType().ToString() +
             "_create(&" + i->GetID() + ");" + NLine(1);
         str += GenTemplateString(port_setter,
             [&]()->std::string {
-              return inf.GetID() + "_" +
+              return GetInterfaceIdWithNamespace(inf) + "_" +
                   i->GetParameterType().GetBaseType().ToString();
             },
             [&]()->std::string {
@@ -248,7 +248,7 @@ std::string CStubBodyGen::GetMethodString(const Interface& inf,
   if (decl.GetMethodType() == Declaration::MethodType::SYNC) {
     str += GenTemplateString(do_while_block,
         [&]()->std::string {
-          return inf.GetID();
+          return GetInterfaceIdWithNamespace(inf);
         },
         [&]()->std::string {
           std::string s;
@@ -296,7 +296,7 @@ std::string CStubBodyGen::GetMethodString(const Interface& inf,
 
   for (auto& i: decl.GetParameters().GetParams()) {
     if (TypeIsDelegator(inf, i->GetParameterType().GetBaseType())) {
-      str += "rpc_port_" + inf.GetID() + "_" +
+      str += "rpc_port_" + GetInterfaceIdWithNamespace(inf) + "_" +
           i->GetParameterType().GetBaseType().ToString() +
           "_destroy(" + i->GetID() + ");" + NLine(1);
     } else {
@@ -347,7 +347,7 @@ void CStubBodyGen::GenInterfaceDelegators(std::ofstream& stream,
   for (auto& i : inf.GetDeclarations().GetDecls()) {
     if (i->GetMethodType() != Declaration::MethodType::DELEGATE)
       continue;
-    GenInterfaceDelegator(stream, inf.GetID(), *i);
+    GenInterfaceDelegator(stream, GetInterfaceIdWithNamespace(inf), *i);
   }
 }
 
@@ -487,43 +487,43 @@ void CStubBodyGen::GenInterfaceContext(std::ofstream& stream,
 void CStubBodyGen::GenInterfaceContextDeclaration(std::ofstream& stream,
                                                   const Interface& inf) {
   stream << SmartIndent(ReplaceAll(
-      CB_INTERFACE_CONTEXT_DECL, "##", inf.GetID()));
+      CB_INTERFACE_CONTEXT_DECL, "##", GetInterfaceIdWithNamespace(inf)));
 }
 
 void CStubBodyGen::GenInterfaceContextConstructor(std::ofstream& stream,
                                                   const Interface& inf) {
   stream << SmartIndent(ReplaceAll(
-      CB_INTERFACE_CONTEXT_CTOR, "##", inf.GetID()));
+      CB_INTERFACE_CONTEXT_CTOR, "##", GetInterfaceIdWithNamespace(inf)));
 }
 
 void CStubBodyGen::GenInterfaceContextDestructor(std::ofstream& stream,
                                                  const Interface& inf) {
   stream << SmartIndent(ReplaceAll(
-      CB_INTERFACE_CONTEXT_DTOR, "##", inf.GetID()));
+      CB_INTERFACE_CONTEXT_DTOR, "##", GetInterfaceIdWithNamespace(inf)));
 }
 
 void CStubBodyGen::GenInterfaceContextFinder(std::ofstream& stream,
                                              const Interface& inf) {
   stream << SmartIndent(ReplaceAll(
-      CB_INTERFACE_CONTEXT_FINDER, "##", inf.GetID()));
+      CB_INTERFACE_CONTEXT_FINDER, "##", GetInterfaceIdWithNamespace(inf)));
 }
 
 void CStubBodyGen::GenInterfaceContextTagSetter(std::ofstream& stream,
                                                 const Interface& inf) {
   stream << SmartIndent(ReplaceAll(
-      CB_INTERFACE_CONTEXT_TAG_SETTER, "##", inf.GetID()));
+      CB_INTERFACE_CONTEXT_TAG_SETTER, "##", GetInterfaceIdWithNamespace(inf)));
 }
 
 void CStubBodyGen::GenInterfaceContextTagGetter(std::ofstream& stream,
                                                 const Interface& inf) {
   stream << SmartIndent(ReplaceAll(
-      CB_INTERFACE_CONTEXT_TAG_GETTER, "##", inf.GetID()));
+      CB_INTERFACE_CONTEXT_TAG_GETTER, "##", GetInterfaceIdWithNamespace(inf)));
 }
 
 void CStubBodyGen::GenInterfaceContextSenderGetter(std::ofstream& stream,
                                                    const Interface& inf) {
   stream << SmartIndent(ReplaceAll(
-      CB_INTERFACE_CONTEXT_GET_SENDER, "##", inf.GetID()));
+      CB_INTERFACE_CONTEXT_GET_SENDER, "##", GetInterfaceIdWithNamespace(inf)));
 }
 
 void CStubBodyGen::GenInterfaceContextPortExist(std::ofstream& stream,
@@ -532,7 +532,7 @@ void CStubBodyGen::GenInterfaceContextPortExist(std::ofstream& stream,
     return;
 
   stream << SmartIndent(ReplaceAll(
-      CB_INTERFACE_CONTEXT_PORT_EXIST, "##", inf.GetID()));
+      CB_INTERFACE_CONTEXT_PORT_EXIST, "##", GetInterfaceIdWithNamespace(inf)));
 }
 
 void CStubBodyGen::GenTypedefStubMethod(std::ofstream& stream) {
@@ -543,16 +543,16 @@ void CStubBodyGen::GenInterfaceAddPrivileges(std::ofstream& stream,
                                              const Interface& inf) {
   stream << SmartIndent(GenTemplateString(CB_INTERFACE_ADD_PRIVILEGE,
         [&]()->std::string {
-          return inf.GetID();
+          return GetInterfaceIdWithNamespace(inf);
         },
         [&]()->std::string {
           std::string str;
           for (auto& a : inf.GetAttributes().GetAttrs()) {
             if (a->GetKey() == "privilege") {
-              str += GetAddPrivilegeString(inf.GetID(), *a);
+              str += GetAddPrivilegeString(GetInterfaceIdWithNamespace(inf), *a);
               str += NLine(1);
             } else if (a->GetKey() == "trusted" && a->GetValue() == "true") {
-              str += GetTrustedModeString(inf.GetID(), *a);
+              str += GetTrustedModeString(GetInterfaceIdWithNamespace(inf), *a);
               str += NLine(1);
             }
           }
index 4c0927b..7c74b5b 100644 (file)
@@ -60,7 +60,7 @@ void CStubHeaderGen::GenInterface(std::ofstream& stream,
 void CStubHeaderGen::GenInterfaceDeclaration(std::ofstream& stream,
                                              const Interface& inf) {
   stream << SmartIndent(GenTemplateString(ReplaceAll(
-        CB_INTERFACE_DECL, "##", inf.GetID()),
+        CB_INTERFACE_DECL, "##", GetInterfaceIdWithNamespace(inf)),
         [&]()->std::string {
           std::string str;
           for (auto& i: inf.GetDeclarations().GetDecls()) {
@@ -74,13 +74,13 @@ void CStubHeaderGen::GenInterfaceDeclaration(std::ofstream& stream,
                   return i->GetID();
                 },
                 [&]()->std::string {
-                  return inf.GetID();
+                  return GetInterfaceIdWithNamespace(inf);
                 },
                 [&]()->std::string {
                   std::string s;
                   for (auto& p : i->GetParameters().GetParams()) {
                     if (TypeIsDelegator(inf, p->GetParameterType().GetBaseType())) {
-                      s += "rpc_port_" + inf.GetID() + "_" +
+                      s += "rpc_port_" + GetInterfaceIdWithNamespace(inf) + "_" +
                           p->GetParameterType().GetBaseType().ToString() + "_h " +
                           p->GetID();
                     } else {
@@ -109,22 +109,22 @@ void CStubHeaderGen::GenInterfaceContext(std::ofstream& stream,
 
 void CStubHeaderGen::GenInterfaceContextDeclaration(
     std::ofstream& stream, const Interface& inf) {
-  stream << ReplaceAll(CB_INTERFACE_CONTEXT_DECL, "##", inf.GetID());
+  stream << ReplaceAll(CB_INTERFACE_CONTEXT_DECL, "##", GetInterfaceIdWithNamespace(inf));
 }
 
 void CStubHeaderGen::GenInterfaceContextTagSetter(
     std::ofstream& stream, const Interface& inf) {
-  stream << ReplaceAll(CB_INTERFACE_CONTEXT_SET_TAG, "##", inf.GetID());
+  stream << ReplaceAll(CB_INTERFACE_CONTEXT_SET_TAG, "##", GetInterfaceIdWithNamespace(inf));
 }
 
 void CStubHeaderGen::GenInterfaceContextTagGetter(
     std::ofstream& stream, const Interface& inf) {
-  stream << ReplaceAll(CB_INTERFACE_CONTEXT_GET_TAG, "##", inf.GetID());
+  stream << ReplaceAll(CB_INTERFACE_CONTEXT_GET_TAG, "##", GetInterfaceIdWithNamespace(inf));
 }
 
 void CStubHeaderGen::GenInterfaceContextSenderGetter(
     std::ofstream& stream, const Interface& inf) {
-  stream << ReplaceAll(CB_INTERFACE_CONTEXT_GET_SENDER, "##", inf.GetID());
+  stream << ReplaceAll(CB_INTERFACE_CONTEXT_GET_SENDER, "##", GetInterfaceIdWithNamespace(inf));
 }
 
 void CStubHeaderGen::GenInterfaceDelegators(std::ofstream& stream,
@@ -132,7 +132,7 @@ void CStubHeaderGen::GenInterfaceDelegators(std::ofstream& stream,
   for (auto& i : inf.GetDeclarations().GetDecls()) {
     if (i->GetMethodType() != Declaration::MethodType::DELEGATE)
       continue;
-    GenInterfaceDelegator(stream, inf.GetID(), *i);
+    GenInterfaceDelegator(stream, GetInterfaceIdWithNamespace(inf), *i);
   }
 }
 
@@ -181,12 +181,12 @@ void CStubHeaderGen::GenInterfaceDelegatorInvoker(
 
 void CStubHeaderGen::GenInterfaceRegister(std::ofstream& stream,
                                           const Interface& inf) {
-  stream << ReplaceAll(CB_INTERFACE_REGISTER, "##", inf.GetID());
+  stream << ReplaceAll(CB_INTERFACE_REGISTER, "##", GetInterfaceIdWithNamespace(inf));
 }
 
 void CStubHeaderGen::GenInterfaceUnregister(std::ofstream& stream,
                                             const Interface& inf) {
-  stream << ReplaceAll(CB_INTERFACE_UNREGISTER, "##", inf.GetID());
+  stream << ReplaceAll(CB_INTERFACE_UNREGISTER, "##", GetInterfaceIdWithNamespace(inf));
 }
 
 }  // namespace tidl
index dedd852..9257cac 100644 (file)
@@ -37,6 +37,14 @@ class Generator {
   std::string AddIndent(int indent, std::string lines, bool space = true);
   std::string GetFileNamespace() const;
 
+  void EnableNamespace(bool enable) {
+    hasNamespace_ = enable;
+  }
+
+  bool HasNamespace() const {
+    return hasNamespace_;
+  }
+
   template<typename T, typename ...ARGS>
   void GenTemplate(std::string templ, std::ofstream& stream, T cb, ARGS... args) {
     size_t f = templ.find("$$");
@@ -84,6 +92,7 @@ class Generator {
  private:
   std::shared_ptr<Document> doc_;
   std::ofstream out_file_;
+  bool hasNamespace_ = true;
 };
 
 }  // namespace tidl
index a3b99ba..ffdaf5e 100644 (file)
@@ -43,6 +43,7 @@ class Options {
   std::string GetLanguage() const { return language_; }
   std::string GetInput() const { return input_; }
   std::string GetOutput() const { return output_; }
+  bool HasNamespace() const { return hasNamespace_; }
 
  private:
   enum Cmd {
@@ -56,6 +57,7 @@ class Options {
     OPT_LANGUAGE,
     OPT_INPUT,
     OPT_OUTPUT,
+    OPT_NAMESPACE,
     OPT_MAX
   };
 
@@ -68,6 +70,7 @@ class Options {
   std::string input_;
   std::string output_;
   std::string help_;
+  bool hasNamespace_ = false;
 };
 
 void Options::PrintUsage() {
@@ -97,6 +100,9 @@ std::unique_ptr<Options> Options::Parse(int argc, char** argv) {
       "A tidl interface file.", "INPUT" },
     { "output", 'o', 0, G_OPTION_ARG_STRING, &opt[OPT_OUTPUT],
       "The generated interface file.", "OUTPUT" },
+    { "namespace", 'n', 0, G_OPTION_ARG_NONE, &opt[OPT_NAMESPACE],
+      "Add the prefix in the funtion name as output file name (C language only).",
+      NULL },
     { NULL }
   };
 
@@ -149,6 +155,7 @@ std::unique_ptr<Options> Options::Parse(int argc, char** argv) {
   options->language_ = static_cast<char*>(opt[OPT_LANGUAGE]);
   options->input_ = static_cast<char*>(opt[OPT_INPUT]);
   options->output_ = static_cast<char*>(opt[OPT_OUTPUT]);
+  options->hasNamespace_ = opt[OPT_NAMESPACE] ? true : false;
 
   return options;
 }
@@ -177,8 +184,10 @@ int main(int argc, char** argv) {
       proxy_body.Run(options->GetOutput() + ".cc");
     } else if (options->GetLanguage() == "C") {
       tidl::CProxyHeaderGen proxy_header(ps.GetDoc());
+      proxy_header.EnableNamespace(options->HasNamespace());
       proxy_header.Run(options->GetOutput() + ".h");
       tidl::CProxyBodyGen proxy_body(ps.GetDoc());
+      proxy_body.EnableNamespace(options->HasNamespace());
       proxy_body.Run(options->GetOutput() + ".c");
     }
   } else {
@@ -192,8 +201,10 @@ int main(int argc, char** argv) {
       stub_body.Run(options->GetOutput() + ".cc");
     } else if (options->GetLanguage() == "C") {
       tidl::CStubHeaderGen stub_header(ps.GetDoc());
+      stub_header.EnableNamespace(options->HasNamespace());
       stub_header.Run(options->GetOutput() + ".h");
       tidl::CStubBodyGen stub_body(ps.GetDoc());
+      stub_body.EnableNamespace(options->HasNamespace());
       stub_body.Run(options->GetOutput() + ".c");
     }
   }