diff options
54 files changed, 1493 insertions, 1215 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 85c4caab..2181154e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -17,6 +17,7 @@ add_definitions(-DPROJECT_QUALITY="${PROJECT_QUALITY}") set (LIB_SUFFIX "" CACHE STRING "Define suffix of directory name (32/64)" ) set (LIB_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/lib${LIB_SUFFIX}/${CMAKE_LIBRARY_ARCHITECTURE}" CACHE STRING "Directory where lib will install") +set (PLUGIN_INSTALL_PATH "${LIB_INSTALL_DIR}/${PROJECT_NAME}") set (INCLUDE_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/include" CACHE PATH "The directory the headers are installed in") set (DOC_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/share/doc/packages/${PROJECT_NAME}" CACHE PATH "The directory the docs will be installed to") @@ -30,7 +31,7 @@ option(qt_bindings "AMB Qt DBus bindings" OFF) option(opencvlux_plugin "OpenCV Lux plugin" OFF) option(murphy_plugin "murphy policy framework plugin" OFF) option(test_plugin "Test Plugin" ON) -option(bluemonkey_plugin "bluemonkey irc plugin" OFF) +option(bluemonkey_plugin "bluemonkey plugin" OFF) option(gpsnmea_plugin "gps NMEA location plugin" OFF) option(openxc_plugin "OpenXC plugin" OFF) option(bluetooth_plugin "bluetooth plugin" OFF) @@ -152,6 +153,8 @@ SET(CPACK_DEBIAN_PACKAGE_DESCRIPTION ${CPACK_PACKAGE_DESCRIPTION}) INCLUDE(CPack) +configure_file (${CMAKE_CURRENT_SOURCE_DIR}/packaging.in/config.tizen.in ${CMAKE_CURRENT_BINARY_DIR}/packaging.in/config.tizen @ONLY) + add_subdirectory(lib) add_subdirectory(ambd) add_subdirectory(plugins) diff --git a/ambd/CMakeLists.txt b/ambd/CMakeLists.txt index 9ce7c18b..3e5c6a4d 100644 --- a/ambd/CMakeLists.txt +++ b/ambd/CMakeLists.txt @@ -17,6 +17,8 @@ add_executable(ambd ${ambd_sources}) include_directories(${include_dirs} ) target_link_libraries(ambd ${link_libraries} amb) +configure_file (${CMAKE_CURRENT_SOURCE_DIR}/config.in ${CMAKE_CURRENT_BINARY_DIR}/config @ONLY) + install (TARGETS ambd RUNTIME DESTINATION bin) -install (FILES ${CMAKE_CURRENT_SOURCE_DIR}/config DESTINATION /etc/ambd) +install (FILES ${CMAKE_CURRENT_BINARY_DIR}/config DESTINATION /etc/ambd) diff --git a/ambd/config b/ambd/config deleted file mode 100644 index 2cedc779..00000000 --- a/ambd/config +++ /dev/null @@ -1,19 +0,0 @@ -{ - "sources" : [ - { - "name" : "ExampleSouce", - "path" : "/usr/lib/automotive-message-broker/examplesourceplugin.so" - } - ], - "sinks": [ - { - "name" : "ExampleSink", - "path" : "/usr/lib/automotive-message-broker/examplesinkplugin.so" - }, - { - "name" : "DBusSink", - "path" : "/usr/lib/automotive-message-broker/dbussinkplugin.so" - } - ] -} - diff --git a/ambd/config.in b/ambd/config.in new file mode 100644 index 00000000..850ec786 --- /dev/null +++ b/ambd/config.in @@ -0,0 +1,19 @@ +{ + "sources" : [ + { + "name" : "ExampleSouce", + "path" : "@PLUGIN_INSTALL_PATH@/examplesourceplugin.so" + } + ], + "sinks": [ + { + "name" : "ExampleSink", + "path" : "@PLUGIN_INSTALL_PATH@/examplesinkplugin.so" + }, + { + "name" : "DBusSink", + "path" : "@PLUGIN_INSTALL_PATH@/dbussinkplugin.so" + } + ] +} + diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 2fb5f4d1..866fbb02 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -2,5 +2,20 @@ set(amb_examples configwheel databaseconfig databasesource dbusconfig examplecon gpsnmea obdsourceconfig opencvluxconfig opencvdbusconfig qtmainloopconfig websocketsink2 websocketsource2 testsourceconfig) + +configure_file (${CMAKE_CURRENT_SOURCE_DIR}/configwheel.in ${CMAKE_CURRENT_SOURCE_DIR}/configwheel @ONLY) +configure_file (${CMAKE_CURRENT_SOURCE_DIR}/databaseconfig.in ${CMAKE_CURRENT_SOURCE_DIR}/databaseconfig @ONLY) +configure_file (${CMAKE_CURRENT_SOURCE_DIR}/databasesource.in ${CMAKE_CURRENT_SOURCE_DIR}/databasesource @ONLY) +configure_file (${CMAKE_CURRENT_SOURCE_DIR}/dbusconfig.in ${CMAKE_CURRENT_SOURCE_DIR}/dbusconfig @ONLY) +configure_file (${CMAKE_CURRENT_SOURCE_DIR}/exampleconfig.in ${CMAKE_CURRENT_SOURCE_DIR}/exampleconfig @ONLY) +configure_file (${CMAKE_CURRENT_SOURCE_DIR}/gpsnmea.in ${CMAKE_CURRENT_SOURCE_DIR}/gpsnmea @ONLY) +configure_file (${CMAKE_CURRENT_SOURCE_DIR}/obdsourceconfig.in ${CMAKE_CURRENT_SOURCE_DIR}/obdsourceconfig @ONLY) +configure_file (${CMAKE_CURRENT_SOURCE_DIR}/opencvluxconfig.in ${CMAKE_CURRENT_SOURCE_DIR}/opencvluxconfig @ONLY) +configure_file (${CMAKE_CURRENT_SOURCE_DIR}/opencvdbusconfig.in ${CMAKE_CURRENT_SOURCE_DIR}/opencvdbusconfig @ONLY) +configure_file (${CMAKE_CURRENT_SOURCE_DIR}/qtmainloopconfig.in ${CMAKE_CURRENT_SOURCE_DIR}/qtmainloopconfig @ONLY) +configure_file (${CMAKE_CURRENT_SOURCE_DIR}/websocketsink2.in ${CMAKE_CURRENT_SOURCE_DIR}/websocketsink2 @ONLY) +configure_file (${CMAKE_CURRENT_SOURCE_DIR}/websocketsource2.in ${CMAKE_CURRENT_SOURCE_DIR}/websocketsource2 @ONLY) +configure_file (${CMAKE_CURRENT_SOURCE_DIR}/testsourceconfig.in ${CMAKE_CURRENT_SOURCE_DIR}/testsourceconfig @ONLY) + install (FILES ${amb_examples} DESTINATION /etc/ambd/examples) diff --git a/examples/configwheel b/examples/configwheel index 752397b7..a2e40117 100644 --- a/examples/configwheel +++ b/examples/configwheel @@ -1,16 +1,16 @@ { - "sources" : [ - { - "name" : "WheelSource", - "path" : "/usr/lib/automotive-message-broker/wheelsourceplugin.so", - "device" : "/dev/input/js0" - } - ], - "sinks": [ - { - "name" : "DBusSink", - "path" : "/usr/lib/automotive-message-broker/dbussinkplugin.so" - } - ] + "sources" : [ + { + "name" : "WheelSource", + "path" : "/usr/lib/i386-linux-gnu/automotive-message-broker/wheelsourceplugin.so", + "device" : "/dev/input/js0" + } + ], + "sinks": [ + { + "name" : "DBusSink", + "path" : "/usr/lib/i386-linux-gnu/automotive-message-broker/dbussinkplugin.so" + } + ] } diff --git a/examples/configwheel.in b/examples/configwheel.in new file mode 100644 index 00000000..ebd9335e --- /dev/null +++ b/examples/configwheel.in @@ -0,0 +1,16 @@ +{ + "sources" : [ + { + "name" : "WheelSource", + "path" : "@PLUGIN_INSTALL_PATH@/wheelsourceplugin.so", + "device" : "/dev/input/js0" + } + ], + "sinks": [ + { + "name" : "DBusSink", + "path" : "@PLUGIN_INSTALL_PATH@/dbussinkplugin.so" + } + ] +} + diff --git a/examples/databaseconfig b/examples/databaseconfig index 45d7c60d..ba4b0ada 100644 --- a/examples/databaseconfig +++ b/examples/databaseconfig @@ -1,28 +1,28 @@ { - "sources" : [ - { - "name" : "ExampleSouce", - "path" : "/usr/lib/automotive-message-broker/examplesourceplugin.so" - } - ], - "sinks": [ - { - "name" : "Database", - "path" : "/usr/lib/automotive-message-broker/databasesinkplugin.so", - "properties" : "{ 'properties' : ['VehicleSpeed','EngineSpeed'] }", - "databaseFile" : "/tmp/storage", - "startOnLoad" : "true", - "bufferLength" : "1", - "frequency" : "1" - }, - { - "name" : "Example Sink", - "path" : "/usr/lib/automotive-message-broker/examplesinkplugin.so" - }, - { - "path" : "/usr/lib/automotive-message-broker/dbussinkplugin.so" - } - - ] + "sources" : [ + { + "name" : "ExampleSouce", + "path" : "/usr/lib/i386-linux-gnu/automotive-message-broker/examplesourceplugin.so" + } + ], + "sinks": [ + { + "name" : "Database", + "path" : "/usr/lib/i386-linux-gnu/automotive-message-broker/databasesinkplugin.so", + "properties" : "{ 'properties' : ['VehicleSpeed','EngineSpeed'] }", + "databaseFile" : "/tmp/storage", + "startOnLoad" : "true", + "bufferLength" : "1", + "frequency" : "1" + }, + { + "name" : "Example Sink", + "path" : "/usr/lib/i386-linux-gnu/automotive-message-broker/examplesinkplugin.so" + }, + { + "path" : "/usr/lib/i386-linux-gnu/automotive-message-broker/dbussinkplugin.so" + } + + ] } diff --git a/examples/databaseconfig.in b/examples/databaseconfig.in new file mode 100644 index 00000000..577c82ee --- /dev/null +++ b/examples/databaseconfig.in @@ -0,0 +1,28 @@ +{ + "sources" : [ + { + "name" : "ExampleSouce", + "path" : "@PLUGIN_INSTALL_PATH@/examplesourceplugin.so" + } + ], + "sinks": [ + { + "name" : "Database", + "path" : "@PLUGIN_INSTALL_PATH@/databasesinkplugin.so", + "properties" : "{ 'properties' : ['VehicleSpeed','EngineSpeed'] }", + "databaseFile" : "/tmp/storage", + "startOnLoad" : "true", + "bufferLength" : "1", + "frequency" : "1" + }, + { + "name" : "Example Sink", + "path" : "@PLUGIN_INSTALL_PATH@/examplesinkplugin.so" + }, + { + "path" : "@PLUGIN_INSTALL_PATH@/dbussinkplugin.so" + } + + ] +} + diff --git a/examples/databasesource b/examples/databasesource index 36934bdd..c24e58f3 100644 --- a/examples/databasesource +++ b/examples/databasesource @@ -1,16 +1,16 @@ { - "sources" : [ - { - "name" : "Database Source", - "path" : "/usr/lib/automotive-message-broker/databasesinkplugin.so", - "playbackOnLoad" : "true", - "databaseFile" : "generated.db" - } - ], - "sinks": [ - { - "path" : "/usr/lib/automotive-message-broker/dbussinkplugin.so" - } - ] + "sources" : [ + { + "name" : "Database Source", + "path" : "/usr/lib/i386-linux-gnu/automotive-message-broker/databasesinkplugin.so", + "playbackOnLoad" : "true", + "databaseFile" : "generated.db" + } + ], + "sinks": [ + { + "path" : "/usr/lib/i386-linux-gnu/automotive-message-broker/dbussinkplugin.so" + } + ] } diff --git a/examples/databasesource.in b/examples/databasesource.in new file mode 100644 index 00000000..ccfa4915 --- /dev/null +++ b/examples/databasesource.in @@ -0,0 +1,16 @@ +{ + "sources" : [ + { + "name" : "Database Source", + "path" : "@PLUGIN_INSTALL_PATH@/databasesinkplugin.so", + "playbackOnLoad" : "true", + "databaseFile" : "generated.db" + } + ], + "sinks": [ + { + "path" : "@PLUGIN_INSTALL_PATH@/dbussinkplugin.so" + } + ] +} + diff --git a/examples/dbusconfig b/examples/dbusconfig index 43a5ff44..c5ca01da 100644 --- a/examples/dbusconfig +++ b/examples/dbusconfig @@ -1,18 +1,18 @@ { - "sources" : [ - { - "name" : "ExampleSouce", - "path" : "/usr/lib/automotive-message-broker/examplesourceplugin.so", - "delay" : "6" - } - ], - "sinks": [ - { - "name" : "DBusSink", - "path" : "/usr/lib/automotive-message-broker/dbussinkplugin.so", - "frequency" : "30" - } + "sources" : [ + { + "name" : "ExampleSouce", + "path" : "/usr/lib/i386-linux-gnu/automotive-message-broker/examplesourceplugin.so", + "delay" : "6" + } + ], + "sinks": [ + { + "name" : "DBusSink", + "path" : "/usr/lib/i386-linux-gnu/automotive-message-broker/dbussinkplugin.so", + "frequency" : "30" + } - ] + ] } diff --git a/examples/dbusconfig.in b/examples/dbusconfig.in new file mode 100644 index 00000000..22ebc564 --- /dev/null +++ b/examples/dbusconfig.in @@ -0,0 +1,18 @@ +{ + "sources" : [ + { + "name" : "ExampleSouce", + "path" : "@PLUGIN_INSTALL_PATH@/examplesourceplugin.so", + "delay" : "6" + } + ], + "sinks": [ + { + "name" : "DBusSink", + "path" : "@PLUGIN_INSTALL_PATH@/dbussinkplugin.so", + "frequency" : "30" + } + + ] +} + diff --git a/examples/exampleconfig b/examples/exampleconfig index 323c64a4..aab38363 100644 --- a/examples/exampleconfig +++ b/examples/exampleconfig @@ -1,16 +1,16 @@ { - "sources" : [ - { - "name" : "ExampleSouce", - "path" : "/usr/lib/automotive-message-broker/examplesourceplugin.so", - "delay" : "1" - } - ], - "sinks": [ - { - "name" : "ExampleSink", - "path" : "/usr/lib/automotive-message-broker/examplesinkplugin.so" - } - ] + "sources" : [ + { + "name" : "ExampleSouce", + "path" : "/usr/lib/i386-linux-gnu/automotive-message-broker/examplesourceplugin.so", + "delay" : "1" + } + ], + "sinks": [ + { + "name" : "ExampleSink", + "path" : "/usr/lib/i386-linux-gnu/automotive-message-broker/examplesinkplugin.so" + } + ] } diff --git a/examples/exampleconfig.in b/examples/exampleconfig.in new file mode 100644 index 00000000..f6c3520a --- /dev/null +++ b/examples/exampleconfig.in @@ -0,0 +1,16 @@ +{ + "sources" : [ + { + "name" : "ExampleSouce", + "path" : "@PLUGIN_INSTALL_PATH@/examplesourceplugin.so", + "delay" : "1" + } + ], + "sinks": [ + { + "name" : "ExampleSink", + "path" : "@PLUGIN_INSTALL_PATH@/examplesinkplugin.so" + } + ] +} + diff --git a/examples/gpsnmea b/examples/gpsnmea index 039199f6..1966dd54 100644 --- a/examples/gpsnmea +++ b/examples/gpsnmea @@ -1,16 +1,16 @@ { - "sources" : [ - { - "name" : "gps nmea plugin", - "path" : "/usr/lib/automotive-message-broker/gpsnmea.so", - "test" : "true", - "device" : "/dev/ttyACM0" - } - ], - "sinks": [ - { - "path" : "/usr/lib/automotive-message-broker/dbussinkplugin.so" - } - ] + "sources" : [ + { + "name" : "gps nmea plugin", + "path" : "/usr/lib/i386-linux-gnu/automotive-message-broker/gpsnmea.so", + "test" : "true", + "device" : "/dev/ttyACM0" + } + ], + "sinks": [ + { + "path" : "/usr/lib/i386-linux-gnu/automotive-message-broker/dbussinkplugin.so" + } + ] } diff --git a/examples/gpsnmea.in b/examples/gpsnmea.in new file mode 100644 index 00000000..95f5602a --- /dev/null +++ b/examples/gpsnmea.in @@ -0,0 +1,16 @@ +{ + "sources" : [ + { + "name" : "gps nmea plugin", + "path" : "@PLUGIN_INSTALL_PATH@/gpsnmea.so", + "test" : "true", + "device" : "/dev/ttyACM0" + } + ], + "sinks": [ + { + "path" : "@PLUGIN_INSTALL_PATH@/dbussinkplugin.so" + } + ] +} + diff --git a/examples/obdsourceconfig b/examples/obdsourceconfig index a76cdc61..f776ab35 100644 --- a/examples/obdsourceconfig +++ b/examples/obdsourceconfig @@ -1,18 +1,18 @@ { - "sources" : [ - { - "name" : "OBD2Source", - "path" : "/usr/lib/automotive-message-broker/obd2sourceplugin.so", - "device" : "/dev/pts/5", - "baud" : "115200", - "bluetoothAdapter" : "" - } - ], - "sinks": [ - { - "name" : "ExampleSink", - "path" : "/usr/lib/automotive-message-broker/examplesinkplugin.so" - } - ] + "sources" : [ + { + "name" : "OBD2Source", + "path" : "/usr/lib/i386-linux-gnu/automotive-message-broker/obd2sourceplugin.so", + "device" : "/dev/pts/5", + "baud" : "115200", + "bluetoothAdapter" : "" + } + ], + "sinks": [ + { + "name" : "ExampleSink", + "path" : "/usr/lib/i386-linux-gnu/automotive-message-broker/examplesinkplugin.so" + } + ] } diff --git a/examples/obdsourceconfig.in b/examples/obdsourceconfig.in new file mode 100644 index 00000000..57f4aa2a --- /dev/null +++ b/examples/obdsourceconfig.in @@ -0,0 +1,18 @@ +{ + "sources" : [ + { + "name" : "OBD2Source", + "path" : "@PLUGIN_INSTALL_PATH@/obd2sourceplugin.so", + "device" : "/dev/pts/5", + "baud" : "115200", + "bluetoothAdapter" : "" + } + ], + "sinks": [ + { + "name" : "ExampleSink", + "path" : "@PLUGIN_INSTALL_PATH@/examplesinkplugin.so" + } + ] +} + diff --git a/examples/opencvdbusconfig b/examples/opencvdbusconfig index 549b0db1..e11b4420 100644 --- a/examples/opencvdbusconfig +++ b/examples/opencvdbusconfig @@ -1,27 +1,27 @@ { - "mainloop" : "/usr/lib/automotive-message-broker/qtmainloopplugin.so", - "sources" : [ - { - "name" : "OpenCV LUX", - "path" : "/usr/lib/automotive-message-broker/opencvluxplugin.so", - "threaded" : "true", - "cuda" : "true", - "fps" : "30", - "pixelLowerBound" : "18", - "pixelUpperBound" : "255", - "device" : "0", - "codec" : "divx", - "logging" : "true", - "logfile" : "/tmp/video.avi" - }, - { - "path" : "/usr/lib/automotive-message-broker/examplesourceplugin.so" - } - ], - "sinks": [ - { - "path" : "/usr/lib/automotive-message-broker/dbussinkplugin.so", - }, - ] + "mainloop" : "/usr/lib/i386-linux-gnu/automotive-message-broker/qtmainloopplugin.so", + "sources" : [ + { + "name" : "OpenCV LUX", + "path" : "/usr/lib/i386-linux-gnu/automotive-message-broker/opencvluxplugin.so", + "threaded" : "true", + "cuda" : "true", + "fps" : "30", + "pixelLowerBound" : "18", + "pixelUpperBound" : "255", + "device" : "0", + "codec" : "divx", + "logging" : "true", + "logfile" : "/tmp/video.avi" + }, + { + "path" : "/usr/lib/i386-linux-gnu/automotive-message-broker/examplesourceplugin.so" + } + ], + "sinks": [ + { + "path" : "/usr/lib/i386-linux-gnu/automotive-message-broker/dbussinkplugin.so", + }, + ] } diff --git a/examples/opencvdbusconfig.in b/examples/opencvdbusconfig.in new file mode 100644 index 00000000..0ee79402 --- /dev/null +++ b/examples/opencvdbusconfig.in @@ -0,0 +1,27 @@ +{ + "mainloop" : "@PLUGIN_INSTALL_PATH@/qtmainloopplugin.so", + "sources" : [ + { + "name" : "OpenCV LUX", + "path" : "@PLUGIN_INSTALL_PATH@/opencvluxplugin.so", + "threaded" : "true", + "cuda" : "true", + "fps" : "30", + "pixelLowerBound" : "18", + "pixelUpperBound" : "255", + "device" : "0", + "codec" : "divx", + "logging" : "true", + "logfile" : "/tmp/video.avi" + }, + { + "path" : "@PLUGIN_INSTALL_PATH@/examplesourceplugin.so" + } + ], + "sinks": [ + { + "path" : "@PLUGIN_INSTALL_PATH@/dbussinkplugin.so", + }, + ] +} + diff --git a/examples/opencvluxconfig b/examples/opencvluxconfig index b348e4ba..ea620717 100644 --- a/examples/opencvluxconfig +++ b/examples/opencvluxconfig @@ -1,24 +1,24 @@ { - "mainloop" : "/usr/lib/automotive-message-broker/qtmainloopplugin.so", - "sources" : [ - { - "name" : "OpenCV Lux plugin", - "path" : "/usr/lib/automotive-message-broker/opencvluxplugin.so", - "threaded" : "true", - "kinect" : "false", - "opencl" : "false", - "cuda" : "true", - "pixelLowerBound" : "0", - "pixelUpperBound" : "255", - "fps" : "30", - "device" : "0" - } - ], - "sinks": [ - { - "name" : "Example sink", - "path" : "/usr/lib/automotive-message-broker/examplesinkplugin.so" - } - ] + "mainloop" : "/usr/lib/i386-linux-gnu/automotive-message-broker/qtmainloopplugin.so", + "sources" : [ + { + "name" : "OpenCV Lux plugin", + "path" : "/usr/lib/i386-linux-gnu/automotive-message-broker/opencvluxplugin.so", + "threaded" : "true", + "kinect" : "false", + "opencl" : "false", + "cuda" : "true", + "pixelLowerBound" : "0", + "pixelUpperBound" : "255", + "fps" : "30", + "device" : "0" + } + ], + "sinks": [ + { + "name" : "Example sink", + "path" : "/usr/lib/i386-linux-gnu/automotive-message-broker/examplesinkplugin.so" + } + ] } diff --git a/examples/opencvluxconfig.in b/examples/opencvluxconfig.in new file mode 100644 index 00000000..b6860614 --- /dev/null +++ b/examples/opencvluxconfig.in @@ -0,0 +1,24 @@ +{ + "mainloop" : "@PLUGIN_INSTALL_PATH@/qtmainloopplugin.so", + "sources" : [ + { + "name" : "OpenCV Lux plugin", + "path" : "@PLUGIN_INSTALL_PATH@/opencvluxplugin.so", + "threaded" : "true", + "kinect" : "false", + "opencl" : "false", + "cuda" : "true", + "pixelLowerBound" : "0", + "pixelUpperBound" : "255", + "fps" : "30", + "device" : "0" + } + ], + "sinks": [ + { + "name" : "Example sink", + "path" : "@PLUGIN_INSTALL_PATH@/examplesinkplugin.so" + } + ] +} + diff --git a/examples/qtmainloopconfig b/examples/qtmainloopconfig index 0318255e..10c252b2 100644 --- a/examples/qtmainloopconfig +++ b/examples/qtmainloopconfig @@ -1,18 +1,18 @@ { - "mainloop" : "/usr/lib/automotive-message-broker/qtmainloopplugin.so", - "sources" : [ - { - "name" : "ExampleSouce", - "path" : "/usr/lib/automotive-message-broker/examplesourceplugin.so" - } - ], - "sinks": [ - { - "name" : "Example sink", - "path" : "/usr/lib/automotive-message-broker/examplesinkplugin.so", - "interface" : "lo", - "port" : "23000" - } - ] + "mainloop" : "/usr/lib/i386-linux-gnu/automotive-message-broker/qtmainloopplugin.so", + "sources" : [ + { + "name" : "ExampleSouce", + "path" : "/usr/lib/i386-linux-gnu/automotive-message-broker/examplesourceplugin.so" + } + ], + "sinks": [ + { + "name" : "Example sink", + "path" : "/usr/lib/i386-linux-gnu/automotive-message-broker/examplesinkplugin.so", + "interface" : "lo", + "port" : "23000" + } + ] } diff --git a/examples/qtmainloopconfig.in b/examples/qtmainloopconfig.in new file mode 100644 index 00000000..99a01542 --- /dev/null +++ b/examples/qtmainloopconfig.in @@ -0,0 +1,18 @@ +{ + "mainloop" : "@PLUGIN_INSTALL_PATH@/qtmainloopplugin.so", + "sources" : [ + { + "name" : "ExampleSouce", + "path" : "@PLUGIN_INSTALL_PATH@/examplesourceplugin.so" + } + ], + "sinks": [ + { + "name" : "Example sink", + "path" : "@PLUGIN_INSTALL_PATH@/examplesinkplugin.so", + "interface" : "lo", + "port" : "23000" + } + ] +} + diff --git a/examples/testsourceconfig b/examples/testsourceconfig index 00289e70..f66b16eb 100644 --- a/examples/testsourceconfig +++ b/examples/testsourceconfig @@ -1,15 +1,15 @@ { - "sources" : [ - { - "name" : "TestPlugin", - "path" : "/usr/lib/automotive-message-broker/testplugin.so" - } - ], - "sinks": [ - { - "name" : "ExampleSink", - "path" : "/usr/lib/automotive-message-broker/examplesinkplugin.so" - } - ] + "sources" : [ + { + "name" : "TestPlugin", + "path" : "/usr/lib/i386-linux-gnu/automotive-message-broker/testplugin.so" + } + ], + "sinks": [ + { + "name" : "ExampleSink", + "path" : "/usr/lib/i386-linux-gnu/automotive-message-broker/examplesinkplugin.so" + } + ] } diff --git a/examples/testsourceconfig.in b/examples/testsourceconfig.in new file mode 100644 index 00000000..01029c0d --- /dev/null +++ b/examples/testsourceconfig.in @@ -0,0 +1,15 @@ +{ + "sources" : [ + { + "name" : "TestPlugin", + "path" : "@PLUGIN_INSTALL_PATH@/testplugin.so" + } + ], + "sinks": [ + { + "name" : "ExampleSink", + "path" : "@PLUGIN_INSTALL_PATH@/examplesinkplugin.so" + } + ] +} + diff --git a/examples/websocketsink2 b/examples/websocketsink2 index 45d4a514..af755faa 100644 --- a/examples/websocketsink2 +++ b/examples/websocketsink2 @@ -1,21 +1,21 @@ { - "sources" : [ - { - "name" : "ExampleSouce", - "path" : "/usr/lib/automotive-message-broker/examplesourceplugin.so", - "delay" : "6" - } - ], - "sinks": [ - { - "name" : "WebSocketSink", - "path" : "/usr/lib/automotive-message-broker/websocketsink.so", - "interface" : "eth1", - "ssl" : "false", - "port" : "23000", - "binaryProtocol" : "false", - "useExtensions" : "true" - } - ] + "sources" : [ + { + "name" : "ExampleSouce", + "path" : "/usr/lib/i386-linux-gnu/automotive-message-broker/examplesourceplugin.so", + "delay" : "6" + } + ], + "sinks": [ + { + "name" : "WebSocketSink", + "path" : "/usr/lib/i386-linux-gnu/automotive-message-broker/websocketsink.so", + "interface" : "eth1", + "ssl" : "false", + "port" : "23000", + "binaryProtocol" : "false", + "useExtensions" : "true" + } + ] } diff --git a/examples/websocketsink2.in b/examples/websocketsink2.in new file mode 100644 index 00000000..8e631781 --- /dev/null +++ b/examples/websocketsink2.in @@ -0,0 +1,21 @@ +{ + "sources" : [ + { + "name" : "ExampleSouce", + "path" : "@PLUGIN_INSTALL_PATH@/examplesourceplugin.so", + "delay" : "6" + } + ], + "sinks": [ + { + "name" : "WebSocketSink", + "path" : "@PLUGIN_INSTALL_PATH@/websocketsink.so", + "interface" : "eth1", + "ssl" : "false", + "port" : "23000", + "binaryProtocol" : "false", + "useExtensions" : "true" + } + ] +} + diff --git a/examples/websocketsource2 b/examples/websocketsource2 index ecb86d87..e102713d 100644 --- a/examples/websocketsource2 +++ b/examples/websocketsource2 @@ -1,20 +1,20 @@ { - "sources" : [ - { - "name" : "WebsocketSource", - "path" : "/usr/lib/automotive-message-broker/websocketsource.so", - "port" : "23000", - "ssl" : "false", - "ip" : "127.0.0.1", - "binaryProtocol" : "false", - "useExtensions" : "true" - } - ], - "sinks": [ - { - "name" : "ExampleSink", - "path" : "/usr/lib/automotive-message-broker/examplesinkplugin.so" - } - ] + "sources" : [ + { + "name" : "WebsocketSource", + "path" : "/usr/lib/i386-linux-gnu/automotive-message-broker/websocketsource.so", + "port" : "23000", + "ssl" : "false", + "ip" : "127.0.0.1", + "binaryProtocol" : "false", + "useExtensions" : "true" + } + ], + "sinks": [ + { + "name" : "ExampleSink", + "path" : "/usr/lib/i386-linux-gnu/automotive-message-broker/examplesinkplugin.so" + } + ] } diff --git a/examples/websocketsource2.in b/examples/websocketsource2.in new file mode 100644 index 00000000..c537fb45 --- /dev/null +++ b/examples/websocketsource2.in @@ -0,0 +1,20 @@ +{ + "sources" : [ + { + "name" : "WebsocketSource", + "path" : "@PLUGIN_INSTALL_PATH@/websocketsource.so", + "port" : "23000", + "ssl" : "false", + "ip" : "127.0.0.1", + "binaryProtocol" : "false", + "useExtensions" : "true" + } + ], + "sinks": [ + { + "name" : "ExampleSink", + "path" : "@PLUGIN_INSTALL_PATH@/examplesinkplugin.so" + } + ] +} + diff --git a/packaging.in/config.tizen b/packaging.in/config.tizen.in index 2bdb5240..56f7f68f 100644 --- a/packaging.in/config.tizen +++ b/packaging.in/config.tizen.in @@ -2,19 +2,19 @@ "sources" : [ { "name" : "Murphy Source", - "path" : "/usr/lib/automotive-message-broker/murphysourceplugin.so", + "path" : "@PLUGIN_INSTALL_PATH@/murphysourceplugin.so", "address" : "unxs:/tmp/murphy/amb" }, { "name" : "VehicleSource", - "path" : "/usr/lib/automotive-message-broker/vehicleplugin.so", + "path" : "@PLUGIN_INSTALL_PATH@/vehicleplugin.so", "configfile" : "/etc/ambd/AMBformat.conf" } ], "sinks": [ { "name" : "DBusSink", - "path" : "/usr/lib/automotive-message-broker/dbussinkplugin.so" + "path" : "@PLUGIN_INSTALL_PATH@/dbussinkplugin.so" } ] } diff --git a/plugins/CMakeLists.txt b/plugins/CMakeLists.txt index d983bf39..f75c5277 100644 --- a/plugins/CMakeLists.txt +++ b/plugins/CMakeLists.txt @@ -16,8 +16,8 @@ add_library(examplesinkplugin MODULE ${examplesinkplugin_sources}) set_target_properties(examplesinkplugin PROPERTIES PREFIX "") target_link_libraries(examplesinkplugin amb -L${CMAKE_CURRENT_BINARY_DIR}/lib ${link_libraries}) -install(TARGETS examplesinkplugin LIBRARY DESTINATION lib${LIB_SUFFIX}/automotive-message-broker) -install(TARGETS examplesourceplugin LIBRARY DESTINATION lib${LIB_SUFFIX}/automotive-message-broker) +install(TARGETS examplesinkplugin LIBRARY DESTINATION ${PLUGIN_INSTALL_PATH}) +install(TARGETS examplesourceplugin LIBRARY DESTINATION ${PLUGIN_INSTALL_PATH}) add_subdirectory(common) diff --git a/plugins/bluetooth/CMakeLists.txt b/plugins/bluetooth/CMakeLists.txt index 27c13a12..f64be285 100644 --- a/plugins/bluetooth/CMakeLists.txt +++ b/plugins/bluetooth/CMakeLists.txt @@ -24,7 +24,7 @@ add_library(bluetoothplugin MODULE ${bluetooth_sources}) set_target_properties(bluetoothplugin PROPERTIES PREFIX "") target_link_libraries(bluetoothplugin amb -L${CMAKE_CURRENT_BINARY_DIR}/lib amb-plugins-common -L${CMAKE_CURRENT_BINARY_DIR}/plugins/common ${link_libraries} ${gio_LIBRARIES} ${QT_LIBRARIES}) -install(TARGETS bluetoothplugin LIBRARY DESTINATION lib/automotive-message-broker) +install(TARGETS bluetoothplugin LIBRARY DESTINATION ${PLUGIN_INSTALL_PATH}) install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/ambbt.conf DESTINATION /etc/dbus-1/system.d ) diff --git a/plugins/cangenplugin/CMakeLists.txt b/plugins/cangenplugin/CMakeLists.txt index 47f136a2..87056a53 100644 --- a/plugins/cangenplugin/CMakeLists.txt +++ b/plugins/cangenplugin/CMakeLists.txt @@ -12,7 +12,7 @@ add_library(cangenplugin MODULE ${cangenplugin_sources} ${cangenplugin_headers}) set_target_properties(cangenplugin PROPERTIES PREFIX "") target_link_libraries(cangenplugin amb amb-plugins-common -L${CMAKE_CURRENT_BINARY_DIR}/plugins/common ${link_libraries} ${websockets_LIBRARIES} -lrt) -install(TARGETS cangenplugin LIBRARY DESTINATION lib/automotive-message-broker) +install(TARGETS cangenplugin LIBRARY DESTINATION ${PLUGIN_INSTALL_PATH}) ############################################################################################################################################ diff --git a/plugins/cangenplugin/cangenplugin.cpp b/plugins/cangenplugin/cangenplugin.cpp index 555d4eec..5ed91b97 100644 --- a/plugins/cangenplugin/cangenplugin.cpp +++ b/plugins/cangenplugin/cangenplugin.cpp @@ -24,6 +24,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA #include <listplusplus.h> #include <logger.h> +#include <ambplugin.h> #include "cangenplugin.h" @@ -35,15 +36,15 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA extern "C" AbstractSource* create(AbstractRoutingEngine* routingengine, std::map<std::string, std::string> config) { #ifndef UNIT_TESTS - DEBUG_CONF("cangenplugin", - CUtil::Logger::file_off|CUtil::Logger::screen_on, - CUtil::Logger::EInfo, CUtil::Logger::EInfo - ); + DEBUG_CONF("cangenplugin", + CUtil::Logger::file_off|CUtil::Logger::screen_on, + CUtil::Logger::EInfo, CUtil::Logger::EInfo + ); #endif - std::unique_ptr< AmbPlugin<CANGenPlugin> > plugin(new AmbPlugin<CANGenPlugin>(routingengine, config)); - plugin->init(); - return plugin.release(); + std::unique_ptr< AmbPlugin<CANGenPlugin> > plugin(new AmbPlugin<CANGenPlugin>(routingengine, config)); + plugin->init(); + return plugin.release(); } //---------------------------------------------------------------------------- @@ -51,8 +52,8 @@ extern "C" AbstractSource* create(AbstractRoutingEngine* routingengine, std::map //---------------------------------------------------------------------------- CANGenPlugin::CANGenPlugin(AbstractRoutingEngine* re, const map<string, string>& config, AbstractSource& parent) : - AmbPluginImpl(re, config, parent), - ws(new WebSockets(*this)) + AmbPluginImpl(re, config, parent), + ws(new WebSockets(*this)) { addPropertySupport(Zone::None,[]() { @@ -62,22 +63,22 @@ CANGenPlugin::CANGenPlugin(AbstractRoutingEngine* re, const map<string, string>& CANGenPlugin::~CANGenPlugin() { - for(auto it = interfaces.begin(); it != interfaces.end(); ++it){ - it->second->stop(); - } + for(auto it = interfaces.begin(); it != interfaces.end(); ++it){ + it->second->stop(); + } } void CANGenPlugin::init() { - routingEngine->subscribeToProperty("MappingTable", &parent); + routingEngine->subscribeToProperty("MappingTable", &source); } void CANGenPlugin::propertyChanged(AbstractPropertyType* value) { - if(!value) - return; - if(!value->name.compare("MappingTable")) { - parseMappingTable(value->toString()); + if(!value) + return; + if(!value->name.compare("MappingTable")) { + parseMappingTable(value->toString()); } } @@ -95,229 +96,229 @@ AsyncPropertyReply *CANGenPlugin::setProperty(const AsyncSetPropertyRequest &req void CANGenPlugin::parseMappingTable(const std::string& table) { - scoped_lock<interprocess_recursive_mutex> lock(mutex); - - std::string json(table); - std::replace(json.begin(), json.end(), '\'', '"');// replace all ' to " - std::unique_ptr<json_object, decltype(&json_object_put)> rootobject(json_tokener_parse(json.c_str()), &json_object_put); - if(!rootobject) - { - LOG_ERROR("Failed to parse json: " << json); - return; - } - - // Success, use json_obj here. - mappingTable.clear(); - json_object *sources = json_object_object_get(rootobject.get(),"sources"); - if(!sources) - return; - array_list* arraySources = json_object_get_array(sources); - if(!arraySources) - return; - for(int i=0; i < array_list_length(arraySources); ++i) - { - json_object *rootsource = static_cast<json_object*>(array_list_get_idx(arraySources,i)); - if(!rootsource) - continue; - json_object* source = json_object_object_get(rootsource, "source"); - if(!source) - continue; - json_object* guid = json_object_object_get(source, "guid"); - const std::string guidstr(guid ? json_object_get_string(guid) : ""); - json_object* signals = json_object_object_get(rootsource, "signals"); - if(!signals) - continue; - array_list* arraySignals = json_object_get_array(signals); - for(int j = 0; j < array_list_length(arraySignals); ++j) - { - json_object *signal = static_cast<json_object*>(array_list_get_idx(arraySignals,j)); - if(!signal) - continue; - mappingTable.addProperty(guidstr, signal); - }// signals array loop - }// sources array loop + scoped_lock<interprocess_recursive_mutex> lock(mutex); + + std::string json(table); + std::replace(json.begin(), json.end(), '\'', '"');// replace all ' to " + std::unique_ptr<json_object, decltype(&json_object_put)> rootobject(json_tokener_parse(json.c_str()), &json_object_put); + if(!rootobject) + { + LOG_ERROR("Failed to parse json: " << json); + return; + } + + // Success, use json_obj here. + mappingTable.clear(); + json_object *sources = json_object_object_get(rootobject.get(),"sources"); + if(!sources) + return; + array_list* arraySources = json_object_get_array(sources); + if(!arraySources) + return; + for(int i=0; i < array_list_length(arraySources); ++i) + { + json_object *rootsource = static_cast<json_object*>(array_list_get_idx(arraySources,i)); + if(!rootsource) + continue; + json_object* source = json_object_object_get(rootsource, "source"); + if(!source) + continue; + json_object* guid = json_object_object_get(source, "guid"); + const std::string guidstr(guid ? json_object_get_string(guid) : ""); + json_object* signals = json_object_object_get(rootsource, "signals"); + if(!signals) + continue; + array_list* arraySignals = json_object_get_array(signals); + for(int j = 0; j < array_list_length(arraySignals); ++j) + { + json_object *signal = static_cast<json_object*>(array_list_get_idx(arraySignals,j)); + if(!signal) + continue; + mappingTable.addProperty(guidstr, signal); + }// signals array loop + }// sources array loop } // from CANObserver void CANGenPlugin::errorOccured(CANObserver::CANError error) { (void) error; - LOG_INFO( "CANPlugin::errorOccured() not implemented "<< std::endl ); + LOG_INFO( "CANPlugin::errorOccured() not implemented "<< std::endl ); } void CANGenPlugin::standardFrameReceived(const can_frame& frame) { (void) frame; - LOG_INFO( "CANPlugin::standardFrameReceived() not implemented "<< std::endl ); + LOG_INFO( "CANPlugin::standardFrameReceived() not implemented "<< std::endl ); } void CANGenPlugin::extendedFrameReceived(const can_frame& frame) { - LOG_INFO("CANPlugin::extendedFrameReceived()"); - printFrame(frame); + LOG_INFO("CANPlugin::extendedFrameReceived()"); + printFrame(frame); } void CANGenPlugin::errorFrameReceived(const can_frame& frame) { - LOG_INFO("CANPlugin::errorFrameReceived()"); - printFrame(frame); + LOG_INFO("CANPlugin::errorFrameReceived()"); + printFrame(frame); } void CANGenPlugin::remoteTransmissionRequest(const can_frame& frame) { (void) frame; - LOG_INFO( "CANPlugin::remoteTransmissionRequest() not implemented "<< std::endl ); + LOG_INFO( "CANPlugin::remoteTransmissionRequest() not implemented "<< std::endl ); } void CANGenPlugin::printFrame(const can_frame& frame) const { - LOG_INFO( "CANPlugin::printFrame can_id: " << std::hex << frame.can_id << std::dec << endl ); - LOG_INFO( "CANPlugin::printFrame can_dlc: " << int(frame.can_dlc) << endl ); + LOG_INFO( "CANPlugin::printFrame can_id: " << std::hex << frame.can_id << std::dec << endl ); + LOG_INFO( "CANPlugin::printFrame can_dlc: " << int(frame.can_dlc) << endl ); - std::stringstream ss; - for(int i=0; i<frame.can_dlc; ++i){ - ss << " " << std::hex << (int)(frame.data[i]); - } - ss << std::dec; + std::stringstream ss; + for(int i=0; i<frame.can_dlc; ++i){ + ss << " " << std::hex << (int)(frame.data[i]); + } + ss << std::dec; - LOG_INFO( "CANPlugin::printFrame can data" << ss.str() << endl ); + LOG_INFO( "CANPlugin::printFrame can data" << ss.str() << endl ); } bool CANGenPlugin::sendValue(const std::string& interface, AbstractPropertyType* value) { - scoped_lock<interprocess_recursive_mutex> lock(mutex); - - if(!value) - return false; - int can_id = mappingTable.getCanId(value->sourceUuid, value->zone, value->name); - if(can_id == 0) - return false; - - can_frame frame; - frame.can_id = can_id; - std::unique_ptr<GVariant, decltype(&g_variant_unref)> v(value->toVariant(), &g_variant_unref); - gsize vs = g_variant_get_size(v.get()); - assert(vs <= sizeof(frame.data));// Has to be <= 8 - frame.can_dlc = vs > sizeof(frame.data) ? sizeof(frame.data) : vs; - memcpy(frame.data, g_variant_get_data(v.get()), frame.can_dlc); - - auto& canBus = interfaces[interface]; - if(!canBus){ - canBus = std::shared_ptr<CANBus>(new CANBus(*static_cast<CANObserver*>(this))); - bool started(canBus->start(interface.c_str())); - if(!started) - return false; - } - return canBus->sendExtendedFrame(frame); + scoped_lock<interprocess_recursive_mutex> lock(mutex); + + if(!value) + return false; + int can_id = mappingTable.getCanId(value->sourceUuid, value->zone, value->name); + if(can_id == 0) + return false; + + can_frame frame; + frame.can_id = can_id; + std::unique_ptr<GVariant, decltype(&g_variant_unref)> v(value->toVariant(), &g_variant_unref); + gsize vs = g_variant_get_size(v.get()); + assert(vs <= sizeof(frame.data));// Has to be <= 8 + frame.can_dlc = vs > sizeof(frame.data) ? sizeof(frame.data) : vs; + memcpy(frame.data, g_variant_get_data(v.get()), frame.can_dlc); + + auto& canBus = interfaces[interface]; + if(!canBus){ + canBus = std::shared_ptr<CANBus>(new CANBus(*static_cast<CANObserver*>(this))); + bool started(canBus->start(interface.c_str())); + if(!started) + return false; + } + return canBus->sendExtendedFrame(frame); } void CANGenPlugin::getValue(libwebsocket* socket, const std::string& property, int zone, const std::string& id) { - AsyncPropertyRequest request; - PropertyList foo = VehicleProperty::capabilities(); + AsyncPropertyRequest request; + PropertyList foo = VehicleProperty::capabilities(); if(contains(foo, property)) - { - request.property = property; - } - else - { - DebugOut(0)<<"websocketsink: Invalid property requested: "<<property; - return; - } - - request.zoneFilter = zone; - request.completed = [socket,id,property](AsyncPropertyReply* reply) - { - DebugOut()<<"Got property: "<<reply->property.c_str()<<endl; - if(!reply->value){ - DebugOut()<<"Property value is null"<<endl; - delete reply; - return; - } - - stringstream s; - s.precision(15); - - s << "{\"type\":\"methodReply\",\"name\":\"get\",\"data\":{"; - s << "\"property\":\"" << property << "\",\"zone\":\"" << reply->value->zone << "\",\"value\":\"" << reply->value->toString() << "\",\"timestamp\":\""<<reply->value->timestamp<<"\","; - s <<"\"sequence\": \""<<reply->value->sequence<<"\"}"; - s << ",\"transactionid\":\"" << id << "\"}"; - - string replystr = s.str(); - //printf("Reply: %s\n",replystr.c_str()); - LOG_MESSAGE("Reply:" << replystr << endl); - - //if(replystr.length() > 4096){ - // WebSockets::Write(socket, replystr.substr(0,4096)); - // WebSockets::Write(socket, replystr.substr(4096, 4096)); - //} - //else WebSockets::Write(socket, replystr); - WebSockets::Write(socket, replystr); - - delete reply; - }; - - routingEngine->getPropertyAsync(request); + { + request.property = property; + } + else + { + DebugOut(0)<<"websocketsink: Invalid property requested: "<<property; + return; + } + + request.zoneFilter = zone; + request.completed = [socket,id,property](AsyncPropertyReply* reply) + { + DebugOut()<<"Got property: "<<reply->property.c_str()<<endl; + if(!reply->value){ + DebugOut()<<"Property value is null"<<endl; + delete reply; + return; + } + + stringstream s; + s.precision(15); + + s << "{\"type\":\"methodReply\",\"name\":\"get\",\"data\":{"; + s << "\"property\":\"" << property << "\",\"zone\":\"" << reply->value->zone << "\",\"value\":\"" << reply->value->toString() << "\",\"timestamp\":\""<<reply->value->timestamp<<"\","; + s <<"\"sequence\": \""<<reply->value->sequence<<"\"}"; + s << ",\"transactionid\":\"" << id << "\"}"; + + string replystr = s.str(); + //printf("Reply: %s\n",replystr.c_str()); + LOG_MESSAGE("Reply:" << replystr << endl); + + //if(replystr.length() > 4096){ + // WebSockets::Write(socket, replystr.substr(0,4096)); + // WebSockets::Write(socket, replystr.substr(4096, 4096)); + //} + //else WebSockets::Write(socket, replystr); + WebSockets::Write(socket, replystr); + + delete reply; + }; + + routingEngine->getPropertyAsync(request); } void CANGenPlugin::setValue(libwebsocket* socket, const std::string& property, const std::string& value, int zone, const std::string& interface, const std::string& transactionId) { - LOG_MESSAGE( "CANGenPlugin::setValue called with arguments:" << property << ", " << value << endl); + LOG_MESSAGE( "CANGenPlugin::setValue called with arguments:" << property << ", " << value << endl); - bool sent(false); - std::unique_ptr<AbstractPropertyType> type(VehicleProperty::getPropertyTypeForPropertyNameValue(property,value)); - if(type) { - type->zone = zone; - type->sourceUuid = CANSimPluginUUID; + bool sent(false); + std::unique_ptr<AbstractPropertyType> type(VehicleProperty::getPropertyTypeForPropertyNameValue(property,value)); + if(type) { + type->zone = zone; + type->sourceUuid = CANSimPluginUUID; - sent = sendValue(interface, type.get()); - } + sent = sendValue(interface, type.get()); + } - stringstream ss; - ss << "{\"type\":\"methodReply\",\"name\":\"set\",\"data\":[{\"property\":\"" << property << "\"}],\"transactionid\":\"" << transactionId << "\""; - if(!sent) - ss << ",\"error\":\"method call failed\""; - ss << "}"; + stringstream ss; + ss << "{\"type\":\"methodReply\",\"name\":\"set\",\"data\":[{\"property\":\"" << property << "\"}],\"transactionid\":\"" << transactionId << "\""; + if(!sent) + ss << ",\"error\":\"method call failed\""; + ss << "}"; - string replystr = ss.str(); - LOG_MESSAGE( "Reply:" << replystr << endl); + string replystr = ss.str(); + LOG_MESSAGE( "Reply:" << replystr << endl); - WebSockets::Write(socket, replystr); + WebSockets::Write(socket, replystr); } void CANGenPlugin::dataReceived(libwebsocket* socket, const char* data, size_t len) { - if(!data || len == 0) - return; - - //TODO: refactor ? copied from websocketsink - std::unique_ptr<json_object, decltype(&json_object_put)> rootobject(nullptr, &json_object_put); - std::unique_ptr<json_tokener, decltype(&json_tokener_free)> tokener(json_tokener_new(), &json_tokener_free); - enum json_tokener_error err; - do - { std::unique_ptr<json_object, decltype(&json_object_put)> tmpobject(json_tokener_parse_ex(tokener.get(), data, len), &json_object_put); - rootobject.swap(tmpobject); - } while ((err = json_tokener_get_error(tokener.get())) == json_tokener_continue); - if (err != json_tokener_success) - { - LOG_ERROR("Error: " << json_tokener_error_desc(err) << std::endl); - return; - } - if(!rootobject) - { - LOG_ERROR("Failed to parse json: " << data << std::endl); - return; - } - - if (tokener->char_offset < len) // XXX shouldn't access internal fields - { - // Handle extra characters after parsed object as desired. - // e.g. issue an error, parse another object from that point, etc... - } - // Success, use jobj here. - json_object *typeobject = json_object_object_get(rootobject.get(),"type"); - json_object *nameobject = json_object_object_get(rootobject.get(),"name"); - json_object *transidobject = json_object_object_get(rootobject.get(),"transactionid"); + if(!data || len == 0) + return; + + //TODO: refactor ? copied from websocketsink + std::unique_ptr<json_object, decltype(&json_object_put)> rootobject(nullptr, &json_object_put); + std::unique_ptr<json_tokener, decltype(&json_tokener_free)> tokener(json_tokener_new(), &json_tokener_free); + enum json_tokener_error err; + do + { std::unique_ptr<json_object, decltype(&json_object_put)> tmpobject(json_tokener_parse_ex(tokener.get(), data, len), &json_object_put); + rootobject.swap(tmpobject); + } while ((err = json_tokener_get_error(tokener.get())) == json_tokener_continue); + if (err != json_tokener_success) + { + LOG_ERROR("Error: " << json_tokener_error_desc(err) << std::endl); + return; + } + if(!rootobject) + { + LOG_ERROR("Failed to parse json: " << data << std::endl); + return; + } + + if (tokener->char_offset < len) // XXX shouldn't access internal fields + { + // Handle extra characters after parsed object as desired. + // e.g. issue an error, parse another object from that point, etc... + } + // Success, use jobj here. + json_object *typeobject = json_object_object_get(rootobject.get(),"type"); + json_object *nameobject = json_object_object_get(rootobject.get(),"name"); + json_object *transidobject = json_object_object_get(rootobject.get(),"transactionid"); if(!typeobject || !nameobject || !transidobject) { @@ -325,142 +326,142 @@ void CANGenPlugin::dataReceived(libwebsocket* socket, const char* data, size_t l return; } - string type = string(json_object_get_string(typeobject)); - string name = string(json_object_get_string(nameobject)); - string id; - if (json_object_get_type(transidobject) == json_type_string) - { - id = string(json_object_get_string(transidobject)); - } - else - { - stringstream strstr; - strstr << json_object_get_int(transidobject); - id = strstr.str(); - } - if (type == "method") { - - vector<string> propertyNames; - list< std::tuple<string, string, string, Zone::Type, string> > propertyData; - - json_object *dataobject = json_object_object_get(rootobject.get(),"data"); - if (json_object_get_type(dataobject) == json_type_array) - { - array_list *arraylist = json_object_get_array(dataobject); - for (int i=0;i<array_list_length(arraylist);i++) - { - json_object *arrayobject = (json_object*)array_list_get_idx(arraylist,i); - if (json_object_get_type(arrayobject) == json_type_object) - { - json_object *interfaceobject = json_object_object_get(arrayobject,"interface"); - json_object *propobject = json_object_object_get(arrayobject,"property"); - json_object *valueobject = json_object_object_get(arrayobject,"value"); - json_object *zoneobject = json_object_object_get(arrayobject,"zone"); - json_object *sourceobject = json_object_object_get(arrayobject,"source"); - string interfacestr = string(interfaceobject ? json_object_get_string(interfaceobject) : "vcan0"); - string keystr = string(propobject ? json_object_get_string(propobject) : ""); - string valuestr = string(valueobject ? json_object_get_string(valueobject): ""); - string sourcestr = string(sourceobject ? json_object_get_string(sourceobject): ""); - Zone::Type z(Zone::None); - if(zoneobject){ - try { - z = static_cast<Zone::Type>(boost::lexical_cast<int,std::string>(json_object_get_string(zoneobject))); - } catch (...) { } - } - propertyData.push_back(make_tuple(interfacestr, keystr, valuestr, z, sourcestr)); - } - else if (json_object_get_type(arrayobject) == json_type_string) - { - string propertyName = string(json_object_get_string(arrayobject)); - propertyNames.push_back(propertyName); - } - } - //array_list_free(arraylist); - } - else - { - string path = json_object_get_string(dataobject); - if (path != "") - { - propertyNames.push_back(path); - } - } - if (type == "method") - { - if (name == "get") - { - if (!propertyNames.empty()) - { - //GetProperty is going to be a singleshot sink. - getValue(socket,propertyNames.front(),Zone::None,id); - } - else if (!propertyData.empty()) - { - //GetProperty is going to be a singleshot sink. - auto prop = propertyData.front(); - getValue(socket,std::get<1>(prop),std::get<3>(prop),id); - } - else - { - LOG_WARNING(" \"get\" method called with no data! Transaction ID:" << id); - } - } - else if (name == "set") - { - if (!propertyNames.empty()) - { - //Should not happen - } - else if (!propertyData.empty()) - { - auto prop = propertyData.begin(); - for (auto prop = propertyData.begin(); prop != propertyData.end(); ++prop) - { - LOG_MESSAGE("websocketsinkmanager setting " << std::get<1>(*prop) << " to " << std::get<2>(*prop) << " in zone " << std::get<3>(*prop)); - setValue(socket,std::get<1>(*prop),std::get<2>(*prop),std::get<3>(*prop),std::get<0>(*prop), id); - } - } - } - else if (name == "getSupportedEventTypes") - { - //If data.front() dosen't contain a property name, return a list of properties supported. - //if it does, then return the event types that particular property supports. - string typessupported = ""; - if (propertyNames.empty()) - { - //Send what properties we support - PropertyList foo(routingEngine->supported()); - PropertyList::const_iterator i=foo.cbegin(); - while (i != foo.cend()) - { - if(i==foo.cbegin()) - typessupported.append("\"").append((*i)).append("\""); - else - typessupported.append(",\"").append((*i)).append("\""); - ++i; - } - } - else - { - //Send what events a particular property supports - PropertyList foo(routingEngine->supported()); + string type = string(json_object_get_string(typeobject)); + string name = string(json_object_get_string(nameobject)); + string id; + if (json_object_get_type(transidobject) == json_type_string) + { + id = string(json_object_get_string(transidobject)); + } + else + { + stringstream strstr; + strstr << json_object_get_int(transidobject); + id = strstr.str(); + } + if (type == "method") { + + vector<string> propertyNames; + list< std::tuple<string, string, string, Zone::Type, string> > propertyData; + + json_object *dataobject = json_object_object_get(rootobject.get(),"data"); + if (json_object_get_type(dataobject) == json_type_array) + { + array_list *arraylist = json_object_get_array(dataobject); + for (int i=0;i<array_list_length(arraylist);i++) + { + json_object *arrayobject = (json_object*)array_list_get_idx(arraylist,i); + if (json_object_get_type(arrayobject) == json_type_object) + { + json_object *interfaceobject = json_object_object_get(arrayobject,"interface"); + json_object *propobject = json_object_object_get(arrayobject,"property"); + json_object *valueobject = json_object_object_get(arrayobject,"value"); + json_object *zoneobject = json_object_object_get(arrayobject,"zone"); + json_object *sourceobject = json_object_object_get(arrayobject,"source"); + string interfacestr = string(interfaceobject ? json_object_get_string(interfaceobject) : "vcan0"); + string keystr = string(propobject ? json_object_get_string(propobject) : ""); + string valuestr = string(valueobject ? json_object_get_string(valueobject): ""); + string sourcestr = string(sourceobject ? json_object_get_string(sourceobject): ""); + Zone::Type z(Zone::None); + if(zoneobject){ + try { + z = static_cast<Zone::Type>(boost::lexical_cast<int,std::string>(json_object_get_string(zoneobject))); + } catch (...) { } + } + propertyData.push_back(make_tuple(interfacestr, keystr, valuestr, z, sourcestr)); + } + else if (json_object_get_type(arrayobject) == json_type_string) + { + string propertyName = string(json_object_get_string(arrayobject)); + propertyNames.push_back(propertyName); + } + } + //array_list_free(arraylist); + } + else + { + string path = json_object_get_string(dataobject); + if (path != "") + { + propertyNames.push_back(path); + } + } + if (type == "method") + { + if (name == "get") + { + if (!propertyNames.empty()) + { + //GetProperty is going to be a singleshot sink. + getValue(socket,propertyNames.front(),Zone::None,id); + } + else if (!propertyData.empty()) + { + //GetProperty is going to be a singleshot sink. + auto prop = propertyData.front(); + getValue(socket,std::get<1>(prop),std::get<3>(prop),id); + } + else + { + LOG_WARNING(" \"get\" method called with no data! Transaction ID:" << id); + } + } + else if (name == "set") + { + if (!propertyNames.empty()) + { + //Should not happen + } + else if (!propertyData.empty()) + { + auto prop = propertyData.begin(); + for (auto prop = propertyData.begin(); prop != propertyData.end(); ++prop) + { + LOG_MESSAGE("websocketsinkmanager setting " << std::get<1>(*prop) << " to " << std::get<2>(*prop) << " in zone " << std::get<3>(*prop)); + setValue(socket,std::get<1>(*prop),std::get<2>(*prop),std::get<3>(*prop),std::get<0>(*prop), id); + } + } + } + else if (name == "getSupportedEventTypes") + { + //If data.front() dosen't contain a property name, return a list of properties supported. + //if it does, then return the event types that particular property supports. + string typessupported = ""; + if (propertyNames.empty()) + { + //Send what properties we support + PropertyList foo(routingEngine->supported()); + PropertyList::const_iterator i=foo.cbegin(); + while (i != foo.cend()) + { + if(i==foo.cbegin()) + typessupported.append("\"").append((*i)).append("\""); + else + typessupported.append(",\"").append((*i)).append("\""); + ++i; + } + } + else + { + //Send what events a particular property supports + PropertyList foo(routingEngine->supported()); if (contains(foo,propertyNames.front())) - { - //sinkManager->addSingleShotSink(wsi,data.front(),id); - typessupported = "\"get\",\"getSupportedEventTypes\""; - } - } - stringstream s; - string s2; - s << "{\"type\":\"methodReply\",\"name\":\"getSupportedEventTypes\",\"data\":[" << typessupported << "],\"transactionid\":\"" << id << "\"}"; - string replystr = s.str(); - LOG_INFO(" JSON Reply: " << replystr); - WebSockets::Write(socket, replystr); - } - else - { - DebugOut(0)<<"Unknown method called."<<endl; - } - } - } + { + //sinkManager->addSingleShotSink(wsi,data.front(),id); + typessupported = "\"get\",\"getSupportedEventTypes\""; + } + } + stringstream s; + string s2; + s << "{\"type\":\"methodReply\",\"name\":\"getSupportedEventTypes\",\"data\":[" << typessupported << "],\"transactionid\":\"" << id << "\"}"; + string replystr = s.str(); + LOG_INFO(" JSON Reply: " << replystr); + WebSockets::Write(socket, replystr); + } + else + { + DebugOut(0)<<"Unknown method called."<<endl; + } + } + } } diff --git a/plugins/cansimplugin/CMakeLists.txt b/plugins/cansimplugin/CMakeLists.txt index b827061b..1374c619 100644 --- a/plugins/cansimplugin/CMakeLists.txt +++ b/plugins/cansimplugin/CMakeLists.txt @@ -10,7 +10,7 @@ add_library(cansimplugin MODULE ${cansimplugin_sources} ${cansimplugin_headers}) set_target_properties(cansimplugin PROPERTIES PREFIX "") target_link_libraries(cansimplugin amb amb-plugins-common -L${CMAKE_CURRENT_BINARY_DIR}/plugins/common ${link_libraries} -lrt) -install(TARGETS cansimplugin LIBRARY DESTINATION lib/automotive-message-broker) +install(TARGETS cansimplugin LIBRARY DESTINATION ${PLUGIN_INSTALL_PATH}) ############################################################################################################################################ diff --git a/plugins/cansimplugin/cansimplugin.cpp b/plugins/cansimplugin/cansimplugin.cpp index a45adb12..28aeb0da 100644 --- a/plugins/cansimplugin/cansimplugin.cpp +++ b/plugins/cansimplugin/cansimplugin.cpp @@ -24,6 +24,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA #include <listplusplus.h> #include <logger.h> +#include <ambplugin.h> #include "cansimplugin.h" @@ -37,14 +38,14 @@ static const char* DEFAULT_CAN_IF_NAME = "vcan0"; extern "C" AbstractSource* create(AbstractRoutingEngine* routingengine, std::map<std::string, std::string> config) { #ifndef UNIT_TESTS - DEBUG_CONF("cansimplugin", - CUtil::Logger::file_off|CUtil::Logger::screen_on, - CUtil::Logger::EInfo, CUtil::Logger::EInfo - ); + DEBUG_CONF("cansimplugin", + CUtil::Logger::file_off|CUtil::Logger::screen_on, + CUtil::Logger::EInfo, CUtil::Logger::EInfo + ); #endif - std::unique_ptr< AmbPlugin<CANSimPlugin> > plugin(new AmbPlugin<CANSimPlugin>(routingengine, config)); - plugin->init(); - return plugin.release(); + std::unique_ptr< AmbPlugin<CANSimPlugin> > plugin(new AmbPlugin<CANSimPlugin>(routingengine, config)); + plugin->init(); + return plugin.release(); } //---------------------------------------------------------------------------- @@ -66,79 +67,79 @@ const VehicleProperty::Property AvgKW = "AvgKW"; PROPERTYTYPEBASIC(AvgKW, double) #define ADDPROPERTY(property, default_value, zone_value) \ - addPropertySupport(zone_value, [](){ \ - return new property ## Type(default_value); \ - }) + addPropertySupport(zone_value, [](){ \ + return new property ## Type(default_value); \ + }) CANSimPlugin::CANSimPlugin(AbstractRoutingEngine* re, const map<string, string>& config, AbstractSource& parent) : - AmbPluginImpl(re, config, parent) + AmbPluginImpl(re, config, parent) { - auto it = config.find("interfaces"); - if(it != config.end() && it->second.length()){ - std::unique_ptr<json_object, decltype(&json_object_put)> rootobject(json_tokener_parse(it->second.c_str()), &json_object_put); - if(rootobject){ - g_assert(json_object_get_type(rootobject.get())==json_type_array); - array_list *ifacelist = json_object_get_array(rootobject.get()); - if (ifacelist) { - for(int i=0; i < array_list_length(ifacelist); ++i) - { - json_object* obj = (json_object*)array_list_get_idx(ifacelist,i); - const char* str = obj ? json_object_get_string(obj) : nullptr; - if(str){ - interfaces[str] = std::shared_ptr<CANBus>(new CANBus(*static_cast<CANObserver*>(this))); - } - } - } - } - } - // Default interface if none has been configured. - if(interfaces.empty()){ - interfaces[DEFAULT_CAN_IF_NAME] = std::shared_ptr<CANBus>(new CANBus(*static_cast<CANObserver*>(this))); - } - - addPropertySupport( - Zone::None, - [](){ - StringPropertyType *s = new StringPropertyType(MappingTable, ""); - s->zone = Zone::None; - return s; - } - ); - - // - // IVIPOC signals - // - ADDPROPERTY(VehicleProperty::ChildLockStatus, false, Zone::None); - ADDPROPERTY(VehicleProperty::LightHead, false, Zone::None); - ADDPROPERTY(VehicleProperty::LightParking, false, Zone::None); - ADDPROPERTY(VehicleProperty::AirConditioning, false, Zone::None); - ADDPROPERTY(BatteryStatus, 58, Zone::None); - ADDPROPERTY(FullBatteryRange, 350, Zone::None); - ADDPROPERTY(VehicleProperty::ExteriorTemperature, 74, Zone::None); - ADDPROPERTY(VehicleProperty::InteriorTemperature, 68, Zone::None); - ADDPROPERTY(VehicleProperty::FrontWheelRadius, 0, Zone::None); - ADDPROPERTY(Weather, 1, Zone::None); - ADDPROPERTY(AvgKW, 28, Zone::None); - ADDPROPERTY(VehicleProperty::VehicleSpeed, 65, Zone::None); - ADDPROPERTY(VehicleProperty::Odometer, 75126, Zone::None); - ADDPROPERTY(VehicleProperty::TransmissionShiftPosition, Transmission::Drive, Zone::None); - ADDPROPERTY(VehicleProperty::NightMode, false, Zone::None); - ADDPROPERTY(VehicleProperty::ExteriorBrightness, 1000, Zone::None); - // HVAC - ADDPROPERTY(VehicleProperty::LightHazard, false, Zone::None); - ADDPROPERTY(VehicleProperty::SeatHeater, 0, Zone::FrontLeft); - ADDPROPERTY(VehicleProperty::SeatHeater, 0, Zone::FrontRight); - ADDPROPERTY(VehicleProperty::AirRecirculation, false, Zone::None); - ADDPROPERTY(VehicleProperty::AirflowDirection, HVAC::Front, Zone::None); - ADDPROPERTY(VehicleProperty::FanSpeed, 200, Zone::None); - ADDPROPERTY(VehicleProperty::TargetTemperature, 68, Zone::Left); - ADDPROPERTY(VehicleProperty::TargetTemperature, 68, Zone::Right); - - ADDPROPERTY(VehicleProperty::Defrost, false, Zone::Front); - ADDPROPERTY(VehicleProperty::Defrost, false, Zone::Rear); - - ADDPROPERTY(VehicleProperty::VehiclePowerMode, Power::Run, Zone::None); - // TirePresure + auto it = config.find("interfaces"); + if(it != config.end() && it->second.length()){ + std::unique_ptr<json_object, decltype(&json_object_put)> rootobject(json_tokener_parse(it->second.c_str()), &json_object_put); + if(rootobject){ + g_assert(json_object_get_type(rootobject.get())==json_type_array); + array_list *ifacelist = json_object_get_array(rootobject.get()); + if (ifacelist) { + for(int i=0; i < array_list_length(ifacelist); ++i) + { + json_object* obj = (json_object*)array_list_get_idx(ifacelist,i); + const char* str = obj ? json_object_get_string(obj) : nullptr; + if(str){ + interfaces[str] = std::shared_ptr<CANBus>(new CANBus(*static_cast<CANObserver*>(this))); + } + } + } + } + } + // Default interface if none has been configured. + if(interfaces.empty()){ + interfaces[DEFAULT_CAN_IF_NAME] = std::shared_ptr<CANBus>(new CANBus(*static_cast<CANObserver*>(this))); + } + + addPropertySupport( + Zone::None, + [](){ + StringPropertyType *s = new StringPropertyType(MappingTable, ""); + s->zone = Zone::None; + return s; + } + ); + + // + // IVIPOC signals + // + ADDPROPERTY(VehicleProperty::ChildLockStatus, false, Zone::None); + ADDPROPERTY(VehicleProperty::LightHead, false, Zone::None); + ADDPROPERTY(VehicleProperty::LightParking, false, Zone::None); + ADDPROPERTY(VehicleProperty::AirConditioning, false, Zone::None); + ADDPROPERTY(BatteryStatus, 58, Zone::None); + ADDPROPERTY(FullBatteryRange, 350, Zone::None); + ADDPROPERTY(VehicleProperty::ExteriorTemperature, 74, Zone::None); + ADDPROPERTY(VehicleProperty::InteriorTemperature, 68, Zone::None); + ADDPROPERTY(VehicleProperty::FrontWheelRadius, 0, Zone::None); + ADDPROPERTY(Weather, 1, Zone::None); + ADDPROPERTY(AvgKW, 28, Zone::None); + ADDPROPERTY(VehicleProperty::VehicleSpeed, 65, Zone::None); + ADDPROPERTY(VehicleProperty::Odometer, 75126, Zone::None); + ADDPROPERTY(VehicleProperty::TransmissionShiftPosition, Transmission::Drive, Zone::None); + ADDPROPERTY(VehicleProperty::NightMode, false, Zone::None); + ADDPROPERTY(VehicleProperty::ExteriorBrightness, 1000, Zone::None); + // HVAC + ADDPROPERTY(VehicleProperty::LightHazard, false, Zone::None); + ADDPROPERTY(VehicleProperty::SeatHeater, 0, Zone::FrontLeft); + ADDPROPERTY(VehicleProperty::SeatHeater, 0, Zone::FrontRight); + ADDPROPERTY(VehicleProperty::AirRecirculation, false, Zone::None); + ADDPROPERTY(VehicleProperty::AirflowDirection, HVAC::Front, Zone::None); + ADDPROPERTY(VehicleProperty::FanSpeed, 200, Zone::None); + ADDPROPERTY(VehicleProperty::TargetTemperature, 68, Zone::Left); + ADDPROPERTY(VehicleProperty::TargetTemperature, 68, Zone::Right); + + ADDPROPERTY(VehicleProperty::Defrost, false, Zone::Front); + ADDPROPERTY(VehicleProperty::Defrost, false, Zone::Rear); + + ADDPROPERTY(VehicleProperty::VehiclePowerMode, Power::Run, Zone::None); + // TirePresure ADDPROPERTY(VehicleProperty::TirePressure, 2.3, Zone::FrontLeft); ADDPROPERTY(VehicleProperty::TirePressure, 2.3, Zone::FrontRight); ADDPROPERTY(VehicleProperty::TirePressure, 2.4, Zone::RearLeft); @@ -147,242 +148,242 @@ CANSimPlugin::CANSimPlugin(AbstractRoutingEngine* re, const map<string, string>& CANSimPlugin::~CANSimPlugin() { - for(auto it = interfaces.begin(); it != interfaces.end(); ++it){ - it->second->stop(); - } + for(auto it = interfaces.begin(); it != interfaces.end(); ++it){ + it->second->stop(); + } } void CANSimPlugin::init() { - AmbPluginImpl::init(); - for(auto it = interfaces.begin(); it != interfaces.end(); ++it){ - it->second->start(it->first.c_str()); - } + AmbPluginImpl::init(); + for(auto it = interfaces.begin(); it != interfaces.end(); ++it){ + it->second->start(it->first.c_str()); + } } void CANSimPlugin::supportedChanged(const PropertyList& supportedProperties) { PropertyList s = const_cast<PropertyList&>(supportedProperties); removeOne(&s, MappingTable);// CANSimPlugin has own copy of the PropertyList from AmbPlugin - createMappingTable(supportedProperties); + createMappingTable(supportedProperties); } int CANSimPlugin::supportedOperations() const { - return AbstractSource::Get | AbstractSource::Set; + return AbstractSource::Get | AbstractSource::Set; } void CANSimPlugin::createMappingTable(const PropertyList& /*supported*/) { - // - // Local helper classes - // - class JsonObject : public std::unique_ptr<json_object, decltype(&json_object_put)> - { - public: - JsonObject(json_object* object) : std::unique_ptr<json_object, decltype(&json_object_put)>(object, &json_object_put) {} - }; - - class PROPERTY{ - public: - PROPERTY(const VehicleProperty::Property& propertyName, const Zone::Type& z, int canId) : - name(propertyName), - zone(z), - can_id(canId) - { - } - PROPERTY(const PROPERTY& other) = delete; - PROPERTY& operator=(const PROPERTY& other) = delete; - PROPERTY(PROPERTY&& other) = default; - PROPERTY& operator=(PROPERTY&& other) = default; - JsonObject toJson() - { - JsonObject prop(json_object_new_object()); - json_object_object_add(prop.get(), "can_id", json_object_new_int(can_id)); - json_object_object_add(prop.get(), "name", json_object_new_string(name.c_str())); - json_object_object_add(prop.get(), "zone", json_object_new_int(static_cast<int>(zone))); - return prop; - } - private: - std::string name; - Zone::Type zone; - int can_id; - }; - - // - PropertyList allProperties(VehicleProperty::capabilities()); + // + // Local helper classes + // + class JsonObject : public std::unique_ptr<json_object, decltype(&json_object_put)> + { + public: + JsonObject(json_object* object) : std::unique_ptr<json_object, decltype(&json_object_put)>(object, &json_object_put) {} + }; + + class PROPERTY{ + public: + PROPERTY(const VehicleProperty::Property& propertyName, const Zone::Type& z, int canId) : + name(propertyName), + zone(z), + can_id(canId) + { + } + PROPERTY(const PROPERTY& other) = delete; + PROPERTY& operator=(const PROPERTY& other) = delete; + PROPERTY(PROPERTY&& other) = default; + PROPERTY& operator=(PROPERTY&& other) = default; + JsonObject toJson() + { + JsonObject prop(json_object_new_object()); + json_object_object_add(prop.get(), "can_id", json_object_new_int(can_id)); + json_object_object_add(prop.get(), "name", json_object_new_string(name.c_str())); + json_object_object_add(prop.get(), "zone", json_object_new_int(static_cast<int>(zone))); + return prop; + } + private: + std::string name; + Zone::Type zone; + int can_id; + }; + + // + PropertyList allProperties(VehicleProperty::capabilities()); removeOne(&allProperties, MappingTable); - // - // Create mapping table in JSON format - // - map< std::string, std::deque<PROPERTY> > table; - PropertyList addedProperties; - PropertyList removedProperties; - std::map< canid_t, std::tuple< std::string, VehicleProperty::Property, Zone::Type> > newMappingTable; - int can_id = 10; // Let's have a space for a special messages. Just in case .... in the future. - for(PropertyList::const_iterator propIt = allProperties.begin(); propIt != allProperties.end(); ++propIt) - { - VehicleProperty::Property propertyName(*propIt); - - std::list<std::string> sources(routingEngine->sourcesForProperty(propertyName)); - size_t size = sources.size(); + // + // Create mapping table in JSON format + // + map< std::string, std::deque<PROPERTY> > table; + PropertyList addedProperties; + PropertyList removedProperties; + std::map< canid_t, std::tuple< std::string, VehicleProperty::Property, Zone::Type> > newMappingTable; + int can_id = 10; // Let's have a space for a special messages. Just in case .... in the future. + for(PropertyList::const_iterator propIt = allProperties.begin(); propIt != allProperties.end(); ++propIt) + { + VehicleProperty::Property propertyName(*propIt); + + std::list<std::string> sources(routingEngine->sourcesForProperty(propertyName)); + size_t size = sources.size(); bool IAmTheSource = contains(sources, uuid()); - if(size == 0 || size == 1 && IAmTheSource) { - if( size == 0 ){ - // I'm the source from now - ZonePropertyType& zonePropType = properties[propertyName]; - std::shared_ptr<AbstractPropertyType> value(VehicleProperty::getPropertyTypeForPropertyNameValue(propertyName)); - if(value){ - value->zone = Zone::None; - zonePropType.insert(make_pair(Zone::None, value)); - addedProperties.push_back(propertyName); - } - else{ - properties.erase(propertyName); - } - } - std::string source(uuid()); - //PropertyInfo info(routingEngine->getPropertyInfo(propertyName,source)); - //Zone::ZoneList zones(info.zones()); - //if(zones.empty()) - Zone::ZoneList zones; - { - for(int i = 0; i< 10; ++i){ - Zone::Type zone(Zone::None); - if(i) - zone = static_cast<Zone::Type>(1 << i); - zones.push_back(zone); - } - zones.push_back(Zone::FrontRight); - zones.push_back(Zone::FrontLeft); - zones.push_back(Zone::MiddleRight); - zones.push_back(Zone::MiddleLeft); - zones.push_back(Zone::RearRight); - zones.push_back(Zone::RearLeft); - } - for( auto z=zones.begin(); z != zones.end(); ++z ){ - table[source].push_back(PROPERTY(propertyName, *z, can_id)); - newMappingTable[can_id++] = make_tuple(source, propertyName, *z); - } - } - else if(IAmTheSource){ - // I'm the source, and there is another source - properties.erase(propertyName);// I don't need to simulate it anymore - removedProperties.push_back(propertyName); - } - } - - if(addedProperties.size() || removedProperties.size()) { - JsonObject sources(json_object_new_array()); - for(auto it = table.begin(); it != table.end(); ++it) { - // one source object: - JsonObject source(json_object_new_object()); - JsonObject description(json_object_new_object()); - json_object_object_add(description.get(), "guid", json_object_new_string(it->first.c_str())); - json_object_object_add(source.get(), "source", description.release()); - // signals: + if(size == 0 || size == 1 && IAmTheSource) { + if( size == 0 ){ + // I'm the source from now + ZonePropertyType& zonePropType = properties[propertyName]; + std::shared_ptr<AbstractPropertyType> value(VehicleProperty::getPropertyTypeForPropertyNameValue(propertyName)); + if(value){ + value->zone = Zone::None; + zonePropType.insert(make_pair(Zone::None, value)); + addedProperties.push_back(propertyName); + } + else{ + properties.erase(propertyName); + } + } + std::string source(uuid()); + //PropertyInfo info(routingEngine->getPropertyInfo(propertyName,source)); + //Zone::ZoneList zones(info.zones()); + //if(zones.empty()) + Zone::ZoneList zones; + { + for(int i = 0; i< 10; ++i){ + Zone::Type zone(Zone::None); + if(i) + zone = static_cast<Zone::Type>(1 << i); + zones.push_back(zone); + } + zones.push_back(Zone::FrontRight); + zones.push_back(Zone::FrontLeft); + zones.push_back(Zone::MiddleRight); + zones.push_back(Zone::MiddleLeft); + zones.push_back(Zone::RearRight); + zones.push_back(Zone::RearLeft); + } + for( auto z=zones.begin(); z != zones.end(); ++z ){ + table[source].push_back(PROPERTY(propertyName, *z, can_id)); + newMappingTable[can_id++] = make_tuple(source, propertyName, *z); + } + } + else if(IAmTheSource){ + // I'm the source, and there is another source + properties.erase(propertyName);// I don't need to simulate it anymore + removedProperties.push_back(propertyName); + } + } + + if(addedProperties.size() || removedProperties.size()) { + JsonObject sources(json_object_new_array()); + for(auto it = table.begin(); it != table.end(); ++it) { + // one source object: + JsonObject source(json_object_new_object()); + JsonObject description(json_object_new_object()); + json_object_object_add(description.get(), "guid", json_object_new_string(it->first.c_str())); + json_object_object_add(source.get(), "source", description.release()); + // signals: JsonObject sigs(json_object_new_array()); - for(auto signalIt = it->second.begin(); signalIt != it->second.end(); ++signalIt) { + for(auto signalIt = it->second.begin(); signalIt != it->second.end(); ++signalIt) { json_object_array_add(sigs.get(), signalIt->toJson().release()); - } - // add signals into source + } + // add signals into source json_object_object_add(source.get(), "signals", sigs.release()); - // add one source into sources array - json_object_array_add(sources.get(), source.release()); - } - // result json: - JsonObject result(json_object_new_object()); - json_object_object_add(result.get(), "sources", sources.release()); - - std::string mappingTableValue(json_object_to_json_string(result.get())); - - std::replace(mappingTableValue.begin(), mappingTableValue.end(), '"', '\'');// replace all " to ' - auto tableProperty = properties[MappingTable][Zone::None]; - if(tableProperty){ - // we have a new MappingTable - mappingTable.swap(newMappingTable); - tableProperty->setValue(mappingTableValue); - routingEngine->updateProperty(tableProperty.get(), uuid()); - } - - routingEngine->updateSupported(addedProperties, removedProperties, &parent); - } + // add one source into sources array + json_object_array_add(sources.get(), source.release()); + } + // result json: + JsonObject result(json_object_new_object()); + json_object_object_add(result.get(), "sources", sources.release()); + + std::string mappingTableValue(json_object_to_json_string(result.get())); + + std::replace(mappingTableValue.begin(), mappingTableValue.end(), '"', '\'');// replace all " to ' + auto tableProperty = properties[MappingTable][Zone::None]; + if(tableProperty){ + // we have a new MappingTable + mappingTable.swap(newMappingTable); + tableProperty->setValue(mappingTableValue); + routingEngine->updateProperty(tableProperty.get(), uuid()); + } + + routingEngine->updateSupported(addedProperties, removedProperties, &source); + } } // from CANObserver void CANSimPlugin::errorOccured(CANObserver::CANError error) { (void) error; - LOG_INFO( "CANSimPlugin::errorOccured() not implemented "<< std::endl ); + LOG_INFO( "CANSimPlugin::errorOccured() not implemented "<< std::endl ); } void CANSimPlugin::standardFrameReceived(const can_frame& frame) { (void) frame; - LOG_INFO( "CANSimPlugin::standardFrameReceived() not implemented "<< std::endl ); + LOG_INFO( "CANSimPlugin::standardFrameReceived() not implemented "<< std::endl ); } void CANSimPlugin::extendedFrameReceived(const can_frame& frame) { - LOG_INFO("CANSimPlugin::extendedFrameReceived()"); - printFrame(frame); - - auto it = mappingTable.find(frame.can_id); - if( it == mappingTable.end()){ - LOG_WARNING("can_id not found"); - return; - } - - std::string source(std::get<0>(it->second)); - VehicleProperty::Property name(std::get<1>(it->second)); - Zone::Type zone(std::get<2>(it->second)); - AbstractPropertyType* value = findPropertyType(name, zone); - if(!value) - return; - - std::unique_ptr<GVariant, decltype(&g_variant_unref)> v(value->toVariant(), &g_variant_unref); - std::unique_ptr<GVariant, decltype(&g_variant_unref)> v_untrusted( - g_variant_new_from_data( g_variant_get_type(v.release()), frame.data, frame.can_dlc, FALSE, nullptr, nullptr), - &g_variant_unref - ); - std::unique_ptr<GVariant, decltype(&g_variant_unref)> v_normal(g_variant_get_normal_form(v_untrusted.release()), &g_variant_unref); - if(g_variant_is_normal_form(v_normal.get())) { - value->fromVariant(v_normal.get()); - routingEngine->updateProperty(value, source); - } - else{ - LOG_ERROR("Can't convert value from CAN to GVariant"); - } + LOG_INFO("CANSimPlugin::extendedFrameReceived()"); + printFrame(frame); + + auto it = mappingTable.find(frame.can_id); + if( it == mappingTable.end()){ + LOG_WARNING("can_id not found"); + return; + } + + std::string source(std::get<0>(it->second)); + VehicleProperty::Property name(std::get<1>(it->second)); + Zone::Type zone(std::get<2>(it->second)); + AbstractPropertyType* value = findPropertyType(name, zone); + if(!value) + return; + + std::unique_ptr<GVariant, decltype(&g_variant_unref)> v(value->toVariant(), &g_variant_unref); + std::unique_ptr<GVariant, decltype(&g_variant_unref)> v_untrusted( + g_variant_new_from_data( g_variant_get_type(v.release()), frame.data, frame.can_dlc, FALSE, nullptr, nullptr), + &g_variant_unref + ); + std::unique_ptr<GVariant, decltype(&g_variant_unref)> v_normal(g_variant_get_normal_form(v_untrusted.release()), &g_variant_unref); + if(g_variant_is_normal_form(v_normal.get())) { + value->fromVariant(v_normal.get()); + routingEngine->updateProperty(value, source); + } + else{ + LOG_ERROR("Can't convert value from CAN to GVariant"); + } } void CANSimPlugin::errorFrameReceived(const can_frame& frame) { - LOG_INFO("CANSimPlugin::errorFrameReceived()"); - printFrame(frame); + LOG_INFO("CANSimPlugin::errorFrameReceived()"); + printFrame(frame); } void CANSimPlugin::remoteTransmissionRequest(const can_frame& frame) { (void) frame; - LOG_INFO( "CANSimPlugin::remoteTransmissionRequest() not implemented "<< std::endl ); + LOG_INFO( "CANSimPlugin::remoteTransmissionRequest() not implemented "<< std::endl ); } void CANSimPlugin::printFrame(const can_frame& frame) const { - LOG_INFO( "CANSimPlugin::printFrame can_id: " << std::hex << frame.can_id << std::dec << endl ); - LOG_INFO( "CANSimPlugin::printFrame can_dlc: " << int(frame.can_dlc) << endl ); + LOG_INFO( "CANSimPlugin::printFrame can_id: " << std::hex << frame.can_id << std::dec << endl ); + LOG_INFO( "CANSimPlugin::printFrame can_dlc: " << int(frame.can_dlc) << endl ); - std::stringstream ss; - for(int i=0; i<frame.can_dlc; ++i){ - ss << " " << std::hex << (int)(frame.data[i]); - } - ss << std::dec; + std::stringstream ss; + for(int i=0; i<frame.can_dlc; ++i){ + ss << " " << std::hex << (int)(frame.data[i]); + } + ss << std::dec; - LOG_INFO( "CANSimPlugin::printFrame can data" << ss.str() << endl ); + LOG_INFO( "CANSimPlugin::printFrame can data" << ss.str() << endl ); } diff --git a/plugins/common/ambplugin.h b/plugins/common/ambplugin.h index bfad5a66..47191280 100644 --- a/plugins/common/ambplugin.h +++ b/plugins/common/ambplugin.h @@ -20,6 +20,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA #define _AMBPLUGIN_H_ #include <abstractsource.h> +#include "ambpluginimpl.h" #include <string> /*! @@ -57,120 +58,120 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * \class AmbPlugin */ -class AmbPluginImpl; +//class AmbPluginImpl; template<class T> class AmbPlugin : public AbstractSource { - /*! - * Compile time check - * \internal - */ - static_assert(std::is_base_of<AmbPluginImpl, T>::value, "AmbPluginImpl has to be a base of T"); + /*! + * Compile time check + * \internal + */ + static_assert(std::is_base_of<AmbPluginImpl, T>::value, "AmbPluginImpl has to be a base of T"); public: - /*! - * \param re AbstractRoutingEngine - * \param config Map of the configuration string values loaded on startup from AMB configuration file - */ - AmbPlugin(AbstractRoutingEngine* re, const std::map<std::string, std::string>& config); + /*! + * \param re AbstractRoutingEngine + * \param config Map of the configuration string values loaded on startup from AMB configuration file + */ + AmbPlugin(AbstractRoutingEngine* re, const std::map<std::string, std::string>& config); virtual ~AmbPlugin() {} - // from AbstractSource: + // from AbstractSource: public: - /*! - * \brief getPropertyAsync is called when a sink requests the value for given property. - * This is only called if the source supports the Get operation. - * \param reply the reply variable. @see AsyncPropertyReply - */ - virtual void getPropertyAsync(AsyncPropertyReply *reply); - - /*! - * \brief getRangePropertyAsync is called when a sink requests a series of values for a given - * property within a specified time or sequencial range. This will only be called if the source - * support the Ranged Operation. - * \param reply is the reply variable. @see AsyncRangePropertyReply - */ - virtual void getRangePropertyAsync(AsyncRangePropertyReply *reply); - - /*! - * \brief setProperty is called when a sink requests to set a value for a given property. - * This is only called if the source supports the Set Operation. - * \param request the requested property to set. - * \return returns a pointer to the new value for the property. - */ - virtual AsyncPropertyReply * setProperty(AsyncSetPropertyRequest request); - - /*! - * \brief subscribeToPropertyChanges is called when a sink requests a subscription. Source plugins - * can keep track of subscriptions and may wish to sleep if there are no subscriptions. - * \param property the property that is being subscribed. - */ - virtual void subscribeToPropertyChanges(VehicleProperty::Property property); - - /*! - * \brief unsubscribeToPropertyChanges is called when a sink requests to unsubscribe from a given property's changes. - * \param property the property to unsubscribe to - */ - virtual void unsubscribeToPropertyChanges(VehicleProperty::Property property); - - /*! - * \brief supported is called by the routingEngine to understand what properties this source supports - * \return returns a list of supported properties. If the the supported properties changed, the source should call AbstractRoutingEngine::setSupported. - */ - virtual PropertyList supported(); - - /*! - * \brief supportedOperations - * \return returns the supported operations. - */ - virtual int supportedOperations(); - - /*! - * \brief getPropertyInfo used to return specific information about a property. - * The source should override this otherwise a PropertyInfo::invalid() will be returned for the property. - * \param property the property to get info for. - * \return a PropertyInfo object. - */ - virtual PropertyInfo getPropertyInfo(VehicleProperty::Property property); - - // from AbstractSink + /*! + * \brief getPropertyAsync is called when a sink requests the value for given property. + * This is only called if the source supports the Get operation. + * \param reply the reply variable. @see AsyncPropertyReply + */ + virtual void getPropertyAsync(AsyncPropertyReply *reply); + + /*! + * \brief getRangePropertyAsync is called when a sink requests a series of values for a given + * property within a specified time or sequencial range. This will only be called if the source + * support the Ranged Operation. + * \param reply is the reply variable. @see AsyncRangePropertyReply + */ + virtual void getRangePropertyAsync(AsyncRangePropertyReply *reply); + + /*! + * \brief setProperty is called when a sink requests to set a value for a given property. + * This is only called if the source supports the Set Operation. + * \param request the requested property to set. + * \return returns a pointer to the new value for the property. + */ + virtual AsyncPropertyReply * setProperty(AsyncSetPropertyRequest request); + + /*! + * \brief subscribeToPropertyChanges is called when a sink requests a subscription. Source plugins + * can keep track of subscriptions and may wish to sleep if there are no subscriptions. + * \param property the property that is being subscribed. + */ + virtual void subscribeToPropertyChanges(VehicleProperty::Property property); + + /*! + * \brief unsubscribeToPropertyChanges is called when a sink requests to unsubscribe from a given property's changes. + * \param property the property to unsubscribe to + */ + virtual void unsubscribeToPropertyChanges(VehicleProperty::Property property); + + /*! + * \brief supported is called by the routingEngine to understand what properties this source supports + * \return returns a list of supported properties. If the the supported properties changed, the source should call AbstractRoutingEngine::setSupported. + */ + virtual PropertyList supported(); + + /*! + * \brief supportedOperations + * \return returns the supported operations. + */ + virtual int supportedOperations(); + + /*! + * \brief getPropertyInfo used to return specific information about a property. + * The source should override this otherwise a PropertyInfo::invalid() will be returned for the property. + * \param property the property to get info for. + * \return a PropertyInfo object. + */ + virtual PropertyInfo getPropertyInfo(VehicleProperty::Property property); + + // from AbstractSink public: - /*! uuid() is a unique identifier - * \return A guid-style unique identifier - */ - virtual const string uuid(); - - /*! propertyChanged is called when a subscribed to property changes. - * \param value value of the property that changed. this is a temporary pointer that will be destroyed. - * Do not destroy it. If you need to store the value use value.anyValue(), value.value<T>() or - * value->copy() to copy. - */ - virtual void propertyChanged(AbstractPropertyType* value); - - /*! supportedChanged() is called when the supported properties changes - * \param supportedProperties the new list of supported properties. - */ + /*! uuid() is a unique identifier + * \return A guid-style unique identifier + */ + virtual const string uuid(); + + /*! propertyChanged is called when a subscribed to property changes. + * \param value value of the property that changed. this is a temporary pointer that will be destroyed. + * Do not destroy it. If you need to store the value use value.anyValue(), value.value<T>() or + * value->copy() to copy. + */ + virtual void propertyChanged(AbstractPropertyType* value); + + /*! supportedChanged() is called when the supported properties changes + * \param supportedProperties the new list of supported properties. + */ virtual void supportedChanged(const PropertyList & supportedProperties); - // AmbPlugin's own methods + // AmbPlugin's own methods public: - /*! - * Second phase of the plugin initialization. - * \fn init - */ - void init(); + /*! + * Second phase of the plugin initialization. + * \fn init + */ + void init(); private: - /** - * \brief AmbPlugin class private implementation - */ - std::unique_ptr<T> d; + /** + * \brief AmbPlugin class private implementation + */ + std::unique_ptr<T> d; }; //---------------------------------------------------------------------------- @@ -183,8 +184,8 @@ private: template<typename T> AmbPlugin<T>::AmbPlugin(AbstractRoutingEngine* re, const std::map<std::string, std::string>& config) : - AbstractSource(re, config), - d(new T(re, config, *this)) + AbstractSource(re, config), + d(new T(re, config, *this)) { } @@ -192,80 +193,80 @@ AmbPlugin<T>::AmbPlugin(AbstractRoutingEngine* re, const std::map<std::string, s template<typename T> void AmbPlugin<T>::getPropertyAsync(AsyncPropertyReply *reply) { - if(d) - d->getPropertyAsync(reply); + if(d) + d->getPropertyAsync(reply); } template<typename T> void AmbPlugin<T>::getRangePropertyAsync(AsyncRangePropertyReply *reply) { - if(d) - d->getRangePropertyAsync(reply); + if(d) + d->getRangePropertyAsync(reply); } template<typename T> AsyncPropertyReply* AmbPlugin<T>::setProperty(AsyncSetPropertyRequest request) { - return d ? d->setProperty(request) : nullptr; + return d ? d->AmbPluginImpl::setProperty(request) : nullptr; } template<typename T> void AmbPlugin<T>::subscribeToPropertyChanges(VehicleProperty::Property property) { - if(d) - d->subscribeToPropertyChanges(property); + if(d) + d->subscribeToPropertyChanges(property); } template<typename T> void AmbPlugin<T>::unsubscribeToPropertyChanges(VehicleProperty::Property property) { - if(d) - return d->unsubscribeToPropertyChanges(property); + if(d) + return d->unsubscribeToPropertyChanges(property); } template<typename T> PropertyList AmbPlugin<T>::supported() { - return d ? d->supported() : PropertyList(); + return d ? d->supported() : PropertyList(); } template<typename T> int AmbPlugin<T>::supportedOperations() { - return d ? d->supportedOperations() : 0; + return d ? d->supportedOperations() : 0; } template<typename T> PropertyInfo AmbPlugin<T>::getPropertyInfo(VehicleProperty::Property property) { - return d ? d->getPropertyInfo(property) : PropertyInfo::invalid(); + return d ? d->getPropertyInfo(property) : PropertyInfo::invalid(); } template<typename T> const string AmbPlugin<T>::uuid() { - return d ? d->uuid() : ""; + return d ? d->uuid() : ""; } template<typename T> void AmbPlugin<T>::propertyChanged(AbstractPropertyType* value) { - if(d) - d->propertyChanged(value); + if(d) + d->propertyChanged(value); } template<typename T> void AmbPlugin<T>::supportedChanged(const PropertyList &supportedProperties) { - if(d) - d->supportedChanged(supportedProperties); + if(d) + d->supportedChanged(supportedProperties); } template<typename T> void AmbPlugin<T>::init() { - if(d) - d->init(); + if(d) + d->init(); } #endif // _AMBPLUGIN_H_ diff --git a/plugins/common/ambpluginimpl.cpp b/plugins/common/ambpluginimpl.cpp index 39950115..c956dd34 100644 --- a/plugins/common/ambpluginimpl.cpp +++ b/plugins/common/ambpluginimpl.cpp @@ -26,8 +26,9 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA //---------------------------------------------------------------------------- AmbPluginImpl::AmbPluginImpl(AbstractRoutingEngine* re, const map<string, string>& config, AbstractSource& parent) : - parent(parent), - routingEngine(re) + source(parent), + routingEngine(re), + configuration(config) { } @@ -37,83 +38,83 @@ void AmbPluginImpl::init() void AmbPluginImpl::getPropertyAsync(AsyncPropertyReply *reply) { - if(!reply) { - DebugOut(DebugOut::Error) << "AmbPluginImpl::getPropertyAsync - reply is null" << std::endl; - return; - } - - DebugOut() << "AmbPluginImpl::getPropertyAsync called for property: " << reply->property<<endl; - - reply->success = false; - reply->error = AsyncPropertyReply::InvalidOperation; - AbstractPropertyType *value = findPropertyType(reply->property, reply->zoneFilter); - if (value) { - reply->value = value; - reply->success = true; - reply->error = AsyncPropertyReply::NoError; - } - - if(reply->completed) - reply->completed(reply); + if(!reply) { + DebugOut(DebugOut::Error) << "AmbPluginImpl::getPropertyAsync - reply is null" << std::endl; + return; + } + + DebugOut() << "AmbPluginImpl::getPropertyAsync called for property: " << reply->property << endl; + + reply->success = false; + reply->error = AsyncPropertyReply::InvalidOperation; + AbstractPropertyType *value = findPropertyType(reply->property, reply->zoneFilter); + if (value) { + reply->value = value; + reply->success = true; + reply->error = AsyncPropertyReply::NoError; + } + + if(reply->completed) + reply->completed(reply); } void AmbPluginImpl::getRangePropertyAsync(AsyncRangePropertyReply *reply) { - if(!reply) { - DebugOut(DebugOut::Error) << "AmbPluginImpl::getRangePropertyAsync - reply is null" << std::endl; - return; - } - - DebugOut() << "AmbPluginImpl::getRangePropertyAsync not supported "<< std::endl; - reply->success = false; - reply->error = AsyncPropertyReply::InvalidOperation; - if(reply->completed) - reply->completed(reply); + if(!reply) { + DebugOut(DebugOut::Error) << "AmbPluginImpl::getRangePropertyAsync - reply is null" << std::endl; + return; + } + + DebugOut() << "AmbPluginImpl::getRangePropertyAsync not supported "<< std::endl; + reply->success = false; + reply->error = AsyncPropertyReply::InvalidOperation; + if(reply->completed) + reply->completed(reply); } AsyncPropertyReply *AmbPluginImpl::setProperty(const AsyncSetPropertyRequest& request ) { - AsyncPropertyReply* reply = new AsyncPropertyReply(request); - reply->success = false; - reply->error = AsyncPropertyReply::InvalidOperation; - - AbstractPropertyType *value = findPropertyType(request.property, request.zoneFilter); - if (value && request.value) { - DebugOut(2) << "updating property "<< request.property << " to: " << request.value->toString() << endl; - value->fromString(request.value->toString()); - DebugOut(2) << "New value of property "<< request.property << " is: " << value->toString() << endl; - value->timestamp = amb::currentTime(); - routingEngine->updateProperty(value, uuid()); - - reply->success = true; - reply->error = AsyncPropertyReply::NoError; - } - - try { - if(reply->completed) - reply->completed(reply); - } - catch (...) { } - - return reply; + AsyncPropertyReply* reply = new AsyncPropertyReply(request); + reply->success = false; + reply->error = AsyncPropertyReply::InvalidOperation; + + AbstractPropertyType *value = findPropertyType(request.property, request.zoneFilter); + if (value && request.value) { + DebugOut(2) << "updating property "<< request.property << " to: " << request.value->toString() << endl; + value->fromString(request.value->toString()); + DebugOut(2) << "New value of property "<< request.property << " is: " << value->toString() << endl; + value->timestamp = amb::currentTime(); + routingEngine->updateProperty(value, uuid()); + + reply->success = true; + reply->error = AsyncPropertyReply::NoError; + } + + try { + if(reply->completed) + reply->completed(reply); + } + catch (...) { } + + return reply; } void AmbPluginImpl::subscribeToPropertyChanges(const VehicleProperty::Property& property) { - std::list<Zone::Type> zones = getPropertyInfo(property).zones(); - for( auto it=zones.begin(); it!=zones.end(); ++it) { - AbstractPropertyType *value = findPropertyType(property, *it); - if(value) - routingEngine->updateProperty(value, uuid()); - } + std::list<Zone::Type> zones = getPropertyInfo(property).zones(); + for( auto it=zones.begin(); it!=zones.end(); ++it) { + AbstractPropertyType *value = findPropertyType(property, *it); + if(value) + routingEngine->updateProperty(value, uuid()); + } } PropertyList AmbPluginImpl::supported() const { - PropertyList props; - for(auto itPropMap = properties.begin(); itPropMap != properties.end(); ++itPropMap) - props.push_back(itPropMap->first); - return props; + PropertyList props; + for(auto itPropMap = properties.begin(); itPropMap != properties.end(); ++itPropMap) + props.push_back(itPropMap->first); + return props; } int AmbPluginImpl::supportedOperations() const @@ -128,60 +129,56 @@ void AmbPluginImpl::unsubscribeToPropertyChanges(const VehicleProperty::Property // if signal does not exits return nullptr(we do not know its datatype), if zone does not exists, add it AbstractPropertyType* AmbPluginImpl::findPropertyType(const VehicleProperty::Property& propertyName, const Zone::Type& zone) { - auto itPropMap = properties.find(propertyName); - if(itPropMap == properties.end()) - return nullptr; + auto itPropMap = properties.find(propertyName); + if(itPropMap == properties.end()) + return nullptr; - for( auto it = itPropMap->second.begin(); it != itPropMap->second.end(); ++it ) { - if(it->first == zone) - return it->second.get(); - } + for( auto it = itPropMap->second.begin(); it != itPropMap->second.end(); ++it ) { + if(it->first == zone) + return it->second.get(); + } - return nullptr; + return nullptr; } std::shared_ptr<AbstractPropertyType> AmbPluginImpl::addPropertySupport(Zone::Type zone, std::function<AbstractPropertyType* (void)> typeFactory) { - std::shared_ptr<AbstractPropertyType> propertyType(typeFactory()); - if(!propertyType) - return propertyType; + std::shared_ptr<AbstractPropertyType> propertyType(typeFactory()); + if(!propertyType) + return propertyType; - VehicleProperty::Property name(propertyType->name); - PropertyList registeredProperties(VehicleProperty::capabilities()); - bool registeredType(false); + VehicleProperty::Property name(propertyType->name); + PropertyList registeredProperties(VehicleProperty::capabilities()); + bool registeredType(false); if(!contains(registeredProperties,name)) - { - registeredType = VehicleProperty::registerProperty(name, typeFactory); - } - if(!registeredType){ // Property type wasn't registered by us. Is it predefined in AMB API or some other source plug-in has already registered it ??? - PropertyList supportedProperties(routingEngine->supported());// Is this property already supported by any other source plug-in ? - if(contains(supportedProperties,name)) { - return nullptr;// Some other source plug-in supports this property, we can't support it - AMB doesn't support more sources for one property :-) - } - std::shared_ptr<AbstractPropertyType> registeredPropertyType(VehicleProperty::getPropertyTypeForPropertyNameValue(name)); - if(!registeredPropertyType) - return nullptr; - propertyType.swap(registeredPropertyType); - } - propertyType->zone = zone; - propertyType->sourceUuid = uuid(); - ZonePropertyType& zonePropType = properties[name]; - zonePropType.insert( make_pair(zone, propertyType)); - return propertyType; + { + registeredType = VehicleProperty::registerProperty(name, typeFactory); + } + if(!registeredType){ // Property type wasn't registered by us. Is it predefined in AMB API or some other source plug-in has already registered it ??? + std::shared_ptr<AbstractPropertyType> registeredPropertyType(VehicleProperty::getPropertyTypeForPropertyNameValue(name)); + if(!registeredPropertyType) + return nullptr; + propertyType.swap(registeredPropertyType); + } + propertyType->zone = zone; + propertyType->sourceUuid = uuid(); + ZonePropertyType& zonePropType = properties[name]; + zonePropType.insert( make_pair(zone, propertyType)); + return propertyType; } PropertyInfo AmbPluginImpl::getPropertyInfo(const VehicleProperty::Property& property) const { - auto it = properties.find(property); - if(it != properties.end()) { - std::list<Zone::Type> zones; - for(auto itZonePropType = it->second.begin(); itZonePropType != it->second.end(); ++itZonePropType) - zones.push_back(itZonePropType->first); + auto it = properties.find(property); + if(it != properties.end()) { + std::list<Zone::Type> zones; + for(auto itZonePropType = it->second.begin(); itZonePropType != it->second.end(); ++itZonePropType) + zones.push_back(itZonePropType->first); - return PropertyInfo( 0, zones ); - } + return PropertyInfo( 0, zones ); + } - return PropertyInfo::invalid(); + return PropertyInfo::invalid(); } void AmbPluginImpl::propertyChanged(AbstractPropertyType* value) diff --git a/plugins/common/ambpluginimpl.h b/plugins/common/ambpluginimpl.h index e622a068..27c2dcda 100644 --- a/plugins/common/ambpluginimpl.h +++ b/plugins/common/ambpluginimpl.h @@ -19,7 +19,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA #ifndef _AMBPLUGINIMPL_H_ #define _AMBPLUGINIMPL_H_ -#include "ambplugin.h" +#include "abstractsource.h" /*! \addtogroup ivipocbase * @{ @@ -37,141 +37,146 @@ class AmbPluginImpl { public: - /*! - * \param re AbstractRoutingEngine - * \param config Map of the configuration string values loaded on startup from AMB configuration file - * \param parent AmbPlugin instance - */ + /*! + * \param re AbstractRoutingEngine + * \param config Map of the configuration string values loaded on startup from AMB configuration file + * \param parent AmbPlugin instance + */ AmbPluginImpl(AbstractRoutingEngine* re, const map<string, string>& config, AbstractSource &parent); - virtual ~AmbPluginImpl() { } /*LCOV_EXCL_LINE*/ + virtual ~AmbPluginImpl() { } /*LCOV_EXCL_LINE*/ - // aka AbstractSource: + // aka AbstractSource: public: - /*! - * \brief getPropertyAsync is called when a sink requests the value for given property. - * This is only called if the source supports the Get operation. - * \param reply the reply variable. - */ - virtual void getPropertyAsync(AsyncPropertyReply *reply); - - /*! - * \brief getRangePropertyAsync is called when a sink requests a series of values for a given - * property within a specified time or sequencial range. This will only be called if the source - * support the Ranged Operation. - * \param reply is the reply variable. - */ - virtual void getRangePropertyAsync(AsyncRangePropertyReply *reply); - - /*! - * \brief setProperty is called when a sink requests to set a value for a given property. - * This is only called if the source supports the Set Operation. - * \param request the requested property to set. - * \return returns a pointer to the new value for the property. - */ - virtual AsyncPropertyReply *setProperty(const AsyncSetPropertyRequest& request ); - - /*! - * \brief subscribeToPropertyChanges is called when a sink requests a subscription. Source plugins - * can keep track of subscriptions and may wish to sleep if there are no subscriptions. - * \param property the property that is being subscribed. - */ - virtual void subscribeToPropertyChanges(const VehicleProperty::Property& property); - - /*! - * \brief unsubscribeToPropertyChanges is called when a sink requests to unsubscribe from a given property's changes. - * \param property the property to unsubscribe to - */ - virtual void unsubscribeToPropertyChanges(const VehicleProperty::Property& property); - - /*! - * \brief supported is called by the routingEngine to understand what properties this source supports. - * \return returns a list of supported properties. If the the supported properties changed, the source should call AbstractRoutingEngine::setSupported. - */ - virtual PropertyList supported() const; - - /*! - * \brief supportedOperations - * \return returns the supported operations. - */ - virtual int supportedOperations() const; - - /*! - * \brief getPropertyInfo used to return specific information about a property. - * The source should override this otherwise a PropertyInfo::invalid() will be returned for the property - * \param property the property to get info for. - * \return a PropertyInfo object. - */ - virtual PropertyInfo getPropertyInfo(const VehicleProperty::Property& property) const; - - // aka AbstractSink: + /*! + * \brief getPropertyAsync is called when a sink requests the value for given property. + * This is only called if the source supports the Get operation. + * \param reply the reply variable. + */ + virtual void getPropertyAsync(AsyncPropertyReply *reply); + + /*! + * \brief getRangePropertyAsync is called when a sink requests a series of values for a given + * property within a specified time or sequencial range. This will only be called if the source + * support the Ranged Operation. + * \param reply is the reply variable. + */ + virtual void getRangePropertyAsync(AsyncRangePropertyReply *reply); + + /*! + * \brief setProperty is called when a sink requests to set a value for a given property. + * This is only called if the source supports the Set Operation. + * \param request the requested property to set. + * \return returns a pointer to the new value for the property. + */ + virtual AsyncPropertyReply *setProperty(const AsyncSetPropertyRequest& request ); + + /*! + * \brief subscribeToPropertyChanges is called when a sink requests a subscription. Source plugins + * can keep track of subscriptions and may wish to sleep if there are no subscriptions. + * \param property the property that is being subscribed. + */ + virtual void subscribeToPropertyChanges(const VehicleProperty::Property& property); + + /*! + * \brief unsubscribeToPropertyChanges is called when a sink requests to unsubscribe from a given property's changes. + * \param property the property to unsubscribe to + */ + virtual void unsubscribeToPropertyChanges(const VehicleProperty::Property& property); + + /*! + * \brief supported is called by the routingEngine to understand what properties this source supports. + * \return returns a list of supported properties. If the the supported properties changed, the source should call AbstractRoutingEngine::setSupported. + */ + virtual PropertyList supported() const; + + /*! + * \brief supportedOperations + * \return returns the supported operations. + */ + virtual int supportedOperations() const; + + /*! + * \brief getPropertyInfo used to return specific information about a property. + * The source should override this otherwise a PropertyInfo::invalid() will be returned for the property + * \param property the property to get info for. + * \return a PropertyInfo object. + */ + virtual PropertyInfo getPropertyInfo(const VehicleProperty::Property& property) const; + + // aka AbstractSink: public: - /*! uuid() is a unique identifier - * @return a guid-style unique identifier - */ - virtual const std::string uuid() const = 0; - - /*! propertyChanged is called when a subscribed to property changes. - * @param value value of the property that changed. this is a temporary pointer that will be destroyed. - * Do not destroy it. If you need to store the value use value.anyValue(), value.value<T>() or - * value->copy() to copy. - */ - virtual void propertyChanged(AbstractPropertyType* value); - - /*! supportedChanged() is called when the supported properties changes - * \fn supportedChanged - * \param supportedProperties the new list of supported properties. - */ - virtual void supportedChanged(const PropertyList& supportedProperties); - - /*! - * Second phase of the plugin initialization. - * \fn init - */ - virtual void init(); + /*! uuid() is a unique identifier + * @return a guid-style unique identifier + */ + virtual const std::string uuid() const = 0; + + /*! propertyChanged is called when a subscribed to property changes. + * @param value value of the property that changed. this is a temporary pointer that will be destroyed. + * Do not destroy it. If you need to store the value use value.anyValue(), value.value<T>() or + * value->copy() to copy. + */ + virtual void propertyChanged(AbstractPropertyType* value); + + /*! supportedChanged() is called when the supported properties changes + * \fn supportedChanged + * \param supportedProperties the new list of supported properties. + */ + virtual void supportedChanged(const PropertyList& supportedProperties); + + /*! + * Second phase of the plugin initialization. + * \fn init + */ + virtual void init(); protected: - /*! Finds property type in #properties - * \param propertyName Name of the property to be found. - * \param zone Zone of the property to be found. - * \return AbstractPropertyType* if signal exits otherwise nullptr(in this case we do not know its datatype) - */ - virtual AbstractPropertyType* findPropertyType(const VehicleProperty::Property& propertyName, const Zone::Type& zone); - - /*! Registers property in AMB - * \param zone Zone of the property to be registered. - * \param typeFactory Function to be used to create instance of the AbstractPropertyType for registered property - * \return AbstractPropertyType* if signal exits otherwise nullptr(in this case we do not know its datatype) - */ - virtual std::shared_ptr<AbstractPropertyType> addPropertySupport(Zone::Type zone, std::function<AbstractPropertyType* (void)> typeFactory); - - // - // data: - // - - /*! AmbPlugin instance - * \property parent - */ - AbstractSource& parent; - - /*! - * AbstractRoutingEngine instance - * \property routingEngine - */ - AbstractRoutingEngine* routingEngine; - - /*! Helper typedef - * \internal - */ - typedef std::map< Zone::Type, std::shared_ptr<AbstractPropertyType> > ZonePropertyType; - - /*! - * Supported property values map - * \property properties - */ - std::map< VehicleProperty::Property, ZonePropertyType > properties; + /*! Finds property type in #properties + * \param propertyName Name of the property to be found. + * \param zone Zone of the property to be found. + * \return AbstractPropertyType* if signal exits otherwise nullptr(in this case we do not know its datatype) + */ + virtual AbstractPropertyType* findPropertyType(const VehicleProperty::Property& propertyName, const Zone::Type& zone); + + /*! Registers property in AMB + * \param zone Zone of the property to be registered. + * \param typeFactory Function to be used to create instance of the AbstractPropertyType for registered property + * \return AbstractPropertyType* if signal exits otherwise nullptr(in this case we do not know its datatype) + */ + virtual std::shared_ptr<AbstractPropertyType> addPropertySupport(Zone::Type zone, std::function<AbstractPropertyType* (void)> typeFactory); + + // + // data: + // + + /*! AmbPlugin instance + * \property parent + */ + AbstractSource& source; + + /*! + * AbstractRoutingEngine instance + * \property routingEngine + */ + AbstractRoutingEngine* routingEngine; + + /*! Helper typedef + * \internal + */ + typedef std::map< Zone::Type, std::shared_ptr<AbstractPropertyType> > ZonePropertyType; + + /*! + * Supported property values map + * \property properties + */ + std::map< VehicleProperty::Property, ZonePropertyType > properties; + + /*! + * configuration + */ + std::map< std::string, std::string> configuration; }; #endif // _AMBPLUGINIMPL_H_ diff --git a/plugins/database/CMakeLists.txt b/plugins/database/CMakeLists.txt index 882c26e1..3db25adb 100644 --- a/plugins/database/CMakeLists.txt +++ b/plugins/database/CMakeLists.txt @@ -12,6 +12,6 @@ add_library(databasesinkplugin MODULE ${databasesinkplugin_sources}) set_target_properties(databasesinkplugin PROPERTIES PREFIX "") target_link_libraries(databasesinkplugin amb -L${CMAKE_CURRENT_BINARY_DIR}/lib ${link_libraries} ${sqlite_LIBRARIES}) -install(TARGETS databasesinkplugin LIBRARY DESTINATION lib${LIB_SUFFIX}/automotive-message-broker) +install(TARGETS databasesinkplugin LIBRARY DESTINATION ${PLUGIN_INSTALL_PATH}) endif(database_plugin) diff --git a/plugins/dbus/CMakeLists.txt b/plugins/dbus/CMakeLists.txt index bf990197..aab7e90f 100644 --- a/plugins/dbus/CMakeLists.txt +++ b/plugins/dbus/CMakeLists.txt @@ -12,7 +12,7 @@ add_library(dbussinkplugin MODULE ${dbussinkplugin_sources}) set_target_properties(dbussinkplugin PROPERTIES PREFIX "") target_link_libraries(dbussinkplugin amb -L${CMAKE_CURRENT_BINARY_DIR}/lib ${link_libraries} ${gio_LIBRARIES}) -install (TARGETS dbussinkplugin LIBRARY DESTINATION lib${LIB_SUFFIX}/automotive-message-broker) +install (TARGETS dbussinkplugin LIBRARY DESTINATION ${PLUGIN_INSTALL_PATH}) install (FILES ${CMAKE_CURRENT_SOURCE_DIR}/amb.conf DESTINATION /etc/dbus-1/system.d ) add_subdirectory(amb-qt) diff --git a/plugins/demosink/CMakeLists.txt b/plugins/demosink/CMakeLists.txt index 1cc28ba4..8fde5e36 100644 --- a/plugins/demosink/CMakeLists.txt +++ b/plugins/demosink/CMakeLists.txt @@ -13,4 +13,4 @@ add_library(demosinkplugin MODULE ${demosinkplugin_sources}) set_target_properties(demosinkplugin PROPERTIES PREFIX "") target_link_libraries(demosinkplugin amb -L${CMAKE_CURRENT_BINARY_DIR}/lib ${link_libraries}) -install(TARGETS demosinkplugin LIBRARY DESTINATION lib${LIB_SUFFIX}/automotive-message-broker) +install(TARGETS demosinkplugin LIBRARY DESTINATION ${PLUGIN_INSTALL_PATH}) diff --git a/plugins/gpsnmea/CMakeLists.txt b/plugins/gpsnmea/CMakeLists.txt index fddfe883..c59b6082 100644 --- a/plugins/gpsnmea/CMakeLists.txt +++ b/plugins/gpsnmea/CMakeLists.txt @@ -10,6 +10,6 @@ add_executable(gpsnmea.so ${gpsnmea_sources}) set_target_properties(gpsnmea.so PROPERTIES PREFIX "") target_link_libraries(gpsnmea.so amb -L${CMAKE_CURRENT_BINARY_DIR}/lib amb-plugins-common -L${CMAKE_CURRENT_BINARY_DIR}/plugins/common ${link_libraries} ${gio_LIBRARIES}) -install(TARGETS gpsnmea.so RUNTIME DESTINATION lib/automotive-message-broker) +install(TARGETS gpsnmea.so RUNTIME DESTINATION ${PLUGIN_INSTALL_PATH}) endif(gpsnmea_plugin) diff --git a/plugins/murphyplugin/CMakeLists.txt b/plugins/murphyplugin/CMakeLists.txt index fede2909..a484d029 100644 --- a/plugins/murphyplugin/CMakeLists.txt +++ b/plugins/murphyplugin/CMakeLists.txt @@ -10,13 +10,13 @@ pkg_check_modules(MURPHY_COMMON REQUIRED murphy-common) #if(qtmainloop) # pkg_check_modules(MURPHY_QT REQUIRED murphy-qt) - #set(include_dirs ${include_dirs} ${MURPHY_QT_INCLUDE_DIRS}) - #set(murphy_libraries ${murphy_libraries} ${MURPHY_QT_LIBRARIES}) + #set(include_dirs ${include_dirs} ${MURPHY_QT_INCLUDE_DIRS}) + #set(murphy_libraries ${murphy_libraries} ${MURPHY_QT_LIBRARIES}) #else(qtmainloop) pkg_check_modules(MURPHY_GLIB REQUIRED murphy-glib) set(include_dirs ${include_dirs} ${MURPHY_GLIB_INCLUDE_DIRS}) - set(murphy_libraries ${murphy_libraries} ${MURPHY_GLIB_LIBRARIES}) + set(murphy_libraries ${murphy_libraries} ${MURPHY_GLIB_LIBRARIES}) #endif(qtmainloop) @@ -29,6 +29,6 @@ add_library(murphysourceplugin MODULE ${murphysourceplugin_sources}) set_target_properties(murphysourceplugin PROPERTIES PREFIX "") target_link_libraries(murphysourceplugin amb ${MURPHY_COMMON_LIBRARIES} -L${CMAKE_CURRENT_BINARY_DIR}/lib ${link_libraries} ${murphy_libraries}) -install(TARGETS murphysourceplugin LIBRARY DESTINATION lib${LIB_SUFFIX}/automotive-message-broker) +install(TARGETS murphysourceplugin LIBRARY DESTINATION ${PLUGIN_INSTALL_PATH}) endif(murphy_plugin) diff --git a/plugins/obd2plugin/CMakeLists.txt b/plugins/obd2plugin/CMakeLists.txt index c65e73a3..63d89025 100644 --- a/plugins/obd2plugin/CMakeLists.txt +++ b/plugins/obd2plugin/CMakeLists.txt @@ -13,6 +13,6 @@ add_library(obd2sourceplugin MODULE ${obd2sourceplugin_sources}) set_target_properties(obd2sourceplugin PROPERTIES PREFIX "") target_link_libraries(obd2sourceplugin amb -L${CMAKE_CURRENT_BINARY_DIR}/lib amb-plugins-common -L${CMAKE_CURRENT_BINARY_DIR}/plugins/common ${link_libraries} ${gio_LIBRARIES} ${gio-unix_LIBRARIES} ) -install(TARGETS obd2sourceplugin LIBRARY DESTINATION lib${LIB_SUFFIX}/automotive-message-broker) +install(TARGETS obd2sourceplugin LIBRARY DESTINATION ${PLUGIN_INSTALL_PATH}) endif(obd2_plugin) diff --git a/plugins/opencvlux/CMakeLists.txt b/plugins/opencvlux/CMakeLists.txt index 8691e596..e149a733 100644 --- a/plugins/opencvlux/CMakeLists.txt +++ b/plugins/opencvlux/CMakeLists.txt @@ -3,43 +3,43 @@ if(opencvlux_plugin) find_package(OpenCV REQUIRED) if(OpenCV_LIBS) - message(STATUS "opencv found") + message(STATUS "opencv found") else(OpenCV_LIBS) - message(FATAL_ERROR "opencv missing. please install opencv") + message(FATAL_ERROR "opencv missing. please install opencv") endif(OpenCV_LIBS) option(ocl "enable opencl" OFF) if(ocl) - message(STATUS "found opencv ocl headers. enabling opencl support. ${ocl}") - add_definitions(-DOPENCL) + message(STATUS "found opencv ocl headers. enabling opencl support. ${ocl}") + add_definitions(-DOPENCL) else(ocl) - message(STATUS "no opencl support") + message(STATUS "no opencl support") endif(ocl) option(cuda "enable cuda" OFF) if(cuda) - message(STATUS "found opencv cuda headers. enabling cuda support. ${cuda}") - add_definitions(-DCUDA) + message(STATUS "found opencv cuda headers. enabling cuda support. ${cuda}") + add_definitions(-DCUDA) else(cuda) - message(STATUS "no opencv cuda headers found. no cuda support") - remove_definitions(-DCUDA) + message(STATUS "no opencv cuda headers found. no cuda support") + remove_definitions(-DCUDA) endif(cuda) find_package(Qt5Core REQUIRED) if(Qt5Core_FOUND) - message(STATUS "using Qt5") + message(STATUS "using Qt5") - set(QT_INCLUDE_DIRS ${Qt5Core_INCLUDE_DIRS} ) - set(QT_LIBRARIES ${Qt5Core_LIBRARIES} ) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${Qt5Core_EXECUTABLE_COMPILE_FLAGS}") - message(STATUS "size of void_p: ${CMAKE_SIZEOF_VOID_P}") - #if(CMAKE_SIZEOF_VOID_P MATCHES "8") - # set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mcmodel=large") - #endif(CMAKE_SIZEOF_VOID_P MATCHES "8") - add_definitions(${Qt5Core_DEFINITIONS}) + set(QT_INCLUDE_DIRS ${Qt5Core_INCLUDE_DIRS} ) + set(QT_LIBRARIES ${Qt5Core_LIBRARIES} ) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${Qt5Core_EXECUTABLE_COMPILE_FLAGS}") + message(STATUS "size of void_p: ${CMAKE_SIZEOF_VOID_P}") + #if(CMAKE_SIZEOF_VOID_P MATCHES "8") + # set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mcmodel=large") + #endif(CMAKE_SIZEOF_VOID_P MATCHES "8") + add_definitions(${Qt5Core_DEFINITIONS}) endif(Qt5Core_FOUND) set(CMAKE_AUTOMOC ON) @@ -53,6 +53,6 @@ add_library(opencvluxplugin MODULE ${opencvluxplugin_sources}) set_target_properties(opencvluxplugin PROPERTIES PREFIX "") target_link_libraries(opencvluxplugin amb -L${CMAKE_CURRENT_BINARY_DIR}/lib ${link_libraries} ${OpenCV_LIBS} ${Boost_LIBRARIES} ${QT_LIBRARIES}) -install(TARGETS opencvluxplugin LIBRARY DESTINATION lib${LIB_SUFFIX}/automotive-message-broker) +install(TARGETS opencvluxplugin LIBRARY DESTINATION ${PLUGIN_INSTALL_PATH}) endif(opencvlux_plugin) diff --git a/plugins/openxc/CMakeLists.txt b/plugins/openxc/CMakeLists.txt index 12bef215..5c4cc1e0 100644 --- a/plugins/openxc/CMakeLists.txt +++ b/plugins/openxc/CMakeLists.txt @@ -14,6 +14,6 @@ add_library(openxcplugin MODULE ${openxcplugin_sources}) set_target_properties(openxcplugin PROPERTIES PREFIX "") target_link_libraries(openxcplugin amb -L${CMAKE_CURRENT_BINARY_DIR}/lib amb-plugins-common -L${CMAKE_CURRENT_BINARY_DIR}/plugins/common ${link_libraries} ${json_LIBRARIES}) -install(TARGETS openxcplugin LIBRARY DESTINATION lib/automotive-message-broker) +install(TARGETS openxcplugin LIBRARY DESTINATION ${PLUGIN_INSTALL_PATH}) endif(openxc_plugin) diff --git a/plugins/testplugin/CMakeLists.txt b/plugins/testplugin/CMakeLists.txt index 144f3afc..e2750dbf 100644 --- a/plugins/testplugin/CMakeLists.txt +++ b/plugins/testplugin/CMakeLists.txt @@ -11,6 +11,6 @@ add_library(testplugin MODULE ${testplugin_sources}) set_target_properties(testplugin PROPERTIES PREFIX "") target_link_libraries(testplugin amb -L${CMAKE_CURRENT_BINARY_DIR}/lib ${link_libraries}) -install(TARGETS testplugin LIBRARY DESTINATION lib${LIB_SUFFIX}/automotive-message-broker) +install(TARGETS testplugin LIBRARY DESTINATION ${PLUGIN_INSTALL_PATH}) endif(test_plugin) diff --git a/plugins/websocket/CMakeLists.txt b/plugins/websocket/CMakeLists.txt index d5190b57..d594cad3 100644 --- a/plugins/websocket/CMakeLists.txt +++ b/plugins/websocket/CMakeLists.txt @@ -8,18 +8,18 @@ include_directories(${CMAKE_SOURCE_DIR}/lib ${include_dirs}) find_package(Qt5Core REQUIRED) if(Qt5Core_FOUND) - message(STATUS "using Qt5") - - set(QT_INCLUDE_DIRS ${Qt5Core_INCLUDE_DIRS} ) - set(QT_LIBRARIES ${Qt5Core_LIBRARIES} ) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${Qt5Core_EXECUTABLE_COMPILE_FLAGS}") - message(STATUS "size of void_p: ${CMAKE_SIZEOF_VOID_P}") - if(CMAKE_SIZEOF_VOID_P MATCHES "8") - message(STATUS "64bit enabled") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mcmodel=large") - endif(CMAKE_SIZEOF_VOID_P MATCHES "8") - add_definitions(${Qt5Core_DEFINITIONS} -DQTBINARY_DATA) - set(CMAKE_AUTOMOC ON) + message(STATUS "using Qt5") + + set(QT_INCLUDE_DIRS ${Qt5Core_INCLUDE_DIRS} ) + set(QT_LIBRARIES ${Qt5Core_LIBRARIES} ) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${Qt5Core_EXECUTABLE_COMPILE_FLAGS}") + message(STATUS "size of void_p: ${CMAKE_SIZEOF_VOID_P}") + if(CMAKE_SIZEOF_VOID_P MATCHES "8") + message(STATUS "64bit enabled") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mcmodel=large") + endif(CMAKE_SIZEOF_VOID_P MATCHES "8") + add_definitions(${Qt5Core_DEFINITIONS} -DQTBINARY_DATA) + set(CMAKE_AUTOMOC ON) endif(Qt5Core_FOUND) pkg_check_modules(websockets REQUIRED libwebsockets) @@ -32,7 +32,7 @@ add_library(websocketsink MODULE ${websocketsink_sources}) set_target_properties(websocketsink PROPERTIES PREFIX "") target_link_libraries(websocketsink amb ${websockets_LIBRARIES} -L${CMAKE_CURRENT_BINARY_DIR}/lib ${link_libraries} ${QT_LIBRARIES}) -install(TARGETS websocketsink LIBRARY DESTINATION lib${LIB_SUFFIX}/automotive-message-broker) +install(TARGETS websocketsink LIBRARY DESTINATION ${PLUGIN_INSTALL_PATH}) set(websocketsource_headers websocketsource.h common.h) @@ -41,6 +41,6 @@ add_library(websocketsource MODULE ${websocketsource_sources}) set_target_properties(websocketsource PROPERTIES PREFIX "") target_link_libraries(websocketsource amb ${websockets_LIBRARIES} -L${CMAKE_CURRENT_BINARY_DIR}/lib ${link_libraries} ${QT_LIBRARIES}) -install(TARGETS websocketsource LIBRARY DESTINATION lib${LIB_SUFFIX}/automotive-message-broker) +install(TARGETS websocketsource LIBRARY DESTINATION ${PLUGIN_INSTALL_PATH}) endif(websocket_plugin) diff --git a/plugins/websocketsink/CMakeLists.txt b/plugins/websocketsink/CMakeLists.txt index f9110694..d4b1c315 100644 --- a/plugins/websocketsink/CMakeLists.txt +++ b/plugins/websocketsink/CMakeLists.txt @@ -11,6 +11,6 @@ add_library(websocketsinkplugin MODULE ${websocketsinkplugin_sources}) set_target_properties(websocketsinkplugin PROPERTIES PREFIX "") target_link_libraries(websocketsinkplugin amb ${websockets_LIBRARIES} -L${CMAKE_CURRENT_BINARY_DIR}/lib ${link_libraries}) -install(TARGETS websocketsinkplugin LIBRARY DESTINATION lib${LIB_SUFFIX}/automotive-message-broker) +install(TARGETS websocketsinkplugin LIBRARY DESTINATION ${PLUGIN_INSTALL_PATH}) endif(websocketold_plugin) diff --git a/plugins/websocketsourceplugin/CMakeLists.txt b/plugins/websocketsourceplugin/CMakeLists.txt index 2499423e..dff8dec5 100644 --- a/plugins/websocketsourceplugin/CMakeLists.txt +++ b/plugins/websocketsourceplugin/CMakeLists.txt @@ -11,6 +11,6 @@ add_library(websocketsourceplugin MODULE ${websocketsourceplugin_sources}) set_target_properties(websocketsourceplugin PROPERTIES PREFIX "") target_link_libraries(websocketsourceplugin amb ${websockets_LIBRARIES} -L${CMAKE_CURRENT_BINARY_DIR}/lib ${link_libraries}) -install(TARGETS websocketsourceplugin LIBRARY DESTINATION lib${LIB_SUFFIX}/automotive-message-broker) +install(TARGETS websocketsourceplugin LIBRARY DESTINATION ${PLUGIN_INSTALL_PATH}) endif(websocketold_plugin) diff --git a/plugins/wheel/CMakeLists.txt b/plugins/wheel/CMakeLists.txt index ab04d03a..9157ee74 100644 --- a/plugins/wheel/CMakeLists.txt +++ b/plugins/wheel/CMakeLists.txt @@ -13,4 +13,4 @@ add_library(wheelsourceplugin MODULE ${wheelsourceplugin_sources}) set_target_properties(wheelsourceplugin PROPERTIES PREFIX "") target_link_libraries(wheelsourceplugin amb -L${CMAKE_CURRENT_BINARY_DIR}/lib ${link_libraries}) -install(TARGETS wheelsourceplugin LIBRARY DESTINATION lib${LIB_SUFFIX}/automotive-message-broker) +install(TARGETS wheelsourceplugin LIBRARY DESTINATION ${PLUGIN_INSTALL_PATH}) |