Adaptive Framework  0.9.0
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
afw_environment_register_core.c
Go to the documentation of this file.
1 // See the 'COPYING' file in the project root for licensing information.
2 /*
3  * Adaptive Framework Register Core
4  *
5  * Copyright (c) 2010-2023 Clemson University
6  *
7  */
8 
9 
15 #include "afw_internal.h"
16 #include <unicode/utypes.h>
17 
18 
20 afw_function_internal_prepare_environment(afw_xctx_t *xctx);
21 
22 static const afw_utf8_t impl_s_apr =
23 AFW_UTF8_LITERAL("apr");
24 
25 static const afw_utf8_t impl_s_icu =
26 AFW_UTF8_LITERAL("icu");
27 
28 static const afw_utf8_t impl_s_description_initialEnvironmentVariables =
29  AFW_UTF8_LITERAL("Environment variables when environment was created.");
30 
31 /* APR RV decoder. */
32 static const afw_utf8_z_t * impl_rv_decoder_z_apr(int rv,
33  afw_utf8_z_t *wa, afw_size_t wa_size)
34 {
35  return apr_strerror(rv, wa, wa_size);
36 }
37 
38 
39 /* ICU RV decoder. */
40 static const afw_utf8_z_t * impl_rv_decoder_z_icu(int rv,
41  afw_utf8_z_t *wa, afw_size_t wa_size)
42 {
43  return u_errorName(rv);
44 }
45 
47  void *original_context;
48  afw_object_cb_t original_callback;
49  afw_boolean_t skip_runtime;
51 
52 
53 static afw_boolean_t
54 impl_AdaptiveLayoutComponentType_retrieve_cb(
55  const afw_object_t *object,
56  void *context,
57  afw_xctx_t *xctx)
58 {
61 
62  if (object) {
63  if (ctx->skip_runtime) {
66  object->meta.id, xctx))
67  {
68  AFW_LOG_FZ(info, xctx,
69  "/%" AFW_UTF8_FMT
70  "/_AdaptiveLayoutComponentType_/%" AFW_UTF8_FMT
71  " ignored because AFW core or an extension supplies it",
73  AFW_UTF8_FMT_ARG(object->meta.id));
74  return false;
75  }
76  }
77  ctx->original_callback(object, ctx->original_context, xctx);
78  }
79 
80  return false;
81 }
82 
83 
84 /* /afw/_AdaptiveLayoutComponentType_ retrieve_objects(). */
85 static void
86 impl_AdaptiveLayoutComponentType_retrieve_objects(
87  const afw_adaptor_session_t * instance,
88  const afw_adaptor_impl_request_t * impl_request,
89  const afw_utf8_t * object_type_id,
90  const afw_query_criteria_t * criteria,
91  void * context,
92  afw_object_cb_t callback,
93  const afw_object_t *adaptor_type_specific,
94  const afw_pool_t * p,
95  afw_xctx_t *xctx)
96 {
98  const afw_adaptor_session_t *session;
99 
100  ctx.original_callback = callback;
101  ctx.original_context = context;
102  ctx.skip_runtime = false;
103 
104  /* Return core component types. */
105  afw_runtime_foreach(object_type_id, (void *)&ctx,
106  impl_AdaptiveLayoutComponentType_retrieve_cb, xctx);
107 
108  /* If there is a layout adaptor, check it too. */
109  if (xctx->env->layout_adaptor_id) {
110  ctx.skip_runtime = true;
112  false, xctx);
113  afw_adaptor_session_retrieve_objects(session, impl_request,
114  object_type_id, criteria, (void *)&ctx,
115  impl_AdaptiveLayoutComponentType_retrieve_cb,
116  NULL, p, xctx);
117  }
118 
119  /* Call callback one more time with NULL object pointer. */
120  callback(NULL, context, xctx);
121 }
122 
123 
124 
125 /* /afw/_AdaptiveLayoutComponentType_ get_object(). */
126 static void
127 impl_AdaptiveLayoutComponentType_get_object(
128  const afw_adaptor_session_t * instance,
129  const afw_adaptor_impl_request_t * impl_request,
130  const afw_utf8_t * object_type_id,
131  const afw_utf8_t * object_id,
132  void * context,
133  afw_object_cb_t callback,
134  const afw_object_t *adaptor_type_specific,
135  const afw_pool_t * p,
136  afw_xctx_t *xctx)
137 {
138  const afw_object_t *object;
139  const afw_adaptor_session_t *session;
140 
141  /* Check for runtime object first. */
142  object = afw_runtime_get_object(object_type_id, object_id, xctx);
143  if (object) {
144  callback(object, context, xctx);
145  }
146 
147  /* Check in layout adaptor next. */
148  else if (xctx->env->layout_adaptor_id) {
150  false, xctx);
151  afw_adaptor_session_get_object(session, impl_request,
152  object_type_id, object_id,
153  context, callback,
154  adaptor_type_specific,
155  p, xctx);
156  }
157 
158  /* Otherwise, not found. */
159  else {
160  callback(NULL, context, xctx);
161  }
162 }
163 
164 
165 static const afw_object_t *
166 impl_create_environment_variables_object(
167  afw_xctx_t *xctx)
168 {
169  extern char **environ;
170  const afw_object_t *result;
171  char **v;
172  char *s;
173  char *c;
174  const afw_utf8_t *name;
175  const afw_utf8_t *value;
176 
177  result = afw_object_create(xctx->p, xctx);
179  &afw_s_afw,
180  &afw_s__AdaptiveSystemInfo_,
181  &afw_s_initialEnvironmentVariables,
182  xctx);
183  afw_object_meta_set_property_as(result, &afw_s_description, string,
184  &impl_s_description_initialEnvironmentVariables, xctx);
185  afw_object_meta_set_read_only(result, xctx);
186 
187  for (v = environ; *v; v++)
188  {
189  for (s = c = *v; *c != '=' && *c != 0; c++);
190  name = afw_utf8_create_copy(s, c - s, result->p, xctx);
191  if (*c == '=') c++;
192  value = afw_utf8_create_copy(c, AFW_UTF8_Z_LEN, result->p, xctx);
194  name, value, xctx);
195  }
196 
197  return result;
198 }
199 
200 
201 /*
202  * Register anything that is part of libafw. This is a bootstrap function
203  * so order of many of the contained calls is important.
204  */
206 {
208  const afw_adaptor_factory_t *adaptor_factory;
209  const afw_log_factory_t *log_factory;
211  afw_runtime_custom_t *runtime_custom;
212  afw_components_t *afw_components;
213  afw_double_t d0;
214 
215  env = (afw_environment_internal_t *)xctx->env;
216 
217  /* Set infinity, minus infinity, and NaN */
218  d0 = 0;
219  env->pub.infinity = 1 / d0;
220  env->pub.infinity_value =
222  xctx->p, xctx);
223  env->pub.minus_infinity = -1 / d0;
224  env->pub.minus_infinity_value =
226  xctx->p, xctx);
227  env->pub.NaN = sqrt(-1);
228  env->pub.NaN_value =
229  afw_value_create_double(env->pub.NaN,
230  xctx->p, xctx);
231 
232  /* Register core generated data_types, functions, etc. */
234  env->core_data_types_registered = true;
235  env->core_functions_registered = true;
236  env->core_object_type_maps_registered = true;
237 
238  /* Register APR RV decoder. */
240  impl_rv_decoder_z_apr, xctx);
241 
242  /* Register ICU RV decoder. */
244  impl_rv_decoder_z_icu, xctx);
245 
246  /* Register flag that are needed early in register core. */
247  afw_flag_internal_early_register_core(xctx);
248 
249  /* Register core value infs. */
250  afw_value_register_core_value_infs(xctx);
251 
252  /* Register core runtime value accessors. */
254 
255  /* Prepare function environment. */
256  afw_function_internal_prepare_environment(xctx);
257 
258  /* Create and register environment variable object. */
260  impl_create_environment_variables_object(xctx);
262  env->pub.initial_environment_variables, false, xctx);
263 
264  /* Register basic application context type. */
266  xctx);
267 
268  /* Register conf type "adaptor" configuration entry handler. */
270  &afw_s_adaptor,
271  afw_adaptor_internal_conf_type_create_cede_p,
272  &afw_s_a_adaptor_title,
273  &afw_s_a_adaptor_description,
274  &afw_s_adaptorId,
275  &afw_s_adaptor_id,
276  &afw_s__AdaptiveAdaptor_,
277  &afw_s_adaptorType,
278  &afw_s_adaptor_type,
279  &afw_s__AdaptiveAdaptorType_,
280  true,
281  xctx);
282 
283  /* Register /afw/_AdaptiveEnvironmentRegistry_/current */
286  false, xctx);
287 
288  /* Register service type "adaptor". */
289  afw_adaptor_internal_register_service_type(xctx);
290 
291  /* Register type "application" configuration entry handler. */
293  &afw_s_application,
295  &afw_s_a_application_title,
296  &afw_s_a_application_description,
297  NULL,
298  NULL,
299  &afw_s__AdaptiveApplication_,
300  NULL,
301  NULL,
302  NULL,
303  false,
304  xctx);
305 
306  /* Register type "extension" configuration entry handler. */
308  &afw_s_extension,
310  &afw_s_a_extension_title,
311  &afw_s_a_extension_description,
312  &afw_s_extensionId,
313  &afw_s_extension,
314  &afw_s__AdaptiveExtension_,
315  NULL,
316  NULL,
317  NULL,
318  false,
319  xctx);
320 
321  /* Register type "log" configuration entry handler. */
323  &afw_s_log,
325  &afw_s_a_log_title,
326  &afw_s_a_log_description,
327  &afw_s_logId,
328  &afw_s_log_id,
329  &afw_s__AdaptiveLog_,
330  &afw_s_logType,
331  &afw_s_log_type,
332  &afw_s__AdaptiveLogType_,
333  true,
334  xctx);
335 
336  /* Register service type "log" */
337  afw_log_internal_register_service_type(xctx);
338 
339  /* Register type "requestHandler" configuration entry handler. */
341  &afw_s_requestHandler,
343  &afw_s_a_requestHandler_title,
344  &afw_s_a_requestHandler_description,
345  NULL,
346  NULL,
347  &afw_s__AdaptiveRequestHandler_,
348  &afw_s_requestHandlerType,
349  NULL,
350  &afw_s__AdaptiveRequestHandlerType_,
351  false,
352  xctx);
353 
354  /* Register runtime adaptor. */
355  adaptor_factory = afw_runtime_get_adaptor_factory();
357  &adaptor_factory->adaptor_type,
358  adaptor_factory, xctx);
359 
360  /* Register afw adaptor. */
361  afw_adaptor_internal_register_afw_adaptor(xctx);
362 
363  /* Register factory for log_type=standard. */
364  log_factory = afw_log_standard_factory_get();
366  &log_factory->log_type,
367  log_factory, xctx);
368 
369  /* Register special handler for _AdaptiveService_ objects. */
370  runtime_custom = afw_xctx_calloc_type(afw_runtime_custom_t, xctx);
371  runtime_custom->retrieve_objects =
372  afw_service_internal_AdaptiveService_retrieve_objects;
373  runtime_custom->get_object =
374  afw_service_internal_AdaptiveService_get_object;
376  &afw_s__AdaptiveService_,
377  runtime_custom, xctx);
378 
379  /* Register special handler for _AdaptiveLayoutComponentType_ objects. */
380  runtime_custom = afw_xctx_calloc_type(afw_runtime_custom_t, xctx);
381  runtime_custom->retrieve_objects =
382  impl_AdaptiveLayoutComponentType_retrieve_objects;
383  runtime_custom->get_object =
384  impl_AdaptiveLayoutComponentType_get_object;
386  &afw_s__AdaptiveLayoutComponentType_,
387  runtime_custom, xctx);
388 
389  /* Register factory for adaptor_type=file. */
390  adaptor_factory = afw_file_adaptor_factory_get();
392  &adaptor_factory->adaptor_type,
393  adaptor_factory, xctx);
394 
395  /* Register model adaptor factory. */
397  &afw_adaptor_factory_model.adaptor_type,
399 
400  /* Register context_type for model. */
401  afw_model_internal_register_context_type_model(xctx);
402 
403  /* Register request handler factory for handler type "adaptor". */
405  &afw_request_handler_factory_adaptor.request_handler_type,
407 
408  /* Register service type authorizationHandler and default handler. */
409  afw_authorization_internal_register(xctx);
410 
411  /* Allocate request handler head and register its singleton. */
412  head = afw_pool_calloc_type(xctx->env->p, afw_request_handler_head_t, xctx);
414  &AFW_REQUEST_HANDLER_S_SINGLETON_KEY_HEAD,
415  head, xctx);
416 
417  /* Allocate object for accessing and loading afw_components extension. */
418  afw_components = afw_pool_calloc_type(xctx->env->p, afw_components_t, xctx);
420  &afw_s__AdaptiveApplicationComponents_,
421  &afw_s_current, afw_components, true, xctx);
422 
431  /* Register JSON support. */
432  afw_json_register(xctx);
433 
434  /* Register application/x-afw content handler. */
436  afw_content_type_application_afw_register(afw_xctx_t *xctx);
437  afw_content_type_application_afw_register(xctx);
438 
439  /* Call OS environment initialize. */
441 }
#define AFW_DECLARE_INTERNAL(type)
Declare an internal function for /src/afw/ source*.h files.
void afw_generated_register(afw_xctx_t *xctx)
Generated register for afw.
Definition: afw_generated.c:46
Adaptive Framework Core Internal.
#define afw_adaptor_session_retrieve_objects(instance, impl_request, object_type_id, criteria, context, callback, adaptor_type_specific, p, xctx)
Call method retrieve_objects of interface afw_adaptor_session.
#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_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
void afw_application_internal_register_basic_application_context_type(afw_xctx_t *xctx)
Set basic application context type.
void afw_application_internal_application_conf_type_create_cede_p(const afw_utf8_t *type, const afw_object_t *entry, const afw_utf8_t *source_location, const afw_pool_t *p, afw_xctx_t *xctx)
type=application conf handler.
afw_value_create_double(double internal, const afw_pool_t *p, afw_xctx_t *xctx)
Create function for unmanaged data type double value.
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_Z_LEN
String is NUL (0) terminate.
Definition: afw_common.h:266
afw_boolean_t(* afw_object_cb_t)(const afw_object_t *object, void *context, afw_xctx_t *xctx)
Typedef for afw_adaptor_session_object callback.
Definition: afw_common.h:1176
#define AFW_UTF8_LITERAL(A_STRING)
String literal initializer.
Definition: afw_common.h:582
double afw_double_t
Normal AFW number is double.
Definition: afw_common.h:202
_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
afw_utf8_octet_t afw_utf8_z_t
NFC normalized UTF-8 null terminated string.
Definition: afw_common.h:523
apr_size_t afw_size_t
size_t.
Definition: afw_common.h:151
void afw_environment_internal_register_core(afw_xctx_t *xctx)
void afw_environment_internal_extension_conf_type_create_cede_p(const afw_utf8_t *type, const afw_object_t *entry, const afw_utf8_t *source_location, const afw_pool_t *p, afw_xctx_t *xctx)
type=extension conf handler.
void afw_environment_register_request_handler_type(const afw_utf8_t *handler_type, const afw_request_handler_factory_t *request_handler_factory, afw_xctx_t *xctx)
Register a request_handler factory.
void afw_environment_register_runtime_custom(const afw_utf8_t *object_type_id, const afw_runtime_custom_t *custom, afw_xctx_t *xctx)
Register afw_runtime_custom_t for a custom handled runtime object type.
void afw_environment_register_singleton(const afw_utf8_t *singleton_key, const void *void_ptr, afw_xctx_t *xctx)
Register an singleton.
afw_environment_register_adaptor_type(const afw_utf8_t *adaptor_type, const afw_adaptor_factory_t *adaptor_factory, afw_xctx_t *xctx)
Register an adaptor factory.
afw_environment_create_and_register_conf_type(const afw_utf8_t *conf_type_id, afw_environment_conf_type_create_cede_p_t create, const afw_utf8_t *title, const afw_utf8_t *description, const afw_utf8_t *id_property_name, const afw_utf8_t *id_registry_type_id, const afw_utf8_t *id_runtime_object_type_id, const afw_utf8_t *subtype_property_name, const afw_utf8_t *subtype_registry_type_id, const afw_utf8_t *subtype_runtime_object_type_id, afw_boolean_t is_unique, afw_xctx_t *xctx)
Create and register a configuration (conf) type.
void afw_environment_register_log_type(const afw_utf8_t *log_type, const afw_log_factory_t *log_factory, afw_xctx_t *xctx)
Register an log factory.
afw_environment_registry_object_get_current(afw_xctx_t *xctx)
Get current environment registry object.
void afw_environment_register_error_rv_decoder(const afw_utf8_t *rv_source_id, afw_environment_error_rv_decoder_z_t rv_decoder, afw_xctx_t *xctx)
Register an error rv decoder.
afw_file_adaptor_factory_get()
Get the factory for file adaptor.
Definition: afw_file.c:261
void afw_json_register(afw_xctx_t *xctx)
Register JSON support.
void afw_log_internal_conf_type_create_cede_p(const afw_utf8_t *type, const afw_object_t *conf, const afw_utf8_t *source_location, const afw_pool_t *p, afw_xctx_t *xctx)
Configuration handler for entry type "log".
Definition: afw_log.c:391
const afw_log_factory_t * afw_log_standard_factory_get()
Get the factory for log type standard.
#define AFW_LOG_FZ(priority, xctx, format_z,...)
Log an message to environment's log using a printf style format and parameters.
Definition: afw_log.h:192
afw_adaptor_factory_model
Definition: afw_model.h:33
#define afw_object_meta_get_object_type_id(instance, xctx)
Get object's object_type_id.
afw_object_meta_set_read_only(const afw_object_t *instance, afw_xctx_t *xctx)
Set object's meta to indicate object is read-only.
#define afw_object_meta_set_property_as(instance, property_name, data_type, value, xctx)
Set a property in the meta of an object as a value and data type.
afw_object_meta_set_ids(const afw_object_t *instance, const afw_utf8_t *adaptor_id, const afw_utf8_t *object_type_id, const afw_utf8_t *object_id, afw_xctx_t *xctx)
Set object's ids.
#define afw_object_create(p, xctx)
Create an empty unmanaged object in memory.
Definition: afw_object.h:948
void afw_os_environment_initialize(afw_xctx_t *xctx)
afw_os environment initialize
Definition: nix/afw_os.c:607
#define afw_pool_calloc_type(instance, type, xctx)
Macro to allocate cleared memory to hold type in pool.
Definition: afw_pool.h:167
void afw_request_handler_internal_conf_type_create_cede_p(const afw_utf8_t *type, const afw_object_t *entry, const afw_utf8_t *source_location, const afw_pool_t *p, afw_xctx_t *xctx)
Configuration handler for entry type "requestHandler".
afw_request_handler_factory_adaptor
void afw_runtime_register_core_value_accessors(afw_xctx_t *xctx)
Register core runtime value accessors.
afw_runtime_env_create_and_set_indirect_object(const afw_utf8_t *object_type_id, const afw_utf8_t *object_id, void *internal, afw_boolean_t overwrite, afw_xctx_t *xctx)
Create and set an indirect runtime object.
Definition: afw_runtime.c:528
afw_runtime_env_set_object(const afw_object_t *object, afw_boolean_t overwrite, afw_xctx_t *xctx)
Set an object pointer in the environment's runtime objects.
Definition: afw_runtime.c:210
afw_runtime_get_object(const afw_utf8_t *object_type_id, const afw_utf8_t *object_id, afw_xctx_t *xctx)
Get a runtime object.
Definition: afw_runtime.c:853
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
afw_runtime_get_adaptor_factory()
Get singleton factory for runtime adaptor.
Definition: afw_runtime.c:915
#define afw_utf8_create_copy(s, len, p, xctx)
Make a utf-8 sting from chars in pool specified.
Definition: afw_utf8.h:369
#define afw_xctx_calloc_type(type, xctx)
Macro to allocate cleared memory to hold type in xctx's pool.
Definition: afw_xctx.h:199
Interface afw_adaptor_factory public struct.
Internal request info used by afw_adaptor_impl*() functions.
Interface afw_adaptor_session public struct.
afw_double_t minus_infinity
Double minus infinity.
Definition: afw_common.h:1437
afw_double_t NaN
Double NaN.
Definition: afw_common.h:1443
const afw_object_t * initial_environment_variables
Environment variables at environment create.
Definition: afw_common.h:1395
const afw_pool_t * p
Pool used to hold environment.
Definition: afw_common.h:1386
const afw_value_t * NaN_value
Double NaN value.
Definition: afw_common.h:1446
const afw_value_t * infinity_value
Double infinity value.
Definition: afw_common.h:1434
const afw_utf8_t * layout_adaptor_id
Custom layout adaptor or NULL.
Definition: afw_common.h:1416
afw_double_t infinity
Double infinity.
Definition: afw_common.h:1431
const afw_value_t * minus_infinity_value
Double minus infinity value.
Definition: afw_common.h:1440
Interface afw_log_factory public struct.
const afw_utf8_t * id
Object id or property name.
Definition: afw_common.h:782
Interface afw_object public struct.
Interface afw_pool public struct.
Parsed query criteria.
afw_adaptor_session_get_object_t get_object
The session get_object method.
Definition: afw_runtime.h:49
afw_adaptor_session_retrieve_objects_t retrieve_objects
The session retrieve_objects method.
Definition: afw_runtime.h:46
NFC normalized UTF-8 string.
Definition: afw_common.h:545
Interface afw_xctx public struct.