diff --git a/framework/include/fwk_module.h b/framework/include/fwk_module.h index a8de0ba3aee206fcd8cfebf6c3066d684bc240a8..fc66b258de84f8ddc1c3d187d0c84d49c56bf1ae 100644 --- a/framework/include/fwk_module.h +++ b/framework/include/fwk_module.h @@ -395,6 +395,16 @@ bool fwk_module_is_valid_notification_id(fwk_id_t id); */ int fwk_module_get_element_count(fwk_id_t module_id); +/*! + * \brief Get the number of sub-elements within an element. + * + * \param element_id Identifier of the element. + * + * \retval FWK_E_PARAM The identifier of the element is invalid. + * \return Number of sub-elements. + */ +int fwk_module_get_sub_element_count(fwk_id_t element_id); + /*! * \brief Get the name of a module or element. * diff --git a/framework/src/fwk_module.c b/framework/src/fwk_module.c index aaad8efb90eb7348e45f496efbeb7f060b538e81..8f695842ac01ad450c963aa11466e45e5195f1cf 100644 --- a/framework/src/fwk_module.c +++ b/framework/src/fwk_module.c @@ -587,6 +587,14 @@ int fwk_module_get_element_count(fwk_id_t id) return FWK_E_PARAM; } +int fwk_module_get_sub_element_count(fwk_id_t element_id) +{ + if (fwk_module_is_valid_element_id(element_id)) + return __fwk_module_get_element_ctx(element_id)->sub_element_count; + else + return FWK_E_PARAM; +} + const char *fwk_module_get_name(fwk_id_t id) { if (fwk_module_is_valid_element_id(id)) diff --git a/framework/test/test_fwk_module.c b/framework/test/test_fwk_module.c index e3d932af9332c1292f0d972db3fcc99294a7da65..8322ba5169b4d06683d7c23e8a0a3ae583e2b943 100644 --- a/framework/test/test_fwk_module.c +++ b/framework/test/test_fwk_module.c @@ -906,6 +906,28 @@ static void test_fwk_module_get_element_count(void) assert(element_count == FWK_E_PARAM); } +static void test_fwk_module_get_sub_element_count(void) +{ + int sub_element_count; + + /* Invalid element ID */ + sub_element_count = + fwk_module_get_sub_element_count(FWK_ID_ELEMENT(MODULE0_IDX, 0x05)); + assert(sub_element_count == FWK_E_PARAM); + + /* Valid module ID, but not an element */ + sub_element_count = fwk_module_get_sub_element_count(MODULE0_ID); + assert(sub_element_count == FWK_E_PARAM); + + /* Valid element ID with 0 sub-elements */ + sub_element_count = fwk_module_get_sub_element_count(ELEM1_ID); + assert(sub_element_count == 0); + + /* Valid element ID with 1 sub-element */ + sub_element_count = fwk_module_get_sub_element_count(ELEM0_ID); + assert(sub_element_count == 1); +} + static void test_fwk_module_get_name(void) { fwk_id_t id; @@ -1117,6 +1139,7 @@ static const struct fwk_test_case_desc test_case_table[] = { FWK_TEST_CASE(test_fwk_module_is_valid_event_id), FWK_TEST_CASE(test_fwk_module_is_valid_notification_id), FWK_TEST_CASE(test_fwk_module_get_element_count), + FWK_TEST_CASE(test_fwk_module_get_sub_element_count), FWK_TEST_CASE(test_fwk_module_get_name), FWK_TEST_CASE(test_fwk_module_get_data), FWK_TEST_CASE(test_fwk_module_check_call_failed),