-
Notifications
You must be signed in to change notification settings - Fork 97
Expand file tree
/
Copy pathcelix_dm_service_dependency.h
More file actions
176 lines (149 loc) · 7.86 KB
/
celix_dm_service_dependency.h
File metadata and controls
176 lines (149 loc) · 7.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
#ifndef CELIX_DM_SERVICE_DEPENDENCY_H_
#define CELIX_DM_SERVICE_DEPENDENCY_H_
#include "celix_types.h"
#include "celix_errno.h"
#include "celix_threads.h"
#include "celix_dm_info.h"
#include "celix_framework_export.h"
#include "celix_cleanup.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef enum celix_dm_service_dependency_strategy_enum {
DM_SERVICE_DEPENDENCY_STRATEGY_LOCKING,
DM_SERVICE_DEPENDENCY_STRATEGY_SUSPEND
} celix_dm_service_dependency_strategy_t;
typedef int (*celix_dm_service_update_fp)(void *handle, void* service);
typedef int (*celix_dm_service_swap_fp)(void *handle, void* oldService, void* newService);
typedef int (*celix_dm_service_update_with_props_fp)(void *handle, void* service, const celix_properties_t *props);
typedef int (*celix_dm_service_swap_with_props_fp)(void *handle, void* oldService, void* newService, const celix_properties_t *newProps);
typedef struct celix_dm_service_dependency_callback_options {
celix_dm_service_update_fp set;
celix_dm_service_update_fp add;
celix_dm_service_update_fp remove;
celix_dm_service_swap_fp swap; //not used, deprecated
celix_dm_service_update_with_props_fp setWithProps;
celix_dm_service_update_with_props_fp addWithProps;
celix_dm_service_update_with_props_fp removeWithProps;
celix_dm_service_swap_with_props_fp swapWithProps; //not used, deprecated
} celix_dm_service_dependency_callback_options_t;
#define CELIX_EMPTY_DM_SERVICE_DEPENDENCY_CALLBACK_OPTIONS { .set = NULL, \
.add = NULL, \
.remove = NULL, \
.swap = NULL, \
.setWithProps = NULL, \
.addWithProps = NULL, \
.removeWithProps = NULL, \
.swapWithProps = NULL }
/**
* Create a service dependency.
* Caller has ownership.
*
* \warning The dmServiceDependency is not thread safe when constructing or modifying.
* The handling of service updates is thread safe.
*/
CELIX_FRAMEWORK_EXPORT celix_dm_service_dependency_t* celix_dmServiceDependency_create(void);
/**
* Destroys a service dependency.
* Will normally be done the by the DM Component.
*
* Can only be called if the serviceDependency is disabled (note that a service dependency not added to a
* component is disabled).
*/
CELIX_FRAMEWORK_EXPORT void celix_dmServiceDependency_destroy(celix_dm_service_dependency_t *dep);
CELIX_DEFINE_AUTOPTR_CLEANUP_FUNC(celix_dm_service_dependency_t, celix_dmServiceDependency_destroy);
/**
* Specify if the service dependency is required. default is false
*/
CELIX_FRAMEWORK_EXPORT celix_status_t celix_dmServiceDependency_setRequired(celix_dm_service_dependency_t *dependency, bool required);
/**
* Specify the minimum number of services the service dependency requires before being available.
*/
CELIX_FRAMEWORK_EXPORT celix_status_t celix_dmServiceDependency_setMinimalCardinality(celix_dm_service_dependency_t *dependency, size_t minimalCardinality);
/**
* Specify if the service dependency update strategy.
*
* The DM_SERVICE_DEPENDENCY_STRATEGY_LOCKING strategy notifies the component in case the dependencies set
* changes (e.g. a dependency is added/removed): the component is responsible for protecting via locks
* the dependencies list and check (always under lock) if the service he's depending on is still available.
*
* The DM_SERVICE_DEPENDENCY_STRATEGY_SUSPEND (default when no strategy is explicitly set) reliefs the programmer
* from dealing with service dependencies' consistency issues: in case this strategy is adopted, the component
* is stopped and restarted (i.e. temporarily suspended) upon service dependencies' changes.
*
* Default strategy is DM_SERVICE_DEPENDENCY_STRATEGY_SUSPEND
*/
CELIX_FRAMEWORK_EXPORT celix_status_t celix_dmServiceDependency_setStrategy(celix_dm_service_dependency_t *dependency, celix_dm_service_dependency_strategy_t strategy);
/**
* Return the service dependency update strategy.
*/
CELIX_FRAMEWORK_EXPORT celix_dm_service_dependency_strategy_t celix_dmServiceDependency_getStrategy(celix_dm_service_dependency_t *dependency);
/**
* Set the service name, version range and filter.
*
* @param serviceName The service name. Must have a value.
* @param serviceVersionRange The service version range, can be a NULL pointer.
* @param filter The (additional) filter to use (e.g. "(location=front)"). Can be a NULL pointer.
*/
CELIX_FRAMEWORK_EXPORT celix_status_t celix_dmServiceDependency_setService(celix_dm_service_dependency_t *dependency, const char* serviceName, const char* serviceVersionRange, const char* filter);
/**
* Returns the service dependency filter.
*/
CELIX_FRAMEWORK_EXPORT const char* celix_dmServiceDependency_getFilter(celix_dm_service_dependency_t *dependency);
/**
* Set the set callbacks when services specified by the service dependency
* The first argument of the callbacks will be the component implement (@see component_getImplementation)
* The second the argument a pointer to an instance of a service struct of the specified service dependency.
*/
CELIX_FRAMEWORK_EXPORT celix_status_t celix_dmServiceDependency_setCallback(celix_dm_service_dependency_t *dependency, celix_dm_service_update_fp set);
/**
* Set the set function callbacks when services specified by the service dependency
* The first argument of the callbacks will be the component implement (@see component_getImplementation)
* The second argument of th callbacks will be a pointer to an instance of a service struct of the specified service dependency.
* The third argument of th callbacks will be a pointer to a service properties of the a service instance of the specified service dependency.
*/
CELIX_FRAMEWORK_EXPORT celix_status_t celix_dmServiceDependency_setCallbackWithProperties(celix_dm_service_dependency_t *dependency, celix_dm_service_update_with_props_fp set);
/**
* Set the set, add, change, remove and swap function callbacks when services specified by the service dependency
* are (respectively) set, added, changed, removed or swapped.
*
* The version with the WithProps suffix will be called with as third argument the service properties.
*/
CELIX_FRAMEWORK_EXPORT celix_status_t celix_dmServiceDependency_setCallbacksWithOptions(celix_dm_service_dependency_t *dependency, const celix_dm_service_dependency_callback_options_t *opts);
/**
* Set the callback handle to be used in the callbacks. Note that this normally should not be set, because the
* result of component_getImplementation() is used
* This can be used in rare cases when the callbacks are actually interceptors. e.g. in the case of C++ support.
*/
CELIX_FRAMEWORK_EXPORT celix_status_t celix_dmServiceDependency_setCallbackHandle(celix_dm_service_dependency_t *dependency, void* handle);
/**
* Creates a service dependency info. The service dependency info struct contains information about the service dependency.
* The caller is the owner
*/
CELIX_FRAMEWORK_EXPORT dm_service_dependency_info_t* celix_dmServiceDependency_createInfo(celix_dm_service_dependency_t* dep);
/**
* Destroy a provided service dependency info struct.
*/
CELIX_FRAMEWORK_EXPORT void celix_dmServiceDependency_destroyInfo(celix_dm_service_dependency_t *dep, dm_service_dependency_info_t *info);
#ifdef __cplusplus
}
#endif
#endif /* CELIX_DM_SERVICE_DEPENDENCY_H_ */