mirror of
https://codeberg.org/dnkl/yambar.git
synced 2025-04-20 03:35:41 +02:00
module: provide a "common" constructor and destructor
Also, provide a lock for module to use (to ensure run() and content() doesn't step on each other's toes).
This commit is contained in:
parent
3618b863ff
commit
edc418b22d
2 changed files with 29 additions and 0 deletions
23
module.c
23
module.c
|
@ -1,6 +1,29 @@
|
||||||
#include "module.h"
|
#include "module.h"
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
struct module *
|
||||||
|
module_common_new(void)
|
||||||
|
{
|
||||||
|
struct module *mod = malloc(sizeof(*mod));
|
||||||
|
mod->bar = NULL;
|
||||||
|
mtx_init(&mod->lock, mtx_plain);
|
||||||
|
mod->private = NULL;
|
||||||
|
mod->run = NULL;
|
||||||
|
mod->destroy = &module_default_destroy;
|
||||||
|
mod->content = NULL;
|
||||||
|
mod->begin_expose = &module_default_begin_expose;
|
||||||
|
mod->expose = &module_default_expose;
|
||||||
|
mod->end_expose = &module_default_end_expose;
|
||||||
|
return mod;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
module_default_destroy(struct module *mod)
|
||||||
|
{
|
||||||
|
mtx_destroy(&mod->lock);
|
||||||
|
free(mod);
|
||||||
|
}
|
||||||
|
|
||||||
struct module_expose_context
|
struct module_expose_context
|
||||||
module_default_begin_expose(const struct module *mod, cairo_t *cr)
|
module_default_begin_expose(const struct module *mod, cairo_t *cr)
|
||||||
{
|
{
|
||||||
|
|
6
module.h
6
module.h
|
@ -1,5 +1,6 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <threads.h>
|
||||||
#include <cairo.h>
|
#include <cairo.h>
|
||||||
|
|
||||||
#include "particle.h"
|
#include "particle.h"
|
||||||
|
@ -21,6 +22,7 @@ struct module_expose_context {
|
||||||
|
|
||||||
struct module {
|
struct module {
|
||||||
const struct bar *bar;
|
const struct bar *bar;
|
||||||
|
mtx_t lock;
|
||||||
|
|
||||||
void *private;
|
void *private;
|
||||||
|
|
||||||
|
@ -35,6 +37,10 @@ struct module {
|
||||||
void (*end_expose)(const struct module *mod, struct module_expose_context *ctx);
|
void (*end_expose)(const struct module *mod, struct module_expose_context *ctx);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct module *module_common_new(void);
|
||||||
|
|
||||||
|
void module_default_destroy(struct module *mod);
|
||||||
|
|
||||||
struct module_expose_context module_default_begin_expose(
|
struct module_expose_context module_default_begin_expose(
|
||||||
const struct module *mod, cairo_t *cr);
|
const struct module *mod, cairo_t *cr);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue