Adaptive Framework  0.9.0
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
afw_request_handler.c
Go to the documentation of this file.
1 // See the 'COPYING' file in the project root for licensing information.
2 /*
3  * Adaptive Framework Request Handler
4  *
5  * Copyright (c) 2010-2023 Clemson University
6  *
7  */
8 
9 
16 #include "afw_internal.h"
17 
18 
19 
20 /* Configuration handler for entry type "requestHandler". */
22  const afw_utf8_t *type,
23  const afw_object_t *entry,
24  const afw_utf8_t *source_location,
25  const afw_pool_t *p, afw_xctx_t *xctx)
26 {
29  afw_integer_t count;
30 
32  &AFW_REQUEST_HANDLER_S_SINGLETON_KEY_HEAD,
33  xctx);
34  if (!head) {
35  AFW_THROW_ERROR_FZ(general, xctx,
37  "request handler head missing.",
38  AFW_UTF8_FMT_ARG(source_location));
39  }
40 
41  /* Allocate new entry. */
44  entry, xctx);;
45 
46  /* Get uri_prefix and handler_type. */
47  e->uri_prefix = afw_object_old_get_property_as_utf8(entry,
48  &afw_s_uriPrefix, p, xctx);
49  e->handler_type = afw_object_old_get_property_as_utf8(entry,
50  &afw_s_requestHandlerType, p, xctx);
51 
52  /* Log request handler active. */
53  AFW_LOG_FZ(info, xctx, "Request handler for URI prefix %" AFW_UTF8_FMT
54  " starting.",
55  AFW_UTF8_FMT_ARG(e->uri_prefix));
56 
57  /* Use request handler factory for handler id. */
59  e->handler_type, xctx);
60  if (!e->factory) {
61  AFW_THROW_ERROR_FZ(general, xctx,
63  "invalid handler_type %" AFW_UTF8_FMT ".",
64  AFW_UTF8_FMT_ARG(source_location),
65  AFW_UTF8_FMT_ARG(e->handler_type));
66  }
67 
68  /* Create handler. */
70  e->factory, e->properties, p, xctx);
71 
72  /* Add handler entry to list. */
73  if (!head->first_handler) {
74  head->first_handler = e;
75  } else {
76  head->last_handler->next = e;
77  }
78  head->last_handler = e;
79 
80  /* Set runtime object for handler. */
81  for (e = head->first_handler, count = 0; e; e = e->next, count++);
82  head->last_handler->object_id =
83  afw_number_integer_to_utf8(count, p, xctx);
84  afw_object_meta_set_ids(entry, &afw_s_afw,
85  &afw_s__AdaptiveRequestHandler_, head->last_handler->object_id, xctx);
86  afw_runtime_env_set_object(entry, false, xctx);
87 
88  /* Log request handler active. */
89  AFW_LOG_FZ(info, xctx, "Request handler for URI prefix %" AFW_UTF8_FMT
90  " successfully started.",
91  AFW_UTF8_FMT_ARG(head->last_handler->uri_prefix));
92 }
Adaptive Framework Core Internal.
#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_CONTEXTUAL_LABEL_FMT
Format string used for source location.
Definition: afw_common.h:595
#define AFW_UTF8_FMT
Format string specifier used for afw_utf8_t.
Definition: afw_common.h:588
apr_int64_t afw_integer_t
typedef for big signed int.
Definition: afw_common.h:321
const afw_object_t * afw_environment_prepare_conf_type_properties(const afw_object_t *properties, afw_xctx_t *xctx)
Prepare properties for a conf type.
void * afw_environment_get_singleton(const afw_utf8_t *singleton_key, afw_xctx_t *xctx)
Get the singleton value.
const afw_request_handler_factory_t * afw_environment_get_request_handler_type(const afw_utf8_t *handler_type, afw_xctx_t *xctx)
Get the request_handler factory instance associated with handler type.
#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_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_number_integer_to_utf8(afw_integer_t i, const afw_pool_t *p, afw_xctx_t *xctx)
Convert an integer to utf8 in specified pool.
Definition: afw_number.c:168
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.
afw_object_old_get_property_as_utf8(const afw_object_t *instance, const afw_utf8_t *property_name, const afw_pool_t *p, afw_xctx_t *xctx)
Get an object's property value as a string in specified pool.
Definition: afw_object.c:531
#define afw_pool_calloc_type(instance, type, xctx)
Macro to allocate cleared memory to hold type in pool.
Definition: afw_pool.h:167
#define afw_request_handler_factory_create_request_handler_cede_p(instance, properties, p, xctx)
Call method create_request_handler_cede_p of interface afw_request_handler_factory.
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_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
Interface afw_object public struct.
Interface afw_pool public struct.
NFC normalized UTF-8 string.
Definition: afw_common.h:545
Interface afw_xctx public struct.