Adaptive Framework  0.9.0
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
afw_content_type_impl.c
Go to the documentation of this file.
1 // See the 'COPYING' file in the project root for licensing information.
2 /*
3  * Helpers for afw_content_type* implementation development
4  *
5  * Copyright (c) 2010-2023 Clemson University
6  *
7  */
8 
14 #include "afw_internal.h"
15 
16 
17 /*
18  * Declares and rti/inf defines for interface
19  * afw_content_type_object_list_writer
20  */
21 #define AFW_IMPLEMENTATION_ID "impl"
23 
24 
25 /* Self for afw_content_type_object_list_writer implementation. */
28 
29  /* Private implementation variables */
30  const afw_pool_t *p;
31  const afw_content_type_t *content_type;
32  const afw_object_options_t *options;
33  void * context;
34  afw_write_cb_t callback;
35  const afw_memory_t * begin_object_list;
36  const afw_memory_t * object_separator;
37  const afw_memory_t * last_object_separator;
38  const afw_memory_t * end_object_list;
39  afw_size_t object_count;
40 
42 
43 
44 
46 afw_content_type_impl_create_object_list_writer(
47  const afw_content_type_t * instance,
48  const afw_object_options_t *options,
49  void * context,
50  afw_write_cb_t callback,
51  const afw_memory_t * begin_object_list,
52  const afw_memory_t * object_separator,
53  const afw_memory_t * last_object_separator,
54  const afw_memory_t * end_object_list,
55  const afw_pool_t *p, afw_xctx_t *xctx)
56 {
58 
60  xctx);
61  self->pub.inf = &impl_afw_content_type_object_list_writer_inf;
62 
63  /* Finish processing parameters and initializing new instance. */
64  self->p = p;
65  self->content_type = instance;
66  self->options = options;
67  self->context = context;
68  self->callback = callback;
69  self->begin_object_list = begin_object_list;
70  self->object_separator = object_separator;
71  self->last_object_separator = last_object_separator;
72  self->end_object_list = end_object_list;
73 
74  /* Write object list begin for content type. */
75  if (self->begin_object_list && self->begin_object_list->size > 0) {
76  callback(self->context,
77  self->begin_object_list->ptr,
78  self->begin_object_list->size,
79  p, xctx);
80  }
81 
82  /* Return new instance. */
84 }
85 
86 
87 
88 /*
89  * Implementation of method release of interface afw_content_type_object_list_writer.
90  */
91 void
92 impl_afw_content_type_object_list_writer_release(
94  afw_xctx_t *xctx)
95 {
96  /* Assign instance pointer to self. */
99 
100  /* If objects have been written, write last separator if there is one. */
101  if (self->object_count > 0 &&
102  self->last_object_separator &&
103  self->last_object_separator->size > 0)
104  {
105  self->callback(self->context,
106  self->last_object_separator->ptr,
107  self->last_object_separator->size,
108  self->p, xctx);
109  }
110 
111  /* Write object list end for content type. */
112  if (self->end_object_list && self->end_object_list->size > 0) {
113  self->callback(self->context,
114  self->end_object_list->ptr,
115  self->end_object_list->size,
116  self->p, xctx);
117  }
118 }
119 
120 
121 
122 /*
123  * Implementation of method write_object of interface afw_content_type_object_list_writer.
124  */
125 void
126 impl_afw_content_type_object_list_writer_write_object(
127  const afw_content_type_object_list_writer_t * instance,
128  const afw_object_t * object,
129  const afw_pool_t *p,
130  afw_xctx_t *xctx)
131 {
132  /* Assign instance pointer to self. */
135  const afw_memory_t *raw;
136  const afw_value_t *value;
137 
138  /* If objects have been written, write separator if there is one. */
139  if (self->object_count > 0 &&
140  self->object_separator &&
141  self->object_separator->size > 0)
142  {
143  self->callback(self->context,
144  self->object_separator->ptr,
145  self->object_separator->size,
146  p, xctx);
147  }
148 
149  /* Convert value and write. */
150  (self->object_count)++;
151  value = afw_value_create_object(object, p, xctx);
152  raw = afw_content_type_value_to_raw(self->content_type,
153  value, self->options, p, xctx);
154  self->callback(self->context, raw->ptr, raw->size, p, xctx);
155 }
AFW_DEFINE(const afw_object_t *)
Interface afw_interface implementation declares.
Adaptive Framework Core Internal.
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.
apr_size_t afw_size_t
size_t.
Definition: afw_common.h:151
afw_size_t(* afw_write_cb_t)(void *context, const void *buffer, afw_size_t size, const afw_pool_t *p, afw_xctx_t *xctx)
Typedef for write callback function.
Definition: afw_common.h:1226
afw_content_type_value_to_raw(const afw_content_type_t *instance, const afw_value_t *value, const afw_object_options_t *options, const afw_pool_t *p, afw_xctx_t *xctx)
Convert value to the raw in specified pool.
#define afw_pool_calloc_type(instance, type, xctx)
Macro to allocate cleared memory to hold type in pool.
Definition: afw_pool.h:167
Interface afw_content_type_object_list_writer public struct.
Interface afw_content_type public struct.
Struct for memory pointer and size.
Definition: afw_common.h:505
Struct for object processing options.
Interface afw_object public struct.
Interface afw_pool public struct.
Interface afw_value public struct.
Interface afw_xctx public struct.