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_bundle_activator.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_BUNDLE_ACTIVATOR_H_
21 #define CELIX_BUNDLE_ACTIVATOR_H_
22 
23 #include <stdlib.h>
24 
25 #include "celix_bundle_context.h"
26 #include "celix_dependency_manager.h"
27 #include "celix_dm_component.h"
29 #include "celix_constants.h"
30 
31 #if defined(__linux__) || defined(__APPLE__)
32 //always export bundle activator symbols
33 #define CELIX_BUNDLE_ACTIVATOR_EXPORT __attribute__((visibility("default")))
34 #else
35 #define CELIX_BUNDLE_ACTIVATOR_EXPORT
36 #endif
37 
38 #ifdef __cplusplus
39 extern "C" {
40 #endif
41 
57 CELIX_BUNDLE_ACTIVATOR_EXPORT celix_status_t celix_bundleActivator_create(celix_bundle_context_t *ctx, void **userData);
58 
76 CELIX_BUNDLE_ACTIVATOR_EXPORT celix_status_t celix_bundleActivator_start(void *userData, celix_bundle_context_t *ctx);
77 
97 CELIX_BUNDLE_ACTIVATOR_EXPORT celix_status_t celix_bundleActivator_stop(void *userData, celix_bundle_context_t *ctx);
98 
115 CELIX_BUNDLE_ACTIVATOR_EXPORT celix_status_t celix_bundleActivator_destroy(void *userData, celix_bundle_context_t* ctx);
116 
138 #define CELIX_GEN_BUNDLE_ACTIVATOR(actType, actStart, actStop) \
139  \
140 celix_status_t celix_bundleActivator_create(celix_bundle_context_t *ctx, void **userData) { \
141  celix_status_t status = CELIX_SUCCESS; \
142  void* data = calloc(1, sizeof(actType)); \
143  if (data != NULL) { \
144  *userData = data; \
145  } else { \
146  status = CELIX_ENOMEM; \
147  } \
148  return status; \
149 } \
150  \
151 celix_status_t celix_bundleActivator_start(void *userData, celix_bundle_context_t *ctx) { \
152  celix_status_t status = CELIX_SUCCESS; \
153  celix_status_t (*fn)(actType*, celix_bundle_context_t*) = (actStart); \
154  if (fn != NULL) { \
155  status = fn((actType*)userData, ctx); \
156  } \
157  return status; \
158 } \
159  \
160 celix_status_t celix_bundleActivator_stop(void *userData, celix_bundle_context_t *ctx) { \
161  celix_status_t status = CELIX_SUCCESS; \
162  celix_status_t (*fn)(actType*, celix_bundle_context_t*) = (actStop); \
163  if (fn != NULL) { \
164  status = fn((actType*)userData, ctx); \
165  } \
166  celix_dependency_manager_t* mng = celix_bundleContext_getDependencyManager(ctx); \
167  celix_dependencyManager_removeAllComponents(mng); \
168  return status; \
169 } \
170  \
171 celix_status_t celix_bundleActivator_destroy(void *userData, celix_bundle_context_t *ctx) { \
172  celix_bundleContext_waitForEvents(ctx); \
173  free(userData); \
174  return CELIX_SUCCESS; \
175 }
176 
177 #ifdef __cplusplus
178 }
179 #endif
180 
181 #endif /* CELIX_BUNDLE_ACTIVATOR_H_ */
celix_bundleActivator_stop
CELIX_BUNDLE_ACTIVATOR_EXPORT celix_status_t celix_bundleActivator_stop(void *userData, celix_bundle_context_t *ctx)
Called when this bundle is stopped so the Framework can perform the bundle-specific activities necess...
CELIX_BUNDLE_ACTIVATOR_EXPORT
#define CELIX_BUNDLE_ACTIVATOR_EXPORT
Definition: celix_bundle_activator.h:35
celix_bundleActivator_destroy
CELIX_BUNDLE_ACTIVATOR_EXPORT celix_status_t celix_bundleActivator_destroy(void *userData, celix_bundle_context_t *ctx)
Called when this bundle is stopped so the bundle can destroy the instance of its activator.
celix_dm_service_dependency.h
celix_bundleActivator_start
CELIX_BUNDLE_ACTIVATOR_EXPORT celix_status_t celix_bundleActivator_start(void *userData, celix_bundle_context_t *ctx)
Called when this bundle is started so the Framework can perform the bundle-specific activities necess...
celix_dm_component.h
celix_bundle_context.h
celix_bundleActivator_create
CELIX_BUNDLE_ACTIVATOR_EXPORT celix_status_t celix_bundleActivator_create(celix_bundle_context_t *ctx, void **userData)
Called when this bundle is started so the bundle can create an instance for its activator.