Skip to content

Commit

Permalink
Display built-in services as part of show service classes command
Browse files Browse the repository at this point in the history
  • Loading branch information
sharky76 committed Mar 25, 2016
1 parent 1789bae commit 9849926
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
27 changes: 27 additions & 0 deletions builtin_service_manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,30 @@ bool builtin_service_manager_is_class_exists(const char* service_cl
return (NULL != service_var);
}

builtin_service_t* builtin_service_manager_get_class(const char* service_class)
{
uint32_t key = crc32(0, service_class, strlen(service_class));
variant_t* retVal = variant_hash_get(builtin_service_table, key);

return (NULL == retVal)? NULL : (builtin_service_t*)variant_get_ptr(retVal);
}

void builtin_service_manager_for_each_class(void (*visitor)(builtin_service_t*, void*), void* arg)
{
variant_hash_for_each_value(builtin_service_table, builtin_service_t*, visitor, arg)
}

void builtin_service_manager_for_each_method(const char* service_class, void (*visitor)(service_method_t*, void*), void* arg)
{
builtin_service_t* service = builtin_service_manager_get_class(service_class);

if(NULL != service)
{
stack_for_each(service->service_methods, method_variant)
{
service_method_t* method = (service_method_t*)variant_get_ptr(method_variant);
visitor(method, arg);
}
}
}

3 changes: 3 additions & 0 deletions builtin_service_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,7 @@
void builtin_service_manager_init();
service_method_t* builtin_service_manager_get_method(const char* service_class, const char* method_name);
bool builtin_service_manager_is_class_exists(const char* service_class);
builtin_service_t* builtin_service_manager_get_class(const char* service_class);
void builtin_service_manager_for_each_class(void (*visitor)(builtin_service_t*, void*), void* arg);
void builtin_service_manager_for_each_method(const char* service_class, void (*visitor)(service_method_t*, void*), void* arg);

13 changes: 13 additions & 0 deletions cli_service.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "cli_service.h"
#include "service_manager.h"
#include "builtin_service_manager.h"
#include "vty.h"

cli_node_t* service_node;
Expand All @@ -13,6 +14,8 @@ bool cmd_show_service_methods(vty_t* vty, variant_stack_t* params);
bool cmd_show_service_config(vty_t* vty, variant_stack_t* params);

void show_service_helper(service_t* service, void* arg);
void show_builtin_service_helper(builtin_service_t* service, void* arg);

void show_service_method_helper(service_method_t* method, void* arg);
void show_service_config_helper(service_t* service, void* arg);

Expand Down Expand Up @@ -67,12 +70,15 @@ bool cmd_list_service_classes(vty_t* vty, variant_stack_t* params)
{
vty_write(vty, "%-20s%s\n", "Name", "Description");
service_manager_for_each_class(show_service_helper, vty);
builtin_service_manager_for_each_class(show_builtin_service_helper, vty);
}

bool cmd_show_service_methods(vty_t* vty, variant_stack_t* params)
{
vty_write(vty, "%-20s%s\n", "Name", "Description");

service_manager_for_each_method(variant_get_string(stack_peek_at(params, 3)), show_service_method_helper, vty);
builtin_service_manager_for_each_method(variant_get_string(stack_peek_at(params, 3)), show_service_method_helper, vty);
}

bool cmd_show_service_config(vty_t* vty, variant_stack_t* params)
Expand All @@ -87,6 +93,13 @@ void show_service_helper(service_t* service, void* arg)
vty_write(vty, "%-20s%s\n", service->service_name, service->description);
}

void show_builtin_service_helper(builtin_service_t* service, void* arg)
{
vty_t* vty = (vty_t*)arg;

vty_write(vty, "%-20s%s\n", service->service_name, service->description);
}

void show_service_method_helper(service_method_t* method, void* arg)
{
vty_t* vty = (vty_t*)arg;
Expand Down

0 comments on commit 9849926

Please sign in to comment.