UltraGrid
UltraGrid Low-Latency High-Resolution Transmission System
Loading...
Searching...
No Matches
module.c File Reference
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include "debug.h"
#include "module.h"
#include "utils/list.h"
Include dependency graph for module.c:

Go to the source code of this file.

Macros

#define MOD_NAME   "[module] "
 

Functions

void append_message_path (char *buf, int buflen, const enum module_class *modules)
 
void dump_parents (struct module *node)
 
void dump_tree (struct module *root_node, int indent)
 
static struct module * find_child (struct module *node, const char *node_name, int id_num, const char *id_name)
 
struct module * get_matching_child (struct module *node, const char *const_path)
 
struct module * get_module (struct module *root, const char *const_path)
 
static const char * get_module_identifier (struct module *mod)
 
struct module * get_parent_module (struct module *node)
 
static void get_receiver_index (char *node_str, int *index, char **name)
 
struct module * get_root_module (struct module *node)
 
const char * module_class_name (enum module_class cls)
 
void module_done (struct module *module_data)
 
bool module_get_path_str (struct module *mod, char *buf, size_t buflen)
 
void module_init_default (struct module *module_data)
 
static void module_mutex_lock (pthread_mutex_t *lock)
 
static void module_mutex_unlock (pthread_mutex_t *lock)
 
void module_register (struct module *module_data, struct module *parent)
 

Variables

static const char * module_class_name_pairs []
 

Detailed Description

Author
Martin Pulec pulec.nosp@m.@ces.nosp@m.net.c.nosp@m.z

Definition in file module.c.

Macro Definition Documentation

◆ MOD_NAME

#define MOD_NAME   "[module] "

Definition at line 46 of file module.c.

Function Documentation

◆ find_child()

static struct module * find_child ( struct module * node,
const char * node_name,
int id_num,
const char * id_name )
static

id_num and id_name distinguish in case that the node has more child nodes with the same node_name (the same class). If id_name == NULL, id_num is used.

Definition at line 223 of file module.c.

225{
226 for(void *it = simple_linked_list_it_init(node->children); it != NULL; ) {
227 struct module *child = (struct module *) simple_linked_list_it_next(&it);
228 const char *child_name = module_class_name(child->cls);
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) {
234 return child;
235 }
236 } else if (id_num-- == 0) {
238 return child;
239 }
240 }
241 }
242 return NULL;
243}
const char * module_class_name(enum module_class cls)
Definition module.c:178
void * simple_linked_list_it_next(void **i)
Definition list.cpp:119
void simple_linked_list_it_destroy(void *i)
Should be used when it != NULL, eg. when leaving the loop before the end.
Definition list.cpp:139
void * simple_linked_list_it_init(struct simple_linked_list *l)
Definition list.cpp:108
char * name
Definition module.h:129
enum module_class cls
Definition module.h:115
struct simple_linked_list * children
Definition module.h:117

References module::children, module::cls, module_class_name(), module::name, simple_linked_list_it_destroy(), simple_linked_list_it_init(), and simple_linked_list_it_next().

Referenced by get_matching_child().

Here is the call graph for this function:

◆ get_module_identifier()

static const char * get_module_identifier ( struct module * mod)
static
Returns
module_class_name() if we are first child of our class
cls_name[idx] otherwise (idx > 0)

Definition at line 366 of file module.c.

367{
368 const char *cls_name = module_class_name(mod->cls);
369 struct module *parent = get_parent_module(mod);
370 if (parent == NULL) {
371 return cls_name;
372 }
373
375
376 int our_index = 0;
377 for (void *it = simple_linked_list_it_init(parent->children);
378 it != NULL;) {
379 struct module *child = simple_linked_list_it_next(&it);
380 if (child->cls != mod->cls) {
381 continue;
382 }
383 if (child == mod) { // found our node
384 break;
385 }
386 our_index += 1;
387 }
388 if (our_index == 0) {
390 return cls_name;
391 }
392 // append our index if >0
393 _Thread_local static char name[128];
394 name[sizeof name - 1] = '\0';
395 int ret = snprintf(name, sizeof name, "%s[%d]", cls_name, our_index);
396 assert((unsigned)ret < sizeof name);
397
399
400 return name;
401}
struct module * get_parent_module(struct module *node)
Definition module.c:214
static void module_mutex_lock(pthread_mutex_t *lock)
Definition module.c:69
static void module_mutex_unlock(pthread_mutex_t *lock)
Definition module.c:76
const char * parent
Definition settings.cpp:198
const char * name
Definition settings.cpp:193

References module::cls, get_parent_module(), module_class_name(), module_mutex_lock(), module_mutex_unlock(), name, parent, simple_linked_list_it_init(), and simple_linked_list_it_next().

Referenced by module_get_path_str().

Here is the call graph for this function:

◆ get_receiver_index()

static void get_receiver_index ( char * node_str,
int * index,
char ** name )
static

Parses path element, which might be either in form a single-word item (eg "display") or an array, either indexed by a number, in which case non-zero index will be returned or a module name (module::name member) which would be returned in name return value. Both indexing options are mutually exclusive.

Definition at line 251 of file module.c.

251 {
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])) {
257 *index = atoi(item);
258 } else {
259 *name = item;
260 }
261 }
262}
Definition hd-rum.c:27

References name.

Referenced by get_matching_child().

◆ module_mutex_lock()

static void module_mutex_lock ( pthread_mutex_t * lock)
static

Definition at line 69 of file module.c.

70{
71 MSG(DEBUG, "Locking lock %p\n", lock);
72 pthread_mutex_lock(lock);
73}
#define MSG(l, fmt,...)
Definition debug.h:96
#define DEBUG
Definition main.c:27

References DEBUG, and MSG.

Referenced by dump_tree(), get_module(), get_module_identifier(), module_done(), and module_register().

◆ module_mutex_unlock()

static void module_mutex_unlock ( pthread_mutex_t * lock)
static

Definition at line 76 of file module.c.

77{
78 MSG(DEBUG, "Unlocking lock %p\n", lock);
79 pthread_mutex_unlock(lock);
80}

References DEBUG, and MSG.

Referenced by dump_tree(), get_module(), get_module_identifier(), module_done(), and module_register().

Variable Documentation

◆ module_class_name_pairs

const char* module_class_name_pairs[]
static
Initial value:
= {
[MODULE_CLASS_ROOT] = "root",
[MODULE_CLASS_PORT] = "port",
[MODULE_CLASS_COMPRESS] = "compress",
[MODULE_CLASS_DATA] = "data",
[MODULE_CLASS_SENDER] = "sender",
[MODULE_CLASS_RECEIVER] = "receiver",
[MODULE_CLASS_TX] = "transmit",
[MODULE_CLASS_AUDIO] = "audio",
[MODULE_CLASS_CONTROL] = "control",
[MODULE_CLASS_CAPTURE] = "capture",
[MODULE_CLASS_FILTER] = "filter",
[MODULE_CLASS_DISPLAY] = "display",
[MODULE_CLASS_DECODER] = "decoder",
[MODULE_CLASS_EXPORTER] = "exporter",
[MODULE_CLASS_KEYCONTROL] = "keycontrol",
}
@ MODULE_CLASS_CONTROL
Definition module.h:91
@ MODULE_CLASS_DATA
Definition module.h:86
@ MODULE_CLASS_ROOT
Definition module.h:83
@ MODULE_CLASS_DISPLAY
Definition module.h:94
@ MODULE_CLASS_FILTER
Definition module.h:93
@ MODULE_CLASS_EXPORTER
Definition module.h:96
@ MODULE_CLASS_COMPRESS
Definition module.h:85
@ MODULE_CLASS_KEYCONTROL
Definition module.h:97
@ MODULE_CLASS_RECEIVER
Definition module.h:88
@ MODULE_CLASS_AUDIO
Definition module.h:90
@ MODULE_CLASS_CAPTURE
Definition module.h:92
@ MODULE_CLASS_DECODER
Definition module.h:95
@ MODULE_CLASS_TX
Definition module.h:89
@ MODULE_CLASS_SENDER
Definition module.h:87
@ MODULE_CLASS_PORT
Definition module.h:84

Definition at line 160 of file module.c.

160 {
161 [MODULE_CLASS_ROOT] = "root",
162 [MODULE_CLASS_PORT] = "port",
163 [MODULE_CLASS_COMPRESS] = "compress",
164 [MODULE_CLASS_DATA] = "data",
165 [MODULE_CLASS_SENDER] = "sender",
166 [MODULE_CLASS_RECEIVER] = "receiver",
167 [MODULE_CLASS_TX] = "transmit",
168 [MODULE_CLASS_AUDIO] = "audio",
169 [MODULE_CLASS_CONTROL] = "control",
170 [MODULE_CLASS_CAPTURE] = "capture",
171 [MODULE_CLASS_FILTER] = "filter",
172 [MODULE_CLASS_DISPLAY] = "display",
173 [MODULE_CLASS_DECODER] = "decoder",
174 [MODULE_CLASS_EXPORTER] = "exporter",
175 [MODULE_CLASS_KEYCONTROL] = "keycontrol",
176};

Referenced by module_class_name().