コード例 #1
0
ファイル: rsa_tests.cpp プロジェクト: leckie711/celix
    static void setupFm(void) {
        int rc = 0;

        rc = celixLauncher_launch("config.properties", &framework);
        CHECK_EQUAL(CELIX_SUCCESS, rc);

        bundle_pt bundle = NULL;
        rc = framework_getFrameworkBundle(framework, &bundle);
        CHECK_EQUAL(CELIX_SUCCESS, rc);

        rc = bundle_getContext(bundle, &context);
        CHECK_EQUAL(CELIX_SUCCESS, rc);

        rc = bundleContext_getServiceReference(context, (char *)OSGI_RSA_REMOTE_SERVICE_ADMIN, &rsaRef);
        CHECK_EQUAL(CELIX_SUCCESS, rc);
        CHECK(rsaRef != NULL);

        rc = bundleContext_getService(context, rsaRef, (void **)&rsa);
        CHECK_EQUAL(CELIX_SUCCESS, rc);

        rc = bundleContext_getServiceReference(context, (char *)CALCULATOR2_SERVICE, &calcRef);
        CHECK_EQUAL(CELIX_SUCCESS, rc);
        CHECK(calcRef != NULL);

        rc = bundleContext_getService(context, calcRef, (void **)&calc);
        CHECK_EQUAL(CELIX_SUCCESS, rc);
    }
コード例 #2
0
	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);
	}
コード例 #3
0
	static void testProxyRemoval(void) {
		celix_status_t status;
		bundle_pt bundle = NULL;
		array_list_pt bundleNames = NULL;
		array_list_pt proxyBundle = NULL;
		service_reference_pt ref = NULL;

		arrayList_create(&bundleNames);
		arrayList_create(&proxyBundle);

		arrayList_add(bundleNames, (void*) CALCULATOR_PROXY);
		status = getSpecifiedBundles(clientContext, bundleNames, proxyBundle);
		CHECK_EQUAL(CELIX_SUCCESS, status);
		CHECK_EQUAL(arrayList_size(proxyBundle), arrayList_size(bundleNames));

		status = bundleContext_getBundleById(clientContext, (long) arrayList_get(proxyBundle, 0), &bundle);
		CHECK_EQUAL(CELIX_SUCCESS, status);

		status = bundle_stop(bundle);
		CHECK_EQUAL(CELIX_SUCCESS, status);

		status = bundleContext_getServiceReference(clientContext, (char *) CALCULATOR_SERVICE, &ref);
		CHECK_EQUAL(CELIX_SUCCESS, status);
		CHECK(ref == NULL);

		arrayList_destroy(bundleNames);
		arrayList_destroy(proxyBundle);
	}
コード例 #4
0
ファイル: driver_matcher.c プロジェクト: jawi/celix
celix_status_t driverMatcher_getBestMatch(driver_matcher_pt matcher, apr_pool_t *pool, service_reference_pt reference, match_pt *match) {
	celix_status_t status = CELIX_SUCCESS;

	if (*match != NULL) {
		status = CELIX_ILLEGAL_ARGUMENT;
	} else {
		service_reference_pt selectorRef = NULL;
		status = bundleContext_getServiceReference(matcher->context, OSGI_DEVICEACCESS_DRIVER_SELECTOR_SERVICE_NAME, &selectorRef);
		if (status == CELIX_SUCCESS) {
			int index = -1;
			if (selectorRef != NULL) {
				driver_selector_service_pt selector = NULL;
				status = bundleContext_getService(matcher->context, selectorRef, (void **) &selector);
				if (status == CELIX_SUCCESS) {
					if (selector != NULL) {
						int size = -1;
						status = selector->driverSelector_select(selector->selector, reference, matcher->matches, &index);
						if (status == CELIX_SUCCESS) {
							size = arrayList_size(matcher->matches);
							if (index != -1 && index >= 0 && index < size) {
								*match = arrayList_get(matcher->matches, index);
							}
						}
					}
				}
			}
			if (status == CELIX_SUCCESS && *match == NULL) {
				status = driverMatcher_getBestMatchInternal(matcher, pool, match);
			}
		}
	}

	return status;
}
コード例 #5
0
ファイル: rsa_tests.cpp プロジェクト: leckie711/celix
    static void testImportService(void) {
        int rc = 0;
        import_registration_pt reg = NULL;
        endpoint_description_pt endpoint = NULL;

        properties_pt props = properties_create();
        properties_set(props, (char *)OSGI_RSA_ENDPOINT_SERVICE_ID, (char *)"42");
        properties_set(props, (char *)OSGI_RSA_ENDPOINT_FRAMEWORK_UUID, (char *)"eec5404d-51d0-47ef-8d86-c825a8beda42");
        properties_set(props, (char *)OSGI_RSA_ENDPOINT_ID, (char *)"eec5404d-51d0-47ef-8d86-c825a8beda42-42");
        properties_set(props, (char *)OSGI_FRAMEWORK_OBJECTCLASS,(char *)"org.apache.celix.Example");

        rc = endpointDescription_create(props, &endpoint);
        CHECK_EQUAL(CELIX_SUCCESS, rc);

        rc = rsa->importService(rsa->admin, endpoint, &reg);
        CHECK_EQUAL(CELIX_SUCCESS, rc);
        CHECK(reg != NULL);

        service_reference_pt ref = NULL;
        rc = bundleContext_getServiceReference(context, (char *)"org.apache.celix.Example", &ref);
        CHECK_EQUAL(CELIX_SUCCESS, rc);
        CHECK(ref != NULL);

        /* Cannot test. uses requesting bundles descriptor
        void *service = NULL;
        rc = bundleContext_getService(context, ref, &service);
        CHECK_EQUAL(CELIX_SUCCESS, rc);
        CHECK(service != NULL);
         */
    }
コード例 #6
0
ファイル: shell_tui.c プロジェクト: jawi/celix
void shellTui_initializeService(shell_tui_activator_pt activator) {
	if (activator->shell == NULL) {
		bundleContext_getServiceReference(activator->context, (char *) OSGI_SHELL_SERVICE_NAME, &activator->reference);
		if (activator->reference != NULL) {
		    void *shell_svc = NULL;
		    bundleContext_getService(activator->context, activator->reference, &shell_svc);
		    activator->shell = (shell_service_pt) shell_svc;
		}
	}
}
コード例 #7
0
ファイル: tms_tests.cpp プロジェクト: ErjanAltena/celix
    static void setupFmImport(void) {
        int rc = 0;
        rc = celixLauncher_launch("config_import.properties", &framework);
        CHECK_EQUAL(CELIX_SUCCESS, rc);

        bundle_pt bundle = NULL;
        rc = framework_getFrameworkBundle(framework, &bundle);
        CHECK_EQUAL(CELIX_SUCCESS, rc);

        rc = bundle_getContext(bundle, &context);
        CHECK_EQUAL(CELIX_SUCCESS, rc);

        rc = bundleContext_getServiceReference(context, (char *)OSGI_RSA_REMOTE_SERVICE_ADMIN, &rsaRef);
        CHECK_EQUAL(CELIX_SUCCESS, rc);
        CHECK(rsaRef != NULL);

        rc = bundleContext_getService(context, rsaRef, (void **)&rsa);
        CHECK_EQUAL(CELIX_SUCCESS, rc);

        rc = bundleContext_getServiceReference(context, (char *)TOPOLOGYMANAGER_SCOPE_SERVICE, &scopeServiceRef);
        CHECK_EQUAL(CELIX_SUCCESS, rc);
        CHECK(scopeServiceRef != NULL);

        rc = bundleContext_getService(context, scopeServiceRef, (void **)&tmScopeService);
        CHECK_EQUAL(CELIX_SUCCESS, rc);

        rc = bundleContext_getServiceReference(context, (char *)TST_SERVICE_NAME, &testRef);
        CHECK_EQUAL(CELIX_SUCCESS, rc);
        CHECK(testRef != NULL);

        rc = bundleContext_getService(context, testRef, (void **)&testImport);
        CHECK_EQUAL(CELIX_SUCCESS, rc);

        rc = bundleContext_getServiceReference(context, (char*)OSGI_ENDPOINT_LISTENER_SERVICE, &eplRef);
        CHECK_EQUAL(CELIX_SUCCESS, rc);
        CHECK(eplRef != NULL);

        rc = bundleContext_getService(context, eplRef, (void **)&eplService);
        CHECK_EQUAL(CELIX_SUCCESS, rc);
    }
コード例 #8
0
ファイル: sub_command.c プロジェクト: jawi/celix
void subCommand_execute(command_pt command, char *line, void (*out)(char *), void (*err)(char *)) {
	celix_status_t status = CELIX_SUCCESS;
    service_reference_pt calculatorService = NULL;
    apr_pool_t *memory_pool = NULL;
    apr_pool_t *bundle_memory_pool = NULL;

    status = bundleContext_getServiceReference(command->bundleContext, (char *) CALCULATOR_SERVICE, &calculatorService);
    if (status == CELIX_SUCCESS) {
    	char *token;
		char *commandStr = apr_strtok(line, " ", &token);
		char *aStr = apr_strtok(NULL, " ", &token);
		bool numeric;
		subCommand_isNumeric(command, aStr, &numeric);
		if (aStr != NULL && numeric) {
			char *bStr = apr_strtok(NULL, " ", &token);
			subCommand_isNumeric(command, bStr, &numeric);
			if (bStr != NULL && numeric) {
				calculator_service_pt calculator = NULL;
				status = bundleContext_getService(command->bundleContext, calculatorService, (void *) &calculator);
				if (status == CELIX_SUCCESS) {
					double a = atof(aStr);
					double b = atof(bStr);
					double result = 0;
					status = calculator->sub(calculator->calculator, a, b, &result);
					if (status == CELIX_SUCCESS) {
						char line[256];
						sprintf(line, "CALCULATOR_SHELL: Sub: %f - %f = %f\n", a, b, result);
						out(line);
					} else {
						out("SUB: Unexpected exception in Calc service\n");
					}
				} else {
					out("No calc service available\n");
				}
			} else {
				out("SUB: Requires 2 numerical parameter\n");
			}
		} else {
			out("SUB: Requires 2 numerical parameter\n");
			status = CELIX_ILLEGAL_ARGUMENT;
		}

        double a;
        double b;
    } else {
        out("No calc service available\n");
    }

    //return status;
}
コード例 #9
0
ファイル: log_command.c プロジェクト: leckie711/celix
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");
    }
}
コード例 #10
0
ファイル: help_command.c プロジェクト: leckie711/celix
celix_status_t helpCommand_execute(void *_ptr, char *line_str, FILE *out_ptr, FILE *err_ptr) {
    celix_status_t status = CELIX_SUCCESS;

    bundle_context_pt context_ptr = _ptr;
    service_reference_pt shell_service_reference_ptr = NULL;
    shell_service_pt shell_ptr = NULL;

    if (!context_ptr || !line_str || !out_ptr || !err_ptr) {
        status = CELIX_ILLEGAL_ARGUMENT;
    }

    if (status == CELIX_SUCCESS) {
        status = bundleContext_getServiceReference(context_ptr, (char *) OSGI_SHELL_SERVICE_NAME, &shell_service_reference_ptr);
    }

    if (status == CELIX_SUCCESS) {
        status = bundleContext_getService(context_ptr, shell_service_reference_ptr, (void **) &shell_ptr);
    }

    if (status == CELIX_SUCCESS) {
        uint32_t out_len = 256;
        char *sub = NULL;
        char *save_ptr = NULL;
        char out_str[out_len];

        memset(out_str, 0, sizeof(out_str));

        strtok_r(line_str, OSGI_SHELL_COMMAND_SEPARATOR, &save_ptr);
        sub = strtok_r(NULL, OSGI_SHELL_COMMAND_SEPARATOR, &save_ptr);

        if (sub == NULL) {
            unsigned int i;
            array_list_pt commands = NULL;

            status = shell_ptr->getCommands(shell_ptr->shell, &commands);
            for (i = 0; i < arrayList_size(commands); i++) {
                char *name = arrayList_get(commands, i);
                fprintf(out_ptr, "%s\n", name);
            }
            fprintf(out_ptr, "\nUse 'help <command-name>' for more information.\n");
        } else {
            celix_status_t sub_status_desc;
            celix_status_t sub_status_usage;
            int i;
            array_list_pt commands = NULL;
            shell_ptr->getCommands(shell_ptr->shell, &commands);
            for (i = 0; i < arrayList_size(commands); i++) {
                char *name = arrayList_get(commands, i);
                if (strcmp(sub, name) == 0) {
                    char *usage_str = NULL;
                    char *desc_str = NULL;

                    sub_status_desc = shell_ptr->getCommandDescription(shell_ptr->shell, name, &desc_str);
                    sub_status_usage = shell_ptr->getCommandUsage(shell_ptr->shell, name, &usage_str);

                    if (sub_status_usage == CELIX_SUCCESS && sub_status_desc == CELIX_SUCCESS) {
                        fprintf(out_ptr, "Command     : %s\n", name);
                        fprintf(out_ptr, "Usage       : %s\n", usage_str == NULL ? "" : usage_str);
                        fprintf(out_ptr, "Description : %s\n", desc_str == NULL ? "" : desc_str);
                    } else {
                        fprintf(err_ptr, "Error retreiving help info for command '%s'\n", sub);
                    }

                    if (sub_status_desc != CELIX_SUCCESS && status == CELIX_SUCCESS) {
                        status = sub_status_desc;
                    }
                    if (sub_status_usage != CELIX_SUCCESS && status == CELIX_SUCCESS) {
                        status = sub_status_usage;
                    }
                }
            }
            arrayList_destroy(commands);
        }
    }

    return status;
}