int main(void) { apr_status_t rv = APR_SUCCESS; apr_status_t s = APR_SUCCESS; properties_pt config = NULL; char *autoStart = NULL; apr_pool_t *pool = NULL; bundle_pt fwBundle = NULL; rv = apr_initialize(); if (rv != APR_SUCCESS) { return CELIX_START_ERROR; } apr_pool_t *memoryPool; s = apr_pool_create(&memoryPool, NULL); if (s != APR_SUCCESS) { return CELIX_START_ERROR; } struct framework * framework = NULL; celix_status_t status = CELIX_SUCCESS; status = framework_create(&framework, memoryPool, config); if (status == CELIX_SUCCESS) { status = fw_init(framework); if (status == CELIX_SUCCESS) { // Start the system bundle framework_getFrameworkBundle(framework, &fwBundle); bundle_start(fwBundle); bundle_context_pt context = NULL; bundle_getContext(fwBundle, &context); // do some stuff bundle_pt bundle = NULL; status = CELIX_DO_IF(status, bundleContext_installBundle(context, "../test_bundle1/test_bundle1.zip", &bundle)); status = CELIX_DO_IF(status, bundle_start(bundle)); // Stop the system bundle, sleep a bit to let stuff settle down sleep(5); bundle_stop(fwBundle); framework_destroy(framework); } } if (status != CELIX_SUCCESS) { printf("Problem creating framework\n"); } apr_pool_destroy(memoryPool); apr_terminate(); printf("LAUNCHER: Exit\n"); return 0; }
celix_status_t importRegistrationFactory_open(import_registration_factory_pt registration_factory) { celix_status_t status; char *bundleStore = NULL; bundleContext_getProperty(registration_factory->context, BUNDLE_STORE_PROPERTY_NAME, &bundleStore); if (bundleStore == NULL) { bundleStore = DEFAULT_BUNDLE_STORE; } char name[256]; snprintf(name, 256, "%s/%s_proxy.zip", bundleStore, registration_factory->serviceName); status = bundleContext_installBundle(registration_factory->context, name, ®istration_factory->bundle); if (status == CELIX_SUCCESS) { status = bundle_start(registration_factory->bundle); if (status == CELIX_SUCCESS) { logHelper_log(registration_factory->loghelper, OSGI_LOGSERVICE_INFO, "%s successfully started.", name); } } else { logHelper_log(registration_factory->loghelper, OSGI_LOGSERVICE_ERROR, "%s could not be installed.", name); } return status; }
celix_status_t driverLoader_loadDriverForLocator(driver_loader_pt loader, driver_locator_service_pt locator, char *driverId, array_list_pt *references) { celix_status_t status = CELIX_SUCCESS; //The list is created in the bundle_getRegisteredServices chain //arrayList_create(references); char *filename = NULL; status = locator->loadDriver(locator->locator, driverId, &filename); if (status == CELIX_SUCCESS) { bundle_pt bundle = NULL; int length = strlen(DRIVER_LOCATION_PREFIX) + strlen(driverId); char location[length]; snprintf(location, length, "%s%s", DRIVER_LOCATION_PREFIX, driverId); status = bundleContext_installBundle2(loader->context, location, filename, &bundle); if (status == CELIX_SUCCESS) { status = bundle_start(bundle); if (status == CELIX_SUCCESS) { status = bundle_getRegisteredServices(bundle, references); if (status == CELIX_SUCCESS) { arrayList_addAll(loader->loadedDrivers, *references); } } } } return status; }
celix_status_t importRegistrationFactory_open(import_registration_factory_pt registration_factory) { celix_status_t status = CELIX_SUCCESS; char *bundleStore = NULL; bundleContext_getProperty(registration_factory->context, BUNDLE_STORE_PROPERTY_NAME, &bundleStore); if (bundleStore == NULL) { bundleStore = DEFAULT_BUNDLE_STORE; } char *name = apr_pstrcat(registration_factory->pool, bundleStore, "/", registration_factory->serviceName, "_proxy.zip", NULL); status = bundleContext_installBundle(registration_factory->context, name, ®istration_factory->bundle); if (status == CELIX_SUCCESS) { status = bundle_start(registration_factory->bundle); if (status == CELIX_SUCCESS) { printf("%s sucessfully started\n", name); } } else { printf("%s could not be installed.\n", name); } return status; }
celix_status_t deploymentAdmin_startDeploymentPackageCustomizerBundles(deployment_admin_pt admin, deployment_package_pt source, deployment_package_pt target) { celix_status_t status = CELIX_SUCCESS; array_list_pt bundles = NULL; array_list_pt sourceInfos = NULL; arrayList_create(&bundles); deploymentPackage_getBundleInfos(source, &sourceInfos); int i; for (i = 0; i < arrayList_size(sourceInfos); i++) { bundle_info_pt sourceInfo = arrayList_get(sourceInfos, i); if (sourceInfo->customizer) { bundle_pt bundle = NULL; deploymentPackage_getBundle(source, sourceInfo->symbolicName, &bundle); if (bundle != NULL) { arrayList_add(bundles, bundle); } } } if (target != NULL) { array_list_pt targetInfos = NULL; deploymentPackage_getBundleInfos(target, &targetInfos); for (i = 0; i < arrayList_size(targetInfos); i++) { bundle_info_pt targetInfo = arrayList_get(targetInfos, i); if (targetInfo->customizer) { bundle_pt bundle = NULL; deploymentPackage_getBundle(target, targetInfo->symbolicName, &bundle); if (bundle != NULL) { arrayList_add(bundles, bundle); } } } } for (i = 0; i < arrayList_size(bundles); i++) { bundle_pt bundle = arrayList_get(bundles, i); bundle_start(bundle); } return status; }
celix_status_t deploymentAdmin_startDeploymentPackageBundles(deployment_admin_pt admin, deployment_package_pt source) { celix_status_t status = CELIX_SUCCESS; array_list_pt infos = NULL; deploymentPackage_getBundleInfos(source, &infos); int i; for (i = 0; i < arrayList_size(infos); i++) { bundle_pt bundle = NULL; bundle_info_pt info = arrayList_get(infos, i); if (!info->customizer) { deploymentPackage_getBundle(source, info->symbolicName, &bundle); if (bundle != NULL) { bundle_start(bundle); } else { printf("DEPLOYMENT_ADMIN: Could not start bundle %s\n", info->symbolicName); } } } return status; }
static celix_status_t stopStartPermutation(bundle_context_pt context, long* permutation, int size) { celix_status_t status = CELIX_SUCCESS; int y = 0; printf("Test stop/start permutation: "); for (y = 0; (y < size) && (status == CELIX_SUCCESS); y++) { bundle_pt bundle = NULL; status = bundleContext_getBundleById(context, permutation[y], &bundle); if (status == CELIX_SUCCESS) { module_pt module = NULL; const char *name = NULL; status = bundle_getCurrentModule(bundle, &module); if (status == CELIX_SUCCESS) { status = module_getSymbolicName(module, &name); printf("%s (%ld) ", name, permutation[y]); } } } printf("\n"); // stop all bundles if (status == CELIX_SUCCESS) { for (y = 0; (y < size) && (status == CELIX_SUCCESS); y++) { bundle_pt bundle = NULL; status = bundleContext_getBundleById(context, permutation[y], &bundle); if (status == CELIX_SUCCESS) { printf("stop bundle: %ld\n", permutation[y]); status = bundle_stop(bundle); } } } // verify stop state if (status == CELIX_SUCCESS) { for (y = 0; (y < size) && (status == CELIX_SUCCESS); y++) { bundle_pt bundle = NULL; status = bundleContext_getBundleById(context, permutation[y], &bundle); if (status == CELIX_SUCCESS) { bundle_state_e state; status = bundle_getState(bundle, &state); if (state != OSGI_FRAMEWORK_BUNDLE_RESOLVED) { printf("bundle %ld has state %d (should be %d) \n", permutation[y], state, OSGI_FRAMEWORK_BUNDLE_RESOLVED); status = CELIX_ILLEGAL_STATE; } } } } // start all bundles if (status == CELIX_SUCCESS) { for (y = 0; (y < size) && (status == CELIX_SUCCESS); y++) { bundle_pt bundle = NULL; status = bundleContext_getBundleById(context, permutation[y], &bundle); if (status == CELIX_SUCCESS) { printf("start bundle: %ld\n", permutation[y]); status = bundle_start(bundle); } } } // verify started state if (status == CELIX_SUCCESS) { for (y = 0; (y < size) && (status == CELIX_SUCCESS); y++) { bundle_pt bundle = NULL; status = bundleContext_getBundleById(context, permutation[y], &bundle); if (status == CELIX_SUCCESS) { bundle_state_e state; status = bundle_getState(bundle, &state); if (state != OSGI_FRAMEWORK_BUNDLE_ACTIVE) { printf("bundle %ld has state %d (should be %d) \n", permutation[y], state, OSGI_FRAMEWORK_BUNDLE_ACTIVE); status = CELIX_ILLEGAL_STATE; } } } } return status; }