Libecoli 0.4.0
Extensible COmmand LIne library
 
Loading...
Searching...
No Matches
ecoli_node.h
1/* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright 2016, Olivier MATZ <zer0@droids-corp.org>
3 */
4
48
49#ifndef ECOLI_NODE_
50#define ECOLI_NODE_
51
52#include <sys/queue.h>
53#include <sys/types.h>
54#include <stdbool.h>
55#include <stdio.h>
56
60#define EC_NO_ID ""
61
63struct ec_node;
64
65struct ec_pnode;
66struct ec_comp;
67struct ec_strvec;
68struct ec_dict;
69struct ec_config;
70struct ec_config_schema;
71
81#define EC_NODE_TYPE_REGISTER(t) \
82 static void ec_node_init_##t(void); \
83 static void __attribute__((constructor, used)) \
84 ec_node_init_##t(void) \
85 { \
86 if (ec_node_type_register(&t, 0) < 0) \
87 fprintf(stderr, \
88 "cannot register node type %s\n", \
89 t.name); \
90 }
91
105#define EC_NODE_TYPE_REGISTER_OVERRIDE(t) \
106 static void ec_node_init_##t(void); \
107 static void __attribute__((constructor, used)) \
108 ec_node_init_##t(void) \
109 { \
110 if (ec_node_type_register(&t, 1) < 0) \
111 fprintf(stderr, \
112 "cannot register node type %s\n", \
113 t.name); \
114 }
115
119TAILQ_HEAD(ec_node_type_list, ec_node_type);
120
137typedef int (*ec_node_set_config_t)(struct ec_node *node,
138 const struct ec_config *config);
139
163typedef int (*ec_parse_t)(const struct ec_node *node,
164 struct ec_pnode *pstate,
165 const struct ec_strvec *strvec);
166
208typedef int (*ec_complete_t)(const struct ec_node *node,
209 struct ec_comp *comp,
210 const struct ec_strvec *strvec);
211
237typedef char * (*ec_node_desc_t)(const struct ec_node *);
238
253typedef int (*ec_node_init_priv_t)(struct ec_node *);
254
264typedef void (*ec_node_free_priv_t)(struct ec_node *);
265
276typedef size_t (*ec_node_get_children_count_t)(const struct ec_node *);
277
294typedef int (*ec_node_get_child_t)(const struct ec_node *,
295 size_t i, struct ec_node **child, unsigned int *refs);
296
305 TAILQ_ENTRY(ec_node_type) next;
306 const char *name;
309 const struct ec_config_schema *schema;
310 size_t size;
311 ec_node_set_config_t set_config;
312 ec_parse_t parse;
313 ec_complete_t complete;
314 ec_node_desc_t desc;
315 ec_node_init_priv_t init_priv;
316 ec_node_free_priv_t free_priv;
318 ec_node_get_children_count_t get_children_count;
319 ec_node_get_child_t get_child;
320};
321
338int ec_node_type_register(struct ec_node_type *type, bool override);
339
348const struct ec_node_type *ec_node_type_lookup(const char *name);
349
356void ec_node_type_dump(FILE *out);
357
367const struct ec_config_schema *
369
378const char *
379ec_node_type_name(const struct ec_node_type *type);
380
384struct ec_node *ec_node_from_type(const struct ec_node_type *type, const char *id);
385
389struct ec_node *ec_node(const char *typename, const char *id);
390
391struct ec_node *ec_node_clone(struct ec_node *node);
392void ec_node_free(struct ec_node *node);
393
394/* set configuration of a node
395 * after a call to this function, the config is
396 * owned by the node and must not be used by the caller
397 * on error, the config is freed. */
398int ec_node_set_config(struct ec_node *node, struct ec_config *config);
399
400/* get the current node configuration. Return NULL if no configuration. */
401const struct ec_config *ec_node_get_config(struct ec_node *node);
402
403size_t ec_node_get_children_count(const struct ec_node *node);
404int
405ec_node_get_child(const struct ec_node *node, size_t i,
406 struct ec_node **child, unsigned int *refs);
407
408/* XXX add more accessors */
409const struct ec_node_type *ec_node_type(const struct ec_node *node);
410struct ec_dict *ec_node_attrs(const struct ec_node *node);
411const char *ec_node_id(const struct ec_node *node);
412
413char *ec_node_desc(const struct ec_node *node);
414
415void ec_node_dump(FILE *out, const struct ec_node *node);
416struct ec_node *ec_node_find(struct ec_node *node, const char *id);
417
418/* check the type of a node */
419int ec_node_check_type(const struct ec_node *node,
420 const struct ec_node_type *type);
421
422const char *ec_node_get_type_name(const struct ec_node *node);
423
432void *ec_node_priv(const struct ec_node *node);
433
434#endif
435
struct ec_dict * ec_dict(void)
struct ec_node * ec_node_from_type(const struct ec_node_type *type, const char *id)
void(* ec_node_free_priv_t)(struct ec_node *)
Definition ecoli_node.h:264
struct ec_node * ec_node(const char *typename, const char *id)
void ec_node_type_dump(FILE *out)
int(* ec_node_get_child_t)(const struct ec_node *, size_t i, struct ec_node **child, unsigned int *refs)
Definition ecoli_node.h:294
char *(* ec_node_desc_t)(const struct ec_node *)
Definition ecoli_node.h:237
int(* ec_node_set_config_t)(struct ec_node *node, const struct ec_config *config)
Definition ecoli_node.h:137
int ec_node_type_register(struct ec_node_type *type, bool override)
int(* ec_node_init_priv_t)(struct ec_node *)
Definition ecoli_node.h:253
int(* ec_complete_t)(const struct ec_node *node, struct ec_comp *comp, const struct ec_strvec *strvec)
Definition ecoli_node.h:208
size_t(* ec_node_get_children_count_t)(const struct ec_node *)
Definition ecoli_node.h:276
const struct ec_config_schema * ec_node_type_schema(const struct ec_node_type *type)
int(* ec_parse_t)(const struct ec_node *node, struct ec_pnode *pstate, const struct ec_strvec *strvec)
Definition ecoli_node.h:163
const struct ec_node_type * ec_node_type_lookup(const char *name)
const char * ec_node_type_name(const struct ec_node_type *type)
void * ec_node_priv(const struct ec_node *node)
struct ec_pnode * ec_pnode(const struct ec_node *node)
struct ec_strvec * ec_strvec(void)