Apache Celix  2.3.0
An implementation of the OSGi specification adapted to C and C++
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 "properties.h"
28 #include "array_list.h"
29 #include "celix_dm_info.h"
30 
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
34 
35 #define CELIX_DM_COMPONENT_UUID "component.uuid"
36 
49 
59 
60 #define CELIX_DM_COMPONENT_MAX_ID_LENGTH 64
61 #define CELIX_DM_COMPONENT_MAX_NAME_LENGTH 128
62 
63 typedef int (*celix_dm_cmp_lifecycle_fpt)(void *userData);
64 typedef void (*celix_dm_cmp_impl_destroy_fpt)(void*);
65 
70 celix_dm_component_t* celix_dmComponent_create(celix_bundle_context_t *context, const char* name);
71 
76 celix_dm_component_t* celix_dmComponent_createWithUUID(celix_bundle_context_t *context, const char* name, const char* UUID);
77 
81 const char* celix_dmComponent_getUUID(celix_dm_component_t* cmp);
82 
86 void celix_dmComponent_destroy(celix_dm_component_t* cmp);
87 
93 void celix_dmComponent_destroyAsync(celix_dm_component_t* cmp, void *doneData, void (*doneCallback)(void*));
94 
99 celix_status_t celix_dmComponent_setCLanguageProperty(celix_dm_component_t *component, bool setCLangProp);
100 
101 
109 celix_status_t celix_dmComponent_addInterface(celix_dm_component_t *component, const char* serviceName, const char* serviceVersion, const void* service, celix_properties_t *properties);
110 
117 celix_status_t celix_dmComponent_removeInterface(celix_dm_component_t *component, const void* service);
121 celix_status_t celix_dmComponent_setImplementation(celix_dm_component_t *component, void* implementation);
122 
133 
137 #define CELIX_DM_COMPONENT_SET_IMPLEMENTATION_DESTROY_FUNCTION(dmCmp, type, destroy) \
138  do { \
139  void (*_destroyFunction)(type*) = (destroy); \
140  celix_dmComponent_setImplementationDestroyFunction((dmCmp), (void(*)(void*))_destroyFunction); \
141  } while(0)
142 
146 celix_status_t celix_dmComponent_getInterfaces(celix_dm_component_t *component, celix_array_list_t **servicesNames);
147 
151 celix_status_t celix_dmComponent_addServiceDependency(celix_dm_component_t *component, celix_dm_service_dependency_t *dep);
152 
156 celix_status_t celix_dmComponent_removeServiceDependency(celix_dm_component_t *component, celix_dm_service_dependency_t *dependency);
157 
162 
166 void * celix_dmComponent_getImplementation(celix_dm_component_t* cmp);
167 
172 
176 const char* celix_dmComponent_getName(celix_dm_component_t* cmp);
177 
181 celix_bundle_context_t* celix_dmComponent_getBundleContext(celix_dm_component_t *component);
182 
188 
192 #define CELIX_DM_COMPONENT_SET_CALLBACKS(dmCmp, type, init, start, stop, deinit) \
193  do { \
194  int (*_tmp_init)(type*) = (init); \
195  int (*_tmp_start)(type*) = (start); \
196  int (*_tmp_stop)(type*) = (stop); \
197  int (*_tmp_deinit)(type*) = (deinit); \
198  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); \
199  } while(0)
200 
201 
202 bool celix_dmComponent_isActive(celix_dm_component_t *component);
203 
208 
213 #define CELIX_DMCOMPONENT_SETCALLBACKS(dmCmp, type, init, start, stop, deinit) \
214  CELIX_DM_COMPONENT_SET_CALLBACKS(dmCmp, type*, init, start, stop, deinit)
215 
220 celix_status_t celix_dmComponent_getComponentInfo(celix_dm_component_t *component, celix_dm_component_info_t** infoOut);
221 
229 void celix_dmComponent_printComponentInfo(celix_dm_component_info_t* info, bool printFullInfo, bool useAnsiColors, FILE* stream);
230 
235 
236 
237 #ifdef __cplusplus
238 }
239 #endif
240 
241 #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:42
celix_dmComponent_setCLanguageProperty
celix_status_t celix_dmComponent_setCLanguageProperty(celix_dm_component_t *component, bool setCLangProp)
celix_dmComponent_addInterface
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_dmComponent_setCallbacks
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_dm_info.h
celix_dmComponent_getImplementationDestroyFunction
celix_dm_cmp_impl_destroy_fpt celix_dmComponent_getImplementationDestroyFunction(celix_dm_component_t *cmp)
CELIX_DM_CMP_STATE_WAITING_FOR_REQUIRED
@ CELIX_DM_CMP_STATE_WAITING_FOR_REQUIRED
Definition: celix_dm_component.h:39
CELIX_DM_CMP_STATE_SUSPENDING
@ CELIX_DM_CMP_STATE_SUSPENDING
Definition: celix_dm_component.h:46
CELIX_DM_CMP_STATE_TRACKING_OPTIONAL
@ CELIX_DM_CMP_STATE_TRACKING_OPTIONAL
Definition: celix_dm_component.h:45
celix_dmComponent_getComponentInfo
celix_status_t celix_dmComponent_getComponentInfo(celix_dm_component_t *component, celix_dm_component_info_t **infoOut)
celix_dmComponent_createWithUUID
celix_dm_component_t * celix_dmComponent_createWithUUID(celix_bundle_context_t *context, const char *name, const char *UUID)
CELIX_DM_CMP_STATE_INACTIVE
@ CELIX_DM_CMP_STATE_INACTIVE
Definition: celix_dm_component.h:38
celix_dmComponent_getImplementation
void * celix_dmComponent_getImplementation(celix_dm_component_t *cmp)
CELIX_DM_CMP_STATE_SUSPENDED
@ CELIX_DM_CMP_STATE_SUSPENDED
Definition: celix_dm_component.h:47
celix_dmComponent_currentState
celix_dm_component_state_t celix_dmComponent_currentState(celix_dm_component_t *cmp)
celix_dmComponent_setImplementation
celix_status_t celix_dmComponent_setImplementation(celix_dm_component_t *component, void *implementation)
celix_dm_cmp_impl_destroy_fpt
void(* celix_dm_cmp_impl_destroy_fpt)(void *)
Definition: celix_dm_component.h:64
celix_dmComponent_create
celix_dm_component_t * celix_dmComponent_create(celix_bundle_context_t *context, const char *name)
celix_dmComponent_getBundleContext
celix_bundle_context_t * celix_dmComponent_getBundleContext(celix_dm_component_t *component)
celix_dm_cmp_lifecycle_fpt
int(* celix_dm_cmp_lifecycle_fpt)(void *userData)
Definition: celix_dm_component.h:63
CELIX_DM_CMP_STATE_RESUMING
@ CELIX_DM_CMP_STATE_RESUMING
Definition: celix_dm_component.h:48
DM_CMP_STATE_WAITING_FOR_REQUIRED
@ DM_CMP_STATE_WAITING_FOR_REQUIRED
Definition: celix_dm_component.h:55
celix_dmComponent_setImplementationDestroyFunction
void celix_dmComponent_setImplementationDestroyFunction(celix_dm_component_t *cmp, celix_dm_cmp_impl_destroy_fpt destroyFn)
CELIX_DM_CMP_STATE_STARTING
@ CELIX_DM_CMP_STATE_STARTING
Definition: celix_dm_component.h:43
celix_dmComponent_stateToString
const char * celix_dmComponent_stateToString(celix_dm_component_state_t state)
celix_dmComponent_printComponentInfo
void celix_dmComponent_printComponentInfo(celix_dm_component_info_t *info, bool printFullInfo, bool useAnsiColors, FILE *stream)
celix_dmComponent_destroyAsync
void celix_dmComponent_destroyAsync(celix_dm_component_t *cmp, void *doneData, void(*doneCallback)(void *))
DM_CMP_STATE_TRACKING_OPTIONAL
@ DM_CMP_STATE_TRACKING_OPTIONAL
Definition: celix_dm_component.h:57
celix_dmComponent_addServiceDependency
celix_status_t celix_dmComponent_addServiceDependency(celix_dm_component_t *component, celix_dm_service_dependency_t *dep)
celix_dmComponent_getUUID
const char * celix_dmComponent_getUUID(celix_dm_component_t *cmp)
celix_dmComponent_removeServiceDependency
celix_status_t celix_dmComponent_removeServiceDependency(celix_dm_component_t *component, celix_dm_service_dependency_t *dependency)
CELIX_DM_CMP_STATE_STOPPING
@ CELIX_DM_CMP_STATE_STOPPING
Definition: celix_dm_component.h:44
celix_dmComponent_isActive
bool celix_dmComponent_isActive(celix_dm_component_t *component)
celix_dmComponent_getInterfaces
celix_status_t celix_dmComponent_getInterfaces(celix_dm_component_t *component, celix_array_list_t **servicesNames)
celix_dmComponent_destroyComponentInfo
void celix_dmComponent_destroyComponentInfo(dm_component_info_pt info)
celix_dmComponent_getName
const char * celix_dmComponent_getName(celix_dm_component_t *cmp)
celix_dm_component_info_struct
Definition: celix_dm_info.h:54
DM_CMP_STATE_INSTANTIATED_AND_WAITING_FOR_REQUIRED
@ DM_CMP_STATE_INSTANTIATED_AND_WAITING_FOR_REQUIRED
Definition: celix_dm_component.h:56
CELIX_DM_CMP_STATE_INITIALIZING
@ CELIX_DM_CMP_STATE_INITIALIZING
Definition: celix_dm_component.h:40
CELIX_DM_CMP_STATE_DEINITIALIZING
@ CELIX_DM_CMP_STATE_DEINITIALIZING
Definition: celix_dm_component.h:41
celix_dmComponent_destroy
void celix_dmComponent_destroy(celix_dm_component_t *cmp)
celix_dmComponent_removeInterface
celix_status_t celix_dmComponent_removeInterface(celix_dm_component_t *component, const void *service)
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:54
celix_dm_component_state_enum
celix_dm_component_state_enum
Definition: celix_dm_component.h:37