3
0
mirror of https://git.kernel.org/pub/scm/network/wireless/iwd.git synced 2024-12-22 21:22:37 +01:00

client: Add COMMAND_FAMILY

This commit is contained in:
Tim Kourt 2017-04-13 09:56:12 -07:00 committed by Denis Kenzior
parent dcf2a0cae5
commit 6c2eae6999
2 changed files with 40 additions and 0 deletions

View File

@ -24,6 +24,7 @@
#include <config.h> #include <config.h>
#endif #endif
#include <stdio.h>
#include <ell/ell.h> #include <ell/ell.h>
#include "command.h" #include "command.h"
@ -187,13 +188,40 @@ void command_family_unregister(const struct command_family *family)
l_queue_remove(command_families, (void *) family); l_queue_remove(command_families, (void *) family);
} }
extern struct command_family_desc __start___command[];
extern struct command_family_desc __stop___command[];
void command_init(void) void command_init(void)
{ {
struct command_family_desc *desc;
command_families = l_queue_new(); command_families = l_queue_new();
if (__start___command == NULL || __stop___command == NULL)
return;
for (desc = __start___command; desc < __stop___command; desc++) {
if (!desc->init)
continue;
desc->init();
}
} }
void command_exit(void) void command_exit(void)
{ {
struct command_family_desc *desc;
if (__start___command == NULL || __stop___command == NULL)
return;
for (desc = __start___command; desc < __stop___command; desc++) {
if (!desc->exit)
continue;
desc->exit();
}
l_queue_destroy(command_families, NULL); l_queue_destroy(command_families, NULL);
command_families = NULL; command_families = NULL;
} }

View File

@ -42,5 +42,17 @@ void command_process_prompt(char *prompt);
void command_family_register(const struct command_family *family); void command_family_register(const struct command_family *family);
void command_family_unregister(const struct command_family *family); void command_family_unregister(const struct command_family *family);
struct command_family_desc {
const char *name;
int (*init)(void);
void (*exit)(void);
} __attribute__((aligned(8)));
#define COMMAND_FAMILY(name, init, exit) \
static struct command_family_desc __command_family_ ## name \
__attribute__((used, section("__command"), aligned(8))) = {\
#name, init, exit \
}; \
void command_init(void); void command_init(void);
void command_exit(void); void command_exit(void);