summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohannes Schanda <schanda@itestra.de>2013-03-07 16:10:48 +0100
committerJohannes Schanda <schanda@itestra.de>2013-03-07 16:10:48 +0100
commitbfd5ad14a0dce3061cf6b3e8eca2d0e442c8bf44 (patch)
tree174a25233610caf980207fb86692bc9a6df47b24
parent3a202ee076c4d8ca3653f77a5326b4a74675030b (diff)
parent103de8bd9c0afe82ddfb130072fde37db83c5978 (diff)
downloadgenivi-common-api-dbus-runtime-bfd5ad14a0dce3061cf6b3e8eca2d0e442c8bf44.tar.gz
Merge branch 'master' into genivi_release
Conflicts: TODO
-rw-r--r--.gitattributes43
-rw-r--r--.gitignore15
-rw-r--r--Makefile.am47
-rw-r--r--README9
-rw-r--r--README.html506
-rw-r--r--eclipse-code-style-formatter.xml166
-rw-r--r--src/CommonAPI/DBus/DBusAddressTranslator.cpp233
-rw-r--r--src/CommonAPI/DBus/DBusAddressTranslator.h80
-rw-r--r--src/CommonAPI/DBus/DBusConnection.cpp81
-rw-r--r--src/CommonAPI/DBus/DBusConnection.h33
-rw-r--r--src/CommonAPI/DBus/DBusDaemonProxy.cpp263
-rw-r--r--src/CommonAPI/DBus/DBusDaemonProxy.h130
-rw-r--r--src/CommonAPI/DBus/DBusEvent.h5
-rw-r--r--src/CommonAPI/DBus/DBusFactory.cpp279
-rw-r--r--src/CommonAPI/DBus/DBusFactory.h108
-rw-r--r--src/CommonAPI/DBus/DBusFunctionalHash.cpp15
-rw-r--r--src/CommonAPI/DBus/DBusFunctionalHash.h6
-rw-r--r--src/CommonAPI/DBus/DBusInputStream.cpp10
-rw-r--r--src/CommonAPI/DBus/DBusInputStream.h2
-rw-r--r--src/CommonAPI/DBus/DBusMultiEvent.h20
-rw-r--r--src/CommonAPI/DBus/DBusObjectManager.cpp213
-rw-r--r--src/CommonAPI/DBus/DBusObjectManager.h114
-rw-r--r--src/CommonAPI/DBus/DBusOutputStream.cpp12
-rw-r--r--src/CommonAPI/DBus/DBusOutputStream.h3
-rw-r--r--src/CommonAPI/DBus/DBusProxy.cpp138
-rw-r--r--src/CommonAPI/DBus/DBusProxy.h115
-rw-r--r--src/CommonAPI/DBus/DBusProxyBase.cpp68
-rw-r--r--src/CommonAPI/DBus/DBusProxyBase.h107
-rw-r--r--src/CommonAPI/DBus/DBusProxyConnection.h196
-rw-r--r--src/CommonAPI/DBus/DBusProxyHelper.h17
-rw-r--r--src/CommonAPI/DBus/DBusRuntime.cpp64
-rw-r--r--src/CommonAPI/DBus/DBusRuntime.h72
-rw-r--r--src/CommonAPI/DBus/DBusServiceRegistry.cpp896
-rw-r--r--src/CommonAPI/DBus/DBusServiceRegistry.h251
-rw-r--r--src/CommonAPI/DBus/DBusServiceStatusEvent.cpp37
-rw-r--r--src/CommonAPI/DBus/DBusServiceStatusEvent.h84
-rw-r--r--src/CommonAPI/DBus/DBusStubAdapter.cpp39
-rw-r--r--src/CommonAPI/DBus/DBusStubAdapter.h17
-rw-r--r--src/CommonAPI/DBus/DBusStubAdapterHelper.h77
-rw-r--r--src/CommonAPI/DBus/DBusUtils.h28
-rw-r--r--src/murmurhash/MurmurHash3.cpp670
-rw-r--r--src/murmurhash/MurmurHash3.h74
-rw-r--r--src/test/DBusAddressTranslatorTest.cpp272
-rw-r--r--src/test/DBusCommunicationTest.cpp81
-rw-r--r--src/test/DBusDaemonProxyTest.cpp40
-rw-r--r--src/test/DBusInputStreamTest.cpp139
-rw-r--r--src/test/DBusMultipleConnectionTest.cpp67
-rw-r--r--src/test/DBusOutputStreamTest.cpp99
-rw-r--r--src/test/DBusProxyTest.cpp239
-rw-r--r--src/test/DBusServiceRegistryTest.cpp294
-rw-r--r--src/test/DBusStubAdapterTest.cpp17
-rw-r--r--src/test/DBusTestUtils.h20
-rw-r--r--src/test/commonapi/tests/DerivedTypeCollection.cpp52
-rw-r--r--src/test/commonapi/tests/DerivedTypeCollection.h429
-rw-r--r--src/test/commonapi/tests/PredefinedTypeCollection.h88
-rw-r--r--src/test/commonapi/tests/TestInterface.h8
-rw-r--r--src/test/commonapi/tests/TestInterfaceDBusProxy.cpp43
-rw-r--r--src/test/commonapi/tests/TestInterfaceDBusProxy.h14
-rw-r--r--src/test/commonapi/tests/TestInterfaceDBusStubAdapter.cpp50
-rw-r--r--src/test/commonapi/tests/TestInterfaceDBusStubAdapter.h4
-rw-r--r--src/test/commonapi/tests/TestInterfaceProxy.h13
-rw-r--r--src/test/commonapi/tests/TestInterfaceProxyBase.h10
-rw-r--r--src/test/commonapi/tests/TestInterfaceStub.h9
-rw-r--r--src/test/commonapi/tests/TestInterfaceStubDefault.cpp10
-rw-r--r--src/test/commonapi/tests/TestInterfaceStubDefault.h29
-rw-r--r--src/test/fakeLegacyService/fake.legacy.service.xml259
-rw-r--r--src/test/fakeLegacyService/fake/legacy/service/LegacyInterface.h38
-rw-r--r--src/test/fakeLegacyService/fake/legacy/service/LegacyInterfaceDBusProxy.cpp97
-rw-r--r--src/test/fakeLegacyService/fake/legacy/service/LegacyInterfaceDBusProxy.h48
-rw-r--r--src/test/fakeLegacyService/fake/legacy/service/LegacyInterfaceProxy.h131
-rw-r--r--src/test/fakeLegacyService/fake/legacy/service/LegacyInterfaceProxyBase.h40
-rw-r--r--src/test/fakeLegacyService/fakeLegacyService.fidl24
-rw-r--r--src/test/fakeLegacyService/fakeLegacyService.py52
-rw-r--r--src/test/fakeLegacyService/sendToFakeLegacyService.py23
-rw-r--r--src/test/test-derived-types.fidl56
-rw-r--r--src/test/test-interface-proxy.fidl58
-rw-r--r--src/test/test-predefined-types.fidl22
77 files changed, 5132 insertions, 3086 deletions
diff --git a/.gitattributes b/.gitattributes
new file mode 100644
index 0000000..4f3cc44
--- /dev/null
+++ b/.gitattributes
@@ -0,0 +1,43 @@
+# set default behaviour, in case users don't have core.autocrlf set.
+* text=auto
+
+# Explicitly declare text files we want to always be normalized and converted
+# to native line endings on checkout.
+*.am text
+*.ac text
+*.m4 text
+*.in text
+
+*.c text
+*.cpp text
+*.h text
+*.hpp text
+
+*.fidl text
+*.java text
+*.xtend text
+
+*.html text
+*.xml text
+
+*.properties text
+
+*.patch text
+
+AUTHORS text
+LICENSE* text
+README text
+
+# Eclipse
+.autotools text
+.cproject text
+.project text
+org.eclipse.core.resources.prefs text
+*.MF text
+
+# Declare files that will always have CRLF line endings on checkout.
+*.sln text eol=crlf
+
+# Denote all files that are truly binary and should not be modified.
+*.png binary
+*.jpg binary
diff --git a/.gitignore b/.gitignore
index 8000517..29281ae 100644
--- a/.gitignore
+++ b/.gitignore
@@ -22,3 +22,18 @@
/m4/libtool.m4
/m4/lt*.m4
+/DBusBenchmarkingTest
+/DBusCommunicationTest
+/DBusDaemonProxyTest
+/DBusFactoryTest
+/DBusInputStreamTest
+/DBusMultipleConnectionTest
+/DBusOutputStreamTest
+/DBusProxyTest
+/DBusRuntimeTest
+/DBusTypeStreamTest
+/DBusVariantOutputStreamTest
+/DBusVariantTest
+/DBusAddressTranslatorTest
+/.pydevproject
+/DBusServiceRegistryTest
diff --git a/Makefile.am b/Makefile.am
index 8f7dd68..0a42ea5 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -4,9 +4,11 @@ EXTRA_DIST = LICENSE LICENSE_dbus_patch LICENSE_MurmurHash
MOSTLYCLEANFILES =
AM_CPPFLAGS = \
+ -I$(top_srcdir)/src \
+ -I$(top_srcdir)/src/test \
${COMMONAPI_CFLAGS} \
- ${DBUS_CFLAGS} \
- -I$(top_srcdir)/src
+ ${DBUS_CFLAGS}
+
LDADD = \
${COMMONAPI_LIBS} \
@@ -26,6 +28,7 @@ libmurmurhash_internal_la_SOURCES = \
lib_LTLIBRARIES += libCommonAPI-DBus.la
libCommonAPI_DBus_la_SOURCES = \
+ src/CommonAPI/DBus/DBusAddressTranslator.cpp \
src/CommonAPI/DBus/DBusConnection.cpp \
src/CommonAPI/DBus/DBusDaemonProxy.cpp \
src/CommonAPI/DBus/DBusError.cpp \
@@ -34,6 +37,7 @@ libCommonAPI_DBus_la_SOURCES = \
src/CommonAPI/DBus/DBusMessage.cpp \
src/CommonAPI/DBus/DBusObjectManager.cpp \
src/CommonAPI/DBus/DBusOutputStream.cpp \
+ src/CommonAPI/DBus/DBusProxyBase.cpp \
src/CommonAPI/DBus/DBusProxy.cpp \
src/CommonAPI/DBus/DBusFactory.cpp \
src/CommonAPI/DBus/DBusRuntime.cpp \
@@ -47,6 +51,7 @@ libCommonAPI_DBus_la_LIBADD = \
CommonAPI_DBus_includedir=$(includedir)/CommonAPI-${VERSION}/CommonAPI/DBus
CommonAPI_DBus_include_HEADERS = \
+ src/CommonAPI/DBus/DBusAddressTranslator.h \
src/CommonAPI/DBus/DBusAttribute.h \
src/CommonAPI/DBus/DBusConnection.h \
src/CommonAPI/DBus/DBusDaemonProxy.h \
@@ -59,6 +64,7 @@ CommonAPI_DBus_include_HEADERS = \
src/CommonAPI/DBus/DBusMultiEvent.h \
src/CommonAPI/DBus/DBusObjectManager.h \
src/CommonAPI/DBus/DBusOutputStream.h \
+ src/CommonAPI/DBus/DBusProxyBase.h \
src/CommonAPI/DBus/DBusProxy.h \
src/CommonAPI/DBus/DBusProxyAsyncCallbackHandler.h \
src/CommonAPI/DBus/DBusProxyConnection.h \
@@ -82,14 +88,17 @@ TestInterfaceSources = \
src/test/commonapi/tests/DerivedTypeCollection.cpp \
src/test/commonapi/tests/TestInterfaceDBusProxy.cpp \
src/test/commonapi/tests/TestInterfaceDBusStubAdapter.cpp \
- src/test/commonapi/tests/TestInterfaceStubDefault.cpp
+ src/test/commonapi/tests/TestInterfaceStubDefault.cpp \
+ src/test/fakeLegacyService/fake/legacy/service/LegacyInterfaceDBusProxy.cpp
check_PROGRAMS = \
+ DBusServiceRegistryTest \
+ DBusProxyTest \
+ DBusAddressTranslatorTest \
DBusInputStreamTest \
DBusOutputStreamTest \
DBusRuntimeTest \
DBusFactoryTest \
- DBusProxyTest \
DBusVariantTest \
DBusTypeStreamTest \
DBusVariantOutputStreamTest \
@@ -100,7 +109,21 @@ check_PROGRAMS = \
TESTS = ${check_PROGRAMS}
-LDADD_FOR_GTEST = libCommonAPI-DBus.la ${GTEST_LIBS} -lpthread ${LDADD} -lpthread
+LDADD_FOR_GTEST = libCommonAPI-DBus.la ${GTEST_LIBS} ${LDADD}
+
+DBusServiceRegistryTest_SOURCES = \
+ src/test/DBusServiceRegistryTest.cpp \
+ ${TestInterfaceSources}
+DBusServiceRegistryTest_CPPFLAGS = ${AM_CPPFLAGS} ${GTEST_CPPFLAGS}
+DBusServiceRegistryTest_CXXFLAGS = ${GTEST_CXXFLAGS}
+DBusServiceRegistryTest_LDADD = ${LDADD_FOR_GTEST}
+
+DBusAddressTranslatorTest_SOURCES = \
+ src/test/DBusAddressTranslatorTest.cpp \
+ ${TestInterfaceSources}
+DBusAddressTranslatorTest_CPPFLAGS = ${AM_CPPFLAGS} ${GTEST_CPPFLAGS}
+DBusAddressTranslatorTest_CXXFLAGS = ${GTEST_CXXFLAGS}
+DBusAddressTranslatorTest_LDADD = ${LDADD_FOR_GTEST}
DBusTypeStreamTest_SOURCES = src/test/DBusTypeStreamTest.cpp
DBusTypeStreamTest_CPPFLAGS = ${AM_CPPFLAGS} ${GTEST_CPPFLAGS}
@@ -129,12 +152,16 @@ DBusDaemonProxyTest_CPPFLAGS = ${AM_CPPFLAGS} ${GTEST_CPPFLAGS}
DBusDaemonProxyTest_CXXFLAGS = ${GTEST_CXXFLAGS}
DBusDaemonProxyTest_LDADD = ${LDADD_FOR_GTEST}
-DBusInputStreamTest_SOURCES = src/test/DBusInputStreamTest.cpp
+DBusInputStreamTest_SOURCES = \
+ src/test/DBusInputStreamTest.cpp \
+ ${TestInterfaceSources}
DBusInputStreamTest_CPPFLAGS = ${AM_CPPFLAGS} ${GTEST_CPPFLAGS}
DBusInputStreamTest_CXXFLAGS = ${GTEST_CXXFLAGS}
DBusInputStreamTest_LDADD = ${LDADD_FOR_GTEST}
-DBusOutputStreamTest_SOURCES = src/test/DBusOutputStreamTest.cpp
+DBusOutputStreamTest_SOURCES = \
+ src/test/DBusOutputStreamTest.cpp \
+ ${TestInterfaceSources}
DBusOutputStreamTest_CPPFLAGS = ${AM_CPPFLAGS} ${GTEST_CPPFLAGS}
DBusOutputStreamTest_CXXFLAGS = ${GTEST_CXXFLAGS}
DBusOutputStreamTest_LDADD = ${LDADD_FOR_GTEST}
@@ -162,7 +189,9 @@ DBusMultipleConnectionTest_CPPFLAGS = ${AM_CPPFLAGS} ${GTEST_CPPFLAGS}
DBusMultipleConnectionTest_CXXFLAGS = ${GTEST_CXXFLAGS}
DBusMultipleConnectionTest_LDADD = ${LDADD_FOR_GTEST}
-DBusProxyTest_SOURCES = src/test/DBusProxyTest.cpp
+DBusProxyTest_SOURCES = \
+ src/test/DBusProxyTest.cpp \
+ ${TestInterfaceSources}
DBusProxyTest_CPPFLAGS = ${AM_CPPFLAGS} ${GTEST_CPPFLAGS}
DBusProxyTest_CXXFLAGS = ${GTEST_CXXFLAGS}
DBusProxyTest_LDADD = ${LDADD_FOR_GTEST}
@@ -194,4 +223,4 @@ maintainer-clean-local:
-rm -rf build-aux
-rm -f config.h.in*
-rm -f m4/libtool*.m4
- -rm -f m4/lt*.m4
+ -rm -f m4/lt*.m4 \ No newline at end of file
diff --git a/README b/README
index 71e7de8..5b2741d 100644
--- a/README
+++ b/README
@@ -48,9 +48,10 @@ CommonAPI-D-Bus-Tools - The eclipse based tools for CommonAPI D-Bus. This is the
=== Requirements
To build this package the CommonAPI library and a version of libdbus patched with the marshaling patch must be available through PkgConfig.
-=======
-Build Instructions
-==================
+
+
+== Build Instructions
+
To build this package CommonAPI and a version of libdbus patched with the marshaling patch must be available.
@@ -81,7 +82,7 @@ For example, if CommonAPI and patched dbus are available in /usr/local, set the
=== Instructions
Use autotools to build this package withthe above requirements available through Pkgconfig :
----
-# ./autoreconf -i
+# autoreconf -i
# ./configure
# make
# sudo make install (or alternative install process, eg. checkinstall on debian-based distributions, such as Ubuntu)
diff --git a/README.html b/README.html
deleted file mode 100644
index 825ca85..0000000
--- a/README.html
+++ /dev/null
@@ -1,506 +0,0 @@
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
- "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
-<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
-<head>
-<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
-<meta name="generator" content="AsciiDoc 8.4.5" />
-<title>GENIVI_CommonAPI-D-Bus</title>
-<style type="text/css">
-/* Debug borders */
-p, li, dt, dd, div, pre, h1, h2, h3, h4, h5, h6 {
-/*
- border: 1px solid red;
-*/
-}
-
-body {
- margin: 1em 5% 1em 5%;
-}
-
-a {
- color: blue;
- text-decoration: underline;
-}
-a:visited {
- color: fuchsia;
-}
-
-em {
- font-style: italic;
- color: navy;
-}
-
-strong {
- font-weight: bold;
- color: #083194;
-}
-
-tt {
- color: navy;
-}
-
-h1, h2, h3, h4, h5, h6 {
- color: #527bbd;
- font-family: sans-serif;
- margin-top: 1.2em;
- margin-bottom: 0.5em;
- line-height: 1.3;
-}
-
-h1, h2, h3 {
- border-bottom: 2px solid silver;
-}
-h2 {
- padding-top: 0.5em;
-}
-h3 {
- float: left;
-}
-h3 + * {
- clear: left;
-}
-
-div.sectionbody {
- font-family: serif;
- margin-left: 0;
-}
-
-hr {
- border: 1px solid silver;
-}
-
-p {
- margin-top: 0.5em;
- margin-bottom: 0.5em;
-}
-
-ul, ol, li > p {
- margin-top: 0;
-}
-
-pre {
- padding: 0;
- margin: 0;
-}
-
-span#author {
- color: #527bbd;
- font-family: sans-serif;
- font-weight: bold;
- font-size: 1.1em;
-}
-span#email {
-}
-span#revnumber, span#revdate, span#revremark {
- font-family: sans-serif;
-}
-
-div#footer {
- font-family: sans-serif;
- font-size: small;
- border-top: 2px solid silver;
- padding-top: 0.5em;
- margin-top: 4.0em;
-}
-div#footer-text {
- float: left;
- padding-bottom: 0.5em;
-}
-div#footer-badges {
- float: right;
- padding-bottom: 0.5em;
-}
-
-div#preamble {
- margin-top: 1.5em;
- margin-bottom: 1.5em;
-}
-div.tableblock, div.imageblock, div.exampleblock, div.verseblock,
-div.quoteblock, div.literalblock, div.listingblock, div.sidebarblock,
-div.admonitionblock {
- margin-top: 1.5em;
- margin-bottom: 1.5em;
-}
-div.admonitionblock {
- margin-top: 2.5em;
- margin-bottom: 2.5em;
-}
-
-div.content { /* Block element content. */
- padding: 0;
-}
-
-/* Block element titles. */
-div.title, caption.title {
- color: #527bbd;
- font-family: sans-serif;
- font-weight: bold;
- text-align: left;
- margin-top: 1.0em;
- margin-bottom: 0.5em;
-}
-div.title + * {
- margin-top: 0;
-}
-
-td div.title:first-child {
- margin-top: 0.0em;
-}
-div.content div.title:first-child {
- margin-top: 0.0em;
-}
-div.content + div.title {
- margin-top: 0.0em;
-}
-
-div.sidebarblock > div.content {
- background: #ffffee;
- border: 1px solid silver;
- padding: 0.5em;
-}
-
-div.listingblock > div.content {
- border: 1px solid silver;
- background: #f4f4f4;
- padding: 0.5em;
-}
-
-div.quoteblock {
- padding-left: 2.0em;
- margin-right: 10%;
-}
-div.quoteblock > div.attribution {
- padding-top: 0.5em;
- text-align: right;
-}
-
-div.verseblock {
- padding-left: 2.0em;
- margin-right: 10%;
-}
-div.verseblock > div.content {
- white-space: pre;
-}
-div.verseblock > div.attribution {
- padding-top: 0.75em;
- text-align: left;
-}
-/* DEPRECATED: Pre version 8.2.7 verse style literal block. */
-div.verseblock + div.attribution {
- text-align: left;
-}
-
-div.admonitionblock .icon {
- vertical-align: top;
- font-size: 1.1em;
- font-weight: bold;
- text-decoration: underline;
- color: #527bbd;
- padding-right: 0.5em;
-}
-div.admonitionblock td.content {
- padding-left: 0.5em;
- border-left: 2px solid silver;
-}
-
-div.exampleblock > div.content {
- border-left: 2px solid silver;
- padding: 0.5em;
-}
-
-div.imageblock div.content { padding-left: 0; }
-span.image img { border-style: none; }
-a.image:visited { color: white; }
-
-dl {
- margin-top: 0.8em;
- margin-bottom: 0.8em;
-}
-dt {
- margin-top: 0.5em;
- margin-bottom: 0;
- font-style: normal;
- color: navy;
-}
-dd > *:first-child {
- margin-top: 0.1em;
-}
-
-ul, ol {
- list-style-position: outside;
-}
-ol.arabic {
- list-style-type: decimal;
-}
-ol.loweralpha {
- list-style-type: lower-alpha;
-}
-ol.upperalpha {
- list-style-type: upper-alpha;
-}
-ol.lowerroman {
- list-style-type: lower-roman;
-}
-ol.upperroman {
- list-style-type: upper-roman;
-}
-
-div.compact ul, div.compact ol,
-div.compact p, div.compact p,
-div.compact div, div.compact div {
- margin-top: 0.1em;
- margin-bottom: 0.1em;
-}
-
-div.tableblock > table {
- border: 3px solid #527bbd;
-}
-thead {
- font-family: sans-serif;
- font-weight: bold;
-}
-tfoot {
- font-weight: bold;
-}
-td > div.verse {
- white-space: pre;
-}
-p.table {
- margin-top: 0;
-}
-/* Because the table frame attribute is overriden by CSS in most browsers. */
-div.tableblock > table[frame="void"] {
- border-style: none;
-}
-div.tableblock > table[frame="hsides"] {
- border-left-style: none;
- border-right-style: none;
-}
-div.tableblock > table[frame="vsides"] {
- border-top-style: none;
- border-bottom-style: none;
-}
-
-
-div.hdlist {
- margin-top: 0.8em;
- margin-bottom: 0.8em;
-}
-div.hdlist tr {
- padding-bottom: 15px;
-}
-dt.hdlist1.strong, td.hdlist1.strong {
- font-weight: bold;
-}
-td.hdlist1 {
- vertical-align: top;
- font-style: normal;
- padding-right: 0.8em;
- color: navy;
-}
-td.hdlist2 {
- vertical-align: top;
-}
-div.hdlist.compact tr {
- margin: 0;
- padding-bottom: 0;
-}
-
-.comment {
- background: yellow;
-}
-
-@media print {
- div#footer-badges { display: none; }
-}
-
-div#toctitle {
- color: #527bbd;
- font-family: sans-serif;
- font-size: 1.1em;
- font-weight: bold;
- margin-top: 1.0em;
- margin-bottom: 0.1em;
-}
-
-div.toclevel1, div.toclevel2, div.toclevel3, div.toclevel4 {
- margin-top: 0;
- margin-bottom: 0;
-}
-div.toclevel2 {
- margin-left: 2em;
- font-size: 0.9em;
-}
-div.toclevel3 {
- margin-left: 4em;
- font-size: 0.9em;
-}
-div.toclevel4 {
- margin-left: 6em;
- font-size: 0.9em;
-}
-/* Workarounds for IE6's broken and incomplete CSS2. */
-
-div.sidebar-content {
- background: #ffffee;
- border: 1px solid silver;
- padding: 0.5em;
-}
-div.sidebar-title, div.image-title {
- color: #527bbd;
- font-family: sans-serif;
- font-weight: bold;
- margin-top: 0.0em;
- margin-bottom: 0.5em;
-}
-
-div.listingblock div.content {
- border: 1px solid silver;
- background: #f4f4f4;
- padding: 0.5em;
-}
-
-div.quoteblock-attribution {
- padding-top: 0.5em;
- text-align: right;
-}
-
-div.verseblock-content {
- white-space: pre;
-}
-div.verseblock-attribution {
- padding-top: 0.75em;
- text-align: left;
-}
-
-div.exampleblock-content {
- border-left: 2px solid silver;
- padding-left: 0.5em;
-}
-
-/* IE6 sets dynamically generated links as visited. */
-div#toc a:visited { color: blue; }
-</style>
-</head>
-<body>
-<div id="header">
-<h1>GENIVI_CommonAPI-D-Bus</h1>
-<span id="author">Juergen Gehring - juergen.gehring@bmw.de, Manfred Bathelt - manfred.bathelt@bmw.de</span><br />
-</div>
-<h2 id="_copyright">Copyright</h2>
-<div class="sectionbody">
-<div class="paragraph"><p>Copyright &#169; 2013, GENIVI Alliance, Inc.
-Copyright &#169; 2013, BMW AG</p></div>
-<div class="paragraph"><p>This file is part of GENIVI Project IPC Common API.</p></div>
-<div class="paragraph"><p>Contributions are licensed to the GENIVI Alliance under one or more
-Contribution License Agreements or MPL 2.0 .</p></div>
-<div class="paragraph"><p>&#169; Copyright
-This Source Code Form is subject to the terms of the
-Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with
-this file, You can obtain one at <a href="http://mozilla.org/MPL/2.0/">http://mozilla.org/MPL/2.0/</a>.</p></div>
-<div class="paragraph"><p>For further information see <a href="https://collab.genivi.org/wiki/display/genivi/SysInfraEGCommonIDLCommonAPIGuide">https://collab.genivi.org/wiki/display/genivi/SysInfraEGCommonIDLCommonAPIGuide</a></p></div>
-</div>
-<h2 id="_license">License</h2>
-<div class="sectionbody">
-<div class="paragraph"><p>This project is licensed under MPL 2.0</p></div>
-<div class="paragraph"><p>Contribution is done under GENIVI CLA or MPL2.0.</p></div>
-</div>
-<h2 id="_version">Version</h2>
-<div class="sectionbody">
-<div class="paragraph"><p>The current version can be taken from the git.</p></div>
-</div>
-<h2 id="_common_api_overview">Common API Overview</h2>
-<div class="sectionbody">
-<div class="paragraph"><p>Common API and its mechanism specific bindings (e.g. Common API D-Bus) provide a set of libraries and tools to work with
-RPC communication in a way independent of wich mechanism is used. It consist currently consists of four subprojects:</p></div>
-<div class="listingblock">
-<div class="content">
-<pre><tt>CommonAPI - This is the base C++ library, which provides the application interface for users and can
- load runtime bindings such as dbus.
-CommonAPI-Tools - The eclipse based tools for CommonAPI. This is essentially the code generator for
- Franca -&gt; Common API C++ code.
-CommonAPI-D-Bus - This is the D-Bus binding C++ library, which provides the necesary code to communicate
- over D-Bus. This is invisible to the application code, and simply needs to be linked against.
- (This is the current package.)
-CommonAPI-D-Bus-Tools - The eclipse based tools for CommonAPI D-Bus. This is the code generator for
- Franca -&gt; Common API D-Bus C++ code.</tt></pre>
-</div></div>
-</div>
-<h2 id="_build_instructions">Build Instructions</h2>
-<div class="sectionbody">
-<h3 id="_requirements">Requirements</h3><div style="clear:left"></div>
-<div class="paragraph"><p>To build this package the CommonAPI library and a version of libdbus patched with the marshaling patch must be available through PkgConfig.</p></div>
-<div class="paragraph"><p>Instructions for making a patched version of libdbus available in /usr/local:</p></div>
-<div class="listingblock">
-<div class="content">
-<pre><tt># wget http://dbus.freedesktop.org/releases/dbus/dbus-1.4.16.tar.gz
-
-# tar -xzf dbus-1.4.16.tar.gz
-
-# cd dbus-1.4.16
-
-# patch -p1 &lt; /path/to/dbus-DBusMessage-add-support-for-custom-marshaling.patch
-
-# ./configure --prefix=/usr/local
-
-# make -C dbus
-
-# sudo make -C dbus install
-# sudo make install-pkgconfigDATA</tt></pre>
-</div></div>
-<div class="paragraph"><p>The path to CommonAPI and patched libdbus pkgconfig files must be added to the PKG_CONFIG_PATH for the entire build process.</p></div>
-<div class="paragraph"><p>For example, if CommonAPI and patched dbus are available in /usr/local, set the PKG_CONFIG_PATH variable as follows:</p></div>
-<div class="listingblock">
-<div class="content">
-<pre><tt># export PKG_CONFIG_PATH="/usr/local/lib/pkgconfig:$PKG_CONFIG_PATH"</tt></pre>
-</div></div>
-<h3 id="_instructions">Instructions</h3><div style="clear:left"></div>
-<div class="paragraph"><p>Use autotools to build this package withthe above requirements available through Pkgconfig :</p></div>
-<div class="listingblock">
-<div class="content">
-<pre><tt># ./autoreconf -i
-# ./configure
-# make
-# sudo make install (or alternative install process, eg. checkinstall on debian-based distributions, such as Ubuntu)</tt></pre>
-</div></div>
-<div class="paragraph"><p>If the environment variable GTEST_CONFIG is set to the path of the gtest-config script in a Gtest tree test will also be built.</p></div>
-</div>
-<h2 id="_working_on_the_code_amp_contribution">Working on the code &amp; contribution</h2>
-<div class="sectionbody">
-<div class="literalblock">
-<div class="title">First get the code from the git:</div>
-<div class="content">
-<pre><tt>git clone</tt></pre>
-</div></div>
-<div class="literalblock">
-<div class="title">Get an overview of all branches:</div>
-<div class="content">
-<pre><tt>git branch</tt></pre>
-</div></div>
-<div class="literalblock">
-<div class="title">Switch to the branch you want to work on (master is the feature branch) and verify that it has switched (* changed)</div>
-<div class="content">
-<pre><tt>git checkout &lt;your branch&gt;
-git branch</tt></pre>
-</div></div>
-<div class="literalblock">
-<div class="title">Best practice is to create a local branch based on the current branch:</div>
-<div class="content">
-<pre><tt>git branch working_branch</tt></pre>
-</div></div>
-<div class="paragraph"><p>Start working, best practice is to commit smaller, compilable pieces during the development process that makes it easier to handle later on.</p></div>
-<div class="literalblock">
-<div class="title">If you want to commit you changes, send them to the author, you can create a patch like this:</div>
-<div class="content">
-<pre><tt>git format-patch working_branch &lt;your branch&gt;</tt></pre>
-</div></div>
-<div class="paragraph"><p>This creates a set of patches that are published via the mailing list.The patches will be discussed and then merged &amp; uploaded on the git by the maintainer.</p></div>
-<div class="paragraph"><p>Patches can be accepted either under GENIVI Cla or MPL 2.0 (see section License). Please be sure that the signed-off-by is set correctly. For more, check out <a href="http://gerrit.googlecode.com/svn/documentation/2.0/user-signedoffby.html">http://gerrit.googlecode.com/svn/documentation/2.0/user-signedoffby.html</a></p></div>
-</div>
-<div id="footer">
-<div id="footer-text">
-Last updated 2013-01-21 14:49:07 CEST
-</div>
-</div>
-</body>
-</html>
diff --git a/eclipse-code-style-formatter.xml b/eclipse-code-style-formatter.xml
new file mode 100644
index 0000000..8be3b29
--- /dev/null
+++ b/eclipse-code-style-formatter.xml
@@ -0,0 +1,166 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<profiles version="1">
+<profile kind="CodeFormatterProfile" name="C++ Itestra" version="1">
+<setting id="org.eclipse.cdt.core.formatter.insert_space_before_opening_paren_in_method_declaration" value="do not insert"/>
+<setting id="org.eclipse.cdt.core.formatter.insert_space_after_opening_paren_in_for" value="do not insert"/>
+<setting id="org.eclipse.cdt.core.formatter.insert_new_line_in_empty_block" value="insert"/>
+<setting id="org.eclipse.cdt.core.formatter.lineSplit" value="120"/>
+<setting id="org.eclipse.cdt.core.formatter.alignment_for_member_access" value="0"/>
+<setting id="org.eclipse.cdt.core.formatter.insert_space_before_comma_in_base_types" value="do not insert"/>
+<setting id="org.eclipse.cdt.core.formatter.keep_else_statement_on_same_line" value="false"/>
+<setting id="org.eclipse.cdt.core.formatter.indent_switchstatements_compare_to_switch" value="true"/>
+<setting id="org.eclipse.cdt.core.formatter.alignment_for_constructor_initializer_list" value="82"/>
+<setting id="org.eclipse.cdt.core.formatter.insert_space_after_opening_brace_in_array_initializer" value="do not insert"/>
+<setting id="org.eclipse.cdt.core.formatter.insert_space_before_comma_in_method_declaration_parameters" value="do not insert"/>
+<setting id="org.eclipse.cdt.core.formatter.insert_space_after_opening_paren_in_if" value="do not insert"/>
+<setting id="org.eclipse.cdt.core.formatter.insert_space_before_closing_paren_in_parenthesized_expression" value="do not insert"/>
+<setting id="org.eclipse.cdt.core.formatter.insert_space_after_opening_paren_in_exception_specification" value="do not insert"/>
+<setting id="org.eclipse.cdt.core.formatter.insert_space_after_comma_in_base_types" value="insert"/>
+<setting id="org.eclipse.cdt.core.formatter.indent_body_declarations_compare_to_access_specifier" value="true"/>
+<setting id="org.eclipse.cdt.core.formatter.insert_space_before_closing_paren_in_exception_specification" value="do not insert"/>
+<setting id="org.eclipse.cdt.core.formatter.insert_space_after_comma_in_template_arguments" value="insert"/>
+<setting id="org.eclipse.cdt.core.formatter.insert_space_before_opening_brace_in_block" value="insert"/>
+<setting id="org.eclipse.cdt.core.formatter.insert_space_before_closing_paren_in_method_declaration" value="do not insert"/>
+<setting id="org.eclipse.cdt.core.formatter.use_tabs_only_for_leading_indentations" value="true"/>
+<setting id="org.eclipse.cdt.core.formatter.insert_space_before_colon_in_labeled_statement" value="do not insert"/>
+<setting id="org.eclipse.cdt.core.formatter.insert_space_after_colon_in_case" value="insert"/>
+<setting id="org.eclipse.cdt.core.formatter.comment.min_distance_between_code_and_line_comment" value="1"/>
+<setting id="org.eclipse.cdt.core.formatter.insert_space_after_comma_in_array_initializer" value="insert"/>
+<setting id="org.eclipse.cdt.core.formatter.insert_space_after_comma_in_enum_declarations" value="insert"/>
+<setting id="org.eclipse.cdt.core.formatter.alignment_for_expressions_in_array_initializer" value="16"/>
+<setting id="org.eclipse.cdt.core.formatter.insert_space_after_comma_in_declarator_list" value="insert"/>
+<setting id="org.eclipse.cdt.core.formatter.insert_space_before_opening_bracket" value="do not insert"/>
+<setting id="org.eclipse.cdt.core.formatter.insert_space_before_closing_paren_in_for" value="do not insert"/>
+<setting id="org.eclipse.cdt.core.formatter.insert_space_before_prefix_operator" value="do not insert"/>
+<setting id="org.eclipse.cdt.core.formatter.tabulation.size" value="4"/>
+<setting id="org.eclipse.cdt.core.formatter.insert_new_line_before_else_in_if_statement" value="do not insert"/>
+<setting id="org.eclipse.cdt.core.formatter.alignment_for_enumerator_list" value="48"/>
+<setting id="org.eclipse.cdt.core.formatter.insert_space_after_opening_paren_in_parenthesized_expression" value="do not insert"/>
+<setting id="org.eclipse.cdt.core.formatter.insert_space_between_empty_parens_in_method_declaration" value="do not insert"/>
+<setting id="org.eclipse.cdt.core.formatter.insert_space_before_closing_paren_in_switch" value="do not insert"/>
+<setting id="org.eclipse.cdt.core.formatter.alignment_for_declarator_list" value="16"/>
+<setting id="org.eclipse.cdt.core.formatter.insert_space_before_opening_paren_in_parenthesized_expression" value="do not insert"/>
+<setting id="org.eclipse.cdt.core.formatter.indent_empty_lines" value="false"/>
+<setting id="org.eclipse.cdt.core.formatter.indent_switchstatements_compare_to_cases" value="true"/>
+<setting id="org.eclipse.cdt.core.formatter.keep_empty_array_initializer_on_one_line" value="false"/>
+<setting id="org.eclipse.cdt.core.formatter.insert_space_before_opening_brace_in_method_declaration" value="insert"/>
+<setting id="org.eclipse.cdt.core.formatter.put_empty_statement_on_new_line" value="true"/>
+<setting id="org.eclipse.cdt.core.formatter.insert_space_before_opening_brace_in_switch" value="insert"/>
+<setting id="org.eclipse.cdt.core.formatter.insert_space_before_closing_paren_in_cast" value="do not insert"/>
+<setting id="org.eclipse.cdt.core.formatter.insert_space_between_empty_braces_in_array_initializer" value="do not insert"/>
+<setting id="org.eclipse.cdt.core.formatter.brace_position_for_method_declaration" value="end_of_line"/>
+<setting id="org.eclipse.cdt.core.formatter.insert_space_before_closing_paren_in_while" value="do not insert"/>
+<setting id="org.eclipse.cdt.core.formatter.insert_space_after_question_in_conditional" value="insert"/>
+<setting id="org.eclipse.cdt.core.formatter.insert_space_before_semicolon" value="do not insert"/>
+<setting id="org.eclipse.cdt.core.formatter.insert_space_after_closing_angle_bracket_in_template_arguments" value="insert"/>
+<setting id="org.eclipse.cdt.core.formatter.insert_space_before_colon_in_base_clause" value="do not insert"/>
+<setting id="org.eclipse.cdt.core.formatter.indent_breaks_compare_to_cases" value="true"/>
+<setting id="org.eclipse.cdt.core.formatter.insert_space_before_unary_operator" value="do not insert"/>
+<setting id="org.eclipse.cdt.core.formatter.join_wrapped_lines" value="false"/>
+<setting id="org.eclipse.cdt.core.formatter.insert_space_before_comma_in_declarator_list" value="do not insert"/>
+<setting id="org.eclipse.cdt.core.formatter.alignment_for_arguments_in_method_invocation" value="48"/>
+<setting id="org.eclipse.cdt.core.formatter.insert_space_before_opening_paren_in_while" value="insert"/>
+<setting id="org.eclipse.cdt.core.formatter.insert_space_between_empty_brackets" value="do not insert"/>
+<setting id="org.eclipse.cdt.core.formatter.insert_space_after_opening_bracket" value="do not insert"/>
+<setting id="org.eclipse.cdt.core.formatter.alignment_for_parameters_in_method_declaration" value="82"/>
+<setting id="org.eclipse.cdt.core.formatter.insert_new_line_before_closing_brace_in_array_initializer" value="do not insert"/>
+<setting id="org.eclipse.cdt.core.formatter.number_of_empty_lines_to_preserve" value="1"/>
+<setting id="org.eclipse.cdt.core.formatter.insert_space_after_opening_paren_in_method_invocation" value="do not insert"/>
+<setting id="org.eclipse.cdt.core.formatter.insert_space_before_closing_brace_in_array_initializer" value="do not insert"/>
+<setting id="org.eclipse.cdt.core.formatter.insert_space_before_semicolon_in_for" value="do not insert"/>
+<setting id="org.eclipse.cdt.core.formatter.insert_space_before_colon_in_conditional" value="insert"/>
+<setting id="org.eclipse.cdt.core.formatter.brace_position_for_block" value="end_of_line"/>
+<setting id="org.eclipse.cdt.core.formatter.comment.preserve_white_space_between_code_and_line_comments" value="false"/>
+<setting id="org.eclipse.cdt.core.formatter.brace_position_for_type_declaration" value="end_of_line"/>
+<setting id="org.eclipse.cdt.core.formatter.insert_space_before_assignment_operator" value="insert"/>
+<setting id="org.eclipse.cdt.core.formatter.insert_space_before_opening_angle_bracket_in_template_arguments" value="do not insert"/>
+<setting id="org.eclipse.cdt.core.formatter.insert_space_before_comma_in_expression_list" value="do not insert"/>
+<setting id="org.eclipse.cdt.core.formatter.insert_space_after_opening_angle_bracket_in_template_parameters" value="do not insert"/>
+<setting id="org.eclipse.cdt.core.formatter.continuation_indentation" value="4"/>
+<setting id="org.eclipse.cdt.core.formatter.alignment_for_expression_list" value="0"/>
+<setting id="org.eclipse.cdt.core.formatter.insert_space_after_opening_paren_in_method_declaration" value="do not insert"/>
+<setting id="org.eclipse.cdt.core.formatter.insert_space_before_comma_in_template_parameters" value="do not insert"/>
+<setting id="org.eclipse.cdt.core.formatter.insert_space_before_colon_in_default" value="do not insert"/>
+<setting id="org.eclipse.cdt.core.formatter.insert_space_after_binary_operator" value="insert"/>
+<setting id="org.eclipse.cdt.core.formatter.alignment_for_conditional_expression" value="80"/>
+<setting id="org.eclipse.cdt.core.formatter.insert_space_between_empty_parens_in_method_invocation" value="do not insert"/>
+<setting id="org.eclipse.cdt.core.formatter.insert_space_before_comma_in_array_initializer" value="do not insert"/>
+<setting id="org.eclipse.cdt.core.formatter.insert_space_before_closing_paren_in_if" value="do not insert"/>
+<setting id="org.eclipse.cdt.core.formatter.format_guardian_clause_on_one_line" value="false"/>
+<setting id="org.eclipse.cdt.core.formatter.indent_access_specifier_extra_spaces" value="0"/>
+<setting id="org.eclipse.cdt.core.formatter.insert_space_after_opening_paren_in_cast" value="do not insert"/>
+<setting id="org.eclipse.cdt.core.formatter.indent_access_specifier_compare_to_type_header" value="false"/>
+<setting id="org.eclipse.cdt.core.formatter.insert_space_before_opening_brace_in_type_declaration" value="insert"/>
+<setting id="org.eclipse.cdt.core.formatter.continuation_indentation_for_array_initializer" value="4"/>
+<setting id="org.eclipse.cdt.core.formatter.insert_space_after_colon_in_labeled_statement" value="insert"/>
+<setting id="org.eclipse.cdt.core.formatter.insert_space_after_comma_in_method_declaration_parameters" value="insert"/>
+<setting id="org.eclipse.cdt.core.formatter.insert_space_after_semicolon_in_for" value="insert"/>
+<setting id="org.eclipse.cdt.core.formatter.insert_space_before_closing_paren_in_method_invocation" value="do not insert"/>
+<setting id="org.eclipse.cdt.core.formatter.indent_body_declarations_compare_to_namespace_header" value="false"/>
+<setting id="org.eclipse.cdt.core.formatter.alignment_for_compact_if" value="0"/>
+<setting id="org.eclipse.cdt.core.formatter.insert_space_after_assignment_operator" value="insert"/>
+<setting id="org.eclipse.cdt.core.formatter.insert_space_after_closing_brace_in_block" value="insert"/>
+<setting id="org.eclipse.cdt.core.formatter.insert_space_before_opening_brace_in_array_initializer" value="insert"/>
+<setting id="org.eclipse.cdt.core.formatter.insert_new_line_at_end_of_file_if_missing" value="do not insert"/>
+<setting id="org.eclipse.cdt.core.formatter.alignment_for_assignment" value="16"/>
+<setting id="org.eclipse.cdt.core.formatter.alignment_for_conditional_expression_chain" value="18"/>
+<setting id="org.eclipse.cdt.core.formatter.insert_space_after_comma_in_template_parameters" value="insert"/>
+<setting id="org.eclipse.cdt.core.formatter.insert_space_after_comma_in_expression_list" value="insert"/>
+<setting id="org.eclipse.cdt.core.formatter.insert_space_before_question_in_conditional" value="insert"/>
+<setting id="org.eclipse.cdt.core.formatter.insert_space_before_opening_paren_in_exception_specification" value="insert"/>
+<setting id="org.eclipse.cdt.core.formatter.insert_space_before_binary_operator" value="insert"/>
+<setting id="org.eclipse.cdt.core.formatter.insert_new_line_before_identifier_in_function_declaration" value="do not insert"/>
+<setting id="org.eclipse.cdt.core.formatter.alignment_for_base_clause_in_type_declaration" value="80"/>
+<setting id="org.eclipse.cdt.core.formatter.insert_space_before_comma_in_method_declaration_throws" value="do not insert"/>
+<setting id="org.eclipse.cdt.core.formatter.insert_space_between_empty_parens_in_exception_specification" value="do not insert"/>
+<setting id="org.eclipse.cdt.core.formatter.insert_space_before_comma_in_method_invocation_arguments" value="do not insert"/>
+<setting id="org.eclipse.cdt.core.formatter.indent_declaration_compare_to_template_header" value="false"/>
+<setting id="org.eclipse.cdt.core.formatter.insert_space_after_unary_operator" value="do not insert"/>
+<setting id="org.eclipse.cdt.core.formatter.insert_space_before_opening_paren_in_switch" value="insert"/>
+<setting id="org.eclipse.cdt.core.formatter.indent_statements_compare_to_body" value="true"/>
+<setting id="org.eclipse.cdt.core.formatter.insert_space_after_comma_in_method_declaration_throws" value="insert"/>
+<setting id="org.eclipse.cdt.core.formatter.alignment_for_binary_expression" value="16"/>
+<setting id="org.eclipse.cdt.core.formatter.indent_statements_compare_to_block" value="true"/>
+<setting id="org.eclipse.cdt.core.formatter.insert_space_before_comma_in_template_arguments" value="do not insert"/>
+<setting id="org.eclipse.cdt.core.formatter.insert_new_line_before_catch_in_try_statement" value="do not insert"/>
+<setting id="org.eclipse.cdt.core.formatter.alignment_for_throws_clause_in_method_declaration" value="16"/>
+<setting id="org.eclipse.cdt.core.formatter.insert_space_before_opening_paren_in_method_invocation" value="do not insert"/>
+<setting id="org.eclipse.cdt.core.formatter.insert_space_after_closing_paren_in_cast" value="insert"/>
+<setting id="org.eclipse.cdt.core.formatter.insert_space_before_closing_paren_in_catch" value="do not insert"/>
+<setting id="org.eclipse.cdt.core.formatter.insert_space_before_opening_angle_bracket_in_template_parameters" value="do not insert"/>
+<setting id="org.eclipse.cdt.core.formatter.tabulation.char" value="space"/>
+<setting id="org.eclipse.cdt.core.formatter.insert_space_before_closing_angle_bracket_in_template_parameters" value="do not insert"/>
+<setting id="org.eclipse.cdt.core.formatter.insert_new_line_before_colon_in_constructor_initializer_list" value="do not insert"/>
+<setting id="org.eclipse.cdt.core.formatter.insert_space_after_opening_paren_in_while" value="do not insert"/>
+<setting id="org.eclipse.cdt.core.formatter.insert_space_after_comma_in_method_invocation_arguments" value="insert"/>
+<setting id="org.eclipse.cdt.core.formatter.brace_position_for_block_in_case" value="end_of_line"/>
+<setting id="org.eclipse.cdt.core.formatter.compact_else_if" value="true"/>
+<setting id="org.eclipse.cdt.core.formatter.insert_space_after_postfix_operator" value="do not insert"/>
+<setting id="org.eclipse.cdt.core.formatter.insert_new_line_after_template_declaration" value="do not insert"/>
+<setting id="org.eclipse.cdt.core.formatter.insert_space_after_colon_in_base_clause" value="insert"/>
+<setting id="org.eclipse.cdt.core.formatter.insert_space_after_opening_paren_in_catch" value="do not insert"/>
+<setting id="org.eclipse.cdt.core.formatter.keep_then_statement_on_same_line" value="false"/>
+<setting id="org.eclipse.cdt.core.formatter.brace_position_for_switch" value="end_of_line"/>
+<setting id="org.eclipse.cdt.core.formatter.alignment_for_overloaded_left_shift_chain" value="16"/>
+<setting id="org.eclipse.cdt.core.formatter.insert_space_before_opening_paren_in_if" value="insert"/>
+<setting id="org.eclipse.cdt.core.formatter.insert_space_after_opening_paren_in_switch" value="do not insert"/>
+<setting id="org.eclipse.cdt.core.formatter.keep_imple_if_on_one_line" value="false"/>
+<setting id="org.eclipse.cdt.core.formatter.insert_new_line_after_opening_brace_in_array_initializer" value="do not insert"/>
+<setting id="org.eclipse.cdt.core.formatter.indentation.size" value="4"/>
+<setting id="org.eclipse.cdt.core.formatter.brace_position_for_namespace_declaration" value="end_of_line"/>
+<setting id="org.eclipse.cdt.core.formatter.insert_space_after_colon_in_conditional" value="insert"/>
+<setting id="org.eclipse.cdt.core.formatter.insert_space_before_comma_in_enum_declarations" value="do not insert"/>
+<setting id="org.eclipse.cdt.core.formatter.insert_space_after_prefix_operator" value="do not insert"/>
+<setting id="org.eclipse.cdt.core.formatter.insert_space_before_closing_angle_bracket_in_template_arguments" value="do not insert"/>
+<setting id="org.eclipse.cdt.core.formatter.brace_position_for_array_initializer" value="end_of_line"/>
+<setting id="org.eclipse.cdt.core.formatter.insert_space_before_colon_in_case" value="do not insert"/>
+<setting id="org.eclipse.cdt.core.formatter.insert_space_before_opening_paren_in_catch" value="insert"/>
+<setting id="org.eclipse.cdt.core.formatter.insert_space_before_opening_brace_in_namespace_declaration" value="insert"/>
+<setting id="org.eclipse.cdt.core.formatter.insert_space_before_postfix_operator" value="do not insert"/>
+<setting id="org.eclipse.cdt.core.formatter.insert_space_before_closing_bracket" value="do not insert"/>
+<setting id="org.eclipse.cdt.core.formatter.insert_new_line_before_while_in_do_statement" value="do not insert"/>
+<setting id="org.eclipse.cdt.core.formatter.insert_space_before_opening_paren_in_for" value="insert"/>
+<setting id="org.eclipse.cdt.core.formatter.insert_space_after_closing_angle_bracket_in_template_parameters" value="insert"/>
+<setting id="org.eclipse.cdt.core.formatter.insert_space_after_opening_angle_bracket_in_template_arguments" value="do not insert"/>
+</profile>
+</profiles> \ No newline at end of file
diff --git a/src/CommonAPI/DBus/DBusAddressTranslator.cpp b/src/CommonAPI/DBus/DBusAddressTranslator.cpp
new file mode 100644
index 0000000..3e880eb
--- /dev/null
+++ b/src/CommonAPI/DBus/DBusAddressTranslator.cpp
@@ -0,0 +1,233 @@
+/* Copyright (C) 2013 BMW Group
+ * Author: Manfred Bathelt (manfred.bathelt@bmw.de)
+ * Author: Juergen Gehring (juergen.gehring@bmw.de)
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+
+#include "DBusAddressTranslator.h"
+#include "DBusUtils.h"
+
+#include <unordered_set>
+#include <string.h>
+#include <iostream>
+#include <fstream>
+#include <cassert>
+
+
+namespace CommonAPI {
+namespace DBus {
+
+
+enum class TypeEnum {
+ DBUS_CONNECTION, DBUS_OBJECT, DBUS_INTERFACE, DBUS_PREDEFINED
+};
+
+static const std::unordered_map<std::string, TypeEnum> allowedValueTypes = {
+ {"dbus_connection", TypeEnum::DBUS_CONNECTION},
+ {"dbus_object", TypeEnum::DBUS_OBJECT},
+ {"dbus_interface", TypeEnum::DBUS_INTERFACE},
+ {"dbus_predefined", TypeEnum::DBUS_PREDEFINED}
+};
+
+
+DBusAddressTranslator::DBusAddressTranslator() {}
+
+
+void DBusAddressTranslator::init() {
+ std::string fqnOfConfigFile = getCurrentBinaryFileFQN();
+ fqnOfConfigFile += DBUS_CONFIG_SUFFIX;
+
+ std::ifstream addressConfigFile;
+ addressConfigFile.open(fqnOfConfigFile.c_str());
+
+ if(addressConfigFile.is_open()) {
+ readConfigFile(addressConfigFile);
+ addressConfigFile.close();
+ }
+
+ addressConfigFile.clear();
+ std::vector<std::string> splittedConfigFQN = split(fqnOfConfigFile, '/');
+ std::string globalConfigFQN = DBUS_GLOBAL_CONFIG_ROOT + splittedConfigFQN.at(splittedConfigFQN.size() - 1);
+ addressConfigFile.open(globalConfigFQN);
+ if(addressConfigFile.is_open()) {
+ readConfigFile(addressConfigFile);
+ addressConfigFile.close();
+ }
+
+ addressConfigFile.clear();
+ addressConfigFile.open(DBUS_GLOBAL_CONFIG_FQN);
+ if(addressConfigFile.is_open()) {
+ readConfigFile(addressConfigFile);
+ addressConfigFile.close();
+ }
+}
+
+
+inline void readValue(std::string& readLine, CommonApiServiceDetails& serviceDetails) {
+ std::stringstream readStream(readLine);
+
+ std::string paramName;
+ std::string paramValue;
+
+ getline(readStream, paramName, '=');
+
+ auto typeEntry = allowedValueTypes.find(paramName);
+ if(typeEntry != allowedValueTypes.end()) {
+ getline(readStream, paramValue);
+ switch(typeEntry->second) {
+ case TypeEnum::DBUS_CONNECTION:
+ std::get<0>(std::get<0>(serviceDetails)) = paramValue;
+ break;
+ case TypeEnum::DBUS_OBJECT:
+ std::get<1>(std::get<0>(serviceDetails)) = paramValue;
+ break;
+ case TypeEnum::DBUS_INTERFACE:
+ std::get<2>(std::get<0>(serviceDetails)) = paramValue;
+ break;
+ case TypeEnum::DBUS_PREDEFINED:
+ std::get<1>(serviceDetails) = paramValue == "true" ? true : false;
+ break;
+ }
+ }
+}
+
+
+inline void reset(DBusServiceAddress& dbusServiceAddress) {
+ std::get<0>(dbusServiceAddress) = "";
+ std::get<1>(dbusServiceAddress) = "";
+ std::get<2>(dbusServiceAddress) = "";
+}
+
+inline void reset(CommonApiServiceDetails& serviceDetails) {
+ reset(std::get<0>(serviceDetails));
+ std::get<1>(serviceDetails) = false;
+}
+
+
+void DBusAddressTranslator::readConfigFile(std::ifstream& addressConfigFile) {
+ std::string currentlyParsedCommonApiAddress;
+ CommonApiServiceDetails serviceDetails;
+ reset(serviceDetails);
+
+ bool newAddressFound = false;
+
+ while (addressConfigFile.good()) {
+ std::string readLine;
+ getline(addressConfigFile, readLine);
+ const size_t readLineLength = readLine.length();
+
+ if (readLine[0] == '[' && readLine[readLineLength - 1] == ']') {
+ if (newAddressFound) {
+ fillUndefinedValues(serviceDetails, currentlyParsedCommonApiAddress);
+ commonApiAddressDetails.insert( {currentlyParsedCommonApiAddress, serviceDetails});
+ dbusToCommonApiAddress.insert( {std::get<0>(serviceDetails), currentlyParsedCommonApiAddress});
+ }
+ reset(serviceDetails);
+ currentlyParsedCommonApiAddress = readLine.substr(1, readLineLength - 2);
+ newAddressFound = commonApiAddressDetails.find(currentlyParsedCommonApiAddress) == commonApiAddressDetails.end();
+
+ } else if (newAddressFound) {
+ readValue(readLine, serviceDetails);
+ }
+ }
+ if(newAddressFound) {
+ fillUndefinedValues(serviceDetails, currentlyParsedCommonApiAddress);
+ commonApiAddressDetails.insert( {currentlyParsedCommonApiAddress, serviceDetails});
+ dbusToCommonApiAddress.insert( {std::get<0>(serviceDetails), currentlyParsedCommonApiAddress});
+ }
+}
+
+
+void DBusAddressTranslator::fillUndefinedValues(CommonApiServiceDetails& serviceDetails, const std::string& commonApiAddress) const {
+ std::string connectionName;
+ std::string objectPath;
+ std::string interfaceName;
+
+ findFallbackDBusAddress(commonApiAddress, interfaceName, connectionName, objectPath);
+
+ std::get<0>(std::get<0>(serviceDetails)) = std::get<0>(std::get<0>(serviceDetails)) == "" ? connectionName : std::get<0>(std::get<0>(serviceDetails));
+ std::get<1>(std::get<0>(serviceDetails)) = std::get<1>(std::get<0>(serviceDetails)) == "" ? objectPath : std::get<1>(std::get<0>(serviceDetails));
+ std::get<2>(std::get<0>(serviceDetails)) = std::get<2>(std::get<0>(serviceDetails)) == "" ? interfaceName : std::get<2>(std::get<0>(serviceDetails));
+}
+
+
+DBusAddressTranslator& DBusAddressTranslator::getInstance() {
+ static DBusAddressTranslator* dbusNameService_;
+ if(!dbusNameService_) {
+ dbusNameService_ = new DBusAddressTranslator();
+ dbusNameService_->init();
+ }
+ return *dbusNameService_;
+}
+
+
+void DBusAddressTranslator::searchForDBusAddress(const std::string& commonApiAddress,
+ std::string& interfaceName,
+ std::string& connectionName,
+ std::string& objectPath) {
+
+ const auto& foundAddressMapping = commonApiAddressDetails.find(commonApiAddress);
+
+ if(foundAddressMapping != commonApiAddressDetails.end()) {
+ connectionName = std::get<0>(std::get<0>(foundAddressMapping->second));
+ objectPath = std::get<1>(std::get<0>(foundAddressMapping->second));
+ interfaceName = std::get<2>(std::get<0>(foundAddressMapping->second));
+ } else {
+ findFallbackDBusAddress(commonApiAddress, interfaceName, connectionName, objectPath);
+ commonApiAddressDetails.insert( {commonApiAddress, std::make_tuple(std::make_tuple(connectionName, objectPath, interfaceName), false) } );
+ }
+}
+
+void DBusAddressTranslator::searchForCommonAddress(const std::string& interfaceName,
+ const std::string& connectionName,
+ const std::string& objectPath,
+ std::string& commonApiAddress) {
+
+ DBusServiceAddress dbusAddress(connectionName, objectPath, interfaceName);
+
+ const auto& foundAddressMapping = dbusToCommonApiAddress.find(dbusAddress);
+ if (foundAddressMapping != dbusToCommonApiAddress.end()) {
+ commonApiAddress = foundAddressMapping->second;
+ } else {
+ findFallbackCommonAddress(commonApiAddress, interfaceName, connectionName, objectPath);
+ dbusToCommonApiAddress.insert( {std::move(dbusAddress), commonApiAddress} );
+ }
+}
+
+void DBusAddressTranslator::getPredefinedInstances(const std::string& connectionName,
+ std::vector<DBusServiceAddress>& instances) {
+ instances.clear();
+ auto dbusAddress = commonApiAddressDetails.begin();
+ while (dbusAddress != commonApiAddressDetails.end()) {
+ CommonApiServiceDetails serviceDetails = dbusAddress->second;
+ if (connectionName == std::get<0>(std::get<0>(serviceDetails))
+ && true == std::get<1>(serviceDetails)) {
+ instances.push_back(std::get<0>(serviceDetails));
+ }
+ dbusAddress++;
+ }
+}
+
+void DBusAddressTranslator::findFallbackDBusAddress(const std::string& commonApiAddress,
+ std::string& interfaceName,
+ std::string& connectionName,
+ std::string& objectPath) const {
+ std::vector<std::string> parts = split(commonApiAddress, ':');
+ interfaceName = parts[1];
+ connectionName = parts[2];
+ objectPath = '/' + parts[2];
+ std::replace(objectPath.begin(), objectPath.end(), '.', '/');
+}
+
+void DBusAddressTranslator::findFallbackCommonAddress(std::string& commonApiAddress,
+ const std::string& interfaceName,
+ const std::string& connectionName,
+ const std::string& objectPath) const {
+ commonApiAddress = "local:" + interfaceName + ":" + connectionName;
+}
+
+
+}// namespace DBus
+}// namespace CommonAPI
diff --git a/src/CommonAPI/DBus/DBusAddressTranslator.h b/src/CommonAPI/DBus/DBusAddressTranslator.h
new file mode 100644
index 0000000..de38f4e
--- /dev/null
+++ b/src/CommonAPI/DBus/DBusAddressTranslator.h
@@ -0,0 +1,80 @@
+/* Copyright (C) 2013 BMW Group
+ * Author: Manfred Bathelt (manfred.bathelt@bmw.de)
+ * Author: Juergen Gehring (juergen.gehring@bmw.de)
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+
+#ifndef DBUSNAMESERVICE_H_
+#define DBUSNAMESERVICE_H_
+
+#include "DBusFunctionalHash.h"
+
+#include <algorithm>
+#include <unordered_map>
+
+
+namespace CommonAPI {
+namespace DBus {
+
+
+static const char* DBUS_CONFIG_SUFFIX = "_dbus.conf";
+static const char* DBUS_GLOBAL_CONFIG_FQN = "/etc/CommonApiDBus/dbusAddresses.conf";
+static const char* DBUS_GLOBAL_CONFIG_ROOT = "/etc/CommonApiDBus/";
+
+//connectionName, objectPath, interfaceName
+typedef std::tuple<std::string, std::string, std::string> DBusServiceAddress;
+
+//Details for a common api address key: DBusAddress, predefined service
+typedef std::tuple<DBusServiceAddress, bool> CommonApiServiceDetails;
+
+
+class DBusAddressTranslator {
+public:
+ ~DBusAddressTranslator();
+
+ static DBusAddressTranslator& getInstance();
+
+ void searchForDBusAddress(const std::string& commonApiAddress,
+ std::string& interfaceName,
+ std::string& connectionName,
+ std::string& objectPath);
+
+ void searchForCommonAddress(const std::string& interfaceName,
+ const std::string& connectionName,
+ const std::string& objectPath,
+ std::string& commonApiAddress);
+
+ void getPredefinedInstances(const std::string& connectionName,
+ std::vector<DBusServiceAddress>& instances);
+
+private:
+ DBusAddressTranslator();
+ DBusAddressTranslator(const DBusAddressTranslator&) = delete;
+ DBusAddressTranslator& operator=(const DBusAddressTranslator&) = delete;
+
+ void init();
+ void readConfigFile(std::ifstream& addressConfigFile);
+
+ void findFallbackDBusAddress(const std::string& instanceId,
+ std::string& interfaceName,
+ std::string& connectionName,
+ std::string& objectPath) const;
+
+ void findFallbackCommonAddress(std::string& instanceId,
+ const std::string& interfaceName,
+ const std::string& connectionName,
+ const std::string& objectPath) const;
+
+ void fillUndefinedValues(CommonApiServiceDetails& dbusServiceAddress, const std::string& commonApiAddress) const;
+
+ std::unordered_map<std::string, CommonApiServiceDetails> commonApiAddressDetails;
+ std::unordered_map<DBusServiceAddress, std::string> dbusToCommonApiAddress;
+};
+
+
+}// namespace DBus
+}// namespace CommonAPI
+
+#endif /* DBUSNAMESERVICE_H_ */
diff --git a/src/CommonAPI/DBus/DBusConnection.cpp b/src/CommonAPI/DBus/DBusConnection.cpp
index cbe101b..4b4c406 100644
--- a/src/CommonAPI/DBus/DBusConnection.cpp
+++ b/src/CommonAPI/DBus/DBusConnection.cpp
@@ -14,6 +14,15 @@
namespace CommonAPI {
namespace DBus {
+DBusConnectionStatusEvent::DBusConnectionStatusEvent(DBusConnection* dbusConnection):
+ dbusConnection_(dbusConnection) {
+}
+
+void DBusConnectionStatusEvent::onListenerAdded(const CancellableListener& listener) {
+ if (dbusConnection_->isConnected())
+ listener(AvailabilityStatus::AVAILABLE);
+}
+
DBusObjectPathVTable DBusConnection::libdbusObjectPathVTable_ = {
NULL, // no need to handle unregister callbacks
@@ -28,6 +37,7 @@ void DBusConnection::dispatch() {
DBusConnection::DBusConnection(BusType busType) :
busType_(busType),
libdbusConnection_(NULL),
+ dbusConnectionStatusEvent_(this),
isLibdbusSignalFilterAdded_(false),
stopDispatching_(false) {
dbus_threads_init_default();
@@ -36,6 +46,7 @@ DBusConnection::DBusConnection(BusType busType) :
DBusConnection::DBusConnection(::DBusConnection* libDbusConnection) :
busType_(WRAPPED),
libdbusConnection_(libDbusConnection),
+ dbusConnectionStatusEvent_(this),
isLibdbusSignalFilterAdded_(false),
stopDispatching_(false) {
dbus_threads_init_default();
@@ -45,7 +56,6 @@ DBusConnection::~DBusConnection() {
if (isConnected()) {
disconnect();
}
- dispatchThread_.join();
}
bool DBusConnection::connect() {
@@ -62,31 +72,44 @@ bool DBusConnection::connect(DBusError& dbusError) {
const ::DBusBusType libdbusType = static_cast<DBusBusType>(busType_);
libdbusConnection_ = dbus_bus_get_private(libdbusType, &dbusError.libdbusError_);
- if (dbusError)
+ if (dbusError) {
return false;
+ }
assert(libdbusConnection_);
dbus_connection_set_exit_on_disconnect(libdbusConnection_, false);
- dbusConnectionStatusEvent_.notifyListeners(AvailabilityStatus::AVAILABLE);
-
initLibdbusObjectPathHandlerAfterConnect();
initLibdbusSignalFilterAfterConnect();
+ stopDispatching_ = false;
dispatchThread_ = std::thread(std::bind(&DBusConnection::dispatch, this));
+ dbusConnectionStatusEvent_.notifyListeners(AvailabilityStatus::AVAILABLE);
+
return true;
}
void DBusConnection::disconnect() {
+ std::lock_guard<std::mutex> dbusConnectionLock(libdbusConnectionGuard_);
if (isConnected()) {
- stopDispatching_ = true;
if (!dbusSignalMatchRulesMap_.empty()) {
dbus_connection_remove_filter(libdbusConnection_, &onLibdbusSignalFilterThunk, this);
}
+ stopDispatching_ = true;
+
dbus_connection_close(libdbusConnection_);
+
+ //It is possible for the disconnect to be called from within a callback, i.e. from within the dispatch
+ //thread. Self-join is prevented this way.
+ if (dispatchThread_.joinable() && std::this_thread::get_id() != dispatchThread_.get_id()) {
+ dispatchThread_.join();
+ } else {
+ dispatchThread_.detach();
+ }
+
dbus_connection_unref(libdbusConnection_);
libdbusConnection_ = NULL;
@@ -98,27 +121,22 @@ bool DBusConnection::isConnected() const {
return (libdbusConnection_ != NULL);
}
-DBusConnectionStatusEvent& DBusConnection::getConnectionStatusEvent() {
+DBusProxyConnection::ConnectionStatusEvent& DBusConnection::getConnectionStatusEvent() {
return dbusConnectionStatusEvent_;
}
-const std::shared_ptr<DBusServiceRegistry>& DBusConnection::getDBusServiceRegistry() {
- if (!dbusServiceRegistry_) {
- dbusServiceRegistry_ = std::make_shared<DBusServiceRegistry>(this->shared_from_this());
- }
-
- return dbusServiceRegistry_;
-}
-
-const std::shared_ptr<DBusDaemonProxy>& DBusConnection::getDBusDaemonProxy() {
- if (!dbusDaemonProxy_) {
- dbusDaemonProxy_ = std::make_shared<DBusDaemonProxy>(this->shared_from_this());
+const std::shared_ptr<DBusServiceRegistry> DBusConnection::getDBusServiceRegistry() {
+ std::shared_ptr<DBusServiceRegistry> serviceRegistry = dbusServiceRegistry_.lock();
+ if (!serviceRegistry || dbusServiceRegistry_.expired()) {
+ serviceRegistry = std::make_shared<DBusServiceRegistry>(this->shared_from_this());
+ serviceRegistry->init();
+ dbusServiceRegistry_ = serviceRegistry;
}
- return dbusDaemonProxy_;
+ return serviceRegistry;
}
-const std::shared_ptr<DBusObjectManager>& DBusConnection::getDBusObjectManager() {
+const std::shared_ptr<DBusObjectManager> DBusConnection::getDBusObjectManager() {
if (!dbusObjectManager_) {
dbusObjectManager_ = std::make_shared<DBusObjectManager>(this->shared_from_this());
}
@@ -163,12 +181,16 @@ void DBusConnection::onLibdbusPendingCallNotifyThunk(::DBusPendingCall* libdbusP
auto dbusMessageReplyAsyncHandler = reinterpret_cast<DBusMessageReplyAsyncHandler*>(userData);
- ::DBusMessage* libdbusMessage = dbus_pending_call_steal_reply(
- libdbusPendingCall);
+ ::DBusMessage* libdbusMessage = dbus_pending_call_steal_reply(libdbusPendingCall);
const bool increaseLibdbusMessageReferenceCount = false;
DBusMessage dbusMessage(libdbusMessage, increaseLibdbusMessageReferenceCount);
+ CallStatus callStatus = CallStatus::SUCCESS;
+
+ if (!dbusMessage.isMethodReturnType()) {
+ callStatus = CallStatus::REMOTE_ERROR;
+ }
- dbusMessageReplyAsyncHandler->onDBusMessageReply(CallStatus::SUCCESS, dbusMessage);
+ dbusMessageReplyAsyncHandler->onDBusMessageReply(callStatus, dbusMessage);
// libdbus calls the Cleanup method below
dbus_pending_call_unref(libdbusPendingCall);
@@ -255,17 +277,19 @@ DBusProxyConnection::DBusSignalHandlerToken DBusConnection::addSignalMemberHandl
interfaceName,
interfaceMemberName,
interfaceMemberSignature);
+ std::lock_guard<std::mutex> dbusSignalLock(signalGuard_);
const bool isFirstSignalMemberHandler = dbusSignalHandlerTable_.find(dbusSignalHandlerPath) == dbusSignalHandlerTable_.end();
-
dbusSignalHandlerTable_.insert(DBusSignalHandlerTable::value_type(dbusSignalHandlerPath, dbusSignalHandler));
- if (isFirstSignalMemberHandler)
+ if (isFirstSignalMemberHandler) {
addLibdbusSignalMatchRule(objectPath, interfaceName, interfaceMemberName);
+ }
return dbusSignalHandlerPath;
}
void DBusConnection::removeSignalMemberHandler(const DBusSignalHandlerToken& dbusSignalHandlerToken) {
+ std::lock_guard<std::mutex> dbusSignalLock(signalGuard_);
auto equalRangeIteratorPair = dbusSignalHandlerTable_.equal_range(dbusSignalHandlerToken);
// the range can't be empty!
@@ -392,6 +416,7 @@ void DBusConnection::addLibdbusSignalMatchRule(const std::string& objectPath,
void DBusConnection::removeLibdbusSignalMatchRule(const std::string& objectPath,
const std::string& interfaceName,
const std::string& interfaceMemberName) {
+ auto selfReference = this->shared_from_this();
DBusSignalMatchRuleTuple dbusSignalMatchRuleTuple(objectPath, interfaceName, interfaceMemberName);
auto matchRuleIterator = dbusSignalMatchRulesMap_.find(dbusSignalMatchRuleTuple);
const bool matchRuleFound = matchRuleIterator != dbusSignalMatchRulesMap_.end();
@@ -412,8 +437,9 @@ void DBusConnection::removeLibdbusSignalMatchRule(const std::string& objectPath,
dbusSignalMatchRulesMap_.erase(matchRuleIterator);
const bool isLastMatchRule = dbusSignalMatchRulesMap_.empty();
- if (isLastMatchRule)
+ if (isLastMatchRule) {
dbus_connection_remove_filter(libdbusConnection_, &onLibdbusSignalFilterThunk, this);
+ }
}
void DBusConnection::initLibdbusObjectPathHandlerAfterConnect() {
@@ -482,6 +508,7 @@ void DBusConnection::initLibdbusSignalFilterAfterConnect() {
::DBusHandlerResult DBusConnection::onLibdbusSignalFilter(::DBusMessage* libdbusMessage) {
assert(libdbusMessage);
+ auto selfReference = this->shared_from_this();
// handle only signal messages
if (dbus_message_get_type(libdbusMessage) != DBUS_MESSAGE_TYPE_SIGNAL)
@@ -497,6 +524,7 @@ void DBusConnection::initLibdbusSignalFilterAfterConnect() {
assert(interfaceMemberName);
assert(interfaceMemberSignature);
+ std::lock_guard<std::mutex> dbusSignalLock(signalGuard_);
DBusSignalHandlerPath dbusSignalHandlerPath(objectPath, interfaceName, interfaceMemberName, interfaceMemberSignature);
auto equalRangeIteratorPair = dbusSignalHandlerTable_.equal_range(dbusSignalHandlerPath);
@@ -511,8 +539,9 @@ void DBusConnection::initLibdbusSignalFilterAfterConnect() {
auto dbusSignalHandlerSubscription = equalRangeIteratorPair.first;
equalRangeIteratorPair.first++;
dbusSignalHandlerTable_.erase(dbusSignalHandlerSubscription);
- } else
+ } else {
equalRangeIteratorPair.first++;
+ }
}
return DBUS_HANDLER_RESULT_HANDLED;
diff --git a/src/CommonAPI/DBus/DBusConnection.h b/src/CommonAPI/DBus/DBusConnection.h
index 763a76d..8e95296 100644
--- a/src/CommonAPI/DBus/DBusConnection.h
+++ b/src/CommonAPI/DBus/DBusConnection.h
@@ -18,11 +18,18 @@
namespace CommonAPI {
namespace DBus {
-class DBusConnection;
class DBusObjectManager;
-class DBusConnectionStatusEvent: public Event<AvailabilityStatus> {
+class DBusConnectionStatusEvent: public DBusProxyConnection::ConnectionStatusEvent {
friend class DBusConnection;
+
+ public:
+ DBusConnectionStatusEvent(DBusConnection* dbusConnection);
+
+ protected:
+ virtual void onListenerAdded(const CancellableListener& listener);
+
+ DBusConnection* dbusConnection_;
};
@@ -35,6 +42,8 @@ class DBusConnection: public DBusProxyConnection, public std::enable_shared_from
WRAPPED
};
+ DBusConnection(BusType busType);
+
inline static std::shared_ptr<DBusConnection> getBus(const BusType& busType);
inline static std::shared_ptr<DBusConnection> wrapLibDBus(::DBusConnection* libDbusConnection);
inline static std::shared_ptr<DBusConnection> getSessionBus();
@@ -55,7 +64,7 @@ class DBusConnection: public DBusProxyConnection, public std::enable_shared_from
virtual bool isConnected() const;
- virtual DBusConnectionStatusEvent& getConnectionStatusEvent();
+ virtual ConnectionStatusEvent& getConnectionStatusEvent();
virtual bool requestServiceNameAndBlock(const std::string& serviceName) const;
virtual bool releaseServiceName(const std::string& serviceName) const;
@@ -86,9 +95,8 @@ class DBusConnection: public DBusProxyConnection, public std::enable_shared_from
bool readWriteDispatch(int timeoutMilliseconds = -1);
- virtual const std::shared_ptr<DBusDaemonProxy>& getDBusDaemonProxy();
- virtual const std::shared_ptr<DBusServiceRegistry>& getDBusServiceRegistry();
- virtual const std::shared_ptr<DBusObjectManager>& getDBusObjectManager();
+ virtual const std::shared_ptr<DBusServiceRegistry> getDBusServiceRegistry();
+ virtual const std::shared_ptr<DBusObjectManager> getDBusObjectManager();
private:
void dispatch();
@@ -96,8 +104,6 @@ class DBusConnection: public DBusProxyConnection, public std::enable_shared_from
std::thread dispatchThread_;
bool stopDispatching_;
- DBusConnection(BusType busType);
-
void addLibdbusSignalMatchRule(const std::string& objectPath,
const std::string& interfaceName,
const std::string& interfaceMemberName);
@@ -114,7 +120,7 @@ class DBusConnection: public DBusProxyConnection, public std::enable_shared_from
::DBusHandlerResult onLibdbusSignalFilter(::DBusMessage* libdbusMessage);
- static void onLibdbusPendingCallNotifyThunk(::DBusPendingCall* libdbusPendingCall, void *userData);
+ static void onLibdbusPendingCallNotifyThunk(::DBusPendingCall* libdbusPendingCall, void* userData);
static void onLibdbusDataCleanup(void* userData);
static ::DBusHandlerResult onLibdbusObjectPathMessageThunk(::DBusConnection* libdbusConnection,
@@ -128,9 +134,10 @@ class DBusConnection: public DBusProxyConnection, public std::enable_shared_from
BusType busType_;
::DBusConnection* libdbusConnection_;
+ std::mutex libdbusConnectionGuard_;
+ std::mutex signalGuard_;
- std::shared_ptr<DBusDaemonProxy> dbusDaemonProxy_;
- std::shared_ptr<DBusServiceRegistry> dbusServiceRegistry_;
+ std::weak_ptr<DBusServiceRegistry> dbusServiceRegistry_;
std::shared_ptr<DBusObjectManager> dbusObjectManager_;
DBusConnectionStatusEvent dbusConnectionStatusEvent_;
@@ -152,11 +159,11 @@ class DBusConnection: public DBusProxyConnection, public std::enable_shared_from
};
std::shared_ptr<DBusConnection> DBusConnection::getBus(const BusType& busType) {
- return std::shared_ptr<DBusConnection>(new DBusConnection(busType));
+ return std::make_shared<DBusConnection>(busType);
}
std::shared_ptr<DBusConnection> DBusConnection::wrapLibDBus(::DBusConnection* libDbusConnection) {
- return std::shared_ptr<DBusConnection>(new DBusConnection(libDbusConnection));
+ return std::make_shared<DBusConnection>(libDbusConnection);
}
std::shared_ptr<DBusConnection> DBusConnection::getSessionBus() {
diff --git a/src/CommonAPI/DBus/DBusDaemonProxy.cpp b/src/CommonAPI/DBus/DBusDaemonProxy.cpp
index b2eb01c..f18d2ac 100644
--- a/src/CommonAPI/DBus/DBusDaemonProxy.cpp
+++ b/src/CommonAPI/DBus/DBusDaemonProxy.cpp
@@ -1,112 +1,151 @@
-/* Copyright (C) 2013 BMW Group
- * Author: Manfred Bathelt (manfred.bathelt@bmw.de)
- * Author: Juergen Gehring (juergen.gehring@bmw.de)
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-#include "DBusDaemonProxy.h"
-#include "DBusProxyHelper.h"
-
-
-namespace CommonAPI {
-namespace DBus {
-
-DBusDaemonProxy::DBusDaemonProxy(const std::shared_ptr<DBusProxyConnection>& connection):
- DBusProxy("org.freedesktop.DBus", "/org/freedesktop/DBus", getInterfaceName(), connection, true),
- nameOwnerChangedEvent_(*this, "NameOwnerChanged", "sss") {
-}
-
-const char* DBusDaemonProxy::getInterfaceName() const {
- return "org.freedesktop.DBus";
-}
-
-DBusDaemonProxy::NameOwnerChangedEvent& DBusDaemonProxy::getNameOwnerChangedEvent() {
- return nameOwnerChangedEvent_;
-}
-
-void DBusDaemonProxy::listNames(CommonAPI::CallStatus& callStatus, std::vector<std::string>& busNames) const {
- DBusMessage dbusMethodCall = createMethodCall("ListNames", "");
-
- DBusError dbusError;
- DBusMessage dbusMessageReply = getDBusConnection()->sendDBusMessageWithReplyAndBlock(
- dbusMethodCall,
- dbusError);
-
- if (dbusError || !dbusMessageReply.isMethodReturnType()) {
- callStatus = CallStatus::REMOTE_ERROR;
- return;
- }
-
- DBusInputStream inputStream(dbusMessageReply);
- const bool success = DBusSerializableArguments<std::vector<std::string>>::deserialize(inputStream, busNames);
- if (!success) {
- callStatus = CallStatus::REMOTE_ERROR;
- return;
- }
- callStatus = CallStatus::SUCCESS;
-
-}
-
-std::future<CallStatus> DBusDaemonProxy::listNamesAsync(ListNamesAsyncCallback listNamesAsyncCallback) const {
- DBusMessage dbusMessage = createMethodCall("ListNames", "");
-
- return getDBusConnection()->sendDBusMessageWithReplyAsync(
- dbusMessage,
- DBusProxyAsyncCallbackHandler<std::vector<std::string>>::create(listNamesAsyncCallback));
-}
-
-void DBusDaemonProxy::nameHasOwner(const std::string& busName, CommonAPI::CallStatus& callStatus, bool& hasOwner) const {
-
- DBusMessage dbusMethodCall = createMethodCall("NameHasOwner", "s");
-
- DBusOutputStream outputStream(dbusMethodCall);
- bool success = DBusSerializableArguments<std::string>::serialize(outputStream, busName);
- if (!success) {
- callStatus = CallStatus::OUT_OF_MEMORY;
- return;
- }
- outputStream.flush();
-
- DBusError dbusError;
- DBusMessage dbusMessageReply = getDBusConnection()->sendDBusMessageWithReplyAndBlock(
- dbusMethodCall,
- dbusError);
- if (dbusError || !dbusMessageReply.isMethodReturnType()) {
- callStatus = CallStatus::REMOTE_ERROR;
- return;
- }
-
- DBusInputStream inputStream(dbusMessageReply);
- success = DBusSerializableArguments<bool>::deserialize(inputStream, hasOwner);
- if (!success) {
- callStatus = CallStatus::REMOTE_ERROR;
- return;
- }
- callStatus = CallStatus::SUCCESS;
-
-}
-
-std::future<CallStatus> DBusDaemonProxy::nameHasOwnerAsync(const std::string& busName, NameHasOwnerAsyncCallback nameHasOwnerAsyncCallback) const {
-
- DBusMessage dbusMessage = createMethodCall("NameHasOwner", "s");
-
- DBusOutputStream outputStream(dbusMessage);
- const bool success = DBusSerializableArguments<std::string>::serialize(outputStream, busName);
- if (!success) {
- std::promise<CallStatus> promise;
- promise.set_value(CallStatus::OUT_OF_MEMORY);
- return promise.get_future();
- }
- outputStream.flush();
-
- return getDBusConnection()->sendDBusMessageWithReplyAsync(
- dbusMessage,
- DBusProxyAsyncCallbackHandler<bool>::create(nameHasOwnerAsyncCallback));
-
-}
-
-void DBusDaemonProxy::getOwnVersion(uint16_t& ownVersionMajor, uint16_t& ownVersionMinor) const {
-}
-
-} // namespace DBus
-} // namespace CommonAPI
+/* Copyright (C) 2013 BMW Group
+ * Author: Manfred Bathelt (manfred.bathelt@bmw.de)
+ * Author: Juergen Gehring (juergen.gehring@bmw.de)
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+#include "DBusDaemonProxy.h"
+#include "DBusProxyHelper.h"
+
+
+namespace CommonAPI {
+namespace DBus {
+
+StaticInterfaceVersionAttribute::StaticInterfaceVersionAttribute(const uint32_t& majorValue, const uint32_t& minorValue):
+ version_(majorValue, minorValue) {
+}
+
+CallStatus StaticInterfaceVersionAttribute::getValue(Version& version) const {
+ version = version_;
+
+ return CallStatus::SUCCESS;
+}
+
+std::future<CallStatus> StaticInterfaceVersionAttribute::getValueAsync(AttributeAsyncCallback attributeAsyncCallback) {
+ attributeAsyncCallback(CallStatus::SUCCESS, version_);
+
+ std::promise<CallStatus> versionPromise;
+ versionPromise.set_value(CallStatus::SUCCESS);
+
+ return versionPromise.get_future();
+}
+
+
+StaticInterfaceVersionAttribute DBusDaemonProxy::interfaceVersionAttribute_(1, 0);
+
+DBusDaemonProxy::DBusDaemonProxy(const std::shared_ptr<DBusProxyConnection>& dbusConnection):
+ DBusProxyBase(getInterfaceId(), "org.freedesktop.DBus", "/org/freedesktop/DBus", dbusConnection),
+ nameOwnerChangedEvent_(*this, "NameOwnerChanged", "sss") {
+}
+
+bool DBusDaemonProxy::isAvailable() const {
+ return getDBusConnection()->isConnected();
+}
+
+ProxyStatusEvent& DBusDaemonProxy::getProxyStatusEvent() {
+ return getDBusConnection()->getConnectionStatusEvent();
+}
+
+InterfaceVersionAttribute& DBusDaemonProxy::getInterfaceVersionAttribute() {
+ return interfaceVersionAttribute_;
+}
+
+DBusDaemonProxy::NameOwnerChangedEvent& DBusDaemonProxy::getNameOwnerChangedEvent() {
+ return nameOwnerChangedEvent_;
+}
+
+void DBusDaemonProxy::listNames(CommonAPI::CallStatus& callStatus, std::vector<std::string>& busNames) const {
+ DBusMessage dbusMethodCall = createMethodCall("ListNames", "");
+
+ DBusError dbusError;
+ DBusMessage dbusMessageReply = getDBusConnection()->sendDBusMessageWithReplyAndBlock(dbusMethodCall, dbusError);
+
+ if (dbusError || !dbusMessageReply.isMethodReturnType()) {
+ callStatus = CallStatus::REMOTE_ERROR;
+ return;
+ }
+
+ DBusInputStream inputStream(dbusMessageReply);
+ const bool success = DBusSerializableArguments<std::vector<std::string>>::deserialize(inputStream, busNames);
+ if (!success) {
+ callStatus = CallStatus::REMOTE_ERROR;
+ return;
+ }
+
+ callStatus = CallStatus::SUCCESS;
+}
+
+std::future<CallStatus> DBusDaemonProxy::listNamesAsync(ListNamesAsyncCallback listNamesAsyncCallback) const {
+ DBusMessage dbusMessage = createMethodCall("ListNames", "");
+
+ return getDBusConnection()->sendDBusMessageWithReplyAsync(
+ dbusMessage,
+ DBusProxyAsyncCallbackHandler<std::vector<std::string>>::create(listNamesAsyncCallback));
+}
+
+void DBusDaemonProxy::nameHasOwner(const std::string& busName, CommonAPI::CallStatus& callStatus, bool& hasOwner) const {
+ DBusMessage dbusMethodCall = createMethodCall("NameHasOwner", "s");
+
+ DBusOutputStream outputStream(dbusMethodCall);
+ bool success = DBusSerializableArguments<std::string>::serialize(outputStream, busName);
+ if (!success) {
+ callStatus = CallStatus::OUT_OF_MEMORY;
+ return;
+ }
+ outputStream.flush();
+
+ DBusError dbusError;
+ DBusMessage dbusMessageReply = getDBusConnection()->sendDBusMessageWithReplyAndBlock(
+ dbusMethodCall,
+ dbusError);
+ if (dbusError || !dbusMessageReply.isMethodReturnType()) {
+ callStatus = CallStatus::REMOTE_ERROR;
+ return;
+ }
+
+ DBusInputStream inputStream(dbusMessageReply);
+ success = DBusSerializableArguments<bool>::deserialize(inputStream, hasOwner);
+ if (!success) {
+ callStatus = CallStatus::REMOTE_ERROR;
+ return;
+ }
+ callStatus = CallStatus::SUCCESS;
+}
+
+std::future<CallStatus> DBusDaemonProxy::nameHasOwnerAsync(const std::string& busName, NameHasOwnerAsyncCallback nameHasOwnerAsyncCallback) const {
+ DBusMessage dbusMessage = createMethodCall("NameHasOwner", "s");
+
+ DBusOutputStream outputStream(dbusMessage);
+ const bool success = DBusSerializableArguments<std::string>::serialize(outputStream, busName);
+ if (!success) {
+ std::promise<CallStatus> promise;
+ promise.set_value(CallStatus::OUT_OF_MEMORY);
+ return promise.get_future();
+ }
+ outputStream.flush();
+
+ return getDBusConnection()->sendDBusMessageWithReplyAsync(
+ dbusMessage,
+ DBusProxyAsyncCallbackHandler<bool>::create(nameHasOwnerAsyncCallback));
+}
+
+std::future<CallStatus> DBusDaemonProxy::getManagedObjectsAsync(const std::string& forDBusServiceName, GetManagedObjectsAsyncCallback callback) const {
+ // resolve remote objects
+ auto dbusMethodCallMessage = DBusMessage::createMethodCall(
+ forDBusServiceName,
+ "/",
+ "org.freedesktop.DBus.ObjectManager",
+ "GetManagedObjects",
+ "");
+
+ const int timeoutMilliseconds = 100;
+
+ return getDBusConnection()->sendDBusMessageWithReplyAsync(
+ dbusMethodCallMessage,
+ DBusProxyAsyncCallbackHandler<DBusObjectToInterfaceDict>::create(callback),
+ timeoutMilliseconds);
+}
+
+
+} // namespace DBus
+} // namespace CommonAPI
diff --git a/src/CommonAPI/DBus/DBusDaemonProxy.h b/src/CommonAPI/DBus/DBusDaemonProxy.h
index da69e2e..aeb2feb 100644
--- a/src/CommonAPI/DBus/DBusDaemonProxy.h
+++ b/src/CommonAPI/DBus/DBusDaemonProxy.h
@@ -1,54 +1,76 @@
-/* Copyright (C) 2013 BMW Group
- * Author: Manfred Bathelt (manfred.bathelt@bmw.de)
- * Author: Juergen Gehring (juergen.gehring@bmw.de)
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-#ifndef COMMONAPI_DBUS_DBUS_DAEMON_PROXY_H_
-#define COMMONAPI_DBUS_DBUS_DAEMON_PROXY_H_
-
-#include "DBusProxy.h"
-#include "DBusEvent.h"
-
-#include "DBusServiceStatusEvent.h"
-
-#include <string>
-#include <vector>
-
-namespace CommonAPI {
-namespace DBus {
-
-class DBusServiceStatusEvent;
-
-class DBusDaemonProxy: public DBusProxy {
-
- public:
- typedef Event<std::string, std::string, std::string> NameOwnerChangedEvent;
- typedef std::function<void(const CommonAPI::CallStatus&, std::vector<std::string>)> ListNamesAsyncCallback;
- typedef std::function<void(const CommonAPI::CallStatus&, bool)> NameHasOwnerAsyncCallback;
-
-
- DBusDaemonProxy(const std::shared_ptr<DBusProxyConnection>& connection);
-
- const char* getInterfaceName() const;
-
- NameOwnerChangedEvent& getNameOwnerChangedEvent();
-
- void listNames(CommonAPI::CallStatus& callStatus, std::vector<std::string>& busNames) const;
- std::future<CallStatus> listNamesAsync(ListNamesAsyncCallback listNamesAsyncCallback) const;
-
- void nameHasOwner(const std::string& busName, CommonAPI::CallStatus& callStatus, bool& hasOwner) const;
- std::future<CallStatus> nameHasOwnerAsync(const std::string& busName, NameHasOwnerAsyncCallback nameHasOwnerAsyncCallback) const;
-
- protected:
- void getOwnVersion(uint16_t& ownVersionMajor, uint16_t& ownVersionMinor) const;
-
- private:
- DBusEvent<NameOwnerChangedEvent> nameOwnerChangedEvent_;
-
-};
-
-} // namespace DBus
-} // namespace CommonAPI
-
-#endif // COMMONAPI_DBUS_DBUS_DAEMON_PROXY_H_
+/* Copyright (C) 2013 BMW Group
+ * Author: Manfred Bathelt (manfred.bathelt@bmw.de)
+ * Author: Juergen Gehring (juergen.gehring@bmw.de)
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+#ifndef COMMONAPI_DBUS_DBUS_DAEMON_PROXY_H_
+#define COMMONAPI_DBUS_DBUS_DAEMON_PROXY_H_
+
+#include "DBusProxyBase.h"
+#include "DBusEvent.h"
+
+#include <functional>
+#include <string>
+#include <vector>
+
+
+namespace CommonAPI {
+namespace DBus {
+
+class StaticInterfaceVersionAttribute: public InterfaceVersionAttribute {
+ public:
+ StaticInterfaceVersionAttribute(const uint32_t& majorValue, const uint32_t& minorValue);
+
+ CallStatus getValue(Version& version) const;
+ std::future<CallStatus> getValueAsync(AttributeAsyncCallback attributeAsyncCallback);
+
+ private:
+ Version version_;
+};
+
+
+class DBusDaemonProxy: public DBusProxyBase {
+ public:
+ typedef Event<std::string, std::string, std::string> NameOwnerChangedEvent;
+
+ typedef std::unordered_map<std::string, int> PropertyDictStub;
+ typedef std::unordered_map<std::string, PropertyDictStub> InterfaceToPropertyDict;
+ typedef std::unordered_map<std::string, InterfaceToPropertyDict> DBusObjectToInterfaceDict;
+
+ typedef std::function<void(const CommonAPI::CallStatus&, std::vector<std::string>)> ListNamesAsyncCallback;
+ typedef std::function<void(const CommonAPI::CallStatus&, bool)> NameHasOwnerAsyncCallback;
+ typedef std::function<void(const CommonAPI::CallStatus&, DBusObjectToInterfaceDict)> GetManagedObjectsAsyncCallback;
+
+
+ DBusDaemonProxy(const std::shared_ptr<DBusProxyConnection>& dbusConnection);
+
+ virtual bool isAvailable() const;
+ virtual ProxyStatusEvent& getProxyStatusEvent();
+ virtual InterfaceVersionAttribute& getInterfaceVersionAttribute();
+
+ static inline const char* getInterfaceId();
+
+ NameOwnerChangedEvent& getNameOwnerChangedEvent();
+
+ void listNames(CommonAPI::CallStatus& callStatus, std::vector<std::string>& busNames) const;
+ std::future<CallStatus> listNamesAsync(ListNamesAsyncCallback listNamesAsyncCallback) const;
+
+ void nameHasOwner(const std::string& busName, CommonAPI::CallStatus& callStatus, bool& hasOwner) const;
+ std::future<CallStatus> nameHasOwnerAsync(const std::string& busName, NameHasOwnerAsyncCallback nameHasOwnerAsyncCallback) const;
+
+ std::future<CallStatus> getManagedObjectsAsync(const std::string& forDBusServiceName, GetManagedObjectsAsyncCallback) const;
+
+ private:
+ DBusEvent<NameOwnerChangedEvent> nameOwnerChangedEvent_;
+ static StaticInterfaceVersionAttribute interfaceVersionAttribute_;
+};
+
+const char* DBusDaemonProxy::getInterfaceId() {
+ return "org.freedesktop.DBus";
+}
+
+} // namespace DBus
+} // namespace CommonAPI
+
+#endif // COMMONAPI_DBUS_DBUS_DAEMON_PROXY_H_
diff --git a/src/CommonAPI/DBus/DBusEvent.h b/src/CommonAPI/DBus/DBusEvent.h
index 1421639..46ba4ab 100644
--- a/src/CommonAPI/DBus/DBusEvent.h
+++ b/src/CommonAPI/DBus/DBusEvent.h
@@ -10,16 +10,17 @@
#include "DBusProxyConnection.h"
#include "DBusMessage.h"
#include "DBusSerializableArguments.h"
+#include "DBusHelper.h"
#include <CommonAPI/Event.h>
namespace CommonAPI {
namespace DBus {
-class DBusProxy;
+class DBusProxyBase;
-template <typename _EventType, typename _DBusProxy = DBusProxy>
+template <typename _EventType, typename _DBusProxy = DBusProxyBase>
class DBusEvent: public _EventType, public DBusProxyConnection::DBusSignalHandler {
public:
typedef typename _EventType::ArgumentsTuple ArgumentsTuple;
diff --git a/src/CommonAPI/DBus/DBusFactory.cpp b/src/CommonAPI/DBus/DBusFactory.cpp
index 62090b5..de74ef1 100644
--- a/src/CommonAPI/DBus/DBusFactory.cpp
+++ b/src/CommonAPI/DBus/DBusFactory.cpp
@@ -1,116 +1,163 @@
-/* Copyright (C) 2013 BMW Group
- * Author: Manfred Bathelt (manfred.bathelt@bmw.de)
- * Author: Juergen Gehring (juergen.gehring@bmw.de)
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-#include "DBusProxy.h"
-#include "DBusConnection.h"
-#include "DBusFactory.h"
-#include "DBusServiceRegistry.h"
-#include "DBusUtils.h"
-
-#include <algorithm>
-#include <cassert>
-#include <sstream>
-#include <unordered_map>
-#include <vector>
-
-namespace CommonAPI {
-namespace DBus {
-
-std::unordered_map<std::string, DBusProxyFactoryFunction>* registeredProxyFactoryFunctions_;
-std::unordered_map<std::string, DBusAdapterFactoryFunction>* registeredAdapterFactoryFunctions_;
-
-
-void DBusFactory::registerProxyFactoryMethod(std::string interfaceName, DBusProxyFactoryFunction proxyFactoryMethod) {
- if(!registeredProxyFactoryFunctions_) {
- registeredProxyFactoryFunctions_ = new std::unordered_map<std::string, DBusProxyFactoryFunction>();
- }
- registeredProxyFactoryFunctions_->insert({interfaceName, proxyFactoryMethod});
-}
-
-void DBusFactory::registerAdapterFactoryMethod(std::string interfaceName, DBusAdapterFactoryFunction adapterFactoryMethod) {
- if(!registeredAdapterFactoryFunctions_) {
- registeredAdapterFactoryFunctions_ = new std::unordered_map<std::string, DBusAdapterFactoryFunction>();
- }
- registeredAdapterFactoryFunctions_->insert({interfaceName, adapterFactoryMethod});
-}
-
-
-
-DBusFactory::DBusFactory(std::shared_ptr<Runtime> runtime, const MiddlewareInfo* middlewareInfo) :
- CommonAPI::Factory(runtime, middlewareInfo),
- dbusConnection_(CommonAPI::DBus::DBusConnection::getSessionBus()),
- acquiredConnectionName_("") {
- dbusConnection_->connect();
-}
-
-DBusFactory::~DBusFactory() {
-}
-
-
-std::vector<std::string> DBusFactory::getAvailableServiceInstances(const std::string& serviceInterfaceName,
- const std::string& serviceDomainName) {
- return dbusConnection_->getDBusServiceRegistry()->getAvailableServiceInstances(serviceInterfaceName, serviceDomainName);
-}
-
-
-bool DBusFactory::isServiceInstanceAlive(const std::string& serviceInstanceId,
- const std::string& serviceInterfaceName,
- const std::string& serviceDomainName) {
-
- return dbusConnection_->getDBusServiceRegistry()->isServiceInstanceAlive(serviceInstanceId, serviceInterfaceName, serviceDomainName);
-}
-
-std::shared_ptr<Proxy> DBusFactory::createProxy(const char* interfaceName, const std::string& participantId, const std::string& domain) {
- std::string connectionName;
- std::string objectPath;
-
- findFallbackInstanceIdMapping(participantId, connectionName, objectPath);
-
- if(!registeredProxyFactoryFunctions_) {
- registeredProxyFactoryFunctions_ = new std::unordered_map<std::string, DBusProxyFactoryFunction> {};
- }
-
- for (auto it = registeredProxyFactoryFunctions_->begin(); it != registeredProxyFactoryFunctions_->end(); ++it) {
- if(it->first == interfaceName) {
- return (it->second)(connectionName.c_str(), objectPath.c_str(), dbusConnection_);
- }
- }
-
- return NULL;
-}
-
-std::shared_ptr<StubAdapter> DBusFactory::createAdapter(std::shared_ptr<StubBase> stubBase, const char* interfaceName, const std::string& participantId, const std::string& domain) {
- assert(dbusConnection_->isConnected());
-
- std::string connectionName;
- std::string objectPath;
- findFallbackInstanceIdMapping(participantId, connectionName, objectPath);
-
- if(acquiredConnectionName_ == "") {
- dbusConnection_->requestServiceNameAndBlock(connectionName);
- acquiredConnectionName_ = connectionName;
- } else if (acquiredConnectionName_ != connectionName) {
- return NULL;
- }
-
- if(!registeredAdapterFactoryFunctions_) {
- registeredAdapterFactoryFunctions_ = new std::unordered_map<std::string, DBusAdapterFactoryFunction> {};
- }
-
- for (auto it = registeredAdapterFactoryFunctions_->begin(); it != registeredAdapterFactoryFunctions_->end(); ++it) {
- if(it->first == interfaceName) {
- std::shared_ptr<DBusStubAdapter> dbusStubAdapter = (it->second)(connectionName.c_str(), objectPath.c_str(), dbusConnection_, stubBase);
- dbusStubAdapter->init();
- return dbusStubAdapter;
- }
- }
-
- return NULL;
-}
-
-
-} // namespace DBus
-} // namespace CommonAPI
+/* Copyright (C) 2013 BMW Group
+ * Author: Manfred Bathelt (manfred.bathelt@bmw.de)
+ * Author: Juergen Gehring (juergen.gehring@bmw.de)
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+#include "DBusProxy.h"
+#include "DBusConnection.h"
+#include "DBusFactory.h"
+#include "DBusAddressTranslator.h"
+#include "DBusServiceRegistry.h"
+#include "DBusUtils.h"
+
+#include <algorithm>
+#include <cassert>
+#include <sstream>
+#include <unordered_map>
+#include <vector>
+
+namespace CommonAPI {
+namespace DBus {
+
+std::unordered_map<std::string, DBusProxyFactoryFunction>* registeredProxyFactoryFunctions_;
+std::unordered_map<std::string, DBusAdapterFactoryFunction>* registeredAdapterFactoryFunctions_;
+
+
+void DBusFactory::registerProxyFactoryMethod(std::string interfaceName, DBusProxyFactoryFunction proxyFactoryMethod) {
+ if(!registeredProxyFactoryFunctions_) {
+ registeredProxyFactoryFunctions_ = new std::unordered_map<std::string, DBusProxyFactoryFunction>();
+ }
+ registeredProxyFactoryFunctions_->insert({interfaceName, proxyFactoryMethod});
+}
+
+void DBusFactory::registerAdapterFactoryMethod(std::string interfaceName, DBusAdapterFactoryFunction adapterFactoryMethod) {
+ if(!registeredAdapterFactoryFunctions_) {
+ registeredAdapterFactoryFunctions_ = new std::unordered_map<std::string, DBusAdapterFactoryFunction>();
+ }
+ registeredAdapterFactoryFunctions_->insert({interfaceName, adapterFactoryMethod});
+}
+
+
+
+DBusFactory::DBusFactory(std::shared_ptr<Runtime> runtime, const MiddlewareInfo* middlewareInfo) :
+ CommonAPI::Factory(runtime, middlewareInfo),
+ dbusConnection_(CommonAPI::DBus::DBusConnection::getSessionBus()),
+ acquiredConnectionName_("") {
+ dbusConnection_->connect();
+}
+
+
+DBusFactory::~DBusFactory() {
+}
+
+
+std::vector<std::string> DBusFactory::getAvailableServiceInstances(const std::string& serviceName,
+ const std::string& domainName) {
+ return dbusConnection_->getDBusServiceRegistry()->getAvailableServiceInstances(serviceName, domainName);
+}
+
+
+bool DBusFactory::isServiceInstanceAlive(const std::string& serviceAddress) {
+ std::vector<std::string> parts = split(serviceAddress, ':');
+ assert(parts[0] == "local");
+
+ std::string interfaceName;
+ std::string connectionName;
+ std::string objectPath;
+ DBusAddressTranslator::getInstance().searchForDBusAddress(serviceAddress, interfaceName, connectionName, objectPath);
+
+ return dbusConnection_->getDBusServiceRegistry()->isServiceInstanceAlive(interfaceName, connectionName, objectPath);
+}
+
+
+bool DBusFactory::isServiceInstanceAlive(const std::string& participantId,
+ const std::string& serviceName,
+ const std::string& domainName) {
+ std::string serviceAddress = domainName + ":" + serviceName + ":" + participantId;
+ return isServiceInstanceAlive(serviceAddress);
+}
+
+
+std::shared_ptr<Proxy> DBusFactory::createProxy(const char* interfaceId,
+ const std::string& participantId,
+ const std::string& serviceName,
+ const std::string& domain) {
+ std::string commonApiAddress = domain + ":" + serviceName + ":" + participantId;
+
+ std::string interfaceName;
+ std::string connectionName;
+ std::string objectPath;
+
+ DBusAddressTranslator::getInstance().searchForDBusAddress(commonApiAddress, interfaceName, connectionName, objectPath);
+
+ if(!registeredProxyFactoryFunctions_) {
+ registeredProxyFactoryFunctions_ = new std::unordered_map<std::string, DBusProxyFactoryFunction> {};
+ }
+
+ for (auto it = registeredProxyFactoryFunctions_->begin(); it != registeredProxyFactoryFunctions_->end(); ++it) {
+ if(it->first == interfaceId) {
+ return (it->second)(commonApiAddress, interfaceName, connectionName, objectPath, dbusConnection_);
+ }
+ }
+
+ return NULL;
+}
+
+bool DBusFactory::registerAdapter(std::shared_ptr<StubBase> stubBase,
+ const char* interfaceId,
+ const std::string& participantId,
+ const std::string& serviceName,
+ const std::string& domain) {
+ assert(dbusConnection_->isConnected());
+
+ std::string commonApiAddress = domain + ":" + serviceName + ":" + participantId;
+
+ std::string interfaceName;
+ std::string connectionName;
+ std::string objectPath;
+
+ DBusAddressTranslator::getInstance().searchForDBusAddress(commonApiAddress, interfaceName, connectionName, objectPath);
+
+ if(acquiredConnectionName_ == "") {
+ dbusConnection_->requestServiceNameAndBlock(connectionName);
+ acquiredConnectionName_ = connectionName;
+ } else if (acquiredConnectionName_ != connectionName) {
+ return NULL;
+ }
+
+ if(!registeredAdapterFactoryFunctions_) {
+ registeredAdapterFactoryFunctions_ = new std::unordered_map<std::string, DBusAdapterFactoryFunction> {};
+ }
+
+ for (auto it = registeredAdapterFactoryFunctions_->begin(); it != registeredAdapterFactoryFunctions_->end(); ++it) {
+ if(it->first == interfaceId) {
+ std::shared_ptr<DBusStubAdapter> dbusStubAdapter = (it->second)(commonApiAddress, interfaceName, connectionName, objectPath, dbusConnection_, stubBase);
+ if(!dbusStubAdapter) {
+ return false;
+ }
+ std::string address = domain + ":" + serviceName + ":" + participantId;
+ if(registeredServices_.insert( {std::move(address), dbusStubAdapter} ).second) {
+ dbusStubAdapter->init();
+ return true;
+ }
+ }
+ }
+
+ return false;
+}
+
+bool DBusFactory::unregisterService(const std::string& participantId, const std::string& serviceName, const std::string& domain) {
+ std::string commonApiAddress = domain + ":" + serviceName + ":" + participantId;
+ auto foundStubAdapter = registeredServices_.find(commonApiAddress);
+ if(foundStubAdapter != registeredServices_.end()) {
+ std::shared_ptr<DBusStubAdapter> stubAdapter = foundStubAdapter->second;
+ stubAdapter->deinit();
+ return registeredServices_.erase(commonApiAddress);
+ }
+ return false;
+}
+
+
+} // namespace DBus
+} // namespace CommonAPI
diff --git a/src/CommonAPI/DBus/DBusFactory.h b/src/CommonAPI/DBus/DBusFactory.h
index e89b519..a3edfdc 100644
--- a/src/CommonAPI/DBus/DBusFactory.h
+++ b/src/CommonAPI/DBus/DBusFactory.h
@@ -1,47 +1,61 @@
-/* Copyright (C) 2013 BMW Group
- * Author: Manfred Bathelt (manfred.bathelt@bmw.de)
- * Author: Juergen Gehring (juergen.gehring@bmw.de)
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-#ifndef COMMONAPI_DBUS_DBUS_FACTORY_H_
-#define COMMONAPI_DBUS_DBUS_FACTORY_H_
-
-#include <thread>
-
-#include <CommonAPI/Factory.h>
-
-#include "CommonAPI/DBus/DBusStubAdapter.h"
-#include "DBusConnection.h"
-
-namespace CommonAPI {
-namespace DBus {
-
-typedef std::shared_ptr<DBusProxy> (*DBusProxyFactoryFunction) (const char* busName, const char* objectPath, std::shared_ptr<DBusProxyConnection> dbusProxyConnection);
-typedef std::shared_ptr<DBusStubAdapter> (*DBusAdapterFactoryFunction) (std::string busName, std::string objectPath, std::shared_ptr<DBusProxyConnection> dbusProxyConnection, std::shared_ptr<StubBase> stubBase);
-
-class DBusFactory: public Factory {
- public:
- DBusFactory(std::shared_ptr<Runtime> runtime, const MiddlewareInfo* middlewareInfo);
- virtual ~DBusFactory();
-
- static void registerProxyFactoryMethod(std::string interfaceName, DBusProxyFactoryFunction proxyFactoryFunction);
- static void registerAdapterFactoryMethod(std::string interfaceName, DBusAdapterFactoryFunction adapterFactoryMethod);
-
- virtual std::vector<std::string> getAvailableServiceInstances(const std::string& serviceInterfaceName, const std::string& serviceDomainName = "local");
-
- virtual bool isServiceInstanceAlive(const std::string& serviceInstanceID, const std::string& serviceInterfaceName, const std::string& serviceDomainName = "local");
-
- virtual std::shared_ptr<Proxy> createProxy(const char* interfaceName, const std::string& participantId, const std::string& domain);
-
- virtual std::shared_ptr<StubAdapter> createAdapter(std::shared_ptr<StubBase> stubBase, const char* interfaceName, const std::string& participantId, const std::string& domain);
-
- private:
- std::shared_ptr<CommonAPI::DBus::DBusConnection> dbusConnection_;
- std::string acquiredConnectionName_;
-};
-
-} // namespace DBus
-} // namespace CommonAPI
-
-#endif // COMMONAPI_DBUS_DBUS_FACTORY_H_
+/* Copyright (C) 2013 BMW Group
+ * Author: Manfred Bathelt (manfred.bathelt@bmw.de)
+ * Author: Juergen Gehring (juergen.gehring@bmw.de)
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+#ifndef COMMONAPI_DBUS_DBUS_FACTORY_H_
+#define COMMONAPI_DBUS_DBUS_FACTORY_H_
+
+#include <thread>
+
+#include <CommonAPI/Factory.h>
+
+#include "CommonAPI/DBus/DBusStubAdapter.h"
+#include "DBusConnection.h"
+#include "DBusProxy.h"
+
+namespace CommonAPI {
+namespace DBus {
+
+typedef std::shared_ptr<DBusProxy> (*DBusProxyFactoryFunction) (const std::string& commonApiAddress,
+ const std::string& interfaceName,
+ const std::string& busName,
+ const std::string& objectPath,
+ const std::shared_ptr<DBusProxyConnection>& dbusProxyConnection);
+typedef std::shared_ptr<DBusStubAdapter> (*DBusAdapterFactoryFunction) (const std::string& commonApiAddress,
+ const std::string& interfaceName,
+ const std::string& busName,
+ const std::string& objectPath,
+ const std::shared_ptr<DBusProxyConnection>& dbusProxyConnection,
+ const std::shared_ptr<StubBase>& stubBase);
+
+class DBusFactory: public Factory {
+ public:
+ DBusFactory(std::shared_ptr<Runtime> runtime, const MiddlewareInfo* middlewareInfo);
+ virtual ~DBusFactory();
+
+ static void registerProxyFactoryMethod(std::string interfaceName, DBusProxyFactoryFunction proxyFactoryFunction);
+ static void registerAdapterFactoryMethod(std::string interfaceName, DBusAdapterFactoryFunction adapterFactoryMethod);
+
+ virtual std::vector<std::string> getAvailableServiceInstances(const std::string& serviceInterfaceName, const std::string& serviceDomainName = "local");
+
+ virtual bool isServiceInstanceAlive(const std::string& serviceAddress);
+ virtual bool isServiceInstanceAlive(const std::string& participantId, const std::string& serviceName, const std::string& domain = "local");
+
+ virtual bool unregisterService(const std::string& participantId, const std::string& serviceName, const std::string& domain = "local");
+
+ protected:
+ virtual std::shared_ptr<Proxy> createProxy(const char* interfaceId, const std::string& participantId, const std::string& serviceName, const std::string& domain);
+ virtual bool registerAdapter(std::shared_ptr<StubBase> stubBase, const char* interfaceId, const std::string& participantId, const std::string& serviceName, const std::string& domain);
+
+ private:
+ std::shared_ptr<CommonAPI::DBus::DBusConnection> dbusConnection_;
+ std::string acquiredConnectionName_;
+ std::unordered_map<std::string, std::shared_ptr<DBusStubAdapter>> registeredServices_;
+};
+
+} // namespace DBus
+} // namespace CommonAPI
+
+#endif // COMMONAPI_DBUS_DBUS_FACTORY_H_
diff --git a/src/CommonAPI/DBus/DBusFunctionalHash.cpp b/src/CommonAPI/DBus/DBusFunctionalHash.cpp
index 2369446..a4c82fd 100644
--- a/src/CommonAPI/DBus/DBusFunctionalHash.cpp
+++ b/src/CommonAPI/DBus/DBusFunctionalHash.cpp
@@ -60,6 +60,21 @@ size_t hash< tuple<string, string, string> >::operator()(const tuple<string, str
return static_cast<size_t>(seed);
}
+size_t hash< tuple<string, string, string, bool> >::operator()(const tuple<string, string, string, bool>& t) const {
+ const string& a = get<0>(t);
+ const string& b = get<1>(t);
+ const string& c = get<2>(t);
+ const bool d = get<3>(t);
+
+ uint32_t seed = static_cast<uint32_t>(SMHASHER_SEED_VALUE);
+ MurmurHash3_x86_32(a.c_str(), a.length(), seed, &seed);
+ MurmurHash3_x86_32(b.c_str(), b.length(), seed, &seed);
+ MurmurHash3_x86_32(c.c_str(), c.length(), seed, &seed);
+ seed + (int)d;
+
+ return static_cast<size_t>(seed);
+}
+
size_t hash< tuple<string, string, string, string> >::operator()(const tuple<string, string, string, string>& t) const {
const string& a = get<0>(t);
diff --git a/src/CommonAPI/DBus/DBusFunctionalHash.h b/src/CommonAPI/DBus/DBusFunctionalHash.h
index 5867110..9736ac9 100644
--- a/src/CommonAPI/DBus/DBusFunctionalHash.h
+++ b/src/CommonAPI/DBus/DBusFunctionalHash.h
@@ -36,6 +36,12 @@ struct hash< tuple<string, string, string> >:
size_t operator()(const tuple<string, string, string>& t) const;
};
+template<>
+struct hash< tuple<string, string, string, bool> >:
+ public unary_function< tuple<string, string, string, bool>, size_t > {
+
+ size_t operator()(const tuple<string, string, string, bool>& t) const;
+};
template<>
struct hash< tuple<string, string, string, string> >:
diff --git a/src/CommonAPI/DBus/DBusInputStream.cpp b/src/CommonAPI/DBus/DBusInputStream.cpp
index 1356c31..dccf1e9 100644
--- a/src/CommonAPI/DBus/DBusInputStream.cpp
+++ b/src/CommonAPI/DBus/DBusInputStream.cpp
@@ -6,6 +6,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "DBusInputStream.h"
+
namespace CommonAPI {
namespace DBus {
@@ -56,7 +57,9 @@ DBusInputStream& DBusInputStream::readBasicTypeValue<float>(float& val) {
InputStream& DBusInputStream::readValue(bool& boolValue) {
alignToBoundary(4);
- return readBasicTypeValue(boolValue);
+ readBasicTypeValue(boolValue);
+ alignToBoundary(4);
+ return *this;
}
InputStream& DBusInputStream::readValue(int8_t& int8Value) { return readBasicTypeValue(int8Value); }
@@ -288,6 +291,11 @@ void DBusInputStream::endReadMap() {
savedStreamPositions_.pop();
}
+void DBusInputStream::beginReadMapElement() {
+ alignToBoundary(8);
+}
+void DBusInputStream::endReadMapElement() {}
+
} // namespace DBus
} // namespace CommonAPI
diff --git a/src/CommonAPI/DBus/DBusInputStream.h b/src/CommonAPI/DBus/DBusInputStream.h
index 6505923..3409d4c 100644
--- a/src/CommonAPI/DBus/DBusInputStream.h
+++ b/src/CommonAPI/DBus/DBusInputStream.h
@@ -105,6 +105,8 @@ class DBusInputStream: public InputStream {
virtual void beginReadMap();
virtual bool hasMoreMapElements();
virtual void endReadMap();
+ virtual void beginReadMapElement();
+ virtual void endReadMapElement();
/**
diff --git a/src/CommonAPI/DBus/DBusMultiEvent.h b/src/CommonAPI/DBus/DBusMultiEvent.h
index 45c05a7..910c8c1 100644
--- a/src/CommonAPI/DBus/DBusMultiEvent.h
+++ b/src/CommonAPI/DBus/DBusMultiEvent.h
@@ -12,6 +12,7 @@
#include <string>
#include <unordered_map>
+
namespace CommonAPI {
namespace DBus {
@@ -23,7 +24,7 @@ class DBusMultiEvent {
typedef typename ListenersMap::iterator Subscription;
Subscription subscribeAll(const Listener& listener);
- Subscription subscribe(const std::string& name, const Listener& listener);
+ Subscription subscribe(const std::string& eventName, const Listener& listener);
void unsubscribe(Subscription listenerSubscription);
@@ -53,15 +54,16 @@ DBusMultiEvent<_Arguments...>::subscribeAll(const Listener& listener) {
template <typename... _Arguments>
typename DBusMultiEvent<_Arguments...>::Subscription
-DBusMultiEvent<_Arguments...>::subscribe(const std::string& name, const Listener& listener) {
+DBusMultiEvent<_Arguments...>::subscribe(const std::string& eventName, const Listener& listener) {
const bool firstListenerAdded = listenersMap_.empty();
- auto listenerSubscription = listenersMap_.insert({name, listener});
+ auto listenerSubscription = listenersMap_.insert({eventName, listener});
- if (firstListenerAdded)
- onFirstListenerAdded(name, listener);
+ if (firstListenerAdded) {
+ onFirstListenerAdded(eventName, listener);
+ }
- onListenerAdded(name, listener);
+ onListenerAdded(eventName, listener);
return listenerSubscription;
}
@@ -95,16 +97,14 @@ SubscriptionStatus DBusMultiEvent<_Arguments...>::notifyListenersRange(
const std::string& name,
IteratorRange listenersRange,
const _Arguments&... eventArguments) {
- for (auto iterator = listenersRange.first; iterator != listenersRange.second; ) {
+ for (auto iterator = listenersRange.first; iterator != listenersRange.second; iterator++) {
const Listener& listener = iterator->second;
const SubscriptionStatus listenerSubcriptionStatus = listener(name, eventArguments...);
if (listenerSubcriptionStatus == SubscriptionStatus::CANCEL) {
auto listenerIterator = iterator;
listenersMap_.erase(listenerIterator);
- iterator++;
- } else
- iterator++;
+ }
}
return listenersMap_.empty() ? SubscriptionStatus::CANCEL : SubscriptionStatus::RETAIN;
diff --git a/src/CommonAPI/DBus/DBusObjectManager.cpp b/src/CommonAPI/DBus/DBusObjectManager.cpp
index 9d4323d..57c0727 100644
--- a/src/CommonAPI/DBus/DBusObjectManager.cpp
+++ b/src/CommonAPI/DBus/DBusObjectManager.cpp
@@ -1,101 +1,112 @@
-/* Copyright (C) 2013 BMW Group
- * Author: Manfred Bathelt (manfred.bathelt@bmw.de)
- * Author: Juergen Gehring (juergen.gehring@bmw.de)
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-#include "DBusObjectManager.h"
-#include "DBusOutputStream.h"
-
-#include <cassert>
-
-namespace CommonAPI {
-namespace DBus {
-
-DBusObjectManager::DBusObjectManager(const std::shared_ptr<DBusConnection>& dbusConnection):
- dbusConnection_(dbusConnection) {
-
- registerInterfaceHandler("/",
- "org.freedesktop.DBus.ObjectManager",
- std::bind(&DBusObjectManager::onGetDBusObjectManagerData, this, std::placeholders::_1));
-}
-
-DBusInterfaceHandlerToken DBusObjectManager::registerInterfaceHandler(const std::string& objectPath,
- const std::string& interfaceName,
- const DBusMessageInterfaceHandler& dbusMessageInterfaceHandler) {
- DBusInterfaceHandlerPath handlerPath(objectPath, interfaceName);
- bool noSuchHandlerRegistered = dbusRegisteredObjectsTable_.find(handlerPath) == dbusRegisteredObjectsTable_.end();
-
- assert(noSuchHandlerRegistered);
-
- dbusRegisteredObjectsTable_.insert({handlerPath, dbusMessageInterfaceHandler});
- dbusConnection_->registerObjectPath(objectPath);
-
- return handlerPath;
-}
-
-void DBusObjectManager::unregisterInterfaceHandler(const DBusInterfaceHandlerToken& dbusInterfaceHandlerToken) {
- const std::string& objectPath = dbusInterfaceHandlerToken.first;
-
- dbusConnection_->unregisterObjectPath(objectPath);
-
- dbusRegisteredObjectsTable_.erase(dbusInterfaceHandlerToken);
-}
-
-bool DBusObjectManager::handleMessage(const DBusMessage& dbusMessage) const {
- const char* objectPath = dbusMessage.getObjectPath();
- const char* interfaceName = dbusMessage.getInterfaceName();
-
- assert(objectPath);
- assert(interfaceName);
-
- DBusInterfaceHandlerPath handlerPath(objectPath, interfaceName);
- auto handlerIterator = dbusRegisteredObjectsTable_.find(handlerPath);
- const bool foundDBusInterfaceHandler = handlerIterator != dbusRegisteredObjectsTable_.end();
- bool dbusMessageHandled = false;
-
- if (foundDBusInterfaceHandler) {
- const DBusMessageInterfaceHandler& interfaceHandlerDBusMessageHandler = handlerIterator->second;
- dbusMessageHandled = interfaceHandlerDBusMessageHandler(dbusMessage);
- }
-
- return dbusMessageHandled;
-}
-
-bool DBusObjectManager::onGetDBusObjectManagerData(const DBusMessage& callMessage) {
-
- DBusObjectToInterfaceDict dictToSend;
-
- const char* interfaceName = callMessage.getInterfaceName();
- const char* signature = callMessage.getSignatureString();
-
- assert(!strcmp(interfaceName, "org.freedesktop.DBus.ObjectManager"));
- assert(!strcmp(signature, ""));
- assert(callMessage.getType() == DBusMessage::Type::MethodCall);
-
- auto registeredObjectsIterator = dbusRegisteredObjectsTable_.begin();
-
- while(registeredObjectsIterator != dbusRegisteredObjectsTable_.end()) {
- DBusInterfaceHandlerPath handlerPath = registeredObjectsIterator->first;
- auto foundDictEntry = dictToSend.find(handlerPath.first);
-
- if(foundDictEntry == dictToSend.end()) {
- dictToSend.insert( { handlerPath.first, { { handlerPath.second, {} } } } );
- } else {
- foundDictEntry->second.insert( {handlerPath.second, {} } );
- }
-
- ++registeredObjectsIterator;
- }
-
- DBusMessage replyMessage = callMessage.createMethodReturn(DBusServiceRegistry::getManagedObjectsDBusSignature_);
-
- DBusOutputStream outStream(replyMessage);
- outStream << dictToSend;
- outStream.flush();
- return dbusConnection_->sendDBusMessage(replyMessage);
-}
-
-
-} // namespace DBus
-} // namespace CommonAPI
+/* Copyright (C) 2013 BMW Group
+ * Author: Manfred Bathelt (manfred.bathelt@bmw.de)
+ * Author: Juergen Gehring (juergen.gehring@bmw.de)
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+#include "DBusObjectManager.h"
+#include "DBusOutputStream.h"
+
+#include <cassert>
+
+namespace CommonAPI {
+namespace DBus {
+
+DBusObjectManager::DBusObjectManager(const std::shared_ptr<DBusConnection>& dbusConnection):
+ dbusConnection_(dbusConnection) {
+
+ registerInterfaceHandler("/",
+ "org.freedesktop.DBus.ObjectManager",
+ std::bind(&DBusObjectManager::onGetDBusObjectManagerData, this, std::placeholders::_1));
+}
+
+DBusInterfaceHandlerToken DBusObjectManager::registerInterfaceHandler(const std::string& objectPath,
+ const std::string& interfaceName,
+ const DBusMessageInterfaceHandler& dbusMessageInterfaceHandler) {
+ DBusInterfaceHandlerPath handlerPath(objectPath, interfaceName);
+ bool noSuchHandlerRegistered = dbusRegisteredObjectsTable_.find(handlerPath) == dbusRegisteredObjectsTable_.end();
+
+ assert(noSuchHandlerRegistered);
+
+ dbusRegisteredObjectsTable_.insert({handlerPath, dbusMessageInterfaceHandler});
+ std::shared_ptr<DBusConnection> lockedConnection = dbusConnection_.lock();
+ if(lockedConnection) {
+ lockedConnection->registerObjectPath(objectPath);
+ }
+
+ return handlerPath;
+}
+
+void DBusObjectManager::unregisterInterfaceHandler(const DBusInterfaceHandlerToken& dbusInterfaceHandlerToken) {
+ const std::string& objectPath = dbusInterfaceHandlerToken.first;
+
+ std::shared_ptr<DBusConnection> lockedConnection = dbusConnection_.lock();
+ if(lockedConnection) {
+ lockedConnection->unregisterObjectPath(objectPath);
+ }
+
+ dbusRegisteredObjectsTable_.erase(dbusInterfaceHandlerToken);
+}
+
+bool DBusObjectManager::handleMessage(const DBusMessage& dbusMessage) const {
+ const char* objectPath = dbusMessage.getObjectPath();
+ const char* interfaceName = dbusMessage.getInterfaceName();
+
+ assert(objectPath);
+ assert(interfaceName);
+
+ DBusInterfaceHandlerPath handlerPath(objectPath, interfaceName);
+ auto handlerIterator = dbusRegisteredObjectsTable_.find(handlerPath);
+ const bool foundDBusInterfaceHandler = handlerIterator != dbusRegisteredObjectsTable_.end();
+ bool dbusMessageHandled = false;
+
+ if (foundDBusInterfaceHandler) {
+ const DBusMessageInterfaceHandler& interfaceHandlerDBusMessageHandler = handlerIterator->second;
+ dbusMessageHandled = interfaceHandlerDBusMessageHandler(dbusMessage);
+ }
+
+ return dbusMessageHandled;
+}
+
+bool DBusObjectManager::onGetDBusObjectManagerData(const DBusMessage& callMessage) {
+ DBusDaemonProxy::DBusObjectToInterfaceDict dictToSend;
+
+ const char* interfaceName = callMessage.getInterfaceName();
+ const char* signature = callMessage.getSignatureString();
+
+ assert(!strcmp(interfaceName, "org.freedesktop.DBus.ObjectManager"));
+ assert(!strcmp(signature, ""));
+ assert(callMessage.getType() == DBusMessage::Type::MethodCall);
+
+ auto registeredObjectsIterator = dbusRegisteredObjectsTable_.begin();
+
+ while(registeredObjectsIterator != dbusRegisteredObjectsTable_.end()) {
+ DBusInterfaceHandlerPath handlerPath = registeredObjectsIterator->first;
+ auto foundDictEntry = dictToSend.find(handlerPath.first);
+
+ if(foundDictEntry == dictToSend.end()) {
+ dictToSend.insert( { handlerPath.first, { { handlerPath.second, {} } } } );
+ } else {
+ foundDictEntry->second.insert( {handlerPath.second, {} } );
+ }
+
+ ++registeredObjectsIterator;
+ }
+
+ const char* getManagedObjectsDBusSignature = "a{oa{sa{sv}}}";
+ DBusMessage replyMessage = callMessage.createMethodReturn(getManagedObjectsDBusSignature);
+
+ DBusOutputStream outStream(replyMessage);
+ outStream << dictToSend;
+ outStream.flush();
+
+ std::shared_ptr<DBusConnection> lockedConnection = dbusConnection_.lock();
+ if(lockedConnection) {
+ return lockedConnection->sendDBusMessage(replyMessage);
+ }
+ return false;
+}
+
+
+} // namespace DBus
+} // namespace CommonAPI
diff --git a/src/CommonAPI/DBus/DBusObjectManager.h b/src/CommonAPI/DBus/DBusObjectManager.h
index 2424fab..bfd2a71 100644
--- a/src/CommonAPI/DBus/DBusObjectManager.h
+++ b/src/CommonAPI/DBus/DBusObjectManager.h
@@ -1,57 +1,57 @@
-/* Copyright (C) 2013 BMW Group
- * Author: Manfred Bathelt (manfred.bathelt@bmw.de)
- * Author: Juergen Gehring (juergen.gehring@bmw.de)
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-#ifndef COMMONAPI_DBUS_DBUS_OBJECT_MANAGER_H_
-#define COMMONAPI_DBUS_DBUS_OBJECT_MANAGER_H_
-
-#include "DBusMessage.h"
-#include "DBusConnection.h"
-
-namespace CommonAPI {
-namespace DBus {
-
-// objectPath, interfaceName
-typedef std::function<bool(const DBusMessage&)> DBusMessageInterfaceHandler;
-typedef std::pair<std::string, std::string> DBusInterfaceHandlerPath;
-typedef DBusInterfaceHandlerPath DBusInterfaceHandlerToken;
-
-class DBusConnection;
-
-class DBusObjectManager {
- public:
- DBusObjectManager(const std::shared_ptr<DBusConnection>&);
-
- void init();
-
- const DBusInterfaceHandlerToken registerInterfaceHandlerForDBusObject(const std::string& objectPath,
- const std::string& interfaceName,
- const DBusMessageInterfaceHandler& dbusMessageInterfaceHandler);
-
- DBusInterfaceHandlerToken registerInterfaceHandler(const std::string& objectPath,
- const std::string& interfaceName,
- const DBusMessageInterfaceHandler& dbusMessageInterfaceHandler);
-
- void unregisterInterfaceHandler(const DBusInterfaceHandlerToken& dbusInterfaceHandlerToken);
-
- bool handleMessage(const DBusMessage&) const;
-
-
- private:
- void addLibdbusObjectPathHandler(const std::string& objectPath);
- void removeLibdbusObjectPathHandler(const std::string& objectPath);
-
- bool onGetDBusObjectManagerData(const DBusMessage& callMessage);
-
- typedef std::unordered_map<DBusInterfaceHandlerPath, DBusMessageInterfaceHandler> DBusRegisteredObjectsTable;
- DBusRegisteredObjectsTable dbusRegisteredObjectsTable_;
-
- std::shared_ptr<DBusConnection> dbusConnection_;
-};
-
-} // namespace DBus
-} // namespace CommonAPI
-
-#endif // COMMONAPI_DBUS_DBUS_OBJECT_MANAGER_H_
+/* Copyright (C) 2013 BMW Group
+ * Author: Manfred Bathelt (manfred.bathelt@bmw.de)
+ * Author: Juergen Gehring (juergen.gehring@bmw.de)
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+#ifndef COMMONAPI_DBUS_DBUS_OBJECT_MANAGER_H_
+#define COMMONAPI_DBUS_DBUS_OBJECT_MANAGER_H_
+
+#include "DBusMessage.h"
+#include "DBusConnection.h"
+
+namespace CommonAPI {
+namespace DBus {
+
+// objectPath, interfaceName
+typedef std::function<bool(const DBusMessage&)> DBusMessageInterfaceHandler;
+typedef std::pair<std::string, std::string> DBusInterfaceHandlerPath;
+typedef DBusInterfaceHandlerPath DBusInterfaceHandlerToken;
+
+class DBusConnection;
+
+class DBusObjectManager {
+ public:
+ DBusObjectManager(const std::shared_ptr<DBusConnection>&);
+
+ void init();
+
+ const DBusInterfaceHandlerToken registerInterfaceHandlerForDBusObject(const std::string& objectPath,
+ const std::string& interfaceName,
+ const DBusMessageInterfaceHandler& dbusMessageInterfaceHandler);
+
+ DBusInterfaceHandlerToken registerInterfaceHandler(const std::string& objectPath,
+ const std::string& interfaceName,
+ const DBusMessageInterfaceHandler& dbusMessageInterfaceHandler);
+
+ void unregisterInterfaceHandler(const DBusInterfaceHandlerToken& dbusInterfaceHandlerToken);
+
+ bool handleMessage(const DBusMessage&) const;
+
+
+ private:
+ void addLibdbusObjectPathHandler(const std::string& objectPath);
+ void removeLibdbusObjectPathHandler(const std::string& objectPath);
+
+ bool onGetDBusObjectManagerData(const DBusMessage& callMessage);
+
+ typedef std::unordered_map<DBusInterfaceHandlerPath, DBusMessageInterfaceHandler> DBusRegisteredObjectsTable;
+ DBusRegisteredObjectsTable dbusRegisteredObjectsTable_;
+
+ std::weak_ptr<DBusConnection> dbusConnection_;
+};
+
+} // namespace DBus
+} // namespace CommonAPI
+
+#endif // COMMONAPI_DBUS_DBUS_OBJECT_MANAGER_H_
diff --git a/src/CommonAPI/DBus/DBusOutputStream.cpp b/src/CommonAPI/DBus/DBusOutputStream.cpp
index bdefcd4..f600ced 100644
--- a/src/CommonAPI/DBus/DBusOutputStream.cpp
+++ b/src/CommonAPI/DBus/DBusOutputStream.cpp
@@ -16,7 +16,12 @@ DBusOutputStream::DBusOutputStream(DBusMessage dbusMessage) :
DBusOutputStream::~DBusOutputStream() {
}
-OutputStream& DBusOutputStream::writeValue(const bool& boolValue) { return writeBasicTypeValue<uint32_t>(boolValue); }
+OutputStream& DBusOutputStream::writeValue(const bool& boolValue) {
+ alignToBoundary(4);
+ writeBasicTypeValue(boolValue);
+ alignToBoundary(4);
+ return *this;
+}
OutputStream& DBusOutputStream::writeValue(const int8_t& int8Value) { return writeBasicTypeValue(int8Value); }
OutputStream& DBusOutputStream::writeValue(const int16_t& int16Value) { return writeBasicTypeValue(int16Value); }
@@ -191,6 +196,11 @@ void DBusOutputStream::endWriteMap() {
writeBasicTypeValueAtPosition(popRememberedStreamPosition(), numOfWrittenBytes);
}
+void DBusOutputStream::beginWriteMapElement() {
+ alignToBoundary(8);
+}
+void DBusOutputStream::endWriteMapElement() {}
+
void DBusOutputStream::beginWriteSerializableVariant(const SerializableVariant& serializableVariant) {
alignToBoundary(8);
writeValue(serializableVariant.getValueType());
diff --git a/src/CommonAPI/DBus/DBusOutputStream.h b/src/CommonAPI/DBus/DBusOutputStream.h
index 9d3895c..3a6a83b 100644
--- a/src/CommonAPI/DBus/DBusOutputStream.h
+++ b/src/CommonAPI/DBus/DBusOutputStream.h
@@ -237,8 +237,9 @@ class DBusOutputStream: public OutputStream {
virtual void endWriteSerializableStruct(const SerializableStruct& serializableStruct);
virtual void beginWriteMap(size_t elementCount);
-
virtual void endWriteMap();
+ virtual void beginWriteMapElement();
+ virtual void endWriteMapElement();
virtual void beginWriteSerializableVariant(const SerializableVariant& serializableVariant);
diff --git a/src/CommonAPI/DBus/DBusProxy.cpp b/src/CommonAPI/DBus/DBusProxy.cpp
index 7e1eda9..314c63f 100644
--- a/src/CommonAPI/DBus/DBusProxy.cpp
+++ b/src/CommonAPI/DBus/DBusProxy.cpp
@@ -4,15 +4,16 @@
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+// Workaround for libstdc++ bug
+#ifndef _GLIBCXX_USE_NANOSLEEP
+#define _GLIBCXX_USE_NANOSLEEP
+#endif
+
#include "DBusProxy.h"
-#include "DBusServiceRegistry.h"
#include "DBusUtils.h"
-#include <algorithm>
#include <cassert>
-#include <dbus/dbus.h>
-#include <functional>
-#include <CommonAPI/Event.h>
+
namespace CommonAPI {
namespace DBus {
@@ -21,114 +22,71 @@ DBusProxyStatusEvent::DBusProxyStatusEvent(DBusProxy* dbusProxy) :
dbusProxy_(dbusProxy) {
}
-void DBusProxyStatusEvent::onFirstListenerAdded(const Listener& listener) {
- auto serviceStatusListener = std::bind(
- &DBusProxyStatusEvent::onServiceAvailableSignalHandler,
- this,
- std::placeholders::_1,
- std::placeholders::_2);
-
- subscription_ = dbusProxy_->getDBusConnection()->getDBusServiceRegistry()->getServiceStatusEvent().subscribe(
- dbusProxy_->dbusBusName_ + ":" + dbusProxy_->dbusObjectPath_ + ":" + dbusProxy_->interfaceName_,
- serviceStatusListener);
-}
-
-void DBusProxyStatusEvent::onLastListenerRemoved(const Listener& listener) {
- dbusProxy_->getDBusConnection()->getDBusServiceRegistry()->getServiceStatusEvent().unsubscribe(subscription_);
-}
-
-SubscriptionStatus DBusProxyStatusEvent::onServiceAvailableSignalHandler(const std::string& name,
- const AvailabilityStatus& availabilityStatus) {
- AvailabilityStatus availability = availabilityStatus;
-
- return notifyListeners(availability);
+void DBusProxyStatusEvent::onListenerAdded(const CancellableListener& listener) {
+ if (dbusProxy_->isAvailable())
+ listener(AvailabilityStatus::AVAILABLE);
}
-const std::string DBusProxy::domain_ = "local";
-
-DBusProxy::DBusProxy(const std::string& dbusBusName,
- const std::string& dbusObjectPath,
- const std::string& interfaceName,
- const std::shared_ptr<DBusProxyConnection>& dbusProxyConnection) :
- dbusBusName_(dbusBusName),
- dbusObjectPath_(dbusObjectPath),
- interfaceName_(interfaceName),
- statusEvent_(this),
- interfaceVersionAttribute_(*this, "getInterfaceVersion"),
- available_(false),
- availableSet_(false),
- connection_(dbusProxyConnection) {
-}
-DBusProxy::DBusProxy(const std::string& dbusBusName,
+DBusProxy::DBusProxy(const std::string& commonApiAddress,
+ const std::string& dbusInterfaceName,
+ const std::string& dbusBusName,
const std::string& dbusObjectPath,
- const std::string& interfaceName,
- const std::shared_ptr<DBusProxyConnection>& connection,
- const bool isAlwaysAvailable) :
- dbusBusName_(dbusBusName),
- dbusObjectPath_(dbusObjectPath),
- interfaceName_(interfaceName),
- statusEvent_(this),
- interfaceVersionAttribute_(*this, "getInterfaceVersion"),
- available_(isAlwaysAvailable),
- availableSet_(isAlwaysAvailable),
- connection_(connection) {
+ const std::shared_ptr<DBusProxyConnection>& dbusConnection):
+ DBusProxyBase(split(commonApiAddress, ':')[1],
+ split(commonApiAddress, ':')[2],
+ dbusInterfaceName,
+ dbusBusName,
+ dbusObjectPath,
+ dbusConnection),
+ dbusProxyStatusEvent_(this),
+ availabilityStatus_(AvailabilityStatus::UNKNOWN),
+ interfaceVersionAttribute_(*this, "getInterfaceVersion"),
+ dbusServiceRegistry_(dbusConnection->getDBusServiceRegistry()) {
+
+ const std::string commonApiDomain = split(commonApiAddress, ':')[0];
+ assert(commonApiDomain == "local");
+
+ dbusServiceRegistrySubscription_ = dbusServiceRegistry_->subscribeAvailabilityListener(
+ commonApiAddress,
+ std::bind(&DBusProxy::onDBusServiceInstanceStatus, this, std::placeholders::_1));
}
-std::string DBusProxy::getAddress() const {
- return domain_ + ":" + interfaceName_ + ":" + dbusBusName_;
+DBusProxy::~DBusProxy() {
+ dbusServiceRegistry_->unsubscribeAvailabilityListener(
+ getAddress(),
+ dbusServiceRegistrySubscription_);
}
-const std::string& DBusProxy::getDomain() const {
- return domain_;
-}
-
-const std::string& DBusProxy::getServiceId() const {
- return getInterfaceName();
-}
-
-const std::string& DBusProxy::getInstanceId() const {
- return dbusBusName_;
-}
-
-
bool DBusProxy::isAvailable() const {
- if (!availableSet_) {
- auto status = getDBusConnection()->getDBusServiceRegistry()->getReadyFuture().wait_for(std::chrono::milliseconds(1));
- if (checkReady(status)) {
- available_ = getDBusConnection()->getDBusServiceRegistry()->isServiceInstanceAlive(getAddress());
- availableSet_ = true;
- }
- }
- return available_;
+ return (availabilityStatus_ == AvailabilityStatus::AVAILABLE);
}
bool DBusProxy::isAvailableBlocking() const {
+ if (availabilityStatus_ == AvailabilityStatus::UNKNOWN) {
+ std::chrono::milliseconds singleWaitDuration(100);
- if (!availableSet_) {
- getDBusConnection()->getDBusServiceRegistry()->getReadyFuture().wait();
- available_ = getDBusConnection()->getDBusServiceRegistry()->isServiceInstanceAlive(getAddress());
- availableSet_ = true;
+ // Wait for the service registry
+ while (availabilityStatus_ == AvailabilityStatus::UNKNOWN) {
+ std::this_thread::sleep_for(singleWaitDuration);
+ }
}
- return available_;
+
+ return isAvailable();
}
ProxyStatusEvent& DBusProxy::getProxyStatusEvent() {
- return statusEvent_;
+ return dbusProxyStatusEvent_;
}
InterfaceVersionAttribute& DBusProxy::getInterfaceVersionAttribute() {
return interfaceVersionAttribute_;
}
-DBusMessage DBusProxy::createMethodCall(const char* methodName,
- const char* methodSignature) const {
- return DBusMessage::createMethodCall(
- dbusBusName_.c_str(),
- dbusObjectPath_.c_str(),
- getInterfaceName().c_str(),
- methodName,
- methodSignature);
+void DBusProxy::onDBusServiceInstanceStatus(const AvailabilityStatus& availabilityStatus) {
+ availabilityStatus_ = availabilityStatus;
+
+ dbusProxyStatusEvent_.notifyListeners(availabilityStatus);
}
} // namespace DBus
diff --git a/src/CommonAPI/DBus/DBusProxy.h b/src/CommonAPI/DBus/DBusProxy.h
index 0b155ce..6021a01 100644
--- a/src/CommonAPI/DBus/DBusProxy.h
+++ b/src/CommonAPI/DBus/DBusProxy.h
@@ -7,133 +7,62 @@
#ifndef COMMONAPI_DBUS_DBUS_PROXY_H_
#define COMMONAPI_DBUS_DBUS_PROXY_H_
-#include "DBusProxyConnection.h"
+#include "DBusProxyBase.h"
#include "DBusAttribute.h"
-
-#include <CommonAPI/Proxy.h>
-#include <CommonAPI/types.h>
+#include "DBusServiceRegistry.h"
#include <functional>
#include <memory>
#include <string>
+
namespace CommonAPI {
namespace DBus {
-class DBusProxy;
-
-typedef Event<AvailabilityStatus> ProxyStatusEvent;
-
class DBusProxyStatusEvent: public ProxyStatusEvent {
+ friend class DBusProxy;
+
public:
DBusProxyStatusEvent(DBusProxy* dbusProxy);
- void onFirstListenerAdded(const Listener& listener);
- void onLastListenerRemoved(const Listener& listener);
-
- Subscription subscribe(Listener listener);
-
- private:
- SubscriptionStatus onServiceAvailableSignalHandler(const std::string& name, const AvailabilityStatus& availabilityStatus);
+ protected:
+ virtual void onListenerAdded(const CancellableListener& listener);
DBusProxy* dbusProxy_;
- DBusServiceStatusEvent::Subscription subscription_;
-
- friend class DBusProxy;
-
};
-class DBusProxy: public virtual CommonAPI::Proxy {
+class DBusProxy: public DBusProxyBase {
public:
- DBusProxy(const std::string& dbusBusName,
+ DBusProxy(const std::string& commonApiAddress,
+ const std::string& dbusInterfaceName,
+ const std::string& dbusBusName,
const std::string& dbusObjectPath,
- const std::string& interfaceName,
- const std::shared_ptr<DBusProxyConnection>& dbusProxyConnection);
+ const std::shared_ptr<DBusProxyConnection>& dbusConnection);
+
+ virtual ~DBusProxy();
- virtual std::string getAddress() const;
- virtual const std::string& getDomain() const;
- virtual const std::string& getServiceId() const;
- virtual const std::string& getInstanceId() const;
virtual bool isAvailable() const;
- virtual bool isAvailableBlocking() const;
virtual ProxyStatusEvent& getProxyStatusEvent();
virtual InterfaceVersionAttribute& getInterfaceVersionAttribute();
- inline const std::string& getDBusBusName() const;
- inline const std::string& getDBusObjectPath() const;
- inline const std::string& getInterfaceName() const;
- inline const std::shared_ptr<DBusProxyConnection>& getDBusConnection() const;
-
- DBusMessage createMethodCall(const char* methodName,
- const char* methodSignature = NULL) const;
-
- inline DBusProxyConnection::DBusSignalHandlerToken addSignalMemberHandler(
- const std::string& signalName,
- const std::string& signalSignature,
- DBusProxyConnection::DBusSignalHandler* dbusSignalHandler);
-
- inline void removeSignalMemberHandler(const DBusProxyConnection::DBusSignalHandlerToken& dbusSignalHandlerToken);
-
- protected:
- DBusProxy(const DBusProxy& abstractProxy) = delete;
-
- DBusProxy(const std::string& busName,
- const std::string& objectId,
- const std::string& interfaceName,
- const std::shared_ptr<DBusProxyConnection>& connection,
- const bool isAlwaysAvailable);
-
- virtual void getOwnVersion(uint16_t& ownVersionMajor, uint16_t& ownVersionMinor) const = 0;
-
- DBusProxyStatusEvent statusEvent_;
- DBusProxyStatusEvent::Subscription remoteStatusSubscription_;
+ virtual bool isAvailableBlocking() const;
private:
- void onServiceAlive(bool alive);
+ DBusProxy(const DBusProxy&) = delete;
- const std::string dbusBusName_;
- const std::string dbusObjectPath_;
- const std::string interfaceName_;
+ void onDBusServiceInstanceStatus(const AvailabilityStatus& availabilityStatus);
- mutable bool available_;
- mutable bool availableSet_;
-
- std::shared_ptr<DBusProxyConnection> connection_;
+ DBusProxyStatusEvent dbusProxyStatusEvent_;
+ DBusServiceRegistry::Subscription dbusServiceRegistrySubscription_;
+ DBusServiceStatusEvent::Subscription dbusServiceStatusEventSubscription_;
+ AvailabilityStatus availabilityStatus_;
DBusReadonlyAttribute<InterfaceVersionAttribute> interfaceVersionAttribute_;
- static const std::string domain_;
-
- friend class DBusProxyStatusEvent;
+ std::shared_ptr<DBusServiceRegistry> dbusServiceRegistry_;
};
-const std::string& DBusProxy::getDBusBusName() const {
- return dbusBusName_;
-}
-
-const std::string& DBusProxy::getDBusObjectPath() const {
- return dbusObjectPath_;
-}
-
-const std::string& DBusProxy::getInterfaceName() const {
- return interfaceName_;
-}
-
-const std::shared_ptr<DBusProxyConnection>& DBusProxy::getDBusConnection() const {
- return connection_;
-}
-
-DBusProxyConnection::DBusSignalHandlerToken DBusProxy::addSignalMemberHandler(
- const std::string& signalName,
- const std::string& signalSignature,
- DBusProxyConnection::DBusSignalHandler* dbusSignalHandler) {
- return connection_->addSignalMemberHandler(dbusObjectPath_, getInterfaceName(), signalName, signalSignature, dbusSignalHandler);
-}
-
-void DBusProxy::removeSignalMemberHandler(const DBusProxyConnection::DBusSignalHandlerToken& dbusSignalHandlerToken) {
- return connection_->removeSignalMemberHandler(dbusSignalHandlerToken);
-}
} // namespace DBus
} // namespace CommonAPI
diff --git a/src/CommonAPI/DBus/DBusProxyBase.cpp b/src/CommonAPI/DBus/DBusProxyBase.cpp
new file mode 100644
index 0000000..8cb2400
--- /dev/null
+++ b/src/CommonAPI/DBus/DBusProxyBase.cpp
@@ -0,0 +1,68 @@
+/* Copyright (C) 2013 BMW Group
+ * Author: Manfred Bathelt (manfred.bathelt@bmw.de)
+ * Author: Juergen Gehring (juergen.gehring@bmw.de)
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+#include "DBusProxyBase.h"
+#include "DBusMessage.h"
+
+namespace CommonAPI {
+namespace DBus {
+
+const std::string DBusProxyBase::commonApiDomain_ = "local";
+
+DBusProxyBase::DBusProxyBase(const std::string& commonApiServiceId,
+ const std::string& commonApiParticipantId,
+ const std::string& dbusInterfaceName,
+ const std::string& dbusBusName,
+ const std::string& dbusObjectPath,
+ const std::shared_ptr<DBusProxyConnection>& dbusConnection) :
+ commonApiServiceId_(commonApiServiceId),
+ commonApiParticipantId_(commonApiParticipantId),
+ dbusBusName_(dbusBusName),
+ dbusObjectPath_(dbusObjectPath),
+ dbusInterfaceName_(dbusInterfaceName),
+ dbusConnection_(dbusConnection) {
+}
+
+DBusProxyBase::DBusProxyBase(const std::string& dbusInterfaceName,
+ const std::string& dbusBusName,
+ const std::string& dbusObjectPath,
+ const std::shared_ptr<DBusProxyConnection>& dbusConnection) :
+ commonApiServiceId_(dbusInterfaceName),
+ commonApiParticipantId_(dbusBusName + "-" + dbusObjectPath),
+ dbusBusName_(dbusBusName),
+ dbusObjectPath_(dbusObjectPath),
+ dbusInterfaceName_(dbusInterfaceName),
+ dbusConnection_(dbusConnection) {
+}
+
+std::string DBusProxyBase::getAddress() const {
+ return commonApiDomain_ + ":" + commonApiServiceId_ + ":" + commonApiParticipantId_;
+}
+
+const std::string& DBusProxyBase::getDomain() const {
+ return commonApiDomain_;
+}
+
+const std::string& DBusProxyBase::getServiceId() const {
+ return commonApiServiceId_;
+}
+
+const std::string& DBusProxyBase::getInstanceId() const {
+ return commonApiParticipantId_;
+}
+
+DBusMessage DBusProxyBase::createMethodCall(const char* methodName,
+ const char* methodSignature) const {
+ return DBusMessage::createMethodCall(
+ dbusBusName_.c_str(),
+ dbusObjectPath_.c_str(),
+ dbusInterfaceName_.c_str(),
+ methodName,
+ methodSignature);
+}
+
+} // namespace DBus
+} // namespace CommonAPI
diff --git a/src/CommonAPI/DBus/DBusProxyBase.h b/src/CommonAPI/DBus/DBusProxyBase.h
new file mode 100644
index 0000000..10b5bae
--- /dev/null
+++ b/src/CommonAPI/DBus/DBusProxyBase.h
@@ -0,0 +1,107 @@
+/* Copyright (C) 2013 BMW Group
+ * Author: Manfred Bathelt (manfred.bathelt@bmw.de)
+ * Author: Juergen Gehring (juergen.gehring@bmw.de)
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+#ifndef COMMONAPI_DBUS_DBUS_PROXY_BASE_H_
+#define COMMONAPI_DBUS_DBUS_PROXY_BASE_H_
+
+#include "DBusProxyConnection.h"
+
+#include <CommonAPI/Proxy.h>
+#include <CommonAPI/types.h>
+
+#include <functional>
+#include <memory>
+#include <string>
+
+namespace CommonAPI {
+namespace DBus {
+
+class DBusProxyBase: public virtual CommonAPI::Proxy {
+ public:
+ DBusProxyBase(const std::string& commonApiServiceId,
+ const std::string& commonApiParticipantId,
+ const std::string& dbusInterfaceName,
+ const std::string& dbusBusName,
+ const std::string& dbusObjectPath,
+ const std::shared_ptr<DBusProxyConnection>& dbusProxyConnection);
+
+ DBusProxyBase(const std::string& dbusInterfaceName,
+ const std::string& dbusBusName,
+ const std::string& dbusObjectPath,
+ const std::shared_ptr<DBusProxyConnection>& dbusProxyConnection);
+
+ virtual std::string getAddress() const;
+ virtual const std::string& getDomain() const;
+ virtual const std::string& getServiceId() const;
+ virtual const std::string& getInstanceId() const;
+
+ inline const std::string& getDBusBusName() const;
+ inline const std::string& getDBusObjectPath() const;
+ inline const std::string& getInterfaceName() const;
+ inline const std::shared_ptr<DBusProxyConnection>& getDBusConnection() const;
+
+ DBusMessage createMethodCall(const char* methodName,
+ const char* methodSignature = NULL) const;
+
+ inline DBusProxyConnection::DBusSignalHandlerToken addSignalMemberHandler(
+ const std::string& signalName,
+ const std::string& signalSignature,
+ DBusProxyConnection::DBusSignalHandler* dbusSignalHandler);
+
+ inline void removeSignalMemberHandler(const DBusProxyConnection::DBusSignalHandlerToken& dbusSignalHandlerToken);
+
+ private:
+ DBusProxyBase(const DBusProxyBase&) = delete;
+
+ const std::string commonApiServiceId_;
+ const std::string commonApiParticipantId_;
+
+ const std::string dbusBusName_;
+ const std::string dbusObjectPath_;
+ const std::string dbusInterfaceName_;
+
+ std::shared_ptr<DBusProxyConnection> dbusConnection_;
+
+ static const std::string commonApiDomain_;
+};
+
+const std::string& DBusProxyBase::getDBusBusName() const {
+ return dbusBusName_;
+}
+
+const std::string& DBusProxyBase::getDBusObjectPath() const {
+ return dbusObjectPath_;
+}
+
+const std::string& DBusProxyBase::getInterfaceName() const {
+ return dbusInterfaceName_;
+}
+
+const std::shared_ptr<DBusProxyConnection>& DBusProxyBase::getDBusConnection() const {
+ return dbusConnection_;
+}
+
+DBusProxyConnection::DBusSignalHandlerToken DBusProxyBase::addSignalMemberHandler(
+ const std::string& signalName,
+ const std::string& signalSignature,
+ DBusProxyConnection::DBusSignalHandler* dbusSignalHandler) {
+ return dbusConnection_->addSignalMemberHandler(
+ dbusObjectPath_,
+ getInterfaceName(),
+ signalName,
+ signalSignature,
+ dbusSignalHandler);
+}
+
+void DBusProxyBase::removeSignalMemberHandler(const DBusProxyConnection::DBusSignalHandlerToken& dbusSignalHandlerToken) {
+ return dbusConnection_->removeSignalMemberHandler(dbusSignalHandlerToken);
+}
+
+} // namespace DBus
+} // namespace CommonAPI
+
+#endif // COMMONAPI_DBUS_DBUS_PROXY_BASE_H_
+
diff --git a/src/CommonAPI/DBus/DBusProxyConnection.h b/src/CommonAPI/DBus/DBusProxyConnection.h
index 5077ee9..e5dc24a 100644
--- a/src/CommonAPI/DBus/DBusProxyConnection.h
+++ b/src/CommonAPI/DBus/DBusProxyConnection.h
@@ -1,97 +1,99 @@
-/* Copyright (C) 2013 BMW Group
- * Author: Manfred Bathelt (manfred.bathelt@bmw.de)
- * Author: Juergen Gehring (juergen.gehring@bmw.de)
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-#ifndef COMMONAPI_DBUS_DBUS_PROXY_CONNECTION_H_
-#define COMMONAPI_DBUS_DBUS_PROXY_CONNECTION_H_
-
-#include "DBusError.h"
-#include "DBusMessage.h"
-
-#include "DBusFunctionalHash.h"
-#include "DBusServiceStatusEvent.h"
-
-#include <CommonAPI/types.h>
-#include <CommonAPI/Attribute.h>
-#include <CommonAPI/Event.h>
-
-#include <cstdint>
-#include <functional>
-#include <future>
-#include <memory>
-#include <tuple>
-#include <unordered_map>
-#include <utility>
-#include <vector>
-
-namespace CommonAPI {
-namespace DBus {
-
-
-typedef std::function<void(const DBusMessage&)> DBusMessageHandler;
-
-class DBusDaemonProxy;
-class DBusServiceRegistry;
-class DBusObjectManager;
-
-
-class DBusProxyConnection {
- public:
- class DBusMessageReplyAsyncHandler {
- public:
- virtual ~DBusMessageReplyAsyncHandler() { }
- virtual std::future<CallStatus> getFuture() = 0;
- virtual void onDBusMessageReply(const CallStatus&, const DBusMessage&) = 0;
- };
-
- class DBusSignalHandler {
- public:
- virtual ~DBusSignalHandler() { }
- virtual SubscriptionStatus onSignalDBusMessage(const DBusMessage&) = 0;
- };
-
- // objectPath, interfaceName, interfaceMemberName, interfaceMemberSignature
- typedef std::tuple<std::string, std::string, std::string, std::string> DBusSignalHandlerPath;
- typedef std::unordered_multimap<DBusSignalHandlerPath, DBusSignalHandler*> DBusSignalHandlerTable;
- typedef DBusSignalHandlerPath DBusSignalHandlerToken;
-
-
- virtual ~DBusProxyConnection() { }
-
- virtual bool isConnected() const = 0;
-
- virtual bool sendDBusMessage(const DBusMessage& dbusMessage, uint32_t* allocatedSerial = NULL) const = 0;
-
- static const int kDefaultSendTimeoutMs = 100 * 1000;
-
- virtual std::future<CallStatus> sendDBusMessageWithReplyAsync(
- const DBusMessage& dbusMessage,
- std::unique_ptr<DBusMessageReplyAsyncHandler> dbusMessageReplyAsyncHandler,
- int timeoutMilliseconds = kDefaultSendTimeoutMs) const = 0;
-
- virtual DBusMessage sendDBusMessageWithReplyAndBlock(
- const DBusMessage& dbusMessage,
- DBusError& dbusError,
- int timeoutMilliseconds = kDefaultSendTimeoutMs) const = 0;
-
- virtual DBusSignalHandlerToken addSignalMemberHandler(
- const std::string& objectPath,
- const std::string& interfaceName,
- const std::string& interfaceMemberName,
- const std::string& interfaceMemberSignature,
- DBusSignalHandler* dbusSignalHandler) = 0;
-
- virtual void removeSignalMemberHandler(const DBusSignalHandlerToken& dbusSignalHandlerToken) = 0;
-
- virtual const std::shared_ptr<DBusDaemonProxy>& getDBusDaemonProxy() = 0;
- virtual const std::shared_ptr<DBusServiceRegistry>& getDBusServiceRegistry() = 0;
- virtual const std::shared_ptr<DBusObjectManager>& getDBusObjectManager() = 0;
-};
-
-
-} // namespace DBus
-} // namespace CommonAPI
-
-#endif //COMMONAPI_DBUS_DBUS_PROXY_CONNECTION_H_
+/* Copyright (C) 2013 BMW Group
+ * Author: Manfred Bathelt (manfred.bathelt@bmw.de)
+ * Author: Juergen Gehring (juergen.gehring@bmw.de)
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+#ifndef COMMONAPI_DBUS_DBUS_PROXY_CONNECTION_H_
+#define COMMONAPI_DBUS_DBUS_PROXY_CONNECTION_H_
+
+#include "DBusError.h"
+#include "DBusMessage.h"
+
+#include "DBusFunctionalHash.h"
+#include "DBusServiceStatusEvent.h"
+
+#include <CommonAPI/types.h>
+#include <CommonAPI/Attribute.h>
+#include <CommonAPI/Event.h>
+
+#include <cstdint>
+#include <functional>
+#include <future>
+#include <memory>
+#include <tuple>
+#include <unordered_map>
+#include <utility>
+#include <vector>
+
+namespace CommonAPI {
+namespace DBus {
+
+
+typedef std::function<void(const DBusMessage&)> DBusMessageHandler;
+
+class DBusDaemonProxy;
+class DBusServiceRegistry;
+class DBusObjectManager;
+
+
+class DBusProxyConnection {
+ public:
+ class DBusMessageReplyAsyncHandler {
+ public:
+ virtual ~DBusMessageReplyAsyncHandler() { }
+ virtual std::future<CallStatus> getFuture() = 0;
+ virtual void onDBusMessageReply(const CallStatus&, const DBusMessage&) = 0;
+ };
+
+ class DBusSignalHandler {
+ public:
+ virtual ~DBusSignalHandler() { }
+ virtual SubscriptionStatus onSignalDBusMessage(const DBusMessage&) = 0;
+ };
+
+ // objectPath, interfaceName, interfaceMemberName, interfaceMemberSignature
+ typedef std::tuple<std::string, std::string, std::string, std::string> DBusSignalHandlerPath;
+ typedef std::unordered_multimap<DBusSignalHandlerPath, DBusSignalHandler*> DBusSignalHandlerTable;
+ typedef DBusSignalHandlerPath DBusSignalHandlerToken;
+
+ typedef Event<AvailabilityStatus> ConnectionStatusEvent;
+
+ virtual ~DBusProxyConnection() { }
+
+ virtual bool isConnected() const = 0;
+
+ virtual ConnectionStatusEvent& getConnectionStatusEvent() = 0;
+
+ virtual bool sendDBusMessage(const DBusMessage& dbusMessage, uint32_t* allocatedSerial = NULL) const = 0;
+
+ static const int kDefaultSendTimeoutMs = 100 * 1000;
+
+ virtual std::future<CallStatus> sendDBusMessageWithReplyAsync(
+ const DBusMessage& dbusMessage,
+ std::unique_ptr<DBusMessageReplyAsyncHandler> dbusMessageReplyAsyncHandler,
+ int timeoutMilliseconds = kDefaultSendTimeoutMs) const = 0;
+
+ virtual DBusMessage sendDBusMessageWithReplyAndBlock(
+ const DBusMessage& dbusMessage,
+ DBusError& dbusError,
+ int timeoutMilliseconds = kDefaultSendTimeoutMs) const = 0;
+
+ virtual DBusSignalHandlerToken addSignalMemberHandler(
+ const std::string& objectPath,
+ const std::string& interfaceName,
+ const std::string& interfaceMemberName,
+ const std::string& interfaceMemberSignature,
+ DBusSignalHandler* dbusSignalHandler) = 0;
+
+ virtual void removeSignalMemberHandler(const DBusSignalHandlerToken& dbusSignalHandlerToken) = 0;
+
+ virtual const std::shared_ptr<DBusServiceRegistry> getDBusServiceRegistry() = 0;
+ virtual const std::shared_ptr<DBusObjectManager> getDBusObjectManager() = 0;
+};
+
+
+} // namespace DBus
+} // namespace CommonAPI
+
+#endif //COMMONAPI_DBUS_DBUS_PROXY_CONNECTION_H_
diff --git a/src/CommonAPI/DBus/DBusProxyHelper.h b/src/CommonAPI/DBus/DBusProxyHelper.h
index 701c3a9..5483d2b 100644
--- a/src/CommonAPI/DBus/DBusProxyHelper.h
+++ b/src/CommonAPI/DBus/DBusProxyHelper.h
@@ -10,6 +10,7 @@
#include "DBusMessage.h"
#include "DBusSerializableArguments.h"
#include "DBusProxyAsyncCallbackHandler.h"
+#include "DBusProxyConnection.h"
#include <functional>
#include <future>
@@ -129,11 +130,25 @@ struct DBusProxyHelper<_In<_InArgs...>, _Out<_OutArgs...>> {
dbusMessage,
DBusProxyAsyncCallbackHandler<_OutArgs...>::create(std::move(asyncCallback)));
} else {
+
+ CallStatus callStatus = CallStatus::NOT_AVAILABLE;
+
+ callCallbackOnNotAvailable(asyncCallback, typename make_sequence<sizeof...(_OutArgs)>::type());
+
std::promise<CallStatus> promise;
- promise.set_value(CallStatus::NOT_AVAILABLE);
+ promise.set_value(callStatus);
return promise.get_future();
}
}
+
+ template <int... _ArgIndices>
+ static void callCallbackOnNotAvailable(std::function<void(CallStatus, _OutArgs...)> callback,
+ index_sequence<_ArgIndices...>) {
+
+ std::tuple<_OutArgs...> argTuple;
+ const CallStatus callstatus = CallStatus::NOT_AVAILABLE;
+ callback(callstatus, std::move(std::get<_ArgIndices>(argTuple))...);
+ }
};
} // namespace DBus
diff --git a/src/CommonAPI/DBus/DBusRuntime.cpp b/src/CommonAPI/DBus/DBusRuntime.cpp
index 5d80530..da1b272 100644
--- a/src/CommonAPI/DBus/DBusRuntime.cpp
+++ b/src/CommonAPI/DBus/DBusRuntime.cpp
@@ -1,32 +1,32 @@
-/* Copyright (C) 2013 BMW Group
- * Author: Manfred Bathelt (manfred.bathelt@bmw.de)
- * Author: Juergen Gehring (juergen.gehring@bmw.de)
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-#include "DBusRuntime.h"
-
-namespace CommonAPI {
-namespace DBus {
-
-const MiddlewareInfo DBusRuntime::middlewareInfo_("DBus", &DBusRuntime::getInstance);
-
-__attribute__((constructor)) void registerDBusMiddleware(void) {
- Runtime::registerRuntimeLoader("DBus", &DBusRuntime::getInstance);
-}
-
-std::shared_ptr<Runtime> DBusRuntime::getInstance() {
- static std::shared_ptr<Runtime> singleton_;
- if(!singleton_) {
- singleton_ = std::make_shared<DBusRuntime>();
- }
- return singleton_;
-}
-
-std::shared_ptr<Factory> DBusRuntime::createFactory() {
- auto factory = std::make_shared<DBusFactory>(this->shared_from_this(), &middlewareInfo_);
- return factory;
-}
-
-} // namespace DBus
-} // namespace CommonAPI
+/* Copyright (C) 2013 BMW Group
+ * Author: Manfred Bathelt (manfred.bathelt@bmw.de)
+ * Author: Juergen Gehring (juergen.gehring@bmw.de)
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+#include "DBusRuntime.h"
+
+namespace CommonAPI {
+namespace DBus {
+
+const MiddlewareInfo DBusRuntime::middlewareInfo_("DBus", &DBusRuntime::getInstance);
+
+__attribute__((constructor)) void registerDBusMiddleware(void) {
+ Runtime::registerRuntimeLoader("DBus", &DBusRuntime::getInstance);
+}
+
+std::shared_ptr<Runtime> DBusRuntime::getInstance() {
+ static std::shared_ptr<Runtime> singleton_;
+ if(!singleton_) {
+ singleton_ = std::make_shared<DBusRuntime>();
+ }
+ return singleton_;
+}
+
+std::shared_ptr<Factory> DBusRuntime::createFactory() {
+ auto factory = std::make_shared<DBusFactory>(this->shared_from_this(), &middlewareInfo_);
+ return factory;
+}
+
+} // namespace DBus
+} // namespace CommonAPI
diff --git a/src/CommonAPI/DBus/DBusRuntime.h b/src/CommonAPI/DBus/DBusRuntime.h
index 82584f6..b91f304 100644
--- a/src/CommonAPI/DBus/DBusRuntime.h
+++ b/src/CommonAPI/DBus/DBusRuntime.h
@@ -1,36 +1,36 @@
-/* Copyright (C) 2013 BMW Group
- * Author: Manfred Bathelt (manfred.bathelt@bmw.de)
- * Author: Juergen Gehring (juergen.gehring@bmw.de)
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-#ifndef COMMONAPI_DBUS_DBUS_RUNTIME_H_
-#define COMMONAPI_DBUS_DBUS_RUNTIME_H_
-
-#include "CommonAPI/Runtime.h"
-
-#include "DBusFactory.h"
-
-namespace CommonAPI {
-namespace DBus {
-
-class DBusRuntime: public Runtime, public std::enable_shared_from_this<DBusRuntime> {
- public:
- static std::shared_ptr<Runtime> getInstance();
-
- std::shared_ptr<Factory> createFactory();
-
- static const MiddlewareInfo middlewareInfo_;
-};
-
-} // namespace DBus
-} // namespace CommonAPI
-
-
-extern "C" {
-
-CommonAPI::MiddlewareInfo middlewareInfo = CommonAPI::DBus::DBusRuntime::middlewareInfo_;
-
-}
-
-#endif // COMMONAPI_DBUS_DBUS_RUNTIME_H_
+/* Copyright (C) 2013 BMW Group
+ * Author: Manfred Bathelt (manfred.bathelt@bmw.de)
+ * Author: Juergen Gehring (juergen.gehring@bmw.de)
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+#ifndef COMMONAPI_DBUS_DBUS_RUNTIME_H_
+#define COMMONAPI_DBUS_DBUS_RUNTIME_H_
+
+#include "CommonAPI/Runtime.h"
+
+#include "DBusFactory.h"
+
+namespace CommonAPI {
+namespace DBus {
+
+class DBusRuntime: public Runtime, public std::enable_shared_from_this<DBusRuntime> {
+ public:
+ static std::shared_ptr<Runtime> getInstance();
+
+ std::shared_ptr<Factory> createFactory();
+
+ static const MiddlewareInfo middlewareInfo_;
+};
+
+} // namespace DBus
+} // namespace CommonAPI
+
+
+extern "C" {
+
+CommonAPI::MiddlewareInfo middlewareInfo = CommonAPI::DBus::DBusRuntime::middlewareInfo_;
+
+}
+
+#endif // COMMONAPI_DBUS_DBUS_RUNTIME_H_
diff --git a/src/CommonAPI/DBus/DBusServiceRegistry.cpp b/src/CommonAPI/DBus/DBusServiceRegistry.cpp
index 035947b..a0ad227 100644
--- a/src/CommonAPI/DBus/DBusServiceRegistry.cpp
+++ b/src/CommonAPI/DBus/DBusServiceRegistry.cpp
@@ -1,314 +1,582 @@
-/* Copyright (C) 2013 BMW Group
- * Author: Manfred Bathelt (manfred.bathelt@bmw.de)
- * Author: Juergen Gehring (juergen.gehring@bmw.de)
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-#include <utility>
-#include <sstream>
-#include <string>
-#include <tuple>
-#include <unistd.h>
-
-#include "DBusServiceRegistry.h"
-#include "DBusInputStream.h"
-#include "DBusDaemonProxy.h"
-#include "DBusConnection.h"
-#include "DBusUtils.h"
-
-
-namespace CommonAPI {
-namespace DBus {
-
-
-DBusServiceRegistry::DBusServiceRegistry(std::shared_ptr<DBusConnection> dbusConnection) :
- dbusConnection_(dbusConnection),
- ready(false),
- serviceStatusEvent_(std::shared_ptr<DBusServiceRegistry>(this)),
- readyPromise_(),
- readyMutex_()
-{
- readyFuture_ = readyPromise_.get_future();
- cacheAllServices();
- dbusNameOwnerChangedEventSubscription_ =
- dbusConnection_->getDBusDaemonProxy()->getNameOwnerChangedEvent().subscribe(
- std::bind(&DBusServiceRegistry::onDBusNameOwnerChangedEvent,
- this,
- std::placeholders::_1,
- std::placeholders::_2,
- std::placeholders::_3));
- std::thread(std::bind(&DBusServiceRegistry::isReadyBlocking, this)).detach();
-}
-
-void DBusServiceRegistry::registerAvailabilityListener(const std::string& service, const std::function<void(bool)>& listener) {
- availabilityCallbackList.insert({service, listener});
-
-}
-
-DBusServiceStatusEvent& DBusServiceRegistry::getServiceStatusEvent() {
- return serviceStatusEvent_;
-}
-
-DBusServiceRegistry::~DBusServiceRegistry() {
- dbusConnection_->getDBusDaemonProxy()->getNameOwnerChangedEvent().unsubscribe(dbusNameOwnerChangedEventSubscription_);
-}
-
-std::future<bool>& DBusServiceRegistry::getReadyFuture() {
- return readyFuture_;
-}
-
-bool DBusServiceRegistry::isReadyBlocking() {
- if (!ready) {
- readyMutex_.lock();
- auto status = readyFuture_.wait_for(std::chrono::seconds(1));
- if (checkReady(status)) {
- ready = true;
- } else {
- ready = true;
- readyPromise_.set_value(true);
- }
- readyMutex_.unlock();
- }
- return ready;
-}
-
-bool DBusServiceRegistry::isReady() {
- return ready;
-}
-
-std::vector<std::string> DBusServiceRegistry::getAvailableServiceInstances(const std::string& serviceInterfaceName,
- const std::string& serviceDomainName) {
- if (!isReadyBlocking()) {
- return std::vector<std::string>();
- }
-
- if (serviceDomainName != "local" || !dbusConnection_->isConnected()) {
- return std::vector<std::string>();
- }
-
- std::vector<std::string> addressesOfKnownServiceInstances;
- auto knownServiceInstancesIteratorPair = dbusCachedProvidersForInterfaces_.equal_range(serviceInterfaceName);
-
- while(knownServiceInstancesIteratorPair.first != knownServiceInstancesIteratorPair.second) {
- const DBusServiceInstanceId dbusServiceInstanceId = knownServiceInstancesIteratorPair.first->second;
- addressesOfKnownServiceInstances.push_back(findInstanceIdMapping(dbusServiceInstanceId));
- ++knownServiceInstancesIteratorPair.first;
- }
-
- return addressesOfKnownServiceInstances;
-}
-
-void DBusServiceRegistry::onManagedPathsList(const CallStatus& status, DBusObjectToInterfaceDict managedObjects,
- std::list<std::string>::iterator iter, std::shared_ptr<std::list<std::string>> list) {
-
- auto objectPathIterator = managedObjects.begin();
-
- while (objectPathIterator != managedObjects.end()) {
- const std::string& serviceObjPath = objectPathIterator->first;
- auto interfaceNameIterator = objectPathIterator->second.begin();
-
- while (interfaceNameIterator != objectPathIterator->second.end()) {
- const std::string& interfaceName = interfaceNameIterator->first;
- dbusCachedProvidersForInterfaces_.insert( { interfaceName, { *iter, serviceObjPath } });
- ++interfaceNameIterator;
- }
- ++objectPathIterator;
- }
-
- list->erase(iter);
-
- if (list->size() == 0) {
- readyMutex_.lock();
- if (!ready) {
- readyPromise_.set_value(true);
- ready = true;
- }
- readyMutex_.unlock();
- }
-}
-
-bool DBusServiceRegistry::isServiceInstanceAlive(const std::string& address) {
- std::vector<std::string> parts = split(address, ':');
- return isServiceInstanceAlive(parts[2], parts[1], parts[0]);
-}
-
-
-bool DBusServiceRegistry::isServiceInstanceAlive(const std::string& serviceInstanceID,
- const std::string& serviceInterfaceName,
- const std::string& serviceDomainName ) {
- if (!isReadyBlocking()) {
- return false;
- }
-
- if (serviceDomainName != "local" || !dbusConnection_->isConnected()) {
- return false;
- }
-
- DBusServiceInstanceId serviceInstanceId = findInstanceIdMapping(serviceInstanceID);
-
- auto knownInstancesForInterfaceIteratorPair = dbusCachedProvidersForInterfaces_.equal_range(serviceInterfaceName);
-
- while(knownInstancesForInterfaceIteratorPair.first != knownInstancesForInterfaceIteratorPair.second) {
- DBusServiceInstanceId knownServiceId = knownInstancesForInterfaceIteratorPair.first->second;
- if(knownServiceId == serviceInstanceId) {
- return true;
- }
- ++knownInstancesForInterfaceIteratorPair.first;
- }
-
- return false;
-}
-
-void DBusServiceRegistry::getManagedObjects(const std::string& dbusWellKnownBusName) {
- auto callMessage = DBusMessage::createMethodCall(
- dbusWellKnownBusName.c_str(),
- "/",
- "org.freedesktop.DBus.ObjectManager",
- "GetManagedObjects",
- "");
- dbusConnection_->sendDBusMessageWithReplyAsync(
- callMessage,
- DBusProxyAsyncCallbackHandler<DBusObjectToInterfaceDict>::create(
- std::bind(
- &DBusServiceRegistry::onManagedPaths,
- this,
- std::placeholders::_1,
- std::placeholders::_2,
- dbusWellKnownBusName)), 100);
-
-}
-
-void DBusServiceRegistry::onManagedPaths(const CallStatus& status, DBusObjectToInterfaceDict managedObjects,
- std::string dbusWellKnownBusName) {
-
- auto objectPathIterator = managedObjects.begin();
-
- while (objectPathIterator != managedObjects.end()) {
- const std::string& serviceObjPath = objectPathIterator->first;
- auto interfaceNameIterator = objectPathIterator->second.begin();
-
- while (interfaceNameIterator != objectPathIterator->second.end()) {
- const std::string& interfaceName = interfaceNameIterator->first;
- dbusCachedProvidersForInterfaces_.insert( { interfaceName, { dbusWellKnownBusName, serviceObjPath } });
- updateListeners(dbusWellKnownBusName, serviceObjPath, interfaceName, true);
- ++interfaceNameIterator;
- }
-
- ++objectPathIterator;
- }
-}
-
-void DBusServiceRegistry::updateListeners(const std::string& conName, const std::string& objName, const std::string& intName , bool available) {
- auto found = availabilityCallbackList.equal_range(findCommonAPIAddressForDBusAddress(conName, objName, intName));
- auto foundIter = found.first;
- while (foundIter != found.second) {
- foundIter->second(true);
- foundIter++;
- }
-
-}
-
-void DBusServiceRegistry::addProvidedServiceInstancesToCache(const std::string& dbusNames) {
- getManagedObjects(dbusNames);
-}
-
-void DBusServiceRegistry::addProvidedServiceInstancesToCache(std::vector<std::string>& dbusNames) {
-
- std::shared_ptr<std::list<std::string>> dbusList = std::make_shared<std::list<std::string>>(dbusNames.begin(), dbusNames.end());
-
- auto iter = dbusList->begin();
-
- while (iter != dbusList->end()) {
-
- auto callMessage = DBusMessage::createMethodCall(
- iter->c_str(),
- "/",
- "org.freedesktop.DBus.ObjectManager",
- "GetManagedObjects",
- "");
- dbusConnection_->sendDBusMessageWithReplyAsync(
- callMessage,
- DBusProxyAsyncCallbackHandler<DBusObjectToInterfaceDict>::create(
- std::bind(
- &DBusServiceRegistry::onManagedPathsList,
- this,
- std::placeholders::_1,
- std::placeholders::_2,
- iter,
- dbusList)), 10);
- iter++;
- }
-}
-
-
-DBusServiceInstanceId DBusServiceRegistry::findInstanceIdMapping(const std::string& instanceId) const {
- DBusServiceInstanceId instanceDescriptor;
- findFallbackInstanceIdMapping(instanceId, instanceDescriptor.first, instanceDescriptor.second);
- return instanceDescriptor;
-}
-
-std::string DBusServiceRegistry::findInstanceIdMapping(const DBusServiceInstanceId& dbusInstanceId) const {
- return findFallbackInstanceIdMapping(dbusInstanceId.first, dbusInstanceId.second);
-}
-
-inline const bool isServiceName(const std::string& name) {
- return name[0] != ':';
-}
-
-void DBusServiceRegistry::onDBusNameOwnerChangedEvent(const std::string& affectedName,
- const std::string& oldOwner,
- const std::string& newOwner) {
- if (isServiceName(affectedName)) {
- if(!oldOwner.empty()) {
- removeProvidedServiceInstancesFromCache(affectedName);
- }
-
- if (!newOwner.empty()) {
- addProvidedServiceInstancesToCache(affectedName);
- }
- }
-}
-
-
-void DBusServiceRegistry::removeProvidedServiceInstancesFromCache(const std::string& dbusWellKnownBusName) {
- auto providersForInterfacesIteratorPair = dbusCachedProvidersForInterfaces_.equal_range(dbusWellKnownBusName);
-
- //Iteriere über (interfaceName, (serviceInstanceId))
- while(providersForInterfacesIteratorPair.first != providersForInterfacesIteratorPair.second) {
-
- DBusServiceInstanceId dbusInstanceId = providersForInterfacesIteratorPair.first->second;
- if(dbusInstanceId.first == dbusWellKnownBusName) {
- auto toErase = providersForInterfacesIteratorPair.first;
- ++providersForInterfacesIteratorPair.first;
- dbusCachedProvidersForInterfaces_.erase(toErase);
- }
-
- ++providersForInterfacesIteratorPair.first;
- }
-}
-
-void DBusServiceRegistry::onListNames(const CommonAPI::CallStatus& callStatus, std::vector<std::string> existingBusConnections) {
-
- if (callStatus == CallStatus::SUCCESS) {
- std::vector<std::string> dbusLivingServiceBusNames;
- for (const std::string& connectionName : existingBusConnections) {
- const bool isWellKnownName = (connectionName[0] != ':');
-
- if (isWellKnownName) {
- dbusLivingServiceBusNames.push_back(connectionName);
- }
- }
- addProvidedServiceInstancesToCache(dbusLivingServiceBusNames);
- }
-}
-
-void DBusServiceRegistry::cacheAllServices() {
- CommonAPI::CallStatus callStatus;
- std::vector<std::string> existingBusConnections;
- dbusConnection_->getDBusDaemonProxy()->listNames(callStatus, existingBusConnections);
- onListNames(callStatus, existingBusConnections);
-}
-
-
-}// namespace DBus
-} // namespace CommonAPI
+/* Copyright (C) 2013 BMW Group
+ * Author: Manfred Bathelt (manfred.bathelt@bmw.de)
+ * Author: Juergen Gehring (juergen.gehring@bmw.de)
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+#include "DBusFunctionalHash.h"
+#include "DBusServiceRegistry.h"
+#include "DBusDaemonProxy.h"
+#include "DBusProxyAsyncCallbackHandler.h"
+
+namespace CommonAPI {
+namespace DBus {
+
+DBusServiceRegistry::DBusServiceRegistry(std::shared_ptr<DBusProxyConnection> dbusProxyConnection):
+ dbusDaemonProxy_(std::make_shared<CommonAPI::DBus::DBusDaemonProxy>(dbusProxyConnection)),
+ dbusNameListStatus_(AvailabilityStatus::UNKNOWN),
+ initialized_(false) {
+}
+
+DBusServiceRegistry::~DBusServiceRegistry() {
+ if(initialized_) {
+ std::lock_guard<std::mutex> dbusServicesLock(dbusServicesMutex_);
+ dbusDaemonProxy_->getNameOwnerChangedEvent().unsubscribe(dbusDaemonProxyNameOwnerChangedEventSubscription_);
+ dbusDaemonProxy_->getProxyStatusEvent().unsubscribe(dbusDaemonProxyStatusEventSubscription_);
+ }
+}
+
+void DBusServiceRegistry::init() {
+ dbusDaemonProxyStatusEventSubscription_ =
+ dbusDaemonProxy_->getProxyStatusEvent().subscribeCancellableListener(
+ std::bind(&DBusServiceRegistry::onDBusDaemonProxyStatusEvent, this, std::placeholders::_1));
+
+ dbusDaemonProxyNameOwnerChangedEventSubscription_ =
+ dbusDaemonProxy_->getNameOwnerChangedEvent().subscribeCancellableListener(
+ std::bind(&DBusServiceRegistry::onDBusDaemonProxyNameOwnerChangedEvent,
+ this,
+ std::placeholders::_1,
+ std::placeholders::_2,
+ std::placeholders::_3));
+ initialized_ = true;
+}
+
+bool DBusServiceRegistry::waitDBusServicesAvailable(std::unique_lock<std::mutex>& lock, std::chrono::milliseconds& timeout) {
+ bool dbusServicesStatusIsKnown = (dbusNameListStatus_ != AvailabilityStatus::UNKNOWN);
+
+ while (!dbusServicesStatusIsKnown && timeout.count() > 0) {
+ typedef std::chrono::high_resolution_clock clock;
+ clock::time_point startTimePoint = clock::now();
+
+ dbusServicesStatusIsKnown = dbusServiceChanged_.wait_for(
+ lock,
+ timeout,
+ [&]{ return dbusNameListStatus_ != AvailabilityStatus::UNKNOWN; });
+
+ std::chrono::milliseconds elapsedWaitTime =
+ std::chrono::duration_cast<std::chrono::milliseconds>(clock::now() - startTimePoint);
+
+ if (elapsedWaitTime > timeout) {
+ timeout = std::chrono::milliseconds::zero();
+ break;
+ }
+
+ timeout -= elapsedWaitTime;
+ }
+
+ return (dbusNameListStatus_ == AvailabilityStatus::AVAILABLE);
+}
+
+bool DBusServiceRegistry::isServiceInstanceAlive(const std::string& dbusInterfaceName, const std::string& dbusServiceName, const std::string& dbusObjectPath) {
+ if (!dbusDaemonProxy_->isAvailable()) {
+ return false;
+ }
+
+ std::chrono::milliseconds timeout(2000);
+ std::unique_lock<std::mutex> dbusServicesLock(dbusServicesMutex_);
+
+ if (!waitDBusServicesAvailable(dbusServicesLock, timeout)) {
+ return false;
+ }
+
+ auto dbusServiceIterator = dbusServices_.find(dbusServiceName);
+ if (dbusServiceIterator == dbusServices_.end()) {
+ return false;
+ }
+
+ DBusServiceState& dbusServiceState = dbusServiceIterator->second.first;
+
+ if (dbusServiceState == DBusServiceState::AVAILABLE) {
+ resolveDBusServiceInstances(dbusServiceIterator);
+ }
+
+ if (dbusServiceState == DBusServiceState::RESOLVING) {
+ dbusServiceChanged_.wait_for(
+ dbusServicesLock,
+ timeout,
+ [&] { return dbusServiceState != DBusServiceState::RESOLVING; });
+ }
+
+ const DBusInstanceList& dbusInstanceList = dbusServiceIterator->second.second;
+ auto dbusInstanceIterator = dbusInstanceList.find({ dbusObjectPath, dbusInterfaceName });
+
+ if (dbusInstanceIterator != dbusInstanceList.end()) {
+ const AvailabilityStatus& dbusInstanceAvailabilityStatus = dbusInstanceIterator->second.first;
+
+ return (dbusInstanceAvailabilityStatus == AvailabilityStatus::AVAILABLE);
+ }
+
+ return false;
+}
+
+// Go through the list of available services and check their interface lists
+// If a list is still unknown, then send request to the remote object manager and count it as invalid
+// If a list is in acquiring state, then just count it as invalid and skip over it
+// Add all matching valid services to the available service list
+// If the invalid service count is set, then wait upto waitTimeLimit (2 seconds) for the object manager requests to complete
+// If the timeout expires, then go through the list for last time and add everything matching
+// If the timeout didn't expire, then go through the list again and send requests for new UNKNOWN services, then wait again for them to complete
+// Known limitations:
+// - if the method is called before the first "listNames()" call completes, this request will be blocked
+// - if libdbus is broken and doesn't report errors to timed out requests, then this request will always block for the default 2 seconds (waitTimeLimit)
+// - the method has to be called many times, if you actually want to wait for all services, otherwise you'll always get a partial response. I.e. the more you call this method, the hotter the internal cache gets.
+std::vector<std::string> DBusServiceRegistry::getAvailableServiceInstances(const std::string& serviceName,
+ const std::string& domainName) {
+ std::vector<std::string> availableServiceInstances;
+
+ if (!dbusDaemonProxy_->isAvailable()) {
+ return availableServiceInstances;
+ }
+
+ std::chrono::milliseconds timeout(2000);
+ std::unique_lock<std::mutex> dbusServicesLock(dbusServicesMutex_);
+
+ if (!waitDBusServicesAvailable(dbusServicesLock, timeout)) {
+ return availableServiceInstances;
+ }
+
+ while (timeout.count() > 0) {
+ size_t dbusServiceResolvingCount = getAvailableServiceInstances(serviceName, availableServiceInstances);
+
+ if (!dbusServiceResolvingCount) {
+ break;
+ }
+
+ // wait for unknown and acquiring services, then restart from the beginning
+ typedef std::chrono::high_resolution_clock clock;
+ clock::time_point startTimePoint = clock::now();
+
+ size_t wakeupCount = 0;
+ dbusServiceChanged_.wait_for(
+ dbusServicesLock,
+ timeout,
+ [&] {
+ wakeupCount++;
+ return wakeupCount > dbusServiceResolvingCount;
+ });
+
+ if (wakeupCount > 1) {
+ getAvailableServiceInstances(serviceName, availableServiceInstances);
+ break;
+ }
+
+ std::chrono::milliseconds elapsedWaitTime =
+ std::chrono::duration_cast<std::chrono::milliseconds>(clock::now() - startTimePoint);
+ timeout -= elapsedWaitTime;
+ }
+
+ // maybe partial list but it contains everything we know for now
+ return availableServiceInstances;
+}
+
+size_t DBusServiceRegistry::getAvailableServiceInstances(const std::string& dbusInterfaceName, std::vector<std::string>& availableServiceInstances) {
+ size_t dbusServicesResolvingCount = 0;
+
+ availableServiceInstances.clear();
+
+ // caller must hold lock
+ auto dbusServiceIterator = dbusServices_.begin();
+ while (dbusServiceIterator != dbusServices_.end()) {
+ const std::string& dbusServiceName = dbusServiceIterator->first;
+ DBusServiceState& dbusServiceState = dbusServiceIterator->second.first;
+ const DBusInstanceList& dbusInstanceList = dbusServiceIterator->second.second;
+
+ // count the resolving services and start aclquiring the objects for unknown ones
+ switch (dbusServiceState) {
+ case DBusServiceState::AVAILABLE:
+ resolveDBusServiceInstances(dbusServiceIterator);
+ dbusServicesResolvingCount++;
+ break;
+
+ case DBusServiceState::RESOLVING:
+ case DBusServiceState::RESOLVED:
+ if (dbusServiceState == DBusServiceState::RESOLVING) {
+ dbusServicesResolvingCount++;
+ }
+
+ for (auto& dbusInstanceIterator : dbusInstanceList) {
+ const AvailabilityStatus& dbusInstanceAvailabilityStatus = dbusInstanceIterator.second.first;
+ const std::string& dbusInstanceObjectPath = dbusInstanceIterator.first.first;
+ const std::string& dbusInstanceInterfaceName = dbusInstanceIterator.first.second;
+
+ if (dbusInstanceAvailabilityStatus == AvailabilityStatus::AVAILABLE
+ && dbusInstanceInterfaceName == dbusInterfaceName) {
+ std::string commonApiAddress;
+
+ DBusAddressTranslator::getInstance().searchForCommonAddress(
+ dbusInterfaceName,
+ dbusServiceName,
+ dbusInstanceObjectPath,
+ commonApiAddress);
+
+ availableServiceInstances.emplace_back(std::move(commonApiAddress));
+ }
+ }
+ break;
+ }
+
+ dbusServiceIterator++;
+ }
+
+ return dbusServicesResolvingCount;
+}
+
+
+DBusServiceRegistry::Subscription DBusServiceRegistry::subscribeAvailabilityListener(const std::string& commonApiAddress,
+ DBusServiceListener serviceListener) {
+ std::string dbusInterfaceName;
+ std::string dbusServiceName;
+ std::string dbusObjectPath;
+
+ DBusAddressTranslator::getInstance().searchForDBusAddress(commonApiAddress, dbusInterfaceName, dbusServiceName, dbusObjectPath);
+
+ std::lock_guard<std::mutex> dbusServicesLock(dbusServicesMutex_);
+
+ DBusServiceList::iterator dbusServiceIterator = dbusServices_.find(dbusServiceName);
+
+ // add service for the first time
+ if (dbusServiceIterator == dbusServices_.end()) {
+ DBusServiceState dbusConnectionNameState = DBusServiceState::UNKNOWN;
+
+ if (dbusNameListStatus_ == AvailabilityStatus::AVAILABLE) {
+ dbusConnectionNameState = DBusServiceState::RESOLVED;
+ }
+
+ std::pair<DBusServiceList::iterator, bool> insertResult = dbusServices_.insert({ dbusServiceName, { dbusConnectionNameState, DBusInstanceList() } });
+ assert(insertResult.second);
+ dbusServiceIterator = insertResult.first;
+ }
+
+ DBusServiceState& dbusConnectionNameState = dbusServiceIterator->second.first;
+ DBusInstanceList& dbusInstanceList = dbusServiceIterator->second.second;
+
+ auto dbusInstanceIterator = addDBusServiceInstance(
+ dbusInstanceList,
+ dbusObjectPath,
+ dbusInterfaceName);
+ AvailabilityStatus& dbusInstanceAvailabilityStatus = dbusInstanceIterator->second.first;
+ DBusServiceListenerList& dbusServiceListenerList = dbusInstanceIterator->second.second;
+
+ if (dbusConnectionNameState == DBusServiceState::RESOLVED
+ && dbusInstanceAvailabilityStatus == AvailabilityStatus::UNKNOWN) {
+ dbusInstanceAvailabilityStatus = AvailabilityStatus::NOT_AVAILABLE;
+ }
+
+ Subscription listenerSubscription = dbusServiceListenerList.insert(
+ dbusServiceListenerList.end(), serviceListener);
+
+ switch (dbusConnectionNameState) {
+ case DBusServiceState::AVAILABLE:
+ resolveDBusServiceInstances(dbusServiceIterator);
+ break;
+
+ case DBusServiceState::RESOLVING:
+ if (dbusInstanceAvailabilityStatus == AvailabilityStatus::AVAILABLE) {
+ serviceListener(dbusInstanceAvailabilityStatus);
+ }
+ break;
+
+ case DBusServiceState::RESOLVED:
+ case DBusServiceState::NOT_AVAILABLE:
+ serviceListener(dbusInstanceAvailabilityStatus);
+ break;
+ }
+
+ return listenerSubscription;
+}
+
+void DBusServiceRegistry::unsubscribeAvailabilityListener(const std::string& commonApiAddress,
+ Subscription& listenerSubscription) {
+ std::string dbusInterfaceName;
+ std::string dbusServiceName;
+ std::string dbusObjectPath;
+
+ std::lock_guard<std::mutex> dbusServicesLock(dbusServicesMutex_);
+ DBusAddressTranslator::getInstance().searchForDBusAddress(commonApiAddress, dbusInterfaceName, dbusServiceName, dbusObjectPath);
+
+ auto dbusServiceIterator = dbusServices_.find(dbusServiceName);
+
+ if (dbusServiceIterator == dbusServices_.end()) {
+ return;
+ }
+
+ DBusServiceState& dbusServiceState = dbusServiceIterator->second.first;
+ DBusInstanceList& dbusInstanceList = dbusServiceIterator->second.second;
+
+ auto dbusInstanceIterator = dbusInstanceList.find({ dbusObjectPath, dbusInterfaceName });
+ if (dbusInstanceIterator == dbusInstanceList.end()) {
+ return;
+ }
+
+ const AvailabilityStatus& dbusServiceAvailabilityStatus = dbusInstanceIterator->second.first;
+ DBusServiceListenerList& dbusServiceListenerList = dbusInstanceIterator->second.second;
+
+ dbusServiceListenerList.erase(listenerSubscription);
+
+ if (dbusServiceListenerList.empty() && dbusServiceAvailabilityStatus != AvailabilityStatus::AVAILABLE) {
+ dbusInstanceList.erase(dbusInstanceIterator);
+
+ if (dbusInstanceList.empty() && dbusServiceState == DBusServiceState::UNKNOWN) {
+ dbusServices_.erase(dbusServiceIterator);
+ }
+ }
+}
+
+SubscriptionStatus DBusServiceRegistry::onDBusDaemonProxyStatusEvent(const AvailabilityStatus& availabilityStatus) {
+ std::lock_guard<std::mutex> dbusServicesLock(dbusServicesMutex_);
+
+ switch (availabilityStatus) {
+ case AvailabilityStatus::AVAILABLE:
+ dbusNameListStatus_ = AvailabilityStatus::UNKNOWN;
+ dbusDaemonProxy_->listNamesAsync(std::bind(
+ &DBusServiceRegistry::onListNamesCallback,
+ this->shared_from_this(),
+ std::placeholders::_1,
+ std::placeholders::_2));
+ break;
+
+ case AvailabilityStatus::NOT_AVAILABLE:
+ auto dbusServiceIterator = dbusServices_.begin();
+
+ while (dbusServiceIterator != dbusServices_.end()) {
+ dbusServiceIterator = onDBusServiceOffline(dbusServiceIterator, DBusServiceState::NOT_AVAILABLE);
+ }
+
+ dbusNameListStatus_ = AvailabilityStatus::NOT_AVAILABLE;
+ break;
+ }
+
+ return SubscriptionStatus::RETAIN;
+}
+
+SubscriptionStatus DBusServiceRegistry::onDBusDaemonProxyNameOwnerChangedEvent(const std::string& affectedName,
+ const std::string& oldOwner,
+ const std::string& newOwner) {
+ if (isDBusServiceName(affectedName)) {
+ AvailabilityStatus dbusServiceAvailabilityStatus = AvailabilityStatus::AVAILABLE;
+
+ if (newOwner.empty()) {
+ dbusServiceAvailabilityStatus = AvailabilityStatus::NOT_AVAILABLE;
+ }
+
+ std::lock_guard<std::mutex> dbusServicesLock(dbusServicesMutex_);
+
+ onDBusServiceAvailabilityStatus(affectedName, dbusServiceAvailabilityStatus);
+ }
+
+ return SubscriptionStatus::RETAIN;
+}
+
+void DBusServiceRegistry::onListNamesCallback(const CommonAPI::CallStatus& callStatus, std::vector<std::string> dbusNames) {
+ std::lock_guard<std::mutex> dbusServicesLock(dbusServicesMutex_);
+
+ if (callStatus == CallStatus::SUCCESS) {
+ for (const std::string& dbusName : dbusNames) {
+ if (isDBusServiceName(dbusName)) {
+ onDBusServiceAvailabilityStatus(dbusName, AvailabilityStatus::AVAILABLE);
+ }
+ }
+ }
+
+ dbusNameListStatus_ = AvailabilityStatus::AVAILABLE;
+
+ auto dbusServiceIterator = dbusServices_.begin();
+ while (dbusServiceIterator != dbusServices_.end()) {
+ const DBusServiceState& dbusServiceState = dbusServiceIterator->second.first;
+
+ if (dbusServiceState == DBusServiceState::UNKNOWN) {
+ dbusServiceIterator = onDBusServiceOffline(dbusServiceIterator, DBusServiceState::NOT_AVAILABLE);
+ } else {
+ dbusServiceIterator++;
+ }
+ }
+}
+
+void DBusServiceRegistry::onDBusServiceAvailabilityStatus(const std::string& dbusServiceName, const AvailabilityStatus& availabilityStatus) {
+ auto dbusServiceIterator = dbusServices_.find(dbusServiceName);
+
+ if (dbusServiceIterator != dbusServices_.end()) {
+ onDBusServiceAvailabilityStatus(dbusServiceIterator, availabilityStatus);
+
+ } else if (availabilityStatus == AvailabilityStatus::AVAILABLE) {
+ dbusServices_.insert({ dbusServiceName, { DBusServiceState::AVAILABLE, DBusInstanceList() } });
+ dbusServiceChanged_.notify_all();
+ }
+}
+
+DBusServiceRegistry::DBusServiceList::iterator DBusServiceRegistry::onDBusServiceAvailabilityStatus(DBusServiceList::iterator& dbusServiceIterator,
+ const AvailabilityStatus& availabilityStatus) {
+ DBusServiceState& dbusServiceState = dbusServiceIterator->second.first;
+ DBusInstanceList& dbusInstanceList = dbusServiceIterator->second.second;
+
+ if (availabilityStatus == AvailabilityStatus::AVAILABLE) {
+ const std::string& dbusServiceName = dbusServiceIterator->first;
+
+ if (dbusServiceState != DBusServiceState::RESOLVING) {
+ resolveDBusServiceInstances(dbusServiceIterator);
+ }
+
+ return dbusServiceIterator;
+ }
+
+ dbusServiceState = (availabilityStatus == AvailabilityStatus::UNKNOWN) ?
+ DBusServiceState::UNKNOWN :
+ DBusServiceState::NOT_AVAILABLE;
+
+ return onDBusServiceOffline(dbusServiceIterator, dbusServiceState);
+}
+
+DBusServiceRegistry::DBusServiceList::iterator DBusServiceRegistry::onDBusServiceOffline(DBusServiceList::iterator& dbusServiceIterator,
+ const DBusServiceState& newDBusServiceState) {
+ DBusServiceState& dbusServiceState = dbusServiceIterator->second.first;
+ DBusInstanceList& dbusInstanceList = dbusServiceIterator->second.second;
+ auto dbusInstanceIterator = dbusInstanceList.begin();
+
+ assert(newDBusServiceState == DBusServiceState::UNKNOWN || newDBusServiceState == DBusServiceState::NOT_AVAILABLE);
+
+ dbusServiceState = newDBusServiceState;
+
+ while (dbusInstanceIterator != dbusInstanceList.end()) {
+ AvailabilityStatus& dbusInstanceAvailabilityStatus = dbusInstanceIterator->second.first;
+ DBusServiceListenerList& dbusServiceListenerList = dbusInstanceIterator->second.second;
+
+ // notify listeners
+ if (!dbusServiceListenerList.empty()) {
+ // the internal state is unknown until the next time we ask the object manager
+ notifyDBusServiceListeners(dbusServiceListenerList, AvailabilityStatus::NOT_AVAILABLE);
+ dbusInstanceAvailabilityStatus = AvailabilityStatus::UNKNOWN;
+ dbusInstanceIterator++;
+ } else {
+ dbusInstanceIterator = dbusInstanceList.erase(dbusInstanceIterator);
+ }
+ }
+
+ dbusServiceChanged_.notify_all();
+
+ if (dbusInstanceList.empty()) {
+ return dbusServices_.erase(dbusServiceIterator);
+ }
+
+ dbusServiceIterator++;
+
+ return dbusServiceIterator;
+}
+
+void DBusServiceRegistry::resolveDBusServiceInstances(DBusServiceList::iterator& dbusServiceIterator) {
+ const std::string& dbusServiceName = dbusServiceIterator->first;
+ DBusServiceState& dbusServiceState = dbusServiceIterator->second.first;
+ DBusInstanceList& dbusInstanceList = dbusServiceIterator->second.second;
+ std::vector<DBusServiceAddress> predefinedDBusServiceInstances;
+
+ dbusServiceState = DBusServiceState::RESOLVING;
+
+ // add predefined instances
+ DBusAddressTranslator::getInstance().getPredefinedInstances(dbusServiceName, predefinedDBusServiceInstances);
+
+ for (auto& dbusServiceAddress : predefinedDBusServiceInstances) {
+ const std::string& dbusObjectPath = std::get<1>(dbusServiceAddress);
+ const std::string& dbusInterfaceName = std::get<2>(dbusServiceAddress);
+
+ onDBusServiceInstanceAvailable(dbusInstanceList, dbusObjectPath, dbusInterfaceName);
+ }
+
+ dbusServiceChanged_.notify_all();
+
+ // search for remote instances
+ DBusDaemonProxy::GetManagedObjectsAsyncCallback callback = std::bind(&DBusServiceRegistry::onGetManagedObjectsCallback,
+ this->shared_from_this(),
+ std::placeholders::_1,
+ std::placeholders::_2,
+ dbusServiceName);
+ dbusDaemonProxy_->getManagedObjectsAsync(dbusServiceName, callback);
+}
+
+void DBusServiceRegistry::onGetManagedObjectsCallback(const CallStatus& callStatus,
+ DBusDaemonProxy::DBusObjectToInterfaceDict managedObjects,
+ const std::string& dbusServiceName) {
+ std::lock_guard<std::mutex> dbusServicesLock(dbusServicesMutex_);
+
+ // already offline
+ if (dbusNameListStatus_ == AvailabilityStatus::NOT_AVAILABLE) {
+ return;
+ }
+
+ auto dbusServiceIterator = dbusServices_.find(dbusServiceName);
+ if (dbusServiceIterator == dbusServices_.end()) {
+ return; // nothing we can do
+ }
+
+ DBusServiceState& dbusServiceState = dbusServiceIterator->second.first;
+ DBusInstanceList& dbusInstanceList = dbusServiceIterator->second.second;
+
+ dbusServiceState = DBusServiceState::RESOLVED;
+
+ if (callStatus == CallStatus::SUCCESS) {
+ for (auto& dbusObjectPathIterator : managedObjects) {
+ const std::string& dbusObjectPath = dbusObjectPathIterator.first;
+
+ for (auto& dbusInterfaceNameIterator : dbusObjectPathIterator.second) {
+ const std::string& dbusInterfaceName = dbusInterfaceNameIterator.first;
+
+ onDBusServiceInstanceAvailable(dbusInstanceList, dbusObjectPath, dbusInterfaceName);
+ }
+ }
+ }
+
+ dbusServiceChanged_.notify_all();
+
+ // notify only UNKNOWN. The predefined and resolved have already been handled
+ for (auto& dbusInstanceIterator : dbusInstanceList) {
+ AvailabilityStatus& dbusInstanceAvailabilityStatus = dbusInstanceIterator.second.first;
+ DBusServiceListenerList& dbusServiceListenerList = dbusInstanceIterator.second.second;
+
+ if (dbusInstanceAvailabilityStatus == AvailabilityStatus::UNKNOWN) {
+ dbusInstanceAvailabilityStatus = AvailabilityStatus::NOT_AVAILABLE;
+ notifyDBusServiceListeners(dbusServiceListenerList, dbusInstanceAvailabilityStatus);
+ }
+ }
+}
+
+void DBusServiceRegistry::onDBusServiceInstanceAvailable(DBusInstanceList& dbusInstanceList,
+ const std::string& dbusObjectPath,
+ const std::string& dbusInterfaceName) {
+ auto dbusInstanceIterator = addDBusServiceInstance(dbusInstanceList, dbusObjectPath, dbusInterfaceName);
+ AvailabilityStatus& dbusInstanceAvailabilityStatus = dbusInstanceIterator->second.first;
+ DBusServiceListenerList& dbusServiceListenerList = dbusInstanceIterator->second.second;
+
+ dbusInstanceAvailabilityStatus = AvailabilityStatus::AVAILABLE;
+
+ notifyDBusServiceListeners(dbusServiceListenerList, dbusInstanceAvailabilityStatus);
+}
+
+DBusServiceRegistry::DBusInstanceList::iterator DBusServiceRegistry::addDBusServiceInstance(DBusInstanceList& dbusInstanceList,
+ const std::string& dbusObjectPath,
+ const std::string& dbusInterfaceName) {
+ auto dbusInstanceIterator = dbusInstanceList.find({ dbusObjectPath, dbusInterfaceName });
+
+ // add instance for the first time
+ if (dbusInstanceIterator == dbusInstanceList.end()) {
+ auto insertIterator = dbusInstanceList.insert(
+ { { dbusObjectPath, dbusInterfaceName }, { AvailabilityStatus::UNKNOWN, DBusServiceListenerList() } });
+ const bool& insertSuccessfull = insertIterator.second;
+
+ assert(insertSuccessfull);
+ dbusInstanceIterator = insertIterator.first;
+ }
+
+ return dbusInstanceIterator;
+}
+
+void DBusServiceRegistry::notifyDBusServiceListeners(DBusServiceListenerList& dbusServiceListenerList,
+ const AvailabilityStatus& availabilityStatus) {
+ for (auto& dbusServiceListener : dbusServiceListenerList) {
+ dbusServiceListener(availabilityStatus);
+ }
+}
+
+bool DBusServiceRegistry::isDBusServiceName(const std::string& name) {
+ return name[0] != ':';
+}
+
+}// namespace DBus
+}// namespace CommonAPI
diff --git a/src/CommonAPI/DBus/DBusServiceRegistry.h b/src/CommonAPI/DBus/DBusServiceRegistry.h
index b94ac62..d07f457 100644
--- a/src/CommonAPI/DBus/DBusServiceRegistry.h
+++ b/src/CommonAPI/DBus/DBusServiceRegistry.h
@@ -1,119 +1,132 @@
-/* Copyright (C) 2013 BMW Group
- * Author: Manfred Bathelt (manfred.bathelt@bmw.de)
- * Author: Juergen Gehring (juergen.gehring@bmw.de)
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-#ifndef COMMONAPI_DBUS_DBUS_SERVICE_REGISTRY_H_
-#define COMMONAPI_DBUS_DBUS_SERVICE_REGISTRY_H_
-
-
-#include <CommonAPI/types.h>
-#include <CommonAPI/Attribute.h>
-
-#include "DBusConnection.h"
-
-#include <unordered_map>
-#include <map>
-#include <unordered_set>
-#include <string>
-#include <vector>
-#include <memory>
-#include <list>
-#include <mutex>
-
-namespace CommonAPI {
-namespace DBus {
-
-typedef Event<std::string, std::string, std::string> NameOwnerChangedEvent;
-
-typedef Event<std::string, std::string, std::string>::Subscription NameOwnerChangedEventSubscription;
-
-typedef std::pair<std::string, std::string> DBusServiceInstanceId;
-
-typedef std::unordered_map<std::string, int> PropertyDictStub;
-typedef std::unordered_map<std::string, PropertyDictStub> InterfaceToPropertyDict;
-typedef std::unordered_map<std::string, InterfaceToPropertyDict> DBusObjectToInterfaceDict;
-
-class DBusConnection;
-class DBusDaemonProxy;
-
-
-class DBusServiceRegistry {
- public:
- static constexpr const char* getManagedObjectsDBusSignature_ = "a{oa{sa{sv}}}";
-
- DBusServiceRegistry() = delete;
- DBusServiceRegistry(const DBusServiceRegistry&) = delete;
- DBusServiceRegistry& operator=(const DBusServiceRegistry&) = delete;
-
- DBusServiceRegistry(std::shared_ptr<DBusConnection> connection);
- ~DBusServiceRegistry();
-
- std::vector<std::string> getAvailableServiceInstances(const std::string& interfaceName,
- const std::string& domainName = "local");
-
- bool isServiceInstanceAlive(const std::string& instanceID,
- const std::string& interfaceName,
- const std::string& domainName = "local");
-
- bool isServiceInstanceAlive(const std::string& address);
-
- bool isReady();
-
- bool isReadyBlocking();
-
- void registerAvailabilityListener(const std::string& service, const std::function<void(bool)>& listener);
-
- std::future<bool>& getReadyFuture();
-
- DBusServiceStatusEvent& getServiceStatusEvent();
-
- private:
- void cacheAllServices();
-
- void removeProvidedServiceInstancesFromCache(const std::string& serviceBusName);
- void addProvidedServiceInstancesToCache(std::vector<std::string>& dbusNames);
- void addProvidedServiceInstancesToCache(const std::string& dbusNames);
- void addAllProvidedServiceInstancesToCache(const std::vector<std::string>& serviceBusNames);
-
- void getManagedObjects(const std::string& serviceBusName);
-
- void onDBusNameOwnerChangedEvent(const std::string& name, const std::string& oldOwner, const std::string& newOwner);
-
- bool isRemoteServiceVersionMatchingLocalVersion(const std::string& serviceBusName, const std::string& serviceInterfaceName);
- bool isServiceInstanceAliveHelper(const std::string& connectionName) const;
-
- DBusServiceInstanceId findInstanceIdMapping(const std::string& instanceId) const;
- std::string findInstanceIdMapping(const DBusServiceInstanceId& dbusInstanceId) const;
-
- void onManagedPaths(const CallStatus& status, DBusObjectToInterfaceDict replyMessage, std::string dbusWellKnownBusName);
- void onManagedPathsList(const CallStatus& status, DBusObjectToInterfaceDict managedObjects, std::list<std::string>::iterator iter, std::shared_ptr<std::list<std::string>> list);
-
- std::multimap<std::string, DBusServiceInstanceId> dbusCachedProvidersForInterfaces_;
-
- std::shared_ptr<DBusConnection> dbusConnection_;
-
- std::unordered_multimap<std::string, std::function<void(bool)>> availabilityCallbackList;
-
- bool ready;
-
- void onListNames(const CommonAPI::CallStatus&, std::vector<std::string>);
-
- NameOwnerChangedEvent::Subscription dbusNameOwnerChangedEventSubscription_;
-
- void updateListeners(const std::string& conName, const std::string& objName, const std::string& intName , bool available);
-
- mutable std::future<bool> readyFuture_;
- mutable std::promise<bool> readyPromise_;
-
- std::mutex readyMutex_;
-
- DBusServiceStatusEvent serviceStatusEvent_;
-};
-
-
-} // namespace DBus
-} // namespace CommonAPI
-
-#endif // COMMONAPI_DBUS_DBUS_SERVICE_REGISTRY_H_
+/* Copyright (C) 2013 BMW Group
+ * Author: Manfred Bathelt (manfred.bathelt@bmw.de)
+ * Author: Juergen Gehring (juergen.gehring@bmw.de)
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+#ifndef COMMONAPI_DBUS_DBUS_SERVICE_REGISTRY_H_
+#define COMMONAPI_DBUS_DBUS_SERVICE_REGISTRY_H_
+
+#include <CommonAPI/types.h>
+#include <CommonAPI/Attribute.h>
+#include <CommonAPI/Proxy.h>
+
+#include "DBusProxyConnection.h"
+#include "DBusAddressTranslator.h"
+#include "DBusDaemonProxy.h"
+
+#include <unordered_map>
+#include <utility>
+#include <map>
+#include <unordered_set>
+#include <string>
+#include <vector>
+#include <memory>
+#include <list>
+#include <algorithm>
+#include <set>
+
+#include <condition_variable>
+#include <mutex>
+
+namespace CommonAPI {
+namespace DBus {
+
+typedef Event<std::string, std::string, std::string> NameOwnerChangedEvent;
+typedef Event<std::string, std::string, std::string>::Subscription NameOwnerChangedEventSubscription;
+
+//connectionName, objectPath
+typedef std::pair<std::string, std::string> DBusInstanceId;
+
+class DBusProxyConnection;
+class DBusDaemonProxy;
+
+
+class DBusServiceRegistry: public std::enable_shared_from_this<DBusServiceRegistry> {
+ public:
+ enum class DBusServiceState {
+ UNKNOWN,
+ AVAILABLE,
+ RESOLVING,
+ RESOLVED,
+ NOT_AVAILABLE
+ };
+
+ typedef std::function<void(const AvailabilityStatus& availabilityStatus)> DBusServiceListener;
+ typedef std::list<DBusServiceListener> DBusServiceListenerList;
+ typedef DBusServiceListenerList::iterator Subscription;
+
+ typedef std::pair<std::string, std::string> DBusObjectInterfacePair;
+ typedef std::unordered_map<DBusObjectInterfacePair, std::pair<AvailabilityStatus, DBusServiceListenerList> > DBusInstanceList;
+ typedef std::unordered_map<std::string, std::pair<DBusServiceState, DBusInstanceList> > DBusServiceList;
+
+
+ DBusServiceRegistry(std::shared_ptr<DBusProxyConnection> dbusProxyConnection);
+
+ virtual ~DBusServiceRegistry();
+
+ void init();
+
+ bool isServiceInstanceAlive(const std::string& dbusInterfaceName, const std::string& dbusConnectionName, const std::string& dbusObjectPath);
+
+ Subscription subscribeAvailabilityListener(const std::string& commonApiAddress,
+ DBusServiceListener serviceListener);
+ void unsubscribeAvailabilityListener(const std::string& commonApiAddress,
+ Subscription& listenerSubscription);
+
+ virtual std::vector<std::string> getAvailableServiceInstances(const std::string& interfaceName,
+ const std::string& domainName = "local");
+
+ private:
+ DBusServiceRegistry(const DBusServiceRegistry&) = delete;
+ DBusServiceRegistry& operator=(const DBusServiceRegistry&) = delete;
+
+ SubscriptionStatus onDBusDaemonProxyStatusEvent(const AvailabilityStatus& availabilityStatus);
+ SubscriptionStatus onDBusDaemonProxyNameOwnerChangedEvent(const std::string& name, const std::string& oldOwner, const std::string& newOwner);
+
+ void onListNamesCallback(const CommonAPI::CallStatus& callStatus, std::vector<std::string> dbusNames);
+
+ void resolveDBusServiceInstances(DBusServiceList::iterator& dbusServiceIterator);
+ void onGetManagedObjectsCallback(const CallStatus& status, DBusDaemonProxy::DBusObjectToInterfaceDict managedObjects, const std::string& dbusServiceName);
+
+ size_t getAvailableServiceInstances(const std::string& dbusInterfaceName, std::vector<std::string>& availableServiceInstances);
+
+ bool waitDBusServicesAvailable(std::unique_lock<std::mutex>& lock, std::chrono::milliseconds& timeout);
+
+ void onDBusServiceAvailabilityStatus(const std::string& dbusServiceName, const AvailabilityStatus& availabilityStatus);
+ DBusServiceList::iterator onDBusServiceAvailabilityStatus(DBusServiceList::iterator& dbusServiceIterator, const AvailabilityStatus& availabilityStatus);
+ DBusServiceList::iterator onDBusServiceOffline(DBusServiceList::iterator& dbusServiceIterator, const DBusServiceState& dbusServiceState);
+
+ static void onDBusServiceInstanceAvailable(
+ DBusInstanceList& dbusInstanceList,
+ const std::string& dbusObjectPath,
+ const std::string& dbusInterfaceName);
+
+ static DBusInstanceList::iterator addDBusServiceInstance(
+ DBusInstanceList& dbusInstanceList,
+ const std::string& dbusObjectPath,
+ const std::string& dbusInterfaceName);
+
+ static void notifyDBusServiceListeners(DBusServiceListenerList& dbusServiceListenerList, const AvailabilityStatus& availabilityStatus);
+
+ static bool isDBusServiceName(const std::string& name);
+
+
+ std::shared_ptr<DBusDaemonProxy> dbusDaemonProxy_;
+
+ DBusServiceList dbusServices_;
+ AvailabilityStatus dbusNameListStatus_;
+ std::condition_variable dbusServiceChanged_;
+
+ std::mutex dbusServicesMutex_;
+
+ bool initialized_;
+
+ ProxyStatusEvent::Subscription dbusDaemonProxyStatusEventSubscription_;
+ NameOwnerChangedEvent::Subscription dbusDaemonProxyNameOwnerChangedEventSubscription_;
+};
+
+} // namespace DBus
+} // namespace CommonAPI
+
+#endif // COMMONAPI_DBUS_DBUS_SERVICE_REGISTRY_H_
diff --git a/src/CommonAPI/DBus/DBusServiceStatusEvent.cpp b/src/CommonAPI/DBus/DBusServiceStatusEvent.cpp
index ed0dd8c..99ef03e 100644
--- a/src/CommonAPI/DBus/DBusServiceStatusEvent.cpp
+++ b/src/CommonAPI/DBus/DBusServiceStatusEvent.cpp
@@ -15,32 +15,37 @@ DBusServiceStatusEvent::DBusServiceStatusEvent(std::shared_ptr<DBusServiceRegist
registry_(registry) {
}
-void DBusServiceStatusEvent::onFirstListenerAdded(const std::string& serviceName, const Listener& listener) {
+void DBusServiceStatusEvent::onFirstListenerAdded(const std::string& commonApiServiceName, const Listener& listener) {
+
+}
+
+void DBusServiceStatusEvent::availabilityEvent(const std::string& commonApiServiceName, const AvailabilityStatus& availabilityStatus) {
+ notifyListeners(commonApiServiceName, availabilityStatus);
+}
+
+void DBusServiceStatusEvent::onListenerAdded(const std::string& commonApiServiceName, const Listener& listener) {
if (registry_) {
- registry_->registerAvailabilityListener(serviceName, std::bind(
+ registry_->subscribeAvailabilityListener(commonApiServiceName, std::bind(
&DBusServiceStatusEvent::availabilityEvent,
this,
- serviceName,
+ commonApiServiceName,
std::placeholders::_1));
- }
-}
-
-void DBusServiceStatusEvent::availabilityEvent(const std::string& name, const bool& available) {
- const AvailabilityStatus availabilityStatus = !available ? AvailabilityStatus::NOT_AVAILABLE :
- AvailabilityStatus::AVAILABLE;
- notifyListeners(name, availabilityStatus);
-}
+ std::string dbusInterfaceName;
+ std::string dbusConnectionName;
+ std::string dbusObjectPath;
+ DBusAddressTranslator::getInstance().searchForDBusAddress(
+ commonApiServiceName,
+ dbusInterfaceName,
+ dbusConnectionName,
+ dbusObjectPath);
-void DBusServiceStatusEvent::onListenerAdded(const std::string& name, const Listener& listener) {
- if (registry_) {
const AvailabilityStatus availabilityStatus =
- !registry_->isServiceInstanceAlive(name) ? AvailabilityStatus::NOT_AVAILABLE :
+ !registry_->isServiceInstanceAlive(dbusInterfaceName, dbusConnectionName, dbusObjectPath) ? AvailabilityStatus::NOT_AVAILABLE :
AvailabilityStatus::AVAILABLE;
- notifyListeners(name, availabilityStatus);
+ notifyListeners(commonApiServiceName, availabilityStatus);
}
-
}
} // namespace DBus
diff --git a/src/CommonAPI/DBus/DBusServiceStatusEvent.h b/src/CommonAPI/DBus/DBusServiceStatusEvent.h
index c2914f4..1c47cb2 100644
--- a/src/CommonAPI/DBus/DBusServiceStatusEvent.h
+++ b/src/CommonAPI/DBus/DBusServiceStatusEvent.h
@@ -1,42 +1,42 @@
-/* Copyright (C) 2013 BMW Group
- * Author: Manfred Bathelt (manfred.bathelt@bmw.de)
- * Author: Juergen Gehring (juergen.gehring@bmw.de)
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-#ifndef COMMONAPI_DBUS_DBUS_SERVICE_STATUS_EVENT_H_
-#define COMMONAPI_DBUS_DBUS_SERVICE_STATUS_EVENT_H_
-
-#include "DBusMultiEvent.h"
-
-#include <CommonAPI/Event.h>
-#include <CommonAPI/types.h>
-
-#include <string>
-#include <memory>
-
-namespace CommonAPI {
-namespace DBus {
-
-
-class DBusServiceRegistry;
-
-class DBusServiceStatusEvent: public DBusMultiEvent<AvailabilityStatus> {
- public:
- DBusServiceStatusEvent(std::shared_ptr<DBusServiceRegistry> registry);
-
- protected:
- void onFirstListenerAdded(const std::string& serviceName, const Listener& listener);
- void onListenerAdded(const std::string& serviceName, const Listener& listener);
-
- private:
- void availabilityEvent(const std::string& name, const bool& available);
-
- std::shared_ptr<DBusServiceRegistry> registry_;
-};
-
-} // namespace DBus
-} // namespace CommonAPI
-
-#endif // COMMONAPI_DBUS_DBUS_SERVICE_STATUS_EVENT_H_
-
+/* Copyright (C) 2013 BMW Group
+ * Author: Manfred Bathelt (manfred.bathelt@bmw.de)
+ * Author: Juergen Gehring (juergen.gehring@bmw.de)
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+#ifndef COMMONAPI_DBUS_DBUS_SERVICE_STATUS_EVENT_H_
+#define COMMONAPI_DBUS_DBUS_SERVICE_STATUS_EVENT_H_
+
+#include "DBusMultiEvent.h"
+
+#include <CommonAPI/Event.h>
+#include <CommonAPI/types.h>
+
+#include <string>
+#include <memory>
+
+namespace CommonAPI {
+namespace DBus {
+
+
+class DBusServiceRegistry;
+
+class DBusServiceStatusEvent: public DBusMultiEvent<AvailabilityStatus> {
+ public:
+ DBusServiceStatusEvent(std::shared_ptr<DBusServiceRegistry> registry);
+
+ protected:
+ void onFirstListenerAdded(const std::string& commonApiServiceName, const Listener& listener);
+ void onListenerAdded(const std::string& commonApiServiceName, const Listener& listener);
+
+ private:
+ void availabilityEvent(const std::string& commonApiServiceName, const AvailabilityStatus& availabilityStatus);
+
+ std::shared_ptr<DBusServiceRegistry> registry_;
+};
+
+} // namespace DBus
+} // namespace CommonAPI
+
+#endif // COMMONAPI_DBUS_DBUS_SERVICE_STATUS_EVENT_H_
+
diff --git a/src/CommonAPI/DBus/DBusStubAdapter.cpp b/src/CommonAPI/DBus/DBusStubAdapter.cpp
index 0a13d1c..e230062 100644
--- a/src/CommonAPI/DBus/DBusStubAdapter.cpp
+++ b/src/CommonAPI/DBus/DBusStubAdapter.cpp
@@ -5,6 +5,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "DBusStubAdapter.h"
+#include "DBusUtils.h"
#include <dbus/dbus-protocol.h>
@@ -17,30 +18,40 @@ namespace DBus {
const std::string DBusStubAdapter::domain_ = "local";
-DBusStubAdapter::DBusStubAdapter(const std::string& dbusBusName,
+DBusStubAdapter::DBusStubAdapter(const std::string& commonApiAddress,
+ const std::string& dbusInterfaceName,
+ const std::string& dbusBusName,
const std::string& dbusObjectPath,
- const std::string& interfaceName,
const std::shared_ptr<DBusProxyConnection>& dbusConnection) :
+ commonApiDomain_(split(commonApiAddress, ':')[0]),
+ commonApiServiceId_(split(commonApiAddress, ':')[1]),
+ commonApiParticipantId_(split(commonApiAddress, ':')[2]),
+ dbusInterfaceName_(dbusInterfaceName),
dbusBusName_(dbusBusName),
dbusObjectPath_(dbusObjectPath),
- interfaceName_(interfaceName),
dbusConnection_(dbusConnection),
isInitialized_(false) {
assert(!dbusBusName_.empty());
- assert(!interfaceName_.empty());
+ assert(!dbusInterfaceName_.empty());
assert(!dbusObjectPath_.empty());
assert(dbusObjectPath_[0] == '/');
- assert(!interfaceName.empty());
+ assert(!dbusInterfaceName_.empty());
assert(dbusConnection_);
}
DBusStubAdapter::~DBusStubAdapter() {
+ deinit();
+}
+
+void DBusStubAdapter::deinit() {
assert(dbusConnection_);
- assert(isInitialized_);
- dbusConnection_->getDBusObjectManager()->unregisterInterfaceHandler(dbusIntrospectionInterfaceHandlerToken_);
- dbusConnection_->getDBusObjectManager()->unregisterInterfaceHandler(dbusInterfaceHandlerToken_);
+ if(isInitialized_) {
+ dbusConnection_->getDBusObjectManager()->unregisterInterfaceHandler(dbusIntrospectionInterfaceHandlerToken_);
+ dbusConnection_->getDBusObjectManager()->unregisterInterfaceHandler(dbusInterfaceHandlerToken_);
+ isInitialized_ = false;
+ }
}
void DBusStubAdapter::init() {
@@ -51,26 +62,26 @@ void DBusStubAdapter::init() {
dbusInterfaceHandlerToken_ = dbusConnection_->getDBusObjectManager()->registerInterfaceHandler(
dbusObjectPath_,
- interfaceName_,
+ dbusInterfaceName_,
std::bind(&DBusStubAdapter::onInterfaceDBusMessage, this, std::placeholders::_1));
isInitialized_ = true;
}
const std::string DBusStubAdapter::getAddress() const {
- return domain_ + ":" + interfaceName_ + ":" + dbusBusName_;
+ return commonApiDomain_ + ":" + commonApiServiceId_ + ":" + commonApiParticipantId_;
}
const std::string& DBusStubAdapter::getDomain() const {
- return domain_;
+ return commonApiDomain_;
}
const std::string& DBusStubAdapter::getServiceId() const {
- return interfaceName_;
+ return commonApiServiceId_;
}
const std::string& DBusStubAdapter::getInstanceId() const {
- return dbusObjectPath_;
+ return commonApiParticipantId_;
}
bool DBusStubAdapter::onIntrospectionInterfaceDBusMessage(const DBusMessage& dbusMessage) {
@@ -86,7 +97,7 @@ bool DBusStubAdapter::onIntrospectionInterfaceDBusMessage(const DBusMessage& dbu
"<arg type=\"s\" name=\"xml_data\" direction=\"out\"/>\n"
"</method>\n"
"</interface>\n"
- "<interface name=\"" << interfaceName_ << "\">\n"
+ "<interface name=\"" << dbusInterfaceName_ << "\">\n"
<< getMethodsDBusIntrospectionXmlData() << "\n"
"</interface>\n"
"</node>";
diff --git a/src/CommonAPI/DBus/DBusStubAdapter.h b/src/CommonAPI/DBus/DBusStubAdapter.h
index 9521221..fafea2e 100644
--- a/src/CommonAPI/DBus/DBusStubAdapter.h
+++ b/src/CommonAPI/DBus/DBusStubAdapter.h
@@ -20,14 +20,16 @@ namespace DBus {
class DBusStubAdapter: virtual public CommonAPI::StubAdapter {
public:
- DBusStubAdapter(const std::string& dbusBusName,
+ DBusStubAdapter(const std::string& commonApiAddress,
+ const std::string& dbusInterfaceName,
+ const std::string& dbusBusName,
const std::string& dbusObjectPath,
- const std::string& interfaceName,
const std::shared_ptr<DBusProxyConnection>& dbusConnection);
virtual ~DBusStubAdapter();
virtual void init();
+ virtual void deinit();
virtual const std::string getAddress() const;
virtual const std::string& getDomain() const;
@@ -35,6 +37,7 @@ class DBusStubAdapter: virtual public CommonAPI::StubAdapter {
virtual const std::string& getInstanceId() const;
inline const std::string& getObjectPath() const;
+ inline const std::string& getInterfaceName() const;
inline const std::shared_ptr<DBusProxyConnection>& getDBusConnection() const;
@@ -45,9 +48,13 @@ class DBusStubAdapter: virtual public CommonAPI::StubAdapter {
private:
bool onIntrospectionInterfaceDBusMessage(const DBusMessage& dbusMessage);
+ const std::string commonApiDomain_;
+ const std::string commonApiServiceId_;
+ const std::string commonApiParticipantId_;
+
const std::string dbusBusName_;
const std::string dbusObjectPath_;
- const std::string interfaceName_;
+ const std::string dbusInterfaceName_;
const std::shared_ptr<DBusProxyConnection> dbusConnection_;
bool isInitialized_;
@@ -62,6 +69,10 @@ const std::string& DBusStubAdapter::getObjectPath() const {
return dbusObjectPath_;
}
+const std::string& DBusStubAdapter::getInterfaceName() const {
+ return dbusInterfaceName_;
+}
+
const std::shared_ptr<DBusProxyConnection>& DBusStubAdapter::getDBusConnection() const {
return dbusConnection_;
}
diff --git a/src/CommonAPI/DBus/DBusStubAdapterHelper.h b/src/CommonAPI/DBus/DBusStubAdapterHelper.h
index 7c12a29..4417c74 100644
--- a/src/CommonAPI/DBus/DBusStubAdapterHelper.h
+++ b/src/CommonAPI/DBus/DBusStubAdapterHelper.h
@@ -29,32 +29,37 @@ class DBusStubAdapterHelper: public DBusStubAdapter, public std::enable_shared_f
class StubDispatcher {
public:
virtual ~StubDispatcher() { }
- virtual bool dispatchDBusMessage(const DBusMessage& dbusMessage, DBusStubAdapterHelper<_StubClass>& dbusStubAdapterHelper) = 0;
+ virtual bool dispatchDBusMessage(const DBusMessage& dbusMessage, const std::shared_ptr<_StubClass>& stub, DBusStubAdapterHelper<_StubClass>& dbusStubAdapterHelper) = 0;
};
public:
- DBusStubAdapterHelper(const std::string& dbusBusName,
+ DBusStubAdapterHelper(const std::string& commonApiAddress,
+ const std::string& dbusInterfaceName,
+ const std::string& dbusBusName,
const std::string& dbusObjectPath,
- const std::string& interfaceName,
const std::shared_ptr<DBusProxyConnection>& dbusConnection,
- std::shared_ptr<_StubClass> stub):
- DBusStubAdapter(dbusBusName, dbusObjectPath, interfaceName, dbusConnection),
+ const std::shared_ptr<_StubClass>& stub):
+ DBusStubAdapter(commonApiAddress, dbusInterfaceName, dbusBusName, dbusObjectPath, dbusConnection),
stub_(stub) {
}
- virtual ~DBusStubAdapterHelper() { }
+ virtual ~DBusStubAdapterHelper() {
+ DBusStubAdapter::deinit();
+ stub_.reset();
+ }
virtual void init() {
DBusStubAdapter::init();
remoteEventHandler_ = stub_->initStubAdapter(getStubAdapter());
}
- inline std::shared_ptr<StubAdapterType> getStubAdapter() {
- return this->shared_from_this();
+ virtual void deinit() {
+ DBusStubAdapter::deinit();
+ stub_.reset();
}
- inline const std::shared_ptr<_StubClass>& getStub() {
- return stub_;
+ inline std::shared_ptr<StubAdapterType> getStubAdapter() {
+ return this->shared_from_this();
}
inline RemoteEventHandlerType* getRemoteEventHandler() {
@@ -78,9 +83,11 @@ class DBusStubAdapterHelper: public DBusStubAdapter, public std::enable_shared_f
const bool foundInterfaceMemberHandler = (findIterator != this->stubDispatcherTable_.end());
bool dbusMessageHandled = false;
- if (foundInterfaceMemberHandler) {
+ //To prevent the destruction of the stub whilst still handling a message
+ auto stubSafety = stub_;
+ if (stubSafety && foundInterfaceMemberHandler) {
StubDispatcher* stubDispatcher = findIterator->second;
- dbusMessageHandled = stubDispatcher->dispatchDBusMessage(dbusMessage, *this);
+ dbusMessageHandled = stubDispatcher->dispatchDBusMessage(dbusMessage, stubSafety, *this);
}
return dbusMessageHandled;
@@ -138,13 +145,14 @@ class DBusMethodStubDispatcher<_StubClass, _In<_InArgs...> >: public DBusStubAda
stubFunctor_(stubFunctor) {
}
- bool dispatchDBusMessage(const DBusMessage& dbusMessage, DBusStubAdapterHelperType& dbusStubAdapterHelper) {
- return handleDBusMessage(dbusMessage, dbusStubAdapterHelper, typename make_sequence<sizeof...(_InArgs)>::type());
+ bool dispatchDBusMessage(const DBusMessage& dbusMessage, const std::shared_ptr<_StubClass>& stub, DBusStubAdapterHelperType& dbusStubAdapterHelper) {
+ return handleDBusMessage(dbusMessage, stub, dbusStubAdapterHelper, typename make_sequence<sizeof...(_InArgs)>::type());
}
private:
template <int... _InArgIndices, int... _OutArgIndices>
inline bool handleDBusMessage(const DBusMessage& dbusMessage,
+ const std::shared_ptr<_StubClass>& stub,
DBusStubAdapterHelperType& dbusStubAdapterHelper,
index_sequence<_InArgIndices...>) const {
std::tuple<_InArgs...> argTuple;
@@ -156,7 +164,7 @@ class DBusMethodStubDispatcher<_StubClass, _In<_InArgs...> >: public DBusStubAda
return false;
}
- (dbusStubAdapterHelper.getStub().get()->*stubFunctor_)(std::move(std::get<_InArgIndices>(argTuple))...);
+ (stub.get()->*stubFunctor_)(std::move(std::get<_InArgIndices>(argTuple))...);
return true;
}
@@ -183,9 +191,10 @@ class DBusMethodWithReplyStubDispatcher<_StubClass, _In<_InArgs...>, _Out<_OutAr
dbusReplySignature_(dbusReplySignature) {
}
- bool dispatchDBusMessage(const DBusMessage& dbusMessage, DBusStubAdapterHelperType& dbusStubAdapterHelper) {
+ bool dispatchDBusMessage(const DBusMessage& dbusMessage, const std::shared_ptr<_StubClass>& stub, DBusStubAdapterHelperType& dbusStubAdapterHelper) {
return handleDBusMessage(
dbusMessage,
+ stub,
dbusStubAdapterHelper,
typename make_sequence_range<sizeof...(_InArgs), 0>::type(),
typename make_sequence_range<sizeof...(_OutArgs), sizeof...(_InArgs)>::type());
@@ -194,6 +203,7 @@ class DBusMethodWithReplyStubDispatcher<_StubClass, _In<_InArgs...>, _Out<_OutAr
private:
template <int... _InArgIndices, int... _OutArgIndices>
inline bool handleDBusMessage(const DBusMessage& dbusMessage,
+ const std::shared_ptr<_StubClass>& stub,
DBusStubAdapterHelperType& dbusStubAdapterHelper,
index_sequence<_InArgIndices...>,
index_sequence<_OutArgIndices...>) const {
@@ -206,7 +216,7 @@ class DBusMethodWithReplyStubDispatcher<_StubClass, _In<_InArgs...>, _Out<_OutAr
return false;
}
- (dbusStubAdapterHelper.getStub().get()->*stubFunctor_)(std::move(std::get<_InArgIndices>(argTuple))..., std::get<_OutArgIndices>(argTuple)...);
+ (stub.get()->*stubFunctor_)(std::move(std::get<_InArgIndices>(argTuple))..., std::get<_OutArgIndices>(argTuple)...);
DBusMessage dbusMessageReply = dbusMessage.createMethodReturn(dbusReplySignature_);
@@ -238,16 +248,16 @@ class DBusGetAttributeStubDispatcher: public DBusStubAdapterHelper<_StubClass>::
dbusSignature_(dbusSignature) {
}
- bool dispatchDBusMessage(const DBusMessage& dbusMessage, DBusStubAdapterHelperType& dbusStubAdapterHelper) {
- return sendAttributeValueReply(dbusMessage, dbusStubAdapterHelper);
+ bool dispatchDBusMessage(const DBusMessage& dbusMessage, const std::shared_ptr<_StubClass>& stub, DBusStubAdapterHelperType& dbusStubAdapterHelper) {
+ return sendAttributeValueReply(dbusMessage, stub, dbusStubAdapterHelper);
}
protected:
- inline bool sendAttributeValueReply(const DBusMessage& dbusMessage, DBusStubAdapterHelperType& dbusStubAdapterHelper) {
+ inline bool sendAttributeValueReply(const DBusMessage& dbusMessage, const std::shared_ptr<_StubClass>& stub, DBusStubAdapterHelperType& dbusStubAdapterHelper) {
DBusMessage dbusMessageReply = dbusMessage.createMethodReturn(dbusSignature_);
DBusOutputStream dbusOutputStream(dbusMessageReply);
- dbusOutputStream << (dbusStubAdapterHelper.getStub().get()->*getStubFunctor_)();
+ dbusOutputStream << (stub.get()->*getStubFunctor_)();
dbusOutputStream.flush();
return dbusStubAdapterHelper.getDBusConnection()->sendDBusMessage(dbusMessageReply);
@@ -277,10 +287,10 @@ class DBusSetAttributeStubDispatcher: public DBusGetAttributeStubDispatcher<_Stu
onRemoteChangedFunctor_(onRemoteChangedFunctor) {
}
- bool dispatchDBusMessage(const DBusMessage& dbusMessage, DBusStubAdapterHelperType& dbusStubAdapterHelper) {
+ bool dispatchDBusMessage(const DBusMessage& dbusMessage, const std::shared_ptr<_StubClass>& stub, DBusStubAdapterHelperType& dbusStubAdapterHelper) {
bool attributeValueChanged;
- if (!setAttributeValue(dbusMessage, dbusStubAdapterHelper, attributeValueChanged))
+ if (!setAttributeValue(dbusMessage, stub, dbusStubAdapterHelper, attributeValueChanged))
return false;
if (attributeValueChanged)
@@ -290,7 +300,10 @@ class DBusSetAttributeStubDispatcher: public DBusGetAttributeStubDispatcher<_Stu
}
protected:
- inline bool setAttributeValue(const DBusMessage& dbusMessage, DBusStubAdapterHelperType& dbusStubAdapterHelper, bool& attributeValueChanged) {
+ inline bool setAttributeValue(const DBusMessage& dbusMessage,
+ const std::shared_ptr<_StubClass>& stub,
+ DBusStubAdapterHelperType& dbusStubAdapterHelper,
+ bool& attributeValueChanged) {
DBusInputStream dbusInputStream(dbusMessage);
_AttributeType attributeValue;
dbusInputStream >> attributeValue;
@@ -299,15 +312,15 @@ class DBusSetAttributeStubDispatcher: public DBusGetAttributeStubDispatcher<_Stu
attributeValueChanged = (dbusStubAdapterHelper.getRemoteEventHandler()->*onRemoteSetFunctor_)(std::move(attributeValue));
- return this->sendAttributeValueReply(dbusMessage, dbusStubAdapterHelper);
+ return this->sendAttributeValueReply(dbusMessage, stub, dbusStubAdapterHelper);
}
inline void notifyOnRemoteChanged(DBusStubAdapterHelperType& dbusStubAdapterHelper) {
(dbusStubAdapterHelper.getRemoteEventHandler()->*onRemoteChangedFunctor_)();
}
- inline const _AttributeType& getAttributeValue(DBusStubAdapterHelperType& dbusStubAdapterHelper) {
- return (dbusStubAdapterHelper.getStub().get()->*(this->getStubFunctor_))();
+ inline const _AttributeType& getAttributeValue(const std::shared_ptr<_StubClass>& stub) {
+ return (stub.get()->*(this->getStubFunctor_))();
}
const OnRemoteSetFunctor onRemoteSetFunctor_;
@@ -338,21 +351,21 @@ class DBusSetObservableAttributeStubDispatcher: public DBusSetAttributeStubDispa
fireChangedFunctor_(fireChangedFunctor) {
}
- bool dispatchDBusMessage(const DBusMessage& dbusMessage, DBusStubAdapterHelperType& dbusStubAdapterHelper) {
+ bool dispatchDBusMessage(const DBusMessage& dbusMessage, const std::shared_ptr<_StubClass>& stub, DBusStubAdapterHelperType& dbusStubAdapterHelper) {
bool attributeValueChanged;
- if (!this->setAttributeValue(dbusMessage, dbusStubAdapterHelper, attributeValueChanged))
+ if (!this->setAttributeValue(dbusMessage, stub, dbusStubAdapterHelper, attributeValueChanged))
return false;
if (attributeValueChanged) {
- fireAttributeValueChanged(dbusStubAdapterHelper);
+ fireAttributeValueChanged(dbusStubAdapterHelper, stub);
this->notifyOnRemoteChanged(dbusStubAdapterHelper);
}
return true;
}
private:
- inline void fireAttributeValueChanged(DBusStubAdapterHelperType& dbusStubAdapterHelper) {
- (dbusStubAdapterHelper.getStubAdapter().get()->*fireChangedFunctor_)(this->getAttributeValue(dbusStubAdapterHelper));
+ inline void fireAttributeValueChanged(DBusStubAdapterHelperType& dbusStubAdapterHelper, const std::shared_ptr<_StubClass> stub) {
+ (dbusStubAdapterHelper.getStubAdapter().get()->*fireChangedFunctor_)(this->getAttributeValue(stub));
}
const FireChangedFunctor fireChangedFunctor_;
diff --git a/src/CommonAPI/DBus/DBusUtils.h b/src/CommonAPI/DBus/DBusUtils.h
index c303500..4c4c078 100644
--- a/src/CommonAPI/DBus/DBusUtils.h
+++ b/src/CommonAPI/DBus/DBusUtils.h
@@ -11,6 +11,8 @@
#include <string>
#include <sstream>
#include <vector>
+#include <unistd.h>
+#include <future>
namespace CommonAPI {
namespace DBus {
@@ -29,23 +31,21 @@ inline std::vector<std::string> split(const std::string& s, char delim) {
return split(s, delim, elems);
}
-inline void findFallbackInstanceIdMapping(const std::string& instanceId,
- std::string& connectionName,
- std::string& objectPath) {
- connectionName = instanceId;
- objectPath = '/' + instanceId;
- std::replace(objectPath.begin(), objectPath.end(), '.', '/');
-}
-inline std::string findCommonAPIAddressForDBusAddress(const std::string& conName,
- const std::string& objName,
- const std::string& intName) {
+inline std::string getCurrentBinaryFileFQN() {
+ char fqnOfBinary[FILENAME_MAX];
+ char pathToProcessImage[FILENAME_MAX];
- return "local:" + intName + ":" + conName;
-}
+ sprintf(pathToProcessImage, "/proc/%d/exe", getpid());
+ const ssize_t lengthOfFqn = readlink(pathToProcessImage, fqnOfBinary, sizeof(fqnOfBinary) - 1);
-inline std::string findFallbackInstanceIdMapping(const std::string& connectionName, const std::string& objectPath) {
- return connectionName;
+ if (lengthOfFqn != -1) {
+ fqnOfBinary[lengthOfFqn] = '\0';
+ return std::string(std::move(fqnOfBinary));
+ } else {
+ //TODO fail of readlink, i.e. it returns -1, sets errno. See http://linux.die.net/man/3/readlink
+ return std::string("");
+ }
}
template<typename _FutureWaitType>
diff --git a/src/murmurhash/MurmurHash3.cpp b/src/murmurhash/MurmurHash3.cpp
index c2d2fb7..3ee5885 100644
--- a/src/murmurhash/MurmurHash3.cpp
+++ b/src/murmurhash/MurmurHash3.cpp
@@ -1,335 +1,335 @@
-//-----------------------------------------------------------------------------
-// MurmurHash3 was written by Austin Appleby, and is placed in the public
-// domain. The author hereby disclaims copyright to this source code.
-
-// Note - The x86 and x64 versions do _not_ produce the same results, as the
-// algorithms are optimized for their respective platforms. You can still
-// compile and run any of them on any platform, but your performance with the
-// non-native version will be less than optimal.
-
-#include "MurmurHash3.h"
-
-//-----------------------------------------------------------------------------
-// Platform-specific functions and macros
-
-// Microsoft Visual Studio
-
-#if defined(_MSC_VER)
-
-#define FORCE_INLINE __forceinline
-
-#include <stdlib.h>
-
-#define ROTL32(x,y) _rotl(x,y)
-#define ROTL64(x,y) _rotl64(x,y)
-
-#define BIG_CONSTANT(x) (x)
-
-// Other compilers
-
-#else // defined(_MSC_VER)
-
-#define FORCE_INLINE __attribute__((always_inline))
-
-inline uint32_t rotl32 ( uint32_t x, int8_t r )
-{
- return (x << r) | (x >> (32 - r));
-}
-
-inline uint64_t rotl64 ( uint64_t x, int8_t r )
-{
- return (x << r) | (x >> (64 - r));
-}
-
-#define ROTL32(x,y) rotl32(x,y)
-#define ROTL64(x,y) rotl64(x,y)
-
-#define BIG_CONSTANT(x) (x##LLU)
-
-#endif // !defined(_MSC_VER)
-
-//-----------------------------------------------------------------------------
-// Block read - if your platform needs to do endian-swapping or can only
-// handle aligned reads, do the conversion here
-
-inline uint32_t getblock ( const uint32_t * p, int i )
-{
- return p[i];
-}
-
-inline uint64_t getblock ( const uint64_t * p, int i )
-{
- return p[i];
-}
-
-//-----------------------------------------------------------------------------
-// Finalization mix - force all bits of a hash block to avalanche
-
-inline uint32_t fmix ( uint32_t h )
-{
- h ^= h >> 16;
- h *= 0x85ebca6b;
- h ^= h >> 13;
- h *= 0xc2b2ae35;
- h ^= h >> 16;
-
- return h;
-}
-
-//----------
-
-inline uint64_t fmix ( uint64_t k )
-{
- k ^= k >> 33;
- k *= BIG_CONSTANT(0xff51afd7ed558ccd);
- k ^= k >> 33;
- k *= BIG_CONSTANT(0xc4ceb9fe1a85ec53);
- k ^= k >> 33;
-
- return k;
-}
-
-//-----------------------------------------------------------------------------
-
-void MurmurHash3_x86_32 ( const void * key, int len,
- uint32_t seed, void * out )
-{
- const uint8_t * data = (const uint8_t*)key;
- const int nblocks = len / 4;
-
- uint32_t h1 = seed;
-
- uint32_t c1 = 0xcc9e2d51;
- uint32_t c2 = 0x1b873593;
-
- //----------
- // body
-
- const uint32_t * blocks = (const uint32_t *)(data + nblocks*4);
-
- for(int i = -nblocks; i; i++)
- {
- uint32_t k1 = getblock(blocks,i);
-
- k1 *= c1;
- k1 = ROTL32(k1,15);
- k1 *= c2;
-
- h1 ^= k1;
- h1 = ROTL32(h1,13);
- h1 = h1*5+0xe6546b64;
- }
-
- //----------
- // tail
-
- const uint8_t * tail = (const uint8_t*)(data + nblocks*4);
-
- uint32_t k1 = 0;
-
- switch(len & 3)
- {
- case 3: k1 ^= tail[2] << 16;
- case 2: k1 ^= tail[1] << 8;
- case 1: k1 ^= tail[0];
- k1 *= c1; k1 = ROTL32(k1,15); k1 *= c2; h1 ^= k1;
- };
-
- //----------
- // finalization
-
- h1 ^= len;
-
- h1 = fmix(h1);
-
- *(uint32_t*)out = h1;
-}
-
-//-----------------------------------------------------------------------------
-
-void MurmurHash3_x86_128 ( const void * key, const int len,
- uint32_t seed, void * out )
-{
- const uint8_t * data = (const uint8_t*)key;
- const int nblocks = len / 16;
-
- uint32_t h1 = seed;
- uint32_t h2 = seed;
- uint32_t h3 = seed;
- uint32_t h4 = seed;
-
- uint32_t c1 = 0x239b961b;
- uint32_t c2 = 0xab0e9789;
- uint32_t c3 = 0x38b34ae5;
- uint32_t c4 = 0xa1e38b93;
-
- //----------
- // body
-
- const uint32_t * blocks = (const uint32_t *)(data + nblocks*16);
-
- for(int i = -nblocks; i; i++)
- {
- uint32_t k1 = getblock(blocks,i*4+0);
- uint32_t k2 = getblock(blocks,i*4+1);
- uint32_t k3 = getblock(blocks,i*4+2);
- uint32_t k4 = getblock(blocks,i*4+3);
-
- k1 *= c1; k1 = ROTL32(k1,15); k1 *= c2; h1 ^= k1;
-
- h1 = ROTL32(h1,19); h1 += h2; h1 = h1*5+0x561ccd1b;
-
- k2 *= c2; k2 = ROTL32(k2,16); k2 *= c3; h2 ^= k2;
-
- h2 = ROTL32(h2,17); h2 += h3; h2 = h2*5+0x0bcaa747;
-
- k3 *= c3; k3 = ROTL32(k3,17); k3 *= c4; h3 ^= k3;
-
- h3 = ROTL32(h3,15); h3 += h4; h3 = h3*5+0x96cd1c35;
-
- k4 *= c4; k4 = ROTL32(k4,18); k4 *= c1; h4 ^= k4;
-
- h4 = ROTL32(h4,13); h4 += h1; h4 = h4*5+0x32ac3b17;
- }
-
- //----------
- // tail
-
- const uint8_t * tail = (const uint8_t*)(data + nblocks*16);
-
- uint32_t k1 = 0;
- uint32_t k2 = 0;
- uint32_t k3 = 0;
- uint32_t k4 = 0;
-
- switch(len & 15)
- {
- case 15: k4 ^= tail[14] << 16;
- case 14: k4 ^= tail[13] << 8;
- case 13: k4 ^= tail[12] << 0;
- k4 *= c4; k4 = ROTL32(k4,18); k4 *= c1; h4 ^= k4;
-
- case 12: k3 ^= tail[11] << 24;
- case 11: k3 ^= tail[10] << 16;
- case 10: k3 ^= tail[ 9] << 8;
- case 9: k3 ^= tail[ 8] << 0;
- k3 *= c3; k3 = ROTL32(k3,17); k3 *= c4; h3 ^= k3;
-
- case 8: k2 ^= tail[ 7] << 24;
- case 7: k2 ^= tail[ 6] << 16;
- case 6: k2 ^= tail[ 5] << 8;
- case 5: k2 ^= tail[ 4] << 0;
- k2 *= c2; k2 = ROTL32(k2,16); k2 *= c3; h2 ^= k2;
-
- case 4: k1 ^= tail[ 3] << 24;
- case 3: k1 ^= tail[ 2] << 16;
- case 2: k1 ^= tail[ 1] << 8;
- case 1: k1 ^= tail[ 0] << 0;
- k1 *= c1; k1 = ROTL32(k1,15); k1 *= c2; h1 ^= k1;
- };
-
- //----------
- // finalization
-
- h1 ^= len; h2 ^= len; h3 ^= len; h4 ^= len;
-
- h1 += h2; h1 += h3; h1 += h4;
- h2 += h1; h3 += h1; h4 += h1;
-
- h1 = fmix(h1);
- h2 = fmix(h2);
- h3 = fmix(h3);
- h4 = fmix(h4);
-
- h1 += h2; h1 += h3; h1 += h4;
- h2 += h1; h3 += h1; h4 += h1;
-
- ((uint32_t*)out)[0] = h1;
- ((uint32_t*)out)[1] = h2;
- ((uint32_t*)out)[2] = h3;
- ((uint32_t*)out)[3] = h4;
-}
-
-//-----------------------------------------------------------------------------
-
-void MurmurHash3_x64_128 ( const void * key, const int len,
- const uint32_t seed, void * out )
-{
- const uint8_t * data = (const uint8_t*)key;
- const int nblocks = len / 16;
-
- uint64_t h1 = seed;
- uint64_t h2 = seed;
-
- uint64_t c1 = BIG_CONSTANT(0x87c37b91114253d5);
- uint64_t c2 = BIG_CONSTANT(0x4cf5ad432745937f);
-
- //----------
- // body
-
- const uint64_t * blocks = (const uint64_t *)(data);
-
- for(int i = 0; i < nblocks; i++)
- {
- uint64_t k1 = getblock(blocks,i*2+0);
- uint64_t k2 = getblock(blocks,i*2+1);
-
- k1 *= c1; k1 = ROTL64(k1,31); k1 *= c2; h1 ^= k1;
-
- h1 = ROTL64(h1,27); h1 += h2; h1 = h1*5+0x52dce729;
-
- k2 *= c2; k2 = ROTL64(k2,33); k2 *= c1; h2 ^= k2;
-
- h2 = ROTL64(h2,31); h2 += h1; h2 = h2*5+0x38495ab5;
- }
-
- //----------
- // tail
-
- const uint8_t * tail = (const uint8_t*)(data + nblocks*16);
-
- uint64_t k1 = 0;
- uint64_t k2 = 0;
-
- switch(len & 15)
- {
- case 15: k2 ^= uint64_t(tail[14]) << 48;
- case 14: k2 ^= uint64_t(tail[13]) << 40;
- case 13: k2 ^= uint64_t(tail[12]) << 32;
- case 12: k2 ^= uint64_t(tail[11]) << 24;
- case 11: k2 ^= uint64_t(tail[10]) << 16;
- case 10: k2 ^= uint64_t(tail[ 9]) << 8;
- case 9: k2 ^= uint64_t(tail[ 8]) << 0;
- k2 *= c2; k2 = ROTL64(k2,33); k2 *= c1; h2 ^= k2;
-
- case 8: k1 ^= uint64_t(tail[ 7]) << 56;
- case 7: k1 ^= uint64_t(tail[ 6]) << 48;
- case 6: k1 ^= uint64_t(tail[ 5]) << 40;
- case 5: k1 ^= uint64_t(tail[ 4]) << 32;
- case 4: k1 ^= uint64_t(tail[ 3]) << 24;
- case 3: k1 ^= uint64_t(tail[ 2]) << 16;
- case 2: k1 ^= uint64_t(tail[ 1]) << 8;
- case 1: k1 ^= uint64_t(tail[ 0]) << 0;
- k1 *= c1; k1 = ROTL64(k1,31); k1 *= c2; h1 ^= k1;
- };
-
- //----------
- // finalization
-
- h1 ^= len; h2 ^= len;
-
- h1 += h2;
- h2 += h1;
-
- h1 = fmix(h1);
- h2 = fmix(h2);
-
- h1 += h2;
- h2 += h1;
-
- ((uint64_t*)out)[0] = h1;
- ((uint64_t*)out)[1] = h2;
-}
-
-//-----------------------------------------------------------------------------
-
+//-----------------------------------------------------------------------------
+// MurmurHash3 was written by Austin Appleby, and is placed in the public
+// domain. The author hereby disclaims copyright to this source code.
+
+// Note - The x86 and x64 versions do _not_ produce the same results, as the
+// algorithms are optimized for their respective platforms. You can still
+// compile and run any of them on any platform, but your performance with the
+// non-native version will be less than optimal.
+
+#include "MurmurHash3.h"
+
+//-----------------------------------------------------------------------------
+// Platform-specific functions and macros
+
+// Microsoft Visual Studio
+
+#if defined(_MSC_VER)
+
+#define FORCE_INLINE __forceinline
+
+#include <stdlib.h>
+
+#define ROTL32(x,y) _rotl(x,y)
+#define ROTL64(x,y) _rotl64(x,y)
+
+#define BIG_CONSTANT(x) (x)
+
+// Other compilers
+
+#else // defined(_MSC_VER)
+
+#define FORCE_INLINE __attribute__((always_inline))
+
+inline uint32_t rotl32 ( uint32_t x, int8_t r )
+{
+ return (x << r) | (x >> (32 - r));
+}
+
+inline uint64_t rotl64 ( uint64_t x, int8_t r )
+{
+ return (x << r) | (x >> (64 - r));
+}
+
+#define ROTL32(x,y) rotl32(x,y)
+#define ROTL64(x,y) rotl64(x,y)
+
+#define BIG_CONSTANT(x) (x##LLU)
+
+#endif // !defined(_MSC_VER)
+
+//-----------------------------------------------------------------------------
+// Block read - if your platform needs to do endian-swapping or can only
+// handle aligned reads, do the conversion here
+
+inline uint32_t getblock ( const uint32_t * p, int i )
+{
+ return p[i];
+}
+
+inline uint64_t getblock ( const uint64_t * p, int i )
+{
+ return p[i];
+}
+
+//-----------------------------------------------------------------------------
+// Finalization mix - force all bits of a hash block to avalanche
+
+inline uint32_t fmix ( uint32_t h )
+{
+ h ^= h >> 16;
+ h *= 0x85ebca6b;
+ h ^= h >> 13;
+ h *= 0xc2b2ae35;
+ h ^= h >> 16;
+
+ return h;
+}
+
+//----------
+
+inline uint64_t fmix ( uint64_t k )
+{
+ k ^= k >> 33;
+ k *= BIG_CONSTANT(0xff51afd7ed558ccd);
+ k ^= k >> 33;
+ k *= BIG_CONSTANT(0xc4ceb9fe1a85ec53);
+ k ^= k >> 33;
+
+ return k;
+}
+
+//-----------------------------------------------------------------------------
+
+void MurmurHash3_x86_32 ( const void * key, int len,
+ uint32_t seed, void * out )
+{
+ const uint8_t * data = (const uint8_t*)key;
+ const int nblocks = len / 4;
+
+ uint32_t h1 = seed;
+
+ uint32_t c1 = 0xcc9e2d51;
+ uint32_t c2 = 0x1b873593;
+
+ //----------
+ // body
+
+ const uint32_t * blocks = (const uint32_t *)(data + nblocks*4);
+
+ for(int i = -nblocks; i; i++)
+ {
+ uint32_t k1 = getblock(blocks,i);
+
+ k1 *= c1;
+ k1 = ROTL32(k1,15);
+ k1 *= c2;
+
+ h1 ^= k1;
+ h1 = ROTL32(h1,13);
+ h1 = h1*5+0xe6546b64;
+ }
+
+ //----------
+ // tail
+
+ const uint8_t * tail = (const uint8_t*)(data + nblocks*4);
+
+ uint32_t k1 = 0;
+
+ switch(len & 3)
+ {
+ case 3: k1 ^= tail[2] << 16;
+ case 2: k1 ^= tail[1] << 8;
+ case 1: k1 ^= tail[0];
+ k1 *= c1; k1 = ROTL32(k1,15); k1 *= c2; h1 ^= k1;
+ };
+
+ //----------
+ // finalization
+
+ h1 ^= len;
+
+ h1 = fmix(h1);
+
+ *(uint32_t*)out = h1;
+}
+
+//-----------------------------------------------------------------------------
+
+void MurmurHash3_x86_128 ( const void * key, const int len,
+ uint32_t seed, void * out )
+{
+ const uint8_t * data = (const uint8_t*)key;
+ const int nblocks = len / 16;
+
+ uint32_t h1 = seed;
+ uint32_t h2 = seed;
+ uint32_t h3 = seed;
+ uint32_t h4 = seed;
+
+ uint32_t c1 = 0x239b961b;
+ uint32_t c2 = 0xab0e9789;
+ uint32_t c3 = 0x38b34ae5;
+ uint32_t c4 = 0xa1e38b93;
+
+ //----------
+ // body
+
+ const uint32_t * blocks = (const uint32_t *)(data + nblocks*16);
+
+ for(int i = -nblocks; i; i++)
+ {
+ uint32_t k1 = getblock(blocks,i*4+0);
+ uint32_t k2 = getblock(blocks,i*4+1);
+ uint32_t k3 = getblock(blocks,i*4+2);
+ uint32_t k4 = getblock(blocks,i*4+3);
+
+ k1 *= c1; k1 = ROTL32(k1,15); k1 *= c2; h1 ^= k1;
+
+ h1 = ROTL32(h1,19); h1 += h2; h1 = h1*5+0x561ccd1b;
+
+ k2 *= c2; k2 = ROTL32(k2,16); k2 *= c3; h2 ^= k2;
+
+ h2 = ROTL32(h2,17); h2 += h3; h2 = h2*5+0x0bcaa747;
+
+ k3 *= c3; k3 = ROTL32(k3,17); k3 *= c4; h3 ^= k3;
+
+ h3 = ROTL32(h3,15); h3 += h4; h3 = h3*5+0x96cd1c35;
+
+ k4 *= c4; k4 = ROTL32(k4,18); k4 *= c1; h4 ^= k4;
+
+ h4 = ROTL32(h4,13); h4 += h1; h4 = h4*5+0x32ac3b17;
+ }
+
+ //----------
+ // tail
+
+ const uint8_t * tail = (const uint8_t*)(data + nblocks*16);
+
+ uint32_t k1 = 0;
+ uint32_t k2 = 0;
+ uint32_t k3 = 0;
+ uint32_t k4 = 0;
+
+ switch(len & 15)
+ {
+ case 15: k4 ^= tail[14] << 16;
+ case 14: k4 ^= tail[13] << 8;
+ case 13: k4 ^= tail[12] << 0;
+ k4 *= c4; k4 = ROTL32(k4,18); k4 *= c1; h4 ^= k4;
+
+ case 12: k3 ^= tail[11] << 24;
+ case 11: k3 ^= tail[10] << 16;
+ case 10: k3 ^= tail[ 9] << 8;
+ case 9: k3 ^= tail[ 8] << 0;
+ k3 *= c3; k3 = ROTL32(k3,17); k3 *= c4; h3 ^= k3;
+
+ case 8: k2 ^= tail[ 7] << 24;
+ case 7: k2 ^= tail[ 6] << 16;
+ case 6: k2 ^= tail[ 5] << 8;
+ case 5: k2 ^= tail[ 4] << 0;
+ k2 *= c2; k2 = ROTL32(k2,16); k2 *= c3; h2 ^= k2;
+
+ case 4: k1 ^= tail[ 3] << 24;
+ case 3: k1 ^= tail[ 2] << 16;
+ case 2: k1 ^= tail[ 1] << 8;
+ case 1: k1 ^= tail[ 0] << 0;
+ k1 *= c1; k1 = ROTL32(k1,15); k1 *= c2; h1 ^= k1;
+ };
+
+ //----------
+ // finalization
+
+ h1 ^= len; h2 ^= len; h3 ^= len; h4 ^= len;
+
+ h1 += h2; h1 += h3; h1 += h4;
+ h2 += h1; h3 += h1; h4 += h1;
+
+ h1 = fmix(h1);
+ h2 = fmix(h2);
+ h3 = fmix(h3);
+ h4 = fmix(h4);
+
+ h1 += h2; h1 += h3; h1 += h4;
+ h2 += h1; h3 += h1; h4 += h1;
+
+ ((uint32_t*)out)[0] = h1;
+ ((uint32_t*)out)[1] = h2;
+ ((uint32_t*)out)[2] = h3;
+ ((uint32_t*)out)[3] = h4;
+}
+
+//-----------------------------------------------------------------------------
+
+void MurmurHash3_x64_128 ( const void * key, const int len,
+ const uint32_t seed, void * out )
+{
+ const uint8_t * data = (const uint8_t*)key;
+ const int nblocks = len / 16;
+
+ uint64_t h1 = seed;
+ uint64_t h2 = seed;
+
+ uint64_t c1 = BIG_CONSTANT(0x87c37b91114253d5);
+ uint64_t c2 = BIG_CONSTANT(0x4cf5ad432745937f);
+
+ //----------
+ // body
+
+ const uint64_t * blocks = (const uint64_t *)(data);
+
+ for(int i = 0; i < nblocks; i++)
+ {
+ uint64_t k1 = getblock(blocks,i*2+0);
+ uint64_t k2 = getblock(blocks,i*2+1);
+
+ k1 *= c1; k1 = ROTL64(k1,31); k1 *= c2; h1 ^= k1;
+
+ h1 = ROTL64(h1,27); h1 += h2; h1 = h1*5+0x52dce729;
+
+ k2 *= c2; k2 = ROTL64(k2,33); k2 *= c1; h2 ^= k2;
+
+ h2 = ROTL64(h2,31); h2 += h1; h2 = h2*5+0x38495ab5;
+ }
+
+ //----------
+ // tail
+
+ const uint8_t * tail = (const uint8_t*)(data + nblocks*16);
+
+ uint64_t k1 = 0;
+ uint64_t k2 = 0;
+
+ switch(len & 15)
+ {
+ case 15: k2 ^= uint64_t(tail[14]) << 48;
+ case 14: k2 ^= uint64_t(tail[13]) << 40;
+ case 13: k2 ^= uint64_t(tail[12]) << 32;
+ case 12: k2 ^= uint64_t(tail[11]) << 24;
+ case 11: k2 ^= uint64_t(tail[10]) << 16;
+ case 10: k2 ^= uint64_t(tail[ 9]) << 8;
+ case 9: k2 ^= uint64_t(tail[ 8]) << 0;
+ k2 *= c2; k2 = ROTL64(k2,33); k2 *= c1; h2 ^= k2;
+
+ case 8: k1 ^= uint64_t(tail[ 7]) << 56;
+ case 7: k1 ^= uint64_t(tail[ 6]) << 48;
+ case 6: k1 ^= uint64_t(tail[ 5]) << 40;
+ case 5: k1 ^= uint64_t(tail[ 4]) << 32;
+ case 4: k1 ^= uint64_t(tail[ 3]) << 24;
+ case 3: k1 ^= uint64_t(tail[ 2]) << 16;
+ case 2: k1 ^= uint64_t(tail[ 1]) << 8;
+ case 1: k1 ^= uint64_t(tail[ 0]) << 0;
+ k1 *= c1; k1 = ROTL64(k1,31); k1 *= c2; h1 ^= k1;
+ };
+
+ //----------
+ // finalization
+
+ h1 ^= len; h2 ^= len;
+
+ h1 += h2;
+ h2 += h1;
+
+ h1 = fmix(h1);
+ h2 = fmix(h2);
+
+ h1 += h2;
+ h2 += h1;
+
+ ((uint64_t*)out)[0] = h1;
+ ((uint64_t*)out)[1] = h2;
+}
+
+//-----------------------------------------------------------------------------
+
diff --git a/src/murmurhash/MurmurHash3.h b/src/murmurhash/MurmurHash3.h
index 58e9820..54e9d3f 100644
--- a/src/murmurhash/MurmurHash3.h
+++ b/src/murmurhash/MurmurHash3.h
@@ -1,37 +1,37 @@
-//-----------------------------------------------------------------------------
-// MurmurHash3 was written by Austin Appleby, and is placed in the public
-// domain. The author hereby disclaims copyright to this source code.
-
-#ifndef _MURMURHASH3_H_
-#define _MURMURHASH3_H_
-
-//-----------------------------------------------------------------------------
-// Platform-specific functions and macros
-
-// Microsoft Visual Studio
-
-#if defined(_MSC_VER)
-
-typedef unsigned char uint8_t;
-typedef unsigned long uint32_t;
-typedef unsigned __int64 uint64_t;
-
-// Other compilers
-
-#else // defined(_MSC_VER)
-
-#include <stdint.h>
-
-#endif // !defined(_MSC_VER)
-
-//-----------------------------------------------------------------------------
-
-void MurmurHash3_x86_32 ( const void * key, int len, uint32_t seed, void * out );
-
-void MurmurHash3_x86_128 ( const void * key, int len, uint32_t seed, void * out );
-
-void MurmurHash3_x64_128 ( const void * key, int len, uint32_t seed, void * out );
-
-//-----------------------------------------------------------------------------
-
-#endif // _MURMURHASH3_H_
+//-----------------------------------------------------------------------------
+// MurmurHash3 was written by Austin Appleby, and is placed in the public
+// domain. The author hereby disclaims copyright to this source code.
+
+#ifndef _MURMURHASH3_H_
+#define _MURMURHASH3_H_
+
+//-----------------------------------------------------------------------------
+// Platform-specific functions and macros
+
+// Microsoft Visual Studio
+
+#if defined(_MSC_VER)
+
+typedef unsigned char uint8_t;
+typedef unsigned long uint32_t;
+typedef unsigned __int64 uint64_t;
+
+// Other compilers
+
+#else // defined(_MSC_VER)
+
+#include <stdint.h>
+
+#endif // !defined(_MSC_VER)
+
+//-----------------------------------------------------------------------------
+
+void MurmurHash3_x86_32 ( const void * key, int len, uint32_t seed, void * out );
+
+void MurmurHash3_x86_128 ( const void * key, int len, uint32_t seed, void * out );
+
+void MurmurHash3_x64_128 ( const void * key, int len, uint32_t seed, void * out );
+
+//-----------------------------------------------------------------------------
+
+#endif // _MURMURHASH3_H_
diff --git a/src/test/DBusAddressTranslatorTest.cpp b/src/test/DBusAddressTranslatorTest.cpp
new file mode 100644
index 0000000..c9dcca7
--- /dev/null
+++ b/src/test/DBusAddressTranslatorTest.cpp
@@ -0,0 +1,272 @@
+/* Copyright (C) 2013 BMW Group
+ * Author: Manfred Bathelt (manfred.bathelt@bmw.de)
+ * Author: Juergen Gehring (juergen.gehring@bmw.de)
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+
+#include <gtest/gtest.h>
+#include <fstream>
+#include <thread>
+#include <unistd.h>
+
+#include <CommonAPI/DBus/DBusAddressTranslator.h>
+#include <CommonAPI/DBus/DBusUtils.h>
+
+#include <CommonAPI/types.h>
+#include <CommonAPI/AttributeExtension.h>
+#include <CommonAPI/Runtime.h>
+
+#include <CommonAPI/DBus/DBusConnection.h>
+#include <CommonAPI/DBus/DBusProxy.h>
+#include <CommonAPI/DBus/DBusRuntime.h>
+
+#include "commonapi/tests/PredefinedTypeCollection.h"
+#include "commonapi/tests/DerivedTypeCollection.h"
+#include "commonapi/tests/TestInterfaceProxy.h"
+#include "commonapi/tests/TestInterfaceStubDefault.h"
+#include "commonapi/tests/TestInterfaceDBusStubAdapter.h"
+
+#include "fakeLegacyService/fake/legacy/service/LegacyInterfaceProxy.h"
+
+
+static const std::vector<std::string> commonApiAddresses = {
+ "local:no.nothing.service:no.nothing.instance",
+ "local:service:instance",
+ "local:no.interface.service:no.interface.instance",
+ "local:no.connection.service:no.connection.instance",
+ "local:no.object.service:no.object.instance",
+ "local:only.interface.service:only.interface.instance",
+ "local:only.connection.service:only.connection.instance",
+ "local:only.object.service:only.object.instance",
+ "local:fake.legacy.service.LegacyInterface:fake.legacy.service"
+};
+
+static const std::string fileString =
+"[local:no.nothing.service:no.nothing.instance]\n"
+"\n"
+"[local:service:instance]\n"
+"dbus_connection=connection.name\n"
+"dbus_object=/path/to/object\n"
+"dbus_interface=service.name\n"
+"\n"
+"[local:no.interface.service:no.interface.instance]\n"
+"dbus_connection=no.interface.connection\n"
+"dbus_object=/no/interface/path\n"
+"\n"
+"[local:no.connection.service:no.connection.instance]\n"
+"dbus_object=/no/connection/path\n"
+"dbus_interface=no.connection.interface\n"
+"\n"
+"[local:no.object.service:no.object.instance]\n"
+"dbus_connection=no.object.connection\n"
+"dbus_interface=no.object.interface\n"
+"\n"
+"[local:only.interface.service:only.interface.instance]\n"
+"dbus_interface=only.interface.interface\n"
+"\n"
+"[local:only.connection.service:only.connection.instance]\n"
+"dbus_connection=only.connection.connection\n"
+"\n"
+"[local:only.object.service:only.object.instance]\n"
+"dbus_object=/only/object/path\n"
+"\n"
+"[local:fake.legacy.service.LegacyInterface:fake.legacy.service]\n"
+"dbus_connection=fake.legacy.service.connection\n"
+"dbus_object=/some/legacy/path/6259504\n"
+"dbus_interface=fake.legacy.service.LegacyInterface\n"
+"dbus_predefined=true\n";
+
+typedef std::vector<CommonAPI::DBus::DBusServiceAddress>::value_type vt;
+static const std::vector<CommonAPI::DBus::DBusServiceAddress> dbusAddresses = {
+ vt("no.nothing.instance", "/no/nothing/instance", "no.nothing.service"),
+ vt("connection.name", "/path/to/object", "service.name"),
+ vt("no.interface.connection", "/no/interface/path", "no.interface.service"),
+ vt("no.connection.instance", "/no/connection/path", "no.connection.interface"),
+ vt("no.object.connection", "/no/object/instance", "no.object.interface"),
+ vt("only.interface.instance", "/only/interface/instance", "only.interface.interface"),
+ vt("only.connection.connection", "/only/connection/instance", "only.connection.service"),
+ vt("only.object.instance", "/only/object/path", "only.object.service"),
+ vt("fake.legacy.service.connection", "/some/legacy/path/6259504", "fake.legacy.service.LegacyInterface")
+};
+
+
+class Environment: public ::testing::Environment {
+public:
+ virtual ~Environment() {
+ }
+
+ virtual void SetUp() {
+ configFileName_ = CommonAPI::DBus::getCurrentBinaryFileFQN();
+ configFileName_ += CommonAPI::DBus::DBUS_CONFIG_SUFFIX;
+ std::ofstream configFile(configFileName_);
+ ASSERT_TRUE(configFile.is_open());
+ configFile << fileString;
+ configFile.close();
+ }
+
+ virtual void TearDown() {
+ std::remove(configFileName_.c_str());
+ }
+
+ std::string configFileName_;
+};
+
+
+class AddressTranslatorTest: public ::testing::Test {
+protected:
+ void SetUp() {
+ }
+
+ virtual void TearDown() {
+ }
+};
+
+
+TEST_F(AddressTranslatorTest, InstanceCanBeRetrieved) {
+ CommonAPI::DBus::DBusAddressTranslator& translator = CommonAPI::DBus::DBusAddressTranslator::getInstance();
+}
+
+
+TEST_F(AddressTranslatorTest, ParsesDBusAddresses) {
+ CommonAPI::DBus::DBusAddressTranslator& translator = CommonAPI::DBus::DBusAddressTranslator::getInstance();
+
+ for(unsigned int i = 0; i < commonApiAddresses.size(); i++) {
+ std::string interfaceName, connectionName, objectPath;
+ translator.searchForDBusAddress(commonApiAddresses[i], interfaceName, connectionName, objectPath);
+ ASSERT_EQ(std::get<0>(dbusAddresses[i]), connectionName);
+ ASSERT_EQ(std::get<1>(dbusAddresses[i]), objectPath);
+ ASSERT_EQ(std::get<2>(dbusAddresses[i]), interfaceName);
+ }
+}
+
+
+TEST_F(AddressTranslatorTest, ParsesCommonAPIAddresses) {
+ CommonAPI::DBus::DBusAddressTranslator& translator = CommonAPI::DBus::DBusAddressTranslator::getInstance();
+
+ for(unsigned int i = 0; i < commonApiAddresses.size(); i++) {
+ std::string commonApiAddress;
+ translator.searchForCommonAddress(
+ std::get<2>(dbusAddresses[i]),
+ std::get<0>(dbusAddresses[i]),
+ std::get<1>(dbusAddresses[i]),
+ commonApiAddress);
+ ASSERT_EQ(commonApiAddresses[i], commonApiAddress);
+ }
+}
+
+
+TEST_F(AddressTranslatorTest, ServicesUsingPredefinedAddressesCanCommunicate) {
+ std::shared_ptr<CommonAPI::Runtime> runtime;
+ std::shared_ptr<CommonAPI::Factory> proxyFactory;
+ std::shared_ptr<CommonAPI::Factory> stubFactory;
+
+ runtime = CommonAPI::Runtime::load();
+ ASSERT_TRUE((bool)runtime);
+ CommonAPI::DBus::DBusRuntime* dbusRuntime = dynamic_cast<CommonAPI::DBus::DBusRuntime*>(&(*runtime));
+ ASSERT_TRUE(dbusRuntime != NULL);
+
+ proxyFactory = runtime->createFactory();
+ ASSERT_TRUE((bool)proxyFactory);
+ stubFactory = runtime->createFactory();
+ ASSERT_TRUE((bool)stubFactory);
+
+ auto defaultTestProxy = proxyFactory->buildProxy<commonapi::tests::TestInterfaceProxy>(commonApiAddresses[0]);
+ ASSERT_TRUE((bool)defaultTestProxy);
+
+ auto stub = std::make_shared<commonapi::tests::TestInterfaceStubDefault>();
+ bool success = stubFactory->registerService(stub, commonApiAddresses[0]);
+ ASSERT_TRUE(success);
+
+ sleep(1);
+
+ uint32_t v1 = 5;
+ std::string v2 = "Hai :)";
+ CommonAPI::CallStatus stat;
+ defaultTestProxy->testVoidPredefinedTypeMethod(v1, v2, stat);
+
+ ASSERT_EQ(stat, CommonAPI::CallStatus::SUCCESS);
+
+ stubFactory->unregisterService(commonApiAddresses[0]);
+}
+
+
+const std::string addressOfFakeLegacyService = commonApiAddresses[8];
+
+const std::string domainOfFakeLegacyService = "local";
+const std::string serviceIdOfFakeLegacyService = "fake.legacy.service.LegacyInterface";
+const std::string participantIdOfFakeLegacyService = "fake.legacy.service";
+
+TEST_F(AddressTranslatorTest, CreatedProxyHasCorrectCommonApiAddress) {
+ std::shared_ptr<CommonAPI::Runtime> runtime = CommonAPI::Runtime::load();
+ ASSERT_TRUE((bool)runtime);
+ CommonAPI::DBus::DBusRuntime* dbusRuntime = dynamic_cast<CommonAPI::DBus::DBusRuntime*>(&(*runtime));
+ ASSERT_TRUE(dbusRuntime != NULL);
+
+ std::shared_ptr<CommonAPI::Factory> proxyFactory = runtime->createFactory();
+ ASSERT_TRUE((bool)proxyFactory);
+ auto proxyForFakeLegacyService = proxyFactory->buildProxy<fake::legacy::service::LegacyInterfaceProxy>(addressOfFakeLegacyService);
+ ASSERT_TRUE((bool)proxyForFakeLegacyService);
+
+ ASSERT_EQ(addressOfFakeLegacyService, proxyForFakeLegacyService->getAddress());
+ ASSERT_EQ(domainOfFakeLegacyService, proxyForFakeLegacyService->getDomain());
+ ASSERT_EQ(serviceIdOfFakeLegacyService, proxyForFakeLegacyService->getServiceId());
+ ASSERT_EQ(participantIdOfFakeLegacyService, proxyForFakeLegacyService->getInstanceId());
+}
+
+
+void fakeLegacyServiceThread() {
+ int resultCode = system("python ./src/test/fakeLegacyService/fakeLegacyService.py");
+ EXPECT_EQ(0, resultCode);
+}
+
+TEST_F(AddressTranslatorTest, FakeLegacyServiceCanBeAddressed) {
+ std::thread fakeServiceThread = std::thread(fakeLegacyServiceThread);
+ sleep(1);
+
+ std::shared_ptr<CommonAPI::Runtime> runtime = CommonAPI::Runtime::load();
+ ASSERT_TRUE((bool)runtime);
+ CommonAPI::DBus::DBusRuntime* dbusRuntime = dynamic_cast<CommonAPI::DBus::DBusRuntime*>(&(*runtime));
+ ASSERT_TRUE(dbusRuntime != NULL);
+
+ std::shared_ptr<CommonAPI::Factory> proxyFactory = runtime->createFactory();
+ ASSERT_TRUE((bool)proxyFactory);
+ auto proxyForFakeLegacyService = proxyFactory->buildProxy<fake::legacy::service::LegacyInterfaceProxy>(addressOfFakeLegacyService);
+ ASSERT_TRUE((bool)proxyForFakeLegacyService);
+
+ ASSERT_EQ(addressOfFakeLegacyService, proxyForFakeLegacyService->getAddress());
+
+ CommonAPI::CallStatus status;
+
+ const int32_t input = 42;
+ int32_t output1, output2;
+ proxyForFakeLegacyService->TestMethod(input, status, output1, output2);
+ EXPECT_EQ(CommonAPI::CallStatus::SUCCESS, status);
+ if(CommonAPI::CallStatus::SUCCESS == status) {
+ EXPECT_EQ(input -5, output1);
+ EXPECT_EQ(input +5, output2);
+ }
+
+ std::string greeting;
+ int32_t identifier;
+ proxyForFakeLegacyService->OtherTestMethod(status, greeting, identifier);
+ EXPECT_EQ(CommonAPI::CallStatus::SUCCESS, status);
+ if(CommonAPI::CallStatus::SUCCESS == status) {
+ EXPECT_EQ(std::string("Hello"), greeting);
+ EXPECT_EQ(42, identifier);
+ }
+
+ //end the fake legacy service via dbus
+ int resultCode = system("python ./src/test/fakeLegacyService/sendToFakeLegacyService.py finish");
+ EXPECT_EQ(0, resultCode);
+
+ fakeServiceThread.join();
+}
+
+
+int main(int argc, char** argv) {
+ ::testing::InitGoogleTest(&argc, argv);
+ ::testing::AddGlobalTestEnvironment(new Environment());
+ return RUN_ALL_TESTS();
+}
diff --git a/src/test/DBusCommunicationTest.cpp b/src/test/DBusCommunicationTest.cpp
index 0531441..5eeb765 100644
--- a/src/test/DBusCommunicationTest.cpp
+++ b/src/test/DBusCommunicationTest.cpp
@@ -35,6 +35,29 @@
#include "commonapi/tests/TestInterfaceDBusProxy.h"
+namespace myExtensions {
+
+template<typename _AttributeType>
+class AttributeTestExtension: public CommonAPI::AttributeExtension<_AttributeType> {
+ typedef CommonAPI::AttributeExtension<_AttributeType> __baseClass_t;
+
+public:
+ typedef typename _AttributeType::ValueType ValueType;
+ typedef typename _AttributeType::AttributeAsyncCallback AttributeAsyncCallback;
+
+ AttributeTestExtension(_AttributeType& baseAttribute) :
+ CommonAPI::AttributeExtension<_AttributeType>(baseAttribute) {}
+
+ ~AttributeTestExtension() {}
+
+ bool testExtensionMethod() const {
+ return true;
+ }
+};
+
+} // namespace myExtensions
+
+
class DBusCommunicationTest: public ::testing::Test {
protected:
virtual void SetUp() {
@@ -42,65 +65,67 @@ class DBusCommunicationTest: public ::testing::Test {
ASSERT_TRUE((bool)runtime_);
CommonAPI::DBus::DBusRuntime* dbusRuntime = dynamic_cast<CommonAPI::DBus::DBusRuntime*>(&(*runtime_));
ASSERT_TRUE(dbusRuntime != NULL);
+
+ proxyFactory_ = runtime_->createFactory();
+ ASSERT_TRUE((bool)proxyFactory_);
+ stubFactory_ = runtime_->createFactory();
+ ASSERT_TRUE((bool)stubFactory_);
}
virtual void TearDown() {
}
std::shared_ptr<CommonAPI::Runtime> runtime_;
+ std::shared_ptr<CommonAPI::Factory> proxyFactory_;
+ std::shared_ptr<CommonAPI::Factory> stubFactory_;
static const std::string serviceAddress_;
+ static const std::string nonstandardAddress_;
};
const std::string DBusCommunicationTest::serviceAddress_ = "local:commonapi.tests.TestInterface:commonapi.tests.TestInterface";
+const std::string DBusCommunicationTest::nonstandardAddress_ = "local:non.standard.ServiceName:non.standard.participand.ID";
-namespace myExtensions {
-
-template<typename _AttributeType>
-class AttributeTestExtension: public CommonAPI::AttributeExtension<_AttributeType> {
- typedef CommonAPI::AttributeExtension<_AttributeType> __baseClass_t;
-
-public:
- typedef typename _AttributeType::ValueType ValueType;
- typedef typename _AttributeType::AttributeAsyncCallback AttributeAsyncCallback;
-
- AttributeTestExtension(_AttributeType& baseAttribute) :
- CommonAPI::AttributeExtension<_AttributeType>(baseAttribute) {}
+TEST_F(DBusCommunicationTest, RemoteMethodCallSucceeds) {
+ auto defaultTestProxy = proxyFactory_->buildProxy<commonapi::tests::TestInterfaceProxy>(serviceAddress_);
+ ASSERT_TRUE((bool)defaultTestProxy);
- ~AttributeTestExtension() {}
+ auto stub = std::make_shared<commonapi::tests::TestInterfaceStubDefault>();
+ bool success = stubFactory_->registerService(stub, serviceAddress_);
+ ASSERT_TRUE(success);
- bool testExtensionMethod() const {
- return true;
- }
-};
+ sleep(1);
-} // namespace myExtensions
+ uint32_t v1 = 5;
+ std::string v2 = "Ciao ;)";
+ CommonAPI::CallStatus stat;
+ defaultTestProxy->testVoidPredefinedTypeMethod(v1, v2, stat);
-//####################################################################################################################
+ EXPECT_EQ(stat, CommonAPI::CallStatus::SUCCESS);
+ stubFactory_->unregisterService(serviceAddress_);
+}
-TEST_F(DBusCommunicationTest, RemoteMethodCallSucceeds) {
- std::shared_ptr<CommonAPI::Factory> proxyFactory = runtime_->createFactory();
- ASSERT_TRUE((bool)proxyFactory);
- auto defaultTestProxy = proxyFactory->buildProxy<commonapi::tests::TestInterfaceProxy>(serviceAddress_);
+TEST_F(DBusCommunicationTest, RemoteMethodCallWithNonstandardAddressSucceeds) {
+ auto defaultTestProxy = proxyFactory_->buildProxy<commonapi::tests::TestInterfaceProxy>(nonstandardAddress_);
ASSERT_TRUE((bool)defaultTestProxy);
- std::shared_ptr<CommonAPI::Factory> stubFactory = runtime_->createFactory();
- ASSERT_TRUE((bool)stubFactory);
-
auto stub = std::make_shared<commonapi::tests::TestInterfaceStubDefault>();
- bool success = stubFactory->registerService(stub, serviceAddress_);
+ bool success = stubFactory_->registerService(stub, nonstandardAddress_);
ASSERT_TRUE(success);
+ sleep(1);
+
uint32_t v1 = 5;
std::string v2 = "Hai :)";
CommonAPI::CallStatus stat;
defaultTestProxy->testVoidPredefinedTypeMethod(v1, v2, stat);
- ASSERT_EQ(stat, CommonAPI::CallStatus::SUCCESS);
+ EXPECT_EQ(stat, CommonAPI::CallStatus::SUCCESS);
+ stubFactory_->unregisterService(nonstandardAddress_);
}
diff --git a/src/test/DBusDaemonProxyTest.cpp b/src/test/DBusDaemonProxyTest.cpp
index 432bb45..c25098e 100644
--- a/src/test/DBusDaemonProxyTest.cpp
+++ b/src/test/DBusDaemonProxyTest.cpp
@@ -6,6 +6,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include <CommonAPI/DBus/DBusConnection.h>
#include <CommonAPI/DBus/DBusDaemonProxy.h>
+#include <CommonAPI/DBus/DBusUtils.h>
#include <gtest/gtest.h>
@@ -14,44 +15,29 @@
namespace {
-void dispatch(std::shared_ptr<CommonAPI::DBus::DBusConnection> dbusConnection) {
- while (dbusConnection->readWriteDispatch(10)) {}
-}
-
class DBusDaemonProxyTest: public ::testing::Test {
protected:
- std::thread* thread;
-
virtual void SetUp() {
dbusConnection_ = CommonAPI::DBus::DBusConnection::getSessionBus();
ASSERT_TRUE(dbusConnection_->connect());
- thread = new std::thread(dispatch, dbusConnection_);
- thread->detach();
- //readWriteDispatchCount_ = 0;
+ dbusDaemonProxy_ = std::make_shared<CommonAPI::DBus::DBusDaemonProxy>(dbusConnection_);
}
virtual void TearDown() {
- delete thread;
if (dbusConnection_ && dbusConnection_->isConnected()) {
- //dbusConnection_->disconnect();
}
}
- /*bool doReadWriteDispatch(int timeoutMilliseconds = 100) {
- readWriteDispatchCount_++;
- return dbusConnection_->readWriteDispatch(timeoutMilliseconds);
- }*/
-
std::shared_ptr<CommonAPI::DBus::DBusConnection> dbusConnection_;
- //size_t readWriteDispatchCount_;
+ std::shared_ptr<CommonAPI::DBus::DBusDaemonProxy> dbusDaemonProxy_;
};
TEST_F(DBusDaemonProxyTest, ListNames) {
std::vector<std::string> busNames;
CommonAPI::CallStatus callStatus;
- dbusConnection_->getDBusDaemonProxy()->listNames(callStatus, busNames);
+ dbusDaemonProxy_->listNames(callStatus, busNames);
ASSERT_EQ(callStatus, CommonAPI::CallStatus::SUCCESS);
ASSERT_GT(busNames.size(), 0);
@@ -65,12 +51,14 @@ TEST_F(DBusDaemonProxyTest, ListNamesAsync) {
std::promise<std::tuple<CommonAPI::CallStatus, std::vector<std::string>>> promise;
auto future = promise.get_future();
- auto callStatusFuture = dbusConnection_->getDBusDaemonProxy()->listNamesAsync(
+ auto callStatusFuture = dbusDaemonProxy_->listNamesAsync(
[&](const CommonAPI::CallStatus& callStatus, std::vector<std::string> busNames) {
promise.set_value(std::tuple<CommonAPI::CallStatus, std::vector<std::string>>(callStatus, std::move(busNames)));
});
- ASSERT_EQ(future.wait_for(std::chrono::milliseconds(200)), std::future_status::ready);
+ auto status = future.wait_for(std::chrono::milliseconds(200));
+ bool waitResult = CommonAPI::DBus::checkReady(status);
+ ASSERT_EQ(waitResult, true);
ASSERT_EQ(callStatusFuture.get(), CommonAPI::CallStatus::SUCCESS);
@@ -91,11 +79,11 @@ TEST_F(DBusDaemonProxyTest, NameHasOwner) {
bool nameHasOwner;
CommonAPI::CallStatus callStatus;
- dbusConnection_->getDBusDaemonProxy()->nameHasOwner("org.freedesktop.DBus", callStatus, nameHasOwner);
+ dbusDaemonProxy_->nameHasOwner("org.freedesktop.DBus", callStatus, nameHasOwner);
ASSERT_EQ(callStatus, CommonAPI::CallStatus::SUCCESS);
ASSERT_TRUE(nameHasOwner);
- dbusConnection_->getDBusDaemonProxy()->nameHasOwner("org.freedesktop.DBus.InvalidName.XXYYZZ", callStatus, nameHasOwner);
+ dbusDaemonProxy_->nameHasOwner("org.freedesktop.DBus.InvalidName.XXYYZZ", callStatus, nameHasOwner);
ASSERT_EQ(callStatus, CommonAPI::CallStatus::SUCCESS);
ASSERT_FALSE(nameHasOwner);
}
@@ -104,7 +92,7 @@ TEST_F(DBusDaemonProxyTest, NameHasOwnerAsync) {
std::promise<std::tuple<CommonAPI::CallStatus, bool>> promise;
auto future = promise.get_future();
- auto callStatusFuture = dbusConnection_->getDBusDaemonProxy()->nameHasOwnerAsync(
+ auto callStatusFuture = dbusDaemonProxy_->nameHasOwnerAsync(
"org.freedesktop.DBus",
[&](const CommonAPI::CallStatus& callStatus, bool nameHasOwner) {
promise.set_value(std::tuple<CommonAPI::CallStatus, bool>(callStatus, std::move(nameHasOwner)));
@@ -116,7 +104,9 @@ TEST_F(DBusDaemonProxyTest, NameHasOwnerAsync) {
// break;
//}
//ASSERT_NE(readWriteDispatchCount_, 5);
- ASSERT_EQ(future.wait_for(std::chrono::milliseconds(100)), std::future_status::ready);
+ auto status = future.wait_for(std::chrono::milliseconds(100));
+ const bool waitResult = CommonAPI::DBus::checkReady(status);
+ ASSERT_EQ(waitResult, true);
ASSERT_EQ(callStatusFuture.get(), CommonAPI::CallStatus::SUCCESS);
@@ -132,7 +122,7 @@ TEST_F(DBusDaemonProxyTest, NameOwnerChangedEvent) {
std::promise<bool> promise;
auto future = promise.get_future();
- dbusConnection_->getDBusDaemonProxy()->getNameOwnerChangedEvent().subscribe(
+ dbusDaemonProxy_->getNameOwnerChangedEvent().subscribe(
[&](const std::string& name, const std::string& oldOwner, const std::string& newOwner) {
static bool promiseIsSet = false;
if(!promiseIsSet) {
diff --git a/src/test/DBusInputStreamTest.cpp b/src/test/DBusInputStreamTest.cpp
index 81147e2..eaa33c2 100644
--- a/src/test/DBusInputStreamTest.cpp
+++ b/src/test/DBusInputStreamTest.cpp
@@ -57,7 +57,7 @@ TEST_F(InputStreamTest, ReadsEmptyMessages) {
TEST_F(InputStreamTest, ReadsBytes) {
uint8_t val = 0xff;
- for (int i = 0; i < numOfElements; i += 1) {
+ for (unsigned int i = 0; i < numOfElements; i += 1) {
dbus_message_iter_append_basic(&libdbusMessageWriteIter, DBUS_TYPE_BYTE, &val);
}
@@ -65,7 +65,7 @@ TEST_F(InputStreamTest, ReadsBytes) {
CommonAPI::DBus::DBusInputStream inStream(scopedMessage);
EXPECT_EQ(numOfElements, scopedMessage.getBodyLength());
- for (int i = 0; i < numOfElements; i += 1) {
+ for (unsigned int i = 0; i < numOfElements; i += 1) {
uint8_t readVal;
inStream >> readVal;
EXPECT_EQ(val, readVal);
@@ -75,7 +75,7 @@ TEST_F(InputStreamTest, ReadsBytes) {
TEST_F(InputStreamTest, ReadsBools) {
dbus_bool_t f = FALSE;
dbus_bool_t t = TRUE;
- for (int i = 0; i < numOfElements; i += 2) {
+ for (unsigned int i = 0; i < numOfElements; i += 2) {
dbus_message_iter_append_basic(&libdbusMessageWriteIter, DBUS_TYPE_BOOLEAN, &t);
dbus_message_iter_append_basic(&libdbusMessageWriteIter, DBUS_TYPE_BOOLEAN, &f);
}
@@ -84,7 +84,7 @@ TEST_F(InputStreamTest, ReadsBools) {
CommonAPI::DBus::DBusInputStream inStream(scopedMessage);
EXPECT_EQ(numOfElements*4, scopedMessage.getBodyLength());
- for (int i = 0; i < numOfElements; i += 2) {
+ for (unsigned int i = 0; i < numOfElements; i += 2) {
bool readVal;
inStream >> readVal;
EXPECT_EQ(t, readVal);
@@ -96,7 +96,7 @@ TEST_F(InputStreamTest, ReadsBools) {
TEST_F(InputStreamTest, ReadsUint16) {
uint16_t val = 0xffff;
- for (int i = 0; i < numOfElements; i += 1) {
+ for (unsigned int i = 0; i < numOfElements; i += 1) {
dbus_message_iter_append_basic(&libdbusMessageWriteIter, DBUS_TYPE_UINT16, &val);
}
@@ -104,7 +104,7 @@ TEST_F(InputStreamTest, ReadsUint16) {
CommonAPI::DBus::DBusInputStream inStream(scopedMessage);
EXPECT_EQ(numOfElements*2, scopedMessage.getBodyLength());
- for (int i = 0; i < numOfElements; i += 1) {
+ for (unsigned int i = 0; i < numOfElements; i += 1) {
uint16_t readVal;
inStream >> readVal;
EXPECT_EQ(val, readVal);
@@ -114,7 +114,7 @@ TEST_F(InputStreamTest, ReadsUint16) {
TEST_F(InputStreamTest, ReadsInt16) {
int16_t val = 0x7fff;
- for (int i = 0; i < numOfElements; i += 1) {
+ for (unsigned int i = 0; i < numOfElements; i += 1) {
dbus_message_iter_append_basic(&libdbusMessageWriteIter, DBUS_TYPE_INT16, &val);
}
@@ -122,7 +122,7 @@ TEST_F(InputStreamTest, ReadsInt16) {
CommonAPI::DBus::DBusInputStream inStream(scopedMessage);
EXPECT_EQ(numOfElements*2, scopedMessage.getBodyLength());
- for (int i = 0; i < numOfElements; i += 1) {
+ for (unsigned int i = 0; i < numOfElements; i += 1) {
int16_t readVal;
inStream >> readVal;
EXPECT_EQ(val, readVal);
@@ -132,7 +132,7 @@ TEST_F(InputStreamTest, ReadsInt16) {
TEST_F(InputStreamTest, ReadsUint32) {
uint32_t val = 0xffffffff;
- for (int i = 0; i < numOfElements; i += 1) {
+ for (unsigned int i = 0; i < numOfElements; i += 1) {
dbus_message_iter_append_basic(&libdbusMessageWriteIter, DBUS_TYPE_UINT32, &val);
}
@@ -140,7 +140,7 @@ TEST_F(InputStreamTest, ReadsUint32) {
CommonAPI::DBus::DBusInputStream inStream(scopedMessage);
EXPECT_EQ(numOfElements*4, scopedMessage.getBodyLength());
- for (int i = 0; i < numOfElements; i += 1) {
+ for (unsigned int i = 0; i < numOfElements; i += 1) {
uint32_t readVal;
inStream >> readVal;
EXPECT_EQ(val, readVal);
@@ -150,7 +150,7 @@ TEST_F(InputStreamTest, ReadsUint32) {
TEST_F(InputStreamTest, ReadsInt32) {
int32_t val = 0x7fffffff;
- for (int i = 0; i < numOfElements; i += 1) {
+ for (unsigned int i = 0; i < numOfElements; i += 1) {
dbus_message_iter_append_basic(&libdbusMessageWriteIter, DBUS_TYPE_INT32, &val);
}
@@ -158,7 +158,7 @@ TEST_F(InputStreamTest, ReadsInt32) {
CommonAPI::DBus::DBusInputStream inStream(scopedMessage);
EXPECT_EQ(numOfElements*4, scopedMessage.getBodyLength());
- for (int i = 0; i < numOfElements; i += 1) {
+ for (unsigned int i = 0; i < numOfElements; i += 1) {
int32_t readVal;
inStream >> readVal;
EXPECT_EQ(val, readVal);
@@ -168,7 +168,7 @@ TEST_F(InputStreamTest, ReadsInt32) {
TEST_F(InputStreamTest, ReadsUint64) {
uint64_t val = 0xffffffffffffffff;
- for (int i = 0; i < numOfElements; i += 1) {
+ for (unsigned int i = 0; i < numOfElements; i += 1) {
dbus_message_iter_append_basic(&libdbusMessageWriteIter, DBUS_TYPE_UINT64, &val);
}
@@ -176,7 +176,7 @@ TEST_F(InputStreamTest, ReadsUint64) {
CommonAPI::DBus::DBusInputStream inStream(scopedMessage);
EXPECT_EQ(numOfElements*8, scopedMessage.getBodyLength());
- for (int i = 0; i < numOfElements; i += 1) {
+ for (unsigned int i = 0; i < numOfElements; i += 1) {
uint64_t readVal;
inStream >> readVal;
EXPECT_EQ(val, readVal);
@@ -186,7 +186,7 @@ TEST_F(InputStreamTest, ReadsUint64) {
TEST_F(InputStreamTest, ReadsInt64) {
int64_t val = 0x7fffffffffffffff;
- for (int i = 0; i < numOfElements; i += 1) {
+ for (unsigned int i = 0; i < numOfElements; i += 1) {
dbus_message_iter_append_basic(&libdbusMessageWriteIter, DBUS_TYPE_INT64, &val);
}
@@ -194,7 +194,7 @@ TEST_F(InputStreamTest, ReadsInt64) {
CommonAPI::DBus::DBusInputStream inStream(scopedMessage);
EXPECT_EQ(numOfElements*8, scopedMessage.getBodyLength());
- for (int i = 0; i < numOfElements; i += 1) {
+ for (unsigned int i = 0; i < numOfElements; i += 1) {
int64_t readVal;
inStream >> readVal;
EXPECT_EQ(val, readVal);
@@ -204,7 +204,7 @@ TEST_F(InputStreamTest, ReadsInt64) {
TEST_F(InputStreamTest, ReadsDoubles) {
double val = 13.37;
- for (int i = 0; i < numOfElements; i += 1) {
+ for (unsigned int i = 0; i < numOfElements; i += 1) {
dbus_message_iter_append_basic(&libdbusMessageWriteIter, DBUS_TYPE_DOUBLE, &val);
}
@@ -212,7 +212,7 @@ TEST_F(InputStreamTest, ReadsDoubles) {
CommonAPI::DBus::DBusInputStream inStream(scopedMessage);
EXPECT_EQ(numOfElements*8, scopedMessage.getBodyLength());
- for (int i = 0; i < numOfElements; i += 1) {
+ for (unsigned int i = 0; i < numOfElements; i += 1) {
double readVal;
inStream >> readVal;
EXPECT_EQ(val, readVal);
@@ -222,7 +222,7 @@ TEST_F(InputStreamTest, ReadsDoubles) {
TEST_F(InputStreamTest, ReadsStrings) {
std::string val = "hai";
- for (int i = 0; i < numOfElements; i += 1) {
+ for (unsigned int i = 0; i < numOfElements; i += 1) {
dbus_message_iter_append_basic(&libdbusMessageWriteIter, DBUS_TYPE_STRING, &val);
}
@@ -230,7 +230,7 @@ TEST_F(InputStreamTest, ReadsStrings) {
CommonAPI::DBus::DBusInputStream inStream(scopedMessage);
EXPECT_EQ(numOfElements*4 + numOfElements*4, scopedMessage.getBodyLength());
- for (int i = 0; i < numOfElements; i += 1) {
+ for (unsigned int i = 0; i < numOfElements; i += 1) {
std::string readVal;
inStream >> readVal;
EXPECT_EQ(val, readVal);
@@ -316,14 +316,14 @@ TEST_F(InputStreamTest, ReadsArrays) {
std::vector<int32_t> testVector;
int32_t val1 = 0xffffffff;
int32_t val2 = 0x7fffffff;
- for (int i = 0; i < numOfElements; i += 2) {
+ for (unsigned int i = 0; i < numOfElements; i += 2) {
testVector.push_back(val1);
testVector.push_back(val2);
}
DBusMessageIter subIter;
dbus_message_iter_open_container(&libdbusMessageWriteIter, DBUS_TYPE_ARRAY, "i", &subIter);
- for (int i = 0; i < numOfElements; i++) {
+ for (unsigned int i = 0; i < numOfElements; i++) {
dbus_message_iter_append_basic(&subIter, DBUS_TYPE_INT32, &testVector[i]);
}
dbus_message_iter_close_container(&libdbusMessageWriteIter, &subIter);
@@ -336,7 +336,7 @@ TEST_F(InputStreamTest, ReadsArrays) {
inStream >> verifyVector;
int32_t res1;
int32_t res2;
- for (int i = 0; i < numOfElements; i += 2) {
+ for (unsigned int i = 0; i < numOfElements; i += 2) {
res1 = verifyVector[i];
EXPECT_EQ(val1, res1);
res2 = verifyVector[i + 1];
@@ -355,9 +355,9 @@ TEST_F(InputStreamTest, ReadsArraysInArrays) {
std::vector<std::vector<int32_t>> testVector;
int32_t val1 = 0xffffffff;
int32_t val2 = 0x7fffffff;
- for (int i = 0; i < numOfElements; i++) {
+ for (unsigned int i = 0; i < numOfElements; i++) {
std::vector<int32_t> inner;
- for (int j = 0; j < numOfElements; j += 2) {
+ for (unsigned int j = 0; j < numOfElements; j += 2) {
inner.push_back(val1);
inner.push_back(val2);
}
@@ -366,10 +366,10 @@ TEST_F(InputStreamTest, ReadsArraysInArrays) {
DBusMessageIter subIter;
dbus_message_iter_open_container(&writeIter, DBUS_TYPE_ARRAY, "ai", &subIter);
- for (int i = 0; i < numOfElements; i++) {
+ for (unsigned int i = 0; i < numOfElements; i++) {
DBusMessageIter subsubIter;
dbus_message_iter_open_container(&subIter, DBUS_TYPE_ARRAY, "i", &subsubIter);
- for (int j = 0; j < numOfElements; j++) {
+ for (unsigned int j = 0; j < numOfElements; j++) {
dbus_message_iter_append_basic(&subsubIter, DBUS_TYPE_INT32, &(testVector[i][j]));
}
dbus_message_iter_close_container(&subIter, &subsubIter);
@@ -386,9 +386,9 @@ TEST_F(InputStreamTest, ReadsArraysInArrays) {
int32_t res1;
int32_t res2;
- for (int i = 0; i < numOfElements; i++) {
+ for (unsigned int i = 0; i < numOfElements; i++) {
std::vector<int32_t> innerVerify = verifyVector[i];
- for (int j = 0; j < numOfElements; j += 2) {
+ for (unsigned int j = 0; j < numOfElements; j += 2) {
res1 = innerVerify[j];
EXPECT_EQ(val1, res1);
res2 = innerVerify[j + 1];
@@ -403,7 +403,7 @@ TEST_F(InputStreamTest, ReadsInt32Variants) {
int32_t fromInt = 5;
int8_t variantTypeIndex = 3;
- for (int i = 0; i < numOfElements; i += 1) {
+ for (unsigned int i = 0; i < numOfElements; i += 1) {
DBusMessageIter subIter;
dbus_message_iter_open_container(&libdbusMessageWriteIter, DBUS_TYPE_STRUCT, NULL, &subIter);
dbus_message_iter_append_basic(&subIter, DBUS_TYPE_BYTE, &variantTypeIndex);
@@ -420,7 +420,7 @@ TEST_F(InputStreamTest, ReadsInt32Variants) {
TestedVariantType referenceVariant(fromInt);
EXPECT_EQ(numOfElements*4 + numOfElements*4, scopedMessage.getBodyLength());
- for (int i = 0; i < numOfElements; i += 1) {
+ for (unsigned int i = 0; i < numOfElements; i += 1) {
TestedVariantType readVariant;
inStream >> readVariant;
@@ -439,7 +439,7 @@ TEST_F(InputStreamTest, ReadsStringVariants) {
std::string fromString = "Hello World with CommonAPI Variants!";
int8_t variantTypeIndex = 1;
- for (int i = 0; i < numOfElements; i += 1) {
+ for (unsigned int i = 0; i < numOfElements; i += 1) {
DBusMessageIter subIter;
dbus_message_iter_open_container(&libdbusMessageWriteIter, DBUS_TYPE_STRUCT, NULL, &subIter);
dbus_message_iter_append_basic(&subIter, DBUS_TYPE_BYTE, &variantTypeIndex);
@@ -458,7 +458,7 @@ TEST_F(InputStreamTest, ReadsStringVariants) {
//Variant: type-index(1) + signature(2) + padding(1) + stringLength(4) + string(37) = 45
// +struct-padding inbetween (alignment 8)
EXPECT_EQ(numOfElements * (1+3+4+fromString.length()+1) + (numOfElements - 1) * (8-((fromString.length()+1)%8)) , scopedMessage.getBodyLength());
- for (int i = 0; i < numOfElements; i += 1) {
+ for (unsigned int i = 0; i < numOfElements; i += 1) {
TestedVariantType readVariant;
inStream >> readVariant;
@@ -470,67 +470,6 @@ TEST_F(InputStreamTest, ReadsStringVariants) {
}
}
-TEST_F(InputStreamTest, ReadsWriteVariantsWithAnArrayOfStrings) {
-
- size_t numOfElements;
- CommonAPI::DBus::DBusMessage message;
- const char* busName;
- const char* objectPath;
- const char* interfaceName;
- const char* methodName;
-
- busName = "no.bus.here";
- objectPath = "/no/object/here";
- interfaceName = "no.interface.here";
- methodName = "noMethodHere";
-
- const char* signature = "yyyyyyyyyy";
- message = CommonAPI::DBus::DBusMessage::createMethodCall(busName, objectPath, interfaceName, methodName, signature);
- CommonAPI::DBus::DBusOutputStream outputStream(message);
-
-
-
- typedef CommonAPI::Variant<int32_t, double, std::vector<std::string>> TestedVariantType;
-
- std::string testString1 = "Hello World with CommonAPI Variants!";
- std::string testString2 = "What a beautiful world if there are working Arrays within Variants!!";
-
- std::vector<std::string> testInnerVector;
-
- for (int i = 0; i < numOfElements; i += 2) {
- testInnerVector.push_back(testString1);
- testInnerVector.push_back(testString2);
- }
-
- TestedVariantType writtenVariant(testInnerVector);
-
-
- for (int i = 0; i < numOfElements; i += 1) {
-
- outputStream << writtenVariant;
-
- }
-
- CommonAPI::DBus::DBusInputStream inStream(message);
-
- TestedVariantType referenceVariant(testInnerVector);
-
- //Variant: structAlign + type-index(1) + variantSignature(4) + padding(3) + arrayLength(4) + stringLength(4) +
- // string(37) + padding(3) + stringLength(4) + string(69) = 129
-// EXPECT_EQ(129 + 7 + 129, message.getBodyLength());
-// for (int i = 0; i < numOfElements; i += 1) {
-// TestedVariantType readVariant;
-// inStream >> readVariant;
-//
-// bool readSuccess;
-// std::vector<std::string> actualResult = readVariant.get<std::vector<std::string>>(readSuccess);
-// EXPECT_TRUE(readSuccess);
-//
-// bool variantsAreEqual = (referenceVariant == readVariant);
-// EXPECT_TRUE(variantsAreEqual);
-// EXPECT_EQ(testInnerVector, actualResult);
-// }
-}
TEST_F(InputStreamTest, ReadsVariantsWithAnArrayOfStrings) {
typedef CommonAPI::Variant<int32_t, double, std::vector<std::string>> TestedVariantType;
@@ -541,12 +480,12 @@ TEST_F(InputStreamTest, ReadsVariantsWithAnArrayOfStrings) {
std::vector<std::string> testInnerVector;
- for (int i = 0; i < numOfElements; i += 2) {
+ for (unsigned int i = 0; i < numOfElements; i += 2) {
testInnerVector.push_back(testString1);
testInnerVector.push_back(testString2);
}
- for (int i = 0; i < numOfElements; i += 1) {
+ for (unsigned int i = 0; i < numOfElements; i += 1) {
DBusMessageIter subIter;
dbus_message_iter_open_container(&libdbusMessageWriteIter, DBUS_TYPE_STRUCT, NULL, &subIter);
dbus_message_iter_append_basic(&subIter, DBUS_TYPE_BYTE, &variantTypeIndex);
@@ -555,7 +494,7 @@ TEST_F(InputStreamTest, ReadsVariantsWithAnArrayOfStrings) {
DBusMessageIter innerArrayIter;
dbus_message_iter_open_container(&subSubIter, DBUS_TYPE_ARRAY, "s", &innerArrayIter);
- for (int i = 0; i < numOfElements; i++) {
+ for (unsigned int i = 0; i < numOfElements; i++) {
dbus_message_iter_append_basic(&innerArrayIter, DBUS_TYPE_STRING, &testInnerVector[i]);
}
dbus_message_iter_close_container(&subSubIter, &innerArrayIter);
@@ -572,7 +511,7 @@ TEST_F(InputStreamTest, ReadsVariantsWithAnArrayOfStrings) {
//Variant: structAlign + type-index(1) + variantSignature(4) + padding(3) + arrayLength(4) + stringLength(4) +
// string(37) + padding(3) + stringLength(4) + string(69) = 129
EXPECT_EQ(129 + 7 + 129, scopedMessage.getBodyLength());
- for (int i = 0; i < numOfElements; i += 1) {
+ for (unsigned int i = 0; i < numOfElements; i += 1) {
TestedVariantType readVariant;
inStream >> readVariant;
@@ -602,7 +541,7 @@ TEST_F(InputStreamTest, ReadsVariantsWithVariants) {
const uint32_t byteBufferElementCount = numOfElements*10;
CommonAPI::ByteBuffer innerVariant1Value;
- for (int i = 0; i < byteBufferElementCount; ++i) {
+ for (unsigned int i = 0; i < byteBufferElementCount; ++i) {
innerVariant1Value.push_back((char) (i+40));
}
@@ -628,7 +567,7 @@ TEST_F(InputStreamTest, ReadsVariantsWithVariants) {
//begin inner variant content
dbus_message_iter_open_container(&innerVariantActualIterator, DBUS_TYPE_ARRAY, "y", &innerArrayIter);
- for (int i = 0; i < byteBufferElementCount; i++) {
+ for (unsigned int i = 0; i < byteBufferElementCount; i++) {
dbus_message_iter_append_basic(&innerArrayIter, DBUS_TYPE_BYTE, &innerVariant1Value[i]);
}
dbus_message_iter_close_container(&innerVariantActualIterator, &innerArrayIter);
diff --git a/src/test/DBusMultipleConnectionTest.cpp b/src/test/DBusMultipleConnectionTest.cpp
index 32f0717..a0cc497 100644
--- a/src/test/DBusMultipleConnectionTest.cpp
+++ b/src/test/DBusMultipleConnectionTest.cpp
@@ -22,6 +22,8 @@
#include "commonapi/tests/TestInterfaceProxy.h"
#include "commonapi/tests/TestInterfaceStubDefault.h"
+
+
const std::string serviceAddress = "local:commonapi.tests.TestInterface:commonapi.tests.TestInterface";
class DBusMultipleConnectionTest: public ::testing::Test {
@@ -41,6 +43,8 @@ class DBusMultipleConnectionTest: public ::testing::Test {
}
virtual void TearDown() {
+ stubFactory->unregisterService(serviceAddress);
+ sleep(1);
}
std::shared_ptr<CommonAPI::Factory> proxyFactory;
@@ -51,75 +55,74 @@ class DBusMultipleConnectionTest: public ::testing::Test {
};
-TEST_F(DBusMultipleConnectionTest, SetAttribute) {
+TEST_F(DBusMultipleConnectionTest, RemoteMethodCall) {
uint32_t v1 = 5;
- uint32_t v2;
+ std::string v2 = "Hai :)";
CommonAPI::CallStatus stat;
- proxy->getTestPredefinedTypeAttributeAttribute().setValue(v1, stat, v2);
- ASSERT_EQ(stat, CommonAPI::CallStatus::SUCCESS);
- ASSERT_EQ(v1, v2);
+ proxy->testVoidPredefinedTypeMethod(v1, v2, stat);
+ ASSERT_EQ(CommonAPI::CallStatus::SUCCESS, stat);
}
-TEST_F(DBusMultipleConnectionTest, SetAttributeBroadcast) {
- uint32_t v1 = 6;
- uint32_t v2;
+TEST_F(DBusMultipleConnectionTest, Broadcast) {
+ uint32_t v1 = 5;
uint32_t v3 = 0;
+ std::string v2 = "Hai :)";
std::promise<bool> promise;
auto future = promise.get_future();
- proxy->getTestPredefinedTypeAttributeAttribute().getChangedEvent().subscribe([&](
- const uint32_t intVal) {
+ proxy->getTestPredefinedTypeBroadcastEvent().subscribe([&](
+ const uint32_t intVal, const std::string& strVal) {
v3 = intVal;
promise.set_value(true);
});
- CommonAPI::CallStatus stat;
- proxy->getTestPredefinedTypeAttributeAttribute().setValue(v1, stat, v2);
- ASSERT_EQ(stat, CommonAPI::CallStatus::SUCCESS);
- ASSERT_EQ(v1, v2);
+ stub->fireTestPredefinedTypeBroadcastEvent(v1, v2);
ASSERT_TRUE(future.get());
ASSERT_EQ(v1, v3);
-
}
-
-TEST_F(DBusMultipleConnectionTest, GetAttribute) {
- uint32_t v1;
- CommonAPI::CallStatus stat = proxy->getTestPredefinedTypeAttributeAttribute().getValue(v1);
- ASSERT_EQ(stat, CommonAPI::CallStatus::SUCCESS);
-}
-
-TEST_F(DBusMultipleConnectionTest, RemoteMethodCall) {
+TEST_F(DBusMultipleConnectionTest, SetAttribute) {
uint32_t v1 = 5;
- std::string v2 = "Hai :)";
+ uint32_t v2;
CommonAPI::CallStatus stat;
- proxy->testVoidPredefinedTypeMethod(v1, v2, stat);
- ASSERT_EQ(stat, CommonAPI::CallStatus::SUCCESS);
+ proxy->getTestPredefinedTypeAttributeAttribute().setValue(v1, stat, v2);
+ ASSERT_EQ(CommonAPI::CallStatus::SUCCESS, stat);
+ ASSERT_EQ(v1, v2);
}
-TEST_F(DBusMultipleConnectionTest, Broadcast) {
- uint32_t v1 = 5;
+TEST_F(DBusMultipleConnectionTest, SetAttributeBroadcast) {
+ uint32_t v1 = 6;
+ uint32_t v2;
uint32_t v3 = 0;
- std::string v2 = "Hai :)";
std::promise<bool> promise;
auto future = promise.get_future();
- proxy->getTestPredefinedTypeBroadcastEvent().subscribe([&](
- const uint32_t intVal, const std::string& strVal) {
+ proxy->getTestPredefinedTypeAttributeAttribute().getChangedEvent().subscribe([&](
+ const uint32_t intVal) {
v3 = intVal;
promise.set_value(true);
});
- stub->fireTestPredefinedTypeBroadcastEvent(v1, v2);
+ CommonAPI::CallStatus stat;
+ proxy->getTestPredefinedTypeAttributeAttribute().setValue(v1, stat, v2);
+ ASSERT_EQ(CommonAPI::CallStatus::SUCCESS, stat);
+ ASSERT_EQ(v1, v2);
ASSERT_TRUE(future.get());
ASSERT_EQ(v1, v3);
}
+TEST_F(DBusMultipleConnectionTest, GetAttribute) {
+ uint32_t v1;
+ CommonAPI::CallStatus stat = proxy->getTestPredefinedTypeAttributeAttribute().getValue(v1);
+ ASSERT_EQ(CommonAPI::CallStatus::SUCCESS, stat);
+}
+
+
int main(int argc, char** argv) {
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
diff --git a/src/test/DBusOutputStreamTest.cpp b/src/test/DBusOutputStreamTest.cpp
index b1c50f2..34627d8 100644
--- a/src/test/DBusOutputStreamTest.cpp
+++ b/src/test/DBusOutputStreamTest.cpp
@@ -13,6 +13,8 @@
#include <CommonAPI/SerializableStruct.h>
#include <CommonAPI/SerializableVariant.h>
+#include "commonapi/tests/DerivedTypeCollection.h"
+
class OutputStreamTest: public ::testing::Test {
protected:
@@ -47,7 +49,7 @@ TEST_F(OutputStreamTest, WritesBytes) {
outStream.reserveMemory(numOfElements);
uint8_t val1 = 0xff;
uint8_t val2 = 0x00;
- for (int i = 0; i < numOfElements; i += 2) {
+ for (unsigned int i = 0; i < numOfElements; i += 2) {
outStream << val1;
outStream << val2;
}
@@ -59,7 +61,7 @@ TEST_F(OutputStreamTest, WritesBytes) {
uint8_t verifyVal1;
uint8_t verifyVal2;
- for (int i = 0; i < numOfElements; i += 2) {
+ for (unsigned int i = 0; i < numOfElements; i += 2) {
inStream >> verifyVal1;
EXPECT_EQ(val1, verifyVal1);
@@ -76,7 +78,7 @@ TEST_F(OutputStreamTest, WritesBools) {
outStream.reserveMemory(numOfElements * 4);
bool val1 = TRUE;
bool val2 = FALSE;
- for (int i = 0; i < numOfElements; i += 2) {
+ for (unsigned int i = 0; i < numOfElements; i += 2) {
outStream << val1;
outStream << val2;
}
@@ -88,7 +90,7 @@ TEST_F(OutputStreamTest, WritesBools) {
bool verifyVal1;
bool verifyVal2;
- for (int i = 0; i < numOfElements; i += 2) {
+ for (unsigned int i = 0; i < numOfElements; i += 2) {
inStream >> verifyVal1;
EXPECT_EQ(val1, verifyVal1);
@@ -105,7 +107,7 @@ TEST_F(OutputStreamTest, WritesUInt16) {
outStream.reserveMemory(numOfElements * 2);
uint16_t val1 = 0x0000;
uint16_t val2 = 0xffff;
- for (int i = 0; i < numOfElements; i += 2) {
+ for (unsigned int i = 0; i < numOfElements; i += 2) {
outStream << val1;
outStream << val2;
}
@@ -117,7 +119,7 @@ TEST_F(OutputStreamTest, WritesUInt16) {
uint16_t verifyVal1;
uint16_t verifyVal2;
- for (int i = 0; i < numOfElements; i += 2) {
+ for (unsigned int i = 0; i < numOfElements; i += 2) {
inStream >> verifyVal1;
EXPECT_EQ(val1, verifyVal1);
@@ -134,7 +136,7 @@ TEST_F(OutputStreamTest, WritesInt16) {
outStream.reserveMemory(numOfElements * 2);
int16_t val1 = 0x7fff;
int16_t val2 = 0xffff;
- for (int i = 0; i < numOfElements; i += 2) {
+ for (unsigned int i = 0; i < numOfElements; i += 2) {
outStream << val1;
outStream << val2;
}
@@ -146,7 +148,7 @@ TEST_F(OutputStreamTest, WritesInt16) {
int16_t verifyVal1;
int16_t verifyVal2;
- for (int i = 0; i < numOfElements; i += 2) {
+ for (unsigned int i = 0; i < numOfElements; i += 2) {
inStream >> verifyVal1;
EXPECT_EQ(val1, verifyVal1);
@@ -163,7 +165,7 @@ TEST_F(OutputStreamTest, WritesUInt32) {
outStream.reserveMemory(numOfElements * 4);
uint32_t val1 = 0x00000000;
uint32_t val2 = 0xffffffff;
- for (int i = 0; i < numOfElements; i += 2) {
+ for (unsigned int i = 0; i < numOfElements; i += 2) {
outStream << val1;
outStream << val2;
}
@@ -175,7 +177,7 @@ TEST_F(OutputStreamTest, WritesUInt32) {
uint32_t verifyVal1;
uint32_t verifyVal2;
- for (int i = 0; i < numOfElements; i += 2) {
+ for (unsigned int i = 0; i < numOfElements; i += 2) {
inStream >> verifyVal1;
EXPECT_EQ(val1, verifyVal1);
@@ -192,7 +194,7 @@ TEST_F(OutputStreamTest, WritesInt32) {
outStream.reserveMemory(numOfElements * 4);
int32_t val1 = 0x7fffffff;
int32_t val2 = 0xffffffff;
- for (int i = 0; i < numOfElements; i += 2) {
+ for (unsigned int i = 0; i < numOfElements; i += 2) {
outStream << val1;
outStream << val2;
}
@@ -204,7 +206,7 @@ TEST_F(OutputStreamTest, WritesInt32) {
int32_t verifyVal1;
int32_t verifyVal2;
- for (int i = 0; i < numOfElements; i += 2) {
+ for (unsigned int i = 0; i < numOfElements; i += 2) {
inStream >> verifyVal1;
EXPECT_EQ(val1, verifyVal1);
@@ -221,7 +223,7 @@ TEST_F(OutputStreamTest, WritesUInt64) {
outStream.reserveMemory(numOfElements * 8);
uint64_t val1 = 0x0000000000000000;
uint64_t val2 = 0xffffffffffffffff;
- for (int i = 0; i < numOfElements; i += 2) {
+ for (unsigned int i = 0; i < numOfElements; i += 2) {
outStream << val1;
outStream << val2;
}
@@ -233,7 +235,7 @@ TEST_F(OutputStreamTest, WritesUInt64) {
uint64_t verifyVal1;
uint64_t verifyVal2;
- for (int i = 0; i < numOfElements; i += 2) {
+ for (unsigned int i = 0; i < numOfElements; i += 2) {
inStream >> verifyVal1;
EXPECT_EQ(val1, verifyVal1);
@@ -250,7 +252,7 @@ TEST_F(OutputStreamTest, WritesInt64) {
outStream.reserveMemory(numOfElements * 8);
int64_t val1 = 0x7fffffffffffffff;
int64_t val2 = 0xffffffffffffffff;
- for (int i = 0; i < numOfElements; i += 2) {
+ for (unsigned int i = 0; i < numOfElements; i += 2) {
outStream << val1;
outStream << val2;
}
@@ -262,7 +264,7 @@ TEST_F(OutputStreamTest, WritesInt64) {
int64_t verifyVal1;
int64_t verifyVal2;
- for (int i = 0; i < numOfElements; i += 2) {
+ for (unsigned int i = 0; i < numOfElements; i += 2) {
inStream >> verifyVal1;
EXPECT_EQ(val1, verifyVal1);
@@ -279,7 +281,7 @@ TEST_F(OutputStreamTest, WritesDouble) {
outStream.reserveMemory(numOfElements * 8);
double val1 = 13.37;
double val2 = 3.414;
- for (int i = 0; i < numOfElements; i += 2) {
+ for (unsigned int i = 0; i < numOfElements; i += 2) {
outStream << val1;
outStream << val2;
}
@@ -292,7 +294,7 @@ TEST_F(OutputStreamTest, WritesDouble) {
double verifyVal1;
double verifyVal2;
std::string verifySignature;
- for (int i = 0; i < numOfElements; i += 2) {
+ for (unsigned int i = 0; i < numOfElements; i += 2) {
inStream >> verifyVal1;
EXPECT_EQ(val1, verifyVal1);
@@ -403,7 +405,7 @@ TEST_F(OutputStreamTest, WritesArrays) {
std::vector<int32_t> testVector;
int32_t val1 = 0xffffffff;
int32_t val2 = 0x7fffffff;
- for (int i = 0; i < numOfElements; i += 2) {
+ for (unsigned int i = 0; i < numOfElements; i += 2) {
testVector.push_back(val1);
testVector.push_back(val2);
}
@@ -420,7 +422,7 @@ TEST_F(OutputStreamTest, WritesArrays) {
int32_t res1;
int32_t res2;
- for (int i = 0; i < numOfElements; i += 2) {
+ for (unsigned int i = 0; i < numOfElements; i += 2) {
res1 = verifyVector[i];
EXPECT_EQ(val1, res1);
res2 = verifyVector[i + 1];
@@ -436,7 +438,7 @@ TEST_F(OutputStreamTest, WritesArraysOfStrings) {
std::vector<std::string> testVector;
std::string val1 = "Hai";
std::string val2 = "Ciao";
- for (int i = 0; i < numOfElements; i += 2) {
+ for (unsigned int i = 0; i < numOfElements; i += 2) {
testVector.push_back(val1);
testVector.push_back(val2);
}
@@ -457,7 +459,7 @@ TEST_F(OutputStreamTest, WritesArraysOfStrings) {
std::string res1;
std::string res2;
- for (int i = 0; i < numOfElements; i += 2) {
+ for (unsigned int i = 0; i < numOfElements; i += 2) {
res1 = verifyVector[i];
EXPECT_EQ(val1, res1);
res2 = verifyVector[i + 1];
@@ -473,9 +475,9 @@ TEST_F(OutputStreamTest, WritesArraysInArrays) {
std::vector<std::vector<int32_t>> testVector;
int32_t val1 = 0xffffffff;
int32_t val2 = 0x7fffffff;
- for (int i = 0; i < numOfElements; i++) {
+ for (unsigned int i = 0; i < numOfElements; i++) {
std::vector<int32_t> inner;
- for (int j = 0; j < numOfElements; j += 2) {
+ for (unsigned int j = 0; j < numOfElements; j += 2) {
inner.push_back(val1);
inner.push_back(val2);
}
@@ -494,9 +496,9 @@ TEST_F(OutputStreamTest, WritesArraysInArrays) {
int32_t res1;
int32_t res2;
- for (int i = 0; i < numOfElements; i++) {
+ for (unsigned int i = 0; i < numOfElements; i++) {
std::vector<int32_t> innerVerify = verifyVector[i];
- for (int j = 0; j < numOfElements; j += 2) {
+ for (unsigned int j = 0; j < numOfElements; j += 2) {
res1 = innerVerify[j];
EXPECT_EQ(val1, res1);
res2 = innerVerify[j + 1];
@@ -625,7 +627,7 @@ TEST_F(OutputStreamTest, WritesTestStructLists) {
CommonAPI::DBus::DBusOutputStream outStream(message);
com::bmw::test::TestStructList testList;
- for (int i = 0; i < numOfElements; i++) {
+ for (unsigned int i = 0; i < numOfElements; i++) {
testList.emplace_back(1, 12.6, 1e40, "XXXXXXXXXXXXXXXXXXXX");
}
@@ -697,7 +699,7 @@ TEST_F(OutputStreamTest, WritesStructsOfArraysWithSthBefore) {
CommonAPI::DBus::DBusOutputStream outStream(message);
com::bmw::test::ArrayStruct arrayStruct;
- for (int i = 0; i < numOfElements; i++) {
+ for (unsigned int i = 0; i < numOfElements; i++) {
arrayStruct.val1.push_back(i*50);
arrayStruct.val2.push_back("Hai");
arrayStruct.val3.push_back(3.414);
@@ -733,7 +735,7 @@ TEST_F(OutputStreamTest, WritesStructsOfArraysWithSthBefore) {
std::string res4;
uint16_t res5;
- for (int i = 0; i < numOfElements; i++) {
+ for (unsigned int i = 0; i < numOfElements; i++) {
res1 = verifyStruct.val1[i];
res2 = verifyStruct.val2[i];
res3 = verifyStruct.val3[i];
@@ -748,6 +750,45 @@ TEST_F(OutputStreamTest, WritesStructsOfArraysWithSthBefore) {
}
}
+
+
+TEST_F(OutputStreamTest, WritesEnumKeyedMaps) {
+ commonapi::tests::DerivedTypeCollection::TestEnumMap testEnumMap;
+
+ commonapi::tests::DerivedTypeCollection::TestEnum key1 = commonapi::tests::DerivedTypeCollection::TestEnum::E_NOT_USED;
+ commonapi::tests::DerivedTypeCollection::TestEnum key2 = commonapi::tests::DerivedTypeCollection::TestEnum::E_OK;
+ commonapi::tests::DerivedTypeCollection::TestEnum key3 = commonapi::tests::DerivedTypeCollection::TestEnum::E_OUT_OF_RANGE;
+ commonapi::tests::DerivedTypeCollection::TestEnum key4 = commonapi::tests::DerivedTypeCollection::TestEnum::E_UNKNOWN;
+ std::string val = "Hai";
+
+ testEnumMap.insert( {key1, val} );
+ testEnumMap.insert( {key2, val} );
+ testEnumMap.insert( {key3, val} );
+ testEnumMap.insert( {key4, val} );
+
+ const char* signature = "a{is}";
+ message = CommonAPI::DBus::DBusMessage::createMethodCall(busName, objectPath, interfaceName, methodName, signature);
+ CommonAPI::DBus::DBusOutputStream outStream(message);
+
+ //array length (4) + struct-padding (4) +
+ // 3 * (sizeof(int) + sizeof(string) + struct-padding) + (sizeof(int) + sizeof(string))
+ size_t sizeOfBody = 4 + 4 + 3 * (4 + 8 + 4) + (4 + 8);
+ outStream.reserveMemory(sizeOfBody);
+ outStream << testEnumMap;
+ outStream.flush();
+
+ EXPECT_EQ(sizeOfBody, message.getBodyLength());
+
+ CommonAPI::DBus::DBusInputStream inStream(message);
+
+ commonapi::tests::DerivedTypeCollection::TestEnumMap verificationMap;
+ inStream >> verificationMap;
+
+ for(auto it = verificationMap.begin(); it != verificationMap.end(); ++it) {
+ ASSERT_EQ(it->second, testEnumMap[it->first]);
+ }
+}
+
int main(int argc, char** argv) {
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
diff --git a/src/test/DBusProxyTest.cpp b/src/test/DBusProxyTest.cpp
index cd51def..7efdda9 100644
--- a/src/test/DBusProxyTest.cpp
+++ b/src/test/DBusProxyTest.cpp
@@ -4,99 +4,128 @@
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-#include <dbus/dbus.h>
+#ifndef _GLIBCXX_USE_NANOSLEEP
+#define _GLIBCXX_USE_NANOSLEEP
+#endif
+
#include <CommonAPI/DBus/DBusInputStream.h>
#include <CommonAPI/DBus/DBusMessage.h>
#include <CommonAPI/DBus/DBusProxy.h>
#include <CommonAPI/DBus/DBusConnection.h>
#include <CommonAPI/DBus/DBusStubAdapter.h>
-#include <stdint.h>
-#include <vector>
+#include <CommonAPI/DBus/DBusUtils.h>
+
+#include <commonapi/tests/TestInterfaceDBusProxy.h>
+#include <commonapi/tests/TestInterfaceDBusStubAdapter.h>
+#include <commonapi/tests/TestInterfaceStubDefault.h>
+
#include <gtest/gtest.h>
-#include <iostream>
+
#include <algorithm>
+#include <cstdint>
+#include <iostream>
#include <string>
+#include <thread>
+#include <vector>
-class TestProxy: public CommonAPI::DBus::DBusProxy {
-public:
- TestProxy(const std::shared_ptr<CommonAPI::DBus::DBusConnection>& dbusConnection);
- ~TestProxy() = default;
+static const std::string commonApiAddress = "local:CommonAPI.DBus.tests.DBusProxyTestInterface:CommonAPI.DBus.tests.DBusProxyTestService";
+static const std::string commonApiServiceName = "CommonAPI.DBus.tests.DBusProxyTestInterface";
+static const std::string interfaceName = "CommonAPI.DBus.tests.DBusProxyTestInterface";
+static const std::string busName = "CommonAPI.DBus.tests.DBusProxyTestService";
+static const std::string objectPath = "/CommonAPI/DBus/tests/DBusProxyTestService";
+
+class ProxyTest: public ::testing::Test {
protected:
- void getOwnVersion(uint16_t& ownVersionMajor, uint16_t& ownVersionMinor) const;
-};
+ void SetUp() {
+ proxyDBusConnection_ = CommonAPI::DBus::DBusConnection::getSessionBus();
+ ASSERT_TRUE(proxyDBusConnection_->connect());
+
+ proxy_ = std::make_shared<commonapi::tests::TestInterfaceDBusProxy>(
+ commonApiAddress,
+ interfaceName,
+ busName,
+ objectPath,
+ proxyDBusConnection_);
+ }
-class TestStubAdapter: public CommonAPI::DBus::DBusStubAdapter {
-public:
- TestStubAdapter(const std::shared_ptr<CommonAPI::DBus::DBusConnection>& dbusConnection);
-protected:
- bool onInterfaceDBusMessage(const CommonAPI::DBus::DBusMessage& dbusMessage);
- const char* getMethodsDBusIntrospectionXmlData() const;
-};
+ virtual void TearDown() {
+ }
-const char* TestStubAdapter::getMethodsDBusIntrospectionXmlData() const {
- return "";
-}
+ void registerTestStub() {
+ stubDBusConnection_ = CommonAPI::DBus::DBusConnection::getSessionBus();
+ ASSERT_TRUE(stubDBusConnection_->connect());
+
+ ASSERT_TRUE(stubDBusConnection_->requestServiceNameAndBlock(busName));
+
+ auto stubDefault = std::make_shared<commonapi::tests::TestInterfaceStubDefault>();
+ stubAdapter_ = std::make_shared<commonapi::tests::TestInterfaceDBusStubAdapter>(
+ commonApiAddress,
+ interfaceName,
+ busName,
+ objectPath,
+ stubDBusConnection_,
+ stubDefault);
+ stubAdapter_->init();
+ }
-bool TestStubAdapter::onInterfaceDBusMessage(const CommonAPI::DBus::DBusMessage& dbusMessage) {
- return true;
-}
+ void deregisterTestStub() {
+ stubAdapter_->deinit();
+ stubAdapter_.reset();
-TestStubAdapter::TestStubAdapter(const std::shared_ptr<CommonAPI::DBus::DBusConnection>& dbusConnection) :
- CommonAPI::DBus::DBusStubAdapter(
- "com.bmw.test.Echo",
- "/com/bmw/test/Echo",
- "com.bmw.test.Echo",
- dbusConnection) {
-}
+ if (stubDBusConnection_->isConnected()) {
+ stubDBusConnection_->disconnect();
+ }
+ stubDBusConnection_.reset();
+ }
-TestProxy::TestProxy(const std::shared_ptr<CommonAPI::DBus::DBusConnection>& dbusConnection) :
- CommonAPI::DBus::DBusProxy(
- "com.bmw.test.Echo",
- "/com/bmw/test/Echo",
- "com.bmw.test.Echo",
- dbusConnection) {
-}
+ void proxyRegisterForAvailabilityStatus() {
+ proxyAvailabilityStatus_ = CommonAPI::AvailabilityStatus::UNKNOWN;
-void TestProxy::getOwnVersion(uint16_t& ownVersionMajor, uint16_t& ownVersionMinor) const {
-}
+ proxy_->getProxyStatusEvent().subscribe([&](const CommonAPI::AvailabilityStatus& availabilityStatus) {
+ proxyAvailabilityStatus_ = availabilityStatus;
+ });
+ }
+ bool proxyWaitForAvailabilityStatus(const CommonAPI::AvailabilityStatus& availabilityStatus) const {
+ std::chrono::milliseconds loopWaitDuration(100);
-const static std::string ID = "com.bmw.test.Echo";
+ if (proxyAvailabilityStatus_ == availabilityStatus)
+ return true;
+ for (int i = 0; i < 10; i++) {
+ std::this_thread::sleep_for(loopWaitDuration);
-class ProxyTest: public ::testing::Test {
-protected:
+ if (proxyAvailabilityStatus_ == availabilityStatus)
+ return true;
+ }
- virtual void TearDown() {
- dbusConnection_->disconnect();
+ return false;
}
- void SetUp() {
- dbusConnection_ = CommonAPI::DBus::DBusConnection::getSessionBus();
- ASSERT_TRUE(dbusConnection_->connect());
- proxy_ = std::make_shared<TestProxy>(dbusConnection_);
- }
+ std::shared_ptr<CommonAPI::DBus::DBusConnection> proxyDBusConnection_;
+ std::shared_ptr<commonapi::tests::TestInterfaceDBusProxy> proxy_;
+ CommonAPI::AvailabilityStatus proxyAvailabilityStatus_;
- std::shared_ptr<CommonAPI::DBus::DBusConnection> dbusConnection_;
- std::shared_ptr<TestProxy> proxy_;
+ std::shared_ptr<CommonAPI::DBus::DBusConnection> stubDBusConnection_;
+ std::shared_ptr<commonapi::tests::TestInterfaceDBusStubAdapter> stubAdapter_;
};
-TEST_F(ProxyTest, HasCorrectBusName) {
+TEST_F(ProxyTest, HasCorrectConnectionName) {
std::string actualName = proxy_->getDBusBusName();
- EXPECT_EQ("com.bmw.test.Echo", actualName);
+ EXPECT_EQ(busName, actualName);
}
TEST_F(ProxyTest, HasCorrectObjectPath) {
std::string actualPath = proxy_->getDBusObjectPath();
- EXPECT_EQ("/com/bmw/test/Echo", actualPath);
+ EXPECT_EQ(objectPath, actualPath);
}
TEST_F(ProxyTest, HasCorrectInterfaceName) {
std::string actualName = proxy_->getInterfaceName();
- EXPECT_EQ("com.bmw.test.Echo", actualName);
+ EXPECT_EQ(interfaceName, actualName);
}
TEST_F(ProxyTest, IsNotAvailable) {
@@ -110,30 +139,91 @@ TEST_F(ProxyTest, ServiceRegistry) {
ASSERT_FALSE(!registry);
}
+TEST_F(ProxyTest, DBusProxyStatusEventBeforeServiceIsRegistered) {
+ proxyRegisterForAvailabilityStatus();
+
+ EXPECT_NE(proxyAvailabilityStatus_, CommonAPI::AvailabilityStatus::AVAILABLE);
+
+ registerTestStub();
+
+ EXPECT_TRUE(proxyWaitForAvailabilityStatus(CommonAPI::AvailabilityStatus::AVAILABLE));
+
+ stubDBusConnection_->disconnect();
+
+ EXPECT_TRUE(proxyWaitForAvailabilityStatus(CommonAPI::AvailabilityStatus::NOT_AVAILABLE));
+
+ deregisterTestStub();
+}
+
+TEST_F(ProxyTest, DBusProxyStatusEventAfterServiceIsRegistered) {
+ proxyDBusConnection_->disconnect();
+
+ registerTestStub();
+
+ EXPECT_TRUE(proxyDBusConnection_->connect());
+
+ proxyRegisterForAvailabilityStatus();
+
+ EXPECT_TRUE(proxyWaitForAvailabilityStatus(CommonAPI::AvailabilityStatus::AVAILABLE));
+
+ stubDBusConnection_->disconnect();
+
+ EXPECT_TRUE(proxyWaitForAvailabilityStatus(CommonAPI::AvailabilityStatus::NOT_AVAILABLE));
+
+ deregisterTestStub();
+}
+
TEST_F(ProxyTest, ServiceStatus) {
- std::shared_ptr<TestStubAdapter> stub_ = std::make_shared<TestStubAdapter>(dbusConnection_);
- stub_->init();
- dbusConnection_->requestServiceNameAndBlock(ID);
+ registerTestStub();
- std::vector<std::string> actuallyAvailableServices;
+ std::vector<std::string> availableDBusServices;
+ for (int i = 0; i < 5; i++) {
+ availableDBusServices = proxyDBusConnection_->getDBusServiceRegistry()->getAvailableServiceInstances(
+ commonApiServiceName,
+ "local");
- actuallyAvailableServices = dbusConnection_->getDBusServiceRegistry()->getAvailableServiceInstances("com.bmw.test.Echo",
- "local");
+ if (!availableDBusServices.empty()) {
+ break;
+ }
+ }
+ sleep(1);
+ auto found = std::find(availableDBusServices.begin(), availableDBusServices.end(), commonApiAddress);
- std::string toFind = "com.bmw.test.Echo";
- auto found = std::find(actuallyAvailableServices.begin(), actuallyAvailableServices.end(), toFind);
+ EXPECT_TRUE(availableDBusServices.begin() != availableDBusServices.end());
+ EXPECT_TRUE(found != availableDBusServices.end());
- ASSERT_TRUE(actuallyAvailableServices.begin() != actuallyAvailableServices.end());
+ deregisterTestStub();
+}
+
+TEST_F(ProxyTest, isServiceInstanceAlive) {
+ registerTestStub();
+
+ bool isInstanceAlive = proxyDBusConnection_->getDBusServiceRegistry()->isServiceInstanceAlive(interfaceName, busName, objectPath);
+
+ for (int i = 0; !isInstanceAlive && i < 10; i++) {
+ std::this_thread::sleep_for(std::chrono::milliseconds(200));
+ isInstanceAlive = proxyDBusConnection_->getDBusServiceRegistry()->isServiceInstanceAlive(interfaceName, busName, objectPath);
+ }
+
+ EXPECT_TRUE(isInstanceAlive);
+
+ deregisterTestStub();
}
TEST_F(ProxyTest, IsAvailableBlocking) {
- std::shared_ptr<TestStubAdapter> stub = std::make_shared<TestStubAdapter>(dbusConnection_);
- stub->init();
- dbusConnection_->requestServiceNameAndBlock(ID);
+ registerTestStub();
+ // blocking in terms of "if it's still uknown"
bool isAvailable = proxy_->isAvailableBlocking();
+ for (int i = 0; !isAvailable && i < 10; i++) {
+ std::this_thread::sleep_for(std::chrono::milliseconds(200));
+ isAvailable = proxy_->isAvailableBlocking();
+ }
+
EXPECT_TRUE(isAvailable);
+
+ deregisterTestStub();
}
TEST_F(ProxyTest, HasNecessaryAttributesAndEvents) {
@@ -152,6 +242,21 @@ TEST_F(ProxyTest, TestInterfaceVersionAttribute) {
ASSERT_EQ(CommonAPI::CallStatus::NOT_AVAILABLE, status);
}
+TEST_F(ProxyTest, AsyncCallbacksAreCalledIfServiceNotAvailable) {
+ commonapi::tests::DerivedTypeCollection::TestEnumExtended2 testInputStruct;
+ commonapi::tests::DerivedTypeCollection::TestMap testInputMap;
+ bool wasCalled = false;
+ proxy_->testDerivedTypeMethodAsync(testInputStruct, testInputMap, [&] (const CommonAPI::CallStatus& callStatus,
+ const commonapi::tests::DerivedTypeCollection::TestEnumExtended2&,
+ const commonapi::tests::DerivedTypeCollection::TestMap&) {
+ ASSERT_EQ(callStatus, CommonAPI::CallStatus::NOT_AVAILABLE);
+ wasCalled = true;
+ }
+ );
+ sleep(1);
+ ASSERT_TRUE(wasCalled);
+}
+
int main(int argc, char** argv) {
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
diff --git a/src/test/DBusServiceRegistryTest.cpp b/src/test/DBusServiceRegistryTest.cpp
index 4281973..c6036eb 100644
--- a/src/test/DBusServiceRegistryTest.cpp
+++ b/src/test/DBusServiceRegistryTest.cpp
@@ -4,39 +4,271 @@
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+#ifndef _GLIBCXX_USE_NANOSLEEP
+#define _GLIBCXX_USE_NANOSLEEP
+#endif
+
#include <CommonAPI/Runtime.h>
+#include <CommonAPI/Factory.h>
+#include <CommonAPI/DBus/DBusServiceRegistry.h>
+#include <CommonAPI/DBus/DBusConnection.h>
+#include <CommonAPI/DBus/DBusUtils.h>
+
+#include <commonapi/tests/TestInterfaceStub.h>
+#include <commonapi/tests/TestInterfaceStubDefault.h>
+#include <commonapi/tests/TestInterfaceDBusStubAdapter.h>
+
+#include <gtest/gtest.h>
+
+
+// all predefinedInstances will be added for this service
+static const std::string dbusServiceName = "DBusServiceRegistryTest.Predefined.Service";
+
+// dbusInterfaceName, dbusObjectPath -> commonApiAddress
+static const std::unordered_map<std::pair<std::string, std::string>, std::string> predefinedInstancesMap = {
+ { { "tests.Interface1", "/tests/predefined/Object1" }, "local:Interface1:predefined.Instance1" },
+ { { "tests.Interface1", "/tests/predefined/Object2" }, "local:Interface1:predefined.Instance2" },
+ { { "tests.Interface2", "/tests/predefined/Object1" }, "local:Interface2:predefined.Instance" }
+};
+
+
+class Environment: public ::testing::Environment {
+public:
+ virtual ~Environment() {
+ }
+
+ virtual void SetUp() {
+ configFileName_ = CommonAPI::DBus::getCurrentBinaryFileFQN();
+ configFileName_ += CommonAPI::DBus::DBUS_CONFIG_SUFFIX;
+
+ std::ofstream configFile(configFileName_);
+ ASSERT_TRUE(configFile.is_open());
+
+ for (auto& predefinedInstance : predefinedInstancesMap) {
+ const std::string& dbusInterfaceName = predefinedInstance.first.first;
+ const std::string& dbusObjectPath = predefinedInstance.first.second;
+ const std::string& commonApiAddress = predefinedInstance.second;
+
+ configFile << "[" << commonApiAddress << "]\n";
+ configFile << "dbus_connection=" << dbusServiceName << std::endl;
+ configFile << "dbus_object=" << dbusObjectPath << std::endl;
+ configFile << "dbus_interface=" << dbusInterfaceName << std::endl;
+ configFile << "dbus_predefined=true\n";
+ configFile << std::endl;
+ }
+
+ configFile.close();
+ }
+
+ virtual void TearDown() {
+ std::remove(configFileName_.c_str());
+ }
+
+ std::string configFileName_;
+};
+
+
+class DBusServiceRegistryTest: public ::testing::Test {
+ protected:
+ virtual void SetUp() {
+ }
+
+ virtual void TearDown() {
+ }
+};
+
+
+TEST_F(DBusServiceRegistryTest, CanBeConstructed) {
+ std::shared_ptr<CommonAPI::DBus::DBusConnection> dbusConnection = CommonAPI::DBus::DBusConnection::getSessionBus();
+ CommonAPI::DBus::DBusServiceRegistry* registry = new CommonAPI::DBus::DBusServiceRegistry(dbusConnection);
+ ASSERT_TRUE(registry != NULL);
+}
+
+
+TEST_F(DBusServiceRegistryTest, DBusConnectionHasRegistry) {
+ auto dbusConnection = CommonAPI::DBus::DBusConnection::getSessionBus();
+ dbusConnection->connect();
+ auto serviceRegistry = dbusConnection->getDBusServiceRegistry();
+ ASSERT_FALSE(!serviceRegistry);
+}
+
+TEST_F(DBusServiceRegistryTest, DBusAddressTranslatorPredefinedWorks) {
+ std::vector<CommonAPI::DBus::DBusServiceAddress> loadedPredefinedInstances;
+
+ CommonAPI::DBus::DBusAddressTranslator::getInstance().getPredefinedInstances(dbusServiceName, loadedPredefinedInstances);
+
+ ASSERT_EQ(loadedPredefinedInstances.size(), predefinedInstancesMap.size());
+
+ for (auto& dbusServiceAddress : loadedPredefinedInstances) {
+ const std::string& loadedDBusServiceName = std::get<0>(dbusServiceAddress);
+ const std::string& loadedDBusObjectPath = std::get<1>(dbusServiceAddress);
+ const std::string& loadedDBusInterfaceName = std::get<2>(dbusServiceAddress);
+
+ ASSERT_EQ(loadedDBusServiceName, dbusServiceName);
+
+ auto predefinedInstanceIterator = predefinedInstancesMap.find({ loadedDBusInterfaceName, loadedDBusObjectPath });
+ const bool predefinedInstanceFound = (predefinedInstanceIterator != predefinedInstancesMap.end());
+
+ ASSERT_TRUE(predefinedInstanceFound);
+
+ const std::string& commonApiAddress = predefinedInstanceIterator->second;
+ const std::string& predefinedDBusInterfaceName = predefinedInstanceIterator->first.first;
+ const std::string& predefinedDBusObjectPath = predefinedInstanceIterator->first.second;
+
+ ASSERT_EQ(loadedDBusInterfaceName, predefinedDBusInterfaceName);
+ ASSERT_EQ(loadedDBusObjectPath, predefinedDBusObjectPath);
+
+ std::string foundDBusInterfaceName;
+ std::string foundDBusServiceName;
+ std::string foundDBusObjectPath;
+
+ CommonAPI::DBus::DBusAddressTranslator::getInstance().searchForDBusAddress(
+ commonApiAddress,
+ foundDBusInterfaceName,
+ foundDBusServiceName,
+ foundDBusObjectPath);
+
+ ASSERT_EQ(foundDBusInterfaceName, predefinedDBusInterfaceName);
+ ASSERT_EQ(foundDBusServiceName, dbusServiceName);
+ ASSERT_EQ(foundDBusObjectPath, predefinedDBusObjectPath);
+ }
+}
+
+TEST_F(DBusServiceRegistryTest, PredefinedInstances) {
+ auto stubDBusConnection = CommonAPI::DBus::DBusConnection::getSessionBus();
+
+ ASSERT_TRUE(stubDBusConnection->connect());
+ stubDBusConnection->requestServiceNameAndBlock(dbusServiceName);
+
+ auto proxyDBusConnection = CommonAPI::DBus::DBusConnection::getSessionBus();
+ auto dbusServiceRegistry = proxyDBusConnection->getDBusServiceRegistry();
+ std::unordered_map<std::string, std::promise<CommonAPI::AvailabilityStatus> > instanceStatusPromises;
+ std::unordered_map<std::string, CommonAPI::DBus::DBusServiceRegistry::Subscription> instanceSubscriptions;
+
+ for (auto& predefinedInstance : predefinedInstancesMap) {
+ const std::string& commonApiAddress = predefinedInstance.second;
+
+ instanceSubscriptions[commonApiAddress] = dbusServiceRegistry->subscribeAvailabilityListener(
+ commonApiAddress,
+ [&] (const CommonAPI::AvailabilityStatus& availabilityStatus) {
+ ASSERT_EQ(availabilityStatus, CommonAPI::AvailabilityStatus::AVAILABLE);
+ instanceStatusPromises[commonApiAddress].set_value(availabilityStatus);
+ });
+ }
+
+ ASSERT_TRUE(proxyDBusConnection->connect());
+
+ for (auto& predefinedInstance : predefinedInstancesMap) {
+ const std::string& dbusInterfaceName = predefinedInstance.first.first;
+ const std::string& dbusObjectPath = predefinedInstance.first.second;
+ const std::string& commonApiAddress = predefinedInstance.second;
+
+ auto instanceStatusFuture = instanceStatusPromises[commonApiAddress].get_future();
+ auto instanceStatusFutureStatus = instanceStatusFuture.wait_for(std::chrono::milliseconds(2000));
+ const bool instanceReady = CommonAPI::DBus::checkReady(instanceStatusFutureStatus);
+
+ ASSERT_TRUE(instanceReady);
+
+ std::promise<CommonAPI::AvailabilityStatus> postInstanceStatusPromise;
+ auto postInstanceSubscription = dbusServiceRegistry->subscribeAvailabilityListener(
+ commonApiAddress,
+ [&] (const CommonAPI::AvailabilityStatus& availabilityStatus) {
+ ASSERT_EQ(availabilityStatus, CommonAPI::AvailabilityStatus::AVAILABLE);
+ postInstanceStatusPromise.set_value(availabilityStatus);
+ });
+
+ auto postInstanceStatusFuture = postInstanceStatusPromise.get_future();
+ auto postInstanceStatusFutureStatus = postInstanceStatusFuture.wait_for(std::chrono::milliseconds(2000));
+ const bool postInstanceReady = CommonAPI::DBus::checkReady(postInstanceStatusFutureStatus);
+
+ ASSERT_TRUE(postInstanceReady);
+
+ dbusServiceRegistry->unsubscribeAvailabilityListener(commonApiAddress, postInstanceSubscription);
+ dbusServiceRegistry->unsubscribeAvailabilityListener(commonApiAddress, instanceSubscriptions[commonApiAddress]);
+
+
+ bool isInstanceAlive = dbusServiceRegistry->isServiceInstanceAlive(dbusInterfaceName, dbusServiceName, dbusObjectPath);
+ for (int i = 0; !isInstanceAlive && i < 5; i++) {
+ std::this_thread::sleep_for(std::chrono::milliseconds(500));
+ isInstanceAlive = dbusServiceRegistry->isServiceInstanceAlive(dbusInterfaceName, dbusServiceName, dbusObjectPath);
+ }
+
+ ASSERT_TRUE(isInstanceAlive);
+
+
+ std::vector<std::string> availableDBusServiceInstances = dbusServiceRegistry->getAvailableServiceInstances(dbusInterfaceName);
+ bool availableInstanceFound = false;
+
+ for (auto& availableInstance : availableDBusServiceInstances) {
+ if (availableInstance == commonApiAddress) {
+ availableInstanceFound = true;
+ break;
+ }
+ }
+
+ ASSERT_TRUE(availableInstanceFound);
+ }
+}
+
+
+class DBusServiceRegistryTestWithPredefinedRemote: public ::testing::Test {
+ protected:
+ virtual void SetUp() {
+ dbusConnection_ = CommonAPI::DBus::DBusConnection::getSessionBus();
+ dbusServiceRegistry_ = dbusConnection_->getDBusServiceRegistry();
+ dbusConnection_->connect();
+
+ dbusStubConnection_ = CommonAPI::DBus::DBusConnection::getSessionBus();
+ dbusStubConnection_->connect();
+
+ auto stub = std::make_shared<commonapi::tests::TestInterfaceStubDefault>();
+
+ dbusStubConnection_->requestServiceNameAndBlock("test.instance.name");
+ stubAdapter_ = std::make_shared<commonapi::tests::TestInterfaceDBusStubAdapter>(
+ "local:test.service.name:test.instance.name",
+ "test.service.name",
+ "test.instance.name",
+ "/test/instance/name",
+ dbusStubConnection_,
+ stub);
+ stubAdapter_->init();
+ }
+
+ virtual void TearDown() {
+ stubAdapter_->deinit();
+ }
+
+ std::shared_ptr<CommonAPI::DBus::DBusConnection> dbusConnection_;
+ std::shared_ptr<CommonAPI::DBus::DBusConnection> dbusStubConnection_;
+ std::shared_ptr<CommonAPI::DBus::DBusServiceRegistry> dbusServiceRegistry_;
+
+ std::shared_ptr<commonapi::tests::TestInterfaceDBusStubAdapter> stubAdapter_;
+};
+
+
+TEST_F(DBusServiceRegistryTestWithPredefinedRemote, RecognizesCommonAPIDBusServiceInstanceAsAlive) {
+ sleep(1);
+ ASSERT_TRUE(dbusServiceRegistry_->isServiceInstanceAlive("test.service.name", "test.instance.name", "/test/instance/name"));
+}
+
+
+TEST_F(DBusServiceRegistryTestWithPredefinedRemote, FindsCommonAPIDBusServiceInstance) {
+ sleep(1);
+ auto availableServices = dbusServiceRegistry_->getAvailableServiceInstances("test.service.name", "local");
+ ASSERT_EQ(1, availableServices.size());
+ bool serviceFound;
+ for(auto it = availableServices.begin(); it != availableServices.end(); ++it) {
+ if(*it == "local:test.service.name:test.instance.name") {
+ serviceFound = true;
+ }
+ }
+ ASSERT_TRUE(serviceFound);
+}
-//#define ASSERT_DBUSMESSAGE_EQ(_dbusMessage1, _dbusMessage2) \
-// ASSERT_FALSE(_dbusMessage1.getSignatureString() == NULL); \
-// ASSERT_FALSE(_dbusMessage2.getSignatureString() == NULL); \
-// ASSERT_STREQ(_dbusMessage1.getSignatureString(), _dbusMessage2.getSignatureString()); \
-// ASSERT_EQ(_dbusMessage1.getBodyLength(), _dbusMessage2.getBodyLength()); \
-// ASSERT_FALSE(_dbusMessage1.getBodyData() == NULL); \
-// ASSERT_FALSE(_dbusMessage2.getBodyData() == NULL); \
-// ASSERT_EQ(memcmp(_dbusMessage1.getBodyData(), _dbusMessage2.getBodyData(), _dbusMessage1.getBodyLength()), 0)
-//
-//
-//namespace {
-//
-//class DBusConnectionTest: public ::testing::Test {
-// protected:
-// virtual void SetUp() {
-// }
-//
-// virtual void TearDown() {
-// }
-//};
-//
-//
-//TEST_F(DBusConnectionTest, CanBeConstructed) {
-// std::shared_ptr<CommonAPI::Runtime> runtime = CommonAPI::Runtime::load("");
-// std::shared_ptr<CommonAPI::ProxyFactory> proxyFactory_ = runtime->createProxyFactory();
-//}
-//
-//}
-
-
-int main() {
+int main(int argc, char** argv) {
+ ::testing::InitGoogleTest(&argc, argv);
+ ::testing::AddGlobalTestEnvironment(new Environment());
+ return RUN_ALL_TESTS();
}
diff --git a/src/test/DBusStubAdapterTest.cpp b/src/test/DBusStubAdapterTest.cpp
index 4106bd1..984132b 100644
--- a/src/test/DBusStubAdapterTest.cpp
+++ b/src/test/DBusStubAdapterTest.cpp
@@ -98,11 +98,13 @@ typedef CommonAPI::DBus::DBusStubAdapterHelper<TestStub> TestStubAdapterHelper;
class TestDBusStubAdapter: public TestStubAdapter, public TestStubAdapterHelper {
public:
- TestDBusStubAdapter(const std::string& dbusBusName,
- const std::string& dbusObjectPath,
- const std::shared_ptr<CommonAPI::DBus::DBusConnection>& dbusConnection,
- const std::shared_ptr<TestStub>& testStub) :
+ TestDBusStubAdapter(const std::string& commonApiAddress,
+ const std::string& dbusBusName,
+ const std::string& dbusObjectPath,
+ const std::shared_ptr<CommonAPI::DBus::DBusConnection>& dbusConnection,
+ const std::shared_ptr<TestStub>& testStub) :
TestStubAdapterHelper(
+ commonApiAddress,
dbusBusName,
dbusObjectPath,
"org.genivi.CommonAPI.DBus.TestInterface",
@@ -197,6 +199,7 @@ int main(void) {
auto testStub = std::make_shared<TestStub>();
auto testStubAdapter = std::make_shared<TestDBusStubAdapter>(
+ "my:common.api:address.for.dbus",
"org.genivi.CommonAPI.DBus.TestDBusInterfaceAdapter",
"/common/api/dbus/TestDBusInterfaceAdapter",
dbusConnection,
@@ -212,11 +215,9 @@ int main(void) {
const bool messageSent = dbusConnection->sendDBusMessage(dbusMessageCall);
assert(messageSent);
- for (int i = 0; i < 10; i++)
+ for (int i = 0; i < 10; i++) {
dbusConnection->readWriteDispatch(100);
-
-// while (dbusConnection->readWriteDispatch(100))
-// ;
+ }
assert(dispatchedMessageCount > 0);
diff --git a/src/test/DBusTestUtils.h b/src/test/DBusTestUtils.h
index 945813c..8b0cbf9 100644
--- a/src/test/DBusTestUtils.h
+++ b/src/test/DBusTestUtils.h
@@ -12,17 +12,23 @@ inline char eliminateZeroes(char val) {
return !val ? '0' : val;
}
+
+inline void printLibdbusMessageBody(char* data, uint32_t fromByteIndex, uint32_t toByteIndex) {
+ for(int i = fromByteIndex; i < toByteIndex; i++) {
+ std::cout << eliminateZeroes(data[i]);
+ if(i%8 == 7) {
+ std::cout << std::endl;
+ }
+ }
+ std::cout << std::endl;
+}
+
inline void printLibdbusMessage(DBusMessage* libdbusMessage, uint32_t fromByteIndex, uint32_t toByteIndex) {
char* data = dbus_message_get_body(libdbusMessage);
- for(int i = fromByteIndex; i < toByteIndex; i++) {
- std::cout << eliminateZeroes(data[i]);
- if(i%8 == 7) {
- std::cout << std::endl;
- }
- }
- std::cout << std::endl;
+ printLibdbusMessageBody(data, fromByteIndex, toByteIndex);
}
inline void printLibdbusMessage(DBusMessage* libdbusMessage) {
printLibdbusMessage(libdbusMessage, 0, dbus_message_get_body_length(libdbusMessage));
}
+
diff --git a/src/test/commonapi/tests/DerivedTypeCollection.cpp b/src/test/commonapi/tests/DerivedTypeCollection.cpp
index 9087e4d..1ad1cce 100644
--- a/src/test/commonapi/tests/DerivedTypeCollection.cpp
+++ b/src/test/commonapi/tests/DerivedTypeCollection.cpp
@@ -7,55 +7,59 @@ namespace commonapi {
namespace tests {
namespace DerivedTypeCollection {
-TestStruct::TestStruct(const PredefinedTypeCollection::TestString& testStringValue, const uint16_t& uintValueValue):
- testString(testStringValue),
- uintValue(uintValueValue)
+TestStructExtended::TestStructExtended(const PredefinedTypeCollection::TestString& testStringValue, const uint16_t& uintValueValue, const TestEnumExtended2& testEnumExtended2Value, const PredefinedTypeCollection::WeirdStrangeAlienEnum& alienEnumValue):
+ TestStruct(testStringValue, uintValueValue),
+ testEnumExtended2(testEnumExtended2Value),
+ alienEnum(alienEnumValue)
{
}
-bool operator==(const TestStruct& lhs, const TestStruct& rhs) {
+bool operator==(const TestStructExtended& lhs, const TestStructExtended& rhs) {
if (&lhs == &rhs)
return true;
return
- lhs.testString == rhs.testString &&
- lhs.uintValue == rhs.uintValue
+ static_cast<TestStructExtended::TestStruct>(lhs) == static_cast<TestStructExtended::TestStruct>(rhs) &&
+ lhs.testEnumExtended2 == rhs.testEnumExtended2 &&
+ lhs.alienEnum == rhs.alienEnum
;
}
-void TestStruct::readFromInputStream(CommonAPI::InputStream& inputStream) {
- inputStream >> testString;
- inputStream >> uintValue;
+void TestStructExtended::readFromInputStream(CommonAPI::InputStream& inputStream) {
+ TestStruct::readFromInputStream(inputStream);
+ inputStream >> testEnumExtended2;
+ inputStream >> alienEnum;
}
-void TestStruct::writeToOutputStream(CommonAPI::OutputStream& outputStream) const {
- outputStream << testString;
- outputStream << uintValue;
+void TestStructExtended::writeToOutputStream(CommonAPI::OutputStream& outputStream) const {
+ TestStruct::writeToOutputStream(outputStream);
+ outputStream << testEnumExtended2;
+ outputStream << alienEnum;
}
-TestStructExtended::TestStructExtended(const PredefinedTypeCollection::TestString& testStringValue, const uint16_t& uintValueValue, const TestEnumExtended2& testEnumExtended2Value):
- TestStruct(testStringValue, uintValueValue),
- testEnumExtended2(testEnumExtended2Value)
+TestStruct::TestStruct(const PredefinedTypeCollection::TestString& testStringValue, const uint16_t& uintValueValue):
+ testString(testStringValue),
+ uintValue(uintValueValue)
{
}
-bool operator==(const TestStructExtended& lhs, const TestStructExtended& rhs) {
+bool operator==(const TestStruct& lhs, const TestStruct& rhs) {
if (&lhs == &rhs)
return true;
return
- static_cast<TestStructExtended::TestStruct>(lhs) == static_cast<TestStructExtended::TestStruct>(rhs) &&
- lhs.testEnumExtended2 == rhs.testEnumExtended2
+ lhs.testString == rhs.testString &&
+ lhs.uintValue == rhs.uintValue
;
}
-void TestStructExtended::readFromInputStream(CommonAPI::InputStream& inputStream) {
- TestStruct::readFromInputStream(inputStream);
- inputStream >> testEnumExtended2;
+void TestStruct::readFromInputStream(CommonAPI::InputStream& inputStream) {
+ inputStream >> testString;
+ inputStream >> uintValue;
}
-void TestStructExtended::writeToOutputStream(CommonAPI::OutputStream& outputStream) const {
- TestStruct::writeToOutputStream(outputStream);
- outputStream << testEnumExtended2;
+void TestStruct::writeToOutputStream(CommonAPI::OutputStream& outputStream) const {
+ outputStream << testString;
+ outputStream << uintValue;
}
} // namespace DerivedTypeCollection
diff --git a/src/test/commonapi/tests/DerivedTypeCollection.h b/src/test/commonapi/tests/DerivedTypeCollection.h
index 2cb2e70..b1cd43f 100644
--- a/src/test/commonapi/tests/DerivedTypeCollection.h
+++ b/src/test/commonapi/tests/DerivedTypeCollection.h
@@ -7,11 +7,9 @@
#include <CommonAPI/InputStream.h>
#include <CommonAPI/OutputStream.h>
#include <CommonAPI/SerializableStruct.h>
-#include <CommonAPI/SerializableVariant.h>
#include <CommonAPI/types.h>
-#include <test/commonapi/tests/PredefinedTypeCollection.h>
+#include "PredefinedTypeCollection.h"
#include <cstdint>
-#include <memory>
#include <string>
#include <unordered_map>
#include <vector>
@@ -20,95 +18,87 @@ namespace commonapi {
namespace tests {
namespace DerivedTypeCollection {
-
-enum class TestEnum: int32_t {
- E_UNKNOWN = 0,
- E_OK = 1,
- E_OUT_OF_RANGE = 2,
- E_NOT_USED = 3
-};
-
-// XXX Definition of a comparator still is necessary for GCC 4.4.1, topic is fixed since 4.5.1
-struct TestEnumComparator;
-
-enum class TestEnumMissingValue: int32_t {
- E1 = 10,
- E2,
- E3 = 2
-};
-
-// XXX Definition of a comparator still is necessary for GCC 4.4.1, topic is fixed since 4.5.1
-struct TestEnumMissingValueComparator;
-
-enum class TestEnumExtended: int32_t {
- E_UNKNOWN = TestEnum::E_UNKNOWN,
- E_OK = TestEnum::E_OK,
- E_OUT_OF_RANGE = TestEnum::E_OUT_OF_RANGE,
- E_NOT_USED = TestEnum::E_NOT_USED
- ,
- E_NEW = 4
-};
-
-// XXX Definition of a comparator still is necessary for GCC 4.4.1, topic is fixed since 4.5.1
-struct TestEnumExtendedComparator;
-
-enum class TestEnumExtended2: int32_t {
- E_UNKNOWN = TestEnum::E_UNKNOWN,
- E_OK = TestEnum::E_OK,
- E_OUT_OF_RANGE = TestEnum::E_OUT_OF_RANGE,
- E_NOT_USED = TestEnum::E_NOT_USED,
+ enum class TestEnum: int32_t {
+ E_UNKNOWN = 0,
+ E_OK = 1,
+ E_OUT_OF_RANGE = 2,
+ E_NOT_USED = 3
+ };
- E_NEW = TestEnumExtended::E_NEW
- ,
- E_NEW2 = 5
-};
-
-// XXX Definition of a comparator still is necessary for GCC 4.4.1, topic is fixed since 4.5.1
-struct TestEnumExtended2Comparator;
-
-struct TestStruct: CommonAPI::SerializableStruct {
- PredefinedTypeCollection::TestString testString;
- uint16_t uintValue;
-
- TestStruct() = default;
- TestStruct(const PredefinedTypeCollection::TestString& testString, const uint16_t& uintValue);
-
- virtual void readFromInputStream(CommonAPI::InputStream& inputStream);
- virtual void writeToOutputStream(CommonAPI::OutputStream& outputStream) const;
-
- static inline void writeToTypeOutputStream(CommonAPI::TypeOutputStream& typeOutputStream) {
- typeOutputStream.writeStringType();
- typeOutputStream.writeUInt16Type();
- }
-};
-
-struct TestStructExtended: TestStruct {
- TestEnumExtended2 testEnumExtended2;
-
- TestStructExtended() = default;
- TestStructExtended(const PredefinedTypeCollection::TestString& testString, const uint16_t& uintValue, const TestEnumExtended2& testEnumExtended2);
-
- virtual void readFromInputStream(CommonAPI::InputStream& inputStream);
- virtual void writeToOutputStream(CommonAPI::OutputStream& outputStream) const;
-
- static inline void writeToTypeOutputStream(CommonAPI::TypeOutputStream& typeOutputStream) {
-TestStruct::writeToTypeOutputStream(typeOutputStream);
- typeOutputStream.writeInt32Type();
- }
-};
-
-typedef std::vector<uint64_t> TestArrayUInt64;
-
-typedef std::vector<TestStruct> TestArrayTestStruct;
-
-typedef std::unordered_map<uint32_t, TestArrayTestStruct> TestMap;
-
-typedef CommonAPI::Variant<double, int16_t, std::string> TestUnionIn;
-
-typedef CommonAPI::Variant<TestEnumExtended, double, int16_t, std::string> TestUnionOut;
-
-typedef CommonAPI::Variant<TestEnum, TestEnumExtended, double, int16_t, std::string> TestUnionReallyExtended;
+ // XXX Definition of a comparator still is necessary for GCC 4.4.1, topic is fixed since 4.5.1
+ struct TestEnumComparator;
+ enum class TestEnumExtended: int32_t {
+ E_UNKNOWN = TestEnum::E_UNKNOWN,
+ E_OK = TestEnum::E_OK,
+ E_OUT_OF_RANGE = TestEnum::E_OUT_OF_RANGE,
+ E_NOT_USED = TestEnum::E_NOT_USED
+ ,
+ E_NEW = 4
+ };
+
+ // XXX Definition of a comparator still is necessary for GCC 4.4.1, topic is fixed since 4.5.1
+ struct TestEnumExtendedComparator;
+ typedef std::unordered_map<TestEnum, std::string> TestEnumMap;
+ struct TestStruct: CommonAPI::SerializableStruct {
+ PredefinedTypeCollection::TestString testString;
+ uint16_t uintValue;
+
+ TestStruct() = default;
+ TestStruct(const PredefinedTypeCollection::TestString& testString, const uint16_t& uintValue);
+
+ virtual void readFromInputStream(CommonAPI::InputStream& inputStream);
+ virtual void writeToOutputStream(CommonAPI::OutputStream& outputStream) const;
+
+ static inline void writeToTypeOutputStream(CommonAPI::TypeOutputStream& typeOutputStream) {
+ typeOutputStream.writeStringType();
+ typeOutputStream.writeUInt16Type();
+ }
+ };
+ typedef std::vector<TestStruct> TestArrayTestStruct;
+ enum class TestEnumExtended2: int32_t {
+ E_UNKNOWN = TestEnum::E_UNKNOWN,
+ E_OK = TestEnum::E_OK,
+ E_OUT_OF_RANGE = TestEnum::E_OUT_OF_RANGE,
+ E_NOT_USED = TestEnum::E_NOT_USED,
+
+ E_NEW = TestEnumExtended::E_NEW
+ ,
+ E_NEW2 = 5
+ };
+
+ // XXX Definition of a comparator still is necessary for GCC 4.4.1, topic is fixed since 4.5.1
+ struct TestEnumExtended2Comparator;
+ struct TestStructExtended: TestStruct {
+ TestEnumExtended2 testEnumExtended2;
+ PredefinedTypeCollection::WeirdStrangeAlienEnum alienEnum;
+
+ TestStructExtended() = default;
+ TestStructExtended(const PredefinedTypeCollection::TestString& testString, const uint16_t& uintValue, const TestEnumExtended2& testEnumExtended2, const PredefinedTypeCollection::WeirdStrangeAlienEnum& alienEnum);
+
+ virtual void readFromInputStream(CommonAPI::InputStream& inputStream);
+ virtual void writeToOutputStream(CommonAPI::OutputStream& outputStream) const;
+
+ static inline void writeToTypeOutputStream(CommonAPI::TypeOutputStream& typeOutputStream) {
+ TestStruct::writeToTypeOutputStream(typeOutputStream);
+ typeOutputStream.writeInt32Type();
+ typeOutputStream.writeInt32Type();
+ }
+ };
+ typedef std::unordered_map<uint32_t, TestArrayTestStruct> TestMap;
+ enum class TestEnumMissingValue: int32_t {
+ E1 = 10,
+ E2,
+ E3 = 2
+ };
+
+ // XXX Definition of a comparator still is necessary for GCC 4.4.1, topic is fixed since 4.5.1
+ struct TestEnumMissingValueComparator;
+ typedef std::vector<uint64_t> TestArrayUInt64;
+bool operator==(const TestStructExtended& lhs, const TestStructExtended& rhs);
+inline bool operator!=(const TestStructExtended& lhs, const TestStructExtended& rhs) {
+ return !(lhs == rhs);
+}
inline CommonAPI::InputStream& operator>>(CommonAPI::InputStream& inputStream, TestEnum& enumValue) {
return inputStream.readEnumValue<int32_t>(enumValue);
}
@@ -123,95 +113,91 @@ struct TestEnumComparator {
}
};
-inline CommonAPI::InputStream& operator>>(CommonAPI::InputStream& inputStream, TestEnumMissingValue& enumValue) {
+inline CommonAPI::InputStream& operator>>(CommonAPI::InputStream& inputStream, TestEnumExtended2& enumValue) {
return inputStream.readEnumValue<int32_t>(enumValue);
}
-inline CommonAPI::OutputStream& operator<<(CommonAPI::OutputStream& outputStream, const TestEnumMissingValue& enumValue) {
+inline CommonAPI::OutputStream& operator<<(CommonAPI::OutputStream& outputStream, const TestEnumExtended2& enumValue) {
return outputStream.writeEnumValue(static_cast<int32_t>(enumValue));
}
-struct TestEnumMissingValueComparator {
- inline bool operator()(const TestEnumMissingValue& lhs, const TestEnumMissingValue& rhs) const {
+struct TestEnumExtended2Comparator {
+ inline bool operator()(const TestEnumExtended2& lhs, const TestEnumExtended2& rhs) const {
return static_cast<int32_t>(lhs) < static_cast<int32_t>(rhs);
}
};
-inline CommonAPI::InputStream& operator>>(CommonAPI::InputStream& inputStream, TestEnumExtended& enumValue) {
- return inputStream.readEnumValue<int32_t>(enumValue);
-}
-inline CommonAPI::OutputStream& operator<<(CommonAPI::OutputStream& outputStream, const TestEnumExtended& enumValue) {
- return outputStream.writeEnumValue(static_cast<int32_t>(enumValue));
+inline bool operator==(const TestEnumExtended2& lhs, const TestEnum& rhs) {
+ return static_cast<int32_t>(lhs) == static_cast<int32_t>(rhs);
+}
+inline bool operator==(const TestEnum& lhs, const TestEnumExtended2& rhs) {
+ return static_cast<int32_t>(lhs) == static_cast<int32_t>(rhs);
+}
+inline bool operator!=(const TestEnumExtended2& lhs, const TestEnum& rhs) {
+ return static_cast<int32_t>(lhs) != static_cast<int32_t>(rhs);
+}
+inline bool operator!=(const TestEnum& lhs, const TestEnumExtended2& rhs) {
+ return static_cast<int32_t>(lhs) != static_cast<int32_t>(rhs);
}
-struct TestEnumExtendedComparator {
- inline bool operator()(const TestEnumExtended& lhs, const TestEnumExtended& rhs) const {
- return static_cast<int32_t>(lhs) < static_cast<int32_t>(rhs);
- }
-};
-
-
-inline bool operator==(const TestEnumExtended& lhs, const TestEnum& rhs) {
+inline bool operator==(const TestEnumExtended2& lhs, const TestEnumExtended& rhs) {
return static_cast<int32_t>(lhs) == static_cast<int32_t>(rhs);
}
-inline bool operator==(const TestEnum& lhs, const TestEnumExtended& rhs) {
+inline bool operator==(const TestEnumExtended& lhs, const TestEnumExtended2& rhs) {
return static_cast<int32_t>(lhs) == static_cast<int32_t>(rhs);
}
-inline bool operator!=(const TestEnumExtended& lhs, const TestEnum& rhs) {
+inline bool operator!=(const TestEnumExtended2& lhs, const TestEnumExtended& rhs) {
return static_cast<int32_t>(lhs) != static_cast<int32_t>(rhs);
}
-inline bool operator!=(const TestEnum& lhs, const TestEnumExtended& rhs) {
+inline bool operator!=(const TestEnumExtended& lhs, const TestEnumExtended2& rhs) {
return static_cast<int32_t>(lhs) != static_cast<int32_t>(rhs);
}
-inline CommonAPI::InputStream& operator>>(CommonAPI::InputStream& inputStream, TestEnumExtended2& enumValue) {
+inline CommonAPI::InputStream& operator>>(CommonAPI::InputStream& inputStream, TestEnumMissingValue& enumValue) {
return inputStream.readEnumValue<int32_t>(enumValue);
}
-inline CommonAPI::OutputStream& operator<<(CommonAPI::OutputStream& outputStream, const TestEnumExtended2& enumValue) {
+inline CommonAPI::OutputStream& operator<<(CommonAPI::OutputStream& outputStream, const TestEnumMissingValue& enumValue) {
return outputStream.writeEnumValue(static_cast<int32_t>(enumValue));
}
-struct TestEnumExtended2Comparator {
- inline bool operator()(const TestEnumExtended2& lhs, const TestEnumExtended2& rhs) const {
+struct TestEnumMissingValueComparator {
+ inline bool operator()(const TestEnumMissingValue& lhs, const TestEnumMissingValue& rhs) const {
return static_cast<int32_t>(lhs) < static_cast<int32_t>(rhs);
}
};
-
-inline bool operator==(const TestEnumExtended2& lhs, const TestEnum& rhs) {
- return static_cast<int32_t>(lhs) == static_cast<int32_t>(rhs);
-}
-inline bool operator==(const TestEnum& lhs, const TestEnumExtended2& rhs) {
- return static_cast<int32_t>(lhs) == static_cast<int32_t>(rhs);
-}
-inline bool operator!=(const TestEnumExtended2& lhs, const TestEnum& rhs) {
- return static_cast<int32_t>(lhs) != static_cast<int32_t>(rhs);
+inline CommonAPI::InputStream& operator>>(CommonAPI::InputStream& inputStream, TestEnumExtended& enumValue) {
+ return inputStream.readEnumValue<int32_t>(enumValue);
}
-inline bool operator!=(const TestEnum& lhs, const TestEnumExtended2& rhs) {
- return static_cast<int32_t>(lhs) != static_cast<int32_t>(rhs);
+
+inline CommonAPI::OutputStream& operator<<(CommonAPI::OutputStream& outputStream, const TestEnumExtended& enumValue) {
+ return outputStream.writeEnumValue(static_cast<int32_t>(enumValue));
}
-inline bool operator==(const TestEnumExtended2& lhs, const TestEnumExtended& rhs) {
+struct TestEnumExtendedComparator {
+ inline bool operator()(const TestEnumExtended& lhs, const TestEnumExtended& rhs) const {
+ return static_cast<int32_t>(lhs) < static_cast<int32_t>(rhs);
+ }
+};
+
+
+inline bool operator==(const TestEnumExtended& lhs, const TestEnum& rhs) {
return static_cast<int32_t>(lhs) == static_cast<int32_t>(rhs);
}
-inline bool operator==(const TestEnumExtended& lhs, const TestEnumExtended2& rhs) {
+inline bool operator==(const TestEnum& lhs, const TestEnumExtended& rhs) {
return static_cast<int32_t>(lhs) == static_cast<int32_t>(rhs);
}
-inline bool operator!=(const TestEnumExtended2& lhs, const TestEnumExtended& rhs) {
+inline bool operator!=(const TestEnumExtended& lhs, const TestEnum& rhs) {
return static_cast<int32_t>(lhs) != static_cast<int32_t>(rhs);
}
-inline bool operator!=(const TestEnumExtended& lhs, const TestEnumExtended2& rhs) {
+inline bool operator!=(const TestEnum& lhs, const TestEnumExtended& rhs) {
return static_cast<int32_t>(lhs) != static_cast<int32_t>(rhs);
}
bool operator==(const TestStruct& lhs, const TestStruct& rhs);
inline bool operator!=(const TestStruct& lhs, const TestStruct& rhs) {
return !(lhs == rhs);
}
-bool operator==(const TestStructExtended& lhs, const TestStructExtended& rhs);
-inline bool operator!=(const TestStructExtended& lhs, const TestStructExtended& rhs) {
- return !(lhs == rhs);
-}
static inline const char* getTypeCollectionName() {
@@ -247,185 +233,94 @@ namespace CommonAPI {
}
};
template<>
- struct BasicTypeWriter<commonapi::tests::DerivedTypeCollection::TestEnumMissingValue> {
+ struct BasicTypeWriter<commonapi::tests::DerivedTypeCollection::TestEnumExtended2> {
inline static void writeType (CommonAPI::TypeOutputStream& typeStream) {
typeStream.writeInt32EnumType();
}
};
template<>
- struct InputStreamVectorHelper<commonapi::tests::DerivedTypeCollection::TestEnumMissingValue> {
- static void beginReadVector(InputStream& inputStream, const std::vector<commonapi::tests::DerivedTypeCollection::TestEnumMissingValue>& vectorValue) {
+ struct InputStreamVectorHelper<commonapi::tests::DerivedTypeCollection::TestEnumExtended2> {
+ static void beginReadVector(InputStream& inputStream, const std::vector<commonapi::tests::DerivedTypeCollection::TestEnumExtended2>& vectorValue) {
inputStream.beginReadInt32EnumVector();
}
};
template <>
- struct OutputStreamVectorHelper<commonapi::tests::DerivedTypeCollection::TestEnumMissingValue> {
- static void beginWriteVector(OutputStream& outputStream, const std::vector<commonapi::tests::DerivedTypeCollection::TestEnumMissingValue>& vectorValue) {
+ struct OutputStreamVectorHelper<commonapi::tests::DerivedTypeCollection::TestEnumExtended2> {
+ static void beginWriteVector(OutputStream& outputStream, const std::vector<commonapi::tests::DerivedTypeCollection::TestEnumExtended2>& vectorValue) {
outputStream.beginWriteInt32EnumVector(vectorValue.size());
}
};
template<>
- struct BasicTypeWriter<commonapi::tests::DerivedTypeCollection::TestEnumExtended> {
+ struct BasicTypeWriter<commonapi::tests::DerivedTypeCollection::TestEnumMissingValue> {
inline static void writeType (CommonAPI::TypeOutputStream& typeStream) {
typeStream.writeInt32EnumType();
}
};
template<>
- struct InputStreamVectorHelper<commonapi::tests::DerivedTypeCollection::TestEnumExtended> {
- static void beginReadVector(InputStream& inputStream, const std::vector<commonapi::tests::DerivedTypeCollection::TestEnumExtended>& vectorValue) {
+ struct InputStreamVectorHelper<commonapi::tests::DerivedTypeCollection::TestEnumMissingValue> {
+ static void beginReadVector(InputStream& inputStream, const std::vector<commonapi::tests::DerivedTypeCollection::TestEnumMissingValue>& vectorValue) {
inputStream.beginReadInt32EnumVector();
}
};
template <>
- struct OutputStreamVectorHelper<commonapi::tests::DerivedTypeCollection::TestEnumExtended> {
- static void beginWriteVector(OutputStream& outputStream, const std::vector<commonapi::tests::DerivedTypeCollection::TestEnumExtended>& vectorValue) {
+ struct OutputStreamVectorHelper<commonapi::tests::DerivedTypeCollection::TestEnumMissingValue> {
+ static void beginWriteVector(OutputStream& outputStream, const std::vector<commonapi::tests::DerivedTypeCollection::TestEnumMissingValue>& vectorValue) {
outputStream.beginWriteInt32EnumVector(vectorValue.size());
}
};
template<>
- struct BasicTypeWriter<commonapi::tests::DerivedTypeCollection::TestEnumExtended2> {
+ struct BasicTypeWriter<commonapi::tests::DerivedTypeCollection::TestEnumExtended> {
inline static void writeType (CommonAPI::TypeOutputStream& typeStream) {
typeStream.writeInt32EnumType();
}
};
template<>
- struct InputStreamVectorHelper<commonapi::tests::DerivedTypeCollection::TestEnumExtended2> {
- static void beginReadVector(InputStream& inputStream, const std::vector<commonapi::tests::DerivedTypeCollection::TestEnumExtended2>& vectorValue) {
+ struct InputStreamVectorHelper<commonapi::tests::DerivedTypeCollection::TestEnumExtended> {
+ static void beginReadVector(InputStream& inputStream, const std::vector<commonapi::tests::DerivedTypeCollection::TestEnumExtended>& vectorValue) {
inputStream.beginReadInt32EnumVector();
}
};
template <>
- struct OutputStreamVectorHelper<commonapi::tests::DerivedTypeCollection::TestEnumExtended2> {
- static void beginWriteVector(OutputStream& outputStream, const std::vector<commonapi::tests::DerivedTypeCollection::TestEnumExtended2>& vectorValue) {
+ struct OutputStreamVectorHelper<commonapi::tests::DerivedTypeCollection::TestEnumExtended> {
+ static void beginWriteVector(OutputStream& outputStream, const std::vector<commonapi::tests::DerivedTypeCollection::TestEnumExtended>& vectorValue) {
outputStream.beginWriteInt32EnumVector(vectorValue.size());
}
};
- inline bool operator==(
- const commonapi::tests::DerivedTypeCollection::TestUnionOut& lhs,
- const commonapi::tests::DerivedTypeCollection::TestUnionIn& rhs) {
- if (lhs.getValueType() == rhs.getValueType()) {
- if (rhs.getValueType() == 1) {
- std::string a = lhs.get<std::string>();
- std::string b = rhs.get<std::string>();
- return (a == b);
- } else if (rhs.getValueType() == 2) {
- int16_t a = lhs.get<int16_t>();
- int16_t b = rhs.get<int16_t>();
- return (a == b);
- } else if (rhs.getValueType() == 3) {
- double a = lhs.get<double>();
- double b = rhs.get<double>();
- return (a == b);
- }
- }
- return false;
- }
-
- inline bool operator==(
- const commonapi::tests::DerivedTypeCollection::TestUnionIn& lhs,
- const commonapi::tests::DerivedTypeCollection::TestUnionOut& rhs) {
- return rhs == lhs;
- }
-
- inline bool operator!=(
- const commonapi::tests::DerivedTypeCollection::TestUnionOut& lhs,
- const commonapi::tests::DerivedTypeCollection::TestUnionIn& rhs) {
- return lhs != rhs;
- }
-
- inline bool operator!=(
- const commonapi::tests::DerivedTypeCollection::TestUnionIn& lhs,
- const commonapi::tests::DerivedTypeCollection::TestUnionOut& rhs) {
- return lhs != rhs;
- }
- inline bool operator==(
- const commonapi::tests::DerivedTypeCollection::TestUnionReallyExtended& lhs,
- const commonapi::tests::DerivedTypeCollection::TestUnionIn& rhs) {
- if (lhs.getValueType() == rhs.getValueType()) {
- if (rhs.getValueType() == 1) {
- std::string a = lhs.get<std::string>();
- std::string b = rhs.get<std::string>();
- return (a == b);
- } else if (rhs.getValueType() == 2) {
- int16_t a = lhs.get<int16_t>();
- int16_t b = rhs.get<int16_t>();
- return (a == b);
- } else if (rhs.getValueType() == 3) {
- double a = lhs.get<double>();
- double b = rhs.get<double>();
- return (a == b);
- }
- }
- return false;
- }
-
- inline bool operator==(
- const commonapi::tests::DerivedTypeCollection::TestUnionIn& lhs,
- const commonapi::tests::DerivedTypeCollection::TestUnionReallyExtended& rhs) {
- return rhs == lhs;
- }
-
- inline bool operator!=(
- const commonapi::tests::DerivedTypeCollection::TestUnionReallyExtended& lhs,
- const commonapi::tests::DerivedTypeCollection::TestUnionIn& rhs) {
- return lhs != rhs;
- }
-
- inline bool operator!=(
- const commonapi::tests::DerivedTypeCollection::TestUnionIn& lhs,
- const commonapi::tests::DerivedTypeCollection::TestUnionReallyExtended& rhs) {
- return lhs != rhs;
- }
- inline bool operator==(
- const commonapi::tests::DerivedTypeCollection::TestUnionReallyExtended& lhs,
- const commonapi::tests::DerivedTypeCollection::TestUnionOut& rhs) {
- if (lhs.getValueType() == rhs.getValueType()) {
- if (rhs.getValueType() == 1) {
- double a = lhs.get<double>();
- double b = rhs.get<double>();
- return (a == b);
- } else if (rhs.getValueType() == 2) {
- int16_t a = lhs.get<int16_t>();
- int16_t b = rhs.get<int16_t>();
- return (a == b);
- } else if (rhs.getValueType() == 3) {
- std::string a = lhs.get<std::string>();
- std::string b = rhs.get<std::string>();
- return (a == b);
- } else if (rhs.getValueType() == 4) {
- commonapi::tests::DerivedTypeCollection::TestEnumExtended a = lhs.get<commonapi::tests::DerivedTypeCollection::TestEnumExtended>();
- commonapi::tests::DerivedTypeCollection::TestEnumExtended b = rhs.get<commonapi::tests::DerivedTypeCollection::TestEnumExtended>();
- return (a == b);
- }
- }
- return false;
- }
-
- inline bool operator==(
- const commonapi::tests::DerivedTypeCollection::TestUnionOut& lhs,
- const commonapi::tests::DerivedTypeCollection::TestUnionReallyExtended& rhs) {
- return rhs == lhs;
- }
-
- inline bool operator!=(
- const commonapi::tests::DerivedTypeCollection::TestUnionReallyExtended& lhs,
- const commonapi::tests::DerivedTypeCollection::TestUnionOut& rhs) {
- return lhs != rhs;
- }
-
- inline bool operator!=(
- const commonapi::tests::DerivedTypeCollection::TestUnionOut& lhs,
- const commonapi::tests::DerivedTypeCollection::TestUnionReallyExtended& rhs) {
- return lhs != rhs;
- }
-
+}
+
+
+namespace std {
+ template<>
+ struct hash<commonapi::tests::DerivedTypeCollection::TestEnum> {
+ inline size_t operator()(const commonapi::tests::DerivedTypeCollection::TestEnum& testEnum) const {
+ return static_cast<int32_t>(testEnum);
+ }
+ };
+ template<>
+ struct hash<commonapi::tests::DerivedTypeCollection::TestEnumExtended2> {
+ inline size_t operator()(const commonapi::tests::DerivedTypeCollection::TestEnumExtended2& testEnumExtended2) const {
+ return static_cast<int32_t>(testEnumExtended2);
+ }
+ };
+ template<>
+ struct hash<commonapi::tests::DerivedTypeCollection::TestEnumMissingValue> {
+ inline size_t operator()(const commonapi::tests::DerivedTypeCollection::TestEnumMissingValue& testEnumMissingValue) const {
+ return static_cast<int32_t>(testEnumMissingValue);
+ }
+ };
+ template<>
+ struct hash<commonapi::tests::DerivedTypeCollection::TestEnumExtended> {
+ inline size_t operator()(const commonapi::tests::DerivedTypeCollection::TestEnumExtended& testEnumExtended) const {
+ return static_cast<int32_t>(testEnumExtended);
+ }
+ };
}
#endif // COMMONAPI_TESTS_DERIVED_TYPE_COLLECTION_H_
diff --git a/src/test/commonapi/tests/PredefinedTypeCollection.h b/src/test/commonapi/tests/PredefinedTypeCollection.h
index 244f9da..ee9c1ec 100644
--- a/src/test/commonapi/tests/PredefinedTypeCollection.h
+++ b/src/test/commonapi/tests/PredefinedTypeCollection.h
@@ -5,6 +5,8 @@
#define COMMONAPI_TESTS_PREDEFINED_TYPE_COLLECTION_H_
#include <CommonAPI/ByteBuffer.h>
+#include <CommonAPI/InputStream.h>
+#include <CommonAPI/OutputStream.h>
#include <CommonAPI/types.h>
#include <cstdint>
#include <string>
@@ -13,32 +15,41 @@ namespace commonapi {
namespace tests {
namespace PredefinedTypeCollection {
+ typedef uint8_t TestUInt8;
+ typedef uint16_t TestUInt16;
+ typedef uint32_t TestUInt32;
+ typedef uint64_t TestUInt64;
+ typedef int8_t TestInt8;
+ typedef int16_t TestInt16;
+ typedef int32_t TestInt32;
+ typedef int64_t TestInt64;
+ typedef bool TestBoolean;
+ typedef CommonAPI::ByteBuffer TestByteBuffer;
+ typedef double TestDouble;
+ typedef float TestFloat;
+ typedef std::string TestString;
+ enum class WeirdStrangeAlienEnum: int32_t {
+ WEIRD,
+ STRANGE,
+ ALIEN
+ };
+
+ // XXX Definition of a comparator still is necessary for GCC 4.4.1, topic is fixed since 4.5.1
+ struct WeirdStrangeAlienEnumComparator;
+
+inline CommonAPI::InputStream& operator>>(CommonAPI::InputStream& inputStream, WeirdStrangeAlienEnum& enumValue) {
+ return inputStream.readEnumValue<int32_t>(enumValue);
+}
-typedef uint8_t TestUInt8;
-
-typedef uint16_t TestUInt16;
-
-typedef uint32_t TestUInt32;
-
-typedef uint64_t TestUInt64;
-
-typedef int8_t TestInt8;
-
-typedef int16_t TestInt16;
-
-typedef int32_t TestInt32;
-
-typedef int64_t TestInt64;
-
-typedef bool TestBoolean;
-
-typedef CommonAPI::ByteBuffer TestByteBuffer;
-
-typedef double TestDouble;
-
-typedef float TestFloat;
+inline CommonAPI::OutputStream& operator<<(CommonAPI::OutputStream& outputStream, const WeirdStrangeAlienEnum& enumValue) {
+ return outputStream.writeEnumValue(static_cast<int32_t>(enumValue));
+}
-typedef std::string TestString;
+struct WeirdStrangeAlienEnumComparator {
+ inline bool operator()(const WeirdStrangeAlienEnum& lhs, const WeirdStrangeAlienEnum& rhs) const {
+ return static_cast<int32_t>(lhs) < static_cast<int32_t>(rhs);
+ }
+};
@@ -54,8 +65,37 @@ static inline const char* getTypeCollectionName() {
namespace CommonAPI {
+ template<>
+ struct BasicTypeWriter<commonapi::tests::PredefinedTypeCollection::WeirdStrangeAlienEnum> {
+ inline static void writeType (CommonAPI::TypeOutputStream& typeStream) {
+ typeStream.writeInt32EnumType();
+ }
+ };
+ template<>
+ struct InputStreamVectorHelper<commonapi::tests::PredefinedTypeCollection::WeirdStrangeAlienEnum> {
+ static void beginReadVector(InputStream& inputStream, const std::vector<commonapi::tests::PredefinedTypeCollection::WeirdStrangeAlienEnum>& vectorValue) {
+ inputStream.beginReadInt32EnumVector();
+ }
+ };
+ template <>
+ struct OutputStreamVectorHelper<commonapi::tests::PredefinedTypeCollection::WeirdStrangeAlienEnum> {
+ static void beginWriteVector(OutputStream& outputStream, const std::vector<commonapi::tests::PredefinedTypeCollection::WeirdStrangeAlienEnum>& vectorValue) {
+ outputStream.beginWriteInt32EnumVector(vectorValue.size());
+ }
+ };
+
+}
+
+
+namespace std {
+ template<>
+ struct hash<commonapi::tests::PredefinedTypeCollection::WeirdStrangeAlienEnum> {
+ inline size_t operator()(const commonapi::tests::PredefinedTypeCollection::WeirdStrangeAlienEnum& weirdStrangeAlienEnum) const {
+ return static_cast<int32_t>(weirdStrangeAlienEnum);
+ }
+ };
}
#endif // COMMONAPI_TESTS_PREDEFINED_TYPE_COLLECTION_H_
diff --git a/src/test/commonapi/tests/TestInterface.h b/src/test/commonapi/tests/TestInterface.h
index 7b7efa5..fe0121e 100644
--- a/src/test/commonapi/tests/TestInterface.h
+++ b/src/test/commonapi/tests/TestInterface.h
@@ -13,11 +13,11 @@ class TestInterface {
public:
virtual ~TestInterface() { }
- static inline const char* getInterfaceName();
+ static inline const char* getInterfaceId();
static inline CommonAPI::Version getInterfaceVersion();
};
-const char* TestInterface::getInterfaceName() {
+const char* TestInterface::getInterfaceId() {
return "commonapi.tests.TestInterface";
}
@@ -33,4 +33,8 @@ namespace CommonAPI {
}
+
+namespace std {
+}
+
#endif // COMMONAPI_TESTS_TEST_INTERFACE_H_
diff --git a/src/test/commonapi/tests/TestInterfaceDBusProxy.cpp b/src/test/commonapi/tests/TestInterfaceDBusProxy.cpp
index d739269..34981e0 100644
--- a/src/test/commonapi/tests/TestInterfaceDBusProxy.cpp
+++ b/src/test/commonapi/tests/TestInterfaceDBusProxy.cpp
@@ -6,21 +6,29 @@
namespace commonapi {
namespace tests {
-std::shared_ptr<CommonAPI::DBus::DBusProxy> createTestInterfaceDBusProxy(const char* busName,
- const char* objectPath,
- std::shared_ptr<CommonAPI::DBus::DBusProxyConnection> dbusProxyConnection) {
- return std::make_shared<TestInterfaceDBusProxy>(busName, objectPath, dbusProxyConnection);
+std::shared_ptr<CommonAPI::DBus::DBusProxy> createTestInterfaceDBusProxy(
+ const std::string& commonApiAddress,
+ const std::string& interfaceName,
+ const std::string& busName,
+ const std::string& objectPath,
+ const std::shared_ptr<CommonAPI::DBus::DBusProxyConnection>& dbusProxyConnection) {
+ return std::make_shared<TestInterfaceDBusProxy>(commonApiAddress, interfaceName, busName, objectPath, dbusProxyConnection);
}
__attribute__((constructor)) void registerTestInterfaceDBusProxy(void) {
- CommonAPI::DBus::DBusFactory::registerProxyFactoryMethod(TestInterface::getInterfaceName(),
+ CommonAPI::DBus::DBusFactory::registerProxyFactoryMethod(TestInterface::getInterfaceId(),
&createTestInterfaceDBusProxy);
}
-TestInterfaceDBusProxy::TestInterfaceDBusProxy(const std::string& busName, const std::string& objectPath, const std::shared_ptr<CommonAPI::DBus::DBusProxyConnection>& dbusProxyconnection):
- CommonAPI::DBus::DBusProxy(busName, objectPath, TestInterface::getInterfaceName(), dbusProxyconnection)
+TestInterfaceDBusProxy::TestInterfaceDBusProxy(
+ const std::string& commonApiAddress,
+ const std::string& interfaceName,
+ const std::string& busName,
+ const std::string& objectPath,
+ const std::shared_ptr<CommonAPI::DBus::DBusProxyConnection>& dbusProxyconnection):
+ CommonAPI::DBus::DBusProxy(commonApiAddress, interfaceName, busName, objectPath, dbusProxyconnection)
, testPredefinedTypeAttribute_(*this, "onTestPredefinedTypeAttributeAttributeChanged", "setTestPredefinedTypeAttributeAttribute", "u", "getTestPredefinedTypeAttributeAttribute"),
- testDerivedStructAttribute_(*this, "onTestDerivedStructAttributeAttributeChanged", "setTestDerivedStructAttributeAttribute", "(sqi)", "getTestDerivedStructAttributeAttribute"),
+ testDerivedStructAttribute_(*this, "onTestDerivedStructAttributeAttributeChanged", "setTestDerivedStructAttributeAttribute", "(sqii)", "getTestDerivedStructAttributeAttribute"),
testDerivedArrayAttribute_(*this, "onTestDerivedArrayAttributeAttributeChanged", "setTestDerivedArrayAttributeAttribute", "at", "getTestDerivedArrayAttributeAttribute")
, testPredefinedTypeBroadcast_(*this, "TestPredefinedTypeBroadcast", "us")
{
@@ -116,25 +124,6 @@ std::future<CommonAPI::CallStatus> TestInterfaceDBusProxy::testDerivedTypeMethod
testEnumExtended2InValue, testMapInValue,
std::move(callback));
}
-void TestInterfaceDBusProxy::testUnionMethod(const DerivedTypeCollection::TestUnionIn& inParam, CommonAPI::CallStatus& callStatus, DerivedTypeCollection::TestUnionIn& outParam) {
- CommonAPI::DBus::DBusProxyHelper<CommonAPI::DBus::DBusSerializableArguments<DerivedTypeCollection::TestUnionIn>,
- CommonAPI::DBus::DBusSerializableArguments<DerivedTypeCollection::TestUnionIn> >::callMethodWithReply(
- *this,
- "testUnionMethod",
- "(yv)",
- inParam,
- callStatus
- , outParam);
-}
-std::future<CommonAPI::CallStatus> TestInterfaceDBusProxy::testUnionMethodAsync(const DerivedTypeCollection::TestUnionIn& inParam, TestUnionMethodAsyncCallback callback) {
- return CommonAPI::DBus::DBusProxyHelper<CommonAPI::DBus::DBusSerializableArguments<DerivedTypeCollection::TestUnionIn>,
- CommonAPI::DBus::DBusSerializableArguments<DerivedTypeCollection::TestUnionIn> >::callMethodAsync(
- *this,
- "testUnionMethod",
- "(yv)",
- inParam,
- std::move(callback));
-}
void TestInterfaceDBusProxy::getOwnVersion(uint16_t& ownVersionMajor, uint16_t& ownVersionMinor) const {
ownVersionMajor = 1;
diff --git a/src/test/commonapi/tests/TestInterfaceDBusProxy.h b/src/test/commonapi/tests/TestInterfaceDBusProxy.h
index 276a74b..cf3fd76 100644
--- a/src/test/commonapi/tests/TestInterfaceDBusProxy.h
+++ b/src/test/commonapi/tests/TestInterfaceDBusProxy.h
@@ -4,7 +4,7 @@
#ifndef COMMONAPI_TESTS_TEST_INTERFACE_DBUS_PROXY_H_
#define COMMONAPI_TESTS_TEST_INTERFACE_DBUS_PROXY_H_
-#include <test/commonapi/tests/TestInterfaceProxyBase.h>
+#include "TestInterfaceProxyBase.h"
#include <CommonAPI/DBus/DBusFactory.h>
#include <CommonAPI/DBus/DBusProxy.h>
#include <CommonAPI/DBus/DBusAttribute.h>
@@ -17,7 +17,14 @@ namespace tests {
class TestInterfaceDBusProxy: virtual public TestInterfaceProxyBase, virtual public CommonAPI::DBus::DBusProxy {
public:
- TestInterfaceDBusProxy(const std::string& busName, const std::string& objectPath, const std::shared_ptr<CommonAPI::DBus::DBusProxyConnection>& dbusProxyconnection);
+ TestInterfaceDBusProxy(
+ const std::string& commonApiAddress,
+ const std::string& interfaceName,
+ const std::string& busName,
+ const std::string& objectPath,
+ const std::shared_ptr<CommonAPI::DBus::DBusProxyConnection>& dbusProxyconnection);
+
+ virtual ~TestInterfaceDBusProxy() { }
virtual TestPredefinedTypeAttributeAttribute& getTestPredefinedTypeAttributeAttribute();
virtual TestDerivedStructAttributeAttribute& getTestDerivedStructAttributeAttribute();
@@ -37,9 +44,6 @@ class TestInterfaceDBusProxy: virtual public TestInterfaceProxyBase, virtual pub
virtual void testDerivedTypeMethod(const DerivedTypeCollection::TestEnumExtended2& testEnumExtended2InValue, const DerivedTypeCollection::TestMap& testMapInValue, CommonAPI::CallStatus& callStatus, DerivedTypeCollection::TestEnumExtended2& testEnumExtended2OutValue, DerivedTypeCollection::TestMap& testMapOutValue);
virtual std::future<CommonAPI::CallStatus> testDerivedTypeMethodAsync(const DerivedTypeCollection::TestEnumExtended2& testEnumExtended2InValue, const DerivedTypeCollection::TestMap& testMapInValue, TestDerivedTypeMethodAsyncCallback callback);
-
- virtual void testUnionMethod(const DerivedTypeCollection::TestUnionIn& inParam, CommonAPI::CallStatus& callStatus, DerivedTypeCollection::TestUnionIn& outParam);
- virtual std::future<CommonAPI::CallStatus> testUnionMethodAsync(const DerivedTypeCollection::TestUnionIn& inParam, TestUnionMethodAsyncCallback callback);
virtual void getOwnVersion(uint16_t& ownVersionMajor, uint16_t& ownVersionMinor) const;
diff --git a/src/test/commonapi/tests/TestInterfaceDBusStubAdapter.cpp b/src/test/commonapi/tests/TestInterfaceDBusStubAdapter.cpp
index b24e036..869560e 100644
--- a/src/test/commonapi/tests/TestInterfaceDBusStubAdapter.cpp
+++ b/src/test/commonapi/tests/TestInterfaceDBusStubAdapter.cpp
@@ -2,29 +2,34 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "TestInterfaceDBusStubAdapter.h"
-#include <test/commonapi/tests/TestInterface.h>
+#include "TestInterface.h"
namespace commonapi {
namespace tests {
-std::shared_ptr<CommonAPI::DBus::DBusStubAdapter> createTestInterfaceDBusStubAdapter(std::string busName,
- std::string objectPath,
- std::shared_ptr<CommonAPI::DBus::DBusProxyConnection> dbusProxyConnection,
- std::shared_ptr<CommonAPI::StubBase> stubBase) {
- return std::make_shared<TestInterfaceDBusStubAdapter>(busName, objectPath, dbusProxyConnection, stubBase);
+std::shared_ptr<CommonAPI::DBus::DBusStubAdapter> createTestInterfaceDBusStubAdapter(
+ const std::string& commonApiAddress,
+ const std::string& interfaceName,
+ const std::string& busName,
+ const std::string& objectPath,
+ const std::shared_ptr<CommonAPI::DBus::DBusProxyConnection>& dbusProxyConnection,
+ const std::shared_ptr<CommonAPI::StubBase>& stubBase) {
+ return std::make_shared<TestInterfaceDBusStubAdapter>(commonApiAddress, interfaceName, busName, objectPath, dbusProxyConnection, stubBase);
}
__attribute__((constructor)) void registerTestInterfaceDBusStubAdapter(void) {
- CommonAPI::DBus::DBusFactory::registerAdapterFactoryMethod(TestInterface::getInterfaceName(),
+ CommonAPI::DBus::DBusFactory::registerAdapterFactoryMethod(TestInterface::getInterfaceId(),
&createTestInterfaceDBusStubAdapter);
}
TestInterfaceDBusStubAdapter::TestInterfaceDBusStubAdapter(
+ const std::string& commonApiAddress,
+ const std::string& dbusInterfaceName,
const std::string& dbusBusName,
const std::string& dbusObjectPath,
const std::shared_ptr<CommonAPI::DBus::DBusProxyConnection>& dbusConnection,
const std::shared_ptr<CommonAPI::StubBase>& stub):
- TestInterfaceDBusStubAdapterHelper(dbusBusName, dbusObjectPath, TestInterface::getInterfaceName(), dbusConnection, std::dynamic_pointer_cast<TestInterfaceStub>(stub)) {
+ TestInterfaceDBusStubAdapterHelper(commonApiAddress, dbusInterfaceName, dbusBusName, dbusObjectPath, dbusConnection, std::dynamic_pointer_cast<TestInterfaceStub>(stub)) {
}
const char* TestInterfaceDBusStubAdapter::getMethodsDBusIntrospectionXmlData() const {
@@ -40,14 +45,14 @@ const char* TestInterfaceDBusStubAdapter::getMethodsDBusIntrospectionXmlData() c
"<arg name=\"changedValue\" type=\"u\" />\n"
"</signal>\n"
"<method name=\"getTestDerivedStructAttributeAttribute\">\n"
- "<arg name=\"value\" type=\"(sqi)\" direction=\"out\" />"
+ "<arg name=\"value\" type=\"(sqii)\" direction=\"out\" />"
"</method>\n"
"<method name=\"setTestDerivedStructAttributeAttribute\">\n"
- "<arg name=\"requestedValue\" type=\"(sqi)\" direction=\"in\" />\n"
- "<arg name=\"setValue\" type=\"(sqi)\" direction=\"out\" />\n"
+ "<arg name=\"requestedValue\" type=\"(sqii)\" direction=\"in\" />\n"
+ "<arg name=\"setValue\" type=\"(sqii)\" direction=\"out\" />\n"
"</method>\n"
"<signal name=\"onTestDerivedStructAttributeAttributeChanged\">\n"
- "<arg name=\"changedValue\" type=\"(sqi)\" />\n"
+ "<arg name=\"changedValue\" type=\"(sqii)\" />\n"
"</signal>\n"
"<method name=\"getTestDerivedArrayAttributeAttribute\">\n"
"<arg name=\"value\" type=\"at\" direction=\"out\" />"
@@ -83,10 +88,6 @@ const char* TestInterfaceDBusStubAdapter::getMethodsDBusIntrospectionXmlData() c
"<arg name=\"testEnumExtended2OutValue\" type=\"i\" direction=\"out\" />\n"
"<arg name=\"testMapOutValue\" type=\"a{ua(sq)}\" direction=\"out\" />\n"
"</method>\n"
- "<method name=\"testUnionMethod\">\n"
- "<arg name=\"inParam\" type=\"(yv)\" direction=\"in\" />\n"
- "<arg name=\"outParam\" type=\"(yv)\" direction=\"out\" />\n"
- "</method>\n"
;
}
@@ -108,7 +109,7 @@ static CommonAPI::DBus::DBusSetObservableAttributeStubDispatcher<
static CommonAPI::DBus::DBusGetAttributeStubDispatcher<
TestInterfaceStub,
DerivedTypeCollection::TestStructExtended
- > getTestDerivedStructAttributeAttributeStubDispatcher(&TestInterfaceStub::getTestDerivedStructAttributeAttribute, "(sqi)");
+ > getTestDerivedStructAttributeAttributeStubDispatcher(&TestInterfaceStub::getTestDerivedStructAttributeAttribute, "(sqii)");
static CommonAPI::DBus::DBusSetObservableAttributeStubDispatcher<
TestInterfaceStub,
DerivedTypeCollection::TestStructExtended
@@ -117,7 +118,7 @@ static CommonAPI::DBus::DBusSetObservableAttributeStubDispatcher<
&TestInterfaceStubRemoteEvent::onRemoteSetTestDerivedStructAttributeAttribute,
&TestInterfaceStubRemoteEvent::onRemoteTestDerivedStructAttributeAttributeChanged,
&TestInterfaceStubAdapter::fireTestDerivedStructAttributeAttributeChanged,
- "(sqi)");
+ "(sqii)");
static CommonAPI::DBus::DBusGetAttributeStubDispatcher<
TestInterfaceStub,
@@ -158,27 +159,20 @@ static CommonAPI::DBus::DBusMethodWithReplyStubDispatcher<
std::tuple<DerivedTypeCollection::TestEnumExtended2, DerivedTypeCollection::TestMap>
> testDerivedTypeMethodStubDispatcher(&TestInterfaceStub::testDerivedTypeMethod, "ia{ua(sq)}");
-static CommonAPI::DBus::DBusMethodWithReplyStubDispatcher<
- TestInterfaceStub,
- std::tuple<DerivedTypeCollection::TestUnionIn>,
- std::tuple<DerivedTypeCollection::TestUnionIn>
- > testUnionMethodStubDispatcher(&TestInterfaceStub::testUnionMethod, "(yv)");
-
template<>
const TestInterfaceDBusStubAdapterHelper::StubDispatcherTable TestInterfaceDBusStubAdapterHelper::stubDispatcherTable_ = {
{ { "getTestPredefinedTypeAttributeAttribute", "" }, &commonapi::tests::getTestPredefinedTypeAttributeAttributeStubDispatcher }
, { { "setTestPredefinedTypeAttributeAttribute", "u" }, &commonapi::tests::setTestPredefinedTypeAttributeAttributeStubDispatcher },
{ { "getTestDerivedStructAttributeAttribute", "" }, &commonapi::tests::getTestDerivedStructAttributeAttributeStubDispatcher }
- , { { "setTestDerivedStructAttributeAttribute", "(sqi)" }, &commonapi::tests::setTestDerivedStructAttributeAttributeStubDispatcher },
+ , { { "setTestDerivedStructAttributeAttribute", "(sqii)" }, &commonapi::tests::setTestDerivedStructAttributeAttributeStubDispatcher },
{ { "getTestDerivedArrayAttributeAttribute", "" }, &commonapi::tests::getTestDerivedArrayAttributeAttributeStubDispatcher }
, { { "setTestDerivedArrayAttributeAttribute", "at" }, &commonapi::tests::setTestDerivedArrayAttributeAttributeStubDispatcher }
,
{ { "testVoidPredefinedTypeMethod", "us" }, &commonapi::tests::testVoidPredefinedTypeMethodStubDispatcher },
{ { "testPredefinedTypeMethod", "us" }, &commonapi::tests::testPredefinedTypeMethodStubDispatcher },
{ { "testVoidDerivedTypeMethod", "ia{ua(sq)}" }, &commonapi::tests::testVoidDerivedTypeMethodStubDispatcher },
- { { "testDerivedTypeMethod", "ia{ua(sq)}" }, &commonapi::tests::testDerivedTypeMethodStubDispatcher },
- { { "testUnionMethod", "(yv)" }, &commonapi::tests::testUnionMethodStubDispatcher }
+ { { "testDerivedTypeMethod", "ia{ua(sq)}" }, &commonapi::tests::testDerivedTypeMethodStubDispatcher }
};
void TestInterfaceDBusStubAdapter::fireTestPredefinedTypeAttributeAttributeChanged(const uint32_t& value) {
@@ -195,7 +189,7 @@ void TestInterfaceDBusStubAdapter::fireTestDerivedStructAttributeAttributeChange
::sendSignal(
*this,
"onTestDerivedStructAttributeAttributeChanged",
- "(sqi)",
+ "(sqii)",
value
);
}
diff --git a/src/test/commonapi/tests/TestInterfaceDBusStubAdapter.h b/src/test/commonapi/tests/TestInterfaceDBusStubAdapter.h
index 0eaaf75..7a809ad 100644
--- a/src/test/commonapi/tests/TestInterfaceDBusStubAdapter.h
+++ b/src/test/commonapi/tests/TestInterfaceDBusStubAdapter.h
@@ -4,7 +4,7 @@
#ifndef COMMONAPI_TESTS_TEST_INTERFACE_DBUS_STUB_ADAPTER_H_
#define COMMONAPI_TESTS_TEST_INTERFACE_DBUS_STUB_ADAPTER_H_
-#include <test/commonapi/tests/TestInterfaceStub.h>
+#include "TestInterfaceStub.h"
#include <CommonAPI/DBus/DBusStubAdapterHelper.h>
#include <CommonAPI/DBus/DBusFactory.h>
@@ -17,6 +17,8 @@ typedef CommonAPI::DBus::DBusStubAdapterHelper<TestInterfaceStub> TestInterfaceD
class TestInterfaceDBusStubAdapter: public TestInterfaceStubAdapter, public TestInterfaceDBusStubAdapterHelper {
public:
TestInterfaceDBusStubAdapter(
+ const std::string& commonApiAddress,
+ const std::string& dbusInterfaceName,
const std::string& dbusBusName,
const std::string& dbusObjectPath,
const std::shared_ptr<CommonAPI::DBus::DBusProxyConnection>& dbusConnection,
diff --git a/src/test/commonapi/tests/TestInterfaceProxy.h b/src/test/commonapi/tests/TestInterfaceProxy.h
index 0404eea..0e0c54c 100644
--- a/src/test/commonapi/tests/TestInterfaceProxy.h
+++ b/src/test/commonapi/tests/TestInterfaceProxy.h
@@ -36,9 +36,6 @@ class TestInterfaceProxy: virtual public TestInterface, virtual public TestInter
virtual void testDerivedTypeMethod(const DerivedTypeCollection::TestEnumExtended2& testEnumExtended2InValue, const DerivedTypeCollection::TestMap& testMapInValue, CommonAPI::CallStatus& callStatus, DerivedTypeCollection::TestEnumExtended2& testEnumExtended2OutValue, DerivedTypeCollection::TestMap& testMapOutValue);
virtual std::future<CommonAPI::CallStatus> testDerivedTypeMethodAsync(const DerivedTypeCollection::TestEnumExtended2& testEnumExtended2InValue, const DerivedTypeCollection::TestMap& testMapInValue, TestDerivedTypeMethodAsyncCallback callback);
- virtual void testUnionMethod(const DerivedTypeCollection::TestUnionIn& inParam, CommonAPI::CallStatus& callStatus, DerivedTypeCollection::TestUnionIn& outParam);
- virtual std::future<CommonAPI::CallStatus> testUnionMethodAsync(const DerivedTypeCollection::TestUnionIn& inParam, TestUnionMethodAsyncCallback callback);
-
virtual std::string getAddress() const;
virtual const std::string& getDomain() const;
virtual const std::string& getServiceId() const;
@@ -186,16 +183,6 @@ std::future<CommonAPI::CallStatus> TestInterfaceProxy<_AttributeExtensions...>::
return delegate_->testDerivedTypeMethodAsync(testEnumExtended2InValue, testMapInValue, callback);
}
-template <typename ... _AttributeExtensions>
-void TestInterfaceProxy<_AttributeExtensions...>::testUnionMethod(const DerivedTypeCollection::TestUnionIn& inParam, CommonAPI::CallStatus& callStatus, DerivedTypeCollection::TestUnionIn& outParam) {
- delegate_->testUnionMethod(inParam, callStatus, outParam);
-}
-
-template <typename ... _AttributeExtensions>
-std::future<CommonAPI::CallStatus> TestInterfaceProxy<_AttributeExtensions...>::testUnionMethodAsync(const DerivedTypeCollection::TestUnionIn& inParam, TestUnionMethodAsyncCallback callback) {
- return delegate_->testUnionMethodAsync(inParam, callback);
-}
-
template <typename ... _AttributeExtensions>
std::string TestInterfaceProxy<_AttributeExtensions...>::getAddress() const {
diff --git a/src/test/commonapi/tests/TestInterfaceProxyBase.h b/src/test/commonapi/tests/TestInterfaceProxyBase.h
index 9d4dcaa..4210e25 100644
--- a/src/test/commonapi/tests/TestInterfaceProxyBase.h
+++ b/src/test/commonapi/tests/TestInterfaceProxyBase.h
@@ -5,14 +5,12 @@
#define COMMONAPI_TESTS_TEST_INTERFACE_PROXY_BASE_H_
#include "TestInterface.h"
-#include <CommonAPI/SerializableVariant.h>
#include <unordered_map>
#include <cstdint>
-#include <test/commonapi/tests/DerivedTypeCollection.h>
+#include "PredefinedTypeCollection.h"
+#include "DerivedTypeCollection.h"
#include <CommonAPI/InputStream.h>
#include <vector>
-#include <string>
-#include <memory>
#include <CommonAPI/OutputStream.h>
#include <CommonAPI/Attribute.h>
#include <CommonAPI/Event.h>
@@ -33,7 +31,6 @@ class TestInterfaceProxyBase: virtual public CommonAPI::Proxy {
typedef std::function<void(const CommonAPI::CallStatus&, const uint32_t&, const std::string&)> TestPredefinedTypeMethodAsyncCallback;
typedef std::function<void(const CommonAPI::CallStatus&)> TestVoidDerivedTypeMethodAsyncCallback;
typedef std::function<void(const CommonAPI::CallStatus&, const DerivedTypeCollection::TestEnumExtended2&, const DerivedTypeCollection::TestMap&)> TestDerivedTypeMethodAsyncCallback;
- typedef std::function<void(const CommonAPI::CallStatus&, const DerivedTypeCollection::TestUnionIn&)> TestUnionMethodAsyncCallback;
virtual TestPredefinedTypeAttributeAttribute& getTestPredefinedTypeAttributeAttribute() = 0;
virtual TestDerivedStructAttributeAttribute& getTestDerivedStructAttributeAttribute() = 0;
@@ -53,9 +50,6 @@ class TestInterfaceProxyBase: virtual public CommonAPI::Proxy {
virtual void testDerivedTypeMethod(const DerivedTypeCollection::TestEnumExtended2& testEnumExtended2InValue, const DerivedTypeCollection::TestMap& testMapInValue, CommonAPI::CallStatus& callStatus, DerivedTypeCollection::TestEnumExtended2& testEnumExtended2OutValue, DerivedTypeCollection::TestMap& testMapOutValue) = 0;
virtual std::future<CommonAPI::CallStatus> testDerivedTypeMethodAsync(const DerivedTypeCollection::TestEnumExtended2& testEnumExtended2InValue, const DerivedTypeCollection::TestMap& testMapInValue, TestDerivedTypeMethodAsyncCallback callback) = 0;
-
- virtual void testUnionMethod(const DerivedTypeCollection::TestUnionIn& inParam, CommonAPI::CallStatus& callStatus, DerivedTypeCollection::TestUnionIn& outParam) = 0;
- virtual std::future<CommonAPI::CallStatus> testUnionMethodAsync(const DerivedTypeCollection::TestUnionIn& inParam, TestUnionMethodAsyncCallback callback) = 0;
};
diff --git a/src/test/commonapi/tests/TestInterfaceStub.h b/src/test/commonapi/tests/TestInterfaceStub.h
index 45c1d6a..ac34f79 100644
--- a/src/test/commonapi/tests/TestInterfaceStub.h
+++ b/src/test/commonapi/tests/TestInterfaceStub.h
@@ -4,14 +4,12 @@
#ifndef COMMONAPI_TESTS_TEST_INTERFACE_STUB_H_
#define COMMONAPI_TESTS_TEST_INTERFACE_STUB_H_
-#include <CommonAPI/SerializableVariant.h>
#include <unordered_map>
#include <cstdint>
-#include <test/commonapi/tests/DerivedTypeCollection.h>
+#include "PredefinedTypeCollection.h"
+#include "DerivedTypeCollection.h"
#include <CommonAPI/InputStream.h>
#include <vector>
-#include <string>
-#include <memory>
#include <CommonAPI/OutputStream.h>
#include "TestInterface.h"
#include <CommonAPI/Stub.h>
@@ -47,6 +45,8 @@ class TestInterfaceStubRemoteEvent {
class TestInterfaceStub : public CommonAPI::Stub<TestInterfaceStubAdapter , TestInterfaceStubRemoteEvent> {
public:
+ virtual ~TestInterfaceStub() { }
+
virtual const uint32_t& getTestPredefinedTypeAttributeAttribute() = 0;
virtual const DerivedTypeCollection::TestStructExtended& getTestDerivedStructAttributeAttribute() = 0;
virtual const DerivedTypeCollection::TestArrayUInt64& getTestDerivedArrayAttributeAttribute() = 0;
@@ -55,7 +55,6 @@ class TestInterfaceStub : public CommonAPI::Stub<TestInterfaceStubAdapter , Test
virtual void testPredefinedTypeMethod(uint32_t uint32InValue, std::string stringInValue, uint32_t& uint32OutValue, std::string& stringOutValue) = 0;
virtual void testVoidDerivedTypeMethod(DerivedTypeCollection::TestEnumExtended2 testEnumExtended2Value, DerivedTypeCollection::TestMap testMapValue) = 0;
virtual void testDerivedTypeMethod(DerivedTypeCollection::TestEnumExtended2 testEnumExtended2InValue, DerivedTypeCollection::TestMap testMapInValue, DerivedTypeCollection::TestEnumExtended2& testEnumExtended2OutValue, DerivedTypeCollection::TestMap& testMapOutValue) = 0;
- virtual void testUnionMethod(DerivedTypeCollection::TestUnionIn inParam, DerivedTypeCollection::TestUnionIn& outParam) = 0;
virtual void fireTestPredefinedTypeBroadcastEvent(const uint32_t& uint32Value, const std::string& stringValue) = 0;
};
diff --git a/src/test/commonapi/tests/TestInterfaceStubDefault.cpp b/src/test/commonapi/tests/TestInterfaceStubDefault.cpp
index 786766d..c5e7e35 100644
--- a/src/test/commonapi/tests/TestInterfaceStubDefault.cpp
+++ b/src/test/commonapi/tests/TestInterfaceStubDefault.cpp
@@ -1,7 +1,7 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-#include <test/commonapi/tests/TestInterfaceStubDefault.h>
+#include "TestInterfaceStubDefault.h"
namespace commonapi {
namespace tests {
@@ -15,6 +15,10 @@ TestInterfaceStubRemoteEvent* TestInterfaceStubDefault::initStubAdapter(const st
return &remoteEventHandler_;
}
+void TestInterfaceStubDefault::deinitStubAdapter() {
+ stubAdapter_.reset();
+}
+
const uint32_t& TestInterfaceStubDefault::getTestPredefinedTypeAttributeAttribute() {
return testPredefinedTypeAttributeAttributeValue_;
}
@@ -113,10 +117,6 @@ void TestInterfaceStubDefault::testDerivedTypeMethod(DerivedTypeCollection::Test
// No operation in default
}
-void TestInterfaceStubDefault::testUnionMethod(DerivedTypeCollection::TestUnionIn inParam, DerivedTypeCollection::TestUnionIn& outParam) {
- // No operation in default
-}
-
void TestInterfaceStubDefault::fireTestPredefinedTypeBroadcastEvent(const uint32_t& uint32Value, const std::string& stringValue) {
stubAdapter_->fireTestPredefinedTypeBroadcastEvent(uint32Value, stringValue);
diff --git a/src/test/commonapi/tests/TestInterfaceStubDefault.h b/src/test/commonapi/tests/TestInterfaceStubDefault.h
index 042840a..bc5cdff 100644
--- a/src/test/commonapi/tests/TestInterfaceStubDefault.h
+++ b/src/test/commonapi/tests/TestInterfaceStubDefault.h
@@ -4,7 +4,7 @@
#ifndef COMMONAPI_TESTS_TEST_INTERFACE_STUB_DEFAULT_H_
#define COMMONAPI_TESTS_TEST_INTERFACE_STUB_DEFAULT_H_
-#include <test/commonapi/tests/TestInterfaceStub.h>
+#include "TestInterfaceStub.h"
namespace commonapi {
namespace tests {
@@ -14,15 +14,16 @@ class TestInterfaceStubDefault : public TestInterfaceStub {
TestInterfaceStubDefault();
TestInterfaceStubRemoteEvent* initStubAdapter(const std::shared_ptr<TestInterfaceStubAdapter>& stubAdapter);
+ void deinitStubAdapter();
virtual const uint32_t& getTestPredefinedTypeAttributeAttribute();
- void setTestPredefinedTypeAttributeAttribute(uint32_t value);
+ virtual void setTestPredefinedTypeAttributeAttribute(uint32_t value);
virtual const DerivedTypeCollection::TestStructExtended& getTestDerivedStructAttributeAttribute();
- void setTestDerivedStructAttributeAttribute(DerivedTypeCollection::TestStructExtended value);
+ virtual void setTestDerivedStructAttributeAttribute(DerivedTypeCollection::TestStructExtended value);
virtual const DerivedTypeCollection::TestArrayUInt64& getTestDerivedArrayAttributeAttribute();
- void setTestDerivedArrayAttributeAttribute(DerivedTypeCollection::TestArrayUInt64 value);
+ virtual void setTestDerivedArrayAttributeAttribute(DerivedTypeCollection::TestArrayUInt64 value);
virtual void testVoidPredefinedTypeMethod(uint32_t uint32Value, std::string stringValue);
@@ -33,23 +34,21 @@ class TestInterfaceStubDefault : public TestInterfaceStub {
virtual void testDerivedTypeMethod(DerivedTypeCollection::TestEnumExtended2 testEnumExtended2InValue, DerivedTypeCollection::TestMap testMapInValue, DerivedTypeCollection::TestEnumExtended2& testEnumExtended2OutValue, DerivedTypeCollection::TestMap& testMapOutValue);
- virtual void testUnionMethod(DerivedTypeCollection::TestUnionIn inParam, DerivedTypeCollection::TestUnionIn& outParam);
-
virtual void fireTestPredefinedTypeBroadcastEvent(const uint32_t& uint32Value, const std::string& stringValue);
protected:
- void onRemoteTestPredefinedTypeAttributeAttributeChanged();
- bool trySetTestPredefinedTypeAttributeAttribute(uint32_t value);
- bool validateTestPredefinedTypeAttributeAttributeRequestedValue(const uint32_t& value);
+ virtual void onRemoteTestPredefinedTypeAttributeAttributeChanged();
+ virtual bool trySetTestPredefinedTypeAttributeAttribute(uint32_t value);
+ virtual bool validateTestPredefinedTypeAttributeAttributeRequestedValue(const uint32_t& value);
- void onRemoteTestDerivedStructAttributeAttributeChanged();
- bool trySetTestDerivedStructAttributeAttribute(DerivedTypeCollection::TestStructExtended value);
- bool validateTestDerivedStructAttributeAttributeRequestedValue(const DerivedTypeCollection::TestStructExtended& value);
+ virtual void onRemoteTestDerivedStructAttributeAttributeChanged();
+ virtual bool trySetTestDerivedStructAttributeAttribute(DerivedTypeCollection::TestStructExtended value);
+ virtual bool validateTestDerivedStructAttributeAttributeRequestedValue(const DerivedTypeCollection::TestStructExtended& value);
- void onRemoteTestDerivedArrayAttributeAttributeChanged();
- bool trySetTestDerivedArrayAttributeAttribute(DerivedTypeCollection::TestArrayUInt64 value);
- bool validateTestDerivedArrayAttributeAttributeRequestedValue(const DerivedTypeCollection::TestArrayUInt64& value);
+ virtual void onRemoteTestDerivedArrayAttributeAttributeChanged();
+ virtual bool trySetTestDerivedArrayAttributeAttribute(DerivedTypeCollection::TestArrayUInt64 value);
+ virtual bool validateTestDerivedArrayAttributeAttributeRequestedValue(const DerivedTypeCollection::TestArrayUInt64& value);
private:
diff --git a/src/test/fakeLegacyService/fake.legacy.service.xml b/src/test/fakeLegacyService/fake.legacy.service.xml
new file mode 100644
index 0000000..81b4e60
--- /dev/null
+++ b/src/test/fakeLegacyService/fake.legacy.service.xml
@@ -0,0 +1,259 @@
+<!-- Auto-Generated interface from Rhapsody: 'Repository::ssw_LifecycleSupport::NodeStateManagement::Concept::Interface::INSM_Consumer' -->
+<!-- Created at 2012-06-01 09:36:05 by uid65904 -->
+<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN"
+ "http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
+<node>
+<interface name="org.freedesktop.DBus.Introspectable">
+ <method name="Introspect">
+ <arg name="data" direction="out" type="s"/>
+ </method>
+</interface>
+<interface name="org.freedesktop.DBus.Properties">
+ <method name="Get">
+ <arg name="interface" direction="in" type="s"/>
+ <arg name="propname" direction="in" type="s"/>
+ <arg name="value" direction="out" type="v"/>
+ </method>
+
+ <method name="Set">
+ <arg name="interface" direction="in" type="s"/>
+ <arg name="propname" direction="in" type="s"/>
+ <arg name="value" direction="in" type="v"/>
+ </method>
+
+ <method name="GetAll">
+ <arg name="interface" direction="in" type="s"/>
+ <arg name="props" direction="out" type="a{sv}"/>
+ </method>
+</interface>
+ <!--
+ org.genivi.NodeStateManager.Consumer:
+ @short_description: "Consumer" interface of the NodeStateManager.
+
+ This interface contains functions which are not safety critical and can be accessed by "every" client without further restrictions.
+ -->
+ <interface name="org.genivi.NodeStateManager.Consumer">
+ <!--
+ RestartReason: This property informs clients about the reason for the last restart. The values are based upon the enummeration NsmRestartReason_e. Note: The value is only set once at start-up.
+ -->
+ <property name="RestartReason" type="i" access="read"/>
+
+ <!--
+ ShutdownReason: This property informs clients about the reason for the last shutdown. The values are based upon the enummeration NsmShutdownReason_e. Note: The value is only set once at start-up.
+ -->
+ <property name="ShutdownReason" type="i" access="read"/>
+
+ <!--
+ WakeUpReason: This property informs clients about the recent reason for waking up the target. The values are based upon the enummeration NsmWakeUpReason_e. Note: The value is only set once at start-up.
+ -->
+ <property name="WakeUpReason" type="i" access="read"/>
+
+ <!--
+ BootMode: This property informs clients about the recent BootMode of the target. The values will be defined by a third party header, which has not been delivered yet. The description needs to be updated as soon as the header is available.
+ -->
+ <property name="BootMode" type="i" access="read"/>
+
+ <!--
+ NodeState:
+ @NodeState: Numeric value for the current NodeState, defined in NsmNodeState_e.
+
+ Clients can register for notifications when the NodeState is updated inside the NodeStateManager. This signal is sent to registered clients and will include the current NodeState as a parameter.
+ -->
+ <signal name="NodeState">
+ <arg name="NodeState" type="i"/>
+ </signal>
+
+ <!--
+ NodeApplicationMode:
+ @ApplicationModeId: Numeric value for the current ApplicationMode, defined in NsmAplicationMode_e.
+
+ Clients can register for notifications when the NodeApplicationMode is updated inside the NodeStateManager. This signal is sent to registered clients and will include the current NodeApplicationMode as a parameter.
+ -->
+ <signal name="NodeApplicationMode">
+ <arg name="ApplicationModeId" type="i"/>
+ </signal>
+
+ <!--
+ SessionStateChanged:
+ @SessionStateName: The SessionName will be based upon either the pre-defined platform SessionNames or using a newly added product defined session name.
+ @SeatID: This parameter will be based upon the enum NsmSeat_e.
+ @SessionState: This parameter will be based upon the NsmSessionState_e but it will not be bounded by the values in that enumeration. The listed values are the default values that are mandatory for platform sessions, but product sessions may have additional session states.
+
+ This signal is sent to registered clients when a particular session is state is changed. The client can register for notification about a specific session through the use of the SessionName, as a "match rule".
+ -->
+ <signal name="SessionStateChanged">
+ <arg name="SessionStateName" type="s"/>
+ <arg name="SeatID" type="i"/>
+ <arg name="SessionState" type="i"/>
+ </signal>
+
+ <!--
+ GetNodeState:
+ @NodeStateId: Will be based on the NsmNodeState_e.
+ @ErrorCode: Return value passed to the caller, based upon NsmErrorStatus_e.
+
+ The method is used by other applications to get the NodeState without the need of registration to the signal.
+ -->
+ <method name="GetNodeState">
+ <arg name="NodeStateId" direction="out" type="i"/>
+ <arg name="ErrorCode" direction="out" type="i"/>
+ </method>
+
+ <!--
+ SetSessionState:
+ @SessionName: The SessionName will be based upon either the pre-defined platform SessionNames (see NSM content page) or using a newly added product defined session name.
+ @SessionOwner: This parameter defines the name of the application that is setting the state of the session. This must be the applications systemd unit filename.
+ @SeatID: This parameter will be based upon the enum NsmSeat_e
+ @SessionState: This parameter will be based upon the NsmSessionState_e but it will not be bounded by the values in that enumeration. The listed values are the default values that are mandatory for platform sessions, but product sessions may have additional SessionStates.
+ @ErrorCode: Return value passed to the caller, based upon NsmErrorStatus_e.
+
+ The method is used by applications to set the state of a session.
+ -->
+ <method name="SetSessionState">
+ <arg name="SessionName" direction="in" type="s"/>
+ <arg name="SessionOwner" direction="in" type="s"/>
+ <arg name="SeatID" direction="in" type="i"/>
+ <arg name="SessionState" direction="in" type="i"/>
+ <arg name="ErrorCode" direction="out" type="i"/>
+ </method>
+
+ <!--
+ GetSessionState:
+ @SessionName: The SessionName will be based upon either the pre-defined platform session names (see NSM content page) or using a newly added product defined SessionName.
+ @SeatID: This parameter will be based upon the enum NsmSeat_e.
+ @SessionState: This parameter will be based upon the NsmSessionState_e but it will not be bounded by the values in that enumeration. The listed values are the default values that are mandatory for platform sessions, but product sessions may have additional SessionStates.
+ @ErrorCode: Return value passed to the caller, based upon NsmErrorStatus_e.
+
+ The method is used by applications to get the state of a session.
+ -->
+ <method name="GetSessionState">
+ <arg name="SessionName" direction="in" type="s"/>
+ <arg name="SeatID" direction="in" type="i"/>
+ <arg name="SessionState" direction="out" type="i"/>
+ <arg name="ErrorCode" direction="out" type="i"/>
+ </method>
+
+ <!--
+ GetApplicationMode:
+ @ApplicationModeId: This parameter will be based upon the NsmNodeApplicationMode_e.
+ @ErrorCode: Return value passed to the caller, based upon NsmErrorStatus_e.
+
+ The method is used by other applications to get the application mode.
+ -->
+ <method name="GetApplicationMode">
+ <arg name="ApplicationModeId" direction="out" type="i"/>
+ <arg name="ErrorCode" direction="out" type="i"/>
+ </method>
+
+ <!--
+ RegisterShutdownClient:
+ @BusName: Bus name of remote application.
+ @ObjName: Object name of remote object that provides the shutdown interface.
+ @ShutdownMode: Shutdown mode for which client wants to be informed (i.e normal, fast etc).
+ @TimeoutMs: Max. Timeout to wait for response from shutdown client in ms.
+ @ErrorCode: Return value passed to the caller, based upon NsmErrorStatus_e.
+
+ The method is used by other applications to register themselves as shutdown client. Any client that registers must provide a method in their D-Bus object called "LifecycleRequest". This method will take one parameter which is the RequestType (NSM_SHUTDOWNTYPE_NORMAL, NSM_SHUTDOWNTYPE_FAST). For an example of the required client interface please see the BootManager component who will be a client of the NSM.
+ -->
+ <method name="RegisterShutdownClient">
+ <arg name="BusName" direction="in" type="s"/>
+ <arg name="ObjName" direction="in" type="s"/>
+ <arg name="ShutdownMode" direction="in" type="u"/>
+ <arg name="TimeoutMs" direction="in" type="u"/>
+ <arg name="ErrorCode" direction="out" type="i"/>
+ </method>
+
+ <!--
+ UnRegisterShutdownClient:
+ @BusName: Bus name of remote application.
+ @ObjName: Object name of remote object that provides the shutdown interface.
+ @ShutdownMode: Shutdown mode for which client wants to unregister (NSM_SHUTDOWNTYPE_NORMAL, NSM_SHUTDOWNTYPE_FAST).
+ @ErrorCode: Return value passed to the caller, based upon NsmErrorStatus_e.
+
+ The method is used by other applications to unregister themselves as shutdown client.
+ -->
+ <method name="UnRegisterShutdownClient">
+ <arg name="BusName" direction="in" type="s"/>
+ <arg name="ObjName" direction="in" type="s"/>
+ <arg name="ShutdownMode" direction="in" type="u"/>
+ <arg name="ErrorCode" direction="out" type="i"/>
+ </method>
+
+ <!--
+ RegisterSession:
+ @SessionName: The SessionName will be based upon either the pre-defined platform session names (see NSM content page) or using a newly added product defined SessionName.
+ @SessionOwner: This is the name of the application that is registering the new session (this must be the applications systemd unit filename).
+ @SeatID: This parameter will be based upon the enum NsmSeatId_e
+ @SessionState: This parameter will be based upon the NsmSessionState_e but it will not be bounded by the values in that enumeration. The listed values are the default values that are mandatory for platform sessions, but product sessions may have additional session states.
+ @ErrorCode: Return value passed to the caller, based upon NsmErrorStatus_e.
+
+ The method is used by other applications to register a new session whose state should be observed and distributed by the NSM.
+ -->
+ <method name="RegisterSession">
+ <arg name="SessionName" direction="in" type="s"/>
+ <arg name="SessionOwner" direction="in" type="s"/>
+ <arg name="SeatID" direction="in" type="i"/>
+ <arg name="SessionState" direction="in" type="i"/>
+ <arg name="ErrorCode" direction="out" type="i"/>
+ </method>
+
+ <!--
+ UnRegisterSession:
+ @SessionName: The SessionName will be based upon either the pre-defined platform session names (see NSM content page) or using a newly added product defined SessionName.
+ @SessionOwner: This is the name of the application that originally registered the session. It will be validated that this value matches the stored value from the registration.
+ @SeatID: This parameter will be based upon the enum NsmSeat_e.
+ @ErrorCode: Return value passed to the caller, based upon NsmErrorStatus_e.
+
+ The method is used by other applications to remove a new session from the session list hosted by NSM.
+ -->
+ <method name="UnRegisterSession">
+ <arg name="SessionName" direction="in" type="s"/>
+ <arg name="SessionOwner" direction="in" type="s"/>
+ <arg name="SeatID" direction="in" type="i"/>
+ <arg name="ErrorCode" direction="out" type="i"/>
+ </method>
+
+ <!--
+ GetAppHealthCount:
+ @Count: Return value passed to the caller. Number of applications that crashed or terminated accidentally.
+
+ The method returns the number of applications that crashed or terminated accidentally, within the current life cycle. It can be used to observe the system state.
+ -->
+ <method name="GetAppHealthCount">
+ <arg name="Count" direction="out" type="u"/>
+ </method>
+
+ <!--
+ GetInterfaceVersion:
+ @Version: Unsigned integer that represents the version number of the Node State Manager.
+
+ The method returns the version number of the Node State Manager. The number is organized in four bytes:
+
+ Version: VVV.RRR.PPP.BBB
+
+ <literallayout>
+ VVV => Version [1..255]
+ RRR => Release [0..255]
+ PPP => Patch [0..255]
+ BBB => Build [0..255]
+ </literallayout>
+ -->
+ <method name="GetInterfaceVersion">
+ <arg name="Version" direction="out" type="u"/>
+ </method>
+
+ <!--
+ LifecycleRequestComplete:
+ @RequestId: The request Id of the called life cycle client. The value has been passed when "LifecycleRequest" was called.
+ @Status: The result of the call to "LifecycleRequest". NsmErrorStatus_Ok: Request successfully processed. NsmErrorStatus_Error: An error occured while processing the "LifecycleRequest".
+ @ErrorCode: Return value passed to the caller, based upon NsmErrorStatus_e.
+
+ The function has to be called by a "asynchrounous" lifecycle client, when he processed the "LifecycleRequest".
+ -->
+ <method name="LifecycleRequestComplete">
+ <arg name="RequestId" direction="in" type="u"/>
+ <arg name="Status" direction="in" type="i"/>
+ <arg name="ErrorCode" direction="out" type="i"/>
+ </method>
+ </interface>
+</node>
diff --git a/src/test/fakeLegacyService/fake/legacy/service/LegacyInterface.h b/src/test/fakeLegacyService/fake/legacy/service/LegacyInterface.h
new file mode 100644
index 0000000..4b1720d
--- /dev/null
+++ b/src/test/fakeLegacyService/fake/legacy/service/LegacyInterface.h
@@ -0,0 +1,38 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+#ifndef FAKE_LEGACY_SERVICE_LEGACY_INTERFACE_H_
+#define FAKE_LEGACY_SERVICE_LEGACY_INTERFACE_H_
+
+#include <CommonAPI/types.h>
+
+namespace fake {
+namespace legacy {
+namespace service {
+
+class LegacyInterface {
+ public:
+ virtual ~LegacyInterface() { }
+
+ static inline const char* getInterfaceId();
+ static inline CommonAPI::Version getInterfaceVersion();
+};
+
+const char* LegacyInterface::getInterfaceId() {
+ return "fake.legacy.service.LegacyInterface";
+}
+
+CommonAPI::Version LegacyInterface::getInterfaceVersion() {
+ return CommonAPI::Version(1, 0);
+}
+
+
+} // namespace service
+} // namespace legacy
+} // namespace fake
+
+namespace CommonAPI {
+
+}
+
+#endif // FAKE_LEGACY_SERVICE_LEGACY_INTERFACE_H_
diff --git a/src/test/fakeLegacyService/fake/legacy/service/LegacyInterfaceDBusProxy.cpp b/src/test/fakeLegacyService/fake/legacy/service/LegacyInterfaceDBusProxy.cpp
new file mode 100644
index 0000000..292e0c6
--- /dev/null
+++ b/src/test/fakeLegacyService/fake/legacy/service/LegacyInterfaceDBusProxy.cpp
@@ -0,0 +1,97 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+#include "LegacyInterfaceDBusProxy.h"
+
+namespace fake {
+namespace legacy {
+namespace service {
+
+std::shared_ptr<CommonAPI::DBus::DBusProxy> createLegacyInterfaceDBusProxy(
+ const std::string& commonApiAddress,
+ const std::string& interfaceName,
+ const std::string& busName,
+ const std::string& objectPath,
+ const std::shared_ptr<CommonAPI::DBus::DBusProxyConnection>& dbusProxyConnection) {
+ return std::make_shared<LegacyInterfaceDBusProxy>(commonApiAddress, interfaceName, busName, objectPath, dbusProxyConnection);
+}
+
+__attribute__((constructor)) void registerLegacyInterfaceDBusProxy(void) {
+ CommonAPI::DBus::DBusFactory::registerProxyFactoryMethod(LegacyInterface::getInterfaceId(),
+ &createLegacyInterfaceDBusProxy);
+}
+
+LegacyInterfaceDBusProxy::LegacyInterfaceDBusProxy(
+ const std::string& commonApiAddress,
+ const std::string& interfaceName,
+ const std::string& busName,
+ const std::string& objectPath,
+ const std::shared_ptr<CommonAPI::DBus::DBusProxyConnection>& dbusProxyconnection):
+ CommonAPI::DBus::DBusProxy(commonApiAddress, interfaceName, busName, objectPath, dbusProxyconnection)
+ {
+}
+
+
+
+void LegacyInterfaceDBusProxy::TestMethod(const int32_t& input, CommonAPI::CallStatus& callStatus, int32_t& val1, int32_t& val2) {
+ CommonAPI::DBus::DBusProxyHelper<CommonAPI::DBus::DBusSerializableArguments<int32_t>,
+ CommonAPI::DBus::DBusSerializableArguments<int32_t, int32_t> >::callMethodWithReply(
+ *this,
+ "TestMethod",
+ "i",
+ input,
+ callStatus
+ , val1, val2);
+}
+std::future<CommonAPI::CallStatus> LegacyInterfaceDBusProxy::TestMethodAsync(const int32_t& input, TestMethodAsyncCallback callback) {
+ return CommonAPI::DBus::DBusProxyHelper<CommonAPI::DBus::DBusSerializableArguments<int32_t>,
+ CommonAPI::DBus::DBusSerializableArguments<int32_t, int32_t> >::callMethodAsync(
+ *this,
+ "TestMethod",
+ "i",
+ input,
+ std::move(callback));
+}
+void LegacyInterfaceDBusProxy::OtherTestMethod(CommonAPI::CallStatus& callStatus, std::string& greeting, int32_t& identifier) {
+ CommonAPI::DBus::DBusProxyHelper<CommonAPI::DBus::DBusSerializableArguments<>,
+ CommonAPI::DBus::DBusSerializableArguments<std::string, int32_t> >::callMethodWithReply(
+ *this,
+ "OtherTestMethod",
+ "",
+ callStatus
+ , greeting, identifier);
+}
+std::future<CommonAPI::CallStatus> LegacyInterfaceDBusProxy::OtherTestMethodAsync(OtherTestMethodAsyncCallback callback) {
+ return CommonAPI::DBus::DBusProxyHelper<CommonAPI::DBus::DBusSerializableArguments<>,
+ CommonAPI::DBus::DBusSerializableArguments<std::string, int32_t> >::callMethodAsync(
+ *this,
+ "OtherTestMethod",
+ "",
+ std::move(callback));
+}
+void LegacyInterfaceDBusProxy::finish(CommonAPI::CallStatus& callStatus) {
+ CommonAPI::DBus::DBusProxyHelper<CommonAPI::DBus::DBusSerializableArguments<>,
+ CommonAPI::DBus::DBusSerializableArguments<> >::callMethodWithReply(
+ *this,
+ "finish",
+ "",
+ callStatus
+ );
+}
+std::future<CommonAPI::CallStatus> LegacyInterfaceDBusProxy::finishAsync(FinishAsyncCallback callback) {
+ return CommonAPI::DBus::DBusProxyHelper<CommonAPI::DBus::DBusSerializableArguments<>,
+ CommonAPI::DBus::DBusSerializableArguments<> >::callMethodAsync(
+ *this,
+ "finish",
+ "",
+ std::move(callback));
+}
+
+void LegacyInterfaceDBusProxy::getOwnVersion(uint16_t& ownVersionMajor, uint16_t& ownVersionMinor) const {
+ ownVersionMajor = 1;
+ ownVersionMinor = 0;
+}
+
+} // namespace service
+} // namespace legacy
+} // namespace fake
diff --git a/src/test/fakeLegacyService/fake/legacy/service/LegacyInterfaceDBusProxy.h b/src/test/fakeLegacyService/fake/legacy/service/LegacyInterfaceDBusProxy.h
new file mode 100644
index 0000000..db13b78
--- /dev/null
+++ b/src/test/fakeLegacyService/fake/legacy/service/LegacyInterfaceDBusProxy.h
@@ -0,0 +1,48 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+#ifndef FAKE_LEGACY_SERVICE_LEGACY_INTERFACE_DBUS_PROXY_H_
+#define FAKE_LEGACY_SERVICE_LEGACY_INTERFACE_DBUS_PROXY_H_
+
+#include "LegacyInterfaceProxyBase.h"
+#include <CommonAPI/DBus/DBusFactory.h>
+#include <CommonAPI/DBus/DBusProxy.h>
+
+#include <string>
+
+namespace fake {
+namespace legacy {
+namespace service {
+
+class LegacyInterfaceDBusProxy: virtual public LegacyInterfaceProxyBase, virtual public CommonAPI::DBus::DBusProxy {
+ public:
+ LegacyInterfaceDBusProxy(
+ const std::string& commonApiAddress,
+ const std::string& interfaceName,
+ const std::string& busName,
+ const std::string& objectPath,
+ const std::shared_ptr<CommonAPI::DBus::DBusProxyConnection>& dbusProxyconnection);
+
+
+
+
+ virtual void TestMethod(const int32_t& input, CommonAPI::CallStatus& callStatus, int32_t& val1, int32_t& val2);
+ virtual std::future<CommonAPI::CallStatus> TestMethodAsync(const int32_t& input, TestMethodAsyncCallback callback);
+
+ virtual void OtherTestMethod(CommonAPI::CallStatus& callStatus, std::string& greeting, int32_t& identifier);
+ virtual std::future<CommonAPI::CallStatus> OtherTestMethodAsync(OtherTestMethodAsyncCallback callback);
+
+ virtual void finish(CommonAPI::CallStatus& callStatus);
+ virtual std::future<CommonAPI::CallStatus> finishAsync(FinishAsyncCallback callback);
+
+ virtual void getOwnVersion(uint16_t& ownVersionMajor, uint16_t& ownVersionMinor) const;
+
+ private:
+
+};
+
+} // namespace service
+} // namespace legacy
+} // namespace fake
+
+#endif // FAKE_LEGACY_SERVICE_LEGACY_INTERFACE_DBUS_PROXY_H_
diff --git a/src/test/fakeLegacyService/fake/legacy/service/LegacyInterfaceProxy.h b/src/test/fakeLegacyService/fake/legacy/service/LegacyInterfaceProxy.h
new file mode 100644
index 0000000..bb231cb
--- /dev/null
+++ b/src/test/fakeLegacyService/fake/legacy/service/LegacyInterfaceProxy.h
@@ -0,0 +1,131 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+#ifndef FAKE_LEGACY_SERVICE_LEGACY_INTERFACE_PROXY_H_
+#define FAKE_LEGACY_SERVICE_LEGACY_INTERFACE_PROXY_H_
+
+#include "LegacyInterfaceProxyBase.h"
+
+namespace fake {
+namespace legacy {
+namespace service {
+
+template <typename ... _AttributeExtensions>
+class LegacyInterfaceProxy: virtual public LegacyInterface, virtual public LegacyInterfaceProxyBase, public _AttributeExtensions... {
+ public:
+ LegacyInterfaceProxy(std::shared_ptr<CommonAPI::Proxy> delegate);
+ ~LegacyInterfaceProxy();
+
+
+
+
+ virtual void TestMethod(const int32_t& input, CommonAPI::CallStatus& callStatus, int32_t& val1, int32_t& val2);
+ virtual std::future<CommonAPI::CallStatus> TestMethodAsync(const int32_t& input, TestMethodAsyncCallback callback);
+
+ virtual void OtherTestMethod(CommonAPI::CallStatus& callStatus, std::string& greeting, int32_t& identifier);
+ virtual std::future<CommonAPI::CallStatus> OtherTestMethodAsync(OtherTestMethodAsyncCallback callback);
+
+ virtual void finish(CommonAPI::CallStatus& callStatus);
+ virtual std::future<CommonAPI::CallStatus> finishAsync(FinishAsyncCallback callback);
+
+ virtual std::string getAddress() const;
+ virtual const std::string& getDomain() const;
+ virtual const std::string& getServiceId() const;
+ virtual const std::string& getInstanceId() const;
+ virtual bool isAvailable() const;
+ virtual CommonAPI::ProxyStatusEvent& getProxyStatusEvent();
+ virtual CommonAPI::InterfaceVersionAttribute& getInterfaceVersionAttribute();
+
+ private:
+ std::shared_ptr<LegacyInterfaceProxyBase> delegate_;
+};
+
+
+//
+// LegacyInterfaceProxy Implementation
+//
+template <typename ... _AttributeExtensions>
+LegacyInterfaceProxy<_AttributeExtensions...>::LegacyInterfaceProxy(std::shared_ptr<CommonAPI::Proxy> delegate):
+ delegate_(std::dynamic_pointer_cast<LegacyInterfaceProxyBase>(delegate)),
+ _AttributeExtensions(*(std::dynamic_pointer_cast<LegacyInterfaceProxyBase>(delegate)))... {
+}
+
+template <typename ... _AttributeExtensions>
+LegacyInterfaceProxy<_AttributeExtensions...>::~LegacyInterfaceProxy() {
+}
+
+
+
+template <typename ... _AttributeExtensions>
+void LegacyInterfaceProxy<_AttributeExtensions...>::TestMethod(const int32_t& input, CommonAPI::CallStatus& callStatus, int32_t& val1, int32_t& val2) {
+ delegate_->TestMethod(input, callStatus, val1, val2);
+}
+
+template <typename ... _AttributeExtensions>
+std::future<CommonAPI::CallStatus> LegacyInterfaceProxy<_AttributeExtensions...>::TestMethodAsync(const int32_t& input, TestMethodAsyncCallback callback) {
+ return delegate_->TestMethodAsync(input, callback);
+}
+
+template <typename ... _AttributeExtensions>
+void LegacyInterfaceProxy<_AttributeExtensions...>::OtherTestMethod(CommonAPI::CallStatus& callStatus, std::string& greeting, int32_t& identifier) {
+ delegate_->OtherTestMethod(callStatus, greeting, identifier);
+}
+
+template <typename ... _AttributeExtensions>
+std::future<CommonAPI::CallStatus> LegacyInterfaceProxy<_AttributeExtensions...>::OtherTestMethodAsync(OtherTestMethodAsyncCallback callback) {
+ return delegate_->OtherTestMethodAsync(callback);
+}
+
+template <typename ... _AttributeExtensions>
+void LegacyInterfaceProxy<_AttributeExtensions...>::finish(CommonAPI::CallStatus& callStatus) {
+ delegate_->finish(callStatus);
+}
+
+template <typename ... _AttributeExtensions>
+std::future<CommonAPI::CallStatus> LegacyInterfaceProxy<_AttributeExtensions...>::finishAsync(FinishAsyncCallback callback) {
+ return delegate_->finishAsync(callback);
+}
+
+
+template <typename ... _AttributeExtensions>
+std::string LegacyInterfaceProxy<_AttributeExtensions...>::getAddress() const {
+ return delegate_->getAddress();
+}
+
+template <typename ... _AttributeExtensions>
+const std::string& LegacyInterfaceProxy<_AttributeExtensions...>::getDomain() const {
+ return delegate_->getDomain();
+}
+
+template <typename ... _AttributeExtensions>
+const std::string& LegacyInterfaceProxy<_AttributeExtensions...>::getServiceId() const {
+ return delegate_->getServiceId();
+}
+
+template <typename ... _AttributeExtensions>
+const std::string& LegacyInterfaceProxy<_AttributeExtensions...>::getInstanceId() const {
+ return delegate_->getInstanceId();
+}
+
+template <typename ... _AttributeExtensions>
+bool LegacyInterfaceProxy<_AttributeExtensions...>::isAvailable() const {
+ return delegate_->isAvailable();
+}
+
+template <typename ... _AttributeExtensions>
+CommonAPI::ProxyStatusEvent& LegacyInterfaceProxy<_AttributeExtensions...>::getProxyStatusEvent() {
+ return delegate_->getProxyStatusEvent();
+}
+
+template <typename ... _AttributeExtensions>
+CommonAPI::InterfaceVersionAttribute& LegacyInterfaceProxy<_AttributeExtensions...>::getInterfaceVersionAttribute() {
+ return delegate_->getInterfaceVersionAttribute();
+}
+
+} // namespace service
+} // namespace legacy
+} // namespace fake
+
+
+
+#endif // FAKE_LEGACY_SERVICE_LEGACY_INTERFACE_PROXY_H_
diff --git a/src/test/fakeLegacyService/fake/legacy/service/LegacyInterfaceProxyBase.h b/src/test/fakeLegacyService/fake/legacy/service/LegacyInterfaceProxyBase.h
new file mode 100644
index 0000000..fb430e0
--- /dev/null
+++ b/src/test/fakeLegacyService/fake/legacy/service/LegacyInterfaceProxyBase.h
@@ -0,0 +1,40 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+#ifndef FAKE_LEGACY_SERVICE_LEGACY_INTERFACE_PROXY_BASE_H_
+#define FAKE_LEGACY_SERVICE_LEGACY_INTERFACE_PROXY_BASE_H_
+
+#include "LegacyInterface.h"
+#include <CommonAPI/Proxy.h>
+#include <functional>
+#include <future>
+
+namespace fake {
+namespace legacy {
+namespace service {
+
+class LegacyInterfaceProxyBase: virtual public CommonAPI::Proxy {
+ public:
+ typedef std::function<void(const CommonAPI::CallStatus&, const int32_t&, const int32_t&)> TestMethodAsyncCallback;
+ typedef std::function<void(const CommonAPI::CallStatus&, const std::string&, const int32_t&)> OtherTestMethodAsyncCallback;
+ typedef std::function<void(const CommonAPI::CallStatus&)> FinishAsyncCallback;
+
+
+
+
+ virtual void TestMethod(const int32_t& input, CommonAPI::CallStatus& callStatus, int32_t& val1, int32_t& val2) = 0;
+ virtual std::future<CommonAPI::CallStatus> TestMethodAsync(const int32_t& input, TestMethodAsyncCallback callback) = 0;
+
+ virtual void OtherTestMethod(CommonAPI::CallStatus& callStatus, std::string& greeting, int32_t& identifier) = 0;
+ virtual std::future<CommonAPI::CallStatus> OtherTestMethodAsync(OtherTestMethodAsyncCallback callback) = 0;
+
+ virtual void finish(CommonAPI::CallStatus& callStatus) = 0;
+ virtual std::future<CommonAPI::CallStatus> finishAsync(FinishAsyncCallback callback) = 0;
+};
+
+
+} // namespace service
+} // namespace legacy
+} // namespace fake
+
+#endif // FAKE_LEGACY_SERVICE_LEGACY_INTERFACE_PROXY_BASE_H_
diff --git a/src/test/fakeLegacyService/fakeLegacyService.fidl b/src/test/fakeLegacyService/fakeLegacyService.fidl
new file mode 100644
index 0000000..6aaa8a8
--- /dev/null
+++ b/src/test/fakeLegacyService/fakeLegacyService.fidl
@@ -0,0 +1,24 @@
+package fake.legacy.service
+
+interface LegacyInterface {
+ version { major 1 minor 0 }
+
+ method TestMethod {
+ in {
+ Int32 input
+ }
+ out {
+ Int32 val1
+ Int32 val2
+ }
+ }
+
+ method OtherTestMethod {
+ out {
+ String greeting
+ Int32 identifier
+ }
+ }
+
+ method finish {}
+}
diff --git a/src/test/fakeLegacyService/fakeLegacyService.py b/src/test/fakeLegacyService/fakeLegacyService.py
new file mode 100644
index 0000000..b082efd
--- /dev/null
+++ b/src/test/fakeLegacyService/fakeLegacyService.py
@@ -0,0 +1,52 @@
+# Copyright (C) 2013 BMW Group
+# Author: Manfred Bathelt (manfred.bathelt@bmw.de)
+# Author: Juergen Gehring (juergen.gehring@bmw.de)
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+import sys
+import traceback
+import gobject
+import math
+import dbus
+import dbus.service
+import dbus.mainloop.glib
+
+loop = gobject.MainLoop()
+dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
+
+class FakeLegacyService(dbus.service.Object):
+ def __init__(self, loop):
+ busName = dbus.service.BusName('fake.legacy.service.connection', bus = dbus.SessionBus())
+ dbus.service.Object.__init__(self, busName, '/some/legacy/path/6259504')
+ #self.properties = {'RestartReason': 1, 'ShutdownReason': 2, 'WakeUpReason' :3, 'BootMode' :4}
+ self.ABus=""
+ self.APath=""
+ self.loop=loop
+
+ @dbus.service.method(dbus_interface='fake.legacy.service.Introspectable', out_signature = 's')
+ def Introspect(self):
+ f = open('fake.legacy.service.xml', "r")
+ text = f.read()
+ return text
+
+ @dbus.service.method(dbus_interface='fake.legacy.service.LegacyInterface', in_signature = 'i', out_signature = 'ii')
+ def TestMethod(self, input):
+ val1=input - 5
+ val2=input + 5
+ return val1, val2
+
+ @dbus.service.method(dbus_interface='fake.legacy.service.LegacyInterface', out_signature = 'si')
+ def OtherTestMethod(self):
+ greeting='Hello'
+ identifier=42
+ return greeting, identifier
+
+ @dbus.service.method(dbus_interface='fake.legacy.service.LegacyInterface')
+ def finish(self):
+ self.loop.quit()
+ return 0
+
+nsm = FakeLegacyService(loop)
+loop.run()
diff --git a/src/test/fakeLegacyService/sendToFakeLegacyService.py b/src/test/fakeLegacyService/sendToFakeLegacyService.py
new file mode 100644
index 0000000..ea23a74
--- /dev/null
+++ b/src/test/fakeLegacyService/sendToFakeLegacyService.py
@@ -0,0 +1,23 @@
+# Copyright (C) 2013 BMW Group
+# Author: Manfred Bathelt (manfred.bathelt@bmw.de)
+# Author: Juergen Gehring (juergen.gehring@bmw.de)
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+import sys
+import traceback
+import gobject
+import math
+import dbus
+import dbus.service
+
+def finish():
+ bus = dbus.SessionBus()
+ remote_object = bus.get_object('fake.legacy.service.connection','/some/legacy/path/6259504')
+ iface = dbus.Interface(remote_object, 'fake.legacy.service.LegacyInterface')
+ iface.finish()
+
+command=sys.argv[1]
+if command=="finish":
+ finish()
diff --git a/src/test/test-derived-types.fidl b/src/test/test-derived-types.fidl
new file mode 100644
index 0000000..7b8c477
--- /dev/null
+++ b/src/test/test-derived-types.fidl
@@ -0,0 +1,56 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+package commonapi.tests
+
+import commonapi.tests.* from "test-predefined-types.fidl"
+
+typeCollection DerivedTypeCollection {
+ <** @description : Common errors. **>
+ enumeration TestEnum {
+ <** @description : default **>
+ E_UNKNOWN = "0x00"
+ <** @description : no error - positive reply **>
+ E_OK = "0x01"
+ <** @description : value out of range **>
+ E_OUT_OF_RANGE = "0x02"
+ <** @description : not used **>
+ E_NOT_USED = "0x03"
+ }
+
+ enumeration TestEnumMissingValue {
+ <** @description : default **>
+ E1 = "A"
+ E2
+ E3 = "2"
+ }
+
+ enumeration TestEnumExtended extends TestEnum {
+ <** @description : new error **>
+ E_NEW = "0x04"
+ }
+
+ enumeration TestEnumExtended2 extends TestEnumExtended {
+ <** @description : new error **>
+ E_NEW2 = "0x05"
+ }
+
+ struct TestStruct {
+ <** @description : the name of the property **>
+ PredefinedTypeCollection.TestString testString
+
+ <** @description : the actual value **>
+ UInt16 uintValue
+ }
+
+ struct TestStructExtended extends TestStruct {
+ TestEnumExtended2 testEnumExtended2
+ }
+
+ array TestArrayUInt64 of UInt64
+ array TestArrayTestStruct of TestStruct
+
+ map TestMap { UInt32 to TestArrayTestStruct }
+}
+
+
diff --git a/src/test/test-interface-proxy.fidl b/src/test/test-interface-proxy.fidl
new file mode 100644
index 0000000..88d4874
--- /dev/null
+++ b/src/test/test-interface-proxy.fidl
@@ -0,0 +1,58 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+package commonapi.tests
+
+import commonapi.tests.* from "test-derived-types.fidl"
+
+interface TestInterface {
+ version { major 1 minor 0 }
+
+ attribute UInt32 TestPredefinedTypeAttribute
+ attribute DerivedTypeCollection.TestStructExtended TestDerivedStructAttribute
+ attribute DerivedTypeCollection.TestArrayUInt64 TestDerivedArrayAttribute
+
+ method testVoidPredefinedTypeMethod {
+ in {
+ UInt32 uint32Value
+ String stringValue
+ }
+ }
+
+ method testPredefinedTypeMethod {
+ in {
+ UInt32 uint32InValue
+ String stringInValue
+ }
+ out {
+ UInt32 uint32OutValue
+ String stringOutValue
+ }
+ }
+
+ method testVoidDerivedTypeMethod {
+ in {
+ DerivedTypeCollection.TestEnumExtended2 testEnumExtended2Value
+ DerivedTypeCollection.TestMap testMapValue
+ }
+ }
+
+ method testDerivedTypeMethod {
+ in {
+ DerivedTypeCollection.TestEnumExtended2 testEnumExtended2InValue
+ DerivedTypeCollection.TestMap testMapInValue
+ }
+ out {
+ DerivedTypeCollection.TestEnumExtended2 testEnumExtended2OutValue
+ DerivedTypeCollection.TestMap testMapOutValue
+ }
+ }
+
+ broadcast TestPredefinedTypeBroadcast {
+ out {
+ UInt32 uint32Value
+ String stringValue
+ }
+ }
+}
+
diff --git a/src/test/test-predefined-types.fidl b/src/test/test-predefined-types.fidl
new file mode 100644
index 0000000..6226ed2
--- /dev/null
+++ b/src/test/test-predefined-types.fidl
@@ -0,0 +1,22 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+package commonapi.tests
+
+typeCollection PredefinedTypeCollection {
+ typedef TestUInt8 is UInt8
+ typedef TestUInt16 is UInt16
+ typedef TestUInt32 is UInt32
+ typedef TestUInt64 is UInt64
+ typedef TestInt8 is Int8
+ typedef TestInt16 is Int16
+ typedef TestInt32 is Int32
+ typedef TestInt64 is Int64
+ typedef TestBoolean is Boolean
+ typedef TestByteBuffer is ByteBuffer
+ typedef TestDouble is Double
+ typedef TestFloat is Float
+ typedef TestString is String
+}
+
+