Let dds_create_participant determine domain id if config specifies "any" (new default)

Note: DDS_DOMAIN_DEFAULT with a configuration specifying "any" results in domain 0.
Signed-off-by: Erik Boasson <eb@ilities.com>
This commit is contained in:
Erik Boasson 2018-10-14 13:55:56 +08:00
parent 675fbfe013
commit bb92294f4e
10 changed files with 78 additions and 44 deletions

View file

@ -32,7 +32,7 @@ dds__check_domain(
*-# Returns 0 on success or a non-zero error status
**/
dds_return_t
dds_init(void);
dds_init(dds_domainid_t domain);
/* Finalization function, called from main */

View file

@ -137,8 +137,8 @@ dds__create_builtin_participant(
}
pp->m_entity.m_guid = guid;
pp->m_entity.m_domain = dds_domain_create (config.domainId);
pp->m_entity.m_domainid = config.domainId;
pp->m_entity.m_domain = dds_domain_create (config.domainId.value);
pp->m_entity.m_domainid = config.domainId.value;
pp->m_entity.m_deriver.delete = dds__delete_builtin_participant;
fail:

View file

@ -41,7 +41,7 @@ dds_globals dds_global = { .m_default_domain = DDS_DOMAIN_DEFAULT };
static struct cfgst * dds_cfgst = NULL;
dds_return_t
dds_init(void)
dds_init(dds_domainid_t domain)
{
dds_return_t ret = DDS_RETCODE_OK;
const char * uri;
@ -86,9 +86,29 @@ dds_init(void)
ret = DDS_ERRNO(DDS_RETCODE_ERROR, "Failed to parse configuration XML file %s", uri);
goto fail_config;
}
/* if a domain id was explicitly given, check & fix up the configuration */
if (domain != DDS_DOMAIN_DEFAULT)
{
if (domain < 0 || domain > 230)
{
ret = DDS_ERRNO(DDS_RETCODE_ERROR, "requested domain id %d is out of range", domain);
goto fail_config;
}
else if (config.domainId.isdefault)
{
config.domainId.value = domain;
}
else if (domain != config.domainId.value)
{
ret = DDS_ERRNO(DDS_RETCODE_ERROR, "requested domain id %d is inconsistent with configured value %d", domain, config.domainId.value);
goto fail_config;
}
}
/* The config.domainId can change internally in DDSI. So, remember what the
* main configured domain id is. */
dds_global.m_default_domain = config.domainId;
dds_global.m_default_domain = config.domainId.value;
dds__builtin_init();

View file

@ -148,7 +148,7 @@ dds_create_participant(
bool asleep;
/* Make sure DDS instance is initialized. */
ret = dds_init();
ret = dds_init(domain);
if (ret != DDS_RETCODE_OK) {
e = (dds_entity_t)ret;
goto fail_dds_init;

View file

@ -45,13 +45,13 @@ Test(ddsc_participant, create_with_no_conf_no_env) {
dds_entity_t participant, participant2, participant3;
dds_return_t status;
dds_domainid_t domain_id;
dds_domainid_t valid_domain=0;
dds_domainid_t valid_domain=3;
const char * env_uri = os_getenv(DDSC_PROJECT_NAME_NOSPACE_CAPS"_URI");
cr_assert_eq(env_uri, NULL, DDSC_PROJECT_NAME_NOSPACE_CAPS"_URI must be NULL");
//invalid domain
participant = dds_create_participant (1, NULL, NULL);
participant = dds_create_participant (-2, NULL, NULL);
cr_assert_lt(participant, 0, "Error must be received for invalid domain value");
//valid specific domain value