libamxo  4.3.4
Object Definition Language (ODL) parsing
amxo.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** SPDX-License-Identifier: BSD-2-Clause-Patent
4 **
5 ** SPDX-FileCopyrightText: Copyright (c) 2023 SoftAtHome
6 **
7 ** Redistribution and use in source and binary forms, with or without modification,
8 ** are permitted provided that the following conditions are met:
9 **
10 ** 1. Redistributions of source code must retain the above copyright notice,
11 ** this list of conditions and the following disclaimer.
12 **
13 ** 2. Redistributions in binary form must reproduce the above copyright notice,
14 ** this list of conditions and the following disclaimer in the documentation
15 ** and/or other materials provided with the distribution.
16 **
17 ** Subject to the terms and conditions of this license, each copyright holder
18 ** and contributor hereby grants to those receiving rights under this license
19 ** a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable
20 ** (except for failure to satisfy the conditions of this license) patent license
21 ** to make, have made, use, offer to sell, sell, import, and otherwise transfer
22 ** this software, where such license applies only to those patent claims, already
23 ** acquired or hereafter acquired, licensable by such copyright holder or contributor
24 ** that are necessarily infringed by:
25 **
26 ** (a) their Contribution(s) (the licensed copyrights of copyright holders and
27 ** non-copyrightable additions of contributors, in source or binary form) alone;
28 ** or
29 **
30 ** (b) combination of their Contribution(s) with the work of authorship to which
31 ** such Contribution(s) was added by such copyright holder or contributor, if,
32 ** at the time the Contribution is added, such addition causes such combination
33 ** to be necessarily infringed. The patent license shall not apply to any other
34 ** combinations which include the Contribution.
35 **
36 ** Except as expressly stated above, no rights or licenses from any copyright
37 ** holder or contributor is granted under this license, whether expressly, by
38 ** implication, estoppel or otherwise.
39 **
40 ** DISCLAIMER
41 **
42 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
43 ** AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
44 ** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
45 ** ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
46 ** LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
47 ** DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
48 ** SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
49 ** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
50 ** OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
51 ** USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
52 **
53 ****************************************************************************/
54 
55 #if !defined(__AMXO_H__)
56 #define __AMXO_H__
57 
58 #ifdef __cplusplus
59 extern "C"
60 {
61 #endif
62 
63 #if !defined(USE_DOXYGEN)
64 #define AMXO_INLINE static inline
65 #else
66 #define AMXO_INLINE
67 #endif
68 
69 #include <amxo/amxo_types.h>
70 #include <amxo/amxo_resolvers.h>
71 #include <amxo/amxo_hooks.h>
72 #include <amxo/amxo_mibs.h>
73 #include <amxo/amxo_save.h>
74 #include <amxs/amxs.h>
75 
106 const char* amxo_lib_version(void);
107 
144 int amxo_parser_init(amxo_parser_t* parser);
145 
172 void amxo_parser_clean(amxo_parser_t* parser);
173 
213 int amxo_parser_new(amxo_parser_t** parser);
214 
244 void amxo_parser_delete(amxo_parser_t** parser);
245 
286  int fd,
287  amxd_object_t* object);
288 
334  const char* file_path,
335  amxd_object_t* object);
336 
374  const char* text,
375  amxd_object_t* object);
376 
414 amxd_status_t amxo_parser_get_status(amxo_parser_t* parser) {
415  return parser == NULL ? amxd_status_ok : parser->status;
416 }
417 
459  return parser == NULL ? NULL : amxc_string_get(&parser->msg, 0);
460 }
461 
484 const char* amxo_parser_get_file(amxo_parser_t* parser) {
485  return parser == NULL ? NULL : parser->file;
486 }
487 
506  return parser == NULL ? 0 : parser->line;
507 }
508 
537  amxo_entry_point_t fn);
538 
572  amxd_dm_t* dm,
573  int reason);
574 
605  amxd_dm_t* dm,
606  int reason);
607 
639 
657 
677 amxs_sync_ctx_t* amxo_parser_new_sync_ctx(const char* sync_template,
678  const char* object_a,
679  const char* object_b);
712 amxc_var_t* amxo_parser_get_config(amxo_parser_t* parser,
713  const char* path);
714 
735 amxc_var_t* amxo_parser_claim_config(amxo_parser_t* parser,
736  const char* path);
737 
760  const char* path,
761  amxc_var_t* value);
762 
786  int fd,
787  amxo_fd_cb_t reader,
788  const char* uri,
789  amxo_con_type_t type,
790  void* priv);
791 
807  int fd,
808  amxo_fd_cb_t writer);
809 
824  int fd);
825 
840  int fd);
841 
857  int fd,
858  void* el_data);
859 
874  amxo_con_type_t type);
875 
891  amxo_connection_t* con,
892  amxo_con_type_t type);
893 
907 
921 
922 #ifdef __cplusplus
923 }
924 #endif
925 
926 #endif // __AMXO_H__
#define AMXO_INLINE
Definition: amxo.h:64
#define amxo_connection_t
Definition: amxo_types.h:230
int(* amxo_entry_point_t)(int reason, amxd_dm_t *dm, amxo_parser_t *parser)
Definition: amxo_types.h:218
enum _amxo_con_type amxo_con_type_t
void(* amxo_fd_cb_t)(int fd, void *priv)
Definition: amxo_types.h:227
amxc_var_t * amxo_parser_get_config(amxo_parser_t *parser, const char *path)
Gets a configuration option.
int amxo_parser_set_config(amxo_parser_t *parser, const char *path, amxc_var_t *value)
Sets a configuration option.
amxc_var_t * amxo_parser_claim_config(amxo_parser_t *parser, const char *path)
Gets or creates a configuration option.
amxo_connection_t * amxo_connection_get(amxo_parser_t *parser, int fd)
Gets the connection data for a file descriptor.
amxo_connection_t * amxo_connection_get_next(amxo_parser_t *parser, amxo_connection_t *con, amxo_con_type_t type)
Gets the next connection data for a file descriptor.
int amxo_connection_set_el_data(amxo_parser_t *parser, int fd, void *el_data)
Sets event-loop data.
amxo_connection_t * amxo_connection_get_first(amxo_parser_t *parser, amxo_con_type_t type)
Gets the first connection of the given type.
int amxo_connection_remove(amxo_parser_t *parser, int fd)
Removes the fd from the connection list.
int amxo_connection_add(amxo_parser_t *parser, int fd, amxo_fd_cb_t reader, const char *uri, amxo_con_type_t type, void *priv)
Adds a file descriptor (fd) to the list of fds that must be watched.
int amxo_connection_wait_write(amxo_parser_t *parser, int fd, amxo_fd_cb_t writer)
Adds a watcher to check if a fd is ready for write.
int amxo_parser_parse_fd(amxo_parser_t *parser, int fd, amxd_object_t *object)
Parses an odl file.
int amxo_parser_start_synchronize(amxo_parser_t *parser)
Start all object and parameter synchronizations that were declared in the loaded odl files.
static const char * amxo_parser_get_message(amxo_parser_t *parser)
Get the failure message in human readable form.
Definition: amxo.h:458
int amxo_parser_parse_string(amxo_parser_t *parser, const char *text, amxd_object_t *object)
Parses a string containing a valid ODL part.
void amxo_parser_clean(amxo_parser_t *parser)
Cleans up the odl parser instance.
const char * amxo_lib_version(void)
Returns the version of lib amxo.
Definition: amxo_version.c:58
amxc_llist_t * amxo_parser_get_listeners(amxo_parser_t *parser)
Get of the current listen sockets of the application.
int amxo_parser_parse_file(amxo_parser_t *parser, const char *file_path, amxd_object_t *object)
Parses an odl file.
amxc_llist_t * amxo_parser_get_connections(amxo_parser_t *parser)
Get a list of the current connections of the application.
int amxo_parser_add_entry_point(amxo_parser_t *parser, amxo_entry_point_t fn)
Adds an entry point function.
int amxo_parser_new(amxo_parser_t **parser)
Allocates memory for a new parser instance on the heap and initializes the odl parser.
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.
static amxd_status_t amxo_parser_get_status(amxo_parser_t *parser)
Get the status of the odl parser.
Definition: amxo.h:414
int amxo_parser_init(amxo_parser_t *parser)
Initializes a new odl parser instance.
int amxo_parser_rinvoke_entry_points(amxo_parser_t *parser, amxd_dm_t *dm, int reason)
Invokes all registered entry points in reversed order.
static const char * amxo_parser_get_file(amxo_parser_t *parser)
Get the current file name that is being parsed.
Definition: amxo.h:484
static uint32_t amxo_parser_get_line(amxo_parser_t *parser)
Get the current line number that is being parsed.
Definition: amxo.h:505
void amxo_parser_delete(amxo_parser_t **parser)
Cleans the odl parser content and frees the allocated memory.
void amxo_parser_stop_synchronize(amxo_parser_t *parser)
Stop all object and parameter synchronizations that were declared in odl files.
int amxo_parser_invoke_entry_points(amxo_parser_t *parser, amxd_dm_t *dm, int reason)
Invokes all registered entry points.
The ODL parser structure.
Definition: amxo_types.h:245
amxc_string_t msg
Definition: amxo_types.h:259
const char * file
Definition: amxo_types.h:279
amxd_status_t status
Definition: amxo_types.h:258
uint32_t line
Definition: amxo_types.h:280