libamxp  1.4.0
Patterns C Implementation
variant_siginfo.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 #include <string.h>
57 
58 #include <amxc/amxc_macros.h>
59 #include <amxc/amxc.h>
60 #include <amxp/variant_siginfo.h>
61 
62 static int variant_siginfo_init(amxc_var_t* const var) {
63  int retval = -1;
64  amxp_siginfo_t* var_siginfo = (amxp_siginfo_t*) calloc(1, sizeof(amxp_siginfo_t));
65  when_null(var_siginfo, exit);
66 
67  var->data.data = var_siginfo;
68  retval = 0;
69 
70 exit:
71  return retval;
72 }
73 
74 static void variant_siginfo_delete(amxc_var_t* var) {
75  amxp_siginfo_t* var_siginfo = (amxp_siginfo_t*) var->data.data;
76  var->data.data = NULL;
77  free(var_siginfo);
78 }
79 
80 static int variant_siginfo_copy(amxc_var_t* const dest,
81  const amxc_var_t* const src) {
82  int retval = -1;
83  const amxp_siginfo_t* src_var_siginfo = (amxp_siginfo_t*) src->data.data;
84  amxp_siginfo_t* dest_var_siginfo = (amxp_siginfo_t*) dest->data.data;
85 
86  memcpy(dest_var_siginfo, src_var_siginfo, sizeof(amxp_siginfo_t));
87 
88  retval = 0;
89 
90  return retval;
91 }
92 
93 static int variant_siginfo_move(amxc_var_t* const dest,
94  amxc_var_t* const src) {
95  dest->data = src->data;
96  src->data.data = NULL;
97  return 0;
98 }
99 
100 static amxc_var_type_t variant_siginfo = {
101  .init = variant_siginfo_init,
102  .del = variant_siginfo_delete,
103  .copy = variant_siginfo_copy,
104  .move = variant_siginfo_move,
105  .convert_from = NULL,
106  .convert_to = NULL,
107  .compare = NULL,
108  .get_key = NULL,
109  .set_key = NULL,
110  .get_index = NULL,
111  .set_index = NULL,
112  .type_id = 0,
113  .hit = { .ait = NULL, .key = NULL, .next = NULL },
114  .name = AMXC_VAR_NAME_SIGINFO
115 };
116 
117 CONSTRUCTOR_LVL(200) static void variant_siginfo_register(void) {
118  amxc_var_register_type(&variant_siginfo);
119 }
120 
121 DESTRUCTOR_LVL(200) static void variant_siginfo_unregister(void) {
122  amxc_var_unregister_type(&variant_siginfo);
123 }
124 
125 const amxp_siginfo_t* amxc_var_get_const_amxp_siginfo_t(const amxc_var_t* const var) {
126  const amxp_siginfo_t* retval = NULL;
127 
128 
129  when_null(var, exit);
130  when_true(var->type_id != AMXC_VAR_ID_SIGINFO, exit);
131 
132  retval = (amxp_siginfo_t*) var->data.data;
133 exit:
134  return retval;
135 
136 }
137 
138 int amxc_var_set_amxp_siginfo_t(amxc_var_t* const var, const amxp_siginfo_t* const val) {
139  int retval = -1;
140 
141  when_null(var, exit);
142  when_null(val, exit);
143  when_failed(amxc_var_set_type(var, AMXC_VAR_ID_SIGINFO), exit);
144 
145  memcpy(var->data.data, val, sizeof(amxp_siginfo_t));
146 
147  retval = 0;
148 
149 exit:
150  return retval;
151 }
152 
static amxc_var_type_t variant_siginfo
int amxc_var_set_amxp_siginfo_t(amxc_var_t *const var, const amxp_siginfo_t *const val)
static int variant_siginfo_copy(amxc_var_t *const dest, const amxc_var_t *const src)
DESTRUCTOR_LVL(200)
static void variant_siginfo_delete(amxc_var_t *var)
static int variant_siginfo_move(amxc_var_t *const dest, amxc_var_t *const src)
CONSTRUCTOR_LVL(200)
const amxp_siginfo_t * amxc_var_get_const_amxp_siginfo_t(const amxc_var_t *const var)
static int variant_siginfo_init(amxc_var_t *const var)
struct signalfd_siginfo amxp_siginfo_t
#define AMXC_VAR_NAME_SIGINFO
#define AMXC_VAR_ID_SIGINFO