diff --git a/builtin_service_manager.c b/builtin_service_manager.c index 326005c..b98e54d 100644 --- a/builtin_service_manager.c +++ b/builtin_service_manager.c @@ -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); + } + } +} + diff --git a/builtin_service_manager.h b/builtin_service_manager.h index e5a7a3f..8b57b5e 100644 --- a/builtin_service_manager.h +++ b/builtin_service_manager.h @@ -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); diff --git a/cli_service.c b/cli_service.c index 9cc6de6..6a01ac0 100644 --- a/cli_service.c +++ b/cli_service.c @@ -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; @@ -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); @@ -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) @@ -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;