Files
externals/linux/include/ActivMiddleware/ActivAgentApplication/AgentApplication.h
T
2023-12-15 13:15:08 -05:00

182 lines
7.4 KiB
C++

/**
* @file include/ActivMiddleware/ActivAgentApplication/AgentApplication.h
*
* @brief Header file for agent application class.
*/
#if (!defined ACTIV_AGENT_APPLICATION_AGENT_APPLICATION_H)
#define ACTIV_AGENT_APPLICATION_AGENT_APPLICATION_H
#include "ActivMiddleware/ActivAgentApplication/External.h"
#include "ActivMiddleware/ActivAgentApplication/TimerService.h"
#include "ActivMiddleware/ActivAgentApplication/LoggerService.h"
#include "ActivMiddleware/ActivAgentApplication/PubSubService.h"
#include "ActivMiddleware/ActivAgentApplication/MonitorService.h"
#include "ActivMiddleware/ActivAgentApplication/DirectoryService.h"
#include "ActivMiddleware/ActivAgentApplication/UiService.h"
#include "ActivMiddleware/ActivAgentApplication/LicenseService.h"
#include "ActivMiddleware/ActivBase/CommandLineParser.h"
#include "ActivMiddleware/ActivFramework/RouterService.h"
#include ACTIV_BOOST_INCLUDE(scoped_ptr.hpp)
//! Activ namespace.
namespace Activ
{
class UiMainComponent;
// ---------------------------------------------------------------------------------------------------------------------------------
/**
* @brief Agent application class.
*
* The AgentApplication class should be used when creating a shared memory system or stand alone process.
* It provides always on timer, logger, directory, router and pub-sub services.
*/
class AgentApplication : public Application
{
public:
//! Agent settings.
class Settings : public Application::Settings
{
public:
//! Default constructor.
ACTIV_AGENT_APPLICATION_API Settings();
//! Destructor.
ACTIV_AGENT_APPLICATION_API ~Settings();
/**
* @brief Read settings from an ini file.
*
* @param iniFileParser already parsed ini file to get settings from.
*
* @throw Exception
*/
ACTIV_AGENT_APPLICATION_API void Read(const IniFileParser &iniFileParser);
//! Modes for the UiService.
enum UiServiceMode
{
UI_SERVICE_MODE_OFF, ///< No UiService.
UI_SERVICE_MODE_NO_MENU, ///< On, but don't provide a main menu.
UI_SERVICE_MODE_EXTENDED_SHUTDOWN, ///< Regular main menu with shutdown validation.
UI_SERVICE_MODE_QUICK_SHUTDOWN, ///< Regular main menu with no shutdown validation.
UI_SERVICE_MODE_LITE ///< "Lite" main menu.
};
String m_systemVersion; ///< Optional version of the system.
IHeap::Settings m_systemHeapSettings; ///< Properties of the system heap.
String m_serviceLocationIniFile; ///< Service location ini file.
String m_processStartupIniFile; ///< Ini file for processes to launch.
bool m_createSystemLog; ///< Whether to create system log.
UInt m_maxTotalSizeOfBackupFiles; ///< Maximum total size of all system log backup files.
UInt m_systemLogSplitFileSize; ///< Position at which system log should split and move to new file.
UInt m_systemLogNumberOfBackups; ///< Number of past increments (days) for which to keep backup system log files.
bool m_enableTerminateProcessShutdown; ///< Initiate shutdown if SIGTERM/CTRL_CLOSE_EVENT received? Default: false.
UiServiceMode m_uiServiceMode; ///< Mode to run the UiService in.
bool m_isUiRestartEnabled; ///< Show restart option in ui.
// Core service settings.
TimerService::Settings m_timerServiceSettings; ///< Settings for timer service.
LoggerService::Settings m_loggerServiceSettings; ///< Settings for logger service.
RouterService::Settings m_routerServiceSettings; ///< Settings for router service.
PubSubService::Settings m_pubSubServiceSettings; ///< Pubsub service settings.
MonitorService::Settings m_monitorServiceSettings; ///< Monitor service settings.
DirectoryService::Settings m_directoryServiceSettings; ///< Settings for directory service.
UiService::Settings m_uiServiceSettings; ///< Settings for ui service.
LicenseService::Settings m_licenseServiceSettings; ///< Settings for license service.
};
//! Agent command line parser. Provides a common command line parser for ACTIV AgentApplications.
class AgentCommandLineParser : public CommandLineParser
{
public:
//! Default constructor.
ACTIV_AGENT_APPLICATION_API AgentCommandLineParser();
String m_iniFileName; ///< Default: <empty>. Configured file to use.
String m_userName; ///< Default: <empty>. Switch to this user context prior to constructing the AgentApplication (POSIX only).
String m_pidFile; ///< Default: <empty>. File to write the process pid to (POSIX ONLY).
bool m_isDaemon; ///< Default: false. If true start the process as a daemon (POSIX ONLY).
String m_cpuSet; ///< Default: "root". On start attempt to move the process to this cpuset.
bool m_isPrivate; ///< Default: false. If true use MEMORY_MODEL_PRIVATE instead of MEMORY_MODEL_SHARED.
bool m_shouldDisplayVersion; ///< Default: false. If true display ACTIV_MIDDLEWARE_VERSION_STRING and exit.
String m_startCommand; ///< Default: <empty>. The command to use to restart the process if requested.
String m_userContext; ///< Default: <empty>. Context string provided in the system ui field 'User context'.
size_t m_uptimeMilliseconds; ///< Default: 0. If non-zero, shutdown (or restart) the application after this time has elapsed.
String m_uiServiceUrl; ///< Default: UiService::Settings::defaultAccessPoint. The ui service access point to use.
bool m_isRestartEnabled; ///< Default: false. If true process will be restarted on exit.
};
/**
* @brief Create a system.
*
* @param settings agent settings.
* @param componentId the component id.
*
* @throw Exception.
*/
ACTIV_AGENT_APPLICATION_API AgentApplication(const Settings &settings = Settings(),
const String &componentId = defaultComponentId);
//! Destructor.
ACTIV_AGENT_APPLICATION_API virtual ~AgentApplication() ACTIV_OVERRIDE;
/**
* @brief Configure the default Agent settings used by ACTIV AgentApplications.
*
* @param settings agent settings.
* @param commandLineParser
*
* @throw Exception
* @throw std::exception
* @throw Boost::exception
*/
ACTIV_AGENT_APPLICATION_API static void ConfigureAgentSettings(Settings &settings,
const AgentCommandLineParser &commandLineParser);
/**
* @brief Configure Agent environment used by ACTIV AgentApplications.
*
* @param settings agent settings.
* @param commandLineParser
*
* @throw Exception
* @throw std::exception
* @throw Boost::exception
*/
ACTIV_AGENT_APPLICATION_API static void ConfigureAgentEnvironment(Settings &settings,
const AgentCommandLineParser &commandLineParser);
/**
* @brief Process Agent restart.
*
* @param isRestartEnabled
* @param restartCommand
*/
ACTIV_AGENT_APPLICATION_API static void ProcessAgentRestart(const bool isRestartEnabled, const String &restartCommand);
class Private;
protected:
ACTIV_AGENT_APPLICATION_API virtual StatusCode OnMessage(HeapMessage &message) ACTIV_OVERRIDE;
ACTIV_AGENT_APPLICATION_API virtual StatusCode OnRequest(HeapMessage &request) ACTIV_OVERRIDE;
ACTIV_AGENT_APPLICATION_API virtual void OnCtrlEvent(const CtrlHandler::EventType eventType) ACTIV_OVERRIDE;
ACTIV_AGENT_APPLICATION_API virtual bool CanThreadExit() ACTIV_OVERRIDE;
private:
class UiFunctionality;
Boost::scoped_ptr<Private> m_pPrivate; ///< Hidden implementation details
friend class UiMainComponent;
};
} // namespace Activ
#endif // (!defined ACTIV_AGENT_APPLICATION_AGENT_APPLICATION_H)