Adaptive Framework  0.9.0
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
afw_adaptor_add.c
Go to the documentation of this file.
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 
18 /* Call adaptor to add object and remove from cache. */
19 AFW_DEFINE(const afw_utf8_t *)
21  const afw_utf8_t *adaptor_id,
22  const afw_utf8_t *object_type_id,
23  const afw_utf8_t *suggested_object_id,
24  const afw_object_t *object,
25  const afw_object_t *journal_entry,
26  const afw_object_t *adaptor_type_specific,
27  afw_xctx_t *xctx)
28 {
29  const afw_adaptor_session_t *session;
30  const afw_utf8_t *path;
31  const afw_utf8_t *object_id;
32  const afw_object_t *request;
33  const afw_adaptor_journal_t *journal;
34  afw_adaptor_impl_request_t impl_request;
35 
36  /* Set request in journal entry. */
37  afw_memory_clear(&impl_request);
38  impl_request.request = request = afw_object_create_embedded(
39  journal_entry, &afw_s_request, xctx);
40  impl_request.p = request->p;
41  impl_request.journal_entry = journal_entry;
42  impl_request.resource_id = afw_utf8_printf(impl_request.p, xctx,
43  "/"
44  "%" AFW_UTF8_FMT "/"
45  "%" AFW_UTF8_FMT "/"
46  "%" AFW_UTF8_FMT,
47  AFW_UTF8_FMT_ARG(adaptor_id),
48  AFW_UTF8_FMT_ARG(object_type_id),
49  AFW_UTF8_FMT_OPTIONAL_ARG(suggested_object_id));
51  &afw_s_resourceId, impl_request.resource_id, xctx);
53  &afw_s_function, &afw_s_add_object, xctx);
55  &afw_s_adaptorId, adaptor_id, xctx);
57  &afw_s_objectType, object_type_id, xctx);
58  if (suggested_object_id) {
60  &afw_s_suggestedObjectId, suggested_object_id, xctx);
61  }
63  &afw_s_object, object, xctx);
64 
65  /* Get an active session with adaptor. */
66  session = afw_adaptor_session_get_cached(adaptor_id, true, xctx);
67 
68  /* Action prologue. */
69  afw_adaptor_internal_journal_prologue(session, journal_entry, xctx);
70 
71  /* If one of the core object types, handle special */
72  object_id = NULL;
73  if (afw_utf8_starts_with(object_type_id, &AFW_OBJECT_S_CORE_ID_PREFIX)) {
74 
75  /* Journal entry. */
76  if (afw_utf8_equal(object_type_id,
78  {
80  xctx);
81  if (!journal) {
82  AFW_THROW_ERROR_FZ(general, xctx,
83  "adaptor_id %" AFW_UTF8_FMT
84  " session get_journal() returned NULL",
85  AFW_UTF8_FMT_ARG(&session->adaptor->adaptor_id));
86  }
87  object_id = afw_adaptor_journal_add_entry(journal,
88  &impl_request, object, xctx);
89  }
90  }
91 
92  /* If special handling didn't add object, do normal add object. */
93  if (!object_id) {
94  object_id = afw_adaptor_session_add_object(session, &impl_request,
95  object_type_id, suggested_object_id, object,
96  adaptor_type_specific, xctx);
97  }
98 
99  /* Set info in journal entry. */
100  afw_object_set_property_as_string(journal_entry,
101  &afw_s_objectId, object_id, xctx);
102  path = afw_object_path_make(adaptor_id, object_type_id, object_id,
103  journal_entry->p, xctx);
104  afw_object_set_property_as_string(journal_entry,
105  &afw_s_path, path, xctx);
106 
107  /* If requested, write to event journal. */
108  //if (session->adaptor->)
109 
110  /* Action epilogue. */
111  afw_adaptor_internal_journal_epilogue(session, journal_entry, true, xctx);
112 
113  return object_id;
114 }
115 
AFW_DEFINE(const afw_object_t *)
Adaptive Framework Core Internal.
void afw_adaptor_internal_journal_epilogue(const afw_adaptor_session_t *session, const afw_object_t *journal_entry, afw_boolean_t modification, afw_xctx_t *xctx)
#define afw_adaptor_journal_add_entry(instance, impl_request, entry, xctx)
Call method add_entry of interface afw_adaptor_journal.
#define afw_adaptor_session_add_object(instance, impl_request, object_type_id, suggested_object_id, object, adaptor_type_specific, xctx)
Call method add_object of interface afw_adaptor_session.
#define afw_adaptor_session_get_journal_interface(instance, xctx)
Call method get_journal_interface of interface afw_adaptor_session.
afw_adaptor_add_object(const afw_utf8_t *adaptor_id, const afw_utf8_t *object_type_id, const afw_utf8_t *suggested_object_id, const afw_object_t *object, const afw_object_t *journal_entry, const afw_object_t *adaptor_type_specific, afw_xctx_t *xctx)
Call adaptor to add object and remove from cache.
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_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_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
#define AFW_UTF8_FMT_OPTIONAL_ARG(A_STRING)
Convenience Macro for use with AFW_UTF8_FMT to specify optional arg.
Definition: afw_common.h:616
#define AFW_UTF8_FMT
Format string specifier used for afw_utf8_t.
Definition: afw_common.h:588
#define AFW_THROW_ERROR_FZ(code, xctx, format_z,...)
Macro used to set error and 0 rv in xctx and throw it.
Definition: afw_error.h:319
#define afw_memory_clear(to)
Clear preallocated memory for sizeof(*(to)).
Definition: afw_memory.h:47
afw_object_path_make(const afw_utf8_t *adaptor_id, const afw_utf8_t *object_type_id, const afw_utf8_t *object_id, const afw_pool_t *p, afw_xctx_t *xctx)
Construct an object path in a specified pool.
#define AFW_OBJECT_S_CORE_ID_PREFIX
String prefix for all core adaptive object types.
Definition: afw_object.h:33
#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
afw_boolean_t afw_utf8_starts_with(const afw_utf8_t *string, const afw_utf8_t *starts_with)
Check to see if a string starts with another string.
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.
Interface afw_adaptor_journal public struct.
Interface afw_adaptor_session public struct.
Interface afw_object public struct.
NFC normalized UTF-8 string.
Definition: afw_common.h:545
Interface afw_xctx public struct.