UltraGrid
UltraGrid Low-Latency High-Resolution Transmission System
Loading...
Searching...
No Matches
module.h
Go to the documentation of this file.
1
6/*
7 * Copyright (c) 2013-2024 CESNET
8 * All rights reserved.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, is permitted provided that the following conditions
12 * are met:
13 *
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 *
17 * 2. Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in the
19 * documentation and/or other materials provided with the distribution.
20 *
21 * 3. Neither the name of CESNET nor the names of its contributors may be
22 * used to endorse or promote products derived from this software without
23 * specific prior written permission.
24 *
25 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS
26 * "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING,
27 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
28 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
29 * EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
30 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
31 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
32 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
35 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
36 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 */
64#ifndef MODULE_H_
65#define MODULE_H_
66
67#include "messaging.h"
68#include "utils/macros.h"
69
70#include <pthread.h>
71#ifndef __cplusplus
72#include <stdalign.h>
73#endif
74
75#ifdef __cplusplus
76extern "C" {
77#endif
78
79#define MODULE_MAGIC to_fourcc('M', 'O', 'D', ' ')
80
99
100struct module;
101struct simple_linked_list;
102
103typedef void (*module_deleter_t)(struct module *);
104typedef void (*notify_t)(struct module *);
105
111struct module {
112 alignas(8) uint32_t magic;
113 uint32_t priv_magic;
114 pthread_mutex_t lock;
116 struct module *parent;
120
121 pthread_mutex_t msg_queue_lock; // protects msg_queue
123
125
127 //uint32_t id;
128
129 char *name;
131
132#ifdef __cplusplus
133 module() = default;
134 // don't be tempted to copy/move module because parent holds pointer to struct module
135 // which would be dangling thereafter
136 module(module const &) = delete;
137 module(module &&) = delete;
138 module &operator=(module const &) = delete;
139 module &operator=(module &&) = delete;
140#endif
141};
142
143void module_init_default(struct module *module_data);
144void module_register(struct module *module_data, struct module *parent);
145void module_done(struct module *module_data);
146const char *module_class_name(enum module_class cls);
147void append_message_path(char *buf, int buflen,
148 const enum module_class *modules);
149bool module_get_path_str(struct module *mod, char *buf, size_t buflen);
150
151#ifdef __cplusplus
153public:
156 mod.priv_data = priv;
157 mod.cls = type;
158 module_register(&mod, parent);
159 }
160
162 module_done(&mod);
163 }
164
165 module *get(){ return &mod; }
166private:
167 module mod;
168};
169#endif
170
175struct module *get_module(struct module *root, const char *path);
176
183struct module *get_matching_child(struct module *node, const char *path);
184
190struct module *get_root_module(struct module *node);
191
192struct module *get_parent_module(struct module *node);
193
194void dump_tree(struct module *root_node, int indent);
195void dump_parents(struct module *node);
196
197#define CAST_MODULE(x) ((struct module *) x)
198
199#ifdef __cplusplus
200}
201#endif
202
203#endif
module_raii(enum module_class type, module *parent, void *priv)
Definition module.h:154
~module_raii()
Definition module.h:161
void module_init_default(struct module *module_data)
Definition module.c:48
void module_register(struct module *module_data, struct module *parent)
Definition module.c:82
void dump_tree(struct module *root_node, int indent)
Definition module.c:333
bool module_get_path_str(struct module *mod, char *buf, size_t buflen)
Definition module.c:408
struct module * get_module(struct module *root, const char *path)
Definition module.c:264
void dump_parents(struct module *node)
Definition module.c:348
void module_done(struct module *module_data)
Definition module.c:93
module_class
Definition module.h:81
const char * module_class_name(enum module_class cls)
Definition module.c:178
struct module * get_matching_child(struct module *node, const char *path)
Definition module.c:300
struct module * get_root_module(struct module *node)
Definition module.c:203
void(* notify_t)(struct module *)
Definition module.h:104
void(* module_deleter_t)(struct module *)
Definition module.h:103
void append_message_path(char *buf, int buflen, const enum module_class *modules)
Definition module.c:187
struct module * get_parent_module(struct module *node)
Definition module.c:214
@ MODULE_CLASS_CONTROL
Definition module.h:91
@ MODULE_CLASS_NONE
Definition module.h:82
@ 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
enum library_class cls
Definition host.cpp:749
const char * parent
Definition settings.cpp:198
Option::OptType type
Definition settings.cpp:194
uint32_t priv_magic
optional magic number that can a module set
Definition module.h:113
module(module &&)=delete
module()=default
char * name
Definition module.h:129
enum module_class cls
Definition module.h:115
void * priv_data
Definition module.h:126
struct simple_linked_list * msg_queue
Definition module.h:122
notify_t new_message
if set, notifies module that new message is in queue, receiver lock is hold during the call
Definition module.h:119
pthread_mutex_t msg_queue_lock
Definition module.h:121
pthread_mutex_t lock
Definition module.h:114
module(module const &)=delete
uint32_t magic
Definition module.h:112
struct simple_linked_list * children
Definition module.h:117
struct simple_linked_list * msg_queue_children
messages for childern that were not delivered
Definition module.h:124
module_deleter_t deleter
Definition module.h:118
struct module * parent
Definition module.h:116