Skip to content

Commit

Permalink
introduce dds_get_domain_lifecycle
Browse files Browse the repository at this point in the history
Includes a fix for accidental placement of implementation within an
 #ifdef causing havok.
  • Loading branch information
poetinger committed Nov 15, 2023
1 parent 03aa97a commit 2d5a319
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 33 deletions.
19 changes: 19 additions & 0 deletions src/core/ddsc/include/dds/dds.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
82 changes: 49 additions & 33 deletions src/core/ddsc/src/dds_domain.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <string.h>

#include "dds/features.h"
#include "dds/ddsrt/cdtors.h"
#include "dds/ddsrt/process.h"
#include "dds/ddsrt/heap.h"
#include "dds/ddsrt/hopscotch.h"
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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 */

0 comments on commit 2d5a319

Please sign in to comment.