diff options
author | Jens Lorenz <jlorenz@de.adit-jv.com> | 2018-07-03 17:42:05 +0200 |
---|---|---|
committer | Jens Lorenz <jlorenz@de.adit-jv.com> | 2018-07-03 17:42:05 +0200 |
commit | 95c696f818b6840bcbefe6d376ff01fa02dfd772 (patch) | |
tree | d0e8c492a9da884aa57f6464dc515605eba705e0 /AudioManagerDaemon | |
parent | 1117d0eb2fa07f039e3b9283e960db855465b12b (diff) | |
download | audiomanager-95c696f818b6840bcbefe6d376ff01fa02dfd772.tar.gz |
FOO: Issue #26 fix white space issues and apply new coding style
Signed-off-by: Jens Lorenz <jlorenz@de.adit-jv.com>
Diffstat (limited to 'AudioManagerDaemon')
-rw-r--r--[-rwxr-xr-x] | AudioManagerDaemon/src/main.cpp | 258 |
1 files changed, 130 insertions, 128 deletions
diff --git a/AudioManagerDaemon/src/main.cpp b/AudioManagerDaemon/src/main.cpp index 171d6ef..1567265 100755..100644 --- a/AudioManagerDaemon/src/main.cpp +++ b/AudioManagerDaemon/src/main.cpp @@ -25,15 +25,15 @@ #include "audiomanagerconfig.h" #ifdef WITH_CAPI_WRAPPER - #include "CAmCommonAPIWrapper.h" +# include "CAmCommonAPIWrapper.h" #endif #ifdef WITH_DBUS_WRAPPER - #include "CAmDbusWrapper.h" +# include "CAmDbusWrapper.h" #endif #ifdef WITH_SYSTEMD_WATCHDOG - #include "CAmWatchdog.h" +# include "CAmWatchdog.h" #endif #include <sys/resource.h> @@ -61,40 +61,39 @@ #include "CAmDatabaseHandlerMap.h" #ifndef AUDIOMANGER_APP_ID - #define AUDIOMANGER_APP_ID "AUDI" +# define AUDIOMANGER_APP_ID "AUDI" #endif #ifndef AUDIOMANGER_APP_DESCRIPTION - #define AUDIOMANGER_APP_DESCRIPTION "AudioManager" +# define AUDIOMANGER_APP_DESCRIPTION "AudioManager" #endif - using namespace am; -//we need these because we parse them beforehand. +// we need these because we parse them beforehand. std::vector<std::string> listCommandPluginDirs; std::vector<std::string> listRoutingPluginDirs; // List of signals to be handled with signalfd -std::vector<uint8_t> listOfSignalsFD = {SIGHUP, SIGTERM, SIGCHLD}; - -//commandline options used by the Audiomanager itself -TCLAP::ValueArg<std::string> controllerPlugin("c","controllerPlugin","use controllerPlugin full path with .so ending",false,CONTROLLER_PLUGIN_DIR,"string"); -TCLAP::ValueArg<std::string> additionalCommandPluginDirs("L","additionalCommandPluginDirs","additional path for looking for command plugins, can be used after -l option",false," ","string"); -TCLAP::ValueArg<std::string> additionalRoutingPluginDirs("R","additionalRoutingPluginDirs","additional path for looking for routing plugins, can be used after -r option ",false," ","string"); -TCLAP::ValueArg<std::string> routingPluginDir("r","RoutingPluginDir","path for looking for routing plugins",false," ","string"); -TCLAP::ValueArg<std::string> commandPluginDir("l","CommandPluginDir","path for looking for command plugins",false," ","string"); -TCLAP::ValueArg<std::string> dltLogFilename("F","dltLogFilename","the name of the logfile, absolute path. Only if logging is et to file",false," ","string"); -TCLAP::ValueArg<unsigned int> dltOutput ("O","dltOutput","defines where logs are written. 0=dlt-daemon(default), 1=command line, 2=file ",false,0,"int"); -TCLAP::SwitchArg dltEnable ("e","dltEnable","Enables or disables dlt logging. Default = enabled",true); -TCLAP::SwitchArg dbusWrapperTypeBool ("T","dbusType","DbusType to be used by CAmDbusWrapper: if option is selected, DBUS_SYSTEM is used otherwise DBUS_SESSION",false); -TCLAP::SwitchArg currentSettings("i","currentSettings","print current settings and exit",false); -TCLAP::SwitchArg daemonizeAM("d","daemonize","daemonize Audiomanager. Better use systemd...",false); +std::vector<uint8_t> listOfSignalsFD = { SIGHUP, SIGTERM, SIGCHLD }; + +// commandline options used by the Audiomanager itself +TCLAP::ValueArg<std::string> controllerPlugin("c", "controllerPlugin", "use controllerPlugin full path with .so ending", false, CONTROLLER_PLUGIN_DIR, "string"); +TCLAP::ValueArg<std::string> additionalCommandPluginDirs("L", "additionalCommandPluginDirs", "additional path for looking for command plugins, can be used after -l option", false, " ", "string"); +TCLAP::ValueArg<std::string> additionalRoutingPluginDirs("R", "additionalRoutingPluginDirs", "additional path for looking for routing plugins, can be used after -r option ", false, " ", "string"); +TCLAP::ValueArg<std::string> routingPluginDir("r", "RoutingPluginDir", "path for looking for routing plugins", false, " ", "string"); +TCLAP::ValueArg<std::string> commandPluginDir("l", "CommandPluginDir", "path for looking for command plugins", false, " ", "string"); +TCLAP::ValueArg<std::string> dltLogFilename("F", "dltLogFilename", "the name of the logfile, absolute path. Only if logging is et to file", false, " ", "string"); +TCLAP::ValueArg<unsigned int> dltOutput("O", "dltOutput", "defines where logs are written. 0=dlt-daemon(default), 1=command line, 2=file ", false, 0, "int"); +TCLAP::SwitchArg dltEnable("e", "dltEnable", "Enables or disables dlt logging. Default = enabled", true); +TCLAP::SwitchArg dbusWrapperTypeBool("T", "dbusType", "DbusType to be used by CAmDbusWrapper: if option is selected, DBUS_SYSTEM is used otherwise DBUS_SESSION", false); +TCLAP::SwitchArg currentSettings("i", "currentSettings", "print current settings and exit", false); +TCLAP::SwitchArg daemonizeAM("d", "daemonize", "daemonize Audiomanager. Better use systemd...", false); int fd0, fd1, fd2; #ifdef WITH_DBUS_WRAPPER - DBusBusType dbusWrapperType=DBUS_BUS_SESSION; +DBusBusType dbusWrapperType = DBUS_BUS_SESSION; #endif /** @@ -157,29 +156,28 @@ void daemonize() } } - - void printCmdInformation() { - printf("\n\n\nCurrent settings:\n\n"); - printf("\tAudioManagerDaemon Version:\t\t%s\n", DAEMONVERSION EXTRAVERSIONINFO); - printf("\tControllerPlugin: \t\t\t%s\n", controllerPlugin.getValue().c_str()); - printf("\tDirectories of CommandPlugins: \t\t\n"); - std::vector<std::string>::const_iterator dirIter = listCommandPluginDirs.begin(); + printf("\n\n\nCurrent settings:\n\n"); + printf("\tAudioManagerDaemon Version:\t\t%s\n", DAEMONVERSION EXTRAVERSIONINFO); + printf("\tControllerPlugin: \t\t\t%s\n", controllerPlugin.getValue().c_str()); + printf("\tDirectories of CommandPlugins: \t\t\n"); + std::vector<std::string>::const_iterator dirIter = listCommandPluginDirs.begin(); std::vector<std::string>::const_iterator dirIterEnd = listCommandPluginDirs.end(); for (; dirIter < dirIterEnd; ++dirIter) { - printf("\t \t\t%s\n", dirIter->c_str()); + printf("\t \t\t%s\n", dirIter->c_str()); } - printf("\tDirectories of RoutingPlugins: \t\t\n"); - dirIter = listRoutingPluginDirs.begin(); + printf("\tDirectories of RoutingPlugins: \t\t\n"); + dirIter = listRoutingPluginDirs.begin(); dirIterEnd = listRoutingPluginDirs.end(); for (; dirIter < dirIterEnd; ++dirIter) { - printf("\t \t\t%s\n", dirIter->c_str()); + printf("\t \t\t%s\n", dirIter->c_str()); } - exit(0); + + exit(0); } /** @@ -190,36 +188,35 @@ void printCmdInformation() */ static void signalHandler(int sig, siginfo_t *siginfo, void *context) { - (void) sig; - (void) siginfo; - (void) context; - logInfo("signal handler was called, signal",sig); + (void)sig; + (void)siginfo; + (void)context; + logInfo("signal handler was called, signal", sig); switch (sig) { - /*ctl +c lets call direct controllerRundown, because we might be blocked at the moment. - But there is the risk of interrupting something important */ - case SIGINT: - CAmControlSender::CallsetControllerRundown(sig); - break; - - /* huch- we are getting killed. Better take the fast but risky way: */ - case SIGQUIT: - CAmControlSender::CallsetControllerRundown(sig); - break; - default: - break; + /*ctl +c lets call direct controllerRundown, because we might be blocked at the moment. + * But there is the risk of interrupting something important */ + case SIGINT: + CAmControlSender::CallsetControllerRundown(sig); + break; + + /* huch- we are getting killed. Better take the fast but risky way: */ + case SIGQUIT: + CAmControlSender::CallsetControllerRundown(sig); + break; + default: + break; } } - void mainProgram(int argc, char *argv[]) { - //initialize the commandline parser, and add all neccessary commands + // initialize the commandline parser, and add all neccessary commands try { - TCLAP::CmdLine* cmd(CAmCommandLineSingleton::instanciateOnce("The team of the AudioManager wishes you a nice day!",' ', DAEMONVERSION EXTRAVERSIONINFO,true)); + TCLAP::CmdLine *cmd(CAmCommandLineSingleton::instanciateOnce("The team of the AudioManager wishes you a nice day!", ' ', DAEMONVERSION EXTRAVERSIONINFO, true)); cmd->add(controllerPlugin); cmd->add(additionalCommandPluginDirs); cmd->add(commandPluginDir); @@ -235,40 +232,43 @@ void mainProgram(int argc, char *argv[]) #endif } catch (TCLAP::ArgException &e) // catch any exceptions - { std::cerr << "error: " << e.error() << " for arg " << e.argId() << std::endl; } + { + std::cerr << "error: " << e.error() << " for arg " << e.argId() << std::endl; + } - //hen and egg. We need to parse a part of the commandline options to get the paths of the controller and the plugins. - //So we do some little parsing first and the real parsing later so that the plugins can profit from that. - CAmCommandLineSingleton::instance()->preparse(argc,argv); - if (daemonizeAM.getValue()) - { - daemonize(); - } + // hen and egg. We need to parse a part of the commandline options to get the paths of the controller and the plugins. + // So we do some little parsing first and the real parsing later so that the plugins can profit from that. + CAmCommandLineSingleton::instance()->preparse(argc, argv); + if (daemonizeAM.getValue()) + { + daemonize(); + } - CAmDltWrapper::instanctiateOnce(AUDIOMANGER_APP_ID, AUDIOMANGER_APP_DESCRIPTION ,dltEnable.getValue(),static_cast<am::CAmDltWrapper::logDestination>(dltOutput.getValue()),dltLogFilename.getValue()); + CAmDltWrapper::instanctiateOnce(AUDIOMANGER_APP_ID, AUDIOMANGER_APP_DESCRIPTION, dltEnable.getValue(), static_cast<am::CAmDltWrapper::logDestination>(dltOutput.getValue()), dltLogFilename.getValue()); - //Instantiate all classes. Keep in same order ! + // Instantiate all classes. Keep in same order ! CAmSocketHandler iSocketHandler; - if(iSocketHandler.fatalErrorOccurred()) + if (iSocketHandler.fatalErrorOccurred()) { throw std::runtime_error(std::string("CAmSocketHandler: Could not create pipe or file descriptor is invalid.")); } - if(E_OK != iSocketHandler.listenToSignals(listOfSignalsFD)) + if (E_OK != iSocketHandler.listenToSignals(listOfSignalsFD)) { - logWarning("CAmSocketHandler failed to register itself as signal handler."); + logWarning("CAmSocketHandler failed to register itself as signal handler."); } - //Register signal handler + + // Register signal handler sh_pollHandle_t signalHandler; - iSocketHandler.addSignalHandler([&](const sh_pollHandle_t handle, const signalfd_siginfo & info, void* userData){ + iSocketHandler.addSignalHandler([&](const sh_pollHandle_t handle, const signalfd_siginfo &info, void *userData){ - unsigned sig = info.ssi_signo; - unsigned user = info.ssi_uid; + unsigned sig = info.ssi_signo; + unsigned user = info.ssi_uid; - logInfo("signal handler was called from user", user, "with signal ",sig); + logInfo("signal handler was called from user", user, "with signal ", sig); - switch (sig) - { + switch (sig) + { /* more friendly here assuming systemd wants to stop us, so we can use the mainloop */ case SIGTERM: CAmControlSender::CallsetControllerRundownSafe(sig); @@ -280,102 +280,106 @@ void mainProgram(int argc, char *argv[]) break; default: break; - } - },signalHandler,NULL); + } + }, signalHandler, NULL); - if(commandPluginDir.isSet()) + if (commandPluginDir.isSet()) { - listCommandPluginDirs.clear(); - listCommandPluginDirs.push_back(commandPluginDir.getValue()); + listCommandPluginDirs.clear(); + listCommandPluginDirs.push_back(commandPluginDir.getValue()); } if (additionalCommandPluginDirs.isSet()) { - listCommandPluginDirs.push_back(additionalCommandPluginDirs.getValue()); + listCommandPluginDirs.push_back(additionalCommandPluginDirs.getValue()); } - if(routingPluginDir.isSet()) + if (routingPluginDir.isSet()) { - listRoutingPluginDirs.clear(); - listRoutingPluginDirs.push_back(routingPluginDir.getValue()); + listRoutingPluginDirs.clear(); + listRoutingPluginDirs.push_back(routingPluginDir.getValue()); } if (additionalRoutingPluginDirs.isSet()) { - listRoutingPluginDirs.push_back(additionalRoutingPluginDirs.getValue()); + listRoutingPluginDirs.push_back(additionalRoutingPluginDirs.getValue()); } - //in this place, the plugins can get the gloval commandlineparser via CAmCommandLineSingleton::instance() and add their options to the commandline - //this must be done in the constructor. - //later when the plugins are started, the commandline is already parsed and the objects defined before can be used to get the neccesary information - + // in this place, the plugins can get the gloval commandlineparser via CAmCommandLineSingleton::instance() and add their options to the commandline + // this must be done in the constructor. + // later when the plugins are started, the commandline is already parsed and the objects defined before can be used to get the neccesary information + CAmDatabaseHandlerMap iDatabaseHandler; - IAmDatabaseHandler *pDatabaseHandler = dynamic_cast<IAmDatabaseHandler*>( &iDatabaseHandler ); + IAmDatabaseHandler *pDatabaseHandler = dynamic_cast<IAmDatabaseHandler *>(&iDatabaseHandler); - CAmRoutingSender iRoutingSender(listRoutingPluginDirs,pDatabaseHandler); + CAmRoutingSender iRoutingSender(listRoutingPluginDirs, pDatabaseHandler); CAmCommandSender iCommandSender(listCommandPluginDirs, &iSocketHandler); - CAmControlSender iControlSender(controllerPlugin.getValue(),&iSocketHandler); + CAmControlSender iControlSender(controllerPlugin.getValue(), &iSocketHandler); try { - //parse the commandline options - CAmCommandLineSingleton::instance()->reset(); - CAmCommandLineSingleton::instance()->parse(argc,argv); - if (currentSettings.getValue()) - { - printCmdInformation(); - } + // parse the commandline options + CAmCommandLineSingleton::instance()->reset(); + CAmCommandLineSingleton::instance()->parse(argc, argv); + if (currentSettings.getValue()) + { + printCmdInformation(); + } } catch (TCLAP::ArgException &e) // catch any exceptions - { std::cerr << "error: " << e.error() << " for arg " << e.argId() << std::endl; } + { + std::cerr << "error: " << e.error() << " for arg " << e.argId() << std::endl; + } logInfo("The Audiomanager is started"); logInfo("The version of the Audiomanager", DAEMONVERSION EXTRAVERSIONINFO); #ifdef WITH_CAPI_WRAPPER - //We instantiate a singleton with the current socket handler, which loads the common-api runtime. + // We instantiate a singleton with the current socket handler, which loads the common-api runtime. CAmCommonAPIWrapper *pCAPIWrapper = CAmCommonAPIWrapper::instantiateOnce(&iSocketHandler, "AudioManager"); #endif /*WITH_CAPI_WRAPPER */ #ifdef WITH_DBUS_WRAPPER if (dbusWrapperTypeBool.getValue()) - dbusWrapperType=DBUS_BUS_SYSTEM; - CAmDbusWrapper iDBusWrapper(&iSocketHandler,dbusWrapperType); + { + dbusWrapperType = DBUS_BUS_SYSTEM; + } + CAmDbusWrapper iDBusWrapper(&iSocketHandler, dbusWrapperType); #endif /*WITH_DBUS_WRAPPER */ #ifdef WITH_SYSTEMD_WATCHDOG CAmWatchdog iWatchdog(&iSocketHandler); #endif /*WITH_SYSTEMD_WATCHDOG*/ -CAmRouter iRouter(pDatabaseHandler, &iControlSender); + CAmRouter iRouter(pDatabaseHandler, &iControlSender); #ifdef WITH_DBUS_WRAPPER CAmCommandReceiver iCommandReceiver(pDatabaseHandler, &iControlSender, &iSocketHandler, &iDBusWrapper); CAmRoutingReceiver iRoutingReceiver(pDatabaseHandler, &iRoutingSender, &iControlSender, &iSocketHandler, &iDBusWrapper); #else /*WITH_DBUS_WRAPPER*/ - CAmCommandReceiver iCommandReceiver(pDatabaseHandler,&iControlSender,&iSocketHandler); - CAmRoutingReceiver iRoutingReceiver(pDatabaseHandler,&iRoutingSender,&iControlSender,&iSocketHandler); + CAmCommandReceiver iCommandReceiver(pDatabaseHandler, &iControlSender, &iSocketHandler); + CAmRoutingReceiver iRoutingReceiver(pDatabaseHandler, &iRoutingSender, &iControlSender, &iSocketHandler); #endif /*WITH_DBUS_WRAPPER*/ -CAmControlReceiver iControlReceiver(pDatabaseHandler,&iRoutingSender,&iCommandSender,&iSocketHandler, &iRouter); + CAmControlReceiver iControlReceiver(pDatabaseHandler, &iRoutingSender, &iCommandSender, &iSocketHandler, &iRouter); -iDatabaseHandler.registerObserver(&iRoutingSender); -iDatabaseHandler.registerObserver(&iCommandSender); -iDatabaseHandler.registerObserver(&iRouter); -//startup all the Plugins and Interfaces -//at this point, commandline arguments can be parsed -iControlSender.startupController(&iControlReceiver); -iCommandSender.startupInterfaces(&iCommandReceiver); -iRoutingSender.startupInterfaces(&iRoutingReceiver); + iDatabaseHandler.registerObserver(&iRoutingSender); + iDatabaseHandler.registerObserver(&iCommandSender); + iDatabaseHandler.registerObserver(&iRouter); +// startup all the Plugins and Interfaces +// at this point, commandline arguments can be parsed + iControlSender.startupController(&iControlReceiver); + iCommandSender.startupInterfaces(&iCommandReceiver); + iRoutingSender.startupInterfaces(&iRoutingReceiver); -//when the routingInterface is done, all plugins are loaded: -iControlSender.setControllerReady(); +// when the routingInterface is done, all plugins are loaded: + iControlSender.setControllerReady(); #ifdef WITH_SYSTEMD_WATCHDOG iWatchdog.startWatchdog(); #endif /*WITH_SYSTEMD_WATCHDOG*/ - //start the mainloop here.... + // start the mainloop here.... iSocketHandler.start_listenting(); } @@ -385,21 +389,21 @@ iControlSender.setControllerReady(); * @param argv * @return */ -int main(int argc, char *argv[], char** envp) +int main(int argc, char *argv[], char * *envp) { - (void) envp; + (void)envp; listCommandPluginDirs.push_back(std::string(DEFAULT_PLUGIN_COMMAND_DIR)); listRoutingPluginDirs.push_back(std::string(DEFAULT_PLUGIN_ROUTING_DIR)); - //critical signals are registered here: + // critical signals are registered here: struct sigaction signalAction; memset(&signalAction, '\0', sizeof(signalAction)); signalAction.sa_sigaction = &signalHandler; - signalAction.sa_flags = SA_SIGINFO; + signalAction.sa_flags = SA_SIGINFO; sigaction(SIGINT, &signalAction, NULL); sigaction(SIGQUIT, &signalAction, NULL); - - //register new out of memory handler + + // register new out of memory handler std::set_new_handler(&OutOfMemoryHandler); sigset_t signal_mask; @@ -416,14 +420,13 @@ int main(int argc, char *argv[], char** envp) throw std::runtime_error(std::string("Couldn't set mask for potential future threads")); } - //we do this to catch all exceptions and have a graceful ending just in case - mainProgram(argc,argv); + // we do this to catch all exceptions and have a graceful ending just in case + mainProgram(argc, argv); } - - catch (std::exception& exc) + catch (std::exception &exc) { logError("The AudioManager ended by throwing the exception", exc.what()); - std::cerr<<"The AudioManager ended by throwing an exception "<<exc.what()<<std::endl; + std::cerr << "The AudioManager ended by throwing an exception " << exc.what() << std::endl; exit(EXIT_FAILURE); } @@ -433,4 +436,3 @@ int main(int argc, char *argv[], char** envp) exit(0); } - |