APPLINK-6213, Make it possible to disable json/dbus support in intergen
authorIgor Kozyrenko <ikozyrenko@luxoft.com>
Fri, 14 Mar 2014 16:56:15 +0000 (18:56 +0200)
committerJustin Dickow <jjdickow@gmail.com>
Tue, 8 Jul 2014 21:35:59 +0000 (17:35 -0400)
Signed-off-by: Justin Dickow <jjdickow@gmail.com>
Conflicts:
test/components/rpc_base/CMakeLists.txt
test/tools/intergen/CMakeLists.txt

30 files changed:
src/components/CMakeLists.txt
src/components/dbus/CMakeLists.txt
src/components/dbus/include/dbus/dbus_message.h [moved from src/components/rpc_base/include/rpc_base/dbus_message.h with 99% similarity]
src/components/dbus/include/dbus/dbus_message_inl.h [moved from src/components/rpc_base/include/rpc_base/dbus_message_inl.h with 99% similarity]
src/components/dbus/src/dbus_message.cc [moved from src/components/rpc_base/src/rpc_base/dbus_message.cc with 99% similarity]
src/components/rpc_base/CMakeLists.txt [deleted file]
src/components/rpc_base/include/rpc_base/rpc_base_dbus_inl.h
src/components/rpc_base/src/rpc_base/rpc_base.cc [deleted file]
src/components/rpc_base/src/rpc_base/rpc_message.cc [deleted file]
test/components/CMakeLists.txt
test/components/rpc_base/CMakeLists.txt
test/components/rpc_base/rpc_base_dbus_test.cc
test/components/rpc_base/rpc_base_test.cc
test/tools/CMakeLists.txt
test/tools/intergen/CMakeLists.txt
test/tools/intergen/src/generated_interface_dbus_tests.cc [new file with mode: 0644]
test/tools/intergen/src/generated_interface_json_tests.cc [moved from test/tools/intergen/src/generated_interface_tests.cc with 61% similarity]
tools/intergen/GenerateInterfaceLibrary.cmake
tools/intergen/cppgen/include/cppgen/cpp_interface_code_generator.h
tools/intergen/cppgen/include/cppgen/enum_from_json_value_function.h
tools/intergen/cppgen/include/cppgen/generator_preferences.h
tools/intergen/cppgen/include/cppgen/module_manager.h
tools/intergen/cppgen/src/cppgen/cpp_api_code_generator.cc
tools/intergen/cppgen/src/cppgen/cpp_interface_code_generator.cc
tools/intergen/cppgen/src/cppgen/declaration_generator.cc
tools/intergen/cppgen/src/cppgen/definition_generator.cc
tools/intergen/cppgen/src/cppgen/enum_from_json_value_function.cc
tools/intergen/cppgen/src/cppgen/generator_preferences.cc
tools/intergen/cppgen/src/cppgen/module_manager.cc
tools/intergen/tool/intergen.cc

index 829ff70..de4c052 100644 (file)
@@ -49,9 +49,6 @@ add_subdirectory(./connection_handler)
 # --- Utils
 add_subdirectory(./utils)
 
-# --- Validated types
-add_subdirectory(./rpc_base)
-
 # --- SmartObjects
 add_subdirectory(./smart_objects)
 
index 9f68176..48bd05e 100644 (file)
@@ -11,11 +11,12 @@ include_directories (
 )
 
 set (SOURCES
-  ${CMAKE_CURRENT_SOURCE_DIR}/src/schema.cc
-  ${CMAKE_CURRENT_BINARY_DIR}/message_descriptions.cc
   ${CMAKE_CURRENT_BINARY_DIR}/introspection_xml.cc
-  ${CMAKE_CURRENT_SOURCE_DIR}/src/dbus_message_controller.cc
+  ${CMAKE_CURRENT_BINARY_DIR}/message_descriptions.cc
   ${CMAKE_CURRENT_SOURCE_DIR}/src/dbus_adapter.cc
+  ${CMAKE_CURRENT_SOURCE_DIR}/src/dbus_message.cc
+  ${CMAKE_CURRENT_SOURCE_DIR}/src/dbus_message_controller.cc
+  ${CMAKE_CURRENT_SOURCE_DIR}/src/schema.cc
 )
 
 set (LIBRARIES dbus-1)
@@ -171,6 +171,6 @@ MessageRef Signal(const char  *path,
                   const char  *name);
 } // namespace dbus
 
-#include "rpc_base/dbus_message_inl.h"
+#include "dbus/dbus_message_inl.h"
 
 #endif // DBUS_DBUS_MESSAGE_H
@@ -32,7 +32,7 @@
 #ifndef DBUS_MESSAGE_INL_H
 #define DBUS_MESSAGE_INL_H
 
-#include "rpc_base/dbus_message.h"
+#include "dbus/dbus_message.h"
 
 namespace dbus {
 // MessageReader
@@ -29,7 +29,7 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 
-#include "rpc_base/dbus_message.h"
+#include "dbus/dbus_message.h"
 
 #include <algorithm>
 #include <cassert>
diff --git a/src/components/rpc_base/CMakeLists.txt b/src/components/rpc_base/CMakeLists.txt
deleted file mode 100644 (file)
index d137a5a..0000000
+++ /dev/null
@@ -1,24 +0,0 @@
-# find_package(DBus)
-
-include_directories(
-  include
-  ${CMAKE_SOURCE_DIR}/src/thirdPartyLibs/jsoncpp/include
-  ${DBUS_INCLUDE_DIRS}
-)
-
-set (SOURCES
- #src/rpc_base/dbus_message.cc
-)
-
-set (HEADERS
-  include/rpc_base/dbus_message.h
-  include/rpc_base/dbus_message_inl.h
-  include/rpc_base/rpc_base_dbus_inl.h
-  include/rpc_base/rpc_base.h
-  include/rpc_base/rpc_base_inl.h
-  include/rpc_base/rpc_base_json_inl.h
-  include/rpc_base/rpc_message.h
-)
-
-add_library(rpc_base ${HEADERS} ${SOURCES})
-target_link_libraries(rpc_base jsoncpp) # dbus-1)
index f4008ac..2ed0ffa 100644 (file)
@@ -33,9 +33,9 @@
 #ifndef RPC_BASE_DBUS_INL_H_
 #define RPC_BASE_DBUS_INL_H_
 
-#include <rpc_base/dbus_message.h>
-#include "rpc_base/rpc_base.h"
+#include "dbus/dbus_message.h"
 #include "json/value.h"
+#include "rpc_base/rpc_base.h"
 
 namespace rpc {
 namespace impl {
diff --git a/src/components/rpc_base/src/rpc_base/rpc_base.cc b/src/components/rpc_base/src/rpc_base/rpc_base.cc
deleted file mode 100644 (file)
index b4e063e..0000000
+++ /dev/null
@@ -1,41 +0,0 @@
-/**
- * Copyright (c) 2014, Ford Motor Company
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * Redistributions of source code must retain the above copyright notice, this
- * list of conditions and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following
- * disclaimer in the documentation and/or other materials provided with the
- * distribution.
- *
- * Neither the name of the Ford Motor Company nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include "rpc_base/rpc_base.h"
-
-
-namespace rpc {
-
-
-
-
-}  // namespace rpc
diff --git a/src/components/rpc_base/src/rpc_base/rpc_message.cc b/src/components/rpc_base/src/rpc_base/rpc_message.cc
deleted file mode 100644 (file)
index 5f06b61..0000000
+++ /dev/null
@@ -1,42 +0,0 @@
-/**
- * Copyright (c) 2014, Ford Motor Company
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * Redistributions of source code must retain the above copyright notice, this
- * list of conditions and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following
- * disclaimer in the documentation and/or other materials provided with the
- * distribution.
- *
- * Neither the name of the Ford Motor Company nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include "rpc_base/rpc_message.h"
-#include "rpc_base/rpc_base_json_inl.h"
-#include "rpc_base/rpc_base_dbus_inl.h"
-
-
-#include "json/value.h"
-
-namespace rpc {
-
-}  // namespace rpc
index d2b4c0f..c7fc6cc 100644 (file)
@@ -33,7 +33,7 @@ add_subdirectory(./utils)
 add_subdirectory(./policies)
 
 # -- rpc_base
-add_subdirectory(./rpc_base)
+add_subdirectory(./rpc_base)
 
 # --- DBus
 IF (${QT_HMI})
index e623f8f..d2b2465 100644 (file)
@@ -1,26 +1,33 @@
 find_package(DBus)
 
 include_directories (
+  ${CMAKE_SOURCE_DIR}/src/components/dbus/include
   ${CMAKE_SOURCE_DIR}/src/components/rpc_base/include
-  ${CMAKE_SOURCE_DIR}/src/thirdPartyLibs/gmock-1.6.0/include
-  ${CMAKE_SOURCE_DIR}/src/thirdPartyLibs/gmock-1.6.0/gtest/include
+  ${CMAKE_SOURCE_DIR}/src/thirdPartyLibs/gmock-1.7.0/gtest/include
+  ${CMAKE_SOURCE_DIR}/src/thirdPartyLibs/gmock-1.7.0/include
   ${CMAKE_SOURCE_DIR}/src/thirdPartyLibs/jsoncpp/include
   ${DBUS_INCLUDE_DIRS}
 )
 
 set (LIBRARIES
-    gtest
-    gtest_main
     gmock
     gmock_main
-    rpc_base
+    gtest
+    gtest_main
+    jsoncpp
 )
 
 set (SOURCES
-  rpc_base_dbus_test.cc
   rpc_base_json_test.cc
   rpc_base_test.cc
 )
 
-create_test("test_rpc_base" "${SOURCES}" "${LIBRARIES}")
+if (${HMI_DBUS_API})
+  # Build dbus tests
+  find_package(DBus)
+  include_directories(${DBUS_INCLUDE_DIRS})
+  set (LIBRARIES ${LIBRARIES} DBus)
+  set (SOURCES ${SOURCES} rpc_base_dbus_test.cc)
+endif ()
 
+create_test("test_rpc_base" "${SOURCES}" "${LIBRARIES}")
index 3be0f14..b8be0f8 100644 (file)
@@ -32,9 +32,9 @@
 #include "gtest/gtest.h"
 #include "gtest/gtest-spi.h"
 
+#include "dbus/dbus_message.h"
 #include "rpc_base/rpc_base.h"
 #include "rpc_base/rpc_base_dbus_inl.h"
-#include "rpc_base/dbus_message.h"
 
 namespace test {
 using namespace rpc;
@@ -495,4 +495,195 @@ TEST_F(DbusDeserialization, SerializeDeserializeMapOfArrays) {
   }
 }
 
+TEST(ValidatedTypes, TestBooleanDbusSignature) {
+  std::string sign;
+  DbusSignature<Boolean>(&sign);
+  ASSERT_EQ(sign, "b");
+}
+
+TEST(ValidatedTypes, TestIntDbusSignature) {
+  std::string sign;
+  DbusSignature<Integer<int32_t, 1, 2> >(&sign);
+  ASSERT_EQ(sign, "i");
+}
+
+TEST(ValidatedTypes, TestFloatDbusSignature) {
+  std::string sign;
+  DbusSignature<Float<1, 2> >(&sign);
+  ASSERT_EQ(sign, "d");
+}
+
+TEST(ValidatedTypes, TestStringDbusSignature) {
+  std::string sign;
+  DbusSignature<String<1, 2> >(&sign);
+  ASSERT_EQ(sign, "s");
+}
+
+TEST(ValidatedTypes, TestEnumDbusSignature) {
+  std::string sign;
+  DbusSignature<Enum<TestEnum> >(&sign);
+  ASSERT_EQ(sign, "i");
+}
+
+TEST(ValidatedTypes, TestIntArrayDbusSignature) {
+  std::string sign;
+  DbusSignature< Array<Integer<int32_t, 1, 2>, 1, 3> >(&sign);
+  ASSERT_EQ(sign, "ai");
+}
+
+TEST(ValidatedTypes, TestIntArrayArrayDbusSignature) {
+  std::string sign;
+  DbusSignature< Array<Array<Integer<int32_t, 1, 2>, 1, 3>, 4, 5> >(&sign);
+  ASSERT_EQ(sign, "aai");
+}
+
+TEST(ValidatedTypes, TestMapDbusSignature) {
+  std::string sign;
+  DbusSignature< Map<Integer<int32_t, 1, 2>, 3, 4> >(&sign);
+  ASSERT_EQ(sign, "a{si}");
+}
+
+TEST(ValidatedTypes, TestMandatoryEnumDbusSignature) {
+  std::string sign;
+  DbusSignature< Mandatory<Enum<TestEnum> > >(&sign);
+  ASSERT_EQ(sign, "i");
+}
+
+TEST(ValidatedTypes, TestOptionalEnumDbusSignature) {
+  std::string sign;
+  DbusSignature< Optional<Enum<TestEnum> > >(&sign);
+  ASSERT_EQ(sign, "(bi)");
+}
+
+TEST(ValidatedTypes, TestOptionalFloatArrayDbusSignature) {
+  std::string sign;
+  DbusSignature< Optional< Array<Float<1,2>, 3, 4> > >(&sign);
+  ASSERT_EQ(sign, "(bad)");
+}
+
+TEST(DbusMessageConstructionTest, DbusMessageConstruction) {
+  DBusMessage* rawmsg = dbus_message_new(DBUS_MESSAGE_TYPE_METHOD_CALL);
+  dbus::MessageRef msgref(rawmsg);
+}
+
+class DbusTest: public testing::Test {
+public:
+  dbus::MessageRef msgref;
+  DbusTest():
+    msgref(dbus_message_new(DBUS_MESSAGE_TYPE_METHOD_CALL)) {
+  }
+};
+
+TEST_F(DbusTest, DbusWriterConstructionTest) {
+ dbus::MessageWriter writer(msgref);
+}
+
+TEST_F(DbusTest, DbusEmptyMessageReaderTest) {
+  dbus::MessageReader reader(msgref);
+  ASSERT_TRUE(reader.has_failed());
+}
+
+TEST_F(DbusTest, DbusMessageWriterBoolWriteRead) {
+  dbus::MessageWriter writer(msgref);
+  writer.PutBool(true);
+  dbus::MessageReader reader(msgref);
+  bool redback_value = reader.TakeBool();
+  ASSERT_FALSE(reader.has_failed());
+  ASSERT_TRUE(redback_value);
+}
+
+TEST_F(DbusTest, DbusMessageWriterInt32WriteRead) {
+  dbus::MessageWriter writer(msgref);
+  writer.PutInt32(42);
+  dbus::MessageReader reader(msgref);
+  int32_t readback_value = reader.TakeInt32();
+  ASSERT_FALSE(reader.has_failed());
+  ASSERT_EQ(readback_value, 42);
+}
+
+TEST_F(DbusTest, DbusMessageWriterStringWriteRead) {
+  dbus::MessageWriter writer(msgref);
+  writer.PutString("Hello DBus!");
+  dbus::MessageReader reader(msgref);
+  std::string readback_value = reader.TakeString();
+  ASSERT_FALSE(reader.has_failed());
+  ASSERT_EQ(readback_value, "Hello DBus!");
+}
+
+TEST_F(DbusTest, DbusMultipleParamsReadWrite) {
+  {
+    dbus::MessageWriter writer(msgref);
+    writer.PutString("Hello DBus!");
+    writer.PutInt16(42);
+    writer.PutDouble(3.14);
+  }
+  {
+    dbus::MessageReader reader(msgref);
+    std::string readback_string = reader.TakeString();
+    ASSERT_FALSE(reader.has_failed());
+    ASSERT_EQ(readback_string, "Hello DBus!");
+    int16_t readback_int = reader.TakeInt16();
+    ASSERT_FALSE(reader.has_failed());
+    ASSERT_EQ(readback_int, 42);
+    double readback_double = reader.TakeDouble();
+    ASSERT_FALSE(reader.has_failed());
+    ASSERT_DOUBLE_EQ(readback_double, 3.14);
+    ASSERT_FALSE(reader.HasNext());
+  }
+}
+
+TEST_F(DbusTest, DbusArrayTest) {
+  {
+    dbus::MessageWriter writer(msgref);
+    dbus::MessageWriter array_writer(&writer, dbus::kArray,
+                                     DBUS_TYPE_INT16_AS_STRING);
+    array_writer.PutInt16(3);
+    array_writer.PutInt16(4);
+    array_writer.PutInt16(5);
+  }
+  {
+    dbus::MessageReader reader(msgref);
+    dbus::MessageReader array_reader = reader.TakeArrayReader();
+    int16_t readback_val = array_reader.TakeInt16();
+    ASSERT_FALSE(reader.has_failed());
+    ASSERT_EQ(readback_val, 3);
+    readback_val = array_reader.TakeInt16();
+    ASSERT_FALSE(reader.has_failed());
+    ASSERT_EQ(readback_val, 4);
+    readback_val = array_reader.TakeInt16();
+    ASSERT_FALSE(reader.has_failed());
+    ASSERT_EQ(readback_val, 5);
+    ASSERT_FALSE(array_reader.HasNext());
+  }
+}
+
+class DbusFailuresTest: public testing::Test {
+public:
+  dbus::MessageRef int_msg;
+  DbusFailuresTest()
+    : int_msg(dbus_message_new(DBUS_MESSAGE_TYPE_METHOD_CALL)) {
+    dbus::MessageWriter writer(int_msg);
+    writer.PutInt64(42);
+  }
+};
+
+TEST_F(DbusFailuresTest, DbusInconsistentTypeReadFailureTest) {
+  dbus::MessageReader reader(int_msg);
+  std::string str = reader.TakeString();
+  ASSERT_EQ(str, std::string(""));
+  ASSERT_TRUE(reader.has_failed());
+}
+
+TEST_F(DbusFailuresTest, DbusNonExistentArrayReadTest) {
+  dbus::MessageReader reader(int_msg);
+  ASSERT_FALSE(reader.has_failed());
+  dbus::MessageReader array_reader = reader.TakeArrayReader();
+  ASSERT_TRUE(array_reader.has_failed());
+  ASSERT_TRUE(reader.has_failed());
+  int64_t val = array_reader.TakeInt64();
+  ASSERT_TRUE(array_reader.has_failed());
+  ASSERT_EQ(val, 0);
+}
+
+
 }  // namespace test
index 507c743..aa8c52d 100644 (file)
@@ -34,8 +34,6 @@
 #include "json/writer.h"
 #include "rpc_base/rpc_base.h"
 #include "rpc_base/rpc_base_json_inl.h"
-#include "rpc_base/rpc_base_dbus_inl.h"
-
 
 namespace test {
 using namespace rpc;
@@ -300,197 +298,4 @@ TEST(ValidatedTypes, TestDifferentTypesAssignment) {
   ASSERT_FALSE(val.is_valid());
 }
 
-
-// DBus support
-TEST(ValidatedTypes, TestBooleanDbusSignature) {
-  std::string sign;
-  DbusSignature<Boolean>(&sign);
-  ASSERT_EQ(sign, "b");
-}
-
-TEST(ValidatedTypes, TestIntDbusSignature) {
-  std::string sign;
-  DbusSignature<Integer<int32_t, 1, 2> >(&sign);
-  ASSERT_EQ(sign, "i");
-}
-
-TEST(ValidatedTypes, TestFloatDbusSignature) {
-  std::string sign;
-  DbusSignature<Float<1, 2> >(&sign);
-  ASSERT_EQ(sign, "d");
-}
-
-TEST(ValidatedTypes, TestStringDbusSignature) {
-  std::string sign;
-  DbusSignature<String<1, 2> >(&sign);
-  ASSERT_EQ(sign, "s");
-}
-
-TEST(ValidatedTypes, TestEnumDbusSignature) {
-  std::string sign;
-  DbusSignature<Enum<TestEnum> >(&sign);
-  ASSERT_EQ(sign, "i");
-}
-
-TEST(ValidatedTypes, TestIntArrayDbusSignature) {
-  std::string sign;
-  DbusSignature< Array<Integer<int32_t, 1, 2>, 1, 3> >(&sign);
-  ASSERT_EQ(sign, "ai");
-}
-
-TEST(ValidatedTypes, TestIntArrayArrayDbusSignature) {
-  std::string sign;
-  DbusSignature< Array<Array<Integer<int32_t, 1, 2>, 1, 3>, 4, 5> >(&sign);
-  ASSERT_EQ(sign, "aai");
-}
-
-TEST(ValidatedTypes, TestMapDbusSignature) {
-  std::string sign;
-  DbusSignature< Map<Integer<int32_t, 1, 2>, 3, 4> >(&sign);
-  ASSERT_EQ(sign, "a{si}");
-}
-
-TEST(ValidatedTypes, TestMandatoryEnumDbusSignature) {
-  std::string sign;
-  DbusSignature< Mandatory<Enum<TestEnum> > >(&sign);
-  ASSERT_EQ(sign, "i");
-}
-
-TEST(ValidatedTypes, TestOptionalEnumDbusSignature) {
-  std::string sign;
-  DbusSignature< Optional<Enum<TestEnum> > >(&sign);
-  ASSERT_EQ(sign, "(bi)");
-}
-
-TEST(ValidatedTypes, TestOptionalFloatArrayDbusSignature) {
-  std::string sign;
-  DbusSignature< Optional< Array<Float<1,2>, 3, 4> > >(&sign);
-  ASSERT_EQ(sign, "(bad)");
-}
-
-TEST(DbusMessageConstructionTest, DbusMessageConstruction) {
-  DBusMessage* rawmsg = dbus_message_new(DBUS_MESSAGE_TYPE_METHOD_CALL);
-  dbus::MessageRef msgref(rawmsg);
-}
-
-class DbusTest: public testing::Test {
-public:
-  dbus::MessageRef msgref;
-  DbusTest():
-    msgref(dbus_message_new(DBUS_MESSAGE_TYPE_METHOD_CALL)) {
-  }
-};
-
-TEST_F(DbusTest, DbusWriterConstructionTest) {
- dbus::MessageWriter writer(msgref);
-}
-
-TEST_F(DbusTest, DbusEmptyMessageReaderTest) {
-  dbus::MessageReader reader(msgref);
-  ASSERT_TRUE(reader.has_failed());
-}
-
-TEST_F(DbusTest, DbusMessageWriterBoolWriteRead) {
-  dbus::MessageWriter writer(msgref);
-  writer.PutBool(true);
-  dbus::MessageReader reader(msgref);
-  bool redback_value = reader.TakeBool();
-  ASSERT_FALSE(reader.has_failed());
-  ASSERT_TRUE(redback_value);
-}
-
-TEST_F(DbusTest, DbusMessageWriterInt32WriteRead) {
-  dbus::MessageWriter writer(msgref);
-  writer.PutInt32(42);
-  dbus::MessageReader reader(msgref);
-  int32_t readback_value = reader.TakeInt32();
-  ASSERT_FALSE(reader.has_failed());
-  ASSERT_EQ(readback_value, 42);
-}
-
-TEST_F(DbusTest, DbusMessageWriterStringWriteRead) {
-  dbus::MessageWriter writer(msgref);
-  writer.PutString("Hello DBus!");
-  dbus::MessageReader reader(msgref);
-  std::string readback_value = reader.TakeString();
-  ASSERT_FALSE(reader.has_failed());
-  ASSERT_EQ(readback_value, "Hello DBus!");
-}
-
-TEST_F(DbusTest, DbusMultipleParamsReadWrite) {
-  {
-    dbus::MessageWriter writer(msgref);
-    writer.PutString("Hello DBus!");
-    writer.PutInt16(42);
-    writer.PutDouble(3.14);
-  }
-  {
-    dbus::MessageReader reader(msgref);
-    std::string readback_string = reader.TakeString();
-    ASSERT_FALSE(reader.has_failed());
-    ASSERT_EQ(readback_string, "Hello DBus!");
-    int16_t readback_int = reader.TakeInt16();
-    ASSERT_FALSE(reader.has_failed());
-    ASSERT_EQ(readback_int, 42);
-    double readback_double = reader.TakeDouble();
-    ASSERT_FALSE(reader.has_failed());
-    ASSERT_DOUBLE_EQ(readback_double, 3.14);
-    ASSERT_FALSE(reader.HasNext());
-  }
-}
-
-TEST_F(DbusTest, DbusArrayTest) {
-  {
-    dbus::MessageWriter writer(msgref);
-    dbus::MessageWriter array_writer(&writer, dbus::kArray,
-                                     DBUS_TYPE_INT16_AS_STRING);
-    array_writer.PutInt16(3);
-    array_writer.PutInt16(4);
-    array_writer.PutInt16(5);
-  }
-  {
-    dbus::MessageReader reader(msgref);
-    dbus::MessageReader array_reader = reader.TakeArrayReader();
-    int16_t readback_val = array_reader.TakeInt16();
-    ASSERT_FALSE(reader.has_failed());
-    ASSERT_EQ(readback_val, 3);
-    readback_val = array_reader.TakeInt16();
-    ASSERT_FALSE(reader.has_failed());
-    ASSERT_EQ(readback_val, 4);
-    readback_val = array_reader.TakeInt16();
-    ASSERT_FALSE(reader.has_failed());
-    ASSERT_EQ(readback_val, 5);
-    ASSERT_FALSE(array_reader.HasNext());
-  }
-}
-
-class DbusFailuresTest: public testing::Test {
-public:
-  dbus::MessageRef int_msg;
-  DbusFailuresTest()
-    : int_msg(dbus_message_new(DBUS_MESSAGE_TYPE_METHOD_CALL)) {
-    dbus::MessageWriter writer(int_msg);
-    writer.PutInt64(42);
-  }
-};
-
-TEST_F(DbusFailuresTest, DbusInconsistentTypeReadFailureTest) {
-  dbus::MessageReader reader(int_msg);
-  std::string str = reader.TakeString();
-  ASSERT_EQ(str, std::string(""));
-  ASSERT_TRUE(reader.has_failed());
-}
-
-TEST_F(DbusFailuresTest, DbusNonExistentArrayReadTest) {
-  dbus::MessageReader reader(int_msg);
-  ASSERT_FALSE(reader.has_failed());
-  dbus::MessageReader array_reader = reader.TakeArrayReader();
-  ASSERT_TRUE(array_reader.has_failed());
-  ASSERT_TRUE(reader.has_failed());
-  int64_t val = array_reader.TakeInt64();
-  ASSERT_TRUE(array_reader.has_failed());
-  ASSERT_EQ(val, 0);
-}
-
-
 }  // namespace codegen
index f81c116..0e99e22 100644 (file)
@@ -1 +1 @@
-#add_subdirectory(intergen)
+add_subdirectory(intergen)
index 33b7926..fa363fe 100644 (file)
@@ -1,6 +1,10 @@
-message("Intergen tests cmake")
 include(${CMAKE_SOURCE_DIR}/tools/intergen/GenerateInterfaceLibrary.cmake)
-GenerateInterfaceLibrary("test_interface.xml" test_rpc_interface)
+
+if (${HMI_DBUS_API})
+  GenerateInterfaceLibrary("test_interface.xml" test_rpc_interface DBUS_SUPPORT)
+else()
+  GenerateInterfaceLibrary("test_interface.xml" test_rpc_interface)
+endif()
 
 set (TEST_HMI_INTERFACES
   common
@@ -12,12 +16,17 @@ set (TEST_HMI_INTERFACES
   vehicle_info
   vr
 )
-GenerateInterfaceLibrary("test_hmi_interafce.xml" "${TEST_HMI_INTERFACES}" AUTO_FUNC_IDS)
+
+if (${HMI_DBUS_API})
+  GenerateInterfaceLibrary("test_hmi_interafce.xml" "${TEST_HMI_INTERFACES}" AUTO_FUNC_IDS DBUS_SUPPORT)
+else()
+  GenerateInterfaceLibrary("test_hmi_interafce.xml" "${TEST_HMI_INTERFACES}" AUTO_FUNC_IDS)
+endif()
 
 include_directories (
   ${CMAKE_SOURCE_DIR}/src/components/rpc_base/include
-  ${CMAKE_SOURCE_DIR}/src/thirdPartyLibs/gmock-1.6.0/include
-  ${CMAKE_SOURCE_DIR}/src/thirdPartyLibs/gmock-1.6.0/gtest/include
+  ${CMAKE_SOURCE_DIR}/src/thirdPartyLibs/gmock-1.7.0/gtest/include
+  ${CMAKE_SOURCE_DIR}/src/thirdPartyLibs/gmock-1.7.0/include
   ${CMAKE_SOURCE_DIR}/src/thirdPartyLibs/jsoncpp/include
   ${CMAKE_CURRENT_BINARY_DIR}
 )
@@ -27,12 +36,23 @@ set (LIBRARIES
     gtest_main
     gmock
     gmock_main
-    rpc_base
     test_rpc_interface
 )
 
 set (SOURCES
-  src/generated_interface_tests.cc
+  src/generated_interface_json_tests.cc
 )
 
+if (${HMI_DBUS_API})
+  # Build dbus tests
+  find_package(DBus)
+  include_directories(
+      ${CMAKE_SOURCE_DIR}/src/components/dbus/include
+      ${DBUS_INCLUDE_DIRS}
+  )
+  set (LIBRARIES ${LIBRARIES} DBus)
+  set (SOURCES ${SOURCES} src/generated_interface_dbus_tests.cc)
+endif ()
+
+
 create_test(test_generated_interface "${SOURCES}" "${LIBRARIES}")
diff --git a/test/tools/intergen/src/generated_interface_dbus_tests.cc b/test/tools/intergen/src/generated_interface_dbus_tests.cc
new file mode 100644 (file)
index 0000000..468c7c2
--- /dev/null
@@ -0,0 +1,95 @@
+#include "gmock/gmock.h"
+
+#include <test_rpc_interface/interface.h>
+#include <test_rpc_interface/functions.h>
+
+#include "dbus/dbus_message.h"
+
+namespace test {
+using namespace rpc::test_rpc_interface;
+
+TEST(GeneratedInterfaceDbusTests, TestFailedDbusDeserialization) {
+  dbus::MessageRef msg(dbus_message_new(DBUS_MESSAGE_TYPE_METHOD_CALL));
+  {
+    dbus::MessageWriter writer(msg);
+  }
+  {
+    dbus::MessageReader reader(msg);
+    request::DiagnosticMessage dm(&reader);
+    ASSERT_TRUE(reader.has_failed());
+    ASSERT_TRUE(dm.is_initialized());
+    ASSERT_FALSE(dm.is_valid());
+  }
+}
+
+TEST(GeneratedInterfaceDbusTests, TestDbusDeserialization) {
+  dbus::MessageRef msg(dbus_message_new(DBUS_MESSAGE_TYPE_METHOD_CALL));
+  {
+    dbus::MessageWriter writer(msg);
+    writer.PutUint16(22);
+    writer.PutUint16(42);
+    dbus::MessageWriter array_writer(&writer, dbus::kArray, DBUS_TYPE_BYTE_AS_STRING);
+    array_writer.PutByte(11);
+  }
+  {
+    dbus::MessageReader reader(msg);
+    request::DiagnosticMessage dm(&reader);
+    ASSERT_FALSE(reader.has_failed());
+    ASSERT_FALSE(reader.HasNext());
+    ASSERT_TRUE(dm.is_initialized());
+    ASSERT_TRUE(dm.is_valid());
+    ASSERT_EQ(dm.targetID, 22);
+    ASSERT_EQ(dm.messageLength, 42);
+    ASSERT_EQ(dm.messageData.size(), 1);
+  }
+}
+
+TEST(GeneratedInterfaceDbusTests, TestDbusSerializationDeserialization) {
+  dbus::MessageRef msg(dbus_message_new(DBUS_MESSAGE_TYPE_METHOD_CALL));
+  {
+    dbus::MessageWriter writer(msg);
+    request::DiagnosticMessage dm;
+    dm.targetID = 70;
+    dm.messageLength = 1;
+    dm.messageData.push_back(42);
+    dm.ToDbusWriter(&writer);
+  }
+  {
+    dbus::MessageReader reader(msg);
+    request::DiagnosticMessage dm(&reader);
+    ASSERT_FALSE(reader.has_failed());
+    ASSERT_FALSE(reader.HasNext());
+    ASSERT_TRUE(dm.is_initialized());
+    ASSERT_TRUE(dm.is_valid());
+    ASSERT_EQ(dm.targetID, 70);
+    ASSERT_EQ(dm.messageLength, 1);
+    ASSERT_EQ(dm.messageData.size(), 1);
+    ASSERT_EQ(dm.messageData[0], 42);
+  }
+}
+
+TEST(GeneratedInterfaceDbusTests, TestDbusAddSubMenuSerializatioDeserialization) {
+  dbus::MessageRef msg(dbus_message_new(DBUS_MESSAGE_TYPE_METHOD_CALL));
+  {
+    dbus::MessageWriter writer(msg);
+    notification::DummyNotification dn;
+    TdStruct tds;
+    tds.resArrMap["Hello"].push_back(R_SUCCESS);
+    tds.optionalResArrMap["World"].push_back(R_INVALID_DATA);
+    dn.tds.push_back(tds);
+    ASSERT_TRUE(dn.is_valid());
+    dn.ToDbusWriter(&writer);
+  }
+  {
+    dbus::MessageReader reader(msg);
+    notification::DummyNotification dn(&reader);
+    ASSERT_TRUE(dn.is_initialized());
+    ASSERT_TRUE(dn.is_valid());
+    ASSERT_FALSE(reader.has_failed());
+    ASSERT_FALSE(reader.HasNext());
+    ASSERT_EQ(dn.tds[0].resArrMap["Hello"][0], R_SUCCESS);
+    ASSERT_EQ(dn.tds[0].optionalResArrMap["World"][0], R_INVALID_DATA);
+  }
+}
+
+}  // namespace test
@@ -1,11 +1,9 @@
 #include "gmock/gmock.h"
 
-#include <iostream>
 #include <test_rpc_interface/interface.h>
 #include <test_rpc_interface/functions.h>
 #include "json/reader.h"
 #include "json/writer.h"
-#include "rpc_base/dbus_message.h"
 
 namespace test {
 using namespace rpc::test_rpc_interface;
@@ -124,89 +122,4 @@ TEST_F(GeneratedInterfaceTests, TestFactory) {
   req->HandleWith(&mock);
 }
 
-TEST_F(GeneratedInterfaceTests, TestFailedDbusDeserialization) {
-  dbus::MessageRef msg(dbus_message_new(DBUS_MESSAGE_TYPE_METHOD_CALL));
-  {
-    dbus::MessageWriter writer(msg);
-  }
-  {
-    dbus::MessageReader reader(msg);
-    request::DiagnosticMessage dm(&reader);
-    ASSERT_TRUE(reader.has_failed());
-    ASSERT_TRUE(dm.is_initialized());
-    ASSERT_FALSE(dm.is_valid());
-  }
-}
-
-TEST_F(GeneratedInterfaceTests, TestDbusDeserialization) {
-  dbus::MessageRef msg(dbus_message_new(DBUS_MESSAGE_TYPE_METHOD_CALL));
-  {
-    dbus::MessageWriter writer(msg);
-    writer.PutUint16(22);
-    writer.PutUint16(42);
-    dbus::MessageWriter array_writer(&writer, dbus::kArray, DBUS_TYPE_BYTE_AS_STRING);
-    array_writer.PutByte(11);
-  }
-  {
-    dbus::MessageReader reader(msg);
-    request::DiagnosticMessage dm(&reader);
-    ASSERT_FALSE(reader.has_failed());
-    ASSERT_FALSE(reader.HasNext());
-    ASSERT_TRUE(dm.is_initialized());
-    ASSERT_TRUE(dm.is_valid());
-    ASSERT_EQ(dm.targetID, 22);
-    ASSERT_EQ(dm.messageLength, 42);
-    ASSERT_EQ(dm.messageData.size(), 1);
-  }
-}
-
-TEST_F(GeneratedInterfaceTests, TestDbusSerializationDeserialization) {
-  dbus::MessageRef msg(dbus_message_new(DBUS_MESSAGE_TYPE_METHOD_CALL));
-  {
-    dbus::MessageWriter writer(msg);
-    request::DiagnosticMessage dm;
-    dm.targetID = 70;
-    dm.messageLength = 1;
-    dm.messageData.push_back(42);
-    dm.ToDbusWriter(&writer);
-  }
-  {
-    dbus::MessageReader reader(msg);
-    request::DiagnosticMessage dm(&reader);
-    ASSERT_FALSE(reader.has_failed());
-    ASSERT_FALSE(reader.HasNext());
-    ASSERT_TRUE(dm.is_initialized());
-    ASSERT_TRUE(dm.is_valid());
-    ASSERT_EQ(dm.targetID, 70);
-    ASSERT_EQ(dm.messageLength, 1);
-    ASSERT_EQ(dm.messageData.size(), 1);
-    ASSERT_EQ(dm.messageData[0], 42);
-  }
-}
-
-TEST_F(GeneratedInterfaceTests, TestDbusAddSubMenuSerializatioDeserialization) {
-  dbus::MessageRef msg(dbus_message_new(DBUS_MESSAGE_TYPE_METHOD_CALL));
-  {
-    dbus::MessageWriter writer(msg);
-    notification::DummyNotification dn;
-    TdStruct tds;
-    tds.resArrMap["Hello"].push_back(R_SUCCESS);
-    tds.optionalResArrMap["World"].push_back(R_INVALID_DATA);
-    dn.tds.push_back(tds);
-    ASSERT_TRUE(dn.is_valid());
-    dn.ToDbusWriter(&writer);
-  }
-  {
-    dbus::MessageReader reader(msg);
-    notification::DummyNotification dn(&reader);
-    ASSERT_TRUE(dn.is_initialized());
-    ASSERT_TRUE(dn.is_valid());
-    ASSERT_FALSE(reader.has_failed());
-    ASSERT_FALSE(reader.HasNext());
-    ASSERT_EQ(dn.tds[0].resArrMap["Hello"][0], R_SUCCESS);
-    ASSERT_EQ(dn.tds[0].optionalResArrMap["World"][0], R_INVALID_DATA);
-  }
-
-}
-
 }  // namespace test
index 7dec0ff..021e030 100644 (file)
@@ -1,7 +1,7 @@
 find_package(DBus)
 
 set(INTERGEN_CMD ${CMAKE_BINARY_DIR}/tools/intergen/bin/intergen)
-set(GENERATED_LIB_DEPENDENCIES rpc_base jsoncpp)
+set(GENERATED_LIB_DEPENDENCIES jsoncpp)
 set(GENERATED_LIB_HEADER_DEPENDENCIES
   ${CMAKE_SOURCE_DIR}/src/components/rpc_base/include
   ${CMAKE_SOURCE_DIR}/src/thirdPartyLibs/jsoncpp/include
@@ -14,13 +14,18 @@ set(GENERATED_LIB_HEADER_DEPENDENCIES
 # |generated_interface_names| should contain list of generated interfaces
 # if |AUTO_FUNC_IDS| is added to argument list, intergen is called with "-a"
 #   flag telling intergen to generate function ids automatically
+# if |DBUS_SUPPORT| is added to argument list, intergen is called with "-d"
+#   flag that enables DBus serialization code generation
 # from xml_file (intergen creates separate directory for every interface).
 # Their names are written lowercase_underscored_style.
-macro (GenerateInterfaceLibrary xml_file_name generated_interface_names)
-  set(options AUTO_FUNC_IDS)
+function (GenerateInterfaceLibrary xml_file_name generated_interface_names)
+  set(options AUTO_FUNC_IDS DBUS_SUPPORT)
   cmake_parse_arguments(GenerateInterfaceLibrary "${options}" "" "" ${ARGN})
   if (GenerateInterfaceLibrary_AUTO_FUNC_IDS)
-    set(intergen_flags "-a")
+    set(AUTOID "-a")
+  endif()
+  if (GenerateInterfaceLibrary_DBUS_SUPPORT)
+    set(NEED_DBUS "-d")
   endif()
 
   foreach(interface_name ${generated_interface_names})
@@ -38,7 +43,7 @@ macro (GenerateInterfaceLibrary xml_file_name generated_interface_names)
         ${interface_name}/interface.cc
     )
     add_custom_command( OUTPUT ${HEADERS} ${SOURCES}
-                        COMMAND ${INTERGEN_CMD} -f ${CMAKE_CURRENT_SOURCE_DIR}/${xml_file_name} -i ${interface_name} ${intergen_flags}
+                        COMMAND ${INTERGEN_CMD} -f ${CMAKE_CURRENT_SOURCE_DIR}/${xml_file_name} -j ${AUTOID} ${NEED_DBUS} -i ${interface_name}
                         DEPENDS ${INTERGEN_CMD} ${xml_file_name}
                         COMMENT "Generating interface ${interface_name} from ${xml_file_name}"
                         VERBATIM
@@ -54,4 +59,4 @@ macro (GenerateInterfaceLibrary xml_file_name generated_interface_names)
     target_link_libraries(${interface_name} ${GENERATED_LIB_DEPENDENCIES} ${previous_interface})
     set(previous_interface ${interface_name})
   endforeach(interface_name)
-endmacro(GenerateInterfaceLibrary xml_file_name generated_interface_names)
+endfunction(GenerateInterfaceLibrary xml_file_name generated_interface_names)
index bea064d..52937fb 100644 (file)
@@ -68,6 +68,7 @@ class CppInterfaceCodeGenerator {
 private:
   // Fields
   const Interface* interface_;
+  const TypePreferences* preferences_;
   ModuleManager* module_manager_;
   DeclarationGenerator declaration_generator_;
   DefinitionGenerator definition_generator_;
index a71cc47..6195d4d 100644 (file)
@@ -43,10 +43,10 @@ class Enum;
  * Enum constants are serialized/deserialized as strings having value from
  * predefined set.
  */
-class EnumFromJsonValueFunction : public CppFunction {
+class EnumFromJsonStringFunction : public CppFunction {
  public:
-  EnumFromJsonValueFunction(const Enum* enm);
-  ~EnumFromJsonValueFunction();
+  EnumFromJsonStringFunction(const Enum* enm);
+  ~EnumFromJsonStringFunction();
   virtual void DefineBody(std::ostream* os) const;
  private:
   const Enum* enm_;
index 902d4a3..5278a24 100644 (file)
 namespace codegen {
 
 struct TypePreferences {
-  TypePreferences(int minimum_interger_size,
-                  bool avoid_unsigned);
   int minimum_interger_size;
   bool avoid_unsigned;
+  bool generate_json;
+  bool generate_dbus;
+  TypePreferences(int minimum_interger_size,
+                  bool avoid_unsigned,
+                  bool generate_json,
+                  bool generate_dbus);
 };
 
 struct Preferences {
   Preferences(int minimum_interger_size,
               bool avoid_unsigned,
+              bool generate_json,
+              bool generate_dbus,
               const std::set<std::string>& requested_interfaces);
   TypePreferences type_preferences;
   std::set<std::string> requested_interfaces;
index d6f1ad6..6ec13c9 100644 (file)
@@ -41,6 +41,7 @@
 
 namespace codegen {
 class Namespace;
+class TypePreferences;
 
 /*
  * Manages all the source files generated for given interface.
@@ -49,7 +50,7 @@ class Namespace;
  */
 class ModuleManager {
  public:
-  ModuleManager(const std::string& name);
+  ModuleManager(const std::string& name, const TypePreferences& prefs);
   ~ModuleManager();
 
   /*
index 187da53..d8c277f 100644 (file)
@@ -77,7 +77,7 @@ std::set<std::string> codegen::CppApiCodeGenerator::Generate(
 
 bool CppApiCodeGenerator::GenerateInterface(const Interface* interface,
                                             const TypePreferences& preferences) {
-  ModuleManager mgr(LowercaseIntefaceName(*interface));
+  ModuleManager mgr(LowercaseIntefaceName(*interface), preferences);
   CppInterfaceCodeGenerator interface_generator(interface,
                                                 &preferences,
                                                 &mgr);
index 0ad6a29..38b4540 100644 (file)
 
 #include "cppgen/cpp_interface_code_generator.h"
 
+#include "cppgen/generator_preferences.h"
 #include "cppgen/handler_interface.h"
-#include "cppgen/message_interface.h"
 #include "cppgen/message_factory_function.h"
+#include "cppgen/message_interface.h"
 #include "cppgen/module_manager.h"
 #include "model/interface.h"
 #include "model/type_registry.h"
@@ -46,6 +47,7 @@ CppInterfaceCodeGenerator::CppInterfaceCodeGenerator(
     const TypePreferences* preferences,
     ModuleManager* module_manager)
     : interface_(interface),
+      preferences_(preferences),
       module_manager_(module_manager),
       declaration_generator_(preferences, module_manager_),
       definition_generator_(preferences, module_manager_) {
@@ -176,20 +178,23 @@ void CppInterfaceCodeGenerator::GenerateMessageFactories() {
   CppFile& factories_header = module_manager_->HeaderForInterface();
   CppFile& factories_source = module_manager_->SourceForInterface();
 
-  MessageFactoryFunction request_factory(interface_,
-                                         FunctionMessage::kRequest);
-  request_factory.Declare(&factories_header.requests_ns().os(), true);
-  request_factory.Define(&factories_source.requests_ns().os(), true);
-  MessageFactoryFunction response_factory(interface_,
-                                          FunctionMessage::kResponse);
-  response_factory.Declare(&factories_header.responses_ns().os(), true);
-  response_factory.Define(&factories_source.responses_ns().os(), true);
-  MessageFactoryFunction notification_factory(
-        interface_,
-        FunctionMessage::kNotification);
-  notification_factory.Declare(&factories_header.notifications_ns().os(),
-                               true);
-  notification_factory.Define(&factories_source.notifications_ns().os(), true);
+  if (preferences_->generate_json) {
+    MessageFactoryFunction request_factory(interface_,
+                                           FunctionMessage::kRequest);
+    request_factory.Declare(&factories_header.requests_ns().os(), true);
+    request_factory.Define(&factories_source.requests_ns().os(), true);
+    MessageFactoryFunction response_factory(interface_,
+                                            FunctionMessage::kResponse);
+    response_factory.Declare(&factories_header.responses_ns().os(), true);
+    response_factory.Define(&factories_source.responses_ns().os(), true);
+    MessageFactoryFunction notification_factory(
+          interface_,
+          FunctionMessage::kNotification);
+    notification_factory.Declare(&factories_header.notifications_ns().os(),
+                                 true);
+    notification_factory.Define(&factories_source.notifications_ns().os(), true);
+  }
+
 }
 
 }  // namespace codegen
index b142974..e45ba38 100644 (file)
@@ -90,6 +90,22 @@ void DeclareStructureBegin(ostream& o, const string& name,
           base_type.empty() ? "" : " : " + base_type) << endl;
 }
 
+void DeclareExternalTypes(const TypePreferences& prefs, Namespace* ns) {
+  if (prefs.generate_json) {
+    ns->nested("Json").ForwardDeclare(
+        Namespace::ForwardDeclaration(
+            Namespace::ForwardDeclaration::kClass, "Value"));
+  }
+  if (prefs.generate_dbus) {
+    ns->nested("dbus").ForwardDeclare(
+        Namespace::ForwardDeclaration(
+            Namespace::ForwardDeclaration::kClass, "MessageReader"));
+    ns->nested("dbus").ForwardDeclare(
+        Namespace::ForwardDeclaration(
+            Namespace::ForwardDeclaration::kClass, "MessageWriter"));
+  }
+}
+
 }
 
 DeclarationGenerator::DeclarationGenerator(const TypePreferences* preferences,
@@ -118,18 +134,13 @@ void DeclarationGenerator::GenerateCodeForEnum(const Enum* enm) {
   o << "};" << endl;
   IsValidEnumFunction(enm).Declare(&o, false);
   EnumToJsonValueFunction(enm).Declare(&o, false);
-  EnumFromJsonValueFunction(enm).Declare(&o, false);
+  EnumFromJsonStringFunction(enm).Declare(&o, false);
   o << endl;
 }
 
 void DeclarationGenerator::GenerateCodeForStruct(const Struct* strct) {
   CppFile& header_file = module_manager_->HeaderForStruct(*strct);
-  header_file.global_namespace().nested("Json").ForwardDeclare(
-      Namespace::ForwardDeclaration(Namespace::ForwardDeclaration::kClass, "Value"));
-  header_file.global_namespace().nested("dbus").ForwardDeclare(
-      Namespace::ForwardDeclaration(Namespace::ForwardDeclaration::kClass, "MessageReader"));
-  header_file.global_namespace().nested("dbus").ForwardDeclare(
-      Namespace::ForwardDeclaration(Namespace::ForwardDeclaration::kClass, "MessageWriter"));
+  DeclareExternalTypes(*preferences_, &header_file.global_namespace());
   ostream& o = header_file.types_ns().os();
   DeclareStructureBegin(o, strct->name(), "",
                         Comment(strct->description()));
@@ -141,19 +152,23 @@ void DeclarationGenerator::GenerateCodeForStruct(const Struct* strct) {
     Section pub("public", &o);
     StructTypeDefaultConstructor(strct).Declare(&o, true);
     StructTypeMandatoryConstructor mandatory_constructor(preferences_, strct);
-    StructTypeFromJsonConstructor(strct).Declare(&o , true);
-    StructTypeFromDbusReaderConstructor(
-          preferences_, strct, true).Declare(&o, true);
     if (mandatory_constructor.has_mandatory_parameters()) {
       mandatory_constructor.Declare(&o, true);
     }
     CppStructDestructor(strct->name()).Declare(&o, true);
+    if (preferences_->generate_json) {
+      StructTypeFromJsonConstructor(strct).Declare(&o , true);
+      StructTypeToJsonMethod(strct).Declare(&o , true);
+    }
+    if (preferences_->generate_dbus) {
+      StructTypeFromDbusReaderConstructor(
+            preferences_, strct, true).Declare(&o, true);
+      StructTypeToDbusWriterMethod(strct, true).Declare(&o , true);
+      StructTypeDbusMessageSignatureMethod(preferences_,
+                                           strct, true).Declare(&o, true);
+    }
     StructTypeIsValidMethod(strct).Declare(&o, true);
     StructTypeIsInitializedMethod(strct).Declare(&o, true);
-    StructTypeToJsonMethod(strct).Declare(&o , true);
-    StructTypeToDbusWriterMethod(strct, true).Declare(&o , true);
-    StructTypeDbusMessageSignatureMethod(preferences_,
-                                         strct, true).Declare(&o, true);
   }
   {
     Section priv("private", &o);
@@ -220,12 +235,7 @@ void DeclarationGenerator::GenerateCodeForFunction(const Function& function) {
 
 void DeclarationGenerator::GenerateCodeForRequest(const Request& request,
                                                   CppFile* header_file) {
-  header_file->global_namespace().nested("Json").ForwardDeclare(
-      Namespace::ForwardDeclaration(Namespace::ForwardDeclaration::kClass, "Value"));
-  header_file->global_namespace().nested("dbus").ForwardDeclare(
-      Namespace::ForwardDeclaration(Namespace::ForwardDeclaration::kClass, "MessageReader"));
-  header_file->global_namespace().nested("dbus").ForwardDeclare(
-      Namespace::ForwardDeclaration(Namespace::ForwardDeclaration::kClass, "MessageWriter"));
+  DeclareExternalTypes(*preferences_, &header_file->global_namespace());
   Namespace& requests_ns = header_file->requests_ns();
   ostream& o = requests_ns.os();
   DeclareStructureBegin(o, request.name(), "Request",
@@ -242,19 +252,24 @@ void DeclarationGenerator::GenerateCodeForRequest(const Request& request,
     Section pub("public", &o);
     StructTypeDefaultConstructor(&request).Declare(&o, true);
     StructTypeMandatoryConstructor mandatory_constructor(preferences_, &request);
-    StructTypeFromJsonConstructor(&request).Declare(&o , true);
-    StructTypeFromDbusReaderConstructor(preferences_,
-                                        &request, false).Declare(&o, true);
     if (mandatory_constructor.has_mandatory_parameters()) {
       mandatory_constructor.Declare(&o, true);
     }
     CppStructDestructor(request.name()).Declare(&o, true);
+
+    if (preferences_->generate_json) {
+      StructTypeFromJsonConstructor(&request).Declare(&o , true);
+      StructTypeToJsonMethod(&request).Declare(&o , true);
+    }
+    if (preferences_->generate_dbus) {
+      StructTypeFromDbusReaderConstructor(preferences_,
+                                          &request, false).Declare(&o, true);
+      StructTypeToDbusWriterMethod(&request, false).Declare(&o , true);
+      StructTypeDbusMessageSignatureMethod(preferences_,
+                                           &request, false).Declare(&o, true);
+    }
     StructTypeIsValidMethod(&request).Declare(&o, true);
     StructTypeIsInitializedMethod(&request).Declare(&o, true);
-    StructTypeToJsonMethod(&request).Declare(&o , true);
-    StructTypeToDbusWriterMethod(&request, false).Declare(&o , true);
-    StructTypeDbusMessageSignatureMethod(preferences_,
-                                         &request, false).Declare(&o, true);
     MessageHandleWithMethod(request.name()).Declare(&o, true);
     FunctionIdMethod(&request).Define(&o, true);
     FunctionStringIdMethod(&request).Define(&o, true);
@@ -269,12 +284,7 @@ void DeclarationGenerator::GenerateCodeForRequest(const Request& request,
 
 void DeclarationGenerator::GenerateCodeForResponse(const Response& response) {
   CppFile& header_file = module_manager_->HeaderForResponse(response);
-  header_file.global_namespace().nested("Json").ForwardDeclare(
-      Namespace::ForwardDeclaration(Namespace::ForwardDeclaration::kClass, "Value"));
-  header_file.global_namespace().nested("dbus").ForwardDeclare(
-      Namespace::ForwardDeclaration(Namespace::ForwardDeclaration::kClass, "MessageReader"));
-  header_file.global_namespace().nested("dbus").ForwardDeclare(
-      Namespace::ForwardDeclaration(Namespace::ForwardDeclaration::kClass, "MessageWriter"));
+  DeclareExternalTypes(*preferences_, &header_file.global_namespace());
   Namespace& responses_ns = header_file.responses_ns();
   ostream& o = responses_ns.os();
   DeclareStructureBegin(o, response.name(), "Response",
@@ -289,19 +299,25 @@ void DeclarationGenerator::GenerateCodeForResponse(const Response& response) {
     Section pub("public", &o);
     StructTypeDefaultConstructor(&response).Declare(&o, true);
     StructTypeMandatoryConstructor mandatory_constructor(preferences_, &response);
-    StructTypeFromJsonConstructor(&response).Declare(&o, true);
-    StructTypeFromDbusReaderConstructor(preferences_,
-                                        &response, false).Declare(&o, true);
     if (mandatory_constructor.has_mandatory_parameters()) {
       mandatory_constructor.Declare(&o, true);
     }
     CppStructDestructor(response.name()).Declare(&o, true);
+    if (preferences_->generate_json) {
+      StructTypeFromJsonConstructor(&response).Declare(&o, true);
+      StructTypeToJsonMethod(&response).Declare(&o , true);
+
+    }
+    if (preferences_->generate_dbus) {
+      StructTypeFromDbusReaderConstructor(preferences_,
+                                          &response, false).Declare(&o, true);
+      StructTypeToDbusWriterMethod(&response, false).Declare(&o , true);
+
+      StructTypeDbusMessageSignatureMethod(preferences_,
+                                           &response, false).Declare(&o, true);
+    }
     StructTypeIsValidMethod(&response).Declare(&o, true);
     StructTypeIsInitializedMethod(&response).Declare(&o, true);
-    StructTypeToJsonMethod(&response).Declare(&o , true);
-    StructTypeToDbusWriterMethod(&response, false).Declare(&o , true);
-    StructTypeDbusMessageSignatureMethod(preferences_,
-                                         &response, false).Declare(&o, true);
     MessageHandleWithMethod(response.name()).Declare(&o, true);
     FunctionIdMethod(&response).Define(&o, true);
     FunctionStringIdMethod(&response).Define(&o, true);
@@ -317,12 +333,7 @@ void DeclarationGenerator::GenerateCodeForResponse(const Response& response) {
 void DeclarationGenerator::GenerateCodeForNotification(
     const Notification& notification) {
   CppFile& header_file = module_manager_->HeaderForNotification(notification);
-  header_file.global_namespace().nested("Json").ForwardDeclare(
-      Namespace::ForwardDeclaration(Namespace::ForwardDeclaration::kClass, "Value"));
-  header_file.global_namespace().nested("dbus").ForwardDeclare(
-      Namespace::ForwardDeclaration(Namespace::ForwardDeclaration::kClass, "MessageReader"));
-  header_file.global_namespace().nested("dbus").ForwardDeclare(
-      Namespace::ForwardDeclaration(Namespace::ForwardDeclaration::kClass, "MessageWriter"));
+  DeclareExternalTypes(*preferences_, &header_file.global_namespace());
   Namespace& notifications_ns = header_file.notifications_ns();
   ostream& o = notifications_ns.os();
   DeclareStructureBegin(o, notification.name(), "Notification",
@@ -337,19 +348,23 @@ void DeclarationGenerator::GenerateCodeForNotification(
     Section pub("public", &o);
     StructTypeDefaultConstructor(&notification).Declare(&o, true);
     StructTypeMandatoryConstructor mandatory_constructor(preferences_, &notification);
-    StructTypeFromJsonConstructor(&notification).Declare(&o , true);
-    StructTypeFromDbusReaderConstructor(preferences_,
-                                        &notification, false).Declare(&o , true);
     if (mandatory_constructor.has_mandatory_parameters()) {
       mandatory_constructor.Declare(&o, true);
     }
     CppStructDestructor(notification.name()).Declare(&o, true);
+    if (preferences_->generate_json) {
+      StructTypeFromJsonConstructor(&notification).Declare(&o , true);
+      StructTypeToJsonMethod(&notification).Declare(&o , true);
+    }
+    if (preferences_->generate_dbus) {
+      StructTypeFromDbusReaderConstructor(preferences_,
+                                          &notification, false).Declare(&o , true);
+      StructTypeToDbusWriterMethod(&notification, false).Declare(&o , true);
+      StructTypeDbusMessageSignatureMethod(preferences_,
+                                           &notification, false).Declare(&o, true);
+    }
     StructTypeIsValidMethod(&notification).Declare(&o, true);
     StructTypeIsInitializedMethod(&notification).Declare(&o, true);
-    StructTypeToJsonMethod(&notification).Declare(&o , true);
-    StructTypeToDbusWriterMethod(&notification, false).Declare(&o , true);
-    StructTypeDbusMessageSignatureMethod(preferences_,
-                                         &notification, false).Declare(&o, true);
     MessageHandleWithMethod(notification.name()).Declare(&o, true);
     FunctionIdMethod(&notification).Define(&o, true);
     FunctionStringIdMethod(&notification).Define(&o, true);
index 1e38969..e822be4 100644 (file)
@@ -35,6 +35,7 @@
 #include "cppgen/comment.h"
 #include "cppgen/enum_from_json_value_function.h"
 #include "cppgen/enum_to_json_value_function.h"
+#include "cppgen/generator_preferences.h"
 #include "cppgen/is_valid_enum_function.h"
 #include "cppgen/message_handle_with_method.h"
 #include "cppgen/module_manager.h"
@@ -66,7 +67,7 @@ void DefinitionGenerator::GenerateCodeForEnum(const Enum* enm) {
   ostream& o = source_file.types_ns().os();
   IsValidEnumFunction(enm).Define(&o, false);
   EnumToJsonValueFunction(enm).Define(&o, false);
-  EnumFromJsonValueFunction(enm).Define(&o, false);
+  EnumFromJsonStringFunction(enm).Define(&o, false);
   o << endl;
 }
 
@@ -80,15 +81,19 @@ void DefinitionGenerator::GenerateCodeForStruct(const Struct* strct) {
     mandatory_constructor.Define(&o, false);
   }
   CppStructDestructor(strct->name()).Define(&o, false);
+  if (preferences_->generate_json) {
+    StructTypeFromJsonConstructor(strct).Define(&o , false);
+    StructTypeToJsonMethod(strct).Define(&o , false);
+  }
+  if (preferences_->generate_dbus) {
+    StructTypeFromDbusReaderConstructor(preferences_,
+                                        strct, true).Define(&o , false);
+    StructTypeToDbusWriterMethod(strct, true).Define(&o , false);
+    StructTypeDbusMessageSignatureMethod(preferences_,
+                                         strct, true).Define(&o, false);
+  }
   StructTypeIsValidMethod(strct).Define(&o, false);
   StructTypeIsInitializedMethod(strct).Define(&o, false);
-  StructTypeFromJsonConstructor(strct).Define(&o , false);
-  StructTypeFromDbusReaderConstructor(preferences_,
-                                      strct, true).Define(&o , false);
-  StructTypeToJsonMethod(strct).Define(&o , false);
-  StructTypeToDbusWriterMethod(strct, true).Define(&o , false);
-  StructTypeDbusMessageSignatureMethod(preferences_,
-                                       strct, true).Define(&o, false);
   o << endl;
 
   Namespace& val_ns = module_manager_->SourceForValidator().types_ns();
@@ -111,16 +116,20 @@ void DefinitionGenerator::GenerateCodeForResponse(const Response& response) {
     mandatory_constructor.Define(&o, false);
   }
   CppStructDestructor(response.name()).Define(&o, false);
+  if (preferences_->generate_json) {
+    StructTypeFromJsonConstructor(&response).Define(&o , false);
+    StructTypeToJsonMethod(&response).Define(&o , false);
+  }
+  if (preferences_->generate_dbus) {
+    StructTypeFromDbusReaderConstructor(preferences_,
+                                        &response, false).Define(&o , false);
+    StructTypeToDbusWriterMethod(&response, false).Define(&o , false);
+    StructTypeDbusMessageSignatureMethod(preferences_,
+                                         &response, false).Define(&o, false);
+  }
+  MessageHandleWithMethod(response.name()).Define(&o, false);
   StructTypeIsValidMethod(&response).Define(&o, false);
   StructTypeIsInitializedMethod(&response).Define(&o, false);
-  StructTypeFromJsonConstructor(&response).Define(&o , false);
-  StructTypeFromDbusReaderConstructor(preferences_,
-                                      &response, false).Define(&o , false);
-  StructTypeToJsonMethod(&response).Define(&o , false);
-  StructTypeToDbusWriterMethod(&response, false).Define(&o , false);
-  StructTypeDbusMessageSignatureMethod(preferences_,
-                                       &response, false).Define(&o, false);
-  MessageHandleWithMethod(response.name()).Define(&o, false);
   o << endl;
 
   Namespace& val_ns = module_manager_->SourceForValidator().responses_ns();
@@ -138,16 +147,20 @@ void DefinitionGenerator::GenerateCodeForNotification(
     mandatory_constructor.Define(&o, false);
   }
   CppStructDestructor(notification.name()).Define(&o, false);
+  if (preferences_->generate_json) {
+    StructTypeFromJsonConstructor(&notification).Define(&o , false);
+    StructTypeToJsonMethod(&notification).Define(&o , false);
+  }
+  if (preferences_->generate_dbus) {
+    StructTypeFromDbusReaderConstructor(preferences_,
+                                        &notification, false).Define(&o, false);
+    StructTypeToDbusWriterMethod(&notification, false).Define(&o , false);
+    StructTypeDbusMessageSignatureMethod(preferences_,
+                                         &notification, false).Define(&o, false);
+  }
+  MessageHandleWithMethod(notification.name()).Define(&o, false);
   StructTypeIsValidMethod(&notification).Define(&o, false);
   StructTypeIsInitializedMethod(&notification).Define(&o, false);
-  StructTypeFromJsonConstructor(&notification).Define(&o , false);
-  StructTypeFromDbusReaderConstructor(preferences_,
-                                      &notification, false).Define(&o , false);
-  StructTypeToJsonMethod(&notification).Define(&o , false);
-  StructTypeToDbusWriterMethod(&notification, false).Define(&o , false);
-  StructTypeDbusMessageSignatureMethod(preferences_,
-                                       &notification, false).Define(&o, false);
-  MessageHandleWithMethod(notification.name()).Define(&o, false);
   o << endl;
 
   Namespace& val_ns = module_manager_->SourceForValidator().notifications_ns();
@@ -165,15 +178,19 @@ void DefinitionGenerator::GenerateCodeForRequest(const Request& request,
     mandatory_constructor.Define(&o, false);
   }
   CppStructDestructor(request.name()).Define(&o, false);
+  if (preferences_->generate_json) {
+    StructTypeFromJsonConstructor(&request).Define(&o , false);
+    StructTypeToJsonMethod(&request).Define(&o , false);
+  }
+  if (preferences_->generate_dbus) {
+    StructTypeFromDbusReaderConstructor(preferences_,
+                                        &request, false).Define(&o , false);
+    StructTypeToDbusWriterMethod(&request, false).Define(&o , false);
+    StructTypeDbusMessageSignatureMethod(preferences_,
+                                         &request, false).Define(&o, false);
+  }
   StructTypeIsValidMethod(&request).Define(&o, false);
   StructTypeIsInitializedMethod(&request).Define(&o, false);
-  StructTypeFromJsonConstructor(&request).Define(&o , false);
-  StructTypeFromDbusReaderConstructor(preferences_,
-                                      &request, false).Define(&o , false);
-  StructTypeToJsonMethod(&request).Define(&o , false);
-  StructTypeToDbusWriterMethod(&request, false).Define(&o , false);
-  StructTypeDbusMessageSignatureMethod(preferences_,
-                                       &request, false).Define(&o, false);
   MessageHandleWithMethod(request.name()).Define(&o, false);
   o << endl;
 
index c762537..1b663c0 100644 (file)
@@ -44,7 +44,7 @@ using typesafe_format::strmfmt;
 
 namespace codegen {
 
-EnumFromJsonValueFunction::EnumFromJsonValueFunction(
+EnumFromJsonStringFunction::EnumFromJsonStringFunction(
     const Enum* enm)
     : CppFunction("", "EnumFromJsonString", "bool"),
       enm_(enm) {
@@ -52,10 +52,10 @@ EnumFromJsonValueFunction::EnumFromJsonValueFunction(
   Add(Parameter("*result", enm->name()));
 }
 
-EnumFromJsonValueFunction::~EnumFromJsonValueFunction() {
+EnumFromJsonStringFunction::~EnumFromJsonStringFunction() {
 }
 
-void EnumFromJsonValueFunction::DefineBody(std::ostream* os) const {
+void EnumFromJsonStringFunction::DefineBody(std::ostream* os) const {
   const Enum::ConstantsList& consts = enm_->constants();
   if (!consts.empty()) {
     const char* if_statement = "if (\"{0}\" == {1}) {";
index ce7b508..ca5b12e 100644 (file)
@@ -43,15 +43,22 @@ using typesafe_format::format;
 namespace codegen {
 
 TypePreferences::TypePreferences(int minimum_interger_size,
-                                 bool avoid_unsigned)
+                                 bool avoid_unsigned,
+                                 bool generate_json,
+                                 bool generate_dbus)
     : minimum_interger_size(minimum_interger_size),
-      avoid_unsigned(avoid_unsigned) {
+      avoid_unsigned(avoid_unsigned),
+      generate_json(generate_json),
+      generate_dbus(generate_dbus) {
 }
 
 Preferences::Preferences(int minimum_interger_size,
                          bool avoid_unsigned,
+                         bool generate_json,
+                         bool generate_dbus,
                          const std::set<std::string>& requested_interfaces)
-    : type_preferences(minimum_interger_size, avoid_unsigned),
+    : type_preferences(minimum_interger_size, avoid_unsigned,
+                       generate_json, generate_dbus),
       requested_interfaces(requested_interfaces) {
 }
 
index 0d24efc..494e279 100644 (file)
@@ -35,6 +35,8 @@
 #include <errno.h>
 #include <fstream>
 
+#include "cppgen/generator_preferences.h"
+
 #ifdef OS_POSIX
 #include <sys/stat.h>
 #include <sys/types.h>
@@ -64,7 +66,8 @@ bool CreateDirectory(const std::string& name) {
 
 namespace codegen {
 
-ModuleManager::ModuleManager(const std::string& name)
+ModuleManager::ModuleManager(const std::string& name,
+                             const TypePreferences& prefs)
     : module_name_(name),
       enums_header_(module_name_ + "/enums.h", module_name_, true),
       enums_source_(module_name_ + "/enums.cc", module_name_, false),
@@ -85,17 +88,8 @@ ModuleManager::ModuleManager(const std::string& name)
   enums_header_.Include(CppFile::Header("string", false));
   enums_source_.Include(CppFile::Header(enums_header_.file_name(), true));
   structs_source_.Include(CppFile::Header(structs_header_.file_name(), true));
-  structs_source_.Include(
-      CppFile::Header("rpc_base/rpc_base_json_inl.h", true));
-  structs_source_.Include(
-      CppFile::Header("rpc_base/rpc_base_dbus_inl.h", true));
   functions_source_.Include(CppFile::Header(functions_header_.file_name(),
                                             true));
-  functions_source_.Include(
-      CppFile::Header("rpc_base/rpc_base_json_inl.h", true));
-  functions_source_.Include(
-      CppFile::Header("rpc_base/rpc_base_dbus_inl.h", true));
-
   interface_source_.Include((CppFile::Header(interface_header_.file_name(),
                                              true)));
   interface_source_.Include(CppFile::Header(functions_header_.file_name(),
@@ -105,6 +99,18 @@ ModuleManager::ModuleManager(const std::string& name)
       CppFile::Header(structs_header_.file_name(), true));
   additional_validation_source_.Include(
       CppFile::Header(functions_header_.file_name(), true));
+  if (prefs.generate_json) {
+    structs_source_.Include(
+        CppFile::Header("rpc_base/rpc_base_json_inl.h", true));
+    functions_source_.Include(
+        CppFile::Header("rpc_base/rpc_base_json_inl.h", true));
+  }
+  if (prefs.generate_dbus) {
+    structs_source_.Include(
+        CppFile::Header("rpc_base/rpc_base_dbus_inl.h", true));
+    functions_source_.Include(
+        CppFile::Header("rpc_base/rpc_base_dbus_inl.h", true));
+  }
 }
 
 ModuleManager::~ModuleManager() {
index 68c2a10..bad87b1 100644 (file)
@@ -53,6 +53,8 @@ using std::cerr;
 struct Options {
   char* interface_xml;
   bool  auto_generate_function_ids;
+  bool  generate_json_code;
+  bool  generate_dbus_code;
   std::set<std::string> requested_interfaces;
   std::set<std::string> excluded_scopes;
   bool  avoid_unsigned;
@@ -60,6 +62,8 @@ struct Options {
   Options()
       : interface_xml(NULL),
         auto_generate_function_ids(false),
+        generate_json_code(false),
+        generate_dbus_code(false),
         avoid_unsigned(false),
         minimum_word_size(8) {
   }
@@ -78,7 +82,9 @@ void Usage() {
        << "                      generated code. Can occur multiple times.\n"
        << "  -a                  Automatically generates function ID enum.\n"
        << "  -U                  Avoid unsigned integers in generated types\n"
-       << "  -w <word_bits>      Minimal word size (integer size in bits) in generated types\n";
+       << "  -w <word_bits>      Minimal word size (integer size in bits) in generated types\n"
+       << "  -j                  Generate json serialization code\n"
+       << "  -d                  Generate d-bus serialization code\n";
 }
 
 int main(int argc, char* argv[]) {
@@ -87,7 +93,7 @@ int main(int argc, char* argv[]) {
     return EXIT_FAILURE;
   }
   Options options;
-  const char* opts = "aUf:i:s:w:";
+  const char* opts = "ajdUf:i:s:w:";
   for (int opt = getopt(argc, argv, opts); opt != -1;
       opt = getopt(argc, argv, opts)) {
     switch (opt) {
@@ -128,6 +134,14 @@ int main(int argc, char* argv[]) {
         }
         break;
       }
+      case 'j': {
+        options.generate_json_code = true;
+        break;
+      }
+      case 'd': {
+        options.generate_dbus_code = true;
+        break;
+      }
       default: {
         cerr << "Invalid option: '" << opt << "'" << '\n';
         return EXIT_FAILURE;
@@ -150,6 +164,8 @@ int main(int argc, char* argv[]) {
           cpp_code_generator.Generate(
             codegen::Preferences(options.minimum_word_size,
                                  options.avoid_unsigned,
+                                 options.generate_json_code,
+                                 options.generate_dbus_code,
                                  options.requested_interfaces));
       if (bad.empty()) {
         return EXIT_SUCCESS;