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

151 lines
3.6 KiB
C++

/**
* @file include/ActivMiddleware/ActivAgentApplication/PubSubService.h
*
* @brief Header file for pubsub service.
*/
#if (!defined ACTIV_AGENT_APPLICATION_PUB_SUB_SERVICE_H)
#define ACTIV_AGENT_APPLICATION_PUB_SUB_SERVICE_H
#include "ActivMiddleware/ActivAgentApplication/External.h"
#include "ActivMiddleware/ActivFramework/PubSubServiceApi.h"
#include <map>
//! Activ namespace.
namespace Activ
{
/**
* @brief Publish-subscribe service class.
*/
class PubSubService : private ManagedEndPoint, public Component
{
public:
using Component::GetApplication;
/**
* @brief Settings.
*/
class Settings
{
public:
/**
* @brief Republish settings.
*
* This describes a mapping from subject -> set of multicast outputs for that subject.
*/
class Republish
{
public:
typedef std::vector<String> MulticastNameList;
String m_subject; ///< (Partial) subject to match on
MulticastNameList m_multicastNameList; ///< List of multicast groups to output on
};
/**
* @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 &sectionIterator);
typedef std::map<String, PubSubServiceApi::Multicast> MulticastMap;
typedef std::vector<Republish> RepublishList;
IHeap::Settings m_heapSettings; ///< Properties of the service heap.
ManagedEndPoint::Settings m_managedEndPointSettings;
MulticastMap m_multicastMap; ///< Map of multicast outputs.
RepublishList m_republishList; ///< List of subjects to write to multicast outputs.
private:
/**
* @brief Process multicast section in the ini file.
*
* @param sectionIterator iterator to an ini file section.
*
* @throw Exception
*/
void ProcessMulticastSection(const IniFileParser::ConstSectionIterator &sectionIterator);
/**
* @brief Process republish section in the ini file.
*
* @param sectionIterator iterator to an ini file section.
*
* @throw Exception
*/
void ProcessRepublishSection(const IniFileParser::ConstSectionIterator &sectionIterator);
};
/**
* @brief Message broker service ui component.
*/
class UiComponent ACTIV_FINAL : public Activ::UiComponent
{
public:
/**
* @brief Constructor.
*
* @param pubSubService service to show menu for.
* @param uiServiceName name of the ui service.
*
* @throw Exception.
*/
ACTIV_AGENT_APPLICATION_API UiComponent(PubSubService &pubSubService, const String &uiServiceName);
private:
virtual void Run(UiUser &uiUser) ACTIV_OVERRIDE;
PubSubService & m_pubSubService;
// Last member.
Component::Enabler m_componentEnabler;
};
/**
* @brief Constructor.
*
* @param application the application the service will be linked to.
* @param serviceName name of the service.
* @param settings settings for the service.
*
* @throw Exception.
*/
ACTIV_AGENT_APPLICATION_API PubSubService(Application &application, const String &serviceName, const Settings &settings);
/**
* @brief Destructor.
*/
ACTIV_AGENT_APPLICATION_API ~PubSubService();
class Impl;
protected:
virtual bool CanThreadExit() ACTIV_OVERRIDE;
virtual StatusCode OnRequest(HeapMessage &request) ACTIV_OVERRIDE;
virtual StatusCode OnMessage(HeapMessage &message) ACTIV_OVERRIDE;
private:
const Boost::scoped_ptr<Impl> m_pImpl; ///< Implementation.
};
} // namespace Activ
#endif // (!defined ACTIV_AGENT_APPLICATION_PUB_SUB_SERVICE_H)