25 #include "audiomanagerconfig.h"
31 #ifdef WITH_CAPI_WRAPPER
35 #ifdef WITH_DBUS_WRAPPER
40 #ifdef WITH_DATABASE_STORAGE
41 #include "CAmDatabaseHandlerSQLite.h"
46 #ifdef WITH_SYSTEMD_WATCHDOG
50 #include <sys/resource.h>
82 TCLAP::ValueArg<std::string>
controllerPlugin(
"c",
"controllerPlugin",
"use controllerPlugin full path with .so ending",
false,CONTROLLER_PLUGIN_DIR,
"string");
83 TCLAP::ValueArg<std::string>
additionalCommandPluginDirs(
"L",
"additionalCommandPluginDirs",
"additional path for looking for command plugins, can be used after -l option",
false,
" ",
"string");
84 TCLAP::ValueArg<std::string>
additionalRoutingPluginDirs(
"R",
"additionalRoutingPluginDirs",
"additional path for looking for routing plugins, can be used after -r option ",
false,
" ",
"string");
85 TCLAP::ValueArg<std::string>
routingPluginDir(
"r",
"RoutingPluginDir",
"path for looking for routing plugins",
false,
" ",
"string");
86 TCLAP::ValueArg<std::string>
commandPluginDir(
"l",
"CommandPluginDir",
"path for looking for command plugins",
false,
" ",
"string");
87 TCLAP::ValueArg<std::string>
dltLogFilename(
"F",
"dltLogFilename",
"the name of the logfile, absolute path. Only if logging is et to file",
false,
" ",
"string");
88 TCLAP::ValueArg<unsigned int>
dltOutput (
"O",
"dltOutput",
"defines where logs are written. 0=dlt-daemon(default), 1=command line, 2=file ",
false,0,
"int");
89 TCLAP::ValueArg<unsigned int>
telnetPort (
"t",
"telnetport",
"The port that is used for telnet",
false,DEFAULT_TELNETPORT,
"int");
90 TCLAP::ValueArg<unsigned int>
maxConnections (
"m",
"maxConnections",
"Maximal number of connections for telnet",
false,MAX_TELNETCONNECTIONS,
"int");
91 TCLAP::SwitchArg
dltEnable (
"e",
"dltEnable",
"Enables or disables dlt logging. Default = enabled",
true);
92 TCLAP::SwitchArg
dbusWrapperTypeBool (
"T",
"dbusType",
"DbusType to be used by CAmDbusWrapper: if option is selected, DBUS_SYSTEM is used otherwise DBUS_SESSION",
false);
93 TCLAP::SwitchArg
currentSettings(
"i",
"currentSettings",
"print current settings and exit",
false);
94 TCLAP::SwitchArg
daemonizeAM(
"d",
"daemonize",
"daemonize Audiomanager. Better use systemd...",
false);
98 #ifdef WITH_DBUS_WRAPPER
99 DBusBusType dbusWrapperType=DBUS_BUS_SESSION;
108 throw std::runtime_error(std::string(
"SocketHandler::start_listenting ppoll returned with error."));
117 std::string dir =
"/";
120 if (getrlimit(RLIMIT_NOFILE, &rl) < 0)
126 if ((pid = fork()) < 0)
137 if (!dir.empty() && chdir(dir.c_str()) < 0)
139 logError(
"couldn't chdir to the new directory");
142 if (rl.rlim_max == RLIM_INFINITY)
147 for (
unsigned int i = 0; i < rl.rlim_max; i++)
152 fd0 = open(
"/dev/null", O_RDONLY);
153 fd1 = open(
"/dev/null", O_WRONLY | O_CREAT | O_APPEND, S_IRUSR | S_IWUSR);
154 fd2 = open(
"/dev/null", O_WRONLY | O_CREAT | O_APPEND, S_IRUSR | S_IWUSR);
156 if (
fd0 != STDIN_FILENO ||
fd1 != STDOUT_FILENO ||
fd2 != STDERR_FILENO)
158 logError(
"new standard file descriptors were not opened");
166 printf(
"\n\n\nCurrent settings:\n\n");
167 printf(
"\tAudioManagerDaemon Version:\t\t%s\n", DAEMONVERSION);
169 printf(
"\tTelnet portNumber:\t\t\t%i\n",
telnetPort.getValue());
170 printf(
"\tTelnet maxConnections:\t\t\t%i\n",
maxConnections.getValue());
172 printf(
"\tControllerPlugin: \t\t\t%s\n",
controllerPlugin.getValue().c_str());
173 printf(
"\tDirectories of CommandPlugins: \t\t\n");
176 for (; dirIter < dirIterEnd; ++dirIter)
178 printf(
"\t \t\t%s\n", dirIter->c_str());
181 printf(
"\tDirectories of RoutingPlugins: \t\t\n");
184 for (; dirIter < dirIterEnd; ++dirIter)
186 printf(
"\t \t\t%s\n", dirIter->c_str());
197 static void signalHandler(
int sig, siginfo_t *siginfo,
void *context)
202 logInfo(
"signal handler was called, signal",sig);
248 #ifdef WITH_DBUS_WRAPPER
255 #ifdef WITH_DATABASE_STORAGE
256 cmd->add(databasePath);
259 catch (TCLAP::ArgException &e)
260 { std::cerr <<
"error: " << e.error() <<
" for arg " << e.argId() << std::endl; }
318 catch (TCLAP::ArgException &e)
319 { std::cerr <<
"error: " << e.error() <<
" for arg " << e.argId() << std::endl; }
321 logInfo(
"The Audiomanager is started");
322 logInfo(
"The version of the Audiomanager", DAEMONVERSION);
324 #ifdef WITH_CAPI_WRAPPER
329 #ifdef WITH_DBUS_WRAPPER
331 dbusWrapperType=DBUS_BUS_SYSTEM;
335 #ifdef WITH_SYSTEMD_WATCHDOG
339 CAmRouter iRouter(pDatabaseHandler, &iControlSender);
341 #ifdef WITH_DBUS_WRAPPER
342 CAmCommandReceiver iCommandReceiver(pDatabaseHandler, &iControlSender, &iSocketHandler, &iDBusWrapper);
343 CAmRoutingReceiver iRoutingReceiver(pDatabaseHandler, &iRoutingSender, &iControlSender, &iSocketHandler, &iDBusWrapper);
345 CAmCommandReceiver iCommandReceiver(pDatabaseHandler,&iControlSender,&iSocketHandler);
346 CAmRoutingReceiver iRoutingReceiver(pDatabaseHandler,&iRoutingSender,&iControlSender,&iSocketHandler);
349 CAmControlReceiver iControlReceiver(pDatabaseHandler,&iRoutingSender,&iCommandSender,&iSocketHandler, &iRouter);
352 CAmTelnetServer iTelnetServer(&iSocketHandler, &iCommandSender, &iCommandReceiver, &iRoutingSender, &iRoutingReceiver, &iControlSender, &iControlReceiver, pDatabaseHandler, &iRouter,
telnetPort.getValue(),
maxConnections.getValue());
353 CAmDatabaseObserver iObserver(&iCommandSender, &iRoutingSender, &iSocketHandler, &iTelnetServer);
362 iControlSender.startupController(&iControlReceiver);
367 iControlSender.setControllerReady();
369 #ifdef WITH_SYSTEMD_WATCHDOG
374 iSocketHandler.start_listenting();
383 int main(
int argc,
char *argv[],
char** envp)
390 struct sigaction signalAction;
391 memset(&signalAction,
'\0',
sizeof(signalAction));
392 signalAction.sa_sigaction = &signalHandler;
393 signalAction.sa_flags = SA_SIGINFO;
394 sigaction(SIGINT, &signalAction, NULL);
395 sigaction(SIGQUIT, &signalAction, NULL);
396 sigaction(SIGTERM, &signalAction, NULL);
397 sigaction(SIGHUP, &signalAction, NULL);
399 struct sigaction signalChildAction;
400 memset(&signalChildAction,
'\0',
sizeof(signalChildAction));
401 signalChildAction.sa_flags = SA_NOCLDWAIT;
402 sigaction(SIGCHLD, &signalChildAction, NULL);
413 catch (std::exception& exc)
415 logError(
"The AudioManager ended by throwing the exception", exc.what());
416 std::cerr<<
"The AudioManager ended by throwing an exception "<<exc.what()<<std::endl;
Implements the RoutingSendInterface.
This class realizes the command Interface.
SPDX license identifier: MPL-2.0.
TCLAP::ValueArg< std::string > commandPluginDir("l","CommandPluginDir","path for looking for command plugins", false," ","string")
am_Error_e startupInterfaces(CAmCommandReceiver *iCommandReceiver)
int main(int argc, char *argv[], char **envp)
main
void daemonize()
daemonizes the AudioManager
void logInfo(T value, TArgs...args)
logs given values with infolevel with the default context
Implements an autorouting algorithm for connecting sinks and sources via different audio domains...
TCLAP::ValueArg< std::string > additionalCommandPluginDirs("L","additionalCommandPluginDirs","additional path for looking for command plugins, can be used after -l option", false," ","string")
This class is used to receive all commands from the control interface.
static CAmCommonAPIWrapper * instantiateOnce(CAmSocketHandler *socketHandler, const std::string &applicationName="")
Creates a singleton instance attached to the provided socket handler object.
The am::CAmSocketHandler implements a mainloop for the AudioManager.
static CAmDltWrapper * instanctiateOnce(const char *appid, const char *description, const bool debugEnabled=true, const logDestination logDest=logDestination::DAEMON, const std::string Filename="", bool onlyError=false)
Instanciate the Dlt Wrapper.
SPDX license identifier: MPL-2.0.
static TCLAP::CmdLine * instance()
Implements the watchdog of the AudioManager with the help of systemd.
void printCmdInformation()
void registerObserver(CAmDatabaseObserver *iObserver)
registers the Observer at the Database
SPDX license identifier: MPL-2.0.
SPDX license identifier: MPL-2.0.
Implements the Receiving side of the RoutingPlugins.
SPDX license identifier: MPL-2.0.
SPDX license identifier: MPL-2.0.
SPDX license identifier: MPL-2.0.
void OutOfMemoryHandler()
the out of memory handler
SPDX license identifier: MPL-2.0.
SPDX license identifier: MPL-2.0.
static TCLAP::CmdLine * instanciateOnce(const std::string &message, const char delimiter= ' ', const std::string &version="none", bool helpAndVersion=true)
TCLAP::ValueArg< std::string > routingPluginDir("r","RoutingPluginDir","path for looking for routing plugins", false," ","string")
SPDX license identifier: MPL-2.0.
TCLAP::SwitchArg dbusWrapperTypeBool("T","dbusType","DbusType to be used by CAmDbusWrapper: if option is selected, DBUS_SYSTEM is used otherwise DBUS_SESSION", false)
TCLAP::ValueArg< std::string > additionalRoutingPluginDirs("R","additionalRoutingPluginDirs","additional path for looking for routing plugins, can be used after -r option ", false," ","string")
TCLAP::SwitchArg dltEnable("e","dltEnable","Enables or disables dlt logging. Default = enabled", true)
sends data to the commandInterface, takes the file of the library that needs to be loaded ...
This class handles and abstracts the database.
SPDX license identifier: MPL-2.0.
Implements a telnetserver that can be used to connect to the audiomanager, retrieve some information ...
void startWatchdog()
starts the watchdog by sending ready to systemD
SPDX license identifier: MPL-2.0.
static void CallsetControllerRundownSafe(int16_t signal)
TCLAP::ValueArg< unsigned int > dltOutput("O","dltOutput","defines where logs are written. 0=dlt-daemon(default), 1=command line, 2=file ", false, 0,"int")
am_Error_e startupInterfaces(CAmRoutingReceiver *iRoutingReceiver)
TCLAP::ValueArg< unsigned int > telnetPort("t","telnetport","The port that is used for telnet", false, DEFAULT_TELNETPORT,"int")
TCLAP::SwitchArg currentSettings("i","currentSettings","print current settings and exit", false)
void logError(T value, TArgs...args)
logs given values with errorlevel with the default context
std::vector< std::string > listRoutingPluginDirs
TCLAP::SwitchArg daemonizeAM("d","daemonize","daemonize Audiomanager. Better use systemd...", false)
SPDX license identifier: MPL-2.0.
This wraps dbus and provides everything needed to anyone who wants to use dbus (including plugins)...
SPDX license identifier: MPL-2.0.
SPDX license identifier: MPL-2.0.
static void CallsetControllerRundown(int16_t signal)
TCLAP::ValueArg< std::string > dltLogFilename("F","dltLogFilename","the name of the logfile, absolute path. Only if logging is et to file", false," ","string")
std::vector< std::string > listCommandPluginDirs
void mainProgram(int argc, char *argv[])
This class is used to send data to the CommandInterface.
This class handles and abstracts the database.
SPDX license identifier: MPL-2.0.
TCLAP::ValueArg< unsigned int > maxConnections("m","maxConnections","Maximal number of connections for telnet", false, MAX_TELNETCONNECTIONS,"int")
This class observes the Database and notifies other classes about important events, mainly the CommandSender.
TCLAP::ValueArg< std::string > controllerPlugin("c","controllerPlugin","use controllerPlugin full path with .so ending", false, CONTROLLER_PLUGIN_DIR,"string")