21 void *original_context;
23 apr_hash_t *service_ids;
38 impl_startup_values[] =
43 &afw_value_evaluated_string_inf, \
44 AFW_UTF8_LITERAL(# id) \
57 #define impl_startup_value(id) \
58 (const afw_value_t *)&impl_startup_values[afw_service_startup_ ## id]
64 #define XX(id, desc) \
66 &afw_value_evaluated_string_inf, \
67 AFW_UTF8_LITERAL(desc) \
80 impl_status_values[] =
84 &afw_value_evaluated_string_inf, \
85 AFW_UTF8_LITERAL(# id) \
97 #define impl_status_value(id) \
98 (const afw_value_t *)&impl_status_values[afw_service_status_ ## id]
102 impl_status_descriptions[] =
105 #define XX(id, desc) \
107 &afw_value_evaluated_string_inf, \
108 AFW_UTF8_LITERAL(desc) \
128 impl_restart_service(
140 if (i < 0 || i >= afw_service_startup_invalid) {
141 i = afw_service_startup_invalid;
144 return &impl_startup_values[i].internal;
155 if (i < 0 || i >= afw_service_startup_invalid) {
156 i = afw_service_startup_invalid;
159 return (
const afw_value_t *)&impl_startup_values[i];
170 if (i < 0 || i >= afw_service_startup_invalid) {
171 i = afw_service_startup_invalid;
174 return &impl_startup_descriptions[i].internal;
185 if (i < 0 || i >= afw_service_startup_invalid) {
186 i = afw_service_startup_invalid;
189 return (
const afw_value_t*)&impl_startup_descriptions[i];
200 result < afw_service_startup_invalid &&
215 if (i < 0 || i >= afw_service_status_invalid) {
216 i = afw_service_status_invalid;
219 return &impl_status_values[i].internal;
230 if (i < 0 || i >= afw_service_status_invalid) {
231 i = afw_service_status_invalid;
234 return (
const afw_value_t *)&impl_status_values[i];
245 if (i < 0 || i >= afw_service_status_invalid) {
246 i = afw_service_status_invalid;
249 return &impl_status_descriptions[i].internal;
260 if (i < 0 || i >= afw_service_status_invalid) {
261 i = afw_service_status_invalid;
264 return (
const afw_value_t *)&impl_status_descriptions[i];
275 result < afw_service_status_invalid &&
285 impl_initialize_and_start_service_using_conf(
305 &afw_s_sourceLocation, conf_source_location, xctx);
310 if (!service->
type || service->
type->len == 0) {
313 "missing conf/type property",
319 service->
type, xctx);
341 subtype_property_name));
364 object_id = (service->
conf_id) ? service->
conf_id : &afw_s_current;
375 " is not appropriate for this conf",
393 rv = apr_thread_mutex_create(
396 if (rv != APR_SUCCESS) {
398 "apr_thread_mutex_create() failed", xctx);
401 service->
status = afw_service_status_ready_to_start;
403 impl_restart_service(service, xctx);
406 impl_start_service(service, xctx);
429 if (!
object)
return false;
434 service_id = &afw_s_unknown;
442 &afw_s_startup, xctx);
455 &afw_s_serviceId, xctx);
462 "serviceId can not be determined",
472 service->
status != afw_service_status_error &&
473 !(ctx->manual_start &&
474 service->
status == afw_service_status_stopped)
481 old_service = service;
490 service_id->s, service_id->len, p, xctx);
502 "missing conf property",
511 impl_initialize_and_start_service_using_conf(service,
520 service->
status = afw_service_status_error;
548 afw_service_internal_start_initial_services(
569 &afw_s__AdaptiveServiceConf_, NULL,
570 &ctx, impl_start_cb, NULL, p, xctx);
583 impl_add_runtime_service_info_to_object(
611 &afw_s_afw, &afw_s__AdaptiveService_, service_id, xctx);
616 len = service_id->len;
618 w_type.s = c = service_id->s,
619 w_type.len = len = service_id->len;
620 len > 0 && *c !=
'-';
624 w_type.len = c - w_type.s;
628 if (len <= 0 || w_id.len < 1) {
645 &afw_s_serviceId, service_id, xctx);
647 &afw_s_serviceType, type, xctx);
649 &afw_s_confId,
id, xctx);
664 &afw_s_confSubtype, subtype, xctx);
672 id_runtime_object_type_id),
675 &afw_s_uriRelated, s, xctx);
691 &afw_s_confPropertyObjectType, conf_object_type_id, xctx);
693 startup = afw_service_startup_invalid;
702 if (startup == afw_service_startup_permanent) {
703 startup = afw_service_startup_invalid;
706 (
const afw_value_t *)&impl_startup_values[startup], xctx);
708 (
const afw_value_t *)&impl_startup_descriptions[startup], xctx);
710 if (startup == afw_service_startup_manual ||
711 startup == afw_service_startup_immediate)
714 switch (service->
status) {
716 case afw_service_status_error:
717 case afw_service_status_ready_to_start:
718 case afw_service_status_stopped:
722 case afw_service_status_running:
726 case afw_service_status_disabled:
727 case afw_service_status_starting:
728 case afw_service_status_stopping:
729 case afw_service_status_restarting:
733 case afw_service_status_invalid:
746 &impl_startup_values[afw_service_startup_permanent], xctx);
749 &impl_startup_descriptions[afw_service_startup_permanent], xctx);
759 service->
status == afw_service_status_running)
770 &afw_s_statusDescription,
780 &afw_s_startTime, &service->
start_time, xctx);
796 if (startup == afw_service_startup_disabled)
799 &impl_status_values[afw_service_status_disabled];
801 &impl_status_descriptions[afw_service_status_disabled];
804 &impl_status_values[afw_service_status_ready_to_start];
806 &impl_status_descriptions[afw_service_status_ready_to_start];
810 value_description, xctx);
814 &afw_s_canStart, can_start, xctx);
816 &afw_s_canStop, can_stop, xctx);
818 &afw_s_canRestart, can_restart, xctx);
828 impl_AdaptiveService_cb(
847 object = original_object;
849 service_id = &afw_s_unknown;
852 p = original_object->p;
858 &afw_s_serviceId, xctx);
865 &afw_s_uriServiceConf, s, xctx);
867 &afw_s_sourceLocation, s, xctx);
870 &afw_s_annotation, xctx);
877 original_object, &afw_s_conf, xctx);
878 if (!conf_property) {
885 impl_add_runtime_service_info_to_object(
object, service,
886 original_object, conf_property, service_id,
896 &afw_s_statusMessage,
897 error_message, xctx);
902 error_message, xctx);
904 impl_startup_value(disabled), xctx);
906 impl_status_value(error), xctx);
911 meetsCriteria =
true;
914 ctx->criteria, ctx->p, xctx);
917 if (ctx->service_ids) {
918 apr_hash_set(ctx->service_ids, service_id->s, service_id->len,
922 if (meetsCriteria && ctx->original_callback) {
923 is_complete = ctx->original_callback(
object,
924 ctx->original_context, xctx);
928 ctx->last_object = object;
936 impl_retrieve_from_registry_cb(
952 if (!ctx->service_ids || !apr_hash_get(ctx->service_ids, key_s, key_len)) {
955 impl_add_runtime_service_info_to_object(
object, service,
959 meetsCriteria =
true;
962 ctx->criteria, p, xctx);
965 if (meetsCriteria && ctx->original_callback) {
966 is_complete = ctx->original_callback(
object, ctx->original_context,
978 afw_service_internal_AdaptiveService_retrieve_objects (
992 memset(&ctx, 0,
sizeof(ctx));
994 ctx.original_callback = callback;
995 ctx.original_context = context;
996 ctx.criteria = criteria;
1004 session, NULL, &afw_s__AdaptiveServiceConf_,
1006 &ctx, impl_AdaptiveService_cb,
1020 afw_environemnt_registry_type_service,
1021 impl_retrieve_from_registry_cb,
1027 callback(NULL, context, xctx);
1034 afw_service_internal_AdaptiveService_get_object (
1052 callback(result, context, xctx);
1070 memset(&ctx, 0,
sizeof(ctx));
1083 &xctx->env->conf_adaptor->adaptor_id, xctx);
1086 session, NULL, &afw_s__AdaptiveServiceConf_, service_id,
1087 &ctx, impl_AdaptiveService_cb,
1089 result = ctx.last_object;
1097 result = ctx.last_object;
1102 &afw_s_serviceId, service_id, xctx);
1108 &afw_s_statusMessage, error_message, xctx);
1113 &afw_s_statusDebug, error_message, xctx);
1116 impl_startup_value(disabled), xctx);
1118 impl_status_value(error), xctx);
1133 impl_add_runtime_service_info_to_object(result,
1160 impl_initialize_and_start_service_using_conf(service,
1161 &afw_s_conf,
false, conf, source_location, xctx);
1177 service->
status = afw_service_status_starting;
1186 service->
status = afw_service_status_running;
1187 if (existing_service) {
1191 " successfully started.",
1214 ctx.manual_start = manual_start;
1220 service->
status != afw_service_status_ready_to_start &&
1221 service->
status != afw_service_status_stopped &&
1222 service->
status != afw_service_status_error)
1233 if (!xctx->env->conf_adaptor) {
1241 &xctx->env->conf_adaptor->adaptor_id, xctx);
1245 &afw_s__AdaptiveServiceConf_, service_id,
1246 &ctx, impl_start_cb, NULL, p, xctx);
1282 if (service->
status == afw_service_status_running) {
1285 service->
status = afw_service_status_stopping;
1289 service->
status = afw_service_status_stopping;
1293 " successfully stopped.",
1295 service->
status = afw_service_status_stopped;
1303 ? afw_service_status_running
1304 : afw_service_status_stopped;
1328 impl_restart_service(
1337 service->
status = afw_service_status_restarting;
1344 service->
status = afw_service_status_running;
1345 if (existing_service) {
1349 " successfully restarted.",
1358 impl_restart_get_cb(
1372 ctx->object = object;
1373 if (!
object)
return false;
1378 service_id = &afw_s_unknown;
1386 &afw_s_startup, xctx);
1396 &afw_s_serviceId, xctx);
1403 "serviceId can not be determined",
1416 service_id->s, service_id->len, p, xctx);
1427 "missing conf property",
1432 impl_initialize_and_start_service_using_conf(service,
1438 service->
status = afw_service_status_error;
1481 if (!service || service->
status != afw_service_status_running)
1485 " cannot be restarted. It is not running",
1490 if (!xctx->env->conf_adaptor) {
1496 &xctx->env->conf_adaptor->adaptor_id, xctx);
1500 &afw_s__AdaptiveServiceConf_, service_id,
1501 &ctx, impl_restart_get_cb, NULL, p, xctx);
AFW_DEFINE(const afw_object_t *)
#define AFW_DECLARE(type)
Declare a public afw function.
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_release(const afw_adaptor_session_t *session, afw_xctx_t *xctx)
Release an adaptor session created by afw_adaptor_session_create().
afw_adaptor_session_create(const afw_utf8_t *adaptor_id, afw_xctx_t *xctx)
Create an adaptor session.
afw_object_set_property_as_anyURI(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 anyURI values.
afw_object_set_property_as_boolean(const afw_object_t *object, const afw_utf8_t *property_name, afw_boolean_t internal, afw_xctx_t *xctx)
Set property function for data type boolean values.
afw_object_set_property_as_dateTime(const afw_object_t *object, const afw_utf8_t *property_name, const afw_dateTime_t *internal, afw_xctx_t *xctx)
Set property function for data type dateTime values.
#define afw_object_old_get_property_as_object(object, property_name, xctx)
Get property function for data type object value.
#define afw_object_old_get_property_as_string(object, property_name, xctx)
Get property function for data type string value.
afw_value_evaluated_string_inf
Unmanaged evaluated value inf for data type string.
#define afw_value_is_string(A_VALUE)
Macro to determine if value is evaluated string.
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.
#define AFW_SERVICE_STARTUP_MAP(XX)
Map used for afw_service_startup_t enum.
#define AFW_UTF8_Z_LEN
String is NUL (0) terminate.
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.
#define AFW_UTF8_LITERAL(A_STRING)
String literal initializer.
#define AFW_UTF8_CONTEXTUAL_LABEL_FMT
Format string used for source location.
#define AFW_UTF8_FMT
Format string specifier used for afw_utf8_t.
enum afw_service_status_e afw_service_status_t
Typedef for service status enum.
enum afw_service_startup_e afw_service_startup_t
Typedef for service startup type enum.
#define AFW_SERVICE_STATUS_MAP(XX)
Map used for afw_service_status_t enum.
char afw_utf8_octet_t
8 bits of utf-8 codepoint.
apr_size_t afw_size_t
size_t.
void afw_environment_register_service(const afw_utf8_t *service_id, afw_service_t *service, afw_xctx_t *xctx)
Register a service.
const afw_service_type_t * afw_environment_get_service_type(const afw_utf8_t *service_type_id, afw_xctx_t *xctx)
Get the service type instance associated with service_type_id.
afw_environment_foreach(int type_number, afw_environment_foreach_cb_t callback, void *data, const afw_pool_t *p, afw_xctx_t *xctx)
Call a callback function for each entry of a registry type.
afw_service_t * afw_environment_get_service(const afw_utf8_t *service_id, afw_xctx_t *xctx)
Get the service instance associated with service_id.
#define AFW_FINALLY
Always executed regardless of error.
#define AFW_CATCH_UNHANDLED
Catch an unhandled error that occurs in a AFW_TRY block.
afw_error_write_log(afw_log_priority_t priority, const afw_error_t *error, afw_xctx_t *xctx)
Write error to environment log.
#define AFW_THROW_ERROR_RV_Z(code, rv_source_id, rv, message_z, xctx)
Macro used to set error and rv in xctx and throw it.
#define AFW_ENDTRY
Ends an AFW try block.
#define AFW_TRY
Begin an AFW TRY block.
#define AFW_THROW_ERROR_FZ(code, xctx, format_z,...)
Macro used to set error and 0 rv in xctx and throw it.
afw_error_to_utf8(const afw_error_t *error, const afw_pool_t *p, afw_xctx_t *xctx)
Convert error to utf8.
#define AFW_MARK_UNHANDLED
Use in an AFW_CATCH or AFW_CATCH_UNHANDLED block to mark error as unhandled and break.
#define AFW_ERROR_THROWN
Access the thrown error. See AFW_TRY.
#define AFW_THROW_ERROR_Z(code, message_z, xctx)
Macro used to set error and 0 rv in xctx and throw it.
#define AFW_CATCH(__CODE_)
Catch a particular error that occurs in a AFW_TRY block.
#define AFW_LOG_FZ(priority, xctx, format_z,...)
Log an message to environment's log using a printf style format and parameters.
#define AFW_LOG_Z(priority, message_z, xctx)
Log an afw_utf8_z_t message to environment's log.
#define afw_memory_clear(to)
Clear preallocated memory for sizeof(*(to)).
void * afw_memory_dup(const void *from, apr_size_t size, const afw_pool_t *p, afw_xctx_t *xctx)
Duplicate a block of memory into specified pool.
#define afw_object_get_property(instance, property_name, xctx)
Call method get_property of interface afw_object.
afw_object_create_clone(const afw_object_t *object, const afw_pool_t *p, afw_xctx_t *xctx)
Clone an object to a specified pool.
#define afw_object_create_managed(p, xctx)
Create an empty entity object in its own pool.
#define afw_object_create(p, xctx)
Create an empty unmanaged object in memory.
afw_object_set_property(const afw_object_t *instance, const afw_utf8_t *property_name, const afw_value_t *value, afw_xctx_t *xctx)
Set the value of an object's property.
#define afw_pool_get_apr_pool(instance)
Call method get_apr_pool of interface afw_pool.
#define afw_pool_calloc_type(instance, type, xctx)
Macro to allocate cleared memory to hold type in pool.
const afw_pool_t * afw_pool_create(const afw_pool_t *parent, afw_xctx_t *xctx)
Create a new pool.
const afw_pool_t * afw_pool_create_multithreaded(const afw_pool_t *parent, afw_xctx_t *xctx)
Create a new multithreaded pool.
afw_query_criteria_test_object(const afw_object_t *obj, const afw_query_criteria_t *criteria, const afw_pool_t *p, afw_xctx_t *xctx)
Test object against query criteria.
#define afw_service_type_start_cede_p(instance, properties, p, xctx)
Call method start_cede_p of interface afw_service_type.
#define afw_service_type_restart_cede_p(instance, properties, p, xctx)
Call method restart_cede_p of interface afw_service_type.
#define afw_service_type_related_instance_count(instance, id, xctx)
Call method related_instance_count of interface afw_service_type.
#define afw_service_type_stop(instance, id, xctx)
Call method stop of interface afw_service_type.
afw_service_startup_description(afw_service_startup_t startup)
Get description for a afw_service_startup_t enum.
afw_service_restart(const afw_utf8_t *service_id, afw_xctx_t *xctx)
Restart a service.
afw_service_startup_as_value(afw_service_startup_t startup)
Convert afw_service_startup_t enum to corresponding adaptive value.
afw_service_start_using_AdaptiveConf_cede_p(const afw_object_t *conf, const afw_utf8_t *source_location, const afw_pool_t *p, afw_xctx_t *xctx)
Start a service using AdaptiveConf object and cede p.
afw_service_stop(const afw_utf8_t *service_id, afw_xctx_t *xctx)
Stop a service.
const afw_object_t * afw_service_get_object(const afw_utf8_t *service_id, const afw_pool_t *p, afw_xctx_t *xctx)
Get a service object by service id.
const afw_utf8_t * afw_service_status_description(afw_service_status_t status)
Get description for a afw_service_status_t enum.
afw_service_status_as_enum(const afw_utf8_t *s)
Convert utf8 to corresponding afw_service_status_t enum.
afw_service_status_as_utf8(afw_service_status_t status)
Convert afw_service_status_t enum to corresponding utf8.
const afw_value_t * afw_service_status_description_as_value(afw_service_status_t status)
Get description as value for a afw_service_status_t enum.
afw_service_startup_description_as_value(afw_service_startup_t startup)
Get description as value for a afw_service_startup_t enum.
afw_service_status_as_value(afw_service_status_t status)
Convert afw_service_status_t enum to corresponding adaptive value.
afw_service_startup_as_utf8(afw_service_startup_t startup)
Convert afw_service_startup_t enum to corresponding utf8.
afw_service_start(const afw_utf8_t *service_id, afw_boolean_t manual_start, afw_xctx_t *xctx)
Start a service.
afw_service_startup_t afw_service_startup_as_enum(const afw_utf8_t *s)
Convert utf8 to corresponding afw_service_startup_t enum.
#define AFW_THREAD_MUTEX_UNLOCK()
Macro to end a mutex lock.
#define AFW_THREAD_MUTEX_LOCK(mutex, xctx)
Macro to begin a mutex lock section.
afw_dateTime_set_now(afw_dateTime_t *dateTime_local, afw_dateTime_t *dateTime_utc, afw_xctx_t *xctx)
Set local and/or utc dateTime to now.
#define afw_utf8_create_copy(s, len, p, xctx)
Make a utf-8 sting from chars in pool specified.
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.
const afw_utf8_t * afw_utf8_clone(const afw_utf8_t *string, const afw_pool_t *p, afw_xctx_t *xctx)
Clone a utf-8 string into a specific pool.
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.
Internal request info used by afw_adaptor_impl*() functions.
Interface afw_adaptor_session public struct.
const afw_utf8_t * subtype_property_name
Subtype property name for instances of this conf type.
const afw_utf8_t * id_property_name
Id property name for instances of this conf type.
const afw_utf8_t * id_runtime_object_type_id
Runtime object type for instances of this conf type.
const afw_pool_t * p
Pool used to hold environment.
const afw_adaptor_t * conf_adaptor
Adaptor for application.confAdaptorId or NULL.
Interface afw_object public struct.
Interface afw_pool public struct.
const afw_utf8_t * status_message
Optional status message.
afw_utf8_t service_id
Service's name.
const afw_utf8_t * conf_source_location
The source location associated with the conf for this service.
afw_thread_mutex_t * mutex
Mutex used when changing status.
afw_dateTime_t start_time
Start time.
afw_boolean_t has_service_conf
Has a service conf object.
const afw_pool_t * p
Pool that holds service's resources.
const afw_utf8_t * source_location
The source location associated with this service.
const afw_service_type_t * service_type
afw_service_type instance for this service_type_id.
const afw_utf8_t * conf_subtype
This is the value of the subtype property from conf or NULL.
const afw_utf8_t * status_debug
Optional status debug.
const afw_utf8_t * type
The part before the dash ('-') in service_id.
const afw_utf8_t * conf_id
The part after the dash ('-') in the service id.
const afw_object_t * properties
The properties object containing runtime and conf properties.
afw_service_status_t status
The status of the service.
Interface afw_service_type public struct.
NFC normalized UTF-8 string.
Interface afw_value public struct.
struct for data type string values.
Interface afw_xctx public struct.