Adaptive Framework  0.9.0
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
afw_object_meta_accessor.c
Go to the documentation of this file.
1 // See the 'COPYING' file in the project root for licensing information.
2 /*
3  * Interface afw_object Implementation for meta accessor
4  *
5  * Copyright (c) 2010-2023 Clemson University
6  *
7  */
8 
9 
15 #include "afw_internal.h"
16 
17 
18 #define impl_afw_object_get_meta \
19  afw_object_impl_internal_get_meta
20 
21 #define impl_afw_object_get_property_meta \
22  afw_object_impl_internal_get_property_meta
23 
24 #define impl_afw_object_get_next_property_meta \
25  afw_object_impl_internal_get_next_property_meta
26 
27 
28 /* Declares and rti/inf defines for interface afw_object */
29 #define AFW_IMPLEMENTATION_ID "afw_object_meta_accessor"
31 
32 
33 
34 /* Create an object instance to access an object meta with options. */
35 AFW_DEFINE(const afw_object_t *)
37  const afw_object_t *instance,
38  const afw_object_options_t *options,
39  const afw_pool_t *p,
40  afw_xctx_t *xctx)
41 {
43  const afw_iterator_t *iterator;
44  const afw_utf8_t *property_name;
45 
46  /* If instance of this implementation with no meta, return NULL. */
47  if (!instance->meta.meta_object && instance->inf == &impl_afw_object_inf)
48  {
49  return NULL;
50  }
51 
52  /* Create self. */
54  self->pub.inf = &impl_afw_object_inf;
55  self->pub.p = p;
56  self->options = options;
57  self->instance = instance;
58  self->embedded = (instance->meta.embedding_object != NULL);
59  self->limited_meta = !afw_object_meta_object(self->instance) ||
60  AFW_OBJECT_OPTION_IS(self->options, metaLimited);
61 
62  /* If there are no properties to return, return NULL. */
63  iterator = NULL;
64  if (!impl_afw_object_get_next_property((afw_object_t *)self,
65  &iterator, &property_name, xctx))
66  {
67  return NULL;
68  }
69  self->iterator = NULL;
70 
71  /* Return new instance. */
72  return (afw_object_t *)self;
73 }
74 
75 
76 /*
77  * Implementation of method release of interface afw_object.
78  */
79 void
81  const afw_object_t *instance,
82  afw_xctx_t *xctx)
83 {
84  /* Nothing to do. */
85 }
86 
87 
88 
89 /*
90  * Implementation of method add_reference of interface afw_object.
91  */
92 void
93 impl_afw_object_add_reference(
94  const afw_object_t *instance,
95  afw_xctx_t *xctx)
96 {
97  /* There is no intent to implement this method. */
98  AFW_THROW_ERROR_Z(general, "Method not implemented.", xctx);
99 }
100 
101 /*
102  * Implementation of method get_count for interface afw_object.
103  */
106  const afw_object_t * instance,
107  afw_xctx_t * xctx)
108 {
109 // <afwdev {prefixed_interface_name}>_self_t *self =
110 // (<afwdev {prefixed_interface_name}>_self_t *)instance;
111 
113  AFW_THROW_ERROR_Z(general, "Method not implemented.", xctx);
114 
115 }
116 
117 
118 /*
119  * Implementation of method get_property of interface afw_object.
120  */
121 const afw_value_t *
123  const afw_object_t *instance,
124  const afw_utf8_t *property_name,
125  afw_xctx_t *xctx)
126 {
127  /* There is no intent to implement this method. */
128  AFW_THROW_ERROR_Z(general, "Method not implemented.", xctx);
129 }
130 
131 
132 
133 /*
134  * Implementation of method get_next_property of interface afw_object.
135  */
136 const afw_value_t *
137 impl_afw_object_get_next_property(
138  const afw_object_t *instance,
139  const afw_iterator_t **iterator,
140  const afw_utf8_t **property_name,
141  afw_xctx_t *xctx)
142 {
145  const afw_pool_t *p = self->pub.p;
146  const afw_value_t *result = NULL;
147  const afw_utf8_t *s;
148  int state;
149 
150  /*
151  * Note: The options are fairly simple atm. If there is an option added
152  * to merge in associated _AdaptiveObjectType_ properties, multiple
153  * internal iterators will be needed.
154  */
155 
156  /* Initial state is 0 and after that iterator holds state. */
157  if (!*iterator) {
158  *iterator = afw_pool_calloc(self->pub.p, sizeof(int), xctx);
159  }
160  state = *(int *)* iterator;
161 
162  /* Process state. */
163  for (;;) {
164  switch (state) {
165 
166  /* Initial state. */
167  case 0:
168 
169  /* Next state is 1 or 2 depending on limited_meta. */
170  state = (!self->limited_meta) ? 1 : 2;
171 
172  /* If limited_data, always provide parentPaths. */
173  if (self->limited_meta && afw_object_meta_object(self->instance)) {
174  result = afw_object_get_property(
175  afw_object_meta_object(self->instance), &afw_s_parentPaths,
176  xctx);
177  if (result) {
178  if (property_name) {
179  *property_name = &afw_s_parentPaths;
180  }
181  goto return_result;
182  }
183  }
184 
185  /* Next state. */
186  break;
187 
188  /* Not limited meta. Just return all properties in meta and end. */
189  case 1:
190 
192  afw_object_meta_object(self->instance),
193  &self->iterator, property_name, xctx);
194  if (result) {
195  goto return_result;
196  }
197  state = 5;
198 
199  /* options = objectId. */
200  case 2:
201 
202  /* Next state is 3. */
203  state = 3;
204 
205  /* If not already returned by fullMetaObject, return value. */
206  if (!self->embedded &&
207  AFW_OBJECT_OPTION_IS(self->options, objectId))
208  {
209  if (self->limited_meta ||
211  afw_object_meta_object(self->instance),
212  &afw_s_objectId, xctx))
213  {
214  s = afw_object_meta_get_object_id(self->instance, xctx);
215  if (s) {
216  if (property_name) {
217  *property_name = &afw_s_objectId;
218  }
219  result = afw_value_create_string(s, p, xctx);
220  goto return_result;
221  }
222  }
223  }
224 
225 
226  /* options = objectType. */
227  case 3:
228 
229  /* Next state is 4. */
230  state = 4;
231 
232  /*
233  * If option objectType or metaLimited and this is an embedded
234  * object, set meta objectType, return value.
235  */
236  if (AFW_OBJECT_OPTION_IS(self->options, objectType) ||
237  (self->limited_meta && self->instance->meta.embedding_object))
238  {
239  if (self->limited_meta ||
241  afw_object_meta_object(self->instance),
242  &afw_s_objectType, xctx))
243  {
244  s = afw_object_meta_get_object_type_id(self->instance,
245  xctx);
246  if (s) {
247  if (property_name) {
248  *property_name = &afw_s_objectType;
249  }
250  result = afw_value_create_string(s, p, xctx);
251  goto return_result;
252  }
253  }
254  }
255 
256 
257  /* options = path and pathEmbedded. */
258  case 4:
259 
260  /* Next state is 5. */
261  state = 5;
262 
263  /* If not already returned by fullMetaObject, return value. */
264  if ((!self->embedded &&
265  AFW_OBJECT_OPTION_IS(self->options, path))
266  ||
267  (self->embedded &&
268  AFW_OBJECT_OPTION_IS(self->options, pathEmbedded))
269  )
270  {
271  if (self->limited_meta ||
273  afw_object_meta_object(self->instance), &afw_s_path, xctx))
274  {
275  s = afw_object_meta_get_path(self->instance, xctx);
276  if (s) {
277  if (property_name) {
278  *property_name = &afw_s_path;
279  }
280  result = afw_value_create_string(s, p, xctx);
281  goto return_result;
282  }
283  }
284  }
285 
286 
287  /* Nothing left. */
288  default:
289  result = NULL;
290  goto return_result;
291  }
292  }
293 
294 
295  /* Return result. */
296 return_result:
297  if (!result) {
298  *iterator = NULL;
299  }
300  else {
301  *(int *)*iterator = state;
302  }
303  return result;
304 }
305 
306 
307 
308 /*
309  * Implementation of method has_property of interface afw_object.
310  */
312 impl_afw_object_has_property(
313  const afw_object_t *instance,
314  const afw_utf8_t *property_name,
315  afw_xctx_t *xctx)
316 {
317  /* There is no intent to implement this method. */
318  AFW_THROW_ERROR_Z(general, "Method not implemented.", xctx);
319 }
320 
321 
322 
323 /*
324  * Implementation of method get_setter of interface afw_object.
325  */
326 const afw_object_setter_t *
327 impl_afw_object_get_setter(
328  const afw_object_t *instance,
329  afw_xctx_t *xctx)
330 {
331  /* There is no intent to implement this method. */
332  AFW_THROW_ERROR_Z(general, "Method not implemented.", xctx);
333 }
AFW_DEFINE(const afw_object_t *)
Adaptive Framework Core Internal.
Interface afw_interface implementation declares.
afw_value_create_string(const afw_utf8_t *internal, const afw_pool_t *p, afw_xctx_t *xctx)
Create function for unmanaged data type string value.
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
#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
void impl_afw_object_release(const afw_object_t *instance, afw_xctx_t *xctx)
const afw_value_t * impl_afw_object_get_property(const afw_object_t *instance, const afw_utf8_t *property_name, afw_xctx_t *xctx)
afw_size_t impl_afw_object_get_count(const afw_object_t *instance, afw_xctx_t *xctx)
#define afw_object_get_property(instance, property_name, xctx)
Call method get_property of interface afw_object.
#define afw_object_get_next_property(instance, iterator, property_name, xctx)
Call method get_next_property of interface afw_object.
#define afw_object_has_property(instance, property_name, xctx)
Call method has_property of interface afw_object.
#define afw_object_meta_get_object_type_id(instance, xctx)
Get object's object_type_id.
afw_object_meta_get_path(const afw_object_t *instance, afw_xctx_t *xctx)
Get an object's path.
#define afw_object_meta_object(instance)
Return meta object for an object or NULL if there is not one.
afw_object_meta_create_accessor_with_options(const afw_object_t *instance, const afw_object_options_t *options, const afw_pool_t *p, afw_xctx_t *xctx)
Create an object instance to access an object's meta with options.
afw_object_meta_get_object_id(const afw_object_t *instance, afw_xctx_t *xctx)
Get entity object's object id.
#define AFW_OBJECT_OPTION_IS(_options, _option)
Test mask.
#define afw_pool_calloc(instance, size, xctx)
Call method calloc of interface afw_pool.
#define afw_pool_calloc_type(instance, type, xctx)
Macro to allocate cleared memory to hold type in pool.
Definition: afw_pool.h:167
Struct for object processing options.
Interface afw_object public struct.
Interface afw_object_setter public struct.
Interface afw_pool public struct.
NFC normalized UTF-8 string.
Definition: afw_common.h:545
Interface afw_value public struct.
Interface afw_xctx public struct.