diff --git a/src/core/ddsc/include/dds/dds.h b/src/core/ddsc/include/dds/dds.h index d6380a68d5..908ac71feb 100644 --- a/src/core/ddsc/include/dds/dds.h +++ b/src/core/ddsc/include/dds/dds.h @@ -1129,6 +1129,25 @@ dds_return_t dds_set_domain_lifecycle ( const dds_entity_t domain, const enum dds_domain_lifecycle state); +/// @brief Get the status of the domain lifecycle +/// +/// The domain life-cycle state represents the operational phase of the domain. Currently +/// the supported states are: +/// +/// * Initialisation +/// * Operational +/// +/// @param[in] domain The domain entity for which to get the life-cycle state for. Only accepts `DDS_CYCLONEDDS_HANDLE`. +/// @param[out] state The life-cycle state for the provided domain. +/// @return a dds_retcode_t indicating success or failure +/// @retval DDS_RETCODE_SUCCESS The state was successfully retrieved. +/// @retval DDS_RETCODE_BAD_PARAMETER An incorrect domain provided. Only supports `DDS_CYCLONEDDS_HANDLE` currently. +/// @retval DDS_RETCODE_PRECONDITION_NOT_MET An invalid pointer was provided for getting the state. +DDS_EXPORT +dds_return_t dds_get_domain_lifecycle( + const dds_entity_t domain, + enum dds_domain_lifecycle *state); + /** * @brief Get entity parent. * @ingroup entity diff --git a/src/core/ddsc/src/dds_domain.c b/src/core/ddsc/src/dds_domain.c index 2c55a424da..a4de758a7a 100644 --- a/src/core/ddsc/src/dds_domain.c +++ b/src/core/ddsc/src/dds_domain.c @@ -11,6 +11,7 @@ #include #include "dds/features.h" +#include "dds/ddsrt/cdtors.h" #include "dds/ddsrt/process.h" #include "dds/ddsrt/heap.h" #include "dds/ddsrt/hopscotch.h" @@ -440,6 +441,54 @@ void dds_write_set_batch (bool enable) dds_entity_unpin_and_drop_ref (&dds_global.m_entity); } +dds_return_t dds_set_domain_lifecycle(const dds_entity_t domain, const enum dds_domain_lifecycle state) { + dds_return_t result = DDS_RETCODE_ERROR; + if (dds_init () < 0) { + result = DDS_RETCODE_PRECONDITION_NOT_MET; + } else { + if (DDS_CYCLONEDDS_HANDLE == domain) { + switch (state) { + case DDS_DOMAIN_LIFECYCLE_OPERATIONAL: + // Only initialisation->operational is valid + if (LIFECYCLE_STATE == DDS_DOMAIN_LIFECYCLE_INITIALISATION) { + result = ddsrt_lock(); + if (result == DDS_RETCODE_OK) { + LIFECYCLE_STATE = state; + } // else result is the error from ddsrt_lock() + } else { + result = DDS_RETCODE_PRECONDITION_NOT_MET; + } + break; + case DDS_DOMAIN_LIFECYCLE_INITIALISATION: + result = DDS_RETCODE_PRECONDITION_NOT_MET; + break; + default: + result = DDS_RETCODE_ERROR; + break; + } + } else { + result = DDS_RETCODE_ILLEGAL_OPERATION; + } + } + return result; +} + +dds_return_t dds_get_domain_lifecycle(const dds_entity_t domain, enum dds_domain_lifecycle *state) { + dds_return_t result = DDS_RETCODE_OK; + if (NULL == state) { + result = DDS_RETCODE_PRECONDITION_NOT_MET; + } else { + if (DDS_CYCLONEDDS_HANDLE == domain) { + *state = LIFECYCLE_STATE; + } else { + result = DDS_RETCODE_BAD_PARAMETER; + } + } + return result; +} + + + #ifdef DDS_HAS_TYPE_DISCOVERY dds_return_t dds_get_typeobj (dds_entity_t entity, const dds_typeid_t *type_id, dds_duration_t timeout, dds_typeobj_t **type_obj) @@ -490,37 +539,4 @@ dds_return_t dds_free_typeobj (dds_typeobj_t *type_obj) (void) type_obj; return DDS_RETCODE_UNSUPPORTED; } - -dds_return_t dds_set_domain_lifecycle(const dds_entity_t domain, const enum dds_domain_lifecycle state) { - dds_return_t result = DDS_RETCODE_ERROR; - if (dds_init () < 0) { - result = DDS_RETCODE_PRECONDITION_NOT_MET; - } else { - if (DDS_CYCLONEDDS_HANDLE == domain) { - switch (state) { - case DDS_DOMAIN_LIFECYCLE_OPERATIONAL: - // Only initialisation->operational is valid - if (LIFECYCLE_STATE == DDS_DOMAIN_LIFECYCLE_INITIALISATION) { - result = ddsrt_lock(); - if (result == DDS_RETCODE_SUCCESS) { - LIFECYCLE_STATE = state; - } // else result is the error from ddsrt_lock() - } else { - result = DDS_RETCODE_PRECONDITION_NOT_MET; - } - break; - case DDS_DOMAIN_LIFECYCLE_INITIALISATION: - result = DDS_RETCODE_PRECONDITION_NOT_MET; - break; - default: - result = DDS_RETCODE_ERROR; - break; - } - } else { - result = DDS_RETCODE_ILLEGAL_OPEATION; - } - } - return result; -} - #endif /* DDS_HAS_TYPE_DISCOVERY */