libamxb  4.8.2
Bus Agnostic C API
amxb_expr_funcs.c
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 #include <stdlib.h>
56 
57 #include <amxc/amxc.h>
58 #include <amxp/amxp.h>
59 
60 #include <amxd/amxd_common.h>
61 #include <amxd/amxd_dm.h>
62 #include <amxd/amxd_object.h>
63 #include <amxd/amxd_path.h>
64 
65 #include <amxb/amxb.h>
66 #include <amxb/amxb_operators.h>
67 #include "amxb/amxb_be_intf.h"
68 
69 #include "amxb_priv.h"
70 
71 typedef struct _amxb_resolve {
72  amxc_var_t* ret;
73  amxd_path_t* path;
75 
77  UNUSED const amxc_var_t* args,
78  void* priv) {
79  int retval = -1;
80  amxb_resolve_t* resolver = (amxb_resolve_t*) priv;
81  uint32_t caps = 0;
82 
85  goto exit;
86  }
87  retval = amxb_resolve(bus_ctx, resolver->path, resolver->ret);
88 
89 exit:
90  return retval;
91 }
92 
93 static void amxb_ba_get_all_matching(amxd_path_t* path,
94  amxc_var_t* ret) {
95  amxc_var_t args;
96  amxb_resolve_t resolver = {
97  .ret = ret,
98  .path = path
99  };
100  amxc_var_init(&args);
101  amxc_var_set_type(&args, AMXC_VAR_ID_HTABLE);
102 
104 
105  amxc_var_clean(&args);
106 }
107 
108 static amxp_expr_status_t amxb_ba_value_spath(UNUSED amxp_expr_t* expr,
109  amxc_var_t* args,
110  amxc_var_t* ret) {
111 
112  amxp_expr_status_t status = amxp_expr_status_invalid_value;
113  amxc_llist_it_t* it = amxc_llist_get_first(&args->data.vl);
114  amxc_var_t* data = amxc_var_from_llist_it(it);
115  const char* str_path = NULL;
116  amxd_path_t path;
117 
118  amxd_path_init(&path, NULL);
119 
120  when_null(it, exit);
121  when_true(amxc_var_type_of(data) != AMXC_VAR_ID_CSTRING, exit);
122 
123  str_path = amxc_var_constcast(cstring_t, data);
124  when_failed(amxd_path_setf(&path, false, "%s", str_path), exit);
125 
126  amxc_var_set_type(ret, AMXC_VAR_ID_LIST);
127  amxb_ba_get_all_matching(&path, ret);
128 
129  status = amxp_expr_status_ok;
130 
131 exit:
132  amxd_path_clean(&path);
133  return status;
134 }
135 
136 CONSTRUCTOR_LVL(102) static void amxp_expr_functions_init(void) {
137  amxp_expr_add_value_fn("search_path", amxb_ba_value_spath);
138 }
Ambiorix bus agnostic API header file.
Ambiorix Bus Backend Interface.
#define AMXB_BE_DISCOVER_RESOLVE
Definition: amxb_be_intf.h:344
static void amxb_ba_get_all_matching(amxd_path_t *path, amxc_var_t *ret)
static amxp_expr_status_t amxb_ba_value_spath(UNUSED amxp_expr_t *expr, amxc_var_t *args, amxc_var_t *ret)
struct _amxb_resolve amxb_resolve_t
CONSTRUCTOR_LVL(102)
static int amxb_ba_resolve_path(amxb_bus_ctx_t *bus_ctx, UNUSED const amxc_var_t *args, void *priv)
Ambiorix Bus Agnostic Data Model Operators API.
int amxb_resolve(amxb_bus_ctx_t *bus_ctx, amxd_path_t *obj_path, amxc_var_t *ret_val)
uint32_t PRIVATE amxb_be_get_capabilities(amxb_bus_ctx_t *bus_ctx)
Definition: amxb_ba_priv.c:157
static uint32_t caps
Definition: dummy_be.c:70
int amxb_be_for_all_connections(amxb_be_task_fn_t fn, const amxc_var_t *args, void *priv)
Calls a function on all open connections.
amxd_path_t * path
amxc_var_t * ret
static amxb_bus_ctx_t * bus_ctx
Definition: test_amxb_e2e.c:84