2014-06-09 18:54:48 +02:00
|
|
|
#ifndef H_MESSAGE_H
|
|
|
|
#define H_MESSAGE_H
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
|
|
#include "variant.h"
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2018-05-18 20:42:22 +02:00
|
|
|
#define MSG_MAXARGS 8
|
|
|
|
#define MT_NEW_END ((const char *)0)
|
2018-05-18 21:36:10 +02:00
|
|
|
#define MAXSECTIONS 16
|
|
|
|
|
2015-01-30 20:37:14 +01:00
|
|
|
typedef struct arg_type {
|
|
|
|
struct arg_type *next;
|
|
|
|
variant_type vtype;
|
|
|
|
const char *name;
|
|
|
|
void(*release) (variant);
|
|
|
|
variant(*copy) (variant);
|
|
|
|
} arg_type;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2015-01-30 20:37:14 +01:00
|
|
|
typedef struct message_type {
|
|
|
|
unsigned int key;
|
2015-08-17 19:35:07 +02:00
|
|
|
char *name;
|
2018-05-18 19:58:49 +02:00
|
|
|
const char *section;
|
2015-01-30 20:37:14 +01:00
|
|
|
int nparameters;
|
2015-08-17 19:35:07 +02:00
|
|
|
char **pnames;
|
|
|
|
struct arg_type ** types;
|
2015-01-30 20:37:14 +01:00
|
|
|
} message_type;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2015-01-30 20:37:14 +01:00
|
|
|
typedef struct message {
|
|
|
|
const struct message_type *type;
|
|
|
|
variant *parameters;
|
|
|
|
int refcount;
|
|
|
|
} message;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2016-09-07 20:46:41 +02:00
|
|
|
void message_done(void);
|
|
|
|
|
2015-08-17 19:35:07 +02:00
|
|
|
void mt_clear(void);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2016-08-29 18:31:09 +02:00
|
|
|
struct message *msg_create(const struct message_type *type,
|
2015-01-30 20:37:14 +01:00
|
|
|
variant args[]);
|
|
|
|
/* msg_create(&mt_simplesentence, "enno", "eats", "chocolate", &locale_de);
|
|
|
|
* parameters must be in the same order as they were for mt_new! */
|
2021-02-16 10:09:14 +01:00
|
|
|
|
|
|
|
extern char *sections[MAXSECTIONS];
|
|
|
|
extern void(*msg_log_create) (const struct message * msg);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2016-08-29 18:31:09 +02:00
|
|
|
void msg_release(struct message *msg);
|
|
|
|
struct message *msg_addref(struct message *msg);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2016-08-29 18:31:09 +02:00
|
|
|
const char *mt_name(const struct message_type *mtype);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2018-05-18 19:58:49 +02:00
|
|
|
struct message_type *mt_new(const char *name, const char *section);
|
2015-01-30 20:37:14 +01:00
|
|
|
/** message_type registry (optional): **/
|
2018-05-18 20:42:22 +02:00
|
|
|
struct message_type *mt_create(struct message_type *, const char *args[], int nargs);
|
2018-10-28 21:28:05 +01:00
|
|
|
struct message_type *mt_create_feedback(const char *name);
|
|
|
|
struct message_type *mt_create_error(int error);
|
2018-05-18 19:58:49 +02:00
|
|
|
struct message_type *mt_create_va(struct message_type *, ...);
|
2016-08-29 18:31:09 +02:00
|
|
|
const struct message_type *mt_find(const char *);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2016-08-29 18:31:09 +02:00
|
|
|
void register_argtype(const char *name, void(*free_arg) (variant),
|
2015-01-30 20:37:14 +01:00
|
|
|
variant(*copy_arg) (variant), variant_type);
|
2016-08-29 18:31:09 +02:00
|
|
|
arg_type *find_argtype(const char *name);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#endif
|
2014-06-09 18:54:48 +02:00
|
|
|
|