/** * @file include/ActivMiddleware/ActivAgentApplication/UiService.h * * @brief Header file for the ui service class. */ #if (!defined ACTIV_AGENT_APPLICATION_UI_SERVICE_H) #define ACTIV_AGENT_APPLICATION_UI_SERVICE_H #include "ActivMiddleware/ActivAgentApplication/External.h" #include ACTIV_BOOST_INCLUDE(scoped_ptr.hpp) #include //! Activ namespace. namespace Activ { /** * @brief Ui service class. * * A ui service requires the address of the ui component that is to act as the main menu of the service, * which exists on a separate endpoint. A heap with the same name as this service must have been created * before construction of this object. */ class UiService : private ManagedEndPoint, public Service { public: using Service::GetApplication; typedef String UserId; ///< Type of user id. typedef String UserPassword; ///< Type of user password. /** * @brief User info. */ class UserInfo { public: UserId m_id; ///< Id of user. UserPassword m_password; ///< Password of user. UiPermissions m_uiPermissions; ///< Ui permissions of user. }; typedef std::map UserInfoMap; ///< Type of user info map. /** * @brief Settings. */ class Settings { public: /** * @brief Default constructor. */ ACTIV_AGENT_APPLICATION_API Settings(); /** * @brief Destructor. */ ACTIV_AGENT_APPLICATION_API ~Settings(); /** * @brief Read settings from an ini file section. * * @param sectionIterator iterator to an ini file section. * * @throw Exception */ ACTIV_AGENT_APPLICATION_API void Read(const IniFileParser::ConstSectionIterator §ionIterator); //! Options for behavior of local console access to UiService. enum ConsoleMode { CONSOLE_MODE_OFF, ///< No local console session to ui service. CONSOLE_MODE_RESTART_TELNET_ON_CLOSE, ///< Local telnet session to ui service. Restart session if closed. CONSOLE_MODE_SHUTDOWN_SYSTEM_ON_CLOSE ///< Local telnet session to ui service. Shutdown system if closed. }; //! Settings for ui tunnelling. class Tunnel { public: String m_serviceId; ///< Service id for the tunnel service. ServiceAccessPointList m_serviceAccessPointList; ///< Server-side access points. None by default. String m_serviceAttributes; ///< Attributes for the tunnel service. bool m_isClient; ///< Whether to attempt to connect to a tunnel service. }; /** * @brief Default UiService port. Append this to m_serviceAccessPointList if required. */ ACTIV_AGENT_APPLICATION_API static const ServiceAccessPoint defaultAccessPoint; IHeap::Settings m_heapSettings; ///< Heap properties. Default buckets, see above. ManagedEndPoint::Settings m_managedEndPointSettings; ConsoleMode m_consoleMode; ///< Console client mode. Dflt CONSOLE_MODE_SHUTDOWN_SYSTEM_ON_CLOSE. bool m_enableLogOutput; ///< Enable log output? Default == true. bool m_enableAnonymousAccess; ///< Enable view-only anonymous user? Default == true. UiPermissions m_anonymousAccessPermissions; ///< Anonymous access permissions. ServiceAccessPointList m_serviceAccessPointList; ///< Access points. Default is empty; creates only a loopback server. UserInfoMap m_userInfoMap; ///< Info about users. Tunnel m_tunnel; ///< Tunnelling settings. bool m_enableLog; ///< Log file to log user's input and output. Default == false. }; /** * @brief Ui service ui component. */ class UiComponent ACTIV_FINAL : public Activ::UiComponent { public: /** * @brief Constructor. * * @param uiService the ui service to have the ui. * * @throw Exception. */ ACTIV_AGENT_APPLICATION_API UiComponent(UiService &uiService); private: virtual void Run(UiUser &uiUser) ACTIV_OVERRIDE; UiService & m_uiService; // Last member. Component::Enabler m_componentEnabler; }; /** * @brief Constructor. * * @param application Application object to attach to. * @param serviceName name of the service. * @param settings settings for the service. * * @throw Exception. */ ACTIV_AGENT_APPLICATION_API UiService(Application &application, const String &serviceName, const Settings &settings); /** * @brief Destructor. */ ACTIV_AGENT_APPLICATION_API ~UiService(); class Impl; protected: ACTIV_AGENT_APPLICATION_API virtual bool CanThreadExit() ACTIV_OVERRIDE; ACTIV_AGENT_APPLICATION_API virtual StatusCode OnMessage(HeapMessage &message) ACTIV_OVERRIDE; ACTIV_AGENT_APPLICATION_API virtual StatusCode OnAccept(HeapMessage &acceptMessage) ACTIV_OVERRIDE; ACTIV_AGENT_APPLICATION_API virtual StatusCode OnTimer(const Address &timerAddress, const DateTime &dateTime) ACTIV_OVERRIDE; private: static const ServiceId m_serviceId; ///< Id of the ui service. Boost::scoped_ptr m_pImpl; ///< Implementation. }; } // namespace Activ #endif // (!defined ACTIV_AGENT_APPLICATION_UI_SERVICE_H)