From: Aleksandar Kanchev Date: Wed, 13 Feb 2013 11:59:13 +0000 (+0100) Subject: add gitattributes and proper crlf handling X-Git-Tag: gpt_6_1_pre~73 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=e968ffd5f7640320e941e9cb94367636d73b19a1;p=profile%2Fivi%2Fcommon-api-dbus-runtime.git add gitattributes and proper crlf handling --- 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/README.html b/README.html index 825ca85..3da4e2d 100644 --- a/README.html +++ b/README.html @@ -1,506 +1,506 @@ - - - - - -GENIVI_CommonAPI-D-Bus - - - - - -
-

Copyright © 2013, GENIVI Alliance, Inc. -Copyright © 2013, BMW AG

-

This file is part of GENIVI Project IPC Common API.

-

Contributions are licensed to the GENIVI Alliance under one or more -Contribution License Agreements or MPL 2.0 .

-

© 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 http://mozilla.org/MPL/2.0/.

- -
-

License

-
-

This project is licensed under MPL 2.0

-

Contribution is done under GENIVI CLA or MPL2.0.

-
-

Version

-
-

The current version can be taken from the git.

-
-

Common API Overview

-
-

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:

-
-
-
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 -> 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 -> Common API D-Bus C++ code.
-
-
-

Build Instructions

-
-

Requirements

-

To build this package the CommonAPI library and a version of libdbus patched with the marshaling patch must be available through PkgConfig.

-

Instructions for making a patched version of libdbus available in /usr/local:

-
-
-
# 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 < /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
-
-

The path to CommonAPI and patched libdbus pkgconfig files must be added to the PKG_CONFIG_PATH for the entire build process.

-

For example, if CommonAPI and patched dbus are available in /usr/local, set the PKG_CONFIG_PATH variable as follows:

-
-
-
# export PKG_CONFIG_PATH="/usr/local/lib/pkgconfig:$PKG_CONFIG_PATH"
-
-

Instructions

-

Use autotools to build this package withthe above requirements available through Pkgconfig :

-
-
-
# ./autoreconf -i
-# ./configure
-# make
-# sudo make install (or alternative install process, eg. checkinstall on debian-based distributions, such as Ubuntu)
-
-

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.

-
-

Working on the code & contribution

-
-
-
First get the code from the git:
-
-
git clone
-
-
-
Get an overview of all branches:
-
-
git branch
-
-
-
Switch to the branch you want to work on (master is the feature branch) and verify that it has switched (* changed)
-
-
git checkout <your branch>
-git branch
-
-
-
Best practice is to create a local branch based on the current branch:
-
-
git branch working_branch
-
-

Start working, best practice is to commit smaller, compilable pieces during the development process that makes it easier to handle later on.

-
-
If you want to commit you changes, send them to the author, you can create a patch like this:
-
-
git format-patch working_branch <your branch>
-
-

This creates a set of patches that are published via the mailing list.The patches will be discussed and then merged & uploaded on the git by the maintainer.

-

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 http://gerrit.googlecode.com/svn/documentation/2.0/user-signedoffby.html

-
- - - + + + + + +GENIVI_CommonAPI-D-Bus + + + + + +
+

Copyright © 2013, GENIVI Alliance, Inc. +Copyright © 2013, BMW AG

+

This file is part of GENIVI Project IPC Common API.

+

Contributions are licensed to the GENIVI Alliance under one or more +Contribution License Agreements or MPL 2.0 .

+

© 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 http://mozilla.org/MPL/2.0/.

+ +
+

License

+
+

This project is licensed under MPL 2.0

+

Contribution is done under GENIVI CLA or MPL2.0.

+
+

Version

+
+

The current version can be taken from the git.

+
+

Common API Overview

+
+

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:

+
+
+
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 -> 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 -> Common API D-Bus C++ code.
+
+
+

Build Instructions

+
+

Requirements

+

To build this package the CommonAPI library and a version of libdbus patched with the marshaling patch must be available through PkgConfig.

+

Instructions for making a patched version of libdbus available in /usr/local:

+
+
+
# 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 < /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
+
+

The path to CommonAPI and patched libdbus pkgconfig files must be added to the PKG_CONFIG_PATH for the entire build process.

+

For example, if CommonAPI and patched dbus are available in /usr/local, set the PKG_CONFIG_PATH variable as follows:

+
+
+
# export PKG_CONFIG_PATH="/usr/local/lib/pkgconfig:$PKG_CONFIG_PATH"
+
+

Instructions

+

Use autotools to build this package withthe above requirements available through Pkgconfig :

+
+
+
# ./autoreconf -i
+# ./configure
+# make
+# sudo make install (or alternative install process, eg. checkinstall on debian-based distributions, such as Ubuntu)
+
+

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.

+
+

Working on the code & contribution

+
+
+
First get the code from the git:
+
+
git clone
+
+
+
Get an overview of all branches:
+
+
git branch
+
+
+
Switch to the branch you want to work on (master is the feature branch) and verify that it has switched (* changed)
+
+
git checkout <your branch>
+git branch
+
+
+
Best practice is to create a local branch based on the current branch:
+
+
git branch working_branch
+
+

Start working, best practice is to commit smaller, compilable pieces during the development process that makes it easier to handle later on.

+
+
If you want to commit you changes, send them to the author, you can create a patch like this:
+
+
git format-patch working_branch <your branch>
+
+

This creates a set of patches that are published via the mailing list.The patches will be discussed and then merged & uploaded on the git by the maintainer.

+

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 http://gerrit.googlecode.com/svn/documentation/2.0/user-signedoffby.html

+
+ + + diff --git a/src/CommonAPI/DBus/DBusDaemonProxy.cpp b/src/CommonAPI/DBus/DBusDaemonProxy.cpp index 9ed2ba6..8eaa807 100644 --- a/src/CommonAPI/DBus/DBusDaemonProxy.cpp +++ b/src/CommonAPI/DBus/DBusDaemonProxy.cpp @@ -1,108 +1,108 @@ -/* 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& connection): - DBusProxy(getInterfaceName(), "org.freedesktop.DBus", "/org/freedesktop/DBus", connection, true), - nameOwnerChangedEvent_(*this, "NameOwnerChanged", "sss") { -} - -DBusDaemonProxy::NameOwnerChangedEvent& DBusDaemonProxy::getNameOwnerChangedEvent() { - return nameOwnerChangedEvent_; -} - -void DBusDaemonProxy::listNames(CommonAPI::CallStatus& callStatus, std::vector& 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>::deserialize(inputStream, busNames); - if (!success) { - callStatus = CallStatus::REMOTE_ERROR; - return; - } - callStatus = CallStatus::SUCCESS; - -} - -std::future DBusDaemonProxy::listNamesAsync(ListNamesAsyncCallback listNamesAsyncCallback) const { - DBusMessage dbusMessage = createMethodCall("ListNames", ""); - - return getDBusConnection()->sendDBusMessageWithReplyAsync( - dbusMessage, - DBusProxyAsyncCallbackHandler>::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::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::deserialize(inputStream, hasOwner); - if (!success) { - callStatus = CallStatus::REMOTE_ERROR; - return; - } - callStatus = CallStatus::SUCCESS; - -} - -std::future DBusDaemonProxy::nameHasOwnerAsync(const std::string& busName, NameHasOwnerAsyncCallback nameHasOwnerAsyncCallback) const { - - DBusMessage dbusMessage = createMethodCall("NameHasOwner", "s"); - - DBusOutputStream outputStream(dbusMessage); - const bool success = DBusSerializableArguments::serialize(outputStream, busName); - if (!success) { - std::promise promise; - promise.set_value(CallStatus::OUT_OF_MEMORY); - return promise.get_future(); - } - outputStream.flush(); - - return getDBusConnection()->sendDBusMessageWithReplyAsync( - dbusMessage, - DBusProxyAsyncCallbackHandler::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 { + +DBusDaemonProxy::DBusDaemonProxy(const std::shared_ptr& connection): + DBusProxy(getInterfaceName(), "org.freedesktop.DBus", "/org/freedesktop/DBus", connection, true), + nameOwnerChangedEvent_(*this, "NameOwnerChanged", "sss") { +} + +DBusDaemonProxy::NameOwnerChangedEvent& DBusDaemonProxy::getNameOwnerChangedEvent() { + return nameOwnerChangedEvent_; +} + +void DBusDaemonProxy::listNames(CommonAPI::CallStatus& callStatus, std::vector& 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>::deserialize(inputStream, busNames); + if (!success) { + callStatus = CallStatus::REMOTE_ERROR; + return; + } + callStatus = CallStatus::SUCCESS; + +} + +std::future DBusDaemonProxy::listNamesAsync(ListNamesAsyncCallback listNamesAsyncCallback) const { + DBusMessage dbusMessage = createMethodCall("ListNames", ""); + + return getDBusConnection()->sendDBusMessageWithReplyAsync( + dbusMessage, + DBusProxyAsyncCallbackHandler>::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::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::deserialize(inputStream, hasOwner); + if (!success) { + callStatus = CallStatus::REMOTE_ERROR; + return; + } + callStatus = CallStatus::SUCCESS; + +} + +std::future DBusDaemonProxy::nameHasOwnerAsync(const std::string& busName, NameHasOwnerAsyncCallback nameHasOwnerAsyncCallback) const { + + DBusMessage dbusMessage = createMethodCall("NameHasOwner", "s"); + + DBusOutputStream outputStream(dbusMessage); + const bool success = DBusSerializableArguments::serialize(outputStream, busName); + if (!success) { + std::promise promise; + promise.set_value(CallStatus::OUT_OF_MEMORY); + return promise.get_future(); + } + outputStream.flush(); + + return getDBusConnection()->sendDBusMessageWithReplyAsync( + dbusMessage, + DBusProxyAsyncCallbackHandler::create(nameHasOwnerAsyncCallback)); + +} + +void DBusDaemonProxy::getOwnVersion(uint16_t& ownVersionMajor, uint16_t& ownVersionMinor) const { +} + +} // namespace DBus +} // namespace CommonAPI diff --git a/src/CommonAPI/DBus/DBusDaemonProxy.h b/src/CommonAPI/DBus/DBusDaemonProxy.h index 307bfc8..175b1cb 100644 --- a/src/CommonAPI/DBus/DBusDaemonProxy.h +++ b/src/CommonAPI/DBus/DBusDaemonProxy.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_DAEMON_PROXY_H_ -#define COMMONAPI_DBUS_DBUS_DAEMON_PROXY_H_ - -#include "DBusProxy.h" -#include "DBusEvent.h" - -#include "DBusServiceStatusEvent.h" - -#include -#include - -namespace CommonAPI { -namespace DBus { - -class DBusServiceStatusEvent; - -class DBusDaemonProxy: public DBusProxy { - - public: - typedef Event NameOwnerChangedEvent; - typedef std::function)> ListNamesAsyncCallback; - typedef std::function NameHasOwnerAsyncCallback; - - - DBusDaemonProxy(const std::shared_ptr& connection); - - inline const char* getInterfaceName() const; - - NameOwnerChangedEvent& getNameOwnerChangedEvent(); - - void listNames(CommonAPI::CallStatus& callStatus, std::vector& busNames) const; - std::future listNamesAsync(ListNamesAsyncCallback listNamesAsyncCallback) const; - - void nameHasOwner(const std::string& busName, CommonAPI::CallStatus& callStatus, bool& hasOwner) const; - std::future nameHasOwnerAsync(const std::string& busName, NameHasOwnerAsyncCallback nameHasOwnerAsyncCallback) const; - - protected: - void getOwnVersion(uint16_t& ownVersionMajor, uint16_t& ownVersionMinor) const; - - private: - DBusEvent nameOwnerChangedEvent_; -}; - -const char* DBusDaemonProxy::getInterfaceName() const { - return "org.freedesktop.DBus"; -} - -} // 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 "DBusProxy.h" +#include "DBusEvent.h" + +#include "DBusServiceStatusEvent.h" + +#include +#include + +namespace CommonAPI { +namespace DBus { + +class DBusServiceStatusEvent; + +class DBusDaemonProxy: public DBusProxy { + + public: + typedef Event NameOwnerChangedEvent; + typedef std::function)> ListNamesAsyncCallback; + typedef std::function NameHasOwnerAsyncCallback; + + + DBusDaemonProxy(const std::shared_ptr& connection); + + inline const char* getInterfaceName() const; + + NameOwnerChangedEvent& getNameOwnerChangedEvent(); + + void listNames(CommonAPI::CallStatus& callStatus, std::vector& busNames) const; + std::future listNamesAsync(ListNamesAsyncCallback listNamesAsyncCallback) const; + + void nameHasOwner(const std::string& busName, CommonAPI::CallStatus& callStatus, bool& hasOwner) const; + std::future nameHasOwnerAsync(const std::string& busName, NameHasOwnerAsyncCallback nameHasOwnerAsyncCallback) const; + + protected: + void getOwnVersion(uint16_t& ownVersionMajor, uint16_t& ownVersionMinor) const; + + private: + DBusEvent nameOwnerChangedEvent_; +}; + +const char* DBusDaemonProxy::getInterfaceName() const { + return "org.freedesktop.DBus"; +} + +} // namespace DBus +} // namespace CommonAPI + +#endif // COMMONAPI_DBUS_DBUS_DAEMON_PROXY_H_ diff --git a/src/CommonAPI/DBus/DBusFactory.cpp b/src/CommonAPI/DBus/DBusFactory.cpp index 82cb280..52a8737 100644 --- a/src/CommonAPI/DBus/DBusFactory.cpp +++ b/src/CommonAPI/DBus/DBusFactory.cpp @@ -1,144 +1,144 @@ -/* 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 -#include -#include -#include -#include - -namespace CommonAPI { -namespace DBus { - -std::unordered_map* registeredProxyFactoryFunctions_; -std::unordered_map* registeredAdapterFactoryFunctions_; - - -void DBusFactory::registerProxyFactoryMethod(std::string interfaceName, DBusProxyFactoryFunction proxyFactoryMethod) { - if(!registeredProxyFactoryFunctions_) { - registeredProxyFactoryFunctions_ = new std::unordered_map(); - } - registeredProxyFactoryFunctions_->insert({interfaceName, proxyFactoryMethod}); -} - -void DBusFactory::registerAdapterFactoryMethod(std::string interfaceName, DBusAdapterFactoryFunction adapterFactoryMethod) { - if(!registeredAdapterFactoryFunctions_) { - registeredAdapterFactoryFunctions_ = new std::unordered_map(); - } - registeredAdapterFactoryFunctions_->insert({interfaceName, adapterFactoryMethod}); -} - - - -DBusFactory::DBusFactory(std::shared_ptr runtime, const MiddlewareInfo* middlewareInfo) : - CommonAPI::Factory(runtime, middlewareInfo), - dbusConnection_(CommonAPI::DBus::DBusConnection::getSessionBus()), - acquiredConnectionName_("") { - dbusConnection_->connect(); -} - -DBusFactory::~DBusFactory() { -} - - -std::vector 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 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 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 {}; - } - - for (auto it = registeredProxyFactoryFunctions_->begin(); it != registeredProxyFactoryFunctions_->end(); ++it) { - if(it->first == interfaceId) { - return (it->second)(commonApiAddress, interfaceName, connectionName, objectPath, dbusConnection_); - } - } - - return NULL; -} - -std::shared_ptr DBusFactory::createAdapter(std::shared_ptr 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 {}; - } - - for (auto it = registeredAdapterFactoryFunctions_->begin(); it != registeredAdapterFactoryFunctions_->end(); ++it) { - if(it->first == interfaceId) { - std::shared_ptr dbusStubAdapter = (it->second)(commonApiAddress, interfaceName, connectionName, objectPath, 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 +#include +#include +#include +#include + +namespace CommonAPI { +namespace DBus { + +std::unordered_map* registeredProxyFactoryFunctions_; +std::unordered_map* registeredAdapterFactoryFunctions_; + + +void DBusFactory::registerProxyFactoryMethod(std::string interfaceName, DBusProxyFactoryFunction proxyFactoryMethod) { + if(!registeredProxyFactoryFunctions_) { + registeredProxyFactoryFunctions_ = new std::unordered_map(); + } + registeredProxyFactoryFunctions_->insert({interfaceName, proxyFactoryMethod}); +} + +void DBusFactory::registerAdapterFactoryMethod(std::string interfaceName, DBusAdapterFactoryFunction adapterFactoryMethod) { + if(!registeredAdapterFactoryFunctions_) { + registeredAdapterFactoryFunctions_ = new std::unordered_map(); + } + registeredAdapterFactoryFunctions_->insert({interfaceName, adapterFactoryMethod}); +} + + + +DBusFactory::DBusFactory(std::shared_ptr runtime, const MiddlewareInfo* middlewareInfo) : + CommonAPI::Factory(runtime, middlewareInfo), + dbusConnection_(CommonAPI::DBus::DBusConnection::getSessionBus()), + acquiredConnectionName_("") { + dbusConnection_->connect(); +} + +DBusFactory::~DBusFactory() { +} + + +std::vector 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 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 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 {}; + } + + for (auto it = registeredProxyFactoryFunctions_->begin(); it != registeredProxyFactoryFunctions_->end(); ++it) { + if(it->first == interfaceId) { + return (it->second)(commonApiAddress, interfaceName, connectionName, objectPath, dbusConnection_); + } + } + + return NULL; +} + +std::shared_ptr DBusFactory::createAdapter(std::shared_ptr 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 {}; + } + + for (auto it = registeredAdapterFactoryFunctions_->begin(); it != registeredAdapterFactoryFunctions_->end(); ++it) { + if(it->first == interfaceId) { + std::shared_ptr dbusStubAdapter = (it->second)(commonApiAddress, interfaceName, connectionName, objectPath, dbusConnection_, stubBase); + dbusStubAdapter->init(); + return dbusStubAdapter; + } + } + + return NULL; +} + + +} // namespace DBus +} // namespace CommonAPI diff --git a/src/CommonAPI/DBus/DBusFactory.h b/src/CommonAPI/DBus/DBusFactory.h index 144fc5e..b31a36f 100644 --- a/src/CommonAPI/DBus/DBusFactory.h +++ b/src/CommonAPI/DBus/DBusFactory.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_FACTORY_H_ -#define COMMONAPI_DBUS_DBUS_FACTORY_H_ - -#include - -#include - -#include "CommonAPI/DBus/DBusStubAdapter.h" -#include "DBusConnection.h" - -namespace CommonAPI { -namespace DBus { - -typedef std::shared_ptr (*DBusProxyFactoryFunction) (const std::string& commonApiAddress, - const std::string& interfaceName, - const std::string& busName, - const std::string& objectPath, - const std::shared_ptr& dbusProxyConnection); -typedef std::shared_ptr (*DBusAdapterFactoryFunction) (const std::string& commonApiAddress, - const std::string& interfaceName, - const std::string& busName, - const std::string& objectPath, - const std::shared_ptr& dbusProxyConnection, - const std::shared_ptr& stubBase); - -class DBusFactory: public Factory { - public: - DBusFactory(std::shared_ptr 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 getAvailableServiceInstances(const std::string& serviceInterfaceName, const std::string& serviceDomainName = "local"); - - virtual bool isServiceInstanceAlive(const std::string& serviceAddress); - virtual bool isServiceInstanceAlive(const std::string& serviceInstanceID, const std::string& serviceInterfaceName, const std::string& serviceDomainName = "local"); - - protected: - virtual std::shared_ptr createProxy(const char* interfaceId, const std::string& participantId, const std::string& serviceName, const std::string& domain); - virtual std::shared_ptr createAdapter(std::shared_ptr stubBase, const char* interfaceId, const std::string& participantId, const std::string& serviceName, const std::string& domain); - - private: - std::shared_ptr 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 + +#include + +#include "CommonAPI/DBus/DBusStubAdapter.h" +#include "DBusConnection.h" + +namespace CommonAPI { +namespace DBus { + +typedef std::shared_ptr (*DBusProxyFactoryFunction) (const std::string& commonApiAddress, + const std::string& interfaceName, + const std::string& busName, + const std::string& objectPath, + const std::shared_ptr& dbusProxyConnection); +typedef std::shared_ptr (*DBusAdapterFactoryFunction) (const std::string& commonApiAddress, + const std::string& interfaceName, + const std::string& busName, + const std::string& objectPath, + const std::shared_ptr& dbusProxyConnection, + const std::shared_ptr& stubBase); + +class DBusFactory: public Factory { + public: + DBusFactory(std::shared_ptr 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 getAvailableServiceInstances(const std::string& serviceInterfaceName, const std::string& serviceDomainName = "local"); + + virtual bool isServiceInstanceAlive(const std::string& serviceAddress); + virtual bool isServiceInstanceAlive(const std::string& serviceInstanceID, const std::string& serviceInterfaceName, const std::string& serviceDomainName = "local"); + + protected: + virtual std::shared_ptr createProxy(const char* interfaceId, const std::string& participantId, const std::string& serviceName, const std::string& domain); + virtual std::shared_ptr createAdapter(std::shared_ptr stubBase, const char* interfaceId, const std::string& participantId, const std::string& serviceName, const std::string& domain); + + private: + std::shared_ptr dbusConnection_; + std::string acquiredConnectionName_; +}; + +} // namespace DBus +} // namespace CommonAPI + +#endif // COMMONAPI_DBUS_DBUS_FACTORY_H_ diff --git a/src/CommonAPI/DBus/DBusObjectManager.cpp b/src/CommonAPI/DBus/DBusObjectManager.cpp index 9d4323d..f4f65f7 100644 --- a/src/CommonAPI/DBus/DBusObjectManager.cpp +++ b/src/CommonAPI/DBus/DBusObjectManager.cpp @@ -1,101 +1,101 @@ -/* 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 - -namespace CommonAPI { -namespace DBus { - -DBusObjectManager::DBusObjectManager(const std::shared_ptr& 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 + +namespace CommonAPI { +namespace DBus { + +DBusObjectManager::DBusObjectManager(const std::shared_ptr& 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 diff --git a/src/CommonAPI/DBus/DBusObjectManager.h b/src/CommonAPI/DBus/DBusObjectManager.h index 2424fab..712605a 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 DBusMessageInterfaceHandler; -typedef std::pair DBusInterfaceHandlerPath; -typedef DBusInterfaceHandlerPath DBusInterfaceHandlerToken; - -class DBusConnection; - -class DBusObjectManager { - public: - DBusObjectManager(const std::shared_ptr&); - - 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 DBusRegisteredObjectsTable; - DBusRegisteredObjectsTable dbusRegisteredObjectsTable_; - - std::shared_ptr 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 DBusMessageInterfaceHandler; +typedef std::pair DBusInterfaceHandlerPath; +typedef DBusInterfaceHandlerPath DBusInterfaceHandlerToken; + +class DBusConnection; + +class DBusObjectManager { + public: + DBusObjectManager(const std::shared_ptr&); + + 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 DBusRegisteredObjectsTable; + DBusRegisteredObjectsTable dbusRegisteredObjectsTable_; + + std::shared_ptr dbusConnection_; +}; + +} // namespace DBus +} // namespace CommonAPI + +#endif // COMMONAPI_DBUS_DBUS_OBJECT_MANAGER_H_ diff --git a/src/CommonAPI/DBus/DBusProxyConnection.h b/src/CommonAPI/DBus/DBusProxyConnection.h index 5077ee9..3d2c00e 100644 --- a/src/CommonAPI/DBus/DBusProxyConnection.h +++ b/src/CommonAPI/DBus/DBusProxyConnection.h @@ -1,97 +1,97 @@ -/* 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 -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -namespace CommonAPI { -namespace DBus { - - -typedef std::function DBusMessageHandler; - -class DBusDaemonProxy; -class DBusServiceRegistry; -class DBusObjectManager; - - -class DBusProxyConnection { - public: - class DBusMessageReplyAsyncHandler { - public: - virtual ~DBusMessageReplyAsyncHandler() { } - virtual std::future 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 DBusSignalHandlerPath; - typedef std::unordered_multimap 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 sendDBusMessageWithReplyAsync( - const DBusMessage& dbusMessage, - std::unique_ptr 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& getDBusDaemonProxy() = 0; - virtual const std::shared_ptr& getDBusServiceRegistry() = 0; - virtual const std::shared_ptr& 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 +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +namespace CommonAPI { +namespace DBus { + + +typedef std::function DBusMessageHandler; + +class DBusDaemonProxy; +class DBusServiceRegistry; +class DBusObjectManager; + + +class DBusProxyConnection { + public: + class DBusMessageReplyAsyncHandler { + public: + virtual ~DBusMessageReplyAsyncHandler() { } + virtual std::future 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 DBusSignalHandlerPath; + typedef std::unordered_multimap 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 sendDBusMessageWithReplyAsync( + const DBusMessage& dbusMessage, + std::unique_ptr 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& getDBusDaemonProxy() = 0; + virtual const std::shared_ptr& getDBusServiceRegistry() = 0; + virtual const std::shared_ptr& getDBusObjectManager() = 0; +}; + + +} // namespace DBus +} // namespace CommonAPI + +#endif //COMMONAPI_DBUS_DBUS_PROXY_CONNECTION_H_ 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 DBusRuntime::getInstance() { - static std::shared_ptr singleton_; - if(!singleton_) { - singleton_ = std::make_shared(); - } - return singleton_; -} - -std::shared_ptr DBusRuntime::createFactory() { - auto factory = std::make_shared(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 DBusRuntime::getInstance() { + static std::shared_ptr singleton_; + if(!singleton_) { + singleton_ = std::make_shared(); + } + return singleton_; +} + +std::shared_ptr DBusRuntime::createFactory() { + auto factory = std::make_shared(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 { - public: - static std::shared_ptr getInstance(); - - std::shared_ptr 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 { + public: + static std::shared_ptr getInstance(); + + std::shared_ptr 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 2c67c44..80cc4e2 100644 --- a/src/CommonAPI/DBus/DBusServiceRegistry.cpp +++ b/src/CommonAPI/DBus/DBusServiceRegistry.cpp @@ -1,339 +1,339 @@ -/* 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 -#include -#include -#include -#include - -#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), - ready(false), - serviceStatusEvent_(std::shared_ptr(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& listener) { - availabilityCallbackList.insert({service, listener}); -} - -DBusServiceStatusEvent& DBusServiceRegistry::getServiceStatusEvent() { - return serviceStatusEvent_; -} - -DBusServiceRegistry::~DBusServiceRegistry() { - dbusConnection_->getDBusDaemonProxy()->getNameOwnerChangedEvent().unsubscribe(dbusNameOwnerChangedEventSubscription_); -} - -std::future& DBusServiceRegistry::getReadyFuture() { - return readyFuture_; -} - -bool DBusServiceRegistry::isReadyBlocking() const { - 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() const { - return ready; -} - -std::vector DBusServiceRegistry::getAvailableServiceInstances(const std::string& serviceName, - const std::string& domainName) { - - if (!isReadyBlocking()) { - return std::vector(); - } - - if (domainName != "local" || !dbusConnection_->isConnected()) { - return std::vector(); - } - - std::vector addressesOfKnownServiceInstances; - auto knownServiceInstancesIteratorPair = dbusCachedProvidersForInterfaces_.equal_range(serviceName); - - while(knownServiceInstancesIteratorPair.first != knownServiceInstancesIteratorPair.second) { - const DBusInstanceId& dbusServiceInstanceId = knownServiceInstancesIteratorPair.first->second; - const std::string& connectionName = dbusServiceInstanceId.first; - const std::string& objectPath = dbusServiceInstanceId.second; - - std::string commonApiAddress; - DBusAddressTranslator::getInstance().searchForCommonAddress(serviceName, connectionName, objectPath, commonApiAddress); - - addressesOfKnownServiceInstances.push_back(std::move(commonApiAddress)); - ++knownServiceInstancesIteratorPair.first; - } - - return addressesOfKnownServiceInstances; -} - -void DBusServiceRegistry::onManagedPathsList(const CallStatus& status, DBusObjectToInterfaceDict managedObjects, - std::list::iterator iter, std::shared_ptr> 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& dbusInterfaceName, - const std::string& dbusConnectionName, - const std::string& dbusObjectPath) { - - if (!dbusConnection_->isConnected()) { - return false; - } - - - DBusInstanceId serviceInstanceId(dbusConnectionName, dbusObjectPath); - - if (isReady()) { - auto knownInstancesForInterfaceIteratorPair = dbusCachedProvidersForInterfaces_.equal_range(dbusInterfaceName); - - while (knownInstancesForInterfaceIteratorPair.first != knownInstancesForInterfaceIteratorPair.second) { - DBusInstanceId knownServiceId = knownInstancesForInterfaceIteratorPair.first->second; - if (knownServiceId == serviceInstanceId) { - return true; - } - ++knownInstancesForInterfaceIteratorPair.first; - } - } - - if (dbusLivingServiceBusNames_.find(dbusConnectionName) != dbusLivingServiceBusNames_.end()) { - std::promise* pathPromise = new std::promise(); - std::future pathFuture = pathPromise->get_future(); - - getManagedObjects(dbusConnectionName, pathPromise); - - auto status = pathFuture.wait_for(std::chrono::seconds(1)); - if (checkReady(status)) { - delete pathPromise; - auto knownInstancesForInterfaceIteratorPair = dbusCachedProvidersForInterfaces_.equal_range( - dbusInterfaceName); - - while (knownInstancesForInterfaceIteratorPair.first != knownInstancesForInterfaceIteratorPair.second) { - DBusInstanceId knownServiceId = knownInstancesForInterfaceIteratorPair.first->second; - if (knownServiceId == serviceInstanceId) { - return true; - } - ++knownInstancesForInterfaceIteratorPair.first; - } - } - - //If all else fails we have a con name - return true; - } - return false; -} - - -void DBusServiceRegistry::getManagedObjects(const std::string& dbusWellKnownBusName, std::promise* returnPromise) { - auto callMessage = DBusMessage::createMethodCall( - dbusWellKnownBusName.c_str(), - "/", - "org.freedesktop.DBus.ObjectManager", - "GetManagedObjects", - ""); - dbusConnection_->sendDBusMessageWithReplyAsync( - callMessage, - DBusProxyAsyncCallbackHandler::create( - std::bind( - &DBusServiceRegistry::onManagedPaths, - this, - std::placeholders::_1, - std::placeholders::_2, - dbusWellKnownBusName, - returnPromise)), 100); - -} - - -void DBusServiceRegistry::onManagedPaths(const CallStatus& status, DBusObjectToInterfaceDict managedObjects, - std::string dbusWellKnownBusName, std::promise* returnPromise) { - - 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; - } - if (returnPromise != 0) { - returnPromise->set_value(true); - } -} - -void DBusServiceRegistry::updateListeners(const std::string& conName, - const std::string& objName, - const std::string& intName, - bool available) { - std::string commonAPIAddress; - DBusAddressTranslator::getInstance().searchForCommonAddress(conName, objName, intName, commonAPIAddress); - auto found = availabilityCallbackList.equal_range(std::move(commonAPIAddress)); - auto foundIter = found.first; - while (foundIter != found.second) { - foundIter->second(true); - foundIter++; - } - -} - -void DBusServiceRegistry::addProvidedServiceInstancesToCache(const std::string& dbusNames) { - getManagedObjects(dbusNames); -} - -void DBusServiceRegistry::addProvidedServiceInstancesToCache(const std::set& dbusNames) { - - std::shared_ptr> dbusList = std::make_shared>(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::create( - std::bind( - &DBusServiceRegistry::onManagedPathsList, - this, - std::placeholders::_1, - std::placeholders::_2, - iter, - dbusList)), 10); - iter++; - } -} - - -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) { - - DBusInstanceId dbusInstanceId = providersForInterfacesIteratorPair.first->second; - if(std::get<0>(dbusInstanceId) == dbusWellKnownBusName) { - auto toErase = providersForInterfacesIteratorPair.first; - ++providersForInterfacesIteratorPair.first; - dbusCachedProvidersForInterfaces_.erase(toErase); - } - - ++providersForInterfacesIteratorPair.first; - } -} - -void DBusServiceRegistry::onListNames(const CommonAPI::CallStatus& callStatus, std::vector existingBusConnections) { - - if (callStatus == CallStatus::SUCCESS) { - for (const std::string& connectionName : existingBusConnections) { - const bool isWellKnownName = (connectionName[0] != ':'); - - if (isWellKnownName) { - dbusLivingServiceBusNames_.insert(connectionName); - } - } - addProvidedServiceInstancesToCache(dbusLivingServiceBusNames_); - } -} - -void DBusServiceRegistry::cacheAllServices() { - CommonAPI::CallStatus callStatus; - std::vector 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 +#include +#include +#include +#include + +#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), + ready(false), + serviceStatusEvent_(std::shared_ptr(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& listener) { + availabilityCallbackList.insert({service, listener}); +} + +DBusServiceStatusEvent& DBusServiceRegistry::getServiceStatusEvent() { + return serviceStatusEvent_; +} + +DBusServiceRegistry::~DBusServiceRegistry() { + dbusConnection_->getDBusDaemonProxy()->getNameOwnerChangedEvent().unsubscribe(dbusNameOwnerChangedEventSubscription_); +} + +std::future& DBusServiceRegistry::getReadyFuture() { + return readyFuture_; +} + +bool DBusServiceRegistry::isReadyBlocking() const { + 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() const { + return ready; +} + +std::vector DBusServiceRegistry::getAvailableServiceInstances(const std::string& serviceName, + const std::string& domainName) { + + if (!isReadyBlocking()) { + return std::vector(); + } + + if (domainName != "local" || !dbusConnection_->isConnected()) { + return std::vector(); + } + + std::vector addressesOfKnownServiceInstances; + auto knownServiceInstancesIteratorPair = dbusCachedProvidersForInterfaces_.equal_range(serviceName); + + while(knownServiceInstancesIteratorPair.first != knownServiceInstancesIteratorPair.second) { + const DBusInstanceId& dbusServiceInstanceId = knownServiceInstancesIteratorPair.first->second; + const std::string& connectionName = dbusServiceInstanceId.first; + const std::string& objectPath = dbusServiceInstanceId.second; + + std::string commonApiAddress; + DBusAddressTranslator::getInstance().searchForCommonAddress(serviceName, connectionName, objectPath, commonApiAddress); + + addressesOfKnownServiceInstances.push_back(std::move(commonApiAddress)); + ++knownServiceInstancesIteratorPair.first; + } + + return addressesOfKnownServiceInstances; +} + +void DBusServiceRegistry::onManagedPathsList(const CallStatus& status, DBusObjectToInterfaceDict managedObjects, + std::list::iterator iter, std::shared_ptr> 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& dbusInterfaceName, + const std::string& dbusConnectionName, + const std::string& dbusObjectPath) { + + if (!dbusConnection_->isConnected()) { + return false; + } + + + DBusInstanceId serviceInstanceId(dbusConnectionName, dbusObjectPath); + + if (isReady()) { + auto knownInstancesForInterfaceIteratorPair = dbusCachedProvidersForInterfaces_.equal_range(dbusInterfaceName); + + while (knownInstancesForInterfaceIteratorPair.first != knownInstancesForInterfaceIteratorPair.second) { + DBusInstanceId knownServiceId = knownInstancesForInterfaceIteratorPair.first->second; + if (knownServiceId == serviceInstanceId) { + return true; + } + ++knownInstancesForInterfaceIteratorPair.first; + } + } + + if (dbusLivingServiceBusNames_.find(dbusConnectionName) != dbusLivingServiceBusNames_.end()) { + std::promise* pathPromise = new std::promise(); + std::future pathFuture = pathPromise->get_future(); + + getManagedObjects(dbusConnectionName, pathPromise); + + auto status = pathFuture.wait_for(std::chrono::seconds(1)); + if (checkReady(status)) { + delete pathPromise; + auto knownInstancesForInterfaceIteratorPair = dbusCachedProvidersForInterfaces_.equal_range( + dbusInterfaceName); + + while (knownInstancesForInterfaceIteratorPair.first != knownInstancesForInterfaceIteratorPair.second) { + DBusInstanceId knownServiceId = knownInstancesForInterfaceIteratorPair.first->second; + if (knownServiceId == serviceInstanceId) { + return true; + } + ++knownInstancesForInterfaceIteratorPair.first; + } + } + + //If all else fails we have a con name + return true; + } + return false; +} + + +void DBusServiceRegistry::getManagedObjects(const std::string& dbusWellKnownBusName, std::promise* returnPromise) { + auto callMessage = DBusMessage::createMethodCall( + dbusWellKnownBusName.c_str(), + "/", + "org.freedesktop.DBus.ObjectManager", + "GetManagedObjects", + ""); + dbusConnection_->sendDBusMessageWithReplyAsync( + callMessage, + DBusProxyAsyncCallbackHandler::create( + std::bind( + &DBusServiceRegistry::onManagedPaths, + this, + std::placeholders::_1, + std::placeholders::_2, + dbusWellKnownBusName, + returnPromise)), 100); + +} + + +void DBusServiceRegistry::onManagedPaths(const CallStatus& status, DBusObjectToInterfaceDict managedObjects, + std::string dbusWellKnownBusName, std::promise* returnPromise) { + + 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; + } + if (returnPromise != 0) { + returnPromise->set_value(true); + } +} + +void DBusServiceRegistry::updateListeners(const std::string& conName, + const std::string& objName, + const std::string& intName, + bool available) { + std::string commonAPIAddress; + DBusAddressTranslator::getInstance().searchForCommonAddress(conName, objName, intName, commonAPIAddress); + auto found = availabilityCallbackList.equal_range(std::move(commonAPIAddress)); + auto foundIter = found.first; + while (foundIter != found.second) { + foundIter->second(true); + foundIter++; + } + +} + +void DBusServiceRegistry::addProvidedServiceInstancesToCache(const std::string& dbusNames) { + getManagedObjects(dbusNames); +} + +void DBusServiceRegistry::addProvidedServiceInstancesToCache(const std::set& dbusNames) { + + std::shared_ptr> dbusList = std::make_shared>(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::create( + std::bind( + &DBusServiceRegistry::onManagedPathsList, + this, + std::placeholders::_1, + std::placeholders::_2, + iter, + dbusList)), 10); + iter++; + } +} + + +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) { + + DBusInstanceId dbusInstanceId = providersForInterfacesIteratorPair.first->second; + if(std::get<0>(dbusInstanceId) == dbusWellKnownBusName) { + auto toErase = providersForInterfacesIteratorPair.first; + ++providersForInterfacesIteratorPair.first; + dbusCachedProvidersForInterfaces_.erase(toErase); + } + + ++providersForInterfacesIteratorPair.first; + } +} + +void DBusServiceRegistry::onListNames(const CommonAPI::CallStatus& callStatus, std::vector existingBusConnections) { + + if (callStatus == CallStatus::SUCCESS) { + for (const std::string& connectionName : existingBusConnections) { + const bool isWellKnownName = (connectionName[0] != ':'); + + if (isWellKnownName) { + dbusLivingServiceBusNames_.insert(connectionName); + } + } + addProvidedServiceInstancesToCache(dbusLivingServiceBusNames_); + } +} + +void DBusServiceRegistry::cacheAllServices() { + CommonAPI::CallStatus callStatus; + std::vector existingBusConnections; + dbusConnection_->getDBusDaemonProxy()->listNames(callStatus, existingBusConnections); + onListNames(callStatus, existingBusConnections); +} + + +}// namespace DBus +}// namespace CommonAPI diff --git a/src/CommonAPI/DBus/DBusServiceRegistry.h b/src/CommonAPI/DBus/DBusServiceRegistry.h index 4a806f1..7d8d7d3 100644 --- a/src/CommonAPI/DBus/DBusServiceRegistry.h +++ b/src/CommonAPI/DBus/DBusServiceRegistry.h @@ -1,116 +1,116 @@ -/* 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 -#include - -#include "DBusConnection.h" -#include "DBusAddressTranslator.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace CommonAPI { -namespace DBus { - -typedef Event NameOwnerChangedEvent; -typedef Event::Subscription NameOwnerChangedEventSubscription; - -//connectionName, objectPath -typedef std::pair DBusInstanceId; - -typedef std::unordered_map PropertyDictStub; -typedef std::unordered_map InterfaceToPropertyDict; -typedef std::unordered_map 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 connection); - ~DBusServiceRegistry(); - - std::vector getAvailableServiceInstances(const std::string& interfaceName, - const std::string& domainName = "local"); - - bool isServiceInstanceAlive(const std::string& dbusInterfaceName, - const std::string& dbusConnectionName, - const std::string& dbusObjectPath); - bool isConnectionAlive(const std::string& dbusConnectionName) const; - - bool isReady() const; - - bool isReadyBlocking() const; - - void registerAvailabilityListener(const std::string& service, const std::function& listener); - - std::future& getReadyFuture(); - - DBusServiceStatusEvent& getServiceStatusEvent(); - - private: - void cacheAllServices(); - - void removeProvidedServiceInstancesFromCache(const std::string& serviceBusName); - void addProvidedServiceInstancesToCache(const std::set& dbusNames); - void addProvidedServiceInstancesToCache(const std::string& dbusNames); - void addAllProvidedServiceInstancesToCache(const std::vector& serviceBusNames); - - void getManagedObjects(const std::string& serviceBusName, std::promise* returnPromise = 0); - - 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; - - void onManagedPaths(const CallStatus& status, DBusObjectToInterfaceDict replyMessage, std::string dbusWellKnownBusName, std::promise* returnPromise = 0); - void onManagedPathsList(const CallStatus& status, DBusObjectToInterfaceDict managedObjects, std::list::iterator iter, std::shared_ptr> list); - - void onListNames(const CommonAPI::CallStatus&, std::vector); - void updateListeners(const std::string& conName, const std::string& objName, const std::string& intName , bool available); - - std::multimap dbusCachedProvidersForInterfaces_; - std::set dbusLivingServiceBusNames_; - - std::shared_ptr dbusConnection_; - - std::unordered_multimap> availabilityCallbackList; - - NameOwnerChangedEvent::Subscription dbusNameOwnerChangedEventSubscription_; - - mutable bool ready; - mutable std::future readyFuture_; - mutable std::promise readyPromise_; - - mutable 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 +#include + +#include "DBusConnection.h" +#include "DBusAddressTranslator.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace CommonAPI { +namespace DBus { + +typedef Event NameOwnerChangedEvent; +typedef Event::Subscription NameOwnerChangedEventSubscription; + +//connectionName, objectPath +typedef std::pair DBusInstanceId; + +typedef std::unordered_map PropertyDictStub; +typedef std::unordered_map InterfaceToPropertyDict; +typedef std::unordered_map 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 connection); + ~DBusServiceRegistry(); + + std::vector getAvailableServiceInstances(const std::string& interfaceName, + const std::string& domainName = "local"); + + bool isServiceInstanceAlive(const std::string& dbusInterfaceName, + const std::string& dbusConnectionName, + const std::string& dbusObjectPath); + bool isConnectionAlive(const std::string& dbusConnectionName) const; + + bool isReady() const; + + bool isReadyBlocking() const; + + void registerAvailabilityListener(const std::string& service, const std::function& listener); + + std::future& getReadyFuture(); + + DBusServiceStatusEvent& getServiceStatusEvent(); + + private: + void cacheAllServices(); + + void removeProvidedServiceInstancesFromCache(const std::string& serviceBusName); + void addProvidedServiceInstancesToCache(const std::set& dbusNames); + void addProvidedServiceInstancesToCache(const std::string& dbusNames); + void addAllProvidedServiceInstancesToCache(const std::vector& serviceBusNames); + + void getManagedObjects(const std::string& serviceBusName, std::promise* returnPromise = 0); + + 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; + + void onManagedPaths(const CallStatus& status, DBusObjectToInterfaceDict replyMessage, std::string dbusWellKnownBusName, std::promise* returnPromise = 0); + void onManagedPathsList(const CallStatus& status, DBusObjectToInterfaceDict managedObjects, std::list::iterator iter, std::shared_ptr> list); + + void onListNames(const CommonAPI::CallStatus&, std::vector); + void updateListeners(const std::string& conName, const std::string& objName, const std::string& intName , bool available); + + std::multimap dbusCachedProvidersForInterfaces_; + std::set dbusLivingServiceBusNames_; + + std::shared_ptr dbusConnection_; + + std::unordered_multimap> availabilityCallbackList; + + NameOwnerChangedEvent::Subscription dbusNameOwnerChangedEventSubscription_; + + mutable bool ready; + mutable std::future readyFuture_; + mutable std::promise readyPromise_; + + mutable std::mutex readyMutex_; + + DBusServiceStatusEvent serviceStatusEvent_; +}; + +} // namespace DBus +} // namespace CommonAPI + +#endif // COMMONAPI_DBUS_DBUS_SERVICE_REGISTRY_H_ diff --git a/src/CommonAPI/DBus/DBusServiceStatusEvent.h b/src/CommonAPI/DBus/DBusServiceStatusEvent.h index a21e575..b2be5da 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 -#include - -#include -#include - -namespace CommonAPI { -namespace DBus { - - -class DBusServiceRegistry; - -class DBusServiceStatusEvent: public DBusMultiEvent { - public: - DBusServiceStatusEvent(std::shared_ptr 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 bool& available); - - std::shared_ptr 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 +#include + +#include +#include + +namespace CommonAPI { +namespace DBus { + + +class DBusServiceRegistry; + +class DBusServiceStatusEvent: public DBusMultiEvent { + public: + DBusServiceStatusEvent(std::shared_ptr 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 bool& available); + + std::shared_ptr registry_; +}; + +} // namespace DBus +} // namespace CommonAPI + +#endif // COMMONAPI_DBUS_DBUS_SERVICE_STATUS_EVENT_H_ + 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 - -#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 + +#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 - -#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 + +#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/fakeLegacyService/fake.legacy.service.xml b/src/test/fakeLegacyService/fake.legacy.service.xml index bb40a96..81b4e60 100644 --- a/src/test/fakeLegacyService/fake.legacy.service.xml +++ b/src/test/fakeLegacyService/fake.legacy.service.xml @@ -1,259 +1,259 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/test/test-derived-types.fidl b/src/test/test-derived-types.fidl index 051b438..7b8c477 100644 --- a/src/test/test-derived-types.fidl +++ b/src/test/test-derived-types.fidl @@ -1,56 +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 } -} - - +/* 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 index f23fb7a..88d4874 100644 --- a/src/test/test-interface-proxy.fidl +++ b/src/test/test-interface-proxy.fidl @@ -1,58 +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 - } - } -} - +/* 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 index 8a69103..6226ed2 100644 --- a/src/test/test-predefined-types.fidl +++ b/src/test/test-predefined-types.fidl @@ -1,22 +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 -} - - +/* 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 +} + +