Esempio n. 1
0
celix_status_t serviceRegistry_unregisterServices(service_registry_pt registry, bundle_pt bundle) {
	array_list_pt regs = NULL;
	unsigned int i;
	celixThreadMutex_lock(&registry->mutex);
	regs = (array_list_pt) hashMap_get(registry->serviceRegistrations, bundle);
	celixThreadMutex_unlock(&registry->mutex);
	
	for (i = 0; (regs != NULL) && i < arrayList_size(regs); i++) {
		service_registration_pt reg = arrayList_get(regs, i);
		if (serviceRegistration_isValid(reg)) {
			serviceRegistration_unregister(reg);
		}
	}

	if (regs != NULL && arrayList_isEmpty(regs)) {
	    celixThreadMutex_lock(&registry->mutex);
		array_list_pt removed = hashMap_remove(registry->serviceRegistrations, bundle);
		celixThreadMutex_unlock(&registry->mutex);
		arrayList_destroy(removed);
		removed = NULL;
	}

	celixThreadMutex_lock(&registry->mutex);
	hashMap_remove(registry->serviceRegistrations, bundle);
	celixThreadMutex_unlock(&registry->mutex);

	return CELIX_SUCCESS;
}
Esempio n. 2
0
void serviceRegistry_ungetServices(service_registry_pt registry, bundle_pt bundle) {
	array_list_pt fusages;
	array_list_pt usages;
	unsigned int i;

	celixThreadMutex_lock(&registry->mutex);
	usages = hashMap_get(registry->inUseMap, bundle);
	celixThreadMutex_unlock(&registry->mutex);

	if (usages == NULL || arrayList_isEmpty(usages)) {
		return;
	}

	// usage arrays?
	fusages = arrayList_clone(usages);
	
	for (i = 0; i < arrayList_size(fusages); i++) {
		usage_count_pt usage = arrayList_get(fusages, i);
		service_reference_pt reference = usage->reference;
		bool ungetResult = true;
		while (ungetResult) {
			serviceRegistry_ungetService(registry, bundle, reference, &ungetResult);
		}
	}

	arrayList_destroy(fusages);
}
Esempio n. 3
0
static void disconnectPendingPublishers(topic_subscription_pt sub) {
	celixThreadMutex_lock(&sub->pendingDisconnections_lock);
	while(!arrayList_isEmpty(sub->pendingDisconnections)) {
		char * pubEP = arrayList_remove(sub->pendingDisconnections, 0);
		pubsub_topicSubscriptionDisconnectPublisher(sub, pubEP);
		free(pubEP);
	}
	celixThreadMutex_unlock(&sub->pendingDisconnections_lock);
}
celix_status_t dependencyManager_removeAllComponents(dm_dependency_manager_pt manager) {
	celix_status_t status = CELIX_SUCCESS;

	unsigned int i=0;
	unsigned int size = arrayList_size(manager->components);

	for(;i<size;i++){
		dm_component_pt cmp = arrayList_get(manager->components, i);
		printf("Stopping comp %s\n", component_getName(cmp));
		component_stop(cmp);
	}

	while (!arrayList_isEmpty(manager->components)) {
		dm_component_pt cmp = arrayList_remove(manager->components, 0);
        printf("Removing comp %s\n", component_getName(cmp));
        component_destroy(cmp);
	}

	return status;
}
Esempio n. 5
0
celix_status_t inspectCommand_printExportedServices(bundle_context_pt context, array_list_pt ids, FILE *outStream, FILE *errStream) {
	celix_status_t status = CELIX_SUCCESS;
	array_list_pt bundles = NULL;

	if (arrayList_isEmpty(ids)) {
		status = bundleContext_getBundles(context, &bundles);
	} else {
		unsigned int i;

		arrayList_create(&bundles);
		for (i = 0; i < arrayList_size(ids); i++) {
			char *idStr = (char *) arrayList_get(ids, i);
			long id = atol(idStr);
			bundle_pt b = NULL;
			celix_status_t st = bundleContext_getBundleById(context, id, &b);
			if (st == CELIX_SUCCESS) {
				arrayList_add(bundles, b);
			} else {
				fprintf(outStream, "INSPECT: Invalid bundle ID: %ld\n", id);
			}
		}
	}

	if (status == CELIX_SUCCESS) {
		unsigned int i = 0;
		for (i = 0; i < arrayList_size(bundles); i++) {
			bundle_pt bundle = (bundle_pt) arrayList_get(bundles, i);

			if (i > 0) {
				fprintf(outStream, "\n");
			}

			if (bundle != NULL) {
				array_list_pt refs = NULL;

				if (bundle_getRegisteredServices(bundle, &refs) == CELIX_SUCCESS) {
					module_pt module = NULL;
					char * name = NULL;
					status = bundle_getCurrentModule(bundle, &module);
					if (status == CELIX_SUCCESS) {
						status = module_getSymbolicName(module, &name);
						if (status == CELIX_SUCCESS) {
							fprintf(outStream, "%s provides services:\n", name);
							fprintf(outStream, "==============\n");

							if (refs == NULL || arrayList_size(refs) == 0) {
								fprintf(outStream, "Nothing\n");
							} else {
								unsigned int j = 0;
								for (j = 0; j < arrayList_size(refs); j++) {
									service_reference_pt ref = (service_reference_pt) arrayList_get(refs, j);
									unsigned int size = 0;
									char **keys;

									serviceReference_getPropertyKeys(ref, &keys, &size);
									for (int k = 0; k < size; k++) {
									    char *key = keys[k];
									    char *value = NULL;
									    serviceReference_getProperty(ref, key, &value);

										fprintf(outStream, "%s = %s\n", key, value);
									}

//									objectClass = properties_get(props, (char *) OSGI_FRAMEWORK_OBJECTCLASS);
//									sprintf(line, "ObjectClass = %s\n", objectClass);
									if ((j + 1) < arrayList_size(refs)) {
										fprintf(outStream, "----\n");
									}
								}
							}
						}
					}
				}
			}
		}
	}

	if (bundles != NULL) {
	    arrayList_destroy(bundles);
	}

	return status;
}
Esempio n. 6
0
void test_arrayList_isEmpty(void) {
	arrayList_clear(list);
	CU_ASSERT_EQUAL(list->size, 0);
	CU_ASSERT_TRUE(arrayList_isEmpty(list));
}
Esempio n. 7
0
celix_status_t inspectCommand_printImportedServices(command_pt command, array_list_pt ids, void (*out)(char *), void (*err)(char *)) {
    celix_status_t status = CELIX_SUCCESS;
    array_list_pt bundles = NULL;

    if (arrayList_isEmpty(ids)) {
        celix_status_t status = bundleContext_getBundles(command->bundleContext, &bundles);
    } else {
        unsigned int i;

        arrayList_create(&bundles);
        for (i = 0; i < arrayList_size(ids); i++) {
            char *idStr = (char *) arrayList_get(ids, i);
            long id = atol(idStr);
            bundle_pt b = NULL;
            celix_status_t st = bundleContext_getBundleById(command->bundleContext, id, &b);
            if (st == CELIX_SUCCESS) {
                arrayList_add(bundles, b);
            } else {
                char line[256];
                sprintf(line, "INSPECT: Invalid bundle ID: %ld\n", id);
                out(line);
            }
        }
    }

    if (status == CELIX_SUCCESS) {
        unsigned int i = 0;
        for (i = 0; i < arrayList_size(bundles); i++) {
            bundle_pt bundle = (bundle_pt) arrayList_get(bundles, i);

            if (i > 0) {
                out("\n");
            }

            if (bundle != NULL) {
                array_list_pt refs = NULL;

                if (bundle_getServicesInUse(bundle, &refs) == CELIX_SUCCESS) {
                    char line[256];
                    module_pt module = NULL;
                    char * name = NULL;
                    status = bundle_getCurrentModule(bundle, &module);
                    if (status == CELIX_SUCCESS) {
                        status = module_getSymbolicName(module, &name);
                        if (status == CELIX_SUCCESS) {
                            sprintf(line, "%s requires services:\n", name);
                            out(line);
                            out("==============\n");

                            if (refs == NULL || arrayList_size(refs) == 0) {
                                out("Nothing\n");
                            } else {
                                unsigned int j = 0;
                                for (j = 0; j < arrayList_size(refs); j++) {
                                    service_reference_pt ref = (service_reference_pt) arrayList_get(refs, j);
                                    service_registration_pt reg = NULL;
                                    properties_pt props = NULL;
                                    char line[256];
                                    bundle_pt usedBundle = NULL;
                                    module_pt usedModule = NULL;
                                    char *usedSymbolicName = NULL;
                                    long usedBundleId;

                                    serviceReference_getBundle(ref, &usedBundle);
                                    bundle_getBundleId(usedBundle, &usedBundleId);
                                    bundle_getCurrentModule(usedBundle, &usedModule);
                                    module_getSymbolicName(usedModule, &usedSymbolicName);

                                    sprintf(line, "%s [%ld]\n", usedSymbolicName, usedBundleId);
                                    out(line);

                                    serviceReference_getServiceRegistration(ref, &reg);
                                    serviceRegistration_getProperties(reg, &props);
                                    hash_map_iterator_pt iter = hashMapIterator_create(props);
                                    while (hashMapIterator_hasNext(iter)) {
                                        hash_map_entry_pt entry = hashMapIterator_nextEntry(iter);
                                        sprintf(line, "%s = %s\n", hashMapEntry_getKey(entry), hashMapEntry_getValue(entry));
                                        out(line);
                                    }
									hashMapIterator_destroy(iter);

//                                  objectClass = properties_get(props, (char *) OSGI_FRAMEWORK_OBJECTCLASS);
//                                  sprintf(line, "ObjectClass = %s\n", objectClass);
                                    if ((j + 1) < arrayList_size(refs)) {
                                        out("----\n");
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }


    return status;
}