libamxb  4.8.2
Bus Agnostic C API
amxb_ba_op_get_multiple.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 #ifndef _GNU_SOURCE
56 #define _GNU_SOURCE
57 #endif
58 
59 #include <stdlib.h>
60 #include <stdio.h>
61 #include <errno.h>
62 #include <fcntl.h>
63 #include <string.h>
64 
65 #include <amxc/amxc.h>
66 #include <amxp/amxp.h>
67 
68 #include <amxd/amxd_common.h>
69 #include <amxd/amxd_dm.h>
70 #include <amxd/amxd_path.h>
71 #include <amxd/amxd_object.h>
72 
73 #include <amxb/amxb_be_intf.h>
74 #include <amxb/amxb.h>
75 
76 #include "amxb_priv.h"
77 
79  amxc_var_t* req_paths,
80  int32_t depth,
81  amxc_var_t* ret,
82  int timeout) {
83  int retval = amxd_status_ok;
84  amxc_var_set_type(ret, AMXC_VAR_ID_HTABLE);
85 
86  when_false(amxc_var_type_of(req_paths) == AMXC_VAR_ID_LIST, exit);
87 
88  amxc_var_for_each(path, req_paths) {
89  int rv = 0;
90  amxc_var_t* sub_ret = NULL;
91  amxc_var_t* sub_ret_result = NULL;
92  const char* path_string = NULL;
93 
94  path_string = amxc_var_constcast(cstring_t, path);
95  sub_ret = amxc_var_add_key(amxc_htable_t, ret, path_string, NULL);
96  sub_ret_result = amxc_var_add_new_key(sub_ret, "result");
97  rv = amxb_get(bus_ctx, path_string, depth, sub_ret_result, timeout);
98  if(amxc_var_type_of(sub_ret_result) == AMXC_VAR_ID_NULL) {
99  amxc_var_set_type(sub_ret_result, AMXC_VAR_ID_LIST);
100  amxc_var_add(amxc_htable_t, sub_ret_result, NULL);
101  rv = amxd_status_object_not_found;
102  }
103  amxc_var_add_key(uint32_t, sub_ret, "status", rv);
104  }
105 
106  retval = amxd_status_ok;
107 
108 exit:
109  return retval;
110 
111 }
Ambiorix bus agnostic API header file.
Ambiorix Bus Backend Interface.
int amxb_get_multiple(amxb_bus_ctx_t *const bus_ctx, amxc_var_t *req_paths, int32_t depth, amxc_var_t *ret, int timeout)
Fetches one or more (root) objects or multiple parameters.
int amxb_get(amxb_bus_ctx_t *const bus_ctx, const char *object, int32_t depth, amxc_var_t *ret, int timeout)
Fetches one or more objects or a single parameter.
static amxb_bus_ctx_t * bus_ctx
Definition: test_amxb_e2e.c:84