194 lines
4.6 KiB
C++
194 lines
4.6 KiB
C++
/**
|
|
* @file include/ActivMiddleware/ActivFramework/ServiceId.h
|
|
*
|
|
* @brief Header file for ServiceId.
|
|
*/
|
|
|
|
#if (!defined ACTIV_FRAMEWORK_SERVICE_ID_H)
|
|
#define ACTIV_FRAMEWORK_SERVICE_ID_H
|
|
|
|
#include "ActivMiddleware/ActivFramework/External.h"
|
|
|
|
#include "ActivMiddleware/ActivBase/MessageBuilder.h"
|
|
#include "ActivMiddleware/ActivBase/MessageValidator.h"
|
|
|
|
//! Activ namespace.
|
|
namespace Activ
|
|
{
|
|
|
|
/**
|
|
* @brief Service id class.
|
|
*
|
|
* ServiceId uniquely identifies a particular type of service.
|
|
*/
|
|
class ServiceId
|
|
{
|
|
public:
|
|
class Serializer;
|
|
|
|
//! Default constructor.
|
|
ServiceId();
|
|
|
|
/**
|
|
* @brief Constructor.
|
|
*
|
|
* @param id service id in c-string form.
|
|
*/
|
|
ServiceId(const char * const id);
|
|
|
|
/**
|
|
* @brief Constructor.
|
|
*
|
|
* @param id service id in string form.
|
|
*/
|
|
ServiceId(const String &id);
|
|
|
|
/**
|
|
* @brief Set the service id.
|
|
*
|
|
* @param id service id in string form.
|
|
*/
|
|
void Set(const String &id);
|
|
|
|
//! Get service id in string form.
|
|
const String &ToString() const;
|
|
|
|
//! Clear down.
|
|
void Clear();
|
|
|
|
/**
|
|
* @brief Equality operator.
|
|
*
|
|
* @param rhs to compare with.
|
|
*
|
|
* @return Boolean.
|
|
*/
|
|
bool operator==(const ServiceId &rhs) const;
|
|
|
|
/**
|
|
* @brief Inequality operator.
|
|
*
|
|
* @param rhs to compare with.
|
|
*
|
|
* @return Boolean.
|
|
*/
|
|
bool operator!=(const ServiceId &rhs) const;
|
|
|
|
/**
|
|
* @brief Less than operator.
|
|
*
|
|
* @param rhs to compare with.
|
|
*
|
|
* @return Boolean.
|
|
*/
|
|
bool operator<(const ServiceId &rhs) const;
|
|
|
|
/**
|
|
* @brief Serialize.
|
|
*
|
|
* @param messageBuilder
|
|
*
|
|
* @return STATUS_CODE_SUCCESS or an error status.
|
|
*/
|
|
StatusCode Serialize(MessageBuilder &messageBuilder) const;
|
|
|
|
/**
|
|
* @brief Deserialize.
|
|
*
|
|
* @param messageValidator
|
|
*
|
|
* @return STATUS_CODE_SUCCESS or an error status.
|
|
*/
|
|
StatusCode Deserialize(MessageValidator &messageValidator);
|
|
|
|
private:
|
|
String m_id;
|
|
};
|
|
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
inline ServiceId::ServiceId()
|
|
{
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
inline ServiceId::ServiceId(const char * const id) :
|
|
m_id(id)
|
|
{
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
inline ServiceId::ServiceId(const String &id) :
|
|
m_id(id)
|
|
{
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
inline void ServiceId::Set(const String &id)
|
|
{
|
|
m_id = id;
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
inline const String &ServiceId::ToString() const
|
|
{
|
|
return m_id;
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
inline void ServiceId::Clear()
|
|
{
|
|
m_id.clear();
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
inline bool ServiceId::operator==(const ServiceId &rhs) const
|
|
{
|
|
return m_id == rhs.m_id;
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
inline bool ServiceId::operator!=(const ServiceId &rhs) const
|
|
{
|
|
return m_id != rhs.m_id;
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
inline bool ServiceId::operator<(const ServiceId &rhs) const
|
|
{
|
|
return m_id < rhs.m_id;
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
inline StatusCode ServiceId::Serialize(MessageBuilder &messageBuilder) const
|
|
{
|
|
// NB! We can't convert to GenericMessages as it is already remoted in this format.
|
|
// Unlikely it's ever going to change from just being a string so no worries.
|
|
ACTIV_RETURN_RESULT_IF_UNLIKELY(STATUS_CODE_SUCCESS, !=, messageBuilder.Append(m_id));
|
|
|
|
return STATUS_CODE_SUCCESS;
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
inline StatusCode ServiceId::Deserialize(MessageValidator &messageValidator)
|
|
{
|
|
ACTIV_RETURN_RESULT_IF_UNLIKELY(STATUS_CODE_SUCCESS, !=, messageValidator.ValidateString(m_id));
|
|
|
|
return STATUS_CODE_SUCCESS;
|
|
}
|
|
|
|
} // namespace Activ
|
|
|
|
#endif // (!defined ACTIV_FRAMEWORK_SERVICE_ID_H)
|