Apache Celix  latest
Apache Celix is a framework for C, C++14 and C++17 to develop dynamic modular software applications using component and in-process service-oriented programming.
celix_dm_component.h
Go to the documentation of this file.
1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one
3  * or more contributor license agreements. See the NOTICE file
4  * distributed with this work for additional information
5  * regarding copyright ownership. The ASF licenses this file
6  * to you under the Apache License, Version 2.0 (the
7  * "License"); you may not use this file except in compliance
8  * with the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing,
13  * software distributed under the License is distributed on an
14  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15  * KIND, either express or implied. See the License for the
16  * specific language governing permissions and limitations
17  * under the License.
18  */
19 
20 #ifndef CELIX_COMPONENT_H_
21 #define CELIX_COMPONENT_H_
22 
23 #include <stdbool.h>
24 
25 #include "celix_types.h"
26 #include "celix_errno.h"
27 #include "celix_properties.h"
28 #include "celix_array_list.h"
29 #include "celix_dm_info.h"
30 #include "celix_framework_export.h"
31 #include "celix_cleanup.h"
32 
33 #ifdef __cplusplus
34 extern "C" {
35 #endif
36 
37 #define CELIX_DM_COMPONENT_UUID "component.uuid"
38 
51 
61 
62 #define CELIX_DM_COMPONENT_MAX_ID_LENGTH 64
63 #define CELIX_DM_COMPONENT_MAX_NAME_LENGTH 128
64 
65 typedef int (*celix_dm_cmp_lifecycle_fpt)(void *userData);
66 typedef void (*celix_dm_cmp_impl_destroy_fpt)(void*);
67 
72 CELIX_FRAMEWORK_EXPORT celix_dm_component_t* celix_dmComponent_create(celix_bundle_context_t *context, const char* name);
73 
78 CELIX_FRAMEWORK_EXPORT celix_dm_component_t* celix_dmComponent_createWithUUID(celix_bundle_context_t *context, const char* name, const char* UUID);
79 
83 CELIX_FRAMEWORK_EXPORT const char* celix_dmComponent_getUUID(celix_dm_component_t* cmp);
84 
88 CELIX_FRAMEWORK_EXPORT void celix_dmComponent_destroy(celix_dm_component_t* cmp);
89 
91 
97 CELIX_FRAMEWORK_EXPORT void celix_dmComponent_destroyAsync(celix_dm_component_t* cmp, void *doneData, void (*doneCallback)(void*));
98 
103 CELIX_FRAMEWORK_DEPRECATED_EXPORT celix_status_t celix_dmComponent_setCLanguageProperty(celix_dm_component_t *component, bool setCLangProp);
104 
105 
113 CELIX_FRAMEWORK_EXPORT celix_status_t celix_dmComponent_addInterface(celix_dm_component_t *component, const char* serviceName, const char* serviceVersion, const void* service, celix_properties_t *properties);
114 
121 CELIX_FRAMEWORK_EXPORT celix_status_t celix_dmComponent_removeInterface(celix_dm_component_t *component, const void* service);
125 CELIX_FRAMEWORK_EXPORT celix_status_t celix_dmComponent_setImplementation(celix_dm_component_t *component, void* implementation);
126 
136 CELIX_FRAMEWORK_EXPORT void celix_dmComponent_setImplementationDestroyFunction(celix_dm_component_t* cmp, celix_dm_cmp_impl_destroy_fpt destroyFn);
137 
141 #define CELIX_DM_COMPONENT_SET_IMPLEMENTATION_DESTROY_FUNCTION(dmCmp, type, destroy) \
142  do { \
143  void (*_destroyFunction)(type*) = (destroy); \
144  celix_dmComponent_setImplementationDestroyFunction((dmCmp), (void(*)(void*))_destroyFunction); \
145  } while(0)
146 
150 CELIX_FRAMEWORK_EXPORT celix_status_t celix_dmComponent_getInterfaces(celix_dm_component_t *component, celix_array_list_t **servicesNames);
151 
155 CELIX_FRAMEWORK_EXPORT celix_status_t celix_dmComponent_addServiceDependency(celix_dm_component_t *component, celix_dm_service_dependency_t *dep);
156 
160 CELIX_FRAMEWORK_EXPORT celix_status_t celix_dmComponent_removeServiceDependency(celix_dm_component_t *component, celix_dm_service_dependency_t *dependency);
161 
165 CELIX_FRAMEWORK_EXPORT celix_dm_component_state_t celix_dmComponent_currentState(celix_dm_component_t* cmp);
166 
170 CELIX_FRAMEWORK_EXPORT void * celix_dmComponent_getImplementation(celix_dm_component_t* cmp);
171 
175 CELIX_FRAMEWORK_EXPORT celix_dm_cmp_impl_destroy_fpt celix_dmComponent_getImplementationDestroyFunction(celix_dm_component_t* cmp);
176 
180 CELIX_FRAMEWORK_EXPORT const char* celix_dmComponent_getName(celix_dm_component_t* cmp);
181 
185 CELIX_FRAMEWORK_EXPORT celix_bundle_context_t* celix_dmComponent_getBundleContext(celix_dm_component_t *component);
186 
191 CELIX_FRAMEWORK_EXPORT celix_status_t celix_dmComponent_setCallbacks(celix_dm_component_t *component, celix_dm_cmp_lifecycle_fpt init, celix_dm_cmp_lifecycle_fpt start, celix_dm_cmp_lifecycle_fpt stop, celix_dm_cmp_lifecycle_fpt deinit);
192 
196 #define CELIX_DM_COMPONENT_SET_CALLBACKS(dmCmp, type, init, start, stop, deinit) \
197  do { \
198  int (*_tmp_init)(type*) = (init); \
199  int (*_tmp_start)(type*) = (start); \
200  int (*_tmp_stop)(type*) = (stop); \
201  int (*_tmp_deinit)(type*) = (deinit); \
202  celix_dmComponent_setCallbacks((dmCmp), (celix_dm_cmp_lifecycle_fpt)_tmp_init, (celix_dm_cmp_lifecycle_fpt)_tmp_start, (celix_dm_cmp_lifecycle_fpt)_tmp_stop, (celix_dm_cmp_lifecycle_fpt)_tmp_deinit); \
203  } while(0)
204 
205 
206 CELIX_FRAMEWORK_EXPORT bool celix_dmComponent_isActive(celix_dm_component_t *component);
207 
211 CELIX_FRAMEWORK_EXPORT const char* celix_dmComponent_stateToString(celix_dm_component_state_t state);
212 
217 #define CELIX_DMCOMPONENT_SETCALLBACKS(dmCmp, type, init, start, stop, deinit) \
218  CELIX_DM_COMPONENT_SET_CALLBACKS(dmCmp, type*, init, start, stop, deinit)
219 
224 CELIX_FRAMEWORK_EXPORT celix_status_t celix_dmComponent_getComponentInfo(celix_dm_component_t *component, celix_dm_component_info_t** infoOut);
225 
233 CELIX_FRAMEWORK_EXPORT void celix_dmComponent_printComponentInfo(celix_dm_component_info_t* info, bool printFullInfo, bool useAnsiColors, FILE* stream);
234 
238 CELIX_FRAMEWORK_EXPORT void celix_dmComponent_destroyComponentInfo(dm_component_info_pt info);
239 
240 
241 #ifdef __cplusplus
242 }
243 #endif
244 
245 #endif /* COMPONENT_H_ */
CELIX_DM_CMP_STATE_INITIALIZED_AND_WAITING_FOR_REQUIRED
@ CELIX_DM_CMP_STATE_INITIALIZED_AND_WAITING_FOR_REQUIRED
Definition: celix_dm_component.h:44
celix_dmComponent_destroy
CELIX_FRAMEWORK_EXPORT void celix_dmComponent_destroy(celix_dm_component_t *cmp)
celix_dmComponent_destroyComponentInfo
CELIX_FRAMEWORK_EXPORT void celix_dmComponent_destroyComponentInfo(dm_component_info_pt info)
celix_dmComponent_destroyAsync
CELIX_FRAMEWORK_EXPORT void celix_dmComponent_destroyAsync(celix_dm_component_t *cmp, void *doneData, void(*doneCallback)(void *))
celix_dmComponent_setImplementation
CELIX_FRAMEWORK_EXPORT celix_status_t celix_dmComponent_setImplementation(celix_dm_component_t *component, void *implementation)
celix_dm_info.h
CELIX_DM_CMP_STATE_WAITING_FOR_REQUIRED
@ CELIX_DM_CMP_STATE_WAITING_FOR_REQUIRED
Definition: celix_dm_component.h:41
CELIX_DM_CMP_STATE_SUSPENDING
@ CELIX_DM_CMP_STATE_SUSPENDING
Definition: celix_dm_component.h:48
CELIX_DM_CMP_STATE_TRACKING_OPTIONAL
@ CELIX_DM_CMP_STATE_TRACKING_OPTIONAL
Definition: celix_dm_component.h:47
CELIX_DM_CMP_STATE_INACTIVE
@ CELIX_DM_CMP_STATE_INACTIVE
Definition: celix_dm_component.h:40
celix_dmComponent_getComponentInfo
CELIX_FRAMEWORK_EXPORT celix_status_t celix_dmComponent_getComponentInfo(celix_dm_component_t *component, celix_dm_component_info_t **infoOut)
CELIX_DM_CMP_STATE_SUSPENDED
@ CELIX_DM_CMP_STATE_SUSPENDED
Definition: celix_dm_component.h:49
celix_dm_cmp_impl_destroy_fpt
void(* celix_dm_cmp_impl_destroy_fpt)(void *)
Definition: celix_dm_component.h:66
celix_dmComponent_removeServiceDependency
CELIX_FRAMEWORK_EXPORT celix_status_t celix_dmComponent_removeServiceDependency(celix_dm_component_t *component, celix_dm_service_dependency_t *dependency)
celix_dm_cmp_lifecycle_fpt
int(* celix_dm_cmp_lifecycle_fpt)(void *userData)
Definition: celix_dm_component.h:65
celix_dmComponent_create
CELIX_FRAMEWORK_EXPORT celix_dm_component_t * celix_dmComponent_create(celix_bundle_context_t *context, const char *name)
CELIX_DM_CMP_STATE_RESUMING
@ CELIX_DM_CMP_STATE_RESUMING
Definition: celix_dm_component.h:50
celix_dmComponent_getImplementationDestroyFunction
CELIX_FRAMEWORK_EXPORT celix_dm_cmp_impl_destroy_fpt celix_dmComponent_getImplementationDestroyFunction(celix_dm_component_t *cmp)
DM_CMP_STATE_WAITING_FOR_REQUIRED
@ DM_CMP_STATE_WAITING_FOR_REQUIRED
Definition: celix_dm_component.h:57
celix_dmComponent_getUUID
const CELIX_FRAMEWORK_EXPORT char * celix_dmComponent_getUUID(celix_dm_component_t *cmp)
celix_dmComponent_getInterfaces
CELIX_FRAMEWORK_EXPORT celix_status_t celix_dmComponent_getInterfaces(celix_dm_component_t *component, celix_array_list_t **servicesNames)
CELIX_DM_CMP_STATE_STARTING
@ CELIX_DM_CMP_STATE_STARTING
Definition: celix_dm_component.h:45
CELIX_DEFINE_AUTOPTR_CLEANUP_FUNC
CELIX_DEFINE_AUTOPTR_CLEANUP_FUNC(celix_dm_component_t, celix_dmComponent_destroy)
celix_dmComponent_setImplementationDestroyFunction
CELIX_FRAMEWORK_EXPORT void celix_dmComponent_setImplementationDestroyFunction(celix_dm_component_t *cmp, celix_dm_cmp_impl_destroy_fpt destroyFn)
celix_dmComponent_setCLanguageProperty
CELIX_FRAMEWORK_DEPRECATED_EXPORT celix_status_t celix_dmComponent_setCLanguageProperty(celix_dm_component_t *component, bool setCLangProp)
celix_dmComponent_addServiceDependency
CELIX_FRAMEWORK_EXPORT celix_status_t celix_dmComponent_addServiceDependency(celix_dm_component_t *component, celix_dm_service_dependency_t *dep)
celix_dmComponent_currentState
CELIX_FRAMEWORK_EXPORT celix_dm_component_state_t celix_dmComponent_currentState(celix_dm_component_t *cmp)
DM_CMP_STATE_TRACKING_OPTIONAL
@ DM_CMP_STATE_TRACKING_OPTIONAL
Definition: celix_dm_component.h:59
celix_dmComponent_isActive
CELIX_FRAMEWORK_EXPORT bool celix_dmComponent_isActive(celix_dm_component_t *component)
celix_dmComponent_printComponentInfo
CELIX_FRAMEWORK_EXPORT void celix_dmComponent_printComponentInfo(celix_dm_component_info_t *info, bool printFullInfo, bool useAnsiColors, FILE *stream)
celix_dmComponent_addInterface
CELIX_FRAMEWORK_EXPORT celix_status_t celix_dmComponent_addInterface(celix_dm_component_t *component, const char *serviceName, const char *serviceVersion, const void *service, celix_properties_t *properties)
CELIX_DM_CMP_STATE_STOPPING
@ CELIX_DM_CMP_STATE_STOPPING
Definition: celix_dm_component.h:46
celix_dmComponent_removeInterface
CELIX_FRAMEWORK_EXPORT celix_status_t celix_dmComponent_removeInterface(celix_dm_component_t *component, const void *service)
celix_dmComponent_getName
const CELIX_FRAMEWORK_EXPORT char * celix_dmComponent_getName(celix_dm_component_t *cmp)
celix_dmComponent_setCallbacks
CELIX_FRAMEWORK_EXPORT celix_status_t celix_dmComponent_setCallbacks(celix_dm_component_t *component, celix_dm_cmp_lifecycle_fpt init, celix_dm_cmp_lifecycle_fpt start, celix_dm_cmp_lifecycle_fpt stop, celix_dm_cmp_lifecycle_fpt deinit)
celix_dmComponent_getImplementation
CELIX_FRAMEWORK_EXPORT void * celix_dmComponent_getImplementation(celix_dm_component_t *cmp)
celix_dm_component_info_struct
Definition: celix_dm_info.h:53
DM_CMP_STATE_INSTANTIATED_AND_WAITING_FOR_REQUIRED
@ DM_CMP_STATE_INSTANTIATED_AND_WAITING_FOR_REQUIRED
Definition: celix_dm_component.h:58
celix_dmComponent_createWithUUID
CELIX_FRAMEWORK_EXPORT celix_dm_component_t * celix_dmComponent_createWithUUID(celix_bundle_context_t *context, const char *name, const char *UUID)
celix_dmComponent_stateToString
const CELIX_FRAMEWORK_EXPORT char * celix_dmComponent_stateToString(celix_dm_component_state_t state)
CELIX_DM_CMP_STATE_INITIALIZING
@ CELIX_DM_CMP_STATE_INITIALIZING
Definition: celix_dm_component.h:42
celix_dmComponent_getBundleContext
CELIX_FRAMEWORK_EXPORT celix_bundle_context_t * celix_dmComponent_getBundleContext(celix_dm_component_t *component)
CELIX_DM_CMP_STATE_DEINITIALIZING
@ CELIX_DM_CMP_STATE_DEINITIALIZING
Definition: celix_dm_component.h:43
celix_dm_component_state_t
enum celix_dm_component_state_enum celix_dm_component_state_t
DM_CMP_STATE_INACTIVE
@ DM_CMP_STATE_INACTIVE
Definition: celix_dm_component.h:56
celix_dm_component_state_enum
celix_dm_component_state_enum
Definition: celix_dm_component.h:39