diff options
author | Christian Linke <christian.linke@bmw.de> | 2015-03-12 13:43:48 +0100 |
---|---|---|
committer | Christian Linke <christian.linke@bmw.de> | 2015-03-12 13:43:48 +0100 |
commit | 6ffbf25bacf589879198e49ac227cb56e261b7c9 (patch) | |
tree | e6b3ca48d22d06d43da638b1998ab1220ec7ab08 /AudioManagerDaemon/src | |
parent | c628fa5304171cd827f56aa475668d99d26ad28a (diff) | |
download | audiomanager-6ffbf25bacf589879198e49ac227cb56e261b7c9.tar.gz |
* fully rework. Plugins have now a new own git repository
* building out of source of plugins without AM workss
* build system cmake contructions is different now
Signed-off-by: Christian Linke <christian.linke@bmw.de>
Diffstat (limited to 'AudioManagerDaemon/src')
20 files changed, 38 insertions, 1681 deletions
diff --git a/AudioManagerDaemon/src/CAmCommandReceiver.cpp b/AudioManagerDaemon/src/CAmCommandReceiver.cpp index 066fb81..43ccd20 100644 --- a/AudioManagerDaemon/src/CAmCommandReceiver.cpp +++ b/AudioManagerDaemon/src/CAmCommandReceiver.cpp @@ -12,7 +12,7 @@ * this file, You can obtain one at http://mozilla.org/MPL/2.0/. * * - * \author Christian Mueller, christian.ei.mueller@bmw.de BMW 2011,2012 + * \author Christian Linke, christian.linke@bmw.de BMW 2011,2012 * * \file CAmCommandReceiver.cpp * For further information see http://www.genivi.org/. @@ -24,8 +24,8 @@ #include <algorithm> #include "IAmDatabaseHandler.h" #include "CAmControlSender.h" -#include "shared/CAmDltWrapper.h" -#include "shared/CAmSocketHandler.h" +#include "CAmDltWrapper.h" +#include "CAmSocketHandler.h" namespace am { diff --git a/AudioManagerDaemon/src/CAmCommandSender.cpp b/AudioManagerDaemon/src/CAmCommandSender.cpp index bb49c19..3882162 100644 --- a/AudioManagerDaemon/src/CAmCommandSender.cpp +++ b/AudioManagerDaemon/src/CAmCommandSender.cpp @@ -12,7 +12,7 @@ * this file, You can obtain one at http://mozilla.org/MPL/2.0/. * * - * \author Christian Mueller, christian.ei.mueller@bmw.de BMW 2011,2012 + * \author Christian Linke, christian.linke@bmw.de BMW 2011,2012 * * \file CAmCommandSender.cpp * For further information see http://www.genivi.org/. @@ -29,7 +29,7 @@ #include <cstring> #include "CAmCommandReceiver.h" #include "TAmPluginTemplate.h" -#include "shared/CAmDltWrapper.h" +#include "CAmDltWrapper.h" namespace am { diff --git a/AudioManagerDaemon/src/CAmCommonAPIWrapper.cpp b/AudioManagerDaemon/src/CAmCommonAPIWrapper.cpp deleted file mode 100644 index 28103de..0000000 --- a/AudioManagerDaemon/src/CAmCommonAPIWrapper.cpp +++ /dev/null @@ -1,275 +0,0 @@ -/** - * Copyright (C) 2012, BMW AG - * - * \author Christian Mueller, christian.ei.mueller@bmw.de BMW 2011,2012 - * \author Aleksandar Donchev, aleksander.donchev@partner.bmw.de BMW 2013 - * - * \copyright - * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, - * including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. - * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR - * THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - * \file CAmCommonAPIWrapper.cpp - * For further information see http://www.genivi.org/. - */ - - -#include <config.h> -#include <fstream> -#include <sstream> -#include <string> -#include <algorithm> -#include <cassert> -#include <cstdlib> -#include <stdexcept> -#include <poll.h> -#include <tuple> -#include "audiomanagertypes.h" -#include "shared/CAmSocketHandler.h" -#include "shared/CAmDltWrapper.h" -#include "shared/CAmCommonAPIWrapper.h" - - -namespace am -{ -static CAmCommonAPIWrapper* pSingleCommonAPIInstance = NULL; - - -using namespace CommonAPI; - -CAmCommonAPIWrapper::CAmCommonAPIWrapper(CAmSocketHandler* socketHandler): - pCommonPrepareCallback(this,&CAmCommonAPIWrapper::commonPrepareCallback), // - pCommonDispatchCallback(this, &CAmCommonAPIWrapper::commonDispatchCallback), // - pCommonFireCallback(this, &CAmCommonAPIWrapper::commonFireCallback), // - pCommonCheckCallback(this, &CAmCommonAPIWrapper::commonCheckCallback), // - pCommonTimerCallback(this, &CAmCommonAPIWrapper::commonTimerCallback), // - mpSocketHandler(socketHandler), // - mWatchToCheck(NULL) -{ - assert(NULL!=socketHandler); -//1. Load the runtime - std::shared_ptr<CommonAPI::Runtime> runtime = CommonAPI::Runtime::load(); -//2. Get the context and store a pointer to it - mContext = runtime->getNewMainLoopContext(); -//3. Make subscriptions - mDispatchSourceListenerSubscription = mContext->subscribeForDispatchSources( - std::bind(&CAmCommonAPIWrapper::registerDispatchSource, this, std::placeholders::_1, std::placeholders::_2), - std::bind(&CAmCommonAPIWrapper::deregisterDispatchSource, this, std::placeholders::_1)); - mWatchListenerSubscription = mContext->subscribeForWatches( - std::bind(&CAmCommonAPIWrapper::registerWatch, this, std::placeholders::_1, std::placeholders::_2), - std::bind(&CAmCommonAPIWrapper::deregisterWatch, this, std::placeholders::_1)); - mTimeoutSourceListenerSubscription = mContext->subscribeForTimeouts( - std::bind(&CAmCommonAPIWrapper::registerTimeout, this, std::placeholders::_1, std::placeholders::_2), - std::bind(&CAmCommonAPIWrapper::deregisterTimeout, this, std::placeholders::_1)); -//4. Create the factory - std::shared_ptr<CommonAPI::Factory> factory = runtime->createFactory(mContext); - assert(factory); - logInfo(__PRETTY_FUNCTION__,"CommonAPI -> Factory created"); - mFactory = factory; -//5. Get the publisher V.2.1 -// std::shared_ptr<CommonAPI::ServicePublisher> servicePublisher = runtime->getServicePublisher(); -// assert(servicePublisher); -// logInfo(__PRETTY_FUNCTION__,"CommonAPI -> Publisher available"); -//6. Instantiate your concrete stub implementations -// std::shared_ptr<StubImpl> theStub = std::make_shared<StubImpl>(1); -//7. Register the services -// std::string capiAddress("local:org.genivi.audiomanager.sourcestate:de.bmw.infotainment.broadcast.ta"); -// registerStub(theStub, capiAddress); -} - -CAmCommonAPIWrapper::~CAmCommonAPIWrapper() -{ - mContext->unsubscribeForDispatchSources(mDispatchSourceListenerSubscription); - mContext->unsubscribeForWatches(mWatchListenerSubscription); - mContext->unsubscribeForTimeouts(mTimeoutSourceListenerSubscription); -//The following objects must be released in the given order. - mFactory.reset(); - mContext.reset(); - - mpSocketHandler = NULL; - mWatchToCheck = NULL; -} - -CAmCommonAPIWrapper* CAmCommonAPIWrapper::instantiateOnce(CAmSocketHandler* socketHandler) -{ - if(NULL==pSingleCommonAPIInstance) - { - if(NULL==socketHandler) - throw std::runtime_error(std::string("Expected a valid socket handler. The socket handler pointer must not be NULL.")); - else - pSingleCommonAPIInstance = new CAmCommonAPIWrapper(socketHandler); - } - else - throw std::logic_error(std::string("The singleton instance has been already instantiated. This method should be called only once.")); - return pSingleCommonAPIInstance; -} - -CAmCommonAPIWrapper* CAmCommonAPIWrapper::getInstance() -{ - assert(NULL!=pSingleCommonAPIInstance); - return pSingleCommonAPIInstance; -} - -std::shared_ptr<CommonAPI::Factory> CAmCommonAPIWrapper::factory() const -{ - return mFactory; -} - - -std::shared_ptr<CommonAPI::Runtime> CAmCommonAPIWrapper::runtime() const -{ - return mFactory->getRuntime(); -} - -bool CAmCommonAPIWrapper::commonDispatchCallback(const sh_pollHandle_t handle, void *userData) -{ - (void) handle; - (void) userData; - - std::list<DispatchSource*>::iterator iterator(mSourcesToDispatch.begin()); - for(;iterator!=mSourcesToDispatch.end();) - { - DispatchSource* source = *iterator; - if (!source->dispatch()) { - iterator=mSourcesToDispatch.erase(iterator); - } - else - iterator++; - } - if (!mSourcesToDispatch.empty()) - return (true); - - return false; -} - -bool CAmCommonAPIWrapper::commonCheckCallback(const sh_pollHandle_t, void *) -{ - std::vector<DispatchSource*> vecDispatch=mWatchToCheck->getDependentDispatchSources(); - mSourcesToDispatch.insert(mSourcesToDispatch.end(), vecDispatch.begin(), vecDispatch.end()); - - return (mWatchToCheck || !mSourcesToDispatch.empty()); -} - -void CAmCommonAPIWrapper::commonFireCallback(const pollfd pollfd, const sh_pollHandle_t, void *) -{ - mWatchToCheck=NULL; - try - { - mWatchToCheck=mMapWatches.at(pollfd.fd); - } - catch (const std::out_of_range& error) { - logInfo(__PRETTY_FUNCTION__,error.what()); - return; - } - - mWatchToCheck->dispatch(pollfd.events); -} - -void CAmCommonAPIWrapper::commonPrepareCallback(const sh_pollHandle_t, void*) -{ - for (auto dispatchSourceIterator = mRegisteredDispatchSources.begin(); - dispatchSourceIterator != mRegisteredDispatchSources.end(); - dispatchSourceIterator++) - { - int64_t dispatchTimeout(TIMEOUT_INFINITE); - if(dispatchSourceIterator->second->prepare(dispatchTimeout)) - { - while (dispatchSourceIterator->second->dispatch()); - } - } -} - -void CAmCommonAPIWrapper::registerDispatchSource(DispatchSource* dispatchSource, const DispatchPriority dispatchPriority) -{ - mRegisteredDispatchSources.insert({dispatchPriority, dispatchSource}); -} - -void CAmCommonAPIWrapper::deregisterDispatchSource(DispatchSource* dispatchSource) -{ - for(auto dispatchSourceIterator = mRegisteredDispatchSources.begin(); - dispatchSourceIterator != mRegisteredDispatchSources.end(); - dispatchSourceIterator++) { - - if(dispatchSourceIterator->second == dispatchSource) { - mRegisteredDispatchSources.erase(dispatchSourceIterator); - break; - } - } -} - -void CAmCommonAPIWrapper::deregisterWatch(Watch* watch) -{ - logInfo(__PRETTY_FUNCTION__); - for(std::map<int,Watch*>::iterator iter(mMapWatches.begin());iter!=mMapWatches.end();iter++) - { - if (iter->second == watch) - { - mMapWatches.erase(iter); - break; - } - } -} - -void CAmCommonAPIWrapper::registerTimeout(Timeout* timeout, const DispatchPriority) -{ - logInfo(__PRETTY_FUNCTION__); - timespec pollTimeout; - int64_t localTimeout = timeout->getTimeoutInterval(); - - pollTimeout.tv_sec = localTimeout / 1000; - pollTimeout.tv_nsec = (localTimeout % 1000) * 1000000; - - //prepare handle and callback. new is eval, but there is no other choice because we need the pointer! - sh_timerHandle_t handle; - timerHandles myHandle({handle,timeout}); - mpListTimerhandles.push_back(myHandle); - - //add the timer to the pollLoop - mpSocketHandler->addTimer(pollTimeout, &pCommonTimerCallback, handle, timeout); - - return; -} - -void CAmCommonAPIWrapper::deregisterTimeout(Timeout* timeout) -{ - logInfo(__PRETTY_FUNCTION__); - for( std::vector<timerHandles>::iterator iter(mpListTimerhandles.begin());iter!=mpListTimerhandles.end();iter++) - { - if(iter->timeout==timeout) - { - mpSocketHandler->removeTimer(iter->handle); - } - } -} - -void CAmCommonAPIWrapper::registerWatch(Watch* watch, const DispatchPriority) -{ - logInfo(__PRETTY_FUNCTION__); - pollfd pollfd_ (watch->getAssociatedFileDescriptor()); - sh_pollHandle_t handle (0); - - am_Error_e error = mpSocketHandler->addFDPoll(pollfd_.fd, pollfd_.events, &pCommonPrepareCallback, &pCommonFireCallback, &pCommonCheckCallback, &pCommonDispatchCallback, watch, handle); - - //if everything is alright, add the watch and the handle to our map so we know this relationship - if (error == !am_Error_e::E_OK || handle == 0) - logError(__PRETTY_FUNCTION__,"entering watch failed"); - - mMapWatches.insert(std::make_pair(pollfd_.fd,watch)); -} - -void CAmCommonAPIWrapper::commonTimerCallback(sh_timerHandle_t handle, void *) -{ - for( std::vector<timerHandles>::iterator iter(mpListTimerhandles.begin());iter!=mpListTimerhandles.end();iter++) - { - if(iter->handle==handle) - { - iter->timeout->dispatch(); - } - } -} - -} diff --git a/AudioManagerDaemon/src/CAmControlReceiver.cpp b/AudioManagerDaemon/src/CAmControlReceiver.cpp index 6ac7e0a..19b05bd 100644 --- a/AudioManagerDaemon/src/CAmControlReceiver.cpp +++ b/AudioManagerDaemon/src/CAmControlReceiver.cpp @@ -12,7 +12,7 @@ * this file, You can obtain one at http://mozilla.org/MPL/2.0/. * * - * \author Christian Mueller, christian.ei.mueller@bmw.de BMW 2011,2012 + * \author Christian Linke, christian.linke@bmw.de BMW 2011,2012 * * \file CAmControlReceiver.cpp * For further information see http://www.genivi.org/. @@ -28,8 +28,8 @@ #include "CAmRoutingSender.h" #include "CAmCommandSender.h" #include "CAmRouter.h" -#include "shared/CAmDltWrapper.h" -#include "shared/CAmSocketHandler.h" +#include "CAmDltWrapper.h" +#include "CAmSocketHandler.h" #ifdef WITH_NSM #include "CAmNodeStateCommunicator.h" #endif diff --git a/AudioManagerDaemon/src/CAmControlSender.cpp b/AudioManagerDaemon/src/CAmControlSender.cpp index dd3558e..bc51be0 100644 --- a/AudioManagerDaemon/src/CAmControlSender.cpp +++ b/AudioManagerDaemon/src/CAmControlSender.cpp @@ -12,7 +12,7 @@ * this file, You can obtain one at http://mozilla.org/MPL/2.0/. * * - * \author Christian Mueller, christian.ei.mueller@bmw.de BMW 2011,2012 + * \author Christian Linke, christian.linke@bmw.de BMW 2011,2012 * * \file CAmControlSender.cpp * For further information see http://www.genivi.org/. @@ -26,7 +26,7 @@ #include <sstream> #include <stdexcept> #include "TAmPluginTemplate.h" -#include "shared/CAmDltWrapper.h" +#include "CAmDltWrapper.h" namespace am { diff --git a/AudioManagerDaemon/src/CAmDatabaseHandlerMap.cpp b/AudioManagerDaemon/src/CAmDatabaseHandlerMap.cpp index 864ae8c..501ea11 100644 --- a/AudioManagerDaemon/src/CAmDatabaseHandlerMap.cpp +++ b/AudioManagerDaemon/src/CAmDatabaseHandlerMap.cpp @@ -30,7 +30,7 @@ #include "CAmDatabaseHandlerMap.h" #include "CAmDatabaseObserver.h" #include "CAmRouter.h" -#include "shared/CAmDltWrapper.h" +#include "CAmDltWrapper.h" namespace am diff --git a/AudioManagerDaemon/src/CAmDatabaseHandlerSQLite.cpp b/AudioManagerDaemon/src/CAmDatabaseHandlerSQLite.cpp index da86386..bad070c 100644 --- a/AudioManagerDaemon/src/CAmDatabaseHandlerSQLite.cpp +++ b/AudioManagerDaemon/src/CAmDatabaseHandlerSQLite.cpp @@ -12,7 +12,7 @@ * this file, You can obtain one at http://mozilla.org/MPL/2.0/. * * - * \author Christian Mueller, christian.ei.mueller@bmw.de BMW 2011,2012 + * \author Christian Linke, christian.linke@bmw.de BMW 2011,2012 * * \file CAmDatabaseHandlerSQLite.cpp * For further information see http://www.genivi.org/. @@ -28,7 +28,7 @@ #include <string> #include "CAmDatabaseObserver.h" #include "CAmRouter.h" -#include "shared/CAmDltWrapper.h" +#include "CAmDltWrapper.h" #include <sqlite3.h> namespace am diff --git a/AudioManagerDaemon/src/CAmDatabaseObserver.cpp b/AudioManagerDaemon/src/CAmDatabaseObserver.cpp index 57a76cc..cec033f 100644 --- a/AudioManagerDaemon/src/CAmDatabaseObserver.cpp +++ b/AudioManagerDaemon/src/CAmDatabaseObserver.cpp @@ -12,7 +12,7 @@ * this file, You can obtain one at http://mozilla.org/MPL/2.0/. * * - * \author Christian Mueller, christian.ei.mueller@bmw.de BMW 2011,2012 + * \author Christian Linke, christian.linke@bmw.de BMW 2011,2012 * * \file CAmDatabaseObserver.cpp * For further information see http://www.genivi.org/. @@ -28,8 +28,8 @@ #include "CAmCommandSender.h" #include "CAmRoutingSender.h" #include "CAmTelnetServer.h" -#include "shared/CAmDltWrapper.h" -#include "shared/CAmSerializer.h" +#include "CAmDltWrapper.h" +#include "CAmSerializer.h" namespace am { diff --git a/AudioManagerDaemon/src/CAmDbusWrapper.cpp b/AudioManagerDaemon/src/CAmDbusWrapper.cpp deleted file mode 100644 index c9c26a4..0000000 --- a/AudioManagerDaemon/src/CAmDbusWrapper.cpp +++ /dev/null @@ -1,472 +0,0 @@ -/** - * Copyright (C) 2012, BMW AG - * - * This file is part of GENIVI Project AudioManager. - * - * Contributions are licensed to the GENIVI Alliance under one or more - * Contribution License Agreements. - * - * \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/. - * - * - * \author Christian Mueller, christian.ei.mueller@bmw.de BMW 2011,2012 - * - * \file CAmDbusWrapper.cpp - * For further information see http://www.genivi.org/. - * - */ - -#include "shared/CAmDbusWrapper.h" -#include <config.h> -#include <fstream> -#include <sstream> -#include <string> -#include <cassert> -#include <cstdlib> -#include <stdexcept> -#include "shared/CAmDltWrapper.h" -#include "shared/CAmSocketHandler.h" - -namespace am -{ - -/** - * introspectio header - */ -#define ROOT_INTROSPECT_XML \ -DBUS_INTROSPECT_1_0_XML_DOCTYPE_DECL_NODE \ -"<node>" \ -"<interface name='org.AudioManager.freedesktop.DBus.Introspectable'>" \ -"<method name='Introspect'>" \ -" <arg name='xml_data' type='s' direction='out'/>" \ -"</method>" \ -"</interface>" \ - -CAmDbusWrapper* CAmDbusWrapper::mpReference = NULL; - -CAmDbusWrapper::CAmDbusWrapper(CAmSocketHandler* socketHandler, DBusBusType type) : - pDbusPrepareCallback(this,&CAmDbusWrapper::dbusPrepareCallback), // - pDbusDispatchCallback(this, &CAmDbusWrapper::dbusDispatchCallback), // - pDbusFireCallback(this, &CAmDbusWrapper::dbusFireCallback), // - pDbusCheckCallback(this, &CAmDbusWrapper::dbusCheckCallback), // - pDbusTimerCallback(this, &CAmDbusWrapper::dbusTimerCallback), // - mpDbusConnection(0), // - mDBusError(), // - mListNodes(), // - mpListTimerhandles(), // - mpSocketHandler(socketHandler), // - mDbusType(type) -{ - assert(mpSocketHandler!=0); - - dbus_error_init(&mDBusError); - - if (!dbus_threads_init_default()) - logError("CAmDbusWrapper::CAmDbusWrapper threads init call failed"); - logInfo("DBusWrapper::DBusWrapper Opening DBus connection"); - mpDbusConnection = dbus_bus_get(mDbusType, &mDBusError); - if (dbus_error_is_set(&mDBusError)) - { - logError("DBusWrapper::DBusWrapper Error while getting the DBus"); - dbus_error_free(&mDBusError); - } - if (NULL == mpDbusConnection) - { - logError("DBusWrapper::DBusWrapper DBus Connection is null"); - } - - //then we need to adopt the dbus to our mainloop: - //first, we are old enought to live longer then the connection: - dbus_connection_set_exit_on_disconnect(mpDbusConnection, FALSE); - - //we do not need the manual dispatching, since it is not allowed to call from a different thread. So leave it uncommented: - //dbus_connection_set_dispatch_status_function - - //add watch functions: - dbus_bool_t watch = dbus_connection_set_watch_functions(mpDbusConnection, addWatch, removeWatch, toogleWatch, this, NULL); - if (!watch) - { - logError("DBusWrapper::DBusWrapper Registering of watch functions failed"); - } - - //add timer functions: - dbus_bool_t timer = dbus_connection_set_timeout_functions(mpDbusConnection, addTimeout, removeTimeout, toggleTimeout, this, NULL); - if (!timer) - { - logError("DBusWrapper::DBusWrapper Registering of timer functions failed"); - } - - //register callback for Introspectio - mObjectPathVTable.message_function = CAmDbusWrapper::cbRootIntrospection; - logInfo("dbusconnection ",mpDbusConnection); - dbus_connection_register_object_path(mpDbusConnection, DBUS_SERVICE_OBJECT_PATH, &mObjectPathVTable, this); - int ret = dbus_bus_request_name(mpDbusConnection, DBUS_SERVICE_PREFIX, DBUS_NAME_FLAG_DO_NOT_QUEUE, &mDBusError); - if (dbus_error_is_set(&mDBusError)) - { - logError("DBusWrapper::DBusWrapper Name Error", mDBusError.message); - dbus_error_free(&mDBusError); - } - if (DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER != ret) - { - logError("DBusWrapper::DBusWrapper Wrapper is not the Primary Owner ! Another instance already running?"); - throw std::runtime_error("DBusWrapper::DBusWrapper Wrapper is not the Primary Owner ! Another instance already running?"); - } -} - -CAmDbusWrapper::~CAmDbusWrapper() -{ - //close the connection again - logInfo("DBusWrapper::~DBusWrapper Closing DBus connection"); - dbus_connection_unref(mpDbusConnection); - - //clean up all timerhandles we created but did not delete before - std::vector<sh_timerHandle_t*>::iterator it = mpListTimerhandles.begin(); - for (; it != mpListTimerhandles.end(); ++it) - { - delete *it; - } -} - -/** - * registers a callback that is entered as path below the main path. - * The configuration of the mainpath is done via DBusConfiguration.h - * @param vtable the vtable that holds a pointer to the callback that is called when the path is called from the dbus - * @param path the name of the path - * @param userdata pointer to the class that will handle the callback - */ -void CAmDbusWrapper::registerCallback(const DBusObjectPathVTable* vtable, const std::string& path, void* userdata) -{ - logInfo("DBusWrapper::registerCallback register callback:", path); - - std::string completePath = std::string(DBUS_SERVICE_OBJECT_PATH) + "/" + path; - dbus_error_init(&mDBusError); - mpDbusConnection = dbus_bus_get(mDbusType, &mDBusError); - dbus_connection_register_object_path(mpDbusConnection, completePath.c_str(), vtable, userdata); - if (dbus_error_is_set(&mDBusError)) - { - logError("DBusWrapper::registerCallack error: ", mDBusError.message); - dbus_error_free(&mDBusError); - } - mListNodes.push_back(path); -} - -/** - * internal callback for the root introspection - * @param conn - * @param msg - * @param reference - * @return - */ -DBusHandlerResult CAmDbusWrapper::cbRootIntrospection(DBusConnection *conn, DBusMessage *msg, void *reference) -{ - //logInfo("DBusWrapper::~cbRootIntrospection called:"); - - mpReference = (CAmDbusWrapper*) reference; - std::vector<std::string> nodesList = mpReference->mListNodes; - DBusMessage * reply; - DBusMessageIter args; - dbus_uint32_t serial = 0; - if (dbus_message_is_method_call(msg, DBUS_INTERFACE_INTROSPECTABLE, "Introspect")) - { - std::vector<std::string>::iterator nodeIter = nodesList.begin(); - const char *xml = ROOT_INTROSPECT_XML; - std::stringstream introspect; - introspect << std::string(xml); - for (; nodeIter != nodesList.end(); ++nodeIter) - { - introspect << "<node name='" << nodeIter->c_str() << "'/>"; - } - introspect << "</node>"; - - reply = dbus_message_new_method_return(msg); - std::string s = introspect.str(); - const char* string = s.c_str(); - - // add the arguments to the reply - dbus_message_iter_init_append(reply, &args); - if (!dbus_message_iter_append_basic(&args, DBUS_TYPE_STRING, &string)) - { - logError("DBusWrapper::~cbRootIntrospection DBUS Out Of Memory!"); - } - - // send the reply && flush the connection - if (!dbus_connection_send(conn, reply, &serial)) - { - logError("DBusWrapper::~cbRootIntrospection DBUS Out Of Memory!"); - } - dbus_connection_flush(conn); - // free the reply - dbus_message_unref(reply); - - return (DBUS_HANDLER_RESULT_HANDLED); - } - else - { - return (DBUS_HANDLER_RESULT_NOT_YET_HANDLED); - } -} - -/** - * returns the dbus connection - * @param connection pointer to the connection - */ -void CAmDbusWrapper::getDBusConnection(DBusConnection *& connection) const -{ - connection = mpDbusConnection; -} - -dbus_bool_t CAmDbusWrapper::addWatch(DBusWatch *watch, void *userData) -{ - mpReference = (CAmDbusWrapper*) userData; - assert(mpReference!=0); - return (mpReference->addWatchDelegate(watch, userData)); -} - -dbus_bool_t CAmDbusWrapper::addWatchDelegate(DBusWatch * watch, void* userData) -{ - (void) userData; - int16_t event = 0; - sh_pollHandle_t handle = 0; - uint flags = dbus_watch_get_flags(watch); - - /* no watch flags for disabled watches */ - if (dbus_watch_get_enabled(watch)) - { - if (flags & DBUS_WATCH_READABLE) - event |= POLLIN; - if (flags & DBUS_WATCH_WRITABLE) - event |= POLLOUT; - } - - logInfo("DBusWrapper::addWatchDelegate entered new watch, fd=", dbus_watch_get_unix_fd(watch), "event flag=", event); - am_Error_e error = mpSocketHandler->addFDPoll(dbus_watch_get_unix_fd(watch), event, &pDbusPrepareCallback, &pDbusFireCallback, &pDbusCheckCallback, &pDbusDispatchCallback, watch, handle); - - //if everything is alright, add the watch and the handle to our map so we know this relationship - if (error == E_OK && handle != 0) - { - mMapHandleWatch.insert(std::make_pair(watch, handle)); - return (true); - } - logError("DBusWrapper::addWatchDelegate entering watch failed"); - return (true); -} - -void CAmDbusWrapper::removeWatch(DBusWatch *watch, void *userData) -{ - mpReference = (CAmDbusWrapper*) userData; - assert(mpReference!=0); - mpReference->removeWatchDelegate(watch, userData); -} - -void CAmDbusWrapper::removeWatchDelegate(DBusWatch *watch, void *userData) -{ - (void) userData; - std::map<DBusWatch*, sh_pollHandle_t>::iterator iterator = mMapHandleWatch.begin(); - iterator = mMapHandleWatch.find(watch); - if (iterator != mMapHandleWatch.end()) - { - mpSocketHandler->removeFDPoll(iterator->second); - logInfo("DBusWrapper::removeWatch removed watch with handle", iterator->second); - mMapHandleWatch.erase(iterator); - } - else - { - logError("DBusWrapper::removeWatch could not find handle !"); - } -} - -void CAmDbusWrapper::toogleWatch(DBusWatch *watch, void *userData) -{ - mpReference = (CAmDbusWrapper*) userData; - assert(mpReference!=0); - mpReference->toogleWatchDelegate(watch, userData); -} - -void CAmDbusWrapper::toogleWatchDelegate(DBusWatch *watch, void *userData) -{ - (void) userData; - int16_t event = 0; - dbus_watch_get_unix_fd(watch); - uint flags = dbus_watch_get_flags(watch); - /* no watch flags for disabled watches */ - if (dbus_watch_get_enabled(watch)) - { - if (flags & DBUS_WATCH_READABLE) - event |= POLLIN; - if (flags & DBUS_WATCH_WRITABLE) - event |= POLLOUT; - } - std::map<DBusWatch*, sh_pollHandle_t>::iterator iterator = mMapHandleWatch.begin(); - iterator = mMapHandleWatch.find(watch); - if (iterator != mMapHandleWatch.end()) - mpSocketHandler->updateEventFlags(iterator->second, event); -} - -dbus_bool_t CAmDbusWrapper::addTimeout(DBusTimeout *timeout, void* userData) -{ - mpReference = (CAmDbusWrapper*) userData; - assert(mpReference!=0); - return (mpReference->addTimeoutDelegate(timeout, userData)); -} - -dbus_bool_t CAmDbusWrapper::addTimeoutDelegate(DBusTimeout *timeout, void* userData) -{ - (void)userData; - - if (!dbus_timeout_get_enabled(timeout)) - return (false); - - //calculate the timeout in timeval - timespec pollTimeout; - int localTimeout = dbus_timeout_get_interval(timeout); - pollTimeout.tv_sec = localTimeout / 1000; - pollTimeout.tv_nsec = (localTimeout % 1000) * 1000000; - - //prepare handle and callback. new is eval, but there is no other choice because we need the pointer! - sh_timerHandle_t* handle = new sh_timerHandle_t; - mpListTimerhandles.push_back(handle); - - //add the timer to the pollLoop - mpSocketHandler->addTimer(pollTimeout, &pDbusTimerCallback, *handle, timeout); - - //save the handle with dbus context - dbus_timeout_set_data(timeout, handle, NULL); - - //save timeout in Socket context - userData = timeout; - return (true); -} - -void CAmDbusWrapper::removeTimeout(DBusTimeout *timeout, void* userData) -{ - mpReference = (CAmDbusWrapper*) userData; - assert(mpReference!=0); - mpReference->removeTimeoutDelegate(timeout, userData); -} - -void CAmDbusWrapper::removeTimeoutDelegate(DBusTimeout *timeout, void* userData) -{ - (void) userData; - //get the pointer to the handle and remove the timer - sh_timerHandle_t* handle = (sh_timerHandle_t*) dbus_timeout_get_data(timeout); - mpSocketHandler->removeTimer(*handle); - - //now go throught the timerlist and remove the pointer, free memory - std::vector<sh_timerHandle_t*>::iterator it = mpListTimerhandles.begin(); - for (; it != mpListTimerhandles.end(); ++it) - { - if (*it == handle) - { - mpListTimerhandles.erase(it); - break; - } - } - delete handle; - } - -void CAmDbusWrapper::toggleTimeout(DBusTimeout *timeout, void* userData) -{ - mpReference = (CAmDbusWrapper*) userData; - assert(mpReference!=0); - mpReference->toggleTimeoutDelegate(timeout, userData); -} - -bool am::CAmDbusWrapper::dbusDispatchCallback(const sh_pollHandle_t handle, void *userData) -{ - (void) handle; - (void) userData; - bool returnVal = true; - dbus_connection_ref(mpDbusConnection); - if (dbus_connection_dispatch(mpDbusConnection) == DBUS_DISPATCH_COMPLETE) - returnVal = false; - dbus_connection_unref(mpDbusConnection); - //logInfo("DBusWrapper::dbusDispatchCallback was called"); - return (returnVal); -} - -bool am::CAmDbusWrapper::dbusCheckCallback(const sh_pollHandle_t handle, void *userData) -{ - (void) handle; - (void) userData; - bool returnVal = false; - dbus_connection_ref(mpDbusConnection); - if (dbus_connection_get_dispatch_status(mpDbusConnection) == DBUS_DISPATCH_DATA_REMAINS) - returnVal = true; - dbus_connection_unref(mpDbusConnection); - //logInfo("DBusWrapper::dbusCheckCallback was called"); - return (returnVal); -} - -void am::CAmDbusWrapper::dbusFireCallback(const pollfd pollfd, const sh_pollHandle_t handle, void *userData) -{ - (void) handle; - (void) userData; - assert(userData!=NULL); - uint flags = 0; - - if (pollfd.revents & POLLIN) - flags |= DBUS_WATCH_READABLE; - if (pollfd.revents & POLLOUT) - flags |= DBUS_WATCH_WRITABLE; - if (pollfd.revents & POLLHUP) - flags |= DBUS_WATCH_HANGUP; - if (pollfd.revents & POLLERR) - flags |= DBUS_WATCH_ERROR; - - DBusWatch *watch = (DBusWatch*) userData; - - dbus_connection_ref(mpDbusConnection); - dbus_watch_handle(watch, flags); - dbus_connection_unref(mpDbusConnection); - //logInfo("DBusWrapper::dbusFireCallback was called"); -} - -void CAmDbusWrapper::dbusPrepareCallback(const sh_pollHandle_t handle, void* userData) -{ - (void) handle; - (void) userData; - dbus_connection_ref(mpDbusConnection); - while (dbus_connection_get_dispatch_status(mpDbusConnection) == DBUS_DISPATCH_DATA_REMAINS) - { - dbus_connection_dispatch(mpDbusConnection); - //logInfo("prepare was neccessary!"); - } - dbus_connection_unref(mpDbusConnection); -} - -void CAmDbusWrapper::toggleTimeoutDelegate(DBusTimeout *timeout, void* userData) -{ - (void) userData; - //get the pointer to the handle and remove the timer - sh_timerHandle_t* handle = (sh_timerHandle_t*) dbus_timeout_get_data(timeout); - - //stop or restart? - if (dbus_timeout_get_enabled(timeout)) - { - //calculate the timeout in timeval - timespec pollTimeout; - int localTimeout = dbus_timeout_get_interval(timeout); - pollTimeout.tv_sec = localTimeout / 1000; - pollTimeout.tv_nsec = (localTimeout % 1000) * 1000000; - mpSocketHandler->updateTimer(*handle, pollTimeout); - } - else - { - mpSocketHandler->stopTimer(*handle); - } -} - -void CAmDbusWrapper::dbusTimerCallback(sh_timerHandle_t handle, void *userData) -{ - assert(userData!=NULL); - if (dbus_timeout_get_enabled((DBusTimeout*) userData)) - { - mpSocketHandler->restartTimer(handle); - } - dbus_timeout_handle((DBusTimeout*) userData); -} -} - diff --git a/AudioManagerDaemon/src/CAmDltWrapper.cpp b/AudioManagerDaemon/src/CAmDltWrapper.cpp deleted file mode 100644 index fc2aaa4..0000000 --- a/AudioManagerDaemon/src/CAmDltWrapper.cpp +++ /dev/null @@ -1,350 +0,0 @@ -/** - * Copyright (C) 2012, BMW AG - * - * This file is part of GENIVI Project AudioManager. - * - * Contributions are licensed to the GENIVI Alliance under one or more - * Contribution License Agreements. - * - * \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/. - * - * - * \author Christian Mueller, christian.ei.mueller@bmw.de BMW 2011,2012 - * Jens Lorenz, jlorenz@de.adit-jv.com ADIT 2014 - * - * \file CAmDltWrapper.cpp - * For further information see http://www.genivi.org/. - * - */ - - -#include "shared/CAmDltWrapper.h" -#include <string> -#include <sstream> -#include <iostream> -#include <string.h> - -namespace am -{ - -CAmDltWrapper* CAmDltWrapper::mpDLTWrapper = NULL; -pthread_mutex_t CAmDltWrapper::mMutex = PTHREAD_MUTEX_INITIALIZER; - -CAmDltWrapper *CAmDltWrapper::instance(const bool enableNoDLTDebug) -{ - if (!mpDLTWrapper) - mpDLTWrapper = new CAmDltWrapper(enableNoDLTDebug); -#ifndef WITH_DLT - if(enableNoDLTDebug) - mpDLTWrapper->enableNoDLTDebug(true); -#endif - return (mpDLTWrapper); -} - -void CAmDltWrapper::unregisterContext(DltContext & handle) -{ -#ifdef WITH_DLT - dlt_unregister_context(&handle); -#else - (void) handle; -#endif -} - -void CAmDltWrapper::deinit() -{ -#ifdef WITH_DLT - unregisterContext(mDltContext); -#endif -} - -CAmDltWrapper::CAmDltWrapper(const bool enableNoDLTDebug) : -#ifndef WITH_DLT - mEnableNoDLTDebug(enableNoDLTDebug), -#endif - mDltContext(), // - mDltContextData() -{ - (void) enableNoDLTDebug; -#ifndef WITH_DLT - std::cout << "\e[0;34m[DLT]\e[0;30m\tRunning without DLT-support" << std::endl; -#endif -} - -void CAmDltWrapper::registerApp(const char *appid, const char *description) -{ -#ifdef WITH_DLT - dlt_register_app(appid, description); - //register a default context - dlt_register_context(&mDltContext, "def", "default Context registered by DLTWrapper CLass"); -#else - (void) appid; - (void) description; -#endif -} - -void CAmDltWrapper::registerContext(DltContext& handle, const char *contextid, const char *description) -{ -#ifdef WITH_DLT - dlt_register_context(&handle, contextid, description); -#else - strncpy(handle.contextID,contextid,4); - - // store only the first contextID - if(0 == strlen(mDltContext.contextID)) - { - memcpy(&mDltContext.contextID,contextid,4); - const size_t str_len = strlen(description); - if(str_len < 2000) - { - mDltContextData.context_description = new char[str_len + 1]; - (void) strcpy(mDltContextData.context_description,description); - } - } - - std::cout << "\e[0;34m[DLT]\e[0;30m\tRegistering Context " << contextid << " , " << description << std::endl; - -#endif -} - -bool CAmDltWrapper::init(DltLogLevelType loglevel, DltContext* context) -{ - (void) loglevel; - pthread_mutex_lock(&mMutex); - if (!context) - context = &mDltContext; -#ifdef WITH_DLT - if (dlt_user_log_write_start(context, &mDltContextData, loglevel) <= 0) - { - pthread_mutex_unlock(&mMutex); - return false; - } -#else - if(mEnableNoDLTDebug) - std::cout << "\e[0;34m[" << context->contextID << "]\e[0;30m\t"; -#endif - return true; -} - -void CAmDltWrapper::send() -{ -#ifdef WITH_DLT - dlt_user_log_write_finish(&mDltContextData); -#else - if(mEnableNoDLTDebug) - std::cout << mDltContextData.buffer.str().c_str() << std::endl; - - mDltContextData.buffer.str(""); - mDltContextData.buffer.clear(); -#endif - pthread_mutex_unlock(&mMutex); -} - -void CAmDltWrapper::append(const int8_t value) -{ -#ifdef WITH_DLT - dlt_user_log_write_int8(&mDltContextData, value); -#else - appendNoDLT(value); -#endif -} - -void CAmDltWrapper::append(const uint8_t value) -{ -#ifdef WITH_DLT - dlt_user_log_write_uint8(&mDltContextData, value); -#else - appendNoDLT(value); -#endif -} - -void CAmDltWrapper::append(const int16_t value) -{ -#ifdef WITH_DLT - dlt_user_log_write_int16(&mDltContextData, value); -#else - appendNoDLT(value); -#endif -} - -void CAmDltWrapper::append(const uint16_t value) -{ -#ifdef WITH_DLT - dlt_user_log_write_uint16(&mDltContextData, value); -#else - appendNoDLT(value); -#endif -} - -void CAmDltWrapper::append(const int32_t value) -{ -#ifdef WITH_DLT - dlt_user_log_write_int32(&mDltContextData, value); -#else - appendNoDLT(value); -#endif -} - -void CAmDltWrapper::append(const uint32_t value) -{ -#ifdef WITH_DLT - dlt_user_log_write_uint32(&mDltContextData, value); -#else - appendNoDLT(value); -#endif -} - -void CAmDltWrapper::append(const char*& value) -{ -#ifdef WITH_DLT - dlt_user_log_write_string(&mDltContextData, value); -#else - mDltContextData.buffer << value; -#endif -} - -void CAmDltWrapper::append(const std::string& value) -{ -#ifdef WITH_DLT - dlt_user_log_write_string(&mDltContextData, value.c_str()); -#else - mDltContextData.buffer << value; -#endif -} - -void CAmDltWrapper::append(const bool value) -{ -#ifdef WITH_DLT - dlt_user_log_write_bool(&mDltContextData, static_cast<uint8_t>(value)); -#else - appendNoDLT(value); -#endif -} - -void CAmDltWrapper::append(const int64_t value) -{ -#ifdef WITH_DLT - dlt_user_log_write_int64(&mDltContextData, value); -#else - appendNoDLT(value); -#endif -} - -void CAmDltWrapper::append(const uint64_t value) -{ -#ifdef WITH_DLT - dlt_user_log_write_uint64(&mDltContextData, value); -#else - appendNoDLT(value); -#endif -} - -void CAmDltWrapper::append(const am_Error_e value) -{ - switch (value) - { - case am_Error_e::E_OK: - #ifdef WITH_DLT - dlt_user_log_write_string(&mDltContextData, "E_OK"); - #else - mDltContextData.buffer << "E_OK"; - #endif - break; - case am_Error_e::E_ABORTED: - #ifdef WITH_DLT - dlt_user_log_write_string(&mDltContextData, "E_ABORTED"); - #else - mDltContextData.buffer << "E_ABORTED"; - #endif - break; - case am_Error_e::E_ALREADY_EXISTS: - #ifdef WITH_DLT - dlt_user_log_write_string(&mDltContextData, "E_ALREADY_EXISTS"); - #else - mDltContextData.buffer << "E_ALREADY_EXISTS"; - #endif - break; - case am_Error_e::E_DATABASE_ERROR: - #ifdef WITH_DLT - dlt_user_log_write_string(&mDltContextData, "E_DATABASE_ERROR"); - #else - mDltContextData.buffer << "E_DATABASE_ERROR"; - #endif - break; - case am_Error_e::E_NON_EXISTENT: - #ifdef WITH_DLT - dlt_user_log_write_string(&mDltContextData, "E_NON_EXISTENT"); - #else - mDltContextData.buffer << "E_NON_EXISTENT"; - #endif - break; - case am_Error_e::E_NOT_POSSIBLE: - #ifdef WITH_DLT - dlt_user_log_write_string(&mDltContextData, "E_NOT_POSSIBLE"); - #else - mDltContextData.buffer << "E_NOT_POSSIBLE"; - #endif - break; - case am_Error_e::E_NOT_USED: - #ifdef WITH_DLT - dlt_user_log_write_string(&mDltContextData, "E_NOT_USED"); - #else - mDltContextData.buffer << "E_NOT_USED"; - #endif - break; - case am_Error_e::E_NO_CHANGE: - #ifdef WITH_DLT - dlt_user_log_write_string(&mDltContextData, "E_NO_CHANGE"); - #else - mDltContextData.buffer << "E_NO_CHANGE"; - #endif - break; - case am_Error_e::E_OUT_OF_RANGE: - #ifdef WITH_DLT - dlt_user_log_write_string(&mDltContextData, "E_OUT_OF_RANGE"); - #else - mDltContextData.buffer << "E_OUT_OF_RANGE"; - #endif - break; - case am_Error_e::E_UNKNOWN: - #ifdef WITH_DLT - dlt_user_log_write_string(&mDltContextData, "E_UNKNOWN"); - #else - mDltContextData.buffer << "E_UNKNOWN"; - #endif - break; - default: - #ifdef WITH_DLT - dlt_user_log_write_string(&mDltContextData, "E_UNKNOWN"); - #else - mDltContextData.buffer << "E_UNKNOWN"; - #endif - - } -} - -#ifndef WITH_DLT -template<class T> void CAmDltWrapper::appendNoDLT(T value) -{ - mDltContextData.buffer << value; -} - -void CAmDltWrapper::enableNoDLTDebug(const bool enableNoDLTDebug) -{ - mEnableNoDLTDebug = enableNoDLTDebug; -} -#endif - -CAmDltWrapper::~CAmDltWrapper() -{ - if (mpDLTWrapper) - { - mpDLTWrapper->unregisterContext(mDltContext); - delete mpDLTWrapper; - } -} -} - - diff --git a/AudioManagerDaemon/src/CAmNodeStateCommunicatorCAPI.cpp b/AudioManagerDaemon/src/CAmNodeStateCommunicatorCAPI.cpp index d772837..19aaa4b 100644 --- a/AudioManagerDaemon/src/CAmNodeStateCommunicatorCAPI.cpp +++ b/AudioManagerDaemon/src/CAmNodeStateCommunicatorCAPI.cpp @@ -1,5 +1,5 @@ /** - * Copyright (C) 2012, BMW AG +Von mir aus gerne. * Copyright (C) 2012, BMW AG * * This file is part of GENIVI Project AudioManager. * @@ -28,8 +28,8 @@ #include <memory> #include <CommonAPI/CommonAPI.h> #include "config.h" -#include "shared/CAmCommonAPIWrapper.h" -#include "shared/CAmDltWrapper.h" +#include "CAmCommonAPIWrapper.h" +#include "CAmDltWrapper.h" #include "CAmNodeStateCommunicatorCAPI.h" #include "CAmControlSender.h" #include <org/genivi/NodeStateManager/LifeCycleConsumerProxy.h> diff --git a/AudioManagerDaemon/src/CAmNodeStateCommunicatorDBus.cpp b/AudioManagerDaemon/src/CAmNodeStateCommunicatorDBus.cpp index 4173890..14f208b 100644 --- a/AudioManagerDaemon/src/CAmNodeStateCommunicatorDBus.cpp +++ b/AudioManagerDaemon/src/CAmNodeStateCommunicatorDBus.cpp @@ -26,7 +26,7 @@ #include <sstream> #include <stdexcept> #include "CAmControlSender.h" -#include "shared/CAmDltWrapper.h" +#include "CAmDltWrapper.h" #include "config.h" namespace am diff --git a/AudioManagerDaemon/src/CAmRouter.cpp b/AudioManagerDaemon/src/CAmRouter.cpp index 6ab0a07..8e3069d 100644 --- a/AudioManagerDaemon/src/CAmRouter.cpp +++ b/AudioManagerDaemon/src/CAmRouter.cpp @@ -12,7 +12,7 @@ * this file, You can obtain one at http://mozilla.org/MPL/2.0/. * * - * \author Christian Mueller, christian.ei.mueller@bmw.de BMW 2011,2012 + * \author Christian Linke, christian.linke@bmw.de BMW 2011,2012 * \author Aleksandar Donchev, Aleksander.Donchev@partner.bmw.de BMW 2013,2014 * * \file CAmRouter.cpp @@ -27,7 +27,7 @@ #include "CAmRouter.h" #include "IAmDatabaseHandler.h" #include "CAmControlSender.h" -#include "shared/CAmDltWrapper.h" +#include "CAmDltWrapper.h" diff --git a/AudioManagerDaemon/src/CAmRoutingReceiver.cpp b/AudioManagerDaemon/src/CAmRoutingReceiver.cpp index 29f7db7..c36cde7 100644 --- a/AudioManagerDaemon/src/CAmRoutingReceiver.cpp +++ b/AudioManagerDaemon/src/CAmRoutingReceiver.cpp @@ -12,7 +12,7 @@ * this file, You can obtain one at http://mozilla.org/MPL/2.0/. * * - * \author Christian Mueller, christian.ei.mueller@bmw.de BMW 2011,2012 + * \author Christian Linke, christian.linke@bmw.de BMW 2011,2012 * * \file CAmRoutingReceiver.cpp * For further information see http://www.genivi.org/. @@ -25,8 +25,8 @@ #include "IAmDatabaseHandler.h" #include "CAmRoutingSender.h" #include "CAmControlSender.h" -#include "shared/CAmDltWrapper.h" -#include "shared/CAmSocketHandler.h" +#include "CAmDltWrapper.h" +#include "CAmSocketHandler.h" namespace am { diff --git a/AudioManagerDaemon/src/CAmRoutingSender.cpp b/AudioManagerDaemon/src/CAmRoutingSender.cpp index cd9c3d7..77f12d0 100644 --- a/AudioManagerDaemon/src/CAmRoutingSender.cpp +++ b/AudioManagerDaemon/src/CAmRoutingSender.cpp @@ -12,7 +12,7 @@ * this file, You can obtain one at http://mozilla.org/MPL/2.0/. * * - * \author Christian Mueller, christian.ei.mueller@bmw.de BMW 2011,2012 + * \author Christian Linke, christian.linke@bmw.de BMW 2011,2012 * * \file CAmRoutingSender.cpp * For further information see http://www.genivi.org/. @@ -31,7 +31,7 @@ #include <sstream> #include "CAmRoutingReceiver.h" #include "TAmPluginTemplate.h" -#include "shared/CAmDltWrapper.h" +#include "CAmDltWrapper.h" namespace am { diff --git a/AudioManagerDaemon/src/CAmSocketHandler.cpp b/AudioManagerDaemon/src/CAmSocketHandler.cpp deleted file mode 100644 index 455cb32..0000000 --- a/AudioManagerDaemon/src/CAmSocketHandler.cpp +++ /dev/null @@ -1,546 +0,0 @@ -/** - * Copyright (C) 2012, BMW AG - * - * This file is part of GENIVI Project AudioManager. - * - * Contributions are licensed to the GENIVI Alliance under one or more - * Contribution License Agreements. - * - * \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/. - * - * - * \author Christian Mueller, christian.ei.mueller@bmw.de BMW 2011,2012 - * - * \file CAmSocketHandler.cpp - * For further information see http://www.genivi.org/. - * - */ - -#include "shared/CAmSocketHandler.h" -#include <config.h> -#include <cassert> -#include <sys/fcntl.h> -#include <sys/errno.h> -#include <sys/poll.h> -#include <time.h> -#include <algorithm> -#include <features.h> -#include <csignal> -#include <unistd.h> -#include "shared/CAmDltWrapper.h" - -namespace am -{ - -CAmSocketHandler::CAmSocketHandler() : - receiverCallbackT(this, &CAmSocketHandler::receiverCallback),// - checkerCallbackT(this, &CAmSocketHandler::checkerCallback),// - mPipe(), // - mDispatchDone(1),// - mListPoll(), // - mListTimer(), // - mListActiveTimer(), // - mLastInsertedHandle(0), // - mLastInsertedPollHandle(0), // - mRecreatePollfds(true), // - mStartTime() // -{ - if (pipe(mPipe) == -1) - { - logError("CAmSerializer could not create pipe!"); - } - - //add the pipe to the poll - nothing needs to be proccessed here we just need the pipe to trigger the ppoll - short event = 0; - sh_pollHandle_t handle; - event |= POLLIN; - addFDPoll(mPipe[0], event, NULL, &receiverCallbackT, &checkerCallbackT, NULL, NULL, handle); -} - -CAmSocketHandler::~CAmSocketHandler() -{ -} - -//todo: maybe have some: give me more time returned? -/** - * start the block listening for filedescriptors. This is the mainloop. - */ -void CAmSocketHandler::start_listenting() -{ - mDispatchDone = 0; - int16_t pollStatus; - - //prepare the signalmask - sigset_t sigmask; - sigemptyset(&sigmask); - sigaddset(&sigmask, SIGINT); - sigaddset(&sigmask, SIGQUIT); - sigaddset(&sigmask, SIGTERM); - sigaddset(&sigmask, SIGHUP); - sigaddset(&sigmask, SIGQUIT); - - clock_gettime(CLOCK_MONOTONIC, &mStartTime); - while (!mDispatchDone) - { - //first we go through the registered filedescriptors and check if someone needs preparation: - std::for_each(mListPoll.begin(), mListPoll.end(), CAmShCallPrep()); - - if (mRecreatePollfds) - { - mfdPollingArray.clear(); - //there was a change in the setup, so we need to recreate the fdarray from the list - std::for_each(mListPoll.begin(), mListPoll.end(), CAmShCopyPollfd(mfdPollingArray)); - mRecreatePollfds = false; - } - - timerCorrection(); - - //block until something is on a filedescriptor - - timespec buffertime; - if ((pollStatus = ppoll(&mfdPollingArray[0], mfdPollingArray.size(), insertTime(buffertime), &sigmask)) < 0) - { - if (errno == EINTR) - { - //a signal was received, that means it's time to go... - pollStatus = 0; - } - else - { - logError("SocketHandler::start_listenting ppoll returned with error", errno); - exit(0); - } - } - - if (pollStatus != 0) //only check filedescriptors if there was a change - { - //todo: here could be a timer that makes sure naughty plugins return! - - //freeze mListPoll by copying it - otherwise we get problems when we want to manipulate it during the next lines - std::list<sh_poll_s> listPoll; - mListPoll_t::iterator listmPollIt; - - //remove all filedescriptors who did not fire - std::vector<pollfd>::iterator it = mfdPollingArray.begin(); - do - { - it = std::find_if(it, mfdPollingArray.end(), eventFired); - if (it != mfdPollingArray.end()) - { - listmPollIt = mListPoll.begin(); - std::advance(listmPollIt, std::distance(mfdPollingArray.begin(), it)); - listPoll.push_back(*listmPollIt); - listPoll.back().pollfdValue = *it; - it++; - } - } while (it != mfdPollingArray.end()); - - //stage 1, call firedCB - std::for_each(listPoll.begin(), listPoll.end(), CAmShCallFire()); - - //stage 2, lets ask around if some dispatching is necessary, the ones who need stay on the list - listPoll.remove_if(noDispatching); - - //stage 3, the ones left need to dispatch, we do this as long as there is something to dispatch.. - do - { - listPoll.remove_if(dispatchingFinished); - } while (!listPoll.empty()); - - } - else //Timerevent - { - //this was a timer event, we need to take care about the timers - timerUp(); - } - } -} - -/** - * exits the loop - */ -void CAmSocketHandler::stop_listening() -{ - mDispatchDone = 1; - - //this is for all running timers only - we need to handle the additional offset here - if (!mListActiveTimer.empty()) - { - timespec currentTime, correctionTime; - clock_gettime(CLOCK_MONOTONIC, ¤tTime); - correctionTime = timespecSub(currentTime, mStartTime); - std::for_each(mListActiveTimer.begin(), mListActiveTimer.end(), CAmShSubstractTime(correctionTime)); - } - -} - -/** - * Adds a filedescriptor to the polling loop - * @param fd the filedescriptor - * @param event the event flags - * @param prepare a callback that is called before the loop is entered - * @param fired a callback that is called when the filedescriptor needs to be read - * @param check a callback that is called to check if further actions are neccessary - * @param dispatch a callback that is called to dispatch the received data - * @param userData a pointer to userdata that is always passed around - * @param handle the handle of this poll - * @return E_OK if the descriptor was added, E_NON_EXISTENT if the fd is not valid - */ -am_Error_e CAmSocketHandler::addFDPoll(const int fd, const short event, IAmShPollPrepare *prepare, IAmShPollFired *fired, IAmShPollCheck *check, IAmShPollDispatch *dispatch, void *userData, sh_pollHandle_t & handle) -{ - if (!fdIsValid(fd)) - return (E_NON_EXISTENT); - - sh_poll_s pollData; - pollData.pollfdValue.fd = fd; - pollData.handle = ++mLastInsertedPollHandle; - pollData.pollfdValue.events = event; - pollData.pollfdValue.revents = 0; - pollData.userData = userData; - pollData.prepareCB = prepare; - pollData.firedCB = fired; - pollData.checkCB = check; - pollData.dispatchCB = dispatch; - - //add new data to the list - mListPoll.push_back(pollData); - - mRecreatePollfds = true; - - handle = pollData.handle; - return (E_OK); -} - -/** - * removes a filedescriptor from the poll loop - * @param handle - * @return - */ -am_Error_e CAmSocketHandler::removeFDPoll(const sh_pollHandle_t handle) -{ - mListPoll_t::iterator iterator = mListPoll.begin(); - - for (; iterator != mListPoll.end(); ++iterator) - { - if (iterator->handle == handle) - { - iterator = mListPoll.erase(iterator); - mRecreatePollfds = true; - return (E_OK); - } - } - return (E_UNKNOWN); -} - -/** - * adds a timer to the list of timers. The callback will be fired when the timer is up. - * This is not a high precise timer, it is very coarse. It is meant to be used for timeouts when waiting - * for an answer via a filedescriptor. - * One time timer. If you need again a timer, you need to add a new timer in the callback of the old one. - * @param timeouts timeouts time until the callback is fired - * @param callback callback the callback - * @param handle handle the handle that is created for the timer is returned. Can be used to remove the timer - * @param userData pointer always passed with the call - * @return E_OK in case of success - */ -am_Error_e CAmSocketHandler::addTimer(const timespec timeouts, IAmShTimerCallBack* callback, sh_timerHandle_t& handle, void * userData) -{ - assert(!((timeouts.tv_sec==0) && (timeouts.tv_nsec==0))); - assert(callback!=NULL); - - sh_timer_s timerItem; - - //create a new handle for the timer - handle = ++mLastInsertedHandle; //todo: overflow ruling !o - timerItem.handle = handle; - timerItem.countdown = timeouts; - timerItem.callback = callback; - timerItem.userData = userData; - - mListTimer.push_back(timerItem); - - //we add here the time difference between startTime and currenttime, because this time will be substracted later on in timecorrection - timespec currentTime; - clock_gettime(CLOCK_MONOTONIC, ¤tTime); - if (!mDispatchDone) //the mainloop is started - timerItem.countdown = timespecAdd(timeouts, timespecSub(currentTime, mStartTime)); - - mListActiveTimer.push_back(timerItem); - mListActiveTimer.sort(compareCountdown); - return (E_OK); -} - -/** - * removes a timer from the list of timers - * @param handle the handle to the timer - * @return E_OK in case of success, E_UNKNOWN if timer was not found. - */ -am_Error_e CAmSocketHandler::removeTimer(const sh_timerHandle_t handle) -{ - assert(handle!=0); - - //stop the current timer - stopTimer(handle); - - std::list<sh_timer_s>::iterator it(mListTimer.begin()); - for (; it != mListTimer.end(); ++it) - { - if (it->handle == handle) - { - it = mListTimer.erase(it); - return (E_OK); - } - } - return (E_UNKNOWN); -} - -/** - * restarts a timer and updates with a new interva - * @param handle handle to the timer - * @param timeouts new timout time - * @return E_OK on success, E_NON_EXISTENT if the handle was not found - */ -am_Error_e CAmSocketHandler::updateTimer(const sh_timerHandle_t handle, const timespec timeouts) -{ - //update the mList .... - sh_timer_s timerItem; - std::list<sh_timer_s>::iterator it(mListTimer.begin()), activeIt(mListActiveTimer.begin()); - bool found(false); - for (; it != mListTimer.end(); ++it) - { - if (it->handle == handle) - { - it->countdown = timeouts; - timerItem = *it; - found = true; - break; - } - } - if (!found) - return (E_NON_EXISTENT); - - found = false; - - //we add here the time difference between startTime and currenttime, because this time will be substracted later on in timecorrection - timespec currentTime, timeoutsCorrected; - currentTime.tv_nsec=timeoutsCorrected.tv_nsec=0; - currentTime.tv_sec=timeoutsCorrected.tv_sec=0; - clock_gettime(CLOCK_MONOTONIC, ¤tTime); - if (!mDispatchDone) //the mainloop is started - timeoutsCorrected = timespecAdd(timeouts, timespecSub(currentTime, mStartTime)); - - for (; activeIt != mListActiveTimer.end(); ++activeIt) - { - if (activeIt->handle == handle) - { - activeIt->countdown = timeoutsCorrected; - found = true; - break; - } - } - - if (!found) - timerItem.countdown = timeoutsCorrected; - mListActiveTimer.push_back(timerItem); - - mListActiveTimer.sort(compareCountdown); - return (E_OK); -} - -/** - * restarts a timer with the original value - * @param handle - * @return E_OK on success, E_NON_EXISTENT if the handle was not found - */ -am_Error_e CAmSocketHandler::restartTimer(const sh_timerHandle_t handle) -{ - sh_timer_s timerItem; //!<the original timer value - //find the original value - std::list<sh_timer_s>::iterator it(mListTimer.begin()), activeIt(mListActiveTimer.begin()); - bool found(false); - for (; it != mListTimer.end(); ++it) - { - if (it->handle == handle) - { - timerItem = *it; - found = true; - break; - } - } - if (!found) - return (E_NON_EXISTENT); - - found = false; - - //we add here the time difference between startTime and currenttime, because this time will be substracted later on in timecorrection - timespec currentTime, timeoutsCorrected; - clock_gettime(CLOCK_MONOTONIC, ¤tTime); - if (!mDispatchDone) //the mainloop is started - { - timeoutsCorrected = timespecAdd(timerItem.countdown, timespecSub(currentTime, mStartTime)); - timerItem.countdown = timeoutsCorrected; - } - - for (; activeIt != mListActiveTimer.end(); ++activeIt) - { - if (activeIt->handle == handle) - { - activeIt->countdown = timerItem.countdown; - found = true; - break; - } - } - - if (!found) - mListActiveTimer.push_back(timerItem); - - mListActiveTimer.sort(compareCountdown); - - return (E_OK); -} - -/** - * stops a timer - * @param handle - * @return E_OK on success, E_NON_EXISTENT if the handle was not found - */ -am_Error_e CAmSocketHandler::stopTimer(const sh_timerHandle_t handle) -{ - //go through the list and remove the timer with the handle - std::list<sh_timer_s>::iterator it(mListActiveTimer.begin()); - for (; it != mListActiveTimer.end(); ++it) - { - if (it->handle == handle) - { - it = mListActiveTimer.erase(it); - return (E_OK); - } - } - return (E_NON_EXISTENT); -} - -/** - * updates the eventFlags of a poll - * @param handle - * @param events - * @return @return E_OK on succsess, E_NON_EXISTENT if fd was not found - */ -am_Error_e CAmSocketHandler::updateEventFlags(const sh_pollHandle_t handle, const short events) -{ - mListPoll_t::iterator iterator = mListPoll.begin(); - - for (; iterator != mListPoll.end(); ++iterator) - { - if (iterator->handle == handle) - { - iterator->pollfdValue.events = events; - mRecreatePollfds = true; - return (E_OK); - } - } - return (E_UNKNOWN); -} - -/** - * checks if a filedescriptor is validCAmShSubstractTime - * @param fd the filedescriptor - * @return true if the fd is valid - */ -bool CAmSocketHandler::fdIsValid(const int fd) const -{ - return (fcntl(fd, F_GETFL) != -1 || errno != EBADF); -} - -/** - * timer is up. - */ -void CAmSocketHandler::timerUp() -{ - //find out the timedifference to starttime - timespec currentTime, diffTime; - clock_gettime(CLOCK_MONOTONIC, ¤tTime); - diffTime = timespecSub(currentTime, mStartTime); - - //now we need to substract the diffTime from all timers and see if they are up - std::list<sh_timer_s>::reverse_iterator overflowIter = std::find_if(mListActiveTimer.rbegin(), mListActiveTimer.rend(), CAmShCountdownUp(diffTime)); - - //copy all fired timers into a list - std::vector<sh_timer_s> tempList(overflowIter, mListActiveTimer.rend()); - - //erase all fired timers - std::list<sh_timer_s>::iterator it(overflowIter.base()); - mListActiveTimer.erase(mListActiveTimer.begin(), it); - - //call the callbacks for the timers - std::for_each(tempList.begin(), tempList.end(), CAmShCallTimer()); -} - -/** - * correct timers and fire the ones who are up - */ -void CAmSocketHandler::timerCorrection() -{ - //get the current time and calculate the correction value - timespec currentTime, correctionTime; - clock_gettime(CLOCK_MONOTONIC, ¤tTime); - correctionTime = timespecSub(currentTime, mStartTime); - mStartTime = currentTime; - - if (!mListActiveTimer.empty()) - { - - //subtract the correction value from all items in the list - std::for_each(mListActiveTimer.begin(), mListActiveTimer.end(), CAmShSubstractTime(correctionTime)); - - //find the last occurrence of zero -> timer overflowed - std::list<sh_timer_s>::reverse_iterator overflowIter = std::find_if(mListActiveTimer.rbegin(), mListActiveTimer.rend(), CAmShCountdownZero()); - - //only if a timer overflowed - if (overflowIter != mListActiveTimer.rend()) - { - //copy all timers that need to be called to a new list - std::vector<sh_timer_s> tempList(overflowIter, mListActiveTimer.rend()); - - //erase all fired timers - std::list<sh_timer_s>::iterator it(overflowIter.base()); - mListActiveTimer.erase(mListActiveTimer.begin(), it); - - //call the callbacks for the timers - std::for_each(tempList.begin(), tempList.end(), CAmShCallTimer()); - } - } -} - -void CAmSocketHandler::exit_mainloop() -{ - //end the while loop - stop_listening(); - - //fire the ending filedescriptor - int p(1); - write(mPipe[1], &p, sizeof(p)); -} - -/** - * is used to set the pointer for the ppoll command - * @param buffertime - * @return - */ -inline timespec* CAmSocketHandler::insertTime(timespec& buffertime) -{ - if (!mListActiveTimer.empty()) - { - buffertime = mListActiveTimer.front().countdown; - return (&buffertime); - } - else - { - return (NULL); - } -} - -} - diff --git a/AudioManagerDaemon/src/CAmTelnetMenuHelper.cpp b/AudioManagerDaemon/src/CAmTelnetMenuHelper.cpp index 1fb3ddf..f2fe095 100644 --- a/AudioManagerDaemon/src/CAmTelnetMenuHelper.cpp +++ b/AudioManagerDaemon/src/CAmTelnetMenuHelper.cpp @@ -12,7 +12,7 @@ * this file, You can obtain one at http://mozilla.org/MPL/2.0/. * * - * \author Christian Mueller, christian.ei.mueller@bmw.de BMW 2011,2012 + * \author Christian Linke, christian.linke@bmw.de BMW 2011,2012 * \author Frank Herchet, frank.fh.herchet@bmw.de BMW 2012 * * \file CAmTelnetMenuHelper.cpp @@ -32,7 +32,7 @@ #include "CAmRoutingReceiver.h" #include "CAmCommandReceiver.h" #include "CAmControlReceiver.h" -#include "shared/CAmDltWrapper.h" +#include "CAmDltWrapper.h" static const std::string COLOR_WELCOME("\033[1;33m\033[44m"); static const std::string COLOR_HEAD("\033[1m\033[42m"); diff --git a/AudioManagerDaemon/src/CAmTelnetServer.cpp b/AudioManagerDaemon/src/CAmTelnetServer.cpp index 3212ea7..4ae7420 100755 --- a/AudioManagerDaemon/src/CAmTelnetServer.cpp +++ b/AudioManagerDaemon/src/CAmTelnetServer.cpp @@ -12,7 +12,7 @@ * this file, You can obtain one at http://mozilla.org/MPL/2.0/. * * - * \author Christian Mueller, christian.ei.mueller@bmw.de BMW 2011,2012 + * \author Christian Linke, christian.linke@bmw.de BMW 2011,2012 * \author Frank Herchet, frank.fh.herchet@bmw.de BMW 2012 * * \file CAmTelnetServer.cpp @@ -38,7 +38,7 @@ #include <cstdlib> #include "CAmRoutingSender.h" #include "CAmTelnetMenuHelper.h" -#include "shared/CAmDltWrapper.h" +#include "CAmDltWrapper.h" namespace am { diff --git a/AudioManagerDaemon/src/CAmWatchdog.cpp b/AudioManagerDaemon/src/CAmWatchdog.cpp index db34009..874696e 100755 --- a/AudioManagerDaemon/src/CAmWatchdog.cpp +++ b/AudioManagerDaemon/src/CAmWatchdog.cpp @@ -12,7 +12,7 @@ * this file, You can obtain one at http://mozilla.org/MPL/2.0/. * * - * \author Christian Mueller, christian.ei.mueller@bmw.de BMW 2011,2012 + * \author Christian Linke, christian.linke@bmw.de BMW 2011,2012 * * \file CAmWatchdog.cpp * For further information see http://www.genivi.org/. @@ -24,7 +24,7 @@ #include <cstdlib> #include <stdexcept> #include "config.h" -#include "shared/CAmDltWrapper.h" +#include "CAmDltWrapper.h" #ifdef SYSTEMD_FOUND #include <systemd/sd-daemon.h> diff --git a/AudioManagerDaemon/src/main.cpp b/AudioManagerDaemon/src/main.cpp index c6d212e..b8a0688 100755 --- a/AudioManagerDaemon/src/main.cpp +++ b/AudioManagerDaemon/src/main.cpp @@ -12,7 +12,7 @@ * this file, You can obtain one at http://mozilla.org/MPL/2.0/. * * - * \author Christian Mueller, christian.ei.mueller@bmw.de BMW 2011,2012 + * \author Christian Linke, christian.linke@bmw.de BMW 2011,2012 * \author Frank Herchet, frank.fh.herchet@bmw.de BMW 2012 * * \file main.cpp @@ -34,10 +34,10 @@ #endif #ifdef WITH_CAPI_WRAPPER - #include "shared/CAmCommonAPIWrapper.h" + #include "CAmCommonAPIWrapper.h" #else #ifdef WITH_DBUS_WRAPPER - #include "shared/CAmDbusWrapper.h" + #include "CAmDbusWrapper.h" #endif #endif @@ -79,8 +79,8 @@ #include "CAmCommandReceiver.h" #include "CAmControlReceiver.h" #include "CAmDatabaseObserver.h" -#include "shared/CAmDltWrapper.h" -#include "shared/CAmSocketHandler.h" +#include "CAmDltWrapper.h" +#include "CAmSocketHandler.h" using namespace am; |