Adaptive Framework  0.9.0
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
afw_environment_registry_object.c
Go to the documentation of this file.
1 // See the 'COPYING' file in the project root for licensing information.
2 /*
3  * Implementation of afw_object interface for _AdaptiveEnvironmentRegistry_
4  *
5  * Copyright (c) 2010-2023 Clemson University
6  *
7  */
8 
9 
16 #include "afw_internal.h"
17 
18 
19 #define impl_afw_object_get_meta \
20  afw_object_impl_internal_get_meta
21 
22 #define impl_afw_object_get_property_meta \
23  afw_object_impl_internal_get_property_meta
24 
25 #define impl_afw_object_get_next_property_meta \
26  afw_object_impl_internal_get_next_property_meta
27 
28 /* Declares and rti/inf defines for interface afw_object */
29 #define AFW_IMPLEMENTATION_ID "afw_environment_registry"
31 
32 static const afw_utf8_t impl_path =
33 AFW_UTF8_LITERAL("/afw/_AdaptiveEnvironmentRegistry_/current");
34 
35 static const afw_object_t
36 impl_current_object = {
37  &impl_afw_object_inf,
38  NULL,
39  {
40  NULL,
41  NULL,
42  &afw_s_current,
43  &afw_s__AdaptiveEnvironmentRegistry_,
44  &impl_path
45  }
46 };
47 
48 
49 
50 /* Get current environment registry object. */
51 AFW_DEFINE(const afw_object_t *)
53 {
54  return &impl_current_object;
55 }
56 
57 
58 
59 /*
60  * Implementation of method release of interface afw_object.
61  */
62 void
63 impl_afw_object_release (
64  const afw_object_t * instance,
65  afw_xctx_t *xctx)
66 {
67  /* Nothing to do. */
68 }
69 
70 
71 
72 /*
73  * Implementation of method add_reference of interface afw_object.
74  */
75 void
76 impl_afw_object_add_reference (
77  const afw_object_t * instance,
78  afw_xctx_t *xctx)
79 {
80  /* Nothing to do. */
81 }
82 
83 /*
84  * Implementation of method get_count for interface afw_object.
85  */
88  const afw_object_t * instance,
89  afw_xctx_t * xctx)
90 {
91 // <afwdev {prefixed_interface_name}>_self_t *self =
92 // (<afwdev {prefixed_interface_name}>_self_t *)instance;
93 
95  AFW_THROW_ERROR_Z(general, "Method not implemented.", xctx);
96 
97 }
98 
99 
100 
101 static afw_boolean_t
102 impl_entry_cb(
103  const afw_object_t *object,
104  void *context,
105  afw_xctx_t *xctx)
106 {
107  const afw_object_t *entries = (const afw_object_t *)context;
108  const afw_utf8_t *property_name;
109 
110  if (object) {
111  property_name = afw_object_meta_get_object_id(object, xctx);
112  afw_object_set_property_as_object(entries, property_name,
113  object, xctx);
114  }
115 
116  return false;
117 }
118 
119 
120 
121 static const afw_value_t *
122 impl_make_registry_type_value(
123  const afw_utf8_t * object_type_id,
124  afw_xctx_t *xctx)
125 {
126  const afw_object_t *entries;
127 
128  entries = afw_object_create_managed(xctx->p, xctx);
129 
130  afw_runtime_foreach(object_type_id, (void *)entries,
131  impl_entry_cb, xctx);
132 
133  return afw_value_create_object(entries, xctx->p, xctx);
134 }
135 
136 
137 
138 /*
139  * Implementation of method get_property of interface afw_object.
140  */
141 const afw_value_t *
142 impl_afw_object_get_property (
143  const afw_object_t * instance,
144  const afw_utf8_t * property_name,
145  afw_xctx_t *xctx)
146 {
148 
150  property_name, xctx);
151 
152  return (type && type->object_type_id)
153  ? impl_make_registry_type_value(type->object_type_id, xctx)
154  : NULL;
155 }
156 
157 
158 
159 /*
160  * Implementation of method get_next_property of interface afw_object.
161  */
162 const afw_value_t *
163 impl_afw_object_get_next_property (
164  const afw_object_t * instance,
165  const afw_iterator_t * * iterator,
166  const afw_utf8_t * * property_name,
167  afw_xctx_t *xctx)
168 {
169  int registry_type_number;
170  const afw_value_t *result = NULL;
171  const afw_environment_registry_type_t *registry_type;
172 
173  for (
174  registry_type_number = (int)(*((char **)iterator) - (char *)0);
175 
177  registry_type_number, xctx));
178 
179  registry_type_number++)
180  {
181  if (registry_type->object_type_id) {
182  result = impl_make_registry_type_value(
183  registry_type->object_type_id, xctx);
184  break;
185  }
186  }
187 
188  if (registry_type) {
189  *(char **)iterator = (char *)0 + registry_type_number + 1;
190  if (property_name) {
191  *property_name = registry_type->property_name;
192  }
193  }
194  else {
195  *iterator = NULL;
196  result = NULL;
197  if (property_name) {
198  *property_name = NULL;
199  }
200  }
201 
202  return result;
203 }
204 
205 
206 
207 /*
208  * Implementation of method has_property of interface afw_object.
209  */
211 impl_afw_object_has_property (
212  const afw_object_t * instance,
213  const afw_utf8_t * property_name,
214  afw_xctx_t *xctx)
215 {
216  return impl_afw_object_get_property(instance, property_name, xctx) != NULL;
217 }
218 
219 
220 
221 /*
222  * Implementation of method get_setter of interface afw_object.
223  */
224 const afw_object_setter_t *
225 impl_afw_object_get_setter (
226  const afw_object_t * instance,
227  afw_xctx_t *xctx)
228 {
229  /* Immutable. */
230  return NULL;
231 }
AFW_DEFINE(const afw_object_t *)
Adaptive Framework Core Internal.
Interface afw_interface implementation declares.
afw_object_set_property_as_object(const afw_object_t *object, const afw_utf8_t *property_name, const afw_object_t *internal, afw_xctx_t *xctx)
Set property function for data type object values.
afw_value_create_object(const afw_object_t *internal, const afw_pool_t *p, afw_xctx_t *xctx)
Create function for unmanaged data type object value.
#define AFW_UTF8_LITERAL(A_STRING)
String literal initializer.
Definition: afw_common.h:582
struct afw_iterator_s afw_iterator_t
_Bool afw_boolean_t
Definition: afw_common.h:373
apr_size_t afw_size_t
size_t.
Definition: afw_common.h:151
const afw_environment_registry_type_t * afw_environment_get_registry_type(const afw_utf8_t *property_name, afw_xctx_t *xctx)
Get the registry type associated with property name.
afw_environment_get_registry_type_by_number(int registry_type_number, afw_xctx_t *xctx)
Get the registry type associated with a registry type number.
afw_environment_registry_object_get_current(afw_xctx_t *xctx)
Get current environment registry object.
#define AFW_THROW_ERROR_Z(code, message_z, xctx)
Macro used to set error and 0 rv in xctx and throw it.
Definition: afw_error.h:283
afw_size_t impl_afw_object_get_count(const afw_object_t *instance, afw_xctx_t *xctx)
afw_object_meta_get_object_id(const afw_object_t *instance, afw_xctx_t *xctx)
Get entity object's object id.
#define afw_object_create_managed(p, xctx)
Create an empty entity object in its own pool.
Definition: afw_object.h:913
afw_runtime_foreach(const afw_utf8_t *object_type_id, void *context, afw_object_cb_t callback, afw_xctx_t *xctx)
Call a callback for each runtime object.
Definition: afw_runtime.c:900
Interface afw_object public struct.
Interface afw_object_setter public struct.
NFC normalized UTF-8 string.
Definition: afw_common.h:545
Interface afw_value public struct.
Interface afw_xctx public struct.