#include <fstream>
#include <sstream>
#include <string>
-#include <dlt/dlt.h>
-#include <assert.h>
-#include <stdlib.h>
+#include <cassert>
+#include <cstdlib>
+#include "DLTWrapper.h"
using namespace am;
-DLT_IMPORT_CONTEXT(AudioManager)
-
#define ROOT_INTROSPECT_XML \
DBUS_INTROSPECT_1_0_XML_DOCTYPE_DECL_NODE \
"<node>" \
mListTimerhandlePointer()
{
dbus_error_init(&mDBusError);
- DLT_LOG(AudioManager, DLT_LOG_INFO, DLT_STRING("DBusWrapper::DBusWrapper Opening DBus connection"));
+ logInfo("DBusWrapper::DBusWrapper Opening DBus connection");
mDbusConnection = dbus_bus_get(DBUS_BUS_SESSION, &mDBusError);
if (dbus_error_is_set(&mDBusError))
{
- DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DBusWrapper::DBusWrapper Error while getting the DBus"));
+ logError("DBusWrapper::DBusWrapper Error while getting the DBus");
dbus_error_free(&mDBusError);
}
if (NULL == mDbusConnection)
{
- DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DBusWrapper::DBusWrapper DBus Connection is null"));
+ logError("DBusWrapper::DBusWrapper DBus Connection is null");
}
//first, we are old enought to live longer then the connection:
int ret = dbus_bus_request_name(mDbusConnection, DBUS_SERVICE_PREFIX, DBUS_NAME_FLAG_DO_NOT_QUEUE, &mDBusError);
if (dbus_error_is_set(&mDBusError))
{
- DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DBusWrapper::DBusWrapper Name Error"), DLT_STRING(mDBusError.message));
+ logError("DBusWrapper::DBusWrapper Name Error",mDBusError.message);
dbus_error_free(&mDBusError);
}
if (DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER != ret)
{
- DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DBusWrapper::DBusWrapper Wrapper is not the Primary Owner"), DLT_INT(ret));
+ logError("DBusWrapper::DBusWrapper Wrapper is not the Primary Owner",ret);
exit(1);
}
}
assert(mSocketHandler!=0);
dbus_error_init(&mDBusError);
- DLT_LOG(AudioManager, DLT_LOG_INFO, DLT_STRING("DBusWrapper::DBusWrapper Opening DBus connection"));
+ logInfo("DBusWrapper::DBusWrapper Opening DBus connection");
mDbusConnection = dbus_bus_get(DBUS_BUS_SESSION, &mDBusError);
if (dbus_error_is_set(&mDBusError))
{
- DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DBusWrapper::DBusWrapper Error while getting the DBus"));
+ logError("DBusWrapper::DBusWrapper Error while getting the DBus");
dbus_error_free(&mDBusError);
}
if (NULL == mDbusConnection)
{
- DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DBusWrapper::DBusWrapper DBus Connection is null"));
+ logError("DBusWrapper::DBusWrapper DBus Connection is null");
}
//then we need to adopt the dbus to our mainloop:
dbus_bool_t watch = dbus_connection_set_watch_functions(mDbusConnection, addWatch, removeWatch, toogleWatch, this, NULL);
if (!watch)
{
- DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DBusWrapper::DBusWrapper Registering of watch functions failed"));
+ logError("DBusWrapper::DBusWrapper Registering of watch functions failed");
}
//add timer functions:
dbus_bool_t timer = dbus_connection_set_timeout_functions(mDbusConnection, addTimeout, removeTimeout, toggleTimeout, this, NULL);
if (!timer)
{
- DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DBusWrapper::DBusWrapper Registering of timer functions failed"));
+ logError("DBusWrapper::DBusWrapper Registering of timer functions failed");
}
//register callback for Introspectio
int ret = dbus_bus_request_name(mDbusConnection, DBUS_SERVICE_PREFIX, DBUS_NAME_FLAG_DO_NOT_QUEUE, &mDBusError);
if (dbus_error_is_set(&mDBusError))
{
- DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DBusWrapper::DBusWrapper Name Error"), DLT_STRING(mDBusError.message));
+ logError("DBusWrapper::DBusWrapper Name Error",mDBusError.message);
dbus_error_free(&mDBusError);
}
if (DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER != ret)
{
- DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DBusWrapper::DBusWrapper Wrapper is not the Primary Owner"), DLT_INT(ret));
+ logError("DBusWrapper::DBusWrapper Wrapper is not the Primary Owner",ret);
exit(1);
}
}
DBusWrapper::~DBusWrapper()
{
//close the connection again
- DLT_LOG(AudioManager, DLT_LOG_INFO, DLT_STRING("DBusWrapper::~DBusWrapper Closing DBus connection"));
+ logInfo("DBusWrapper::~DBusWrapper Closing DBus connection");
dbus_connection_unref(mDbusConnection);
//clean up all timerhandles we created but did not delete before
void DBusWrapper::registerCallback(const DBusObjectPathVTable* vtable, const std::string& path, void* userdata)
{
- DLT_LOG(AudioManager, DLT_LOG_INFO, DLT_STRING("DBusWrapper::~registerCallback register callback:"), DLT_STRING(path.c_str()));
+ logInfo("DBusWrapper::~registerCallback register callback:",path);
std::string completePath = std::string(DBUS_SERVICE_OBJECT_PATH) + "/" + path;
dbus_error_init(&mDBusError);
dbus_connection_register_object_path(mDbusConnection, completePath.c_str(), vtable, userdata);
if (dbus_error_is_set(&mDBusError))
{
- DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DBusWrapper::registerCallack error: "), DLT_STRING(mDBusError.message));
+ logError("DBusWrapper::registerCallack error: ",mDBusError.message);
dbus_error_free(&mDBusError);
}
mNodesList.push_back(path);
DBusHandlerResult DBusWrapper::cbRootIntrospection(DBusConnection *conn, DBusMessage *msg, void *reference)
{
- DLT_LOG(AudioManager, DLT_LOG_INFO, DLT_STRING("DBusWrapper::~cbRootIntrospection called:"));
+ logInfo("DBusWrapper::~cbRootIntrospection called:");
mReference = (DBusWrapper*) reference;
std::list<std::string> nodesList = mReference->mNodesList;
dbus_message_iter_init_append(reply, &args);
if (!dbus_message_iter_append_basic(&args, DBUS_TYPE_STRING, &string))
{
- DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DBusWrapper::~cbRootIntrospection DBUS Out Of Memory!"));
+ logError("DBusWrapper::~cbRootIntrospection DBUS Out Of Memory!");
}
// send the reply && flush the connection
if (!dbus_connection_send(conn, reply, &serial))
{
- DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DBusWrapper::~cbRootIntrospection DBUS Out Of Memory!"));
+ logError("DBusWrapper::~cbRootIntrospection DBUS Out Of Memory!");
}
dbus_connection_flush(conn);
// free the reply
void DBusWrapper::dbusMainLoop()
{
- DLT_LOG(AudioManager, DLT_LOG_INFO, DLT_STRING("DBusWrapper::dbusMainLoop Entering MainLoop"));
+ logInfo("DBusWrapper::dbusMainLoop Entering MainLoop");
while (dbus_connection_read_write_dispatch(mDbusConnection, -1))
{
dbus_bool_t DBusWrapper::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;
+ if (flags & DBUS_WATCH_READABLE)
+ event |= POLLIN;
+ if (flags & DBUS_WATCH_WRITABLE)
+ event |= POLLOUT;
}
- DLT_LOG(AudioManager, DLT_LOG_INFO, DLT_STRING("DBusWrapper::addWatchDelegate entered new watch, fd="), DLT_INT(dbus_watch_get_unix_fd(watch)), DLT_STRING("event flag="), DLT_INT(event));
+ logInfo("DBusWrapper::addWatchDelegate entered new watch, fd=",dbus_watch_get_unix_fd(watch),"event flag=",event);
am_Error_e error = mSocketHandler->addFDPoll(dbus_watch_get_unix_fd(watch), event, NULL, &pDbusFireCallback, &pDbusCheckCallback, &pDbusDispatchCallback, watch, handle);
//if everything is alright, add the watch and the handle to our map so we know this relationship
{
mMapHandleWatch.insert(std::make_pair(watch, handle));
return true;
- }DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DBusWrapper::addWatchDelegate entering watch failed"));
+ }
+ logError("DBusWrapper::addWatchDelegate entering watch failed");
+ return (true);
}
void DBusWrapper::removeWatch(DBusWatch *watch, void *userData)
void DBusWrapper::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()) mSocketHandler->removeFDPoll(iterator->second);
- DLT_LOG(AudioManager, DLT_LOG_INFO, DLT_STRING("DBusWrapper::removeWatch removed watch with handle"), DLT_INT(iterator->second));
+ if (iterator != mMapHandleWatch.end())
+ mSocketHandler->removeFDPoll(iterator->second);
+ logInfo("DBusWrapper::removeWatch removed watch with handle",iterator->second);
mMapHandleWatch.erase(iterator);
}
void DBusWrapper::toogleWatchDelegate(DBusWatch *watch, void *userData)
{
+ (void) userData;
int16_t event = 0;
- int watchFD = dbus_watch_get_unix_fd(watch);
+ 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;
+ 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()) mSocketHandler->updateEventFlags(iterator->second, event);
- DLT_LOG(AudioManager, DLT_LOG_INFO, DLT_STRING("DBusWrapper::toogleWatchDelegate watch was toggeled"));
+ if (iterator != mMapHandleWatch.end())
+ mSocketHandler->updateEventFlags(iterator->second, event);
+ logInfo("DBusWrapper::toogleWatchDelegate watch was toggeled");
}
dbus_bool_t DBusWrapper::addTimeout(DBusTimeout *timeout, void* userData)
dbus_bool_t DBusWrapper::addTimeoutDelegate(DBusTimeout *timeout, void* userData)
{
- if (!dbus_timeout_get_enabled(timeout)) return false;
+ if (!dbus_timeout_get_enabled(timeout))
+ return false;
//calculate the timeout in timeval
timespec pollTimeout;
//save timeout in Socket context
userData = timeout;
- DLT_LOG(AudioManager, DLT_LOG_INFO, DLT_STRING("DBusWrapper::addTimeoutDelegate a timeout was added"));
+ logInfo("DBusWrapper::addTimeoutDelegate a timeout was added");
return true;
}
void DBusWrapper::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);
mSocketHandler->removeTimer(*handle);
}
}
delete handle;
- DLT_LOG(AudioManager, DLT_LOG_INFO, DLT_STRING("DBusWrapper::removeTimeoutDelegate a timeout was removed"));
+ logInfo("DBusWrapper::removeTimeoutDelegate a timeout was removed");
}
void DBusWrapper::toggleTimeout(DBusTimeout *timeout, void* userData)
bool am::DBusWrapper::dbusDispatchCallback(const sh_pollHandle_t handle, void *userData)
{
+ (void) handle;
+ (void) userData;
bool returnVal = true;
dbus_connection_ref(mDbusConnection);
- if (dbus_connection_dispatch(mDbusConnection) == DBUS_DISPATCH_COMPLETE) returnVal = false;
+ if (dbus_connection_dispatch(mDbusConnection) == DBUS_DISPATCH_COMPLETE)
+ returnVal = false;
dbus_connection_unref(mDbusConnection);
- DLT_LOG(AudioManager, DLT_LOG_INFO, DLT_STRING("DBusWrapper::dbusDispatchCallback was called"));
+// logInfo("DBusWrapper::dbusDispatchCallback was called");
return returnVal;
}
bool am::DBusWrapper::dbusCheckCallback(const sh_pollHandle_t handle, void *userData)
{
+ (void) handle;
+ (void) userData;
bool returnVal = false;
dbus_connection_ref(mDbusConnection);
- if (dbus_connection_get_dispatch_status(mDbusConnection) == DBUS_DISPATCH_DATA_REMAINS) returnVal = true;
+ if (dbus_connection_get_dispatch_status(mDbusConnection) == DBUS_DISPATCH_DATA_REMAINS)
+ returnVal = true;
dbus_connection_unref(mDbusConnection);
- DLT_LOG(AudioManager, DLT_LOG_INFO, DLT_STRING("DBusWrapper::dbusCheckCallback was called"));
+// logInfo("DBusWrapper::dbusCheckCallback was called");
return returnVal;
}
void am::DBusWrapper::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;
+ 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(mDbusConnection);
- bool ok = dbus_watch_handle(watch, flags);
+ dbus_watch_handle(watch, flags);
dbus_connection_unref(mDbusConnection);
- DLT_LOG(AudioManager, DLT_LOG_INFO, DLT_STRING("DBusWrapper::dbusFireCallback was called"));
+// logInfo("DBusWrapper::dbusFireCallback was called");
}
void DBusWrapper::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);
else
{
mSocketHandler->stopTimer(*handle);
- }DLT_LOG(AudioManager, DLT_LOG_INFO, DLT_STRING("DBusWrapper::toggleTimeoutDelegate was called"));
+ }logInfo("DBusWrapper::toggleTimeoutDelegate was called");
}
void DBusWrapper::dbusTimerCallback(sh_timerHandle_t handle, void *userData)
mSocketHandler->restartTimer(handle, ts);
}
dbus_timeout_handle((DBusTimeout*) userData);
- DLT_LOG(AudioManager, DLT_LOG_INFO, DLT_STRING("DBusWrapper::dbusTimerCallback was called"));
+ logInfo("DBusWrapper::dbusTimerCallback was called");
}