# --- Utils
add_subdirectory(./utils)
-# --- Validated types
-add_subdirectory(./rpc_base)
-
# --- SmartObjects
add_subdirectory(./smart_objects)
)
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)
const char *name);
} // namespace dbus
-#include "rpc_base/dbus_message_inl.h"
+#include "dbus/dbus_message_inl.h"
#endif // DBUS_DBUS_MESSAGE_H
#ifndef DBUS_MESSAGE_INL_H
#define DBUS_MESSAGE_INL_H
-#include "rpc_base/dbus_message.h"
+#include "dbus/dbus_message.h"
namespace dbus {
// MessageReader
* POSSIBILITY OF SUCH DAMAGE.
*/
-#include "rpc_base/dbus_message.h"
+#include "dbus/dbus_message.h"
#include <algorithm>
#include <cassert>
+++ /dev/null
-# 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)
#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 {
+++ /dev/null
-/**
- * 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
+++ /dev/null
-/**
- * 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
add_subdirectory(./policies)
# -- rpc_base
-# add_subdirectory(./rpc_base)
+add_subdirectory(./rpc_base)
# --- DBus
IF (${QT_HMI})
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}")
#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;
}
}
+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
#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;
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
-#add_subdirectory(intergen)
+add_subdirectory(intergen)
-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
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}
)
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}")
--- /dev/null
+#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
#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;
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
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
# |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})
${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
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)
private:
// Fields
const Interface* interface_;
+ const TypePreferences* preferences_;
ModuleManager* module_manager_;
DeclarationGenerator declaration_generator_;
DefinitionGenerator definition_generator_;
* 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_;
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;
namespace codegen {
class Namespace;
+class TypePreferences;
/*
* Manages all the source files generated for given interface.
*/
class ModuleManager {
public:
- ModuleManager(const std::string& name);
+ ModuleManager(const std::string& name, const TypePreferences& prefs);
~ModuleManager();
/*
bool CppApiCodeGenerator::GenerateInterface(const Interface* interface,
const TypePreferences& preferences) {
- ModuleManager mgr(LowercaseIntefaceName(*interface));
+ ModuleManager mgr(LowercaseIntefaceName(*interface), preferences);
CppInterfaceCodeGenerator interface_generator(interface,
&preferences,
&mgr);
#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"
const TypePreferences* preferences,
ModuleManager* module_manager)
: interface_(interface),
+ preferences_(preferences),
module_manager_(module_manager),
declaration_generator_(preferences, module_manager_),
definition_generator_(preferences, module_manager_) {
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
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,
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()));
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);
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",
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);
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",
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);
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",
Section pub("public", &o);
StructTypeDefaultConstructor(¬ification).Declare(&o, true);
StructTypeMandatoryConstructor mandatory_constructor(preferences_, ¬ification);
- StructTypeFromJsonConstructor(¬ification).Declare(&o , true);
- StructTypeFromDbusReaderConstructor(preferences_,
- ¬ification, 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(¬ification).Declare(&o , true);
+ StructTypeToJsonMethod(¬ification).Declare(&o , true);
+ }
+ if (preferences_->generate_dbus) {
+ StructTypeFromDbusReaderConstructor(preferences_,
+ ¬ification, false).Declare(&o , true);
+ StructTypeToDbusWriterMethod(¬ification, false).Declare(&o , true);
+ StructTypeDbusMessageSignatureMethod(preferences_,
+ ¬ification, false).Declare(&o, true);
+ }
StructTypeIsValidMethod(¬ification).Declare(&o, true);
StructTypeIsInitializedMethod(¬ification).Declare(&o, true);
- StructTypeToJsonMethod(¬ification).Declare(&o , true);
- StructTypeToDbusWriterMethod(¬ification, false).Declare(&o , true);
- StructTypeDbusMessageSignatureMethod(preferences_,
- ¬ification, false).Declare(&o, true);
MessageHandleWithMethod(notification.name()).Declare(&o, true);
FunctionIdMethod(¬ification).Define(&o, true);
FunctionStringIdMethod(¬ification).Define(&o, true);
#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"
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;
}
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();
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();
mandatory_constructor.Define(&o, false);
}
CppStructDestructor(notification.name()).Define(&o, false);
+ if (preferences_->generate_json) {
+ StructTypeFromJsonConstructor(¬ification).Define(&o , false);
+ StructTypeToJsonMethod(¬ification).Define(&o , false);
+ }
+ if (preferences_->generate_dbus) {
+ StructTypeFromDbusReaderConstructor(preferences_,
+ ¬ification, false).Define(&o, false);
+ StructTypeToDbusWriterMethod(¬ification, false).Define(&o , false);
+ StructTypeDbusMessageSignatureMethod(preferences_,
+ ¬ification, false).Define(&o, false);
+ }
+ MessageHandleWithMethod(notification.name()).Define(&o, false);
StructTypeIsValidMethod(¬ification).Define(&o, false);
StructTypeIsInitializedMethod(¬ification).Define(&o, false);
- StructTypeFromJsonConstructor(¬ification).Define(&o , false);
- StructTypeFromDbusReaderConstructor(preferences_,
- ¬ification, false).Define(&o , false);
- StructTypeToJsonMethod(¬ification).Define(&o , false);
- StructTypeToDbusWriterMethod(¬ification, false).Define(&o , false);
- StructTypeDbusMessageSignatureMethod(preferences_,
- ¬ification, false).Define(&o, false);
- MessageHandleWithMethod(notification.name()).Define(&o, false);
o << endl;
Namespace& val_ns = module_manager_->SourceForValidator().notifications_ns();
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;
namespace codegen {
-EnumFromJsonValueFunction::EnumFromJsonValueFunction(
+EnumFromJsonStringFunction::EnumFromJsonStringFunction(
const Enum* enm)
: CppFunction("", "EnumFromJsonString", "bool"),
enm_(enm) {
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}) {";
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) {
}
#include <errno.h>
#include <fstream>
+#include "cppgen/generator_preferences.h"
+
#ifdef OS_POSIX
#include <sys/stat.h>
#include <sys/types.h>
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),
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(),
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() {
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;
Options()
: interface_xml(NULL),
auto_generate_function_ids(false),
+ generate_json_code(false),
+ generate_dbus_code(false),
avoid_unsigned(false),
minimum_word_size(8) {
}
<< " 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[]) {
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) {
}
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;
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;