am_Error_e getDomainOfSource(const am_sourceID_t sourceID, am_domainID_t& domainID) const;
am_Error_e getDomainOfSink(const am_sinkID_t sinkID, am_domainID_t& domainID) const;
am_Error_e getSoureState(const am_sourceID_t sourceID, am_SourceState_e& sourceState) const;
- am_Error_e getDomainState(const am_domainID_t domainID, am_DomainState_e state) const;
+ am_Error_e getDomainState(const am_domainID_t domainID, am_DomainState_e& state) const;
am_Error_e getRoutingTree(bool onlyfree, CAmRoutingTree& tree, std::vector<CAmRoutingTreeItem*>& flatTree);
am_Error_e peekDomain(const std::string& name, am_domainID_t& domainID);
am_Error_e peekSink(const std::string& name, am_sinkID_t& sinkID);
CAmSocketHandler *mpSocketHandler; //!< pointer to sockethandler
CAmDbusWrapper *mpDBusWrapper; //!< pointer to dbuswrapper
- uint16_t handleCount; //!< counts all handles
std::vector<uint16_t> mListStartupHandles; //!< list of handles that wait for a confirm
std::vector<uint16_t> mListRundownHandles; //!< list of handles that wait for a confirm
+ uint16_t handleCount; //!< counts all handles
bool mWaitStartup; //!< if true confirmation will be sent if list of handles = 0
bool mWaitRundown; //!< if true confirmation will be sent if list of handles = 0
CAmCommandReceiver::CAmCommandReceiver(CAmDatabaseHandler *iDatabaseHandler, CAmControlSender *iControlSender, CAmSocketHandler *iSocketHandler) :
mDatabaseHandler(iDatabaseHandler), //
mControlSender(iControlSender), //
+ mDBusWrapper(NULL), //
mSocketHandler(iSocketHandler), //
+ handleCount(0),//
mListStartupHandles(), //
mListRundownHandles(), //
mWaitStartup(false), //
mControlSender(iControlSender), //
mDBusWrapper(iDBusWrapper), //
mSocketHandler(iSocketHandler), //
+ handleCount(0),//
mListStartupHandles(), //
mListRundownHandles(), //
mWaitStartup(false), //
dbusConnectionWrapper = mDBusWrapper;
return (E_OK);
#else
+ dbusConnectionWrapper = NULL;
return (E_UNKNOWN);
#endif /*WITH_DBUS_WRAPPER*/
}
if (!commander)
{
logInfo("CommandPlugin initialization failed. Entry Function not callable");
+ dlclose(tempLibHandle);
continue;
}
if (majorVersion < REQUIRED_INTERFACE_VERSION_MAJOR || ((majorVersion == REQUIRED_INTERFACE_VERSION_MAJOR) && (minorVersion > REQUIRED_INTERFACE_VERSION_MINOR)))
{
logInfo("CommandInterface initialization failed. Version of Interface to old");
+ dlclose(tempLibHandle);
continue;
}
tempConnection.sourceID = sourceID;
tempConnection.connectionFormat = format;
tempConnection.connectionID = 0;
+ tempConnection.delay=-1;
//todo: enter function to find out what happends if the same connection is in the course of being build up.
if (mDatabaseHandler->existConnection(tempConnection))
#include "CAmDatabaseHandler.h"
#include <cassert>
+#include <stdexcept>
#include <vector>
#include <fstream>
#include <sstream>
return (E_OK);
}
-am_Error_e CAmDatabaseHandler::getDomainState(const am_domainID_t domainID, am_DomainState_e state) const
+am_Error_e CAmDatabaseHandler::getDomainState(const am_domainID_t domainID, am_DomainState_e& state) const
{
assert(domainID!=0);
sqlite3_stmt* query = NULL;
CAmDatabaseObserver::CAmDatabaseObserver(CAmCommandSender *iCommandSender, CAmRoutingSender *iRoutingSender, CAmSocketHandler *iSocketHandler) :
mCommandSender(iCommandSender), //
mRoutingSender(iRoutingSender), //
+ mTelnetServer(NULL), //
mSerializer(iSocketHandler) //
{
assert(mCommandSender!=0);
#include <string>
#include <cassert>
#include <cstdlib>
+#include <stdexcept>
#include "shared/CAmDltWrapper.h"
#include "shared/CAmSocketHandler.h"
}
if (DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER != ret)
{
- logError("DBusWrapper::DBusWrapper Wrapper is not the Primary Owner ! Another instance already running?", ret);
- exit(1);
+ 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?");
}
}
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);
+ 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)
dbus_bool_t CAmDbusWrapper::addTimeoutDelegate(DBusTimeout *timeout, void* userData)
{
+ (void)userData;
+
if (!dbus_timeout_get_enabled(timeout))
return (false);
mpSocketHandler(iSocketHandler), //
mListStartupHandles(), //
mListRundownHandles(), //
+ handleCount(0), //
mWaitStartup(false), //
mWaitRundown(false)
{
mpDBusWrapper(iDBusWrapper), //
mListStartupHandles(), //
mListRundownHandles(), //
+ handleCount(0), //
mWaitStartup(false), //
mWaitRundown(false)
{
if (!router)
{
logError("RoutingSender::RoutingSender RoutingPlugin initialization failed. Entry Function not callable");
+ dlclose(tempLibHandle);
continue;
}
if (majorVersion < REQUIRED_INTERFACE_VERSION_MAJOR || ((majorVersion == REQUIRED_INTERFACE_VERSION_MAJOR) && (minorVersion > REQUIRED_INTERFACE_VERSION_MINOR)))
{
logInfo("RoutingPlugin initialization failed. Version of Interface to old");
+ dlclose(tempLibHandle);
continue;
}
//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 (!gDispatchDone) //the mainloop is started
timeoutsCorrected = timespecAdd(timeouts, timespecSub(currentTime, mStartTime));
//setup the port Listener
mConnectFD = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
+ assert (mConnectFD>0);
setsockopt(mConnectFD, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(int));
memset(&servAddr, 0, sizeof(servAddr));
servAddr.sin_family = AF_INET;
connection.handle = 0;
connection.filedescriptor = accept(pfd.fd, (struct sockaddr*) &answer, &len);
+ assert(connection.filedescriptor>0);
+
// Notiy menuhelper
mTelnetMenuHelper.newSocketConnection(connection.filedescriptor);
if (iterator->handle == handle)
break;
}
+ if (iterator==mListConnections.end())
+ {
+ logError("CAmTelnetServer::dispatchData could not find handle !");
+ return (false);
+ }
std::string command;
std::queue<std::string> MsgQueue;
{
sliceCommand(mListMessages.front(), command, MsgQueue);
mListMessages.pop();
+ mTelnetMenuHelper.enterCmdQueue(MsgQueue, iterator->filedescriptor);
+ }
+ else
+ {
+ logError("CAmTelnetServer::dispatchData Message queue was empty!");
}
-
- mTelnetMenuHelper.enterCmdQueue(MsgQueue, iterator->filedescriptor);
// must return false to stop endless polling
return (false);
exit(1);
}
-/**
- * main
- * @param argc
- * @param argv
- * @return
- */
-int main(int argc, char *argv[])
+void mainProgram()
{
- listCommandPluginDirs.push_back(std::string(DEFAULT_PLUGIN_COMMAND_DIR));
- listRoutingPluginDirs.push_back(std::string(DEFAULT_PLUGIN_ROUTING_DIR));
-
- //parse the commandline options
- parseCommandLine(argc, (char**) argv);
-
- CAmDltWrapper::instance(enableNoDLTDebug)->registerApp("AudioManagerDeamon", "AudioManagerDeamon");
- CAmDltWrapper::instance()->registerContext(AudioManager, "Main", "Main Context");
- logInfo("The Audiomanager is started");
- logInfo("The version of the Audiomanager", DAEMONVERSION);
-
- //now the signal handler:
- struct sigaction signalAction;
- memset(&signalAction, '\0', sizeof(signalAction));
- signalAction.sa_sigaction = &signalHandler;
- signalAction.sa_flags = SA_SIGINFO;
- sigaction(SIGINT, &signalAction, NULL);
- sigaction(SIGQUIT, &signalAction, NULL);
- sigaction(SIGTERM, &signalAction, NULL);
- sigaction(SIGHUP, &signalAction, NULL);
- sigaction(SIGQUIT, &signalAction, NULL);
-
- struct sigaction signalChildAction;
- memset(&signalChildAction, '\0', sizeof(signalChildAction));
- signalChildAction.sa_flags = SA_NOCLDWAIT;
- sigaction(SIGCHLD, &signalChildAction, NULL);
-
- //register new out of memory handler
- std::set_new_handler(&OutOfMemoryHandler);
-
//Instantiate all classes. Keep in same order !
CAmSocketHandler iSocketHandler;
//start the mainloop here....
iSocketHandler.start_listenting();
+}
+
+/**
+ * main
+ * @param argc
+ * @param argv
+ * @return
+ */
+int main(int argc, char *argv[])
+{
+ listCommandPluginDirs.push_back(std::string(DEFAULT_PLUGIN_COMMAND_DIR));
+ listRoutingPluginDirs.push_back(std::string(DEFAULT_PLUGIN_ROUTING_DIR));
+
+ //parse the commandline options
+ parseCommandLine(argc, (char**) argv);
+
+ CAmDltWrapper::instance(enableNoDLTDebug)->registerApp("AudioManagerDeamon", "AudioManagerDeamon");
+ CAmDltWrapper::instance()->registerContext(AudioManager, "Main", "Main Context");
+ logInfo("The Audiomanager is started");
+ logInfo("The version of the Audiomanager", DAEMONVERSION);
+
+ //now the signal handler:
+ struct sigaction signalAction;
+ memset(&signalAction, '\0', sizeof(signalAction));
+ signalAction.sa_sigaction = &signalHandler;
+ signalAction.sa_flags = SA_SIGINFO;
+ sigaction(SIGINT, &signalAction, NULL);
+ sigaction(SIGQUIT, &signalAction, NULL);
+ sigaction(SIGTERM, &signalAction, NULL);
+ sigaction(SIGHUP, &signalAction, NULL);
+ sigaction(SIGQUIT, &signalAction, NULL);
+
+ struct sigaction signalChildAction;
+ memset(&signalChildAction, '\0', sizeof(signalChildAction));
+ signalChildAction.sa_flags = SA_NOCLDWAIT;
+ sigaction(SIGCHLD, &signalChildAction, NULL);
+
+ //register new out of memory handler
+ std::set_new_handler(&OutOfMemoryHandler);
+
+ try
+ {
+ //we do this to catch all exceptions and have a graceful ending just in case
+ mainProgram();
+ }
+
+ catch (std::exception& exc)
+ {
+ logError("The AudioManager ended by throwing the exception", exc.what());
+ //todo: ergency exit here... call destructors etc...
+ exit(EXIT_FAILURE);
+ }
+
+
close(fd0);
close(fd1);
close(fd2);
{
equal = equal && pCF.compareSource(listIterator, secondDynamicSource);
}
- pCF.compareSource(listIterator, secondDynamicSource);
}ASSERT_EQ(true, equal);
char CAmDbusMessageHandler::getByte()
{
- char param;
+ char param(0);
if (DBUS_TYPE_BYTE != dbus_message_iter_get_arg_type(&mDBusMessageIter))
{
dbus_uint16_t CAmDbusMessageHandler::getUInt()
{
- dbus_uint16_t param;
+ dbus_uint16_t param(0);
#ifdef GLIB_DBUS_TYPES_TOLERANT
if (DBUS_TYPE_UINT16 != dbus_message_iter_get_arg_type(&mDBusMessageIter) && DBUS_TYPE_UINT32 != dbus_message_iter_get_arg_type(&mDBusMessageIter))
dbus_int16_t CAmDbusMessageHandler::getInt()
{
- dbus_int16_t param;
+ dbus_int16_t param(0);
#ifdef GLIB_DBUS_TYPES_TOLERANT
if (DBUS_TYPE_INT16 != dbus_message_iter_get_arg_type(&mDBusMessageIter) && DBUS_TYPE_INT32 != dbus_message_iter_get_arg_type(&mDBusMessageIter))
double CAmDbusMessageHandler::getDouble()
{
- double param;
+ double param(0);
if (DBUS_TYPE_DOUBLE != dbus_message_iter_get_arg_type(&mDBusMessageIter))
{
log(&commandDbus, DLT_LOG_ERROR, "DBusMessageHandler::getDouble DBUS handler argument is no double!");
using namespace am;
using namespace testing;
-CAmCommandSenderDbusSignalTest::CAmCommandSenderDbusSignalTest()
+CAmCommandSenderDbusSignalTest::CAmCommandSenderDbusSignalTest() :
+ ppCommandSend(NULL) //
{
CAmDltWrapper::instance()->registerApp("dbusTest", "dbusTest");
logInfo("dbusCommandInterfaceSignalTest started");
return (NULL);
}
-CAmCommandSenderDbusTest::CAmCommandSenderDbusTest()
+CAmCommandSenderDbusTest::CAmCommandSenderDbusTest() :
+ ppCommandSend(NULL) //
{
CAmDltWrapper::instance()->registerApp("dbusTest", "dbusTest");
}
char CAmRoutingDbusMessageHandler::getByte(DBusMessageIter& iter, bool next)
{
- char param;
+ char param(0);
if (DBUS_TYPE_BYTE != dbus_message_iter_get_arg_type(&iter))
{
dbus_uint16_t CAmRoutingDbusMessageHandler::getUInt(DBusMessageIter& iter, bool next)
{
- dbus_uint16_t param;
+ dbus_uint16_t param(0);
#ifdef GLIB_DBUS_TYPES_TOLERANT
if (DBUS_TYPE_UINT16 != dbus_message_iter_get_arg_type(&iter) && DBUS_TYPE_UINT32 != dbus_message_iter_get_arg_type(&iter))
#else
dbus_int16_t CAmRoutingDbusMessageHandler::getInt(DBusMessageIter& iter, bool next)
{
- dbus_int16_t param;
+ dbus_int16_t param(0);
#ifdef GLIB_DBUS_TYPES_TOLERANT
if (DBUS_TYPE_INT16 != dbus_message_iter_get_arg_type(&iter) && DBUS_TYPE_INT32 != dbus_message_iter_get_arg_type(&iter))
#else
double CAmRoutingDbusMessageHandler::getDouble(DBusMessageIter& iter, bool next)
{
- double param;
+ double param(0);
if (DBUS_TYPE_DOUBLE != dbus_message_iter_get_arg_type(&iter))
{
log(&routingDbus, DLT_LOG_ERROR, "DBusMessageHandler::getDouble DBUS handler argument is no double!");