25 #include "audiomanagerconfig.h" 27 #ifdef WITH_CAPI_WRAPPER 31 #ifdef WITH_DBUS_WRAPPER 35 #ifdef WITH_SYSTEMD_WATCHDOG 39 #include <sys/resource.h> 63 #ifndef AUDIOMANGER_APP_ID 64 #define AUDIOMANGER_APP_ID "AUDI" 67 #ifndef AUDIOMANGER_APP_DESCRIPTION 68 #define AUDIOMANGER_APP_DESCRIPTION "AudioManager" 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::SwitchArg
dltEnable (
"e",
"dltEnable",
"Enables or disables dlt logging. Default = enabled",
true);
90 TCLAP::SwitchArg
dbusWrapperTypeBool (
"T",
"dbusType",
"DbusType to be used by CAmDbusWrapper: if option is selected, DBUS_SYSTEM is used otherwise DBUS_SESSION",
false);
91 TCLAP::SwitchArg
currentSettings(
"i",
"currentSettings",
"print current settings and exit",
false);
92 TCLAP::SwitchArg
daemonizeAM(
"d",
"daemonize",
"daemonize Audiomanager. Better use systemd...",
false);
96 #ifdef WITH_DBUS_WRAPPER 97 DBusBusType dbusWrapperType=DBUS_BUS_SESSION;
106 throw std::runtime_error(std::string(
"SocketHandler::start_listenting ppoll returned with error."));
115 std::string dir =
"/";
118 if (getrlimit(RLIMIT_NOFILE, &rl) < 0)
124 if ((pid = fork()) < 0)
135 if (!dir.empty() && chdir(dir.c_str()) < 0)
137 logError(
"couldn't chdir to the new directory");
140 if (rl.rlim_max == RLIM_INFINITY)
145 for (
unsigned int i = 0; i < rl.rlim_max; i++)
150 fd0 = open(
"/dev/null", O_RDONLY);
151 fd1 = open(
"/dev/null", O_WRONLY | O_CREAT | O_APPEND, S_IRUSR | S_IWUSR);
152 fd2 = open(
"/dev/null", O_WRONLY | O_CREAT | O_APPEND, S_IRUSR | S_IWUSR);
154 if (
fd0 != STDIN_FILENO ||
fd1 != STDOUT_FILENO ||
fd2 != STDERR_FILENO)
156 logError(
"new standard file descriptors were not opened");
164 printf(
"\n\n\nCurrent settings:\n\n");
165 printf(
"\tAudioManagerDaemon Version:\t\t%s\n", DAEMONVERSION);
166 printf(
"\tControllerPlugin: \t\t\t%s\n",
controllerPlugin.getValue().c_str());
167 printf(
"\tDirectories of CommandPlugins: \t\t\n");
168 std::vector<std::string>::const_iterator dirIter = listCommandPluginDirs.begin();
169 std::vector<std::string>::const_iterator dirIterEnd = listCommandPluginDirs.end();
170 for (; dirIter < dirIterEnd; ++dirIter)
172 printf(
"\t \t\t%s\n", dirIter->c_str());
175 printf(
"\tDirectories of RoutingPlugins: \t\t\n");
176 dirIter = listRoutingPluginDirs.begin();
177 dirIterEnd = listRoutingPluginDirs.end();
178 for (; dirIter < dirIterEnd; ++dirIter)
180 printf(
"\t \t\t%s\n", dirIter->c_str());
191 static void signalHandler(
int sig, siginfo_t *siginfo,
void *context)
196 logInfo(
"signal handler was called, signal",sig);
233 #ifdef WITH_DBUS_WRAPPER 237 catch (TCLAP::ArgException &e)
238 { std::cerr <<
"error: " << e.error() <<
" for arg " << e.argId() << std::endl; }
252 if(iSocketHandler.fatalErrorOccurred())
254 throw std::runtime_error(std::string(
"CAmSocketHandler: Could not create pipe or file descriptor is invalid."));
257 if(
E_OK != iSocketHandler.listenToSignals(listOfSignalsFD))
259 logWarning(
"CAmSocketHandler failed to register itself as signal handler.");
263 iSocketHandler.addSignalHandler([&](
const sh_pollHandle_t handle,
const signalfd_siginfo & info,
void* userData){
265 unsigned sig = info.ssi_signo;
266 unsigned user = info.ssi_uid;
268 logInfo(
"signal handler was called from user", user,
"with signal ",sig);
284 },signalHandler,NULL);
288 listCommandPluginDirs.clear();
299 listRoutingPluginDirs.clear();
329 catch (TCLAP::ArgException &e)
330 { std::cerr <<
"error: " << e.error() <<
" for arg " << e.argId() << std::endl; }
332 logInfo(
"The Audiomanager is started");
333 logInfo(
"The version of the Audiomanager", DAEMONVERSION);
335 #ifdef WITH_CAPI_WRAPPER 340 #ifdef WITH_DBUS_WRAPPER 342 dbusWrapperType=DBUS_BUS_SYSTEM;
346 #ifdef WITH_SYSTEMD_WATCHDOG 350 CAmRouter iRouter(pDatabaseHandler, &iControlSender);
352 #ifdef WITH_DBUS_WRAPPER 353 CAmCommandReceiver iCommandReceiver(pDatabaseHandler, &iControlSender, &iSocketHandler, &iDBusWrapper);
354 CAmRoutingReceiver iRoutingReceiver(pDatabaseHandler, &iRoutingSender, &iControlSender, &iSocketHandler, &iDBusWrapper);
356 CAmCommandReceiver iCommandReceiver(pDatabaseHandler,&iControlSender,&iSocketHandler);
357 CAmRoutingReceiver iRoutingReceiver(pDatabaseHandler,&iRoutingSender,&iControlSender,&iSocketHandler);
360 CAmControlReceiver iControlReceiver(pDatabaseHandler,&iRoutingSender,&iCommandSender,&iSocketHandler, &iRouter);
367 iControlSender.startupController(&iControlReceiver);
372 iControlSender.setControllerReady();
374 #ifdef WITH_SYSTEMD_WATCHDOG 379 iSocketHandler.start_listenting();
388 int main(
int argc,
char *argv[],
char** envp)
391 listCommandPluginDirs.push_back(std::string(DEFAULT_PLUGIN_COMMAND_DIR));
392 listRoutingPluginDirs.push_back(std::string(DEFAULT_PLUGIN_ROUTING_DIR));
395 struct sigaction signalAction;
396 memset(&signalAction,
'\0',
sizeof(signalAction));
397 signalAction.sa_sigaction = &signalHandler;
398 signalAction.sa_flags = SA_SIGINFO;
399 sigaction(SIGINT, &signalAction, NULL);
400 sigaction(SIGQUIT, &signalAction, NULL);
405 sigset_t signal_mask;
406 sigemptyset(&signal_mask);
407 for (
auto it : listOfSignalsFD)
409 sigaddset(&signal_mask, it);
414 if (pthread_sigmask(SIG_BLOCK, &signal_mask, NULL) != 0)
416 throw std::runtime_error(std::string(
"Couldn't set mask for potential future threads"));
423 catch (std::exception& exc)
425 logError(
"The AudioManager ended by throwing the exception", exc.what());
426 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")
void logWarning(T value, TArgs...args)
logs given values with warninglevel with the default context
A Common-API wrapper class, which loads the common-api runtime and instantiates all necessary objects...
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 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()
#define AUDIOMANGER_APP_DESCRIPTION
uint16_t sh_pollHandle_t
this is a handle for a filedescriptor to be used with the SocketHandler
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.
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)
#define AUDIOMANGER_APP_ID
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.
bool registerObserver(IAmDatabaseObserver *iObserver)
std::vector< uint8_t > listOfSignalsFD
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::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)
This wraps dbus and provides everything needed to anyone who wants to use dbus (including plugins)...
SPDX license identifier: MPL-2.0.
no error - positive reply
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< std::string > controllerPlugin("c","controllerPlugin","use controllerPlugin full path with .so ending", false, CONTROLLER_PLUGIN_DIR,"string")