libamxd  6.4.1
Data Model Manager
amxd_function.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(__AMXD_FUNCTION_H__)
56 #define __AMXD_FUNCTION_H__
57 
58 #ifdef __cplusplus
59 extern "C"
60 {
61 #endif
62 
63 #include <stdint.h>
64 #include <amxd/amxd_types.h>
65 
66 
77 typedef void (* amxd_deferred_cancel_t) (uint64_t call_id, void* const priv);
78 
124  const char* name,
125  const uint32_t ret_type,
126  amxd_object_fn_t impl);
127 
144 
166  const amxd_function_t* const source);
167 
190 
191 
208 
228  amxd_object_t* const object,
229  amxc_var_t* const args,
230  amxc_var_t* const ret);
231 
244 const char* amxd_function_get_name(const amxd_function_t* const func);
245 
259 static inline
260 uint32_t amxd_function_get_type(const amxd_function_t* const func) {
261  return func == NULL ? AMXC_VAR_ID_NULL : func->ret_type;
262 }
263 
287  const amxd_fattr_id_t attr,
288  const bool enable);
289 
326  const uint32_t bitmask,
327  bool enable);
328 
353 uint32_t amxd_function_get_attrs(const amxd_function_t* const func);
354 
372 bool amxd_function_is_attr_set(const amxd_function_t* const func,
373  const amxd_fattr_id_t attr);
374 
391 void amxd_function_set_flag(amxd_function_t* func, const char* flag);
392 
409 void amxd_function_unset_flag(amxd_function_t* func, const char* flag);
410 
430 bool amxd_function_has_flag(const amxd_function_t* const func, const char* flag);
431 
462  amxd_object_fn_t impl);
463 
481  amxc_var_t* const value);
482 
517  uint64_t* call_id,
518  amxc_var_t* const ret,
519  amxd_deferred_cancel_t cancel_fn,
520  void* priv);
521 
538 
553 
574  amxp_deferred_fn_t cb,
575  void* priv);
576 
600  amxc_var_t* out_args,
601  amxc_var_t* ret);
602 
625  amxc_var_t* out_args,
626  amxc_var_t* ret);
642  const char* name,
643  const uint32_t type,
644  amxc_var_t* default_value);
645 
654 void amxd_function_del_arg(amxd_function_t* func, const char* name);
655 
669  const char* name);
670 
691  const char* name,
692  const amxd_aattr_id_t attr,
693  const bool enable);
694 
729  const char* name,
730  const uint32_t bitmask,
731  bool enable);
732 
751 bool amxd_function_arg_is_attr_set(const amxd_function_t* const func,
752  const char* name,
753  const amxd_aattr_id_t attr);
754 
772  amxc_var_t* const value);
773 
804  amxc_var_t* args);
805 
806 #ifdef __cplusplus
807 }
808 #endif
809 
810 #endif // __AMXD_FUNCTION_H__
void(* amxd_deferred_cancel_t)(uint64_t call_id, void *const priv)
Definition: amxd_function.h:77
enum _amxd_status amxd_status_t
amxd_status_t(* amxd_object_fn_t)(amxd_object_t *object, amxd_function_t *func, amxc_var_t *args, amxc_var_t *ret)
Definition: amxd_types.h:272
enum _amxd_fattr_id amxd_fattr_id_t
The method attributes.
enum _amxd_aattr_id amxd_aattr_id_t
The method argument attributes.
amxd_status_t amxd_function_deferred_call_done(uint64_t call_id, amxd_status_t status, amxc_var_t *out_args, amxc_var_t *ret)
Finishes a deferred method and removes the deferred function context.
amxd_status_t amxd_function_set_attr(amxd_function_t *func, const amxd_fattr_id_t attr, const bool enable)
Sets or unsets a method attribute.
amxd_status_t amxd_function_describe(amxd_function_t *const func, amxc_var_t *const value)
Fetches the full RPC method definition in a variant.
const char * amxd_function_get_name(const amxd_function_t *const func)
Get the name of a method.
void amxd_function_delete(amxd_function_t **func)
Data model RPC method destructor function.
amxd_status_t amxd_function_arg_set_attr(amxd_function_t *const func, const char *name, const amxd_aattr_id_t attr, const bool enable)
Sets or unsets a method argument attribute.
amxd_func_arg_t * amxd_function_get_arg(const amxd_function_t *const func, const char *name)
Gets the argument definition of a RPC method.
bool amxd_function_arg_is_attr_set(const amxd_function_t *const func, const char *name, const amxd_aattr_id_t attr)
Checks if a method argument attribute is set.
amxd_status_t amxd_function_arg_describe(amxd_func_arg_t *const arg, amxc_var_t *const value)
Fetches the argument definition in a variant.
void amxd_function_deferred_remove(uint64_t call_id)
Removes a deferred RPC context.
amxd_object_t * amxd_function_get_owner(const amxd_function_t *const func)
Get the object pointer of the object containing the function definition.
static uint32_t amxd_function_get_type(const amxd_function_t *const func)
Gets the return type of a method.
void amxd_function_unset_flag(amxd_function_t *func, const char *flag)
Removes a flag from a function.
amxd_status_t amxd_function_defer(const amxd_function_t *const func, uint64_t *call_id, amxc_var_t *const ret, amxd_deferred_cancel_t cancel_fn, void *priv)
Creates a deferred RPC context.
amxd_status_t amxd_function_new(amxd_function_t **func, const char *name, const uint32_t ret_type, amxd_object_fn_t impl)
Data model RPC method constructor function.
amxd_status_t amxd_function_call_base(const amxd_function_t *const func, amxd_object_t *const object, amxc_var_t *const args, amxc_var_t *const ret)
Call the base function of an overridden function.
amxd_status_t amxd_function_deferred_done(uint64_t call_id, amxd_status_t status, amxc_var_t *out_args, amxc_var_t *ret)
Finishes a deferred method and removes the deferred function context.
void amxd_function_del_arg(amxd_function_t *func, const char *name)
Removes an argument definition from a RPC method definition.
amxd_status_t amxd_function_set_attrs(amxd_function_t *func, const uint32_t bitmask, bool enable)
Sets or unsets method attributes using a bitmap.
amxd_status_t amxd_function_set_deferred_cb(uint64_t call_id, amxp_deferred_fn_t cb, void *priv)
Sets a callback function to get the result of the deferred call.
amxd_status_t amxd_function_copy(amxd_function_t **dest, const amxd_function_t *const source)
Data model RPC method copy constructor function.
bool amxd_function_are_args_valid(amxd_function_t *func, amxc_var_t *args)
Validates that the input arguments are valid.
bool amxd_function_is_attr_set(const amxd_function_t *const func, const amxd_fattr_id_t attr)
Checks if a method attribute is set.
void * amxd_function_deferred_get_priv(uint64_t call_id)
Gets the callee private data of an deferred function.
bool amxd_function_has_flag(const amxd_function_t *const func, const char *flag)
Checks if a flag is set.
void amxd_function_set_flag(amxd_function_t *func, const char *flag)
Sets a flag on a function.
uint32_t amxd_function_get_attrs(const amxd_function_t *const func)
Gets the set attributes of a RPC method.
amxd_function_t * amxd_function_get_base(const amxd_function_t *const func)
Get the base function definition of an overridden function.
amxd_status_t amxd_function_new_arg(amxd_function_t *func, const char *name, const uint32_t type, amxc_var_t *default_value)
Adds an argument definition to a RPC method definition.
amxd_status_t amxd_function_arg_set_attrs(amxd_function_t *func, const char *name, const uint32_t bitmask, bool enable)
Sets or unsets method argument attributes using a bitmap.
amxd_status_t amxd_function_set_impl(amxd_function_t *const func, amxd_object_fn_t impl)
Set an implementation for a RPC method.
RPC method structure.
Definition: amxd_types.h:341
uint32_t ret_type
Definition: amxd_types.h:345
static amxd_status_t status
static uint64_t call_id