1
|
/*
|
2
|
* Tvheadend - idnode (class) system
|
3
|
*
|
4
|
* Copyright (C) 2013 Andreas Öman
|
5
|
*
|
6
|
* This program is free software: you can redistribute it and/or modify
|
7
|
* it under the terms of the GNU General Public License as published by
|
8
|
* the Free Software Foundation, either version 3 of the License, or
|
9
|
* (at your option) any later version.
|
10
|
*
|
11
|
* This program is distributed in the hope that it will be useful,
|
12
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14
|
* GNU General Public License for more details.
|
15
|
*
|
16
|
* You should have received a copy of the GNU General Public License
|
17
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
18
|
*/
|
19
|
|
20
|
#ifndef __TVH_IDNODE_H__
|
21
|
#define __TVH_IDNODE_H__
|
22
|
|
23
|
#include "tvheadend.h"
|
24
|
#include "prop.h"
|
25
|
|
26
|
#include <regex.h>
|
27
|
|
28
|
#define UUID_STR_LEN 33 // inc NUL char
|
29
|
#define UUID_BIN_LEN 16
|
30
|
|
31
|
struct htsmsg;
|
32
|
typedef struct idnode idnode_t;
|
33
|
|
34
|
/*
|
35
|
* Node set
|
36
|
*/
|
37
|
typedef struct idnode_set
|
38
|
{
|
39
|
idnode_t **is_array; ///< Array of nodes
|
40
|
size_t is_alloc; ///< Size of is_array
|
41
|
size_t is_count; ///< Current usage of is_array
|
42
|
} idnode_set_t;
|
43
|
|
44
|
/*
|
45
|
* Class definition
|
46
|
*/
|
47
|
typedef struct idclass {
|
48
|
const struct idclass *ic_super; /// Parent class
|
49
|
const char *ic_class; /// Class name
|
50
|
const char *ic_caption; /// Class description
|
51
|
const property_t *ic_properties; /// Property list
|
52
|
const char *ic_event; /// Events to fire on add/delete/title
|
53
|
|
54
|
/* Callbacks */
|
55
|
idnode_set_t *(*ic_get_childs)(idnode_t *self);
|
56
|
const char *(*ic_get_title) (idnode_t *self);
|
57
|
void (*ic_save) (idnode_t *self);
|
58
|
void (*ic_delete) (idnode_t *self);
|
59
|
} idclass_t;
|
60
|
|
61
|
/*
|
62
|
* Node definition
|
63
|
*/
|
64
|
struct idnode {
|
65
|
uint8_t in_uuid[UUID_BIN_LEN]; ///< Unique ID
|
66
|
RB_ENTRY(idnode) in_link; ///< Global hash
|
67
|
const idclass_t *in_class; ///< Class definition
|
68
|
};
|
69
|
|
70
|
/*
|
71
|
* Sorting definition
|
72
|
*/
|
73
|
typedef struct idnode_sort {
|
74
|
const char *key; ///< Sort key
|
75
|
enum {
|
76
|
IS_ASC,
|
77
|
IS_DSC
|
78
|
} dir; ///< Sort direction
|
79
|
} idnode_sort_t;
|
80
|
|
81
|
/*
|
82
|
* Filter definition
|
83
|
*/
|
84
|
typedef struct idnode_filter_ele
|
85
|
{
|
86
|
LIST_ENTRY(idnode_filter_ele) link; ///< List link
|
87
|
|
88
|
char *key; ///< Filter key
|
89
|
enum {
|
90
|
IF_STR,
|
91
|
IF_NUM,
|
92
|
IF_BOOL
|
93
|
} type; ///< Filter type
|
94
|
union {
|
95
|
int b;
|
96
|
char *s;
|
97
|
int64_t n;
|
98
|
regex_t re;
|
99
|
} u; ///< Filter data
|
100
|
enum {
|
101
|
IC_EQ, ///< Equals
|
102
|
IC_LT, ///< LT
|
103
|
IC_GT, ///< GT
|
104
|
IC_IN, ///< contains (STR only)
|
105
|
IC_RE, ///< regexp (STR only)
|
106
|
} comp; ///< Filter comparison
|
107
|
} idnode_filter_ele_t;
|
108
|
|
109
|
typedef LIST_HEAD(,idnode_filter_ele) idnode_filter_t;
|
110
|
|
111
|
void idnode_init(void);
|
112
|
|
113
|
int idnode_insert(idnode_t *in, const char *uuid, const idclass_t *idc);
|
114
|
void idnode_unlink(idnode_t *in);
|
115
|
|
116
|
uint32_t idnode_get_short_uuid (const idnode_t *in);
|
117
|
const char *idnode_uuid_as_str0 (const idnode_t *in, char *b);
|
118
|
const char *idnode_uuid_as_str (const idnode_t *in);
|
119
|
idnode_set_t *idnode_get_childs (idnode_t *in);
|
120
|
const char *idnode_get_title (idnode_t *in);
|
121
|
int idnode_is_leaf (idnode_t *in);
|
122
|
int idnode_is_instance (idnode_t *in, const idclass_t *idc);
|
123
|
void idnode_delete (idnode_t *in);
|
124
|
|
125
|
void *idnode_find (const char *uuid, const idclass_t *idc);
|
126
|
idnode_set_t *idnode_find_all(const idclass_t *idc);
|
127
|
|
128
|
#define idnode_updated(in) idnode_notify(in, NULL, 0, 0)
|
129
|
void idnode_notify
|
130
|
(idnode_t *in, const char *chn, int force, int event);
|
131
|
void idnode_notify_simple (void *in);
|
132
|
void idnode_notify_title_changed (void *in);
|
133
|
|
134
|
const idclass_t *idclass_find ( const char *name );
|
135
|
htsmsg_t *idclass_serialize0 (const idclass_t *idc, int optmask);
|
136
|
htsmsg_t *idnode_serialize0 (idnode_t *self, int optmask);
|
137
|
void idnode_read0 (idnode_t *self, htsmsg_t *m, int optmask);
|
138
|
int idnode_write0 (idnode_t *self, htsmsg_t *m, int optmask, int dosave);
|
139
|
|
140
|
#define idclass_serialize(idc) idclass_serialize0(idc, 0)
|
141
|
#define idnode_serialize(in) idnode_serialize0(in, 0)
|
142
|
#define idnode_load(in, m) idnode_write0(in, m, 0, 0)
|
143
|
#define idnode_save(in, m) idnode_read0(in, m, PO_NOSAVE | PO_USERAW)
|
144
|
#define idnode_update(in, m) idnode_write0(in, m, PO_RDONLY | PO_WRONCE, 1)
|
145
|
|
146
|
const char *idnode_get_str (idnode_t *self, const char *key );
|
147
|
int idnode_get_u32 (idnode_t *self, const char *key, uint32_t *u32);
|
148
|
int idnode_get_bool(idnode_t *self, const char *key, int *b);
|
149
|
|
150
|
void idnode_filter_add_str
|
151
|
(idnode_filter_t *f, const char *k, const char *v, int t);
|
152
|
void idnode_filter_add_num
|
153
|
(idnode_filter_t *f, const char *k, int64_t s64, int t);
|
154
|
void idnode_filter_add_bool
|
155
|
(idnode_filter_t *f, const char *k, int b, int t);
|
156
|
void idnode_filter_clear
|
157
|
(idnode_filter_t *f);
|
158
|
int idnode_filter
|
159
|
( idnode_t *in, idnode_filter_t *filt );
|
160
|
#define idnode_set_create() calloc(1, sizeof(idnode_set_t))
|
161
|
void idnode_set_add
|
162
|
( idnode_set_t *is, idnode_t *in, idnode_filter_t *filt );
|
163
|
void idnode_set_sort ( idnode_set_t *is, idnode_sort_t *s );
|
164
|
void idnode_set_sort_by_title ( idnode_set_t *is );
|
165
|
void idnode_set_free ( idnode_set_t *is );
|
166
|
|
167
|
#endif /* __TVH_IDNODE_H__ */
|
168
|
|
169
|
/******************************************************************************
|
170
|
* Editor Configuration
|
171
|
*
|
172
|
* vim:sts=2:ts=2:sw=2:et
|
173
|
*****************************************************************************/
|