libamxd  6.4.1
Data Model Manager
amxd_path.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_PATH_H__)
56 #define __AMXD_PATH_H__
57 
58 #ifdef __cplusplus
59 extern "C"
60 {
61 #endif
62 
134  const char* object_path);
135 
145 void amxd_path_clean(amxd_path_t* path);
146 
166  const char* object_path);
167 
180 void amxd_path_delete(amxd_path_t** path);
181 
189 void amxd_path_reset(amxd_path_t* path);
190 
209  bool add_dot,
210  const char* obj_path,
211  va_list args);
212 
239  bool add_dot,
240  const char* obj_path, ...) \
241  __attribute__ ((format(printf, 3, 4)));
242 
260 amxd_status_t amxd_path_append(amxd_path_t* path, const char* extension, bool add_dot);
261 
279 amxd_status_t amxd_path_prepend(amxd_path_t* path, const char* extension);
280 
299 const char* amxd_path_get(amxd_path_t* path, int flags);
300 
314 const char* amxd_path_get_param(amxd_path_t* path);
315 
335 char* amxd_path_get_first(amxd_path_t* path, bool remove);
336 
359 char* amxd_path_get_last(amxd_path_t* path, bool remove);
360 
383 char* amxd_path_get_fixed_part(amxd_path_t* path, bool remove);
384 
408 
433 char* amxd_path_get_reference_part(amxd_path_t* path, bool remove);
434 
460 
477 
492 uint32_t amxd_path_get_depth(const amxd_path_t* const path);
493 
506 static inline
508  return path == NULL ? amxd_path_invalid : path->type;
509 }
510 
525 static inline
527  return path == NULL ? false : (path->type != amxd_path_invalid);
528 }
529 
543 static inline
545  return path == NULL ? false : (path->type == amxd_path_search);
546 }
547 
561 static inline
563  return path == NULL ? false : (path->type == amxd_path_supported);
564 }
565 
578 static inline
580  return path == NULL ? false : (path->type == amxd_path_object);
581 }
582 
596 bool amxd_path_is_instance_path(const amxd_path_t* const path);
597 
612 
613 #ifdef __cplusplus
614 }
615 #endif
616 
617 #endif // __AMXD_PATH_H__
618 
enum _amxd_path_type amxd_path_type_t
enum _amxd_status amxd_status_t
@ amxd_path_invalid
Definition: amxd_types.h:399
@ amxd_path_supported
Definition: amxd_types.h:402
@ amxd_path_search
Definition: amxd_types.h:401
@ amxd_path_object
Definition: amxd_types.h:400
void amxd_path_delete(amxd_path_t **path)
Frees an allocated amxd_path_t structure.
Definition: amxd_path.c:378
amxd_status_t amxd_path_init(amxd_path_t *path, const char *object_path)
Initializes an amxd_path_t structure.
Definition: amxd_path.c:328
static bool amxd_path_is_object_path(amxd_path_t *path)
Checks if the path is an object path.
Definition: amxd_path.h:579
char * amxd_path_build_supported_path(amxd_path_t *path)
Creates the supported path representation of the given path.
Definition: amxd_path.c:699
const char * amxd_path_get_param(amxd_path_t *path)
Gets the parameter name.
Definition: amxd_path.c:497
uint32_t amxd_path_get_depth(const amxd_path_t *const path)
Calculates the depth of the path.
Definition: amxd_path.c:733
static bool amxd_path_is_supported_path(amxd_path_t *path)
Checks if the path is in the supported data model.
Definition: amxd_path.h:562
static bool amxd_path_is_valid(amxd_path_t *path)
Checks if the path is valid path.
Definition: amxd_path.h:526
char * amxd_path_get_first(amxd_path_t *path, bool remove)
Gets the first part of the path.
Definition: amxd_path.c:501
static bool amxd_path_is_search_path(amxd_path_t *path)
Checks if the path is a search path.
Definition: amxd_path.h:544
char * amxd_path_get_last(amxd_path_t *path, bool remove)
Gets the last part of the path.
Definition: amxd_path.c:531
char * amxd_path_get_reference_part(amxd_path_t *path, bool remove)
Returns the reference path.
Definition: amxd_path.c:640
bool amxd_path_is_instance_path(const amxd_path_t *const path)
Checks if the path is in the instantiated data model.
Definition: amxd_path.c:753
amxd_status_t amxd_status_t amxd_path_append(amxd_path_t *path, const char *extension, bool add_dot)
Appends a parameter name or object name/index to the path.
Definition: amxd_path.c:441
amxd_status_t amxd_path_new(amxd_path_t **path, const char *object_path)
Allocates and initializes an amxd_path_t structure.
Definition: amxd_path.c:365
const char * amxd_path_get(amxd_path_t *path, int flags)
Returns the path stored in the amxd_path_t structure.
Definition: amxd_path.c:470
char * amxd_path_get_supported_path(amxd_path_t *path)
Translates the path into a path that can be used to fetch the object definition.
Definition: amxd_path.c:611
amxd_status_t amxd_path_prepend(amxd_path_t *path, const char *extension)
Prepends an object name/index to the path.
Definition: amxd_path.c:456
char * amxd_path_get_param_path(amxd_path_t *path)
Get the full parameter path from the provided amxd_path_t struct.
Definition: amxd_path.c:787
void amxd_path_clean(amxd_path_t *path)
Cleans an amxd_path_t structure.
Definition: amxd_path.c:351
amxd_status_t amxd_path_setf(amxd_path_t *path, bool add_dot, const char *obj_path,...) __attribute__((format(printf
Sets or replaces the path contained in the amxd_path_t structure.
static amxd_path_type_t amxd_path_get_type(amxd_path_t *path)
Returns the path type.
Definition: amxd_path.h:507
uint32_t amxd_path_get_reference_index(amxd_path_t *path)
Returns the reference path index.
Definition: amxd_path.c:689
amxd_status_t amxd_path_vsetf(amxd_path_t *path, bool add_dot, const char *obj_path, va_list args)
Sets or replaces the path contained in the amxd_path_t structure.
Definition: amxd_path.c:403
void amxd_path_reset(amxd_path_t *path)
Resets the amxd_path_t structure.
Definition: amxd_path.c:389
char * amxd_path_get_fixed_part(amxd_path_t *path, bool remove)
Gets the fixed part of the path.
Definition: amxd_path.c:576
amxd_path_type_t type
Definition: amxd_types.h:410