libamxo  4.3.4
Object Definition Language (ODL) parsing
amxo_parser_main.c File Reference
#include "amxo_parser_priv.h"
#include "amxo_parser_hooks_priv.h"
#include "amxo_parser.tab.h"

Go to the source code of this file.

Macros

#define _GNU_SOURCE
 

Functions

static ssize_t amxo_parser_string_reader (amxo_parser_t *parser, char *buf, size_t max_size)
 
static int amxo_parser_parse_fd_internal (amxo_parser_t *parser, int fd, amxd_object_t *object)
 
static void amxo_parser_entry_point_free (amxc_llist_it_t *it)
 
ssize_t amxo_parser_fd_reader (amxo_parser_t *parser, char *buf, size_t max_size)
 
static void amxo_parser_pop_event (event_t *e, amxd_dm_t *dm)
 
static void amxo_parser_send_events (amxo_parser_t *parser, amxd_dm_t *dm)
 
int amxo_parser_parse_file_impl (amxo_parser_t *parser, const char *file_path, amxd_object_t *object)
 
void amxo_parser_child_init (amxo_parser_t *parser)
 
int amxo_parser_init (amxo_parser_t *parser)
 Initializes a new odl parser instance. More...
 
void amxo_parser_clean (amxo_parser_t *parser)
 Cleans up the odl parser instance. More...
 
int amxo_parser_new (amxo_parser_t **parser)
 Allocates memory for a new parser instance on the heap and initializes the odl parser. More...
 
void amxo_parser_delete (amxo_parser_t **parser)
 Cleans the odl parser content and frees the allocated memory. More...
 
int amxo_parser_parse_fd (amxo_parser_t *parser, int fd, amxd_object_t *object)
 Parses an odl file. More...
 
int amxo_parser_parse_file (amxo_parser_t *parser, const char *file_path, amxd_object_t *object)
 Parses an odl file. More...
 
int amxo_parser_parse_string (amxo_parser_t *parser, const char *text, amxd_object_t *object)
 Parses a string containing a valid ODL part. More...
 
amxc_var_t * amxo_parser_claim_config (amxo_parser_t *parser, const char *path)
 Gets or creates a configuration option. More...
 
amxc_var_t * amxo_parser_get_config (amxo_parser_t *parser, const char *path)
 Gets a configuration option. More...
 
int amxo_parser_set_config (amxo_parser_t *parser, const char *path, amxc_var_t *value)
 Sets a configuration option. More...
 
int amxo_parser_add_entry_point (amxo_parser_t *parser, amxo_entry_point_t fn)
 Adds an entry point function. More...
 
int amxo_parser_invoke_entry_points (amxo_parser_t *parser, amxd_dm_t *dm, int reason)
 Invokes all registered entry points. More...
 
int amxo_parser_rinvoke_entry_points (amxo_parser_t *parser, amxd_dm_t *dm, int reason)
 Invokes all registered entry points in reversed order. More...
 
int amxo_parser_start_synchronize (amxo_parser_t *parser)
 Start all object and parameter synchronizations that were declared in the loaded odl files. More...
 
void amxo_parser_stop_synchronize (amxo_parser_t *parser)
 Stop all object and parameter synchronizations that were declared in odl files. More...
 
amxs_sync_ctx_t * amxo_parser_new_sync_ctx (const char *sync_template, const char *object_a, const char *object_b)
 Create a new synchronization context from a synchronization template. More...
 

Macro Definition Documentation

◆ _GNU_SOURCE

#define _GNU_SOURCE

Definition at line 56 of file amxo_parser_main.c.

Function Documentation

◆ amxo_parser_child_init()

void amxo_parser_child_init ( amxo_parser_t parser)

Definition at line 181 of file amxo_parser_main.c.

181  {
182  when_null(parser, exit);
183 
184  parser->fd = -1;
185  parser->object = NULL;
186  parser->param = NULL;
187  parser->func = NULL;
188  parser->status = amxd_status_ok;
189  parser->resolved_fn = NULL;
190  parser->resolvers = NULL;
191  parser->include_stack = NULL;
192  parser->hooks = NULL;
193  parser->entry_points = NULL;
194  parser->_unused_1 = NULL;
195  parser->_unused_2 = NULL;
196  parser->post_includes = NULL;
197  parser->parent = NULL;
198  parser->resolved_fn_name = NULL;
199  parser->buffer_len = 0;
200  parser->data = NULL;
201  parser->sync_contexts = NULL;
202 
203  memset(parser->buffer, 0, 128);
204  amxc_rbuffer_init(&parser->rbuffer, 0);
205  amxc_string_init(&parser->msg, 0);
206  amxc_astack_init(&parser->object_stack);
207  amxc_llist_init(&parser->event_list);
208  amxc_var_init(&parser->config);
209  amxc_llist_init(&parser->global_config);
210  amxc_htable_init(&parser->mibs, 5);
211  amxc_llist_init(&parser->function_names);
212 
213  parser->file = "<unknown>";
214 
215 exit:
216  return;
217 }
amxc_htable_t * resolvers
Definition: amxo_types.h:269
amxc_htable_t mibs
Definition: amxo_types.h:282
amxo_fn_ptr_t resolved_fn
Definition: amxo_types.h:266
amxc_llist_t * hooks
Definition: amxo_types.h:274
char buffer[128]
Definition: amxo_types.h:287
amxc_llist_t * _unused_2
Definition: amxo_types.h:272
amxc_astack_t object_stack
Definition: amxo_types.h:261
size_t buffer_len
Definition: amxo_types.h:288
amxc_lstack_t event_list
Definition: amxo_types.h:283
amxc_llist_t function_names
Definition: amxo_types.h:268
amxc_string_t msg
Definition: amxo_types.h:259
amxd_param_t * param
Definition: amxo_types.h:263
amxc_var_t config
Definition: amxo_types.h:250
amxc_string_t * resolved_fn_name
Definition: amxo_types.h:267
amxc_rbuffer_t rbuffer
Definition: amxo_types.h:256
amxc_var_t * include_stack
Definition: amxo_types.h:277
amxc_llist_t * _unused_1
Definition: amxo_types.h:271
const char * file
Definition: amxo_types.h:279
amxc_llist_t * entry_points
Definition: amxo_types.h:273
amxd_status_t status
Definition: amxo_types.h:258
amxc_var_t * data
Definition: amxo_types.h:265
amxc_llist_t global_config
Definition: amxo_types.h:253
amxc_var_t * post_includes
Definition: amxo_types.h:275
amxd_object_t * object
Definition: amxo_types.h:262
amxd_function_t * func
Definition: amxo_types.h:264
amxo_parser_t * parent
Definition: amxo_types.h:285
amxc_llist_t * sync_contexts
Definition: amxo_types.h:290

◆ amxo_parser_entry_point_free()

static void amxo_parser_entry_point_free ( amxc_llist_it_t *  it)
static

Definition at line 99 of file amxo_parser_main.c.

99  {
100  amxo_entry_t* entry = amxc_llist_it_get_data(it, amxo_entry_t, it);
101  free(entry);
102 }
Definition: amxo_types.h:222

◆ amxo_parser_fd_reader()

ssize_t amxo_parser_fd_reader ( amxo_parser_t parser,
char *  buf,
size_t  max_size 
)

Definition at line 104 of file amxo_parser_main.c.

104  {
105  ssize_t result = 0;
106  off_t offset = 0;
107 
108  errno = 0;
109  result = read(parser->fd, buf, max_size - 1);
110  if((result == -1) && (errno != EAGAIN)) {
111  printf("Read failed %d\n", errno);
112  goto exit;
113  }
114  errno = 0;
115 
116  buf[result] = 0;
117  while(result - offset > 0 && buf[result - offset - 1] != '\n') {
118  offset++;
119  }
120  if(result - offset > 0) {
121  lseek(parser->fd, -offset, SEEK_CUR);
122  result -= offset;
123  }
124 
125 exit:
126  return result;
127 }

◆ amxo_parser_parse_fd_internal()

static int amxo_parser_parse_fd_internal ( amxo_parser_t parser,
int  fd,
amxd_object_t *  object 
)
static

Definition at line 73 of file amxo_parser_main.c.

75  {
76  int retval = -1;
77 
78  parser->fd = fd;
79  parser->object = object;
80  parser->reader = amxo_parser_fd_reader;
81  parser->status = amxd_status_ok;
82 
83  amxc_string_reset(&parser->msg);
84  amxo_parser_create_lex(parser);
85  retval = yyparse(parser->scanner);
87 
89 
90  parser->fd = -1;
91 
92  if(retval == 0) {
93  amxc_string_clean(&parser->msg);
94  }
95 
96  return retval;
97 }
ssize_t amxo_parser_fd_reader(amxo_parser_t *parser, char *buf, size_t max_size)
PRIVATE void amxo_parser_create_lex(amxo_parser_t *parser)
PRIVATE void amxo_parser_sync_remove_invalid(amxo_parser_t *pctx)
PRIVATE void amxo_parser_destroy_lex(amxo_parser_t *parser)
amxo_reader_t reader
Definition: amxo_types.h:257
void * scanner
Definition: amxo_types.h:246

◆ amxo_parser_parse_file_impl()

int amxo_parser_parse_file_impl ( amxo_parser_t parser,
const char *  file_path,
amxd_object_t *  object 
)

Definition at line 156 of file amxo_parser_main.c.

158  {
159  int retval = -1;
160  int fd = -1;
161 
162  fd = open(file_path, O_RDONLY);
163  if(fd == -1) {
164  retval = errno;
165  if(errno == ENOENT) {
166  amxo_parser_msg(parser, "File not found %s", file_path);
167  } else {
168  amxo_parser_msg(parser, "File open error 0x%8.8X", errno);
169  }
170  goto exit;
171  }
172  parser->file = file_path;
173  retval = amxo_parser_parse_fd_internal(parser, fd, object);
174  parser->file = NULL;
175  close(fd);
176 
177 exit:
178  return retval;
179 }
static int amxo_parser_parse_fd_internal(amxo_parser_t *parser, int fd, amxd_object_t *object)
PRIVATE void amxo_parser_msg(amxo_parser_t *parser, const char *format,...) __attribute__((format(printf

◆ amxo_parser_pop_event()

static void amxo_parser_pop_event ( event_t e,
amxd_dm_t *  dm 
)
static

Definition at line 129 of file amxo_parser_main.c.

129  {
130  amxd_object_t* object = amxd_dm_findf(dm, "%s", e->path);
131 
132  when_null(object, exit);
133 
134  if(dm->sigmngr.enabled) {
135  if(e->id == event_instance_add) {
136  amxd_object_send_add_inst(object, false);
137  } else if(e->id == event_object_change) {
138  amxd_object_send_changed(object, &e->data, false);
139  }
140  }
141 
142 exit:
143  amxc_llist_it_take(&e->it);
144  amxc_var_clean(&e->data);
145  free(e->path);
146  free(e);
147 }
@ event_instance_add
@ event_object_change
char * path
event_id_t id
amxc_llist_it_t it
amxc_var_t data

◆ amxo_parser_send_events()

static void amxo_parser_send_events ( amxo_parser_t parser,
amxd_dm_t *  dm 
)
static

Definition at line 149 of file amxo_parser_main.c.

149  {
150  amxc_llist_for_each(it, &parser->event_list) {
151  event_t* e = amxc_container_of(it, event_t, it);
152  amxo_parser_pop_event(e, dm);
153  }
154 }
static void amxo_parser_pop_event(event_t *e, amxd_dm_t *dm)

◆ amxo_parser_string_reader()

static ssize_t amxo_parser_string_reader ( amxo_parser_t parser,
char *  buf,
size_t  max_size 
)
static

Definition at line 63 of file amxo_parser_main.c.

65  {
66  ssize_t result = 0;
67  result = amxc_rbuffer_read(&parser->rbuffer, (char*) buf, max_size);
68  errno = 0;
69 
70  return result;
71 }