static void test1(void) {
		celix_status_t status;
		service_reference_pt ref = NULL;
		calculator_service_pt calcService = NULL;
        int retries = 4;

        while (ref == NULL && retries > 0) {
            printf("Waiting for service .. %d\n", retries);
            status = bundleContext_getServiceReference(clientContext, (char *) CALCULATOR_SERVICE, &ref);
            usleep(1000000);
            --retries;
        }

		CHECK_EQUAL(CELIX_SUCCESS, status);
		CHECK(ref != NULL);

		status = bundleContext_getService(clientContext, ref, (void **) &calcService);
		CHECK_EQUAL(CELIX_SUCCESS, status);
		CHECK(calcService != NULL);

		double result = 0;
		status = calcService->add(calcService->calculator, 2.0, 5.0, &result);
		CHECK_EQUAL(CELIX_SUCCESS, status);
		CHECK_EQUAL(7.0, result);

		bundleContext_ungetService(clientContext, ref, NULL);
		bundleContext_ungetServiceReference(clientContext, ref);
	}
Exemple #2
0
    static void teardownFmImport(void) {
        int rc = 0;

        rc = bundleContext_ungetService(context, rsaRef, NULL);
        CHECK_EQUAL(CELIX_SUCCESS, rc);
        rc = bundleContext_ungetServiceReference(context,rsaRef);
        CHECK_EQUAL(CELIX_SUCCESS, rc);

        rc = bundleContext_ungetService(context, scopeServiceRef, NULL);
        CHECK_EQUAL(CELIX_SUCCESS, rc);
        rc = bundleContext_ungetServiceReference(context,scopeServiceRef);
        CHECK_EQUAL(CELIX_SUCCESS, rc);

        rc = bundleContext_ungetService(context, testRef, NULL);
        CHECK_EQUAL(CELIX_SUCCESS, rc);
        rc = bundleContext_ungetServiceReference(context,testRef);
        CHECK_EQUAL(CELIX_SUCCESS, rc);

        rc = bundleContext_ungetService(context, eplRef, NULL);
        CHECK_EQUAL(CELIX_SUCCESS, rc);
        rc = bundleContext_ungetServiceReference(context,eplRef);
        CHECK_EQUAL(CELIX_SUCCESS, rc);

        celixLauncher_stop(framework);
        celixLauncher_waitForShutdown(framework);
        celixLauncher_destroy(framework);

        scopeServiceRef = NULL;
        tmScopeService = NULL;
        calcRef = NULL;
        calc = NULL;

        rsaRef = NULL;
        rsa = NULL;
        discRef = NULL;
        discMock = NULL;

        testRef = NULL;
        testImport = NULL;

        eplRef = NULL;
        eplService = NULL;

        context = NULL;
        framework = NULL;
    }
Exemple #3
0
static celix_status_t serviceTracker_untrack(service_tracker_pt tracker, service_reference_pt reference, service_event_pt event) {
	celix_status_t status = CELIX_SUCCESS;
	tracked_pt tracked = NULL;
	unsigned int i;
	bool result = false;

	for (i = 0; i < arrayList_size(tracker->tracked); i++) {
		bool equals;
		tracked = (tracked_pt) arrayList_get(tracker->tracked, i);
		serviceReference_equals(reference, tracked->reference, &equals);
		if (equals) {
			arrayList_remove(tracker->tracked, i);
			if (status == CELIX_SUCCESS) {
				if (tracker->customizer != NULL) {
					void *handle = NULL;
					removed_callback_pt function = NULL;

					serviceTrackerCustomizer_getHandle(tracker->customizer, &handle);
					serviceTrackerCustomizer_getRemovedFunction(tracker->customizer, &function);

					if (function != NULL) {
						status = function(handle, reference, tracked->service);
					} else {
						status = bundleContext_ungetService(tracker->context, reference, &result);
					}
				} else {
					status = bundleContext_ungetService(tracker->context, reference, &result);
				}
				
				// ungetServiceReference
				bundleContext_ungetServiceReference(tracker->context, reference);
                //break;
			}
			free(tracked);
		}
	}

	framework_logIfError(logger, status, NULL, "Cannot untrack reference");

	return status;
}
Exemple #4
0
celix_status_t shell_removeCommand(shell_pt shell_ptr, service_reference_pt reference_ptr) {
	celix_status_t status = CELIX_SUCCESS;

	command_service_pt command_ptr = NULL;
	char *name_str = NULL;

	if (!shell_ptr || !reference_ptr) {
		status = CELIX_ILLEGAL_ARGUMENT;
	}

	if (status == CELIX_SUCCESS) {
		command_ptr = hashMap_remove(shell_ptr->command_reference_map_ptr, reference_ptr);
		if (!command_ptr) {
			status = CELIX_ILLEGAL_ARGUMENT;
		}
	}

	if (status == CELIX_SUCCESS) {
		status = serviceReference_getProperty(reference_ptr, "command.name", &name_str);
		if (!name_str) {
			status = CELIX_BUNDLE_EXCEPTION;
		}
	}

	if (status == CELIX_SUCCESS) {
		hashMap_remove(shell_ptr->command_name_map_ptr, name_str);
	}

	celix_status_t sub_status = bundleContext_ungetService(shell_ptr->bundle_context_ptr, reference_ptr, NULL);
	if (sub_status != CELIX_SUCCESS && status == CELIX_SUCCESS) {
		status = sub_status;
	}

	sub_status = bundleContext_ungetServiceReference(shell_ptr->bundle_context_ptr, reference_ptr);
	if (sub_status != CELIX_SUCCESS && status == CELIX_SUCCESS) {
		status = sub_status;
	}

	return status;
}
Exemple #5
0
void logCommand_execute(bundle_context_pt context, char *line, FILE *outStream, FILE *errStream) {
    service_reference_pt readerService = NULL;

    bundleContext_getServiceReference(context, (char *) OSGI_LOGSERVICE_READER_SERVICE_NAME, &readerService);
    if (readerService != NULL) {
        linked_list_pt list = NULL;
        linked_list_iterator_pt iter = NULL;
        log_reader_service_pt reader = NULL;


		bundleContext_getService(context, readerService, (void **) &reader);
		reader->getLog(reader->reader, &list);
		iter = linkedListIterator_create(list, 0);
		while (linkedListIterator_hasNext(iter)) {
			log_entry_pt entry = linkedListIterator_next(iter);
			char time[20];
			char *level = NULL;
			char errorString[256];

            strftime(time, 20, "%Y-%m-%d %H:%M:%S", localtime(&entry->time));
            logCommand_levelAsString(context, entry->level, &level);

			if (entry->errorCode > 0) {
				celix_strerror(entry->errorCode, errorString, 256);
				fprintf(outStream, "%s - Bundle: %s - %s - %d %s\n", time, entry->bundleSymbolicName, entry->message, entry->errorCode, errorString);
			} else {
				fprintf(outStream, "%s - Bundle: %s - %s\n", time, entry->bundleSymbolicName, entry->message);
			}
		}
		linkedListIterator_destroy(iter);
		linkedList_destroy(list);
		bool result = true;
		bundleContext_ungetService(context, readerService, &result);
        bundleContext_ungetServiceReference(context, readerService);
    } else {
		fprintf(outStream, "No log reader available\n");
    }
}