libamxrt  0.4.2
Ambiorix Run Time Library
amxrt.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(__AMXRT_H__)
56 #define __AMXRT_H__
57 
58 #ifdef __cplusplus
59 extern "C"
60 {
61 #endif
62 
63 #include <getopt.h>
64 
65 #include <amxc/amxc_macros.h>
66 #include <amxc/amxc.h>
67 #include <amxp/amxp.h>
68 #include <amxd/amxd_dm.h>
69 #include <amxo/amxo.h>
70 #include <amxo/amxo_mibs.h>
71 #include <amxb/amxb.h>
72 
73 #define AMXRT_COPT_URIS "uris"
74 #define AMXRT_COPT_DATA_URIS "data-uris"
75 #define AMXRT_COPT_BACKENDS "backends"
76 #define AMXRT_COPT_AUTO_DETECT "auto-detect"
77 #define AMXRT_COPT_AUTO_CONNECT "auto-connect"
78 #define AMXRT_COPT_INCDIRS "include-dirs"
79 #define AMXRT_COPT_LIBDIRS "import-dirs"
80 #define AMXRT_COPT_MIBDIRS "mib-dirs"
81 #define AMXRT_COPT_ODL "ODL"
82 #define AMXRT_COPT_DAEMON "daemon"
83 #define AMXRT_COPT_PRIORITY "priority"
84 #define AMXRT_COPT_PID_FILE "pid-file"
85 #define AMXRT_COPT_NAME "name"
86 #define AMXRT_COPT_PREFIX_PATH "prefix"
87 #define AMXRT_COPT_PLUGIN_DIR "plugin-dir"
88 #define AMXRT_COPT_CFG_DIR "cfg-dir"
89 #define AMXRT_COPT_LISTEN "listen"
90 #define AMXRT_COPT_EVENT "dm-eventing-enabled"
91 #define AMXRT_COPT_DUMP_CONFIG "dump-config"
92 #define AMXRT_COPT_DUMP_CAPS "dump-caps"
93 #define AMXRT_COPT_BACKENDS_DIR "backend-dir"
94 #define AMXRT_COPT_RW_DATA_PATH "rw_data_path"
95 #define AMXRT_COPT_STORAGE_DIR "storage-path"
96 #define AMXRT_COPT_STORAGE_TYPE "storage-type"
97 #define AMXRT_COPT_ODL_CONFIG "odl"
98 #define AMXRT_COPT_LOG "log"
99 #define AMXRT_COPT_REQUIRES "requires"
100 #define AMXRT_COPT_HANDLE_EVENTS "dm-events-before-start"
101 #define AMXRT_COPT_SUSPEND "dm-events-suspend-when-requires"
102 #define AMXRT_COPT_EXT_DIR "extensions-dir"
103 
104 #define AMXRT_COPT_DIRECTORY "odl.directory"
105 #define AMXRT_COPT_DEFAULTS "odl.dm-defaults"
106 #define AMXRT_COPT_EVENTS "odl.load-dm-events"
107 #define AMXRT_COPT_OBJECTS "odl.dm-objects"
108 #define AMXRT_COPT_LOAD "odl.dm-load"
109 #define AMXRT_COPT_SAVE "odl.dm-save"
110 #define AMXRT_COPT_ON_CHANGED "odl.dm-save-on-changed"
111 #define AMXRT_COPT_DELAY "odl.dm-save-delay"
112 #define AMXRT_COPT_INIT_DELAY "odl.dm-save-init-delay"
113 #define AMXRT_COPT_STORAGE "storage-type"
114 
115 typedef int (* amxrt_arg_fn_t) (amxc_var_t* config,
116  int arg_id,
117  const char* value);
118 
177 amxc_var_t* amxrt_get_config(void);
178 
198 amxo_parser_t* amxrt_get_parser(void);
199 
208 amxd_dm_t* amxrt_get_dm(void);
209 
226 void amxrt_new(void);
227 
300 int amxrt(int argc, char* argv[], amxrt_arg_fn_t fn);
301 
345 int amxrt_init(int argc, char* argv[], amxrt_arg_fn_t fn);
346 
367 int amxrt_register_or_wait(void);
368 
382 int amxrt_run(void);
383 
403 void amxrt_stop(void);
404 
414 void amxrt_delete(void);
415 
443 int amxrt_load_odl_files(int argc, char* argv[], int index);
444 
464 int amxrt_connect(void);
465 
481 void amxrt_enable_syssigs(amxc_var_t* syssigs);
482 
548 
568 int amxrt_cmd_line_add_option(int id, char short_option, const char* long_option, int has_args, const char* doc, const char* arg_doc);
569 
600 void amxrt_cmd_line_set_usage_doc(const char* usage);
601 
636 int amxrt_cmd_line_parse(int argc, char* argv[], amxrt_arg_fn_t fn);
637 
662 void amxrt_cmd_line_parse_assignment(const char* option, bool force);
663 
703 void amxrt_print_usage(void);
704 
723 int amxrt_config_init(int argc, char* argv[], int* index, amxrt_arg_fn_t fn);
724 
737 
751 void amxrt_config_read_env_var(const char* var_name, const char* config_name, int32_t var_type);
752 
810 int amxrt_el_create(void);
811 
830 int amxrt_el_start(void);
831 
849 int amxrt_el_stop(void);
850 
862 int amxrt_el_destroy(void);
863 
897 int amxrt_dm_save_load_main(int reason, amxd_dm_t* dm, amxo_parser_t* parser);
898 
940 int amxrt_caps_apply(void);
941 
949 void amxrt_caps_dump(void);
950 
951 #ifdef __cplusplus
952 }
953 #endif
954 
955 #endif // __AMXRT_H__
int(* amxrt_arg_fn_t)(amxc_var_t *config, int arg_id, const char *value)
Definition: amxrt.h:115
void amxrt_cmd_line_parse_assignment(const char *option, bool force)
Parses an command line option or an argument with an assignment.
Definition: amxrt_args.c:296
int amxrt_cmd_line_add_option(int id, char short_option, const char *long_option, int has_args, const char *doc, const char *arg_doc)
Adds a command line option definition.
Definition: amxrt_args.c:206
int amxrt_cmd_line_parse(int argc, char *argv[], amxrt_arg_fn_t fn)
Starts parsing the command line options.
Definition: amxrt_args.c:236
void amxrt_cmd_line_set_usage_doc(const char *usage)
Set the overall usage documentation string.
Definition: amxrt_args.c:230
void amxrt_cmd_line_options_reset(void)
Removes all default options.
Definition: amxrt_args.c:200
void amxrt_print_usage(void)
Prints the usage information and all available options to stdout.
int amxrt_el_destroy(void)
Cleans-up the event loop components.
int amxrt_el_start(void)
Starts the event loop.
int amxrt_el_stop(void)
Stops the event loop.
int amxrt_el_create(void)
Creates and initializes all needed event loop components.
void amxrt_caps_dump(void)
Dumps the capabilities of the process.
Definition: amxrt_cap.c:180
int amxrt_caps_apply(void)
Apply the user, group and capabilities as defined in the configuration.
Definition: amxrt_cap.c:101
void amxrt_config_scan_backend_dirs(void)
Scan backend directories for available backends.
Definition: amxrt_config.c:246
amxc_var_t * amxrt_get_config(void)
Gets the htable variant containing the configuration options.
Definition: amxrt.c:301
int amxrt_connect(void)
Connects to all bus sockets.
Definition: amxrt.c:488
int amxrt_init(int argc, char *argv[], amxrt_arg_fn_t fn)
Initializes the ambiorix runtime.
Definition: amxrt.c:348
int amxrt(int argc, char *argv[], amxrt_arg_fn_t fn)
This function can create full ambiorix application (data model provider or client).
Definition: amxrt.c:334
int amxrt_dm_save_load_main(int reason, amxd_dm_t *dm, amxo_parser_t *parser)
The data model auto load and save module.
void amxrt_delete(void)
Clean-up ambiorix runtime.
Definition: amxrt.c:378
int amxrt_load_odl_files(int argc, char *argv[], int index)
Load odls files mentioned on the command line or the default odl file.
Definition: amxrt.c:466
int amxrt_run(void)
Starts the event loop.
Definition: amxrt.c:425
amxd_dm_t * amxrt_get_dm(void)
Gets the runtime data model storage.
Definition: amxrt.c:309
void amxrt_new(void)
Create the ambiorix runtime.
Definition: amxrt.c:313
void amxrt_config_read_env_var(const char *var_name, const char *config_name, int32_t var_type)
Helper function to read an environment variable and add it's value to the runtime configuration.
Definition: amxrt_config.c:264
void amxrt_stop(void)
Stops the runtime.
Definition: amxrt.c:440
amxo_parser_t * amxrt_get_parser(void)
Gets runtime odl parser.
Definition: amxrt.c:305
void amxrt_enable_syssigs(amxc_var_t *syssigs)
Enables system signals that should be monitored by the eventloop.
Definition: amxrt.c:516
int amxrt_register_or_wait(void)
Register the data model or wait for required data model objects.
Definition: amxrt.c:389
int amxrt_config_init(int argc, char *argv[], int *index, amxrt_arg_fn_t fn)
Initializes the default runtime configuration.
Definition: amxrt_config.c:217
config
Definition: test.odl:54