Celix  2.2.0
An implementation of the OSGi specification adapted to C and C++
celix_bundle_context.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 "celix_types.h"
21 #include "celix_service_factory.h"
22 #include "celix_properties.h"
23 #include "celix_array_list.h"
24 #include "celix_filter.h"
25 
26 #ifndef CELIX_BUNDLE_CONTEXT_H_
27 #define CELIX_BUNDLE_CONTEXT_H_
28 
29 
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33 
37 #ifdef __cplusplus
38 #define OPTS_INIT {}
39 #else
40 #define OPTS_INIT
41 #endif
42 
52 long celix_bundleContext_registerService(celix_bundle_context_t *ctx, void *svc, const char *serviceName, celix_properties_t *properties);
53 
70 long celix_bundleContext_registerServiceFactory(celix_bundle_context_t *ctx, celix_service_factory_t *factory, const char *serviceName, celix_properties_t *props);
71 
83  void *svc OPTS_INIT;
84 
99  celix_service_factory_t *factory OPTS_INIT;
100 
105  const char *serviceName OPTS_INIT;
106 
114  celix_properties_t *properties OPTS_INIT;
115 
119  const char *serviceLanguage OPTS_INIT;
120 
128  const char *serviceVersion OPTS_INIT;
130 
134 #ifndef __cplusplus
135 #define CELIX_EMPTY_SERVICE_REGISTRATION_OPTIONS { .svc = NULL, \
136  .factory = NULL, \
137  .serviceName = NULL, \
138  .properties = NULL, \
139  .serviceLanguage = NULL, \
140  .serviceVersion = NULL }
141 #endif
142 
143 
151 long celix_bundleContext_registerServiceWithOptions(celix_bundle_context_t *ctx, const celix_service_registration_options_t *opts);
152 
153 
163 void celix_bundleContext_unregisterService(celix_bundle_context_t *ctx, long serviceId);
164 
165 
166 
167 
168 
169 
170 
171 
179 long celix_bundleContext_findService(celix_bundle_context_t *ctx, const char *serviceName);
180 
188 celix_array_list_t* celix_bundleContext_findServices(celix_bundle_context_t *ctx, const char *serviceName);
189 
197  const char* serviceName OPTS_INIT;
198 
204  const char* versionRange OPTS_INIT;
205 
210  const char* filter OPTS_INIT;
211 
215  const char* serviceLanguage OPTS_INIT;
216 
217 
222  bool ignoreServiceLanguage OPTS_INIT;
224 
228 #ifndef __cplusplus
229 #define CELIX_EMPTY_SERVICE_FILTER_OPTIONS {.serviceName = NULL, .versionRange = NULL, .filter = NULL, .serviceLanguage = NULL, .ignoreServiceLanguage = false}
230 #endif
231 
232 
240 long celix_bundleContext_findServiceWithOptions(celix_bundle_context_t *ctx, const celix_service_filter_options_t *opts);
241 
249 celix_array_list_t* celix_bundleContext_findServicesWithOptions(celix_bundle_context_t *ctx, const celix_service_filter_options_t *opts);
250 
251 
265  celix_bundle_context_t* ctx,
266  const char* serviceName,
267  void* callbackHandle,
268  void (*set)(void* handle, void* svc)
269 );
270 
282  celix_bundle_context_t* ctx,
283  const char* serviceName,
284  void* callbackHandle,
285  void (*add)(void* handle, void* svc),
286  void (*remove)(void* handle, void* svc)
287 );
288 
297 
301  void* callbackHandle OPTS_INIT;
302 
309  void (*set)(void *handle, void *svc) OPTS_INIT;
310 
315  void (*setWithProperties)(void *handle, void *svc, const celix_properties_t *props) OPTS_INIT; //highest ranking
316 
321  void (*setWithOwner)(void *handle, void *svc, const celix_properties_t *props, const celix_bundle_t *svcOwner) OPTS_INIT; //highest ranking
322 
329  void (*add)(void *handle, void *svc) OPTS_INIT;
330 
335  void (*addWithProperties)(void *handle, void *svc, const celix_properties_t *props) OPTS_INIT;
336 
341  void (*addWithOwner)(void *handle, void *svc, const celix_properties_t *props, const celix_bundle_t *svcOwner) OPTS_INIT;
342 
352  void (*remove)(void *handle, void *svc) OPTS_INIT;
353 
358  void (*removeWithProperties)(void *handle, void *svc, const celix_properties_t *props) OPTS_INIT;
359 
364  void (*removeWithOwner)(void *handle, void *svc, const celix_properties_t *props, const celix_bundle_t *svcOwner) OPTS_INIT;
366 
370 #ifndef __cplusplus
371 #define CELIX_EMPTY_SERVICE_TRACKING_OPTIONS { .filter.serviceName = NULL, \
372  .filter.versionRange = NULL, \
373  .filter.filter = NULL, \
374  .filter.serviceLanguage = NULL, \
375  .filter.ignoreServiceLanguage = false, \
376  .callbackHandle = NULL, \
377  .set = NULL, \
378  .add = NULL, \
379  .remove = NULL, \
380  .setWithProperties = NULL, \
381  .addWithProperties = NULL, \
382  .removeWithProperties = NULL, \
383  .setWithOwner = NULL, \
384  .addWithOwner = NULL, \
385  .removeWithOwner = NULL}
386 #endif
387 
396 long celix_bundleContext_trackServicesWithOptions(celix_bundle_context_t *ctx, const celix_service_tracking_options_t *opts);
397 
405 void celix_bundleContext_stopTracker(celix_bundle_context_t *ctx, long trackerId);
406 
407 
408 
409 
410 
411 
430  celix_bundle_context_t *ctx,
431  long serviceId,
432  const char *serviceName /*sanity check*/,
433  void *callbackHandle,
434  void (*use)(void *handle, void* svc)
435 );
436 
454  celix_bundle_context_t *ctx,
455  const char* serviceName,
456  void *callbackHandle,
457  void (*use)(void *handle, void *svc)
458 );
459 
476  celix_bundle_context_t *ctx,
477  const char* serviceName,
478  void *callbackHandle,
479  void (*use)(void *handle, void *svc)
480 );
481 
490 
496  double waitTimeoutInSeconds OPTS_INIT;
497 
501  void *callbackHandle OPTS_INIT;
502 
510  void (*use)(void *handle, void *svc) OPTS_INIT;
511 
516  void (*useWithProperties)(void *handle, void *svc, const celix_properties_t *props) OPTS_INIT;
517 
522  void (*useWithOwner)(void *handle, void *svc, const celix_properties_t *props, const celix_bundle_t *svcOwner) OPTS_INIT;
524 
528 #ifndef __cplusplus
529 #define CELIX_EMPTY_SERVICE_USE_OPTIONS {.filter.serviceName = NULL, \
530  .filter.versionRange = NULL, \
531  .filter.filter = NULL, \
532  .filter.serviceLanguage = NULL, \
533  .waitTimeoutInSeconds = 0.0F, \
534  .callbackHandle = NULL, \
535  .use = NULL, \
536  .useWithProperties = NULL, \
537  .useWithOwner = NULL}
538 #endif
539 
555  celix_bundle_context_t *ctx,
556  const celix_service_use_options_t *opts);
557 
558 
573  celix_bundle_context_t *ctx,
574  const celix_service_use_options_t *opts);
575 
576 
577 
578 
586 celix_array_list_t* celix_bundleContext_listBundles(celix_bundle_context_t *ctx);
587 
594 bool celix_bundleContext_isBundleInstalled(celix_bundle_context_t *ctx, long bndId);
595 
596 
606 long celix_bundleContext_installBundle(celix_bundle_context_t *ctx, const char *bundleLoc, bool autoStart);
607 
616 bool celix_bundleContext_uninstallBundle(celix_bundle_context_t *ctx, long bundleId);
617 
626 bool celix_bundleContext_stopBundle(celix_bundle_context_t *ctx, long bundleId);
627 
636 bool celix_bundleContext_startBundle(celix_bundle_context_t *ctx, long bundleId);
637 
649  celix_bundle_context_t* ctx,
650  void* callbackHandle,
651  void (*onStarted)(void* handle, const celix_bundle_t *bundle),
652  void (*onStopped)(void *handle, const celix_bundle_t *bundle)
653 );
654 
655 
663  void* callbackHandle OPTS_INIT;
664 
671  void (*onStarted)(void *handle, const celix_bundle_t *bundle) OPTS_INIT; //highest ranking
672 
679  void (*onStopped)(void *handle, const celix_bundle_t *bundle) OPTS_INIT;
680 
681  //TODO callback for on installed, resolved, uninstalled ??
682 
688  void (*onBundleEvent)(void *handle, const celix_bundle_event_t *event) OPTS_INIT;
689 
694  bool includeFrameworkBundle OPTS_INIT;
696 
700 #ifndef __cplusplus
701 #define CELIX_EMPTY_BUNDLE_TRACKING_OPTIONS {.callbackHandle = NULL, .onStarted = NULL, .onStopped = NULL, .onBundleEvent = NULL}
702 #endif
703 
714  celix_bundle_context_t* ctx,
716 );
717 
730  celix_bundle_context_t *ctx,
731  long bundleId,
732  void *callbackHandle,
733  void (*use)(void *handle, const celix_bundle_t *bundle)
734 );
735 
746  celix_bundle_context_t *ctx,
747  void *callbackHandle,
748  void (*use)(void *handle, const celix_bundle_t *bundle)
749 );
750 
751 
752 
753 //TODO add useBundleWithOptions (e.g. which state)
754 //TODO findBundles
755 
763  celix_filter_t *filter;
764 
768  const char *serviceName;
769 
773  const char *serviceLanguage;
774 
778  long bundleId;
780 
799  celix_bundle_context_t *ctx,
800  const char *serviceName,
801  void *callbackHandle,
802  void (*trackerAdd)(void *handle, const celix_service_tracker_info_t *info),
803  void (*trackerRemove)(void *handle, const celix_service_tracker_info_t *info));
804 
810 celix_dependency_manager_t* celix_bundleContext_getDependencyManager(celix_bundle_context_t *ctx);
811 
812 
816 celix_bundle_t* celix_bundleContext_getBundle(celix_bundle_context_t *ctx);
817 
818 
825 const char* celix_bundleContext_getProperty(celix_bundle_context_t *ctx, const char *key, const char *defaultVal);
826 
835 long celix_bundleContext_getPropertyAsLong(celix_bundle_context_t *ctx, const char *key, long defaultValue);
836 
845 double celix_bundleContext_getPropertyAsDouble(celix_bundle_context_t *ctx, const char *key, double defaultValue);
846 
855 bool celix_bundleContext_getPropertyAsBool(celix_bundle_context_t *ctx, const char *key, bool defaultValue);
856 
857 //TODO getPropertyAs for int, uint, ulong, bool, etc
858 
859 #undef OPTS_INIT
860 
861 #ifdef __cplusplus
862 }
863 #endif
864 
865 #endif //CELIX_BUNDLE_CONTEXT_H_
long celix_bundleContext_findService(celix_bundle_context_t *ctx, const char *serviceName)
long celix_bundleContext_trackService(celix_bundle_context_t *ctx, const char *serviceName, void *callbackHandle, void(*set)(void *handle, void *svc))
bool ignoreServiceLanguage OPTS_INIT
Definition: celix_bundle_context.h:222
long celix_bundleContext_trackBundles(celix_bundle_context_t *ctx, void *callbackHandle, void(*onStarted)(void *handle, const celix_bundle_t *bundle), void(*onStopped)(void *handle, const celix_bundle_t *bundle))
celix_array_list_t * celix_bundleContext_listBundles(celix_bundle_context_t *ctx)
Definition: celix_bundle_context.h:485
celix_bundle_t * celix_bundleContext_getBundle(celix_bundle_context_t *ctx)
Definition: celix_bundle_context.h:193
long celix_bundleContext_trackServiceTrackers(celix_bundle_context_t *ctx, const char *serviceName, void *callbackHandle, void(*trackerAdd)(void *handle, const celix_service_tracker_info_t *info), void(*trackerRemove)(void *handle, const celix_service_tracker_info_t *info))
void celix_bundleContext_useServicesWithOptions(celix_bundle_context_t *ctx, const celix_service_use_options_t *opts)
const char *serviceLanguage OPTS_INIT
Definition: celix_bundle_context.h:119
const char *versionRange OPTS_INIT
Definition: celix_bundle_context.h:204
bool celix_bundleContext_startBundle(celix_bundle_context_t *ctx, long bundleId)
bool celix_bundleContext_useService(celix_bundle_context_t *ctx, const char *serviceName, void *callbackHandle, void(*use)(void *handle, void *svc))
const char * celix_bundleContext_getProperty(celix_bundle_context_t *ctx, const char *key, const char *defaultVal)
celix_service_factory_t *factory OPTS_INIT
Definition: celix_bundle_context.h:99
Definition: celix_bundle_context.h:75
const char *serviceName OPTS_INIT
Definition: celix_bundle_context.h:105
celix_array_list_t * celix_bundleContext_findServicesWithOptions(celix_bundle_context_t *ctx, const celix_service_filter_options_t *opts)
long celix_bundleContext_findServiceWithOptions(celix_bundle_context_t *ctx, const celix_service_filter_options_t *opts)
long celix_bundleContext_registerServiceWithOptions(celix_bundle_context_t *ctx, const celix_service_registration_options_t *opts)
bool celix_bundleContext_uninstallBundle(celix_bundle_context_t *ctx, long bundleId)
long celix_bundleContext_trackServices(celix_bundle_context_t *ctx, const char *serviceName, void *callbackHandle, void(*add)(void *handle, void *svc), void(*remove)(void *handle, void *svc))
long celix_bundleContext_trackServicesWithOptions(celix_bundle_context_t *ctx, const celix_service_tracking_options_t *opts)
bool celix_bundleContext_getPropertyAsBool(celix_bundle_context_t *ctx, const char *key, bool defaultValue)
struct celix_service_registration_options celix_service_registration_options_t
celix_properties_t *properties OPTS_INIT
Definition: celix_bundle_context.h:114
void *callbackHandle OPTS_INIT
Definition: celix_bundle_context.h:501
bool celix_bundleContext_useServiceWithId(celix_bundle_context_t *ctx, long serviceId, const char *serviceName, void *callbackHandle, void(*use)(void *handle, void *svc))
const char *serviceLanguage OPTS_INIT
Definition: celix_bundle_context.h:215
void celix_bundleContext_useServices(celix_bundle_context_t *ctx, const char *serviceName, void *callbackHandle, void(*use)(void *handle, void *svc))
double celix_bundleContext_getPropertyAsDouble(celix_bundle_context_t *ctx, const char *key, double defaultValue)
struct celix_service_tracking_options celix_service_tracking_options_t
long celix_bundleContext_registerService(celix_bundle_context_t *ctx, void *svc, const char *serviceName, celix_properties_t *properties)
long celix_bundleContext_trackBundlesWithOptions(celix_bundle_context_t *ctx, const celix_bundle_tracking_options_t *opts)
bool celix_bundleContext_useServiceWithOptions(celix_bundle_context_t *ctx, const celix_service_use_options_t *opts)
void celix_bundleContext_useBundles(celix_bundle_context_t *ctx, void *callbackHandle, void(*use)(void *handle, const celix_bundle_t *bundle))
long celix_bundleContext_getPropertyAsLong(celix_bundle_context_t *ctx, const char *key, long defaultValue)
struct celix_bundle_tracker_options celix_bundle_tracking_options_t
struct celix_service_use_options celix_service_use_options_t
const char * serviceLanguage
Definition: celix_bundle_context.h:773
double waitTimeoutInSeconds OPTS_INIT
Definition: celix_bundle_context.h:496
Definition: celix_bundle_context.h:659
Definition: celix_bundle_context.h:292
long celix_bundleContext_installBundle(celix_bundle_context_t *ctx, const char *bundleLoc, bool autoStart)
bool celix_bundleContext_useBundle(celix_bundle_context_t *ctx, long bundleId, void *callbackHandle, void(*use)(void *handle, const celix_bundle_t *bundle))
celix_dependency_manager_t * celix_bundleContext_getDependencyManager(celix_bundle_context_t *ctx)
const char * serviceName
Definition: celix_bundle_context.h:768
Definition: celix_bundle_context.h:759
celix_service_filter_options_t filter OPTS_INIT
Definition: celix_bundle_context.h:489
void *callbackHandle OPTS_INIT
Definition: celix_bundle_context.h:301
void *svc OPTS_INIT
Definition: celix_bundle_context.h:83
void celix_bundleContext_stopTracker(celix_bundle_context_t *ctx, long trackerId)
struct celix_service_filter_options celix_service_filter_options_t
void *callbackHandle OPTS_INIT
Definition: celix_bundle_context.h:663
void celix_bundleContext_unregisterService(celix_bundle_context_t *ctx, long serviceId)
struct celix_service_tracker_info celix_service_tracker_info_t
bool includeFrameworkBundle OPTS_INIT
Definition: celix_bundle_context.h:694
celix_array_list_t * celix_bundleContext_findServices(celix_bundle_context_t *ctx, const char *serviceName)
const char *serviceVersion OPTS_INIT
Definition: celix_bundle_context.h:128
long bundleId
Definition: celix_bundle_context.h:778
celix_service_filter_options_t filter OPTS_INIT
Definition: celix_bundle_context.h:296
bool celix_bundleContext_isBundleInstalled(celix_bundle_context_t *ctx, long bndId)
celix_filter_t * filter
Definition: celix_bundle_context.h:763
bool celix_bundleContext_stopBundle(celix_bundle_context_t *ctx, long bundleId)
const char *serviceName OPTS_INIT
Definition: celix_bundle_context.h:197
const char *filter OPTS_INIT
Definition: celix_bundle_context.h:210
long celix_bundleContext_registerServiceFactory(celix_bundle_context_t *ctx, celix_service_factory_t *factory, const char *serviceName, celix_properties_t *props)