/** * @file include/ActivMiddleware/ActivFramework/Application.h * * @brief Header file for base application class. */ #if (!defined ACTIV_FRAMEWORK_APPLICATION_H) #define ACTIV_FRAMEWORK_APPLICATION_H #include "ActivMiddleware/ActivFramework/External.h" #include "ActivMiddleware/ActivFramework/Component.h" #include "ActivMiddleware/ActivFramework/DirectoryWatchApi.h" #include "ActivMiddleware/ActivFramework/TimerServiceApi.h" #include "ActivMiddleware/ActivFramework/LoggerServiceApi.h" #include "ActivMiddleware/ActivFramework/ManagedEndPoint.h" #include "ActivMiddleware/ActivFramework/RouterServiceApi.h" #include "ActivMiddleware/ActivFramework/PubSubServiceApi.h" #include "ActivMiddleware/ActivFramework/ServiceApi.h" #include "ActivMiddleware/ActivFramework/ISystem.h" #include "ActivMiddleware/ActivBase/CtrlHandler.h" #include ACTIV_BOOST_INCLUDE(scoped_ptr.hpp) #if (defined ACTIV_ENABLE_DPDK) #include "ActivMiddleware/ActivFramework/KernelBypass/DpdkSettings.h" #endif //! Activ namespace. namespace Activ { class SystemImpl; class PostMessageHelper; // --------------------------------------------------------------------------------------------------------------------------------- /** * @brief Proxy class for ISystem interface. */ class SystemProxy : public ISystem { public: /** * @brief Destructor. */ ACTIV_FRAMEWORK_API ~SystemProxy(); // ISystem. ACTIV_FRAMEWORK_API virtual IEndPoint *CreatePrivateEndPoint(const IEndPoint::Settings &settings) ACTIV_OVERRIDE; ACTIV_FRAMEWORK_API virtual IAddressableEndPoint *CreateEndPoint(const IAddressableEndPoint::Settings &settings) ACTIV_OVERRIDE; ACTIV_FRAMEWORK_API virtual IAddressableEndPoint *OpenEndPoint(const String &name, Timeout &timeout = Timeout::GetInfinite()) ACTIV_OVERRIDE; ACTIV_FRAMEWORK_API virtual IAddressableEndPoint *OpenEndPoint(EndPointId endPointId, Timeout &timeout = Timeout::GetInfinite()) ACTIV_OVERRIDE; ACTIV_FRAMEWORK_API virtual IAddressableEndPoint *OpenSystemEndPoint() ACTIV_OVERRIDE; ACTIV_FRAMEWORK_API virtual IHeap *CreateHeap(const String &name, const IHeap::Settings &settings) ACTIV_OVERRIDE; ACTIV_FRAMEWORK_API virtual IHeap *OpenHeap(const String &name, Timeout &timeout = Timeout::GetInfinite()) ACTIV_OVERRIDE; ACTIV_FRAMEWORK_API virtual IHeap *OpenHeap(const HeapId heapId, Timeout &timeout = Timeout::GetInfinite()) ACTIV_OVERRIDE; ACTIV_FRAMEWORK_API virtual IProcess *OpenProcess(const String &name, Timeout &timeout = Timeout::GetInfinite()) ACTIV_OVERRIDE; ACTIV_FRAMEWORK_API virtual IProcess *OpenProcess(const ProcessId processId, Timeout &timeout = Timeout::GetInfinite()) ACTIV_OVERRIDE; ACTIV_FRAMEWORK_API virtual const String &GetSystemName() const ACTIV_OVERRIDE; ACTIV_FRAMEWORK_API virtual IHeap *GetSystemHeap() const ACTIV_OVERRIDE; ACTIV_FRAMEWORK_API virtual IProcess *GetProcess() const ACTIV_OVERRIDE; ACTIV_FRAMEWORK_API virtual SystemInfo GetSystemInfo() const ACTIV_OVERRIDE; ACTIV_FRAMEWORK_API virtual void EnumerateObjects(IProcessEnumerator &enumerator) ACTIV_OVERRIDE; ACTIV_FRAMEWORK_API virtual void EnumerateObjects(IEndPointEnumerator &enumerator) ACTIV_OVERRIDE; ACTIV_FRAMEWORK_API virtual void EnumerateObjects(IHeapEnumerator &enumerator) ACTIV_OVERRIDE; ACTIV_FRAMEWORK_API virtual uint16_t GetNextAffinityProcessorId() const ACTIV_OVERRIDE; private: /** * @brief Create a system. * * @param settings settings. * @param processName the name of this process, if an empty string is provided uses the system name. * @param heapSettings describing the properties of the system heap to create. * @param systemVersion arbitrary version string for the system. * * @throw Exception. */ SystemProxy(const ISystem::Settings &settings, const String &processName, const IHeap::Settings &heapSettings, const String &systemVersion); /** * @brief Open a system. * * @param settings settings. * @param processName the name of this process, empty string gives a process name based on the os process id. * @param timeout how long to wait for the system to exist, in ms. * * @throw Exception. */ SystemProxy(const ISystem::Settings &settings, const String &processName, Timeout &timeout = Timeout::GetInfinite()); const Boost::scoped_ptr m_pSystem; ///< The underlying system friend class Application; friend class ManagedEndPointImpl; friend class PostMessageHelper; }; // --------------------------------------------------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------------------------------------------------- /** * @brief Base application class. * * The base application class provides the ISystem interface to create and open heaps, endpoints. * It also provides always on router and timer functionality and creates a default endpoint which is given the * name of the process. * * Do not use the Application class directly. AgentApplication is provided for processes which are to * create a shared memory system or standalone private memory application, * and ThinApplication for those which link into an existing shared memory system. */ class Application : public SystemProxy, public ManagedEndPoint, public Component { public: using Component::GetApplication; /** * @brief Settings. */ class Settings : public ISystem::Settings { public: /** * @brief List of exception handler types. * * Exception handler on available on Windows platform. */ enum ExceptionHandlerType { EXCEPTION_HANDLER_TYPE_NONE, ///< no exception handler EXCEPTION_HANDLER_TYPE_NORMAL, ///< don't dump entire address space EXCEPTION_HANDLER_TYPE_FULL_MEMORY ///< do dump address space }; /** * @brief Default constructor. */ ACTIV_FRAMEWORK_API Settings(); /** * @brief Read settings from an ini file section. * * @param sectionIterator iterator to an ini file section. * * @throw Exception */ ACTIV_FRAMEWORK_API void Read(const IniFileParser::ConstSectionIterator §ionIterator); String m_processName; ///< If empty a name will be assigned automatically. bool m_enableCtrlHandler; ///< Default: true. bool m_shouldMemoryLock; ///< Default: false. Posix only. Should the application be locked in memory. ExceptionHandlerType m_exceptionHandlerType; ///< Default: EXCEPTION_HANDLER_TYPE_NONE. ManagedEndPoint::Settings m_managedEndPointSettings; ///< Settings for default application endpoint. IHeap::Settings m_loggerServiceHeapSettings;///< Settings for thread-specific logger service heap. #if (defined ACTIV_ENABLE_DPDK) KernelBypass::DpdkSettings m_dpdkSettings; #endif }; /** * @brief Shutdown reasons. */ enum ShutdownReason { SHUTDOWN_REASON_API, ///< Shutdown() called on Application object. SHUTDOWN_REASON_UI, ///< System shutdown initiated from UI service. SHUTDOWN_REASON_UI_RESTART, ///< System restart initiated from UI service. SHUTDOWN_REASON_LOGOFF, ///< System shutdown initiated due to OS shutting down / user logging off. SHUTDOWN_REASON_TERMINATE_PROCESS, ///< SIGTERM, CTRL_CLOSE_EVENT received. SHUTDOWN_REASON_NOT_LICENSED ///< System is not licensed. }; /** * @brief Destructor. */ ACTIV_FRAMEWORK_API virtual ~Application() ACTIV_OVERRIDE; /** * @brief Set the state of the process. * * @param state new state. */ ACTIV_FRAMEWORK_API void SetState(const IProcess::State state); /** * @brief Initiate a shutdown. */ ACTIV_FRAMEWORK_API void Shutdown(); /** * @brief Get the monitor service heap. * * The monitor service heap should be used for publishing monitoring messages. * * @return Heap used by the monitor service. */ ACTIV_FRAMEWORK_API IHeap *GetMonitorServiceHeap() const; /** * @brief Get the monitor service heap. * * The monitor service heap should be used for publishing monitoring messages. * * @param component * * @return Heap used by the monitor service for this component. */ ACTIV_FRAMEWORK_API IHeap *GetMonitorServiceHeap(const Component &component) const; /** * @brief Get the name of the default ui service. * * This name should be used when adding components to the ui service. See UiComponent.h. * * @return The name of the default ui service. */ ACTIV_FRAMEWORK_API static const String &GetUiServiceName(); class Private; /** * @brief Get private implementation. * * @return Const reference to private implementation object. */ const Private &GetPrivate() const; protected: ACTIV_FRAMEWORK_API virtual StatusCode OnMessage(HeapMessage &message) ACTIV_OVERRIDE; /** * @brief Application has received a ctrl event. * * @param eventType the type of ctrl event. */ ACTIV_FRAMEWORK_API virtual void OnCtrlEvent(const CtrlHandler::EventType eventType); /** * @brief Shutdown has been invoked. * * This callback is invoked for all processes when a system is shutdown (i.e. the Agent has called AgentApplication::Shutdown()), * or for a single application if it itself calls ThinApplication::Shutdown(). * * When overriding, call the base class method at the end of the override. * * @param shutdownReason the reason for the shutdown. */ ACTIV_FRAMEWORK_API virtual void OnShutdown(const ShutdownReason shutdownReason); private: /** * @brief Create a system. * * @param settings settings for the application. * @param heapSettings info describing the properties of the system heap to create. * @param systemVersion arbitrary version string for the system. * * @throw Exception. */ ACTIV_FRAMEWORK_API Application(const Settings &settings, const IHeap::Settings &heapSettings, const String &systemVersion); /** * @brief Open a system. * * @param settings settings for the application. * @param heapSettings info describing the properties of the application's heap. If empty, use the system heap. * @param timeout how long to wait for the system to exist, in ms. * * @throw Exception. */ Application(const Settings &settings, const IHeap::Settings &heapSettings, Timeout &timeout = Timeout::GetInfinite()); Private *m_pPrivate; ///< Hidden implementation details. friend class AgentApplication; friend class ThinApplication; }; // --------------------------------------------------------------------------------------------------------------------------------- inline const Application::Private &Application::GetPrivate() const { return *m_pPrivate; } } // namespace Activ #endif // (!defined ACTIV_FRAMEWORK_APPLICATION_H)