Apache Celix  2.4.0
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 
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
35 
36 #define CELIX_DM_COMPONENT_UUID "component.uuid"
37 
50 
60 
61 #define CELIX_DM_COMPONENT_MAX_ID_LENGTH 64
62 #define CELIX_DM_COMPONENT_MAX_NAME_LENGTH 128
63 
64 typedef int (*celix_dm_cmp_lifecycle_fpt)(void *userData);
65 typedef void (*celix_dm_cmp_impl_destroy_fpt)(void*);
66 
71 CELIX_FRAMEWORK_EXPORT celix_dm_component_t* celix_dmComponent_create(celix_bundle_context_t *context, const char* name);
72 
77 CELIX_FRAMEWORK_EXPORT celix_dm_component_t* celix_dmComponent_createWithUUID(celix_bundle_context_t *context, const char* name, const char* UUID);
78 
82 CELIX_FRAMEWORK_EXPORT const char* celix_dmComponent_getUUID(celix_dm_component_t* cmp);
83 
87 CELIX_FRAMEWORK_EXPORT void celix_dmComponent_destroy(celix_dm_component_t* cmp);
88 
94 CELIX_FRAMEWORK_EXPORT void celix_dmComponent_destroyAsync(celix_dm_component_t* cmp, void *doneData, void (*doneCallback)(void*));
95 
100 CELIX_FRAMEWORK_DEPRECATED_EXPORT celix_status_t celix_dmComponent_setCLanguageProperty(celix_dm_component_t *component, bool setCLangProp);
101 
102 
110 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);
111 
118 CELIX_FRAMEWORK_EXPORT celix_status_t celix_dmComponent_removeInterface(celix_dm_component_t *component, const void* service);
122 CELIX_FRAMEWORK_EXPORT celix_status_t celix_dmComponent_setImplementation(celix_dm_component_t *component, void* implementation);
123 
133 CELIX_FRAMEWORK_EXPORT void celix_dmComponent_setImplementationDestroyFunction(celix_dm_component_t* cmp, celix_dm_cmp_impl_destroy_fpt destroyFn);
134 
138 #define CELIX_DM_COMPONENT_SET_IMPLEMENTATION_DESTROY_FUNCTION(dmCmp, type, destroy) \
139  do { \
140  void (*_destroyFunction)(type*) = (destroy); \
141  celix_dmComponent_setImplementationDestroyFunction((dmCmp), (void(*)(void*))_destroyFunction); \
142  } while(0)
143 
147 CELIX_FRAMEWORK_EXPORT celix_status_t celix_dmComponent_getInterfaces(celix_dm_component_t *component, celix_array_list_t **servicesNames);
148 
152 CELIX_FRAMEWORK_EXPORT celix_status_t celix_dmComponent_addServiceDependency(celix_dm_component_t *component, celix_dm_service_dependency_t *dep);
153 
157 CELIX_FRAMEWORK_EXPORT celix_status_t celix_dmComponent_removeServiceDependency(celix_dm_component_t *component, celix_dm_service_dependency_t *dependency);
158 
162 CELIX_FRAMEWORK_EXPORT celix_dm_component_state_t celix_dmComponent_currentState(celix_dm_component_t* cmp);
163 
167 CELIX_FRAMEWORK_EXPORT void * celix_dmComponent_getImplementation(celix_dm_component_t* cmp);
168 
172 CELIX_FRAMEWORK_EXPORT celix_dm_cmp_impl_destroy_fpt celix_dmComponent_getImplementationDestroyFunction(celix_dm_component_t* cmp);
173 
177 CELIX_FRAMEWORK_EXPORT const char* celix_dmComponent_getName(celix_dm_component_t* cmp);
178 
182 CELIX_FRAMEWORK_EXPORT celix_bundle_context_t* celix_dmComponent_getBundleContext(celix_dm_component_t *component);
183 
188 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);
189 
193 #define CELIX_DM_COMPONENT_SET_CALLBACKS(dmCmp, type, init, start, stop, deinit) \
194  do { \
195  int (*_tmp_init)(type*) = (init); \
196  int (*_tmp_start)(type*) = (start); \
197  int (*_tmp_stop)(type*) = (stop); \
198  int (*_tmp_deinit)(type*) = (deinit); \
199  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); \
200  } while(0)
201 
202 
203 CELIX_FRAMEWORK_EXPORT bool celix_dmComponent_isActive(celix_dm_component_t *component);
204 
208 CELIX_FRAMEWORK_EXPORT const char* celix_dmComponent_stateToString(celix_dm_component_state_t state);
209 
214 #define CELIX_DMCOMPONENT_SETCALLBACKS(dmCmp, type, init, start, stop, deinit) \
215  CELIX_DM_COMPONENT_SET_CALLBACKS(dmCmp, type*, init, start, stop, deinit)
216 
221 CELIX_FRAMEWORK_EXPORT celix_status_t celix_dmComponent_getComponentInfo(celix_dm_component_t *component, celix_dm_component_info_t** infoOut);
222 
230 CELIX_FRAMEWORK_EXPORT void celix_dmComponent_printComponentInfo(celix_dm_component_info_t* info, bool printFullInfo, bool useAnsiColors, FILE* stream);
231 
235 CELIX_FRAMEWORK_EXPORT void celix_dmComponent_destroyComponentInfo(dm_component_info_pt info);
236 
237 
238 #ifdef __cplusplus
239 }
240 #endif
241 
242 #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:43
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:40
CELIX_DM_CMP_STATE_SUSPENDING
@ CELIX_DM_CMP_STATE_SUSPENDING
Definition: celix_dm_component.h:47
CELIX_DM_CMP_STATE_TRACKING_OPTIONAL
@ CELIX_DM_CMP_STATE_TRACKING_OPTIONAL
Definition: celix_dm_component.h:46
CELIX_DM_CMP_STATE_INACTIVE
@ CELIX_DM_CMP_STATE_INACTIVE
Definition: celix_dm_component.h:39
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:48
celix_dm_cmp_impl_destroy_fpt
void(* celix_dm_cmp_impl_destroy_fpt)(void *)
Definition: celix_dm_component.h:65
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:64
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:49
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:56
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:44
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:58
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:45
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:57
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:41
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:42
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:55
celix_dm_component_state_enum
celix_dm_component_state_enum
Definition: celix_dm_component.h:38