Adaptive Framework  0.9.0
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
afw_adaptor_get.c
1 // See the 'COPYING' file in the project root for licensing information.
2 /*
3  * Adaptive Framework Adaptor Add Object
4  *
5  * Copyright (c) 2010-2023 Clemson University
6  *
7  */
8 
14 #include "afw_internal.h"
15 
16 
17 /* Get object callback. */
18 static afw_boolean_t
19 impl_get_object_cb(
20  const afw_object_t *object,
21  void *context,
22  afw_xctx_t *xctx)
23 {
25  const afw_object_t *adapted_object;
26  const afw_object_t *view;
27 
28  /* Process object from adaptor and cache it. */
29  view = object;
30  if (object) {
32  &adapted_object, &view, ctx, object, ctx->p, xctx);
33  }
34 
35  *(const afw_object_t **)ctx->original_context = view;
36 
37  /* Return indicating not to short circuit */
38  return false;
39 }
40 
41 
42 
43 /* Get and cache object. */
44 AFW_DEFINE(const afw_object_t *)
46  const afw_utf8_t *adaptor_id,
47  const afw_utf8_t *object_type_id,
48  const afw_utf8_t *object_id,
49  const afw_object_options_t *options,
50  const afw_query_criteria_t *criteria,
51  const afw_object_t *journal_entry,
52  const afw_object_t *adaptor_type_specific,
53  const afw_pool_t *p,
54  afw_xctx_t *xctx)
55 {
56  const afw_adaptor_session_t *session;
58  const afw_object_t *obj;
59  const afw_object_t *request;
60  afw_adaptor_impl_t *impl;
61  afw_adaptor_impl_request_t impl_request;
62 
63 
64  /* Set request in journal entry. */
65  afw_memory_clear(&impl_request);
66  impl_request.request = request = afw_object_create_embedded(
67  journal_entry, &afw_s_request, xctx);
68  impl_request.p = request->p;
69  impl_request.journal_entry = journal_entry;
70  impl_request.resource_id = afw_utf8_printf(impl_request.p, xctx,
71  "/"
72  "%" AFW_UTF8_FMT "/"
73  "%" AFW_UTF8_FMT "/"
74  "%" AFW_UTF8_FMT,
75  AFW_UTF8_FMT_ARG(adaptor_id),
76  AFW_UTF8_FMT_ARG(object_type_id),
77  AFW_UTF8_FMT_ARG(object_id));
79  &afw_s_resourceId, impl_request.resource_id, xctx);
80  impl_request.options = options;
82  &afw_s_function, &afw_s_get_object, xctx);
84  &afw_s_adaptorId, adaptor_id, xctx);
86  &afw_s_objectType, object_type_id, xctx);
88  &afw_s_objectId, object_id, xctx);
89 
90  /* Get an active session with adaptor. */
91  session = afw_adaptor_session_get_cached(adaptor_id, false, xctx);
92  impl = (afw_adaptor_impl_t *)session->adaptor->impl;
93 
94  /* Initialize context. */
95  afw_memory_clear(&ctx);
96  ctx.p = p;
97  ctx.session = session;
98  ctx.impl = impl;
99  ctx.adaptor_id = adaptor_id;
100  ctx.object_type_id = object_type_id;
101  ctx.object_id = object_id;
102  ctx.original_context = (void *)&obj;
103  ctx.original_callback = NULL;
104  ctx.journal_entry = journal_entry;
105  ctx.options = options;
106 
107 
108  /* If object_type_id is _AdaptiveJournalEntry_, handle special */
109  if (afw_utf8_equal(object_type_id,
111  {
112  return afw_adaptor_internal_journal_get_entry(session, object_id, journal_entry,
113  xctx);
114  }
115 
116  /* Get objects via session using intermediate callback. */
117  afw_adaptor_session_get_object(session, &impl_request,
118  object_type_id, object_id,
119  &ctx, impl_get_object_cb,
120  adaptor_type_specific,
121  p, xctx);
122 
123  /* Return object. */
124  return obj;
125 }
126 
127 
128 
129 /* Get and cache object by path. */
130 AFW_DEFINE(const afw_object_t *)
132  const afw_utf8_t *path,
133  const afw_object_t *journal_entry,
134  const afw_object_t *adaptor_type_specific,
135  afw_xctx_t *xctx)
136 {
137  const afw_object_path_parsed_t *parsed_path;
138 
139  /* Parse path. */
140  parsed_path = afw_object_path_parse(path, NULL, NULL, xctx->p, xctx);
141  if (!parsed_path ||
142  !parsed_path->entity_object_id.s ||
143  parsed_path->first_property_name)
144  {
145  AFW_THROW_ERROR_Z(general, "Invalid path", xctx);
146  }
147 
148  /* Return object. */
149  return afw_adaptor_get_object(
150  &parsed_path->adaptor_id,
151  &parsed_path->object_type_id,
152  &parsed_path->entity_object_id,
153  NULL, NULL, journal_entry,
154  adaptor_type_specific, xctx->p, xctx);
155 }
AFW_DEFINE(const afw_object_t *)
Adaptive Framework Core Internal.
const afw_object_t * afw_adaptor_internal_journal_get_entry(const afw_adaptor_session_t *session, const afw_utf8_t *object_id, const afw_object_t *journal_entry, afw_xctx_t *xctx)
void afw_adaptor_internal_process_object_from_adaptor(const afw_object_t **adapted_object, const afw_object_t **view, afw_adaptor_internal_object_cb_context_t *ctx, const afw_object_t *object, const afw_pool_t *p, afw_xctx_t *xctx)
Definition: afw_adaptor.c:625
#define afw_adaptor_session_get_object(instance, impl_request, object_type_id, object_id, context, callback, adaptor_type_specific, p, xctx)
Call method get_object of interface afw_adaptor_session.
afw_adaptor_get_object_by_path(const afw_utf8_t *path, const afw_object_t *journal_entry, const afw_object_t *adaptor_type_specific, afw_xctx_t *xctx)
Get and cache object by path.
afw_adaptor_session_get_cached(const afw_utf8_t *adaptor_id, afw_boolean_t begin_transaction, afw_xctx_t *xctx)
Get/create an active cached session for adaptor_id.
Definition: afw_adaptor.c:375
afw_adaptor_get_object(const afw_utf8_t *adaptor_id, const afw_utf8_t *object_type_id, const afw_utf8_t *object_id, const afw_object_options_t *options, const afw_query_criteria_t *criteria, const afw_object_t *journal_entry, const afw_object_t *adaptor_type_specific, const afw_pool_t *p, afw_xctx_t *xctx)
Get and cache object.
afw_object_set_property_as_string(const afw_object_t *object, const afw_utf8_t *property_name, const afw_utf8_t *internal, afw_xctx_t *xctx)
Set property function for data type string values.
#define AFW_UTF8_FMT_ARG(A_STRING)
Convenience Macro for use with AFW_UTF8_FMT to specify arg.
Definition: afw_common.h:605
_Bool afw_boolean_t
Definition: afw_common.h:373
#define AFW_UTF8_FMT
Format string specifier used for afw_utf8_t.
Definition: afw_common.h:588
#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
#define afw_memory_clear(to)
Clear preallocated memory for sizeof(*(to)).
Definition: afw_memory.h:47
afw_object_path_parse(const afw_utf8_t *path, const afw_utf8_t *current_path, const afw_object_options_t *default_options, const afw_pool_t *p, afw_xctx_t *xctx)
Parse an object value path in specific pool.
#define AFW_OBJECT_S_OBJECT_TYPE_ID_JOURNAL_ENTRY
String object type id for Journal Entry object.
Definition: afw_object.h:63
const afw_object_t * afw_object_create_embedded(const afw_object_t *embedding_object, const afw_utf8_t *property_name, afw_xctx_t *xctx)
Create an empty embedded object in a memory object.
afw_boolean_t afw_utf8_equal(const afw_utf8_t *s1, const afw_utf8_t *s2)
Check to see if a string equals another string.
afw_utf8_printf(const afw_pool_t *p, afw_xctx_t *xctx, const afw_utf8_z_t *format,...)
Create a utf-8 string using a c format string in specified pool.
Definition: afw_utf8.c:459
Internal request info used by afw_adaptor_impl*() functions.
const afw_utf8_t * resource_id
resource id
const afw_object_t * journal_entry
Journal entry.
const afw_object_t * request
Request object.
const afw_pool_t * p
Pool used.
const afw_object_options_t * options
Object options.
Internal struct used by common adaptor code for all adaptors.
Interface afw_adaptor_session public struct.
Struct for object processing options.
Typedef for parsed object path.
Interface afw_object public struct.
Interface afw_pool public struct.
Parsed query criteria.
NFC normalized UTF-8 string.
Definition: afw_common.h:545
Interface afw_xctx public struct.