46#define MOD_NAME "[module] "
51 memset(module_data, 0,
sizeof(
struct module));
53 pthread_mutexattr_t attr;
54 ret |= pthread_mutexattr_init(&attr);
55 ret |= pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
56 ret |= pthread_mutex_init(&module_data->
lock, &attr);
58 ret |= pthread_mutexattr_destroy(&attr);
59 assert(ret == 0 &&
"Unable to create mutex or set attributes");
72 pthread_mutex_lock(
lock);
79 pthread_mutex_unlock(
lock);
114 memcpy(&tmp, module_data,
sizeof(
struct module));
120 module_data->
deleter(module_data);
137 fprintf(stderr,
"Warning: Message queue not empty!\n");
155 pthread_mutex_destroy(&tmp.
lock);
192 if(strlen(buf) > 0) {
193 strncat(buf,
".", buflen - strlen(buf) - 1);
196 assert(node_name != NULL);
198 strncat(buf, node_name, buflen - strlen(buf) - 1);
229 assert(child_name != NULL);
230 if(strcasecmp(child_name, node_name) == 0) {
231 if (id_name != NULL) {
232 if (child->
name && strcmp(child->
name, id_name) == 0) {
236 }
else if (id_num-- == 0) {
252 if (strchr(node_str,
'[') && (strchr(node_str,
']') > strchr(node_str,
'['))) {
253 char *
item = strchr(node_str,
'[') + 1;
254 *strchr(node_str,
'[') =
'\0';
255 *strchr(
item,
']') =
'\0';
256 if (isdigit(
item[0])) {
266 assert(root != NULL);
267 assert(const_path != NULL);
269 struct module *receiver = root;
271 char *
item, *save_ptr;
275 tmp = path = strdup(const_path);
276 assert(path != NULL);
277 while ((
item = strtok_r(path,
".", &save_ptr))) {
278 struct module *old_receiver = receiver;
302 struct module *receiver = node;
304 char *
item, *save_ptr = NULL;
306 assert(node != NULL);
308 tmp = path = strdup(const_path);
309 assert(path != NULL);
310 if ((
item = strtok_r(path,
".", &save_ptr))) {
312 char *id_name = NULL;
334 for(
int i = 0; i < indent; ++i)
351 while (node != NULL) {
380 if (child->
cls != mod->
cls) {
388 if (our_index == 0) {
393 _Thread_local
static char name[128];
395 int ret = snprintf(
name,
sizeof name,
"%s[%d]", cls_name, our_index);
396 assert((
unsigned)ret <
sizeof name);
414 if (
sizeof(buf) + 1 +
sizeof(cur_name) >= buflen) {
418 if (strlen(buf) > 0) {
419 memmove(buf + strlen(cur_name) + 1, buf, strlen(buf) + 1);
420 buf[strlen(cur_name)] =
'.';
422 buf[strlen(cur_name)] =
'\0';
424 memcpy(buf, cur_name, strlen(cur_name));
void log_msg(int level, const char *format,...)
#define LOG_LEVEL_VERBOSE
#define LOG_LEVEL_WARNING
less severe errors
void module_init_default(struct module *module_data)
void module_register(struct module *module_data, struct module *parent)
void dump_tree(struct module *root_node, int indent)
bool module_get_path_str(struct module *mod, char *buf, size_t buflen)
struct module * get_module(struct module *root, const char *const_path)
void dump_parents(struct module *node)
void module_done(struct module *module_data)
const char * module_class_name(enum module_class cls)
struct module * get_matching_child(struct module *node, const char *const_path)
struct module * get_root_module(struct module *node)
void append_message_path(char *buf, int buflen, const enum module_class *modules)
struct module * get_parent_module(struct module *node)
@ MODULE_CLASS_KEYCONTROL
void simple_linked_list_append(struct simple_linked_list *l, void *data)
void * simple_linked_list_it_next(void **i)
bool simple_linked_list_remove(struct simple_linked_list *l, void *item)
int simple_linked_list_size(struct simple_linked_list *l)
struct simple_linked_list * simple_linked_list_init(void)
void simple_linked_list_destroy(struct simple_linked_list *l)
void simple_linked_list_it_destroy(void *i)
Should be used when it != NULL, eg. when leaving the loop before the end.
void * simple_linked_list_pop(struct simple_linked_list *l)
void * simple_linked_list_it_init(struct simple_linked_list *l)
void free_message(struct message *msg, struct response *r)
void free_message_for_child(void *m, struct response *r)
struct message * check_message(struct module *mod)
void module_check_undelivered_messages(struct module *node)
Sends message with waiting for response.
static void get_receiver_index(char *node_str, int *index, char **name)
static const char * module_class_name_pairs[]
static void module_mutex_lock(pthread_mutex_t *lock)
static const char * get_module_identifier(struct module *mod)
static struct module * find_child(struct module *node, const char *node_name, int id_num, const char *id_name)
static void module_mutex_unlock(pthread_mutex_t *lock)
struct simple_linked_list * msg_queue
pthread_mutex_t msg_queue_lock
struct simple_linked_list * children
struct simple_linked_list * msg_queue_children
messages for childern that were not delivered