service: use id in get by name function
This commit reworks the service_get_by_name() function to accept an integer, and removes the service_get_by_id() function. All functions now accept an integer argument representing the service, so it is no longer required to expose the service_spec pointers to the application. Signed-off-by: Harry van Haaren <harry.van.haaren@intel.com> Acked-by: Pavan Nikhilesh <pbhagavatula@caviumnetworks.com>
This commit is contained in:
parent
891f07e54e
commit
8edc9aaaf2
@ -218,6 +218,7 @@ EXPERIMENTAL {
|
|||||||
rte_service_get_by_id;
|
rte_service_get_by_id;
|
||||||
rte_service_get_by_name;
|
rte_service_get_by_name;
|
||||||
rte_service_get_count;
|
rte_service_get_count;
|
||||||
|
rte_service_get_name;
|
||||||
rte_service_lcore_add;
|
rte_service_lcore_add;
|
||||||
rte_service_lcore_count;
|
rte_service_lcore_count;
|
||||||
rte_service_lcore_count_services;
|
rte_service_lcore_count_services;
|
||||||
|
@ -61,9 +61,6 @@ extern "C" {
|
|||||||
|
|
||||||
#include <rte_lcore.h>
|
#include <rte_lcore.h>
|
||||||
|
|
||||||
/* forward declaration only. Definition in rte_service_private.h */
|
|
||||||
struct rte_service_spec;
|
|
||||||
|
|
||||||
#define RTE_SERVICE_NAME_MAX 32
|
#define RTE_SERVICE_NAME_MAX 32
|
||||||
|
|
||||||
/* Capabilities of a service.
|
/* Capabilities of a service.
|
||||||
@ -89,40 +86,32 @@ struct rte_service_spec;
|
|||||||
*/
|
*/
|
||||||
uint32_t rte_service_get_count(void);
|
uint32_t rte_service_get_count(void);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @warning
|
* @warning
|
||||||
* @b EXPERIMENTAL: this API may change without prior notice
|
* @b EXPERIMENTAL: this API may change without prior notice
|
||||||
*
|
*
|
||||||
* Return the specification of a service by integer id.
|
* Return the id of a service by name.
|
||||||
*
|
*
|
||||||
* This function provides the specification of a service. This can be used by
|
* This function provides the id of the service using the service name as
|
||||||
* the application to understand what the service represents. The service
|
* lookup key. The service id is to be passed to other functions in the
|
||||||
* must not be modified by the application directly, only passed to the various
|
* rte_service_* API.
|
||||||
* rte_service_* functions.
|
|
||||||
*
|
*
|
||||||
* @param id The integer id of the service to retrieve
|
* Example usage:
|
||||||
* @retval non-zero A valid pointer to the service_spec
|
* @code
|
||||||
* @retval NULL Invalid *id* provided.
|
* uint32_t service_id;
|
||||||
*/
|
* int32_t ret = rte_service_get_by_name("service_X", &service_id);
|
||||||
struct rte_service_spec *rte_service_get_by_id(uint32_t id);
|
* if (ret) {
|
||||||
|
* // handle error
|
||||||
/**
|
* }
|
||||||
* @warning
|
* @endcode
|
||||||
* @b EXPERIMENTAL: this API may change without prior notice
|
|
||||||
*
|
|
||||||
* Return the specification of a service by name.
|
|
||||||
*
|
|
||||||
* 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.
|
|
||||||
*
|
*
|
||||||
* @param name The name of the service to retrieve
|
* @param name The name of the service to retrieve
|
||||||
* @retval non-zero A valid pointer to the service_spec
|
* @param[out] service_id A pointer to a uint32_t, to be filled in with the id.
|
||||||
* @retval NULL Invalid *name* provided.
|
* @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
|
* @warning
|
||||||
|
@ -185,29 +185,21 @@ rte_service_get_count(void)
|
|||||||
return rte_service_count;
|
return rte_service_count;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct rte_service_spec *
|
int32_t rte_service_get_by_name(const char *name, uint32_t *service_id)
|
||||||
rte_service_get_by_id(uint32_t id)
|
|
||||||
{
|
{
|
||||||
struct rte_service_spec *service = NULL;
|
if (!service_id)
|
||||||
if (id < rte_service_count)
|
return -EINVAL;
|
||||||
service = (struct rte_service_spec *)&rte_services[id];
|
|
||||||
|
|
||||||
return service;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct rte_service_spec *rte_service_get_by_name(const char *name)
|
|
||||||
{
|
|
||||||
struct rte_service_spec *service = NULL;
|
|
||||||
int i;
|
int i;
|
||||||
for (i = 0; i < RTE_SERVICE_NUM_MAX; i++) {
|
for (i = 0; i < RTE_SERVICE_NUM_MAX; i++) {
|
||||||
if (service_valid(i) &&
|
if (service_valid(i) &&
|
||||||
strcmp(name, rte_services[i].spec.name) == 0) {
|
strcmp(name, rte_services[i].spec.name) == 0) {
|
||||||
service = (struct rte_service_spec *)&rte_services[i];
|
*service_id = i;
|
||||||
break;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return service;
|
return -ENODEV;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *
|
const char *
|
||||||
@ -420,10 +412,6 @@ rte_service_start_with_defaults(void)
|
|||||||
rte_service_lcore_start(ids[i]);
|
rte_service_lcore_start(ids[i]);
|
||||||
|
|
||||||
for (i = 0; i < count; 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
|
/* do 1:1 core mapping here, with each service getting
|
||||||
* assigned a single core by default. Adding multiple services
|
* assigned a single core by default. Adding multiple services
|
||||||
* should multiplex to a single core, or 1:1 if there are the
|
* should multiplex to a single core, or 1:1 if there are the
|
||||||
|
@ -223,6 +223,7 @@ EXPERIMENTAL {
|
|||||||
rte_service_get_by_id;
|
rte_service_get_by_id;
|
||||||
rte_service_get_by_name;
|
rte_service_get_by_name;
|
||||||
rte_service_get_count;
|
rte_service_get_count;
|
||||||
|
rte_service_get_name;
|
||||||
rte_service_lcore_add;
|
rte_service_lcore_add;
|
||||||
rte_service_lcore_count;
|
rte_service_lcore_count;
|
||||||
rte_service_lcore_count_services;
|
rte_service_lcore_count_services;
|
||||||
|
@ -178,9 +178,13 @@ service_get_by_name(void)
|
|||||||
{
|
{
|
||||||
unregister_all();
|
unregister_all();
|
||||||
|
|
||||||
/* ensure with no services registered returns NULL */
|
uint32_t sid;
|
||||||
TEST_ASSERT_EQUAL(0, rte_service_get_by_name(DUMMY_SERVICE_NAME),
|
TEST_ASSERT_EQUAL(-ENODEV,
|
||||||
"Service get by name should return NULL");
|
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 */
|
/* register service */
|
||||||
struct rte_service_spec service;
|
struct rte_service_spec service;
|
||||||
@ -196,16 +200,19 @@ service_get_by_name(void)
|
|||||||
TEST_ASSERT_EQUAL(0, rte_service_component_register(&service, NULL),
|
TEST_ASSERT_EQUAL(0, rte_service_component_register(&service, NULL),
|
||||||
"Failed to register valid service");
|
"Failed to register valid service");
|
||||||
|
|
||||||
/* ensure with dummy services registered returns same ptr as ID */
|
/* we unregistered all service, now registering 1, should be id 0 */
|
||||||
struct rte_service_spec *s_by_id = rte_service_get_by_id(0);
|
uint32_t service_id_as_expected = 0;
|
||||||
TEST_ASSERT_EQUAL(s_by_id, rte_service_get_by_name(DUMMY_SERVICE_NAME),
|
TEST_ASSERT_EQUAL(0, rte_service_get_by_name(DUMMY_SERVICE_NAME, &sid),
|
||||||
"Service get_by_name should equal get_by_id()");
|
"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();
|
unregister_all();
|
||||||
|
|
||||||
/* ensure after unregister, get_by_name returns NULL */
|
/* ensure after unregister, get_by_name returns NULL */
|
||||||
TEST_ASSERT_EQUAL(0, rte_service_get_by_name(DUMMY_SERVICE_NAME),
|
TEST_ASSERT_EQUAL(-ENODEV,
|
||||||
"get by name should return NULL after unregister");
|
rte_service_get_by_name(DUMMY_SERVICE_NAME, &sid),
|
||||||
|
"get by name should return -ENODEV after unregister");
|
||||||
|
|
||||||
return TEST_SUCCESS;
|
return TEST_SUCCESS;
|
||||||
}
|
}
|
||||||
@ -249,9 +256,8 @@ service_probe_capability(void)
|
|||||||
static int
|
static int
|
||||||
service_name(void)
|
service_name(void)
|
||||||
{
|
{
|
||||||
struct rte_service_spec *service = rte_service_get_by_id(0);
|
const char *name = rte_service_get_name(0);
|
||||||
|
int equal = strcmp(name, DUMMY_SERVICE_NAME);
|
||||||
int equal = strcmp(service->name, DUMMY_SERVICE_NAME);
|
|
||||||
TEST_ASSERT_EQUAL(0, equal, "Error: Service name not correct");
|
TEST_ASSERT_EQUAL(0, equal, "Error: Service name not correct");
|
||||||
|
|
||||||
return unregister_all();
|
return unregister_all();
|
||||||
|
Loading…
Reference in New Issue
Block a user