libamxo  4.3.4
Object Definition Language (ODL) parsing
amxo_resolver_mngr.c File Reference
#include "amxo_parser_priv.h"

Go to the source code of this file.

Macros

#define _GNU_SOURCE
 

Functions

int amxo_parser_resolve (amxo_parser_t *parser, const char *resolver_name, const char *func_name, amxo_fn_type_t type, const char *data)
 
amxc_htable_t * amxo_parser_get_resolvers (void)
 
void amxo_parser_clean_resolvers (amxo_parser_t *parser)
 
void amxo_parser_init_resolvers (amxo_parser_t *parser)
 
int amxo_register_resolver (const char *name, amxo_resolver_t *resolver)
 Registers a function resolver. More...
 
int amxo_unregister_resolver (const char *name)
 Unregisters a function resolver. More...
 
amxc_htable_t * amxo_parser_claim_resolver_data (amxo_parser_t *parser, const char *resolver_name)
 Fetches resolver specific data for a parser instance. More...
 
amxc_htable_t * amxo_parser_get_resolver_data (amxo_parser_t *parser, const char *resolver_name)
 Gets the resolver specific parser data. More...
 
void amxo_parser_remove_resolver_data (amxo_parser_t *parser, const char *resolver_name)
 Removes the resolver specific parser data. More...
 
 CONSTRUCTOR_LVL (101)
 
 DESTRUCTOR_LVL (101)
 

Variables

static amxc_htable_t resolvers
 

Macro Definition Documentation

◆ _GNU_SOURCE

#define _GNU_SOURCE

Definition at line 56 of file amxo_resolver_mngr.c.

Function Documentation

◆ amxo_parser_clean_resolvers()

void amxo_parser_clean_resolvers ( amxo_parser_t parser)

Definition at line 103 of file amxo_resolver_mngr.c.

103  {
104  amxc_htable_it_t* hit_data = NULL;
105  amxc_htable_it_t* hit_resolver = NULL;
106 
107  when_null(parser->resolvers, exit);
108 
109  hit_data = amxc_htable_get_first(parser->resolvers);
110  while(hit_data) {
111  const char* key = amxc_htable_it_get_key(hit_data);
112  amxo_resolver_t* resolver = NULL;
113  hit_resolver = amxc_htable_get(&resolvers, key);
114  resolver = amxc_htable_it_get_data(hit_resolver, amxo_resolver_t, hit);
115  if(resolver->clean != NULL) {
116  resolver->clean(parser, resolver->priv);
117  }
118  hit_data = amxc_htable_get_first(parser->resolvers);
119  }
120 
121 exit:
122  return;
123 }
static amxc_htable_t resolvers
amxc_htable_t * resolvers
Definition: amxo_types.h:269
amxo_res_clean_fn_t clean
Definition: amxo_types.h:104

◆ amxo_parser_get_resolvers()

amxc_htable_t* amxo_parser_get_resolvers ( void  )

Definition at line 99 of file amxo_resolver_mngr.c.

99  {
100  return &resolvers;
101 }

◆ amxo_parser_init_resolvers()

void amxo_parser_init_resolvers ( amxo_parser_t parser)

Definition at line 125 of file amxo_resolver_mngr.c.

125  {
126  amxc_htable_for_each(hit, (&resolvers)) {
127  amxo_resolver_t* resolver =
128  amxc_htable_it_get_data(hit, amxo_resolver_t, hit);
129  if(resolver->get != NULL) {
130  resolver->get(parser, resolver->priv);
131  }
132  }
133 
134  return;
135 }
amxo_res_get_default_t get
Definition: amxo_types.h:102

◆ amxo_parser_resolve()

int amxo_parser_resolve ( amxo_parser_t parser,
const char *  resolver_name,
const char *  func_name,
amxo_fn_type_t  type,
const char *  data 
)

Definition at line 63 of file amxo_resolver_mngr.c.

67  {
68  int retval = -1;
69  amxo_resolver_t* resolver = NULL;
70  amxc_htable_it_t* hit = NULL;
71  amxc_string_t res_name;
72  amxc_string_init(&res_name, 0);
73 
74  if(amxc_string_set_resolved(&res_name, resolver_name, &parser->config) > 0) {
75  resolver_name = amxc_string_get(&res_name, 0);
76  }
77 
78  hit = amxc_htable_get(&resolvers, resolver_name);
79  when_null(hit, exit);
80 
81  parser->status = amxd_status_ok;
82  resolver = amxc_htable_it_get_data(hit, amxo_resolver_t, hit);
83  parser->resolved_fn = resolver->resolve(parser,
84  func_name,
85  type,
86  data,
87  resolver->priv);
88  if(parser->status == amxd_status_ok) {
89  retval = parser->resolved_fn == NULL ? 1 : 0;
90  } else {
91  retval = -2;
92  }
93 
94 exit:
95  amxc_string_clean(&res_name);
96  return retval;
97 }
amxo_fn_ptr_t resolved_fn
Definition: amxo_types.h:266
amxc_var_t config
Definition: amxo_types.h:250
amxd_status_t status
Definition: amxo_types.h:258
amxo_res_resolve_fn_t resolve
Definition: amxo_types.h:103

◆ CONSTRUCTOR_LVL()

CONSTRUCTOR_LVL ( 101  )

Definition at line 236 of file amxo_resolver_mngr.c.

236  {
237  amxc_htable_init(&resolvers, 10);
238 }

◆ DESTRUCTOR_LVL()

DESTRUCTOR_LVL ( 101  )

Definition at line 240 of file amxo_resolver_mngr.c.

240  {
241  amxc_htable_clean(&resolvers, NULL);
242 }

Variable Documentation

◆ resolvers

amxc_htable_t resolvers
static

Definition at line 61 of file amxo_resolver_mngr.c.