rte_service_get_by_id;
rte_service_get_by_name;
rte_service_get_count;
+ rte_service_get_name;
rte_service_lcore_add;
rte_service_lcore_count;
rte_service_lcore_count_services;
#include <rte_lcore.h>
-/* forward declaration only. Definition in rte_service_private.h */
-struct rte_service_spec;
-
#define RTE_SERVICE_NAME_MAX 32
/* Capabilities of a service.
*/
uint32_t rte_service_get_count(void);
-
/**
* @warning
* @b EXPERIMENTAL: this API may change without prior notice
*
- * Return the specification of a service by integer id.
- *
- * This function provides the specification of a service. This can be used by
- * the application to understand what the service represents. The service
- * must not be modified by the application directly, only passed to the various
- * rte_service_* functions.
- *
- * @param id The integer id of the service to retrieve
- * @retval non-zero A valid pointer to the service_spec
- * @retval NULL Invalid *id* provided.
- */
-struct rte_service_spec *rte_service_get_by_id(uint32_t id);
-
-/**
- * @warning
- * @b EXPERIMENTAL: this API may change without prior notice
+ * Return the id of a service by name.
*
- * Return the specification of a service by name.
+ * This function provides the id of the service using the service name as
+ * lookup key. The service id is to be passed to other functions in the
+ * rte_service_* API.
*
- * This function provides the specification of a service using the service name
- * as lookup key. This can be used by the application to understand what the
- * service represents. The service must not be modified by the application
- * directly, only passed to the various rte_service_* functions.
+ * Example usage:
+ * @code
+ * uint32_t service_id;
+ * int32_t ret = rte_service_get_by_name("service_X", &service_id);
+ * if (ret) {
+ * // handle error
+ * }
+ * @endcode
*
* @param name The name of the service to retrieve
- * @retval non-zero A valid pointer to the service_spec
- * @retval NULL Invalid *name* provided.
+ * @param[out] service_id A pointer to a uint32_t, to be filled in with the id.
+ * @retval 0 Success. The service id is provided in *service_id*.
+ * @retval -EINVAL Null *service_id* pointer provided
+ * @retval -ENODEV No such service registered
*/
-struct rte_service_spec *rte_service_get_by_name(const char *name);
+int32_t rte_service_get_by_name(const char *name, uint32_t *service_id);
/**
* @warning
return rte_service_count;
}
-struct rte_service_spec *
-rte_service_get_by_id(uint32_t id)
+int32_t rte_service_get_by_name(const char *name, uint32_t *service_id)
{
- struct rte_service_spec *service = NULL;
- if (id < rte_service_count)
- service = (struct rte_service_spec *)&rte_services[id];
-
- return service;
-}
+ if (!service_id)
+ return -EINVAL;
-struct rte_service_spec *rte_service_get_by_name(const char *name)
-{
- struct rte_service_spec *service = NULL;
int i;
for (i = 0; i < RTE_SERVICE_NUM_MAX; i++) {
if (service_valid(i) &&
strcmp(name, rte_services[i].spec.name) == 0) {
- service = (struct rte_service_spec *)&rte_services[i];
- break;
+ *service_id = i;
+ return 0;
}
}
- return service;
+ return -ENODEV;
}
const char *
rte_service_lcore_start(ids[i]);
for (i = 0; i < count; i++) {
- struct rte_service_spec *s = rte_service_get_by_id(i);
- if (!s)
- return -EINVAL;
-
/* do 1:1 core mapping here, with each service getting
* assigned a single core by default. Adding multiple services
* should multiplex to a single core, or 1:1 if there are the
rte_service_get_by_id;
rte_service_get_by_name;
rte_service_get_count;
+ rte_service_get_name;
rte_service_lcore_add;
rte_service_lcore_count;
rte_service_lcore_count_services;
{
unregister_all();
- /* ensure with no services registered returns NULL */
- TEST_ASSERT_EQUAL(0, rte_service_get_by_name(DUMMY_SERVICE_NAME),
- "Service get by name should return NULL");
+ uint32_t sid;
+ TEST_ASSERT_EQUAL(-ENODEV,
+ rte_service_get_by_name(DUMMY_SERVICE_NAME, &sid),
+ "get by name with invalid name should return -ENODEV");
+ TEST_ASSERT_EQUAL(-EINVAL,
+ rte_service_get_by_name(DUMMY_SERVICE_NAME, 0x0),
+ "get by name with NULL ptr should return -ENODEV");
/* register service */
struct rte_service_spec service;
TEST_ASSERT_EQUAL(0, rte_service_component_register(&service, NULL),
"Failed to register valid service");
- /* ensure with dummy services registered returns same ptr as ID */
- struct rte_service_spec *s_by_id = rte_service_get_by_id(0);
- TEST_ASSERT_EQUAL(s_by_id, rte_service_get_by_name(DUMMY_SERVICE_NAME),
- "Service get_by_name should equal get_by_id()");
+ /* we unregistered all service, now registering 1, should be id 0 */
+ uint32_t service_id_as_expected = 0;
+ TEST_ASSERT_EQUAL(0, rte_service_get_by_name(DUMMY_SERVICE_NAME, &sid),
+ "Service get_by_name should return 0 on valid inputs");
+ TEST_ASSERT_EQUAL(service_id_as_expected, sid,
+ "Service get_by_name should equal expected id");
unregister_all();
/* ensure after unregister, get_by_name returns NULL */
- TEST_ASSERT_EQUAL(0, rte_service_get_by_name(DUMMY_SERVICE_NAME),
- "get by name should return NULL after unregister");
+ TEST_ASSERT_EQUAL(-ENODEV,
+ rte_service_get_by_name(DUMMY_SERVICE_NAME, &sid),
+ "get by name should return -ENODEV after unregister");
return TEST_SUCCESS;
}
static int
service_name(void)
{
- struct rte_service_spec *service = rte_service_get_by_id(0);
-
- int equal = strcmp(service->name, DUMMY_SERVICE_NAME);
+ const char *name = rte_service_get_name(0);
+ int equal = strcmp(name, DUMMY_SERVICE_NAME);
TEST_ASSERT_EQUAL(0, equal, "Error: Service name not correct");
return unregister_all();