483 lines
14 KiB
C++
483 lines
14 KiB
C++
/**
|
|
* @file include/ActivMiddleware/ActivFramework/ISystem.h
|
|
*
|
|
* @brief Header file for abstract system class.
|
|
*/
|
|
|
|
#if (!defined ACTIV_FRAMEWORK_ISYSTEM_H)
|
|
#define ACTIV_FRAMEWORK_ISYSTEM_H
|
|
|
|
#include "ActivMiddleware/ActivFramework/External.h"
|
|
|
|
#include "ActivMiddleware/ActivBase/FieldTypes/DateTime.h"
|
|
#include "ActivMiddleware/ActivBase/GenericMessages.h"
|
|
#include "ActivMiddleware/ActivBase/IniFileParser.h"
|
|
#include "ActivMiddleware/ActivBase/Process.h"
|
|
#include "ActivMiddleware/ActivBase/SystemInfo.h"
|
|
#include "ActivMiddleware/ActivBase/Timeout.h"
|
|
#include "ActivMiddleware/ActivFramework/IEndPoint.h"
|
|
#include "ActivMiddleware/ActivFramework/IHeap.h"
|
|
#include "ActivMiddleware/ActivFramework/IProcess.h"
|
|
|
|
//! Activ namespace.
|
|
namespace Activ
|
|
{
|
|
|
|
/**
|
|
* @brief Abstract system interface class.
|
|
*
|
|
* Provides functionality to create new or open existing endpoints and heaps.
|
|
*/
|
|
class ISystem : private Boost::noncopyable
|
|
{
|
|
public:
|
|
/**
|
|
* @brief Settings.
|
|
*/
|
|
class Settings
|
|
{
|
|
public:
|
|
enum MemoryModel
|
|
{
|
|
MEMORY_MODEL_SHARED, ///< System exists in shared memory.
|
|
MEMORY_MODEL_PRIVATE ///< System exists in private memory.
|
|
};
|
|
|
|
enum SystemLogMode
|
|
{
|
|
SYSTEM_LOG_MODE_OFF, ///< System log off for this process.
|
|
SYSTEM_LOG_MODE_TO_CONSOLE, ///< System log goes to local console for this process.
|
|
SYSTEM_LOG_MODE_TO_AGENT ///< System log messages published to agent for this process.
|
|
};
|
|
|
|
/**
|
|
* @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_systemName; ///< Name of the system to create / open (default is contents of ACTIV_SYSTEM_NAME env-var if set, otherwise "System").
|
|
MemoryModel m_memoryModel; ///< Shared or private memory system (default private).
|
|
String m_processVersion; ///< Process version string.
|
|
String m_processType; ///< Process type string.
|
|
String m_processUserContext; ///< Arbitrary user context string for the process.
|
|
bool m_setConsoleTitle; ///< Set console title (default false).
|
|
SystemLogMode m_systemLogMode; ///< System log mode for this process (default SYSTEM_LOG_MODE_TO_AGENT).
|
|
ProcessorAffinity m_processorAffinity; ///< Default: do not adjust.
|
|
uint16_t m_initialThreadAffinityProcessorId; ///< First processor to use when allocating thread affinities.
|
|
bool m_shouldSwitchToAgentUser; ///< Linux only. Default: true. If true the child process should be switch to the Agent user if run as root.
|
|
|
|
String m_memoryAllocationTraceFile; ///< Linux only: file to trace malloc/frees to. Default: empty.
|
|
bool m_shouldEnableThreadSpecificEndPoints; ///< Default: false for release builds; true for debug builds on non-Windows. Enable thread-specific endpoints.
|
|
|
|
protected:
|
|
ACTIV_FRAMEWORK_API
|
|
static const String sectionName; ///< All settings are in this section.
|
|
};
|
|
|
|
/**
|
|
* @brief System information.
|
|
*/
|
|
class SystemInfo : public Activ::SystemInfo
|
|
{
|
|
public:
|
|
/**
|
|
* @brief Default constructor.
|
|
*/
|
|
ACTIV_FRAMEWORK_API
|
|
SystemInfo();
|
|
|
|
/**
|
|
* @brief Serialize this SystemInfo in non-versioned generic self-describing format.
|
|
*
|
|
* @param messageBuilder to serialize into.
|
|
*
|
|
* @return STATUS_CODE_SUCCESS or error code.
|
|
*/
|
|
ACTIV_FRAMEWORK_API
|
|
StatusCode Serialize2(MessageBuilder &messageBuilder) const;
|
|
|
|
/**
|
|
* @brief Serialize this SystemInfo in legacy versioned format.
|
|
*
|
|
* @param messageBuilder to serialize into.
|
|
*
|
|
* @return STATUS_CODE_SUCCESS or error code.
|
|
*/
|
|
ACTIV_FRAMEWORK_API
|
|
StatusCode SerializeVersioned(MessageBuilder &messageBuilder) const;
|
|
|
|
/**
|
|
* @brief Serialize this SystemInfo in legacy versioned format, to the version of the SystemInfo parameter.
|
|
*
|
|
* @param messageBuilder to serialize into.
|
|
* @param systemInfo containing the version to serialize to.
|
|
*
|
|
* @return STATUS_CODE_SUCCESS or error code.
|
|
*/
|
|
ACTIV_FRAMEWORK_API
|
|
StatusCode SerializeVersioned(MessageBuilder &messageBuilder, const SystemInfo &systemInfo) const;
|
|
|
|
/**
|
|
* @brief Deserialize SystemInfo in generic self-describing format.
|
|
*
|
|
* @param messageValidator to deserialize from.
|
|
*
|
|
* @return STATUS_CODE_SUCCESS or error code.
|
|
*/
|
|
ACTIV_FRAMEWORK_API
|
|
StatusCode Deserialize2(MessageValidator &messageValidator);
|
|
|
|
/**
|
|
* @brief Deserialize SystemInfo in legacy versioned format.
|
|
*
|
|
* @param messageValidator to deserialize from.
|
|
*
|
|
* @return STATUS_CODE_SUCCESS or error code.
|
|
*/
|
|
ACTIV_FRAMEWORK_API
|
|
StatusCode DeserializeVersioned(MessageValidator &messageValidator);
|
|
|
|
String m_systemName; ///< System name.
|
|
String m_systemVersion; ///< System version.
|
|
Settings::MemoryModel m_memoryModel; ///< Shared or private memory system (default shared).
|
|
DateTime m_utcStartupDateTime; ///< System startup time, utc.
|
|
size_t m_upTimeSeconds; ///< System uptime in seconds.
|
|
|
|
private:
|
|
/**
|
|
* @brief Serialize this SystemInfo to a specific legacy version.
|
|
*
|
|
* @param messageBuilder to serialize into.
|
|
* @param version containing the version to serialize to.
|
|
*
|
|
* @return STATUS_CODE_SUCCESS or error code.
|
|
*/
|
|
StatusCode SerializeVersioned(MessageBuilder &messageBuilder, const byte_t version) const;
|
|
|
|
static const byte_t currentVersion = 1; ///< Current version of serialized format.
|
|
|
|
byte_t m_version;
|
|
|
|
class Message;
|
|
};
|
|
|
|
/**
|
|
* @brief Process enumerator callback interface.
|
|
*/
|
|
class IProcessEnumerator
|
|
{
|
|
public:
|
|
/**
|
|
* @brief Destructor.
|
|
*/
|
|
virtual ~IProcessEnumerator() = 0;
|
|
|
|
/**
|
|
* @brief Callback on a process instance.
|
|
*
|
|
* @param pProcess pointer to an object providing an IProcess interface.
|
|
*
|
|
* @retval true to continue enumerating.
|
|
* @retval false to stop enumerating.
|
|
*/
|
|
virtual bool OnObject(IProcess * const pProcess) = 0;
|
|
};
|
|
|
|
/**
|
|
* @brief Endpoint enumerator callback interface.
|
|
*/
|
|
class IEndPointEnumerator
|
|
{
|
|
public:
|
|
/**
|
|
* @brief Destructor.
|
|
*/
|
|
virtual ~IEndPointEnumerator() = 0;
|
|
|
|
/**
|
|
* @brief Callback on an endpoint instance.
|
|
*
|
|
* @param pEndPoint pointer to an object providing an IAddressableEndPoint interface.
|
|
*
|
|
* @retval true to continue enumerating.
|
|
* @retval false to stop enumerating.
|
|
*/
|
|
virtual bool OnObject(IAddressableEndPoint * const pEndPoint) = 0;
|
|
};
|
|
|
|
/**
|
|
* @brief Heap enumerator callback interface.
|
|
*/
|
|
class IHeapEnumerator
|
|
{
|
|
public:
|
|
/**
|
|
* @brief Destructor.
|
|
*/
|
|
virtual ~IHeapEnumerator() = 0;
|
|
|
|
/**
|
|
* @brief Callback on a heap instance.
|
|
*
|
|
* @param pHeap pointer to an object providing an IHeap interface.
|
|
*
|
|
* @retval true to continue enumerating.
|
|
* @retval false to stop enumerating.
|
|
*/
|
|
virtual bool OnObject(IHeap * const pHeap) = 0;
|
|
};
|
|
|
|
/**
|
|
* @brief Destructor.
|
|
*/
|
|
virtual ~ISystem() = 0;
|
|
|
|
/**
|
|
* @brief Create a private, local memory endpoint.
|
|
*
|
|
* @param settings describing the endpoint to create.
|
|
*
|
|
* @return Pointer to an object providing an IEndPoint interface.
|
|
*
|
|
* @throw Exception
|
|
*/
|
|
virtual IEndPoint *CreatePrivateEndPoint(const IEndPoint::Settings &settings) = 0;
|
|
|
|
/**
|
|
* @brief Create a system endpoint.
|
|
*
|
|
* @param settings describing the endpoint to create.
|
|
*
|
|
* @return Pointer to an object providing an IAddressableEndPoint interface.
|
|
*
|
|
* @throw Exception
|
|
*/
|
|
virtual IAddressableEndPoint *CreateEndPoint(const IAddressableEndPoint::Settings &settings) = 0;
|
|
|
|
/**
|
|
* @brief Open a system endpoint by name.
|
|
*
|
|
* @param name the name of the endpoint which exists within the parent system namespace.
|
|
* @param timeout a Timeout object specifying how long to wait for the endpoint to exist.
|
|
*
|
|
* @return Pointer to an object providing an IAddressableEndPoint interface.
|
|
*
|
|
* @throw Exception
|
|
*/
|
|
virtual IAddressableEndPoint *OpenEndPoint(const String &name, Timeout &timeout = Timeout::GetInfinite()) = 0;
|
|
|
|
/**
|
|
* @brief Open a system endpoint by id.
|
|
*
|
|
* @param endPointId the system unique id of the endpoint to open.
|
|
* @param timeout a Timeout object specifying how long to wait for the endpoint to exist.
|
|
*
|
|
* @return Pointer to an object providing an IAddressableEndPoint interface.
|
|
*
|
|
* @throw Exception
|
|
*/
|
|
virtual IAddressableEndPoint *OpenEndPoint(EndPointId endPointId, Timeout &timeout = Timeout::GetInfinite()) = 0;
|
|
|
|
/**
|
|
* @brief Open the system endpoint.
|
|
*
|
|
* @return Pointer to an object providing an IAddressableEndPoint interface.
|
|
*
|
|
* @throw Exception
|
|
*/
|
|
virtual IAddressableEndPoint *OpenSystemEndPoint() = 0;
|
|
|
|
/**
|
|
* @brief Create a named memory heap.
|
|
*
|
|
* @param name the name of the heap which will exist within the parent system namespace.
|
|
* @param settings describing the layout of the heap.
|
|
*
|
|
* @return Pointer to an object providing an IHeap interface.
|
|
*
|
|
* @throw Exception
|
|
*/
|
|
virtual IHeap *CreateHeap(const String &name, const IHeap::Settings &settings) = 0;
|
|
|
|
/**
|
|
* @brief Open an existing named memory heap.
|
|
*
|
|
* @param name the name of the heap which exists within the parent system namespace.
|
|
* @param timeout a Timeout object specifying how long to wait for the heap to exist.
|
|
*
|
|
* @return Pointer to an object providing an IHeap interface.
|
|
*
|
|
* @throw Exception
|
|
*/
|
|
virtual IHeap *OpenHeap(const String &name, Timeout &timeout = Timeout::GetInfinite()) = 0;
|
|
|
|
/**
|
|
* @brief Open an existing named memory heap.
|
|
*
|
|
* @param heapId the system unique id of the heap to open.
|
|
* @param timeout a Timeout object specifying how long to wait for the heap to exist.
|
|
*
|
|
* @return Pointer to an object providing an IHeap interface.
|
|
*
|
|
* @throw Exception
|
|
*/
|
|
virtual IHeap *OpenHeap(const HeapId heapId, Timeout &timeout = Timeout::GetInfinite()) = 0;
|
|
|
|
/**
|
|
* @brief Open an existing process within the shared memory system.
|
|
*
|
|
* @param name the name of the process.
|
|
* @param timeout a Timeout object specifying how long to wait for the process to exist, in ms.
|
|
*
|
|
* @return An object providing an IProcess interface.
|
|
*
|
|
* @throw Exception.
|
|
*/
|
|
virtual IProcess *OpenProcess(const String &name, Timeout &timeout = Timeout::GetInfinite()) = 0;
|
|
|
|
/**
|
|
* @brief Open an existing process within the shared memory system.
|
|
*
|
|
* @param processId the id of the process within the system.
|
|
* @param timeout a Timeout object specifying how long to wait for the process to exist, in ms.
|
|
*
|
|
* @return An object providing an IProcess interface.
|
|
*
|
|
* @throw Exception.
|
|
*/
|
|
virtual IProcess *OpenProcess(const ProcessId processId, Timeout &timeout = Timeout::GetInfinite()) = 0;
|
|
|
|
/**
|
|
* @brief Get the name of the system.
|
|
*
|
|
* @return Reference to a string object containing the name of the system.
|
|
*/
|
|
virtual const String &GetSystemName() const = 0;
|
|
|
|
/**
|
|
* @brief Get the system heap.
|
|
*
|
|
* @return An object providing an IHeap interface.
|
|
*/
|
|
virtual IHeap *GetSystemHeap() const = 0;
|
|
|
|
/**
|
|
* @brief Get this process.
|
|
*
|
|
* @return An IProcess interface to this process.
|
|
*/
|
|
virtual IProcess *GetProcess() const = 0;
|
|
|
|
/**
|
|
* @brief Get system info.
|
|
*
|
|
* @return SystemInfo.
|
|
*
|
|
* @throw Exception.
|
|
*/
|
|
virtual SystemInfo GetSystemInfo() const = 0;
|
|
|
|
/**
|
|
* @brief Enumerate all opened processes.
|
|
*
|
|
* @param enumerator reference to an object providing an IProcessEnumerator interface to
|
|
* be called back on a process instance.
|
|
*/
|
|
virtual void EnumerateObjects(IProcessEnumerator &enumerator) = 0;
|
|
|
|
/**
|
|
* @brief Enumerate all opened endpoints.
|
|
*
|
|
* @param enumerator reference to an object providing an IEndPointEnumerator interface to
|
|
* be called back on an endpoint instance.
|
|
*/
|
|
virtual void EnumerateObjects(IEndPointEnumerator &enumerator) = 0;
|
|
|
|
/**
|
|
* @brief Enumerate all opened heaps.
|
|
*
|
|
* @param enumerator reference to an object providing an IHeapEnumerator interface to
|
|
* be called back on a process instance.
|
|
*/
|
|
virtual void EnumerateObjects(IHeapEnumerator &enumerator) = 0;
|
|
|
|
/**
|
|
* @brief Get the next processor id for setting a thread's affinity.
|
|
*
|
|
* The system maintains an atomic system-wide cyclic processor id that can be used for setting a thread's affinity.
|
|
* This function is mainly intended to be used by the ManagedEndPoint::Settings::m_shouldAllocateThreadAffinity setting
|
|
* and should be used with care beyond this.
|
|
*
|
|
* @return Processor id.
|
|
*/
|
|
virtual uint16_t GetNextAffinityProcessorId() const = 0;
|
|
};
|
|
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
inline ISystem::~ISystem()
|
|
{
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
inline ISystem::IProcessEnumerator::~IProcessEnumerator()
|
|
{
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
inline ISystem::IEndPointEnumerator::~IEndPointEnumerator()
|
|
{
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
inline ISystem::IHeapEnumerator::~IHeapEnumerator()
|
|
{
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
namespace GenericMessages
|
|
{
|
|
|
|
/**
|
|
* @brief Specialization of SystemInfo GenericMessage serialization.
|
|
*/
|
|
template<>
|
|
class ObjectSerializeForwarder<ISystem::SystemInfo>
|
|
{
|
|
public:
|
|
static StatusCode Serialize(MessageBuilder &messageBuilder, const ISystem::SystemInfo &systemInfo)
|
|
{
|
|
return systemInfo.Serialize2(messageBuilder);
|
|
}
|
|
|
|
static StatusCode Deserialize(MessageValidator &messageValidator, ISystem::SystemInfo &systemInfo)
|
|
{
|
|
return systemInfo.Deserialize2(messageValidator);
|
|
}
|
|
};
|
|
|
|
} // namespace GenericMessages
|
|
|
|
} // namespace Activ
|
|
|
|
#endif // (!defined ACTIV_FRAMEWORK_ISYSTEM_H)
|