Apache Celix  2.3.0
An implementation of the OSGi specification adapted to C and C++
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 #include <stdlib.h>
21 
22 #include "celix_bundle_context.h"
23 #include "celix_dependency_manager.h"
24 
25 #ifndef CELIX_BUNDLE_ACTIVATOR_H_
26 #define CELIX_BUNDLE_ACTIVATOR_H_
27 
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31 
47 celix_status_t celix_bundleActivator_create(celix_bundle_context_t *ctx, void **userData);
48 
66 celix_status_t celix_bundleActivator_start(void *userData, celix_bundle_context_t *ctx);
67 
87 celix_status_t celix_bundleActivator_stop(void *userData, celix_bundle_context_t *ctx);
88 
105 celix_status_t celix_bundleActivator_destroy(void *userData, celix_bundle_context_t* ctx);
106 
128 #define CELIX_GEN_BUNDLE_ACTIVATOR(actType, actStart, actStop) \
129  \
130 celix_status_t celix_bundleActivator_create(celix_bundle_context_t *ctx, void **userData) { \
131  celix_status_t status = CELIX_SUCCESS; \
132  void* data = calloc(1, sizeof(actType)); \
133  if (data != NULL) { \
134  *userData = data; \
135  } else { \
136  status = CELIX_ENOMEM; \
137  } \
138  return status; \
139 } \
140  \
141 celix_status_t celix_bundleActivator_start(void *userData, celix_bundle_context_t *ctx) { \
142  celix_status_t status = CELIX_SUCCESS; \
143  celix_status_t (*fn)(actType*, celix_bundle_context_t*) = (actStart); \
144  if (fn != NULL) { \
145  status = fn((actType*)userData, ctx); \
146  } \
147  return status; \
148 } \
149  \
150 celix_status_t celix_bundleActivator_stop(void *userData, celix_bundle_context_t *ctx) { \
151  celix_status_t status = CELIX_SUCCESS; \
152  celix_status_t (*fn)(actType*, celix_bundle_context_t*) = (actStop); \
153  if (fn != NULL) { \
154  status = fn((actType*)userData, ctx); \
155  } \
156  celix_dependency_manager_t* mng = celix_bundleContext_getDependencyManager(ctx); \
157  celix_dependencyManager_removeAllComponents(mng); \
158  return status; \
159 } \
160  \
161 celix_status_t celix_bundleActivator_destroy(void *userData, celix_bundle_context_t *ctx) { \
162  celix_bundleContext_waitForEvents(ctx); \
163  free(userData); \
164  return CELIX_SUCCESS; \
165 }
166 
167 #ifdef __cplusplus
168 }
169 #endif
170 
171 #endif /* CELIX_BUNDLE_ACTIVATOR_H_ */
celix_bundleActivator_stop
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_bundleActivator_create
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.
celix_bundleActivator_start
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_bundle_context.h
celix_bundleActivator_destroy
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.