Beispiel #1
0
celix_status_t filter_match(filter_pt filter, properties_pt properties, bool *result) {
	switch (filter->operand) {
		case AND: {
			array_list_pt filters = (array_list_pt) filter->value;
			unsigned int i;
			for (i = 0; i < arrayList_size(filters); i++) {
				filter_pt sfilter = (filter_pt) arrayList_get(filters, i);
				bool mresult;
				filter_match(sfilter, properties, &mresult);
				if (!mresult) {
					*result = 0;
					return CELIX_SUCCESS;
				}
			}
			*result = 1;
			return CELIX_SUCCESS;
		}
		case OR: {
			array_list_pt filters = (array_list_pt) filter->value;
			unsigned int i;
			for (i = 0; i < arrayList_size(filters); i++) {
				filter_pt sfilter = (filter_pt) arrayList_get(filters, i);
				bool mresult;
				filter_match(sfilter, properties, &mresult);
				if (mresult) {
					*result = 1;
					return CELIX_SUCCESS;
				}
			}
			*result = 0;
			return CELIX_SUCCESS;
		}
		case NOT: {
			filter_pt sfilter = (filter_pt) filter->value;
			bool mresult;
			filter_match(sfilter, properties, &mresult);
			*result = !mresult;
			return CELIX_SUCCESS;
		}
		case SUBSTRING :
		case EQUAL :
		case GREATER :
        case GREATEREQUAL :
		case LESS :
        case LESSEQUAL :
		case APPROX : {
			char * value = (properties == NULL) ? NULL: (char*)properties_get(properties, filter->attribute);

			return filter_compare(filter->operand, value, filter->value, result);
		}
		case PRESENT: {
			char * value = (properties == NULL) ? NULL: (char*)properties_get(properties, filter->attribute);
			*result = value != NULL;
			return CELIX_SUCCESS;
		}
	}
	*result = 0;
	return CELIX_SUCCESS;
}
Beispiel #2
0
celix_status_t deviceManager_isDriverBundle(device_manager_pt manager, bundle_pt bundle, bool *isDriver) {
	celix_status_t status = CELIX_SUCCESS;
	(*isDriver) = false;

	array_list_pt refs = NULL;
		status = bundle_getRegisteredServices(bundle, &refs);
		if (status == CELIX_SUCCESS) {
			if (refs != NULL) {
				int i;
				for (i = 0; i < arrayList_size(refs); i++) {
					celix_status_t substatus = CELIX_SUCCESS;
					service_reference_pt ref = arrayList_get(refs, i);
					service_registration_pt registration = NULL;
					substatus = serviceReference_getServiceRegistration(ref, &registration);
					if (substatus == CELIX_SUCCESS) {
						properties_pt properties = NULL;
						substatus = serviceRegistration_getProperties(registration, &properties);
						if (substatus == CELIX_SUCCESS) {
							char *object = properties_get(properties, (char *) OSGI_FRAMEWORK_OBJECTCLASS);
																if (strcmp(object, "driver") == 0) {
																	*isDriver = true;
																	break;
																}
						}

					}
				}
				arrayList_destroy(refs);
			}
		}

	return status;
}
Beispiel #3
0
celix_status_t bundleCache_create(properties_pt configurationMap, framework_logger_pt logger, bundle_cache_pt *bundle_cache) {
    celix_status_t status;
    bundle_cache_pt cache;

	cache = (bundle_cache_pt) malloc((sizeof(*cache)));
    if (cache == NULL) {
        status = CELIX_ENOMEM;
    } else {
		if (configurationMap != NULL && *bundle_cache == NULL) {
            char * cacheDir = properties_get(configurationMap, (char *) OSGI_FRAMEWORK_FRAMEWORK_STORAGE);
			cache->configurationMap = configurationMap;
            if (cacheDir == NULL) {
                cacheDir = ".cache";
            }
            cache->cacheDir = cacheDir;
            cache->logger = logger;

            *bundle_cache = cache;
            status = CELIX_SUCCESS;
        } else {
            status = CELIX_ILLEGAL_ARGUMENT;
        }
    }

    framework_logIfError(cache->logger, status, NULL, "Failed to create bundle cache");

	return status;
}
celix_status_t managedServiceImpl_updated(managed_service_pt managedService, properties_pt properties){
	struct test_managed_service *msp = (struct test_managed_service *) managedService;

	if (properties == NULL){
		printf("[ managedServiceImpl ]: updated - Received NULL properties \n");
		msp->store_props(msp->handle, "", "");
	}else{
		printf("[ managedServiceImpl ]: updated - Received New Properties \n");
		char *value = properties_get(properties, "type");
		char *value2 = properties_get(properties, "second_type");
		msp->store_props(msp->handle, value, value2);
		// it would be nicer if we get the property values here and store them in the activator structure.
	}

	return CELIX_SUCCESS;
}
celix_status_t wiringAdmin_importWiringEndpoint(wiring_admin_pt admin, wiring_endpoint_description_pt wEndpointDescription) {
    celix_status_t status = CELIX_SUCCESS;

    wiring_send_service_pt wiringSendService = calloc(1, sizeof(*wiringSendService));

    if (!wiringSendService) {
        status = CELIX_ENOMEM;
    } else {
        service_registration_pt wiringSendServiceReg = NULL;
        char* wireId = properties_get(wEndpointDescription->properties, WIRING_ENDPOINT_DESCRIPTION_WIRE_ID_KEY);

        properties_pt props = properties_create();
        properties_set(props, (char*) INAETICS_WIRING_WIRE_ID, wireId);

        wiringSendService->wiringEndpointDescription = wEndpointDescription;
        wiringSendService->send = wiringAdmin_send;
        wiringSendService->admin = admin;
        wiringSendService->errorCount = 0;

        status = bundleContext_registerService(admin->context, (char *) INAETICS_WIRING_SEND_SERVICE, wiringSendService, props, &wiringSendServiceReg);

        if (status == CELIX_SUCCESS) {

            hashMap_put(admin->wiringSendServices, wEndpointDescription, wiringSendService);
            hashMap_put(admin->wiringSendRegistrations, wEndpointDescription, wiringSendServiceReg);

            printf("%s: SEND SERVICE sucessfully registered w/ wireId %s\n", TAG, wireId);
        } else {
            printf("%s: could not register SEND SERVICE w/ wireId %s\n", TAG, wireId);

        }
    }

    return status;
}
Beispiel #6
0
celix_status_t eventAdmin_getTopic( event_pt *event, char **topic){
	celix_status_t status = CELIX_SUCCESS;
	char *value;
	value = properties_get((*event)->properties,(char*) EVENT_TOPIC);
	*topic = value;

	return status;
}
celix_status_t wiringAdmin_exportWiringEndpoint(wiring_admin_pt admin, wiring_endpoint_description_pt* wEndpointDescription) {
    celix_status_t status = CELIX_SUCCESS;

    celixThreadMutex_lock(&admin->exportedWiringEndpointLock);

    if (hashMap_size(admin->wiringReceiveTracker) == 0) {
        status = wiringAdmin_startWebserver(admin->context, &admin);
    }

    if (status == CELIX_SUCCESS) {
        char* fwuuid = NULL;

        status = bundleContext_getProperty(admin->context, OSGI_FRAMEWORK_FRAMEWORK_UUID, &fwuuid);

        if (status == CELIX_SUCCESS) {
            char* wireId = NULL;
            properties_pt props = properties_create();

            printf("%s: HTTP Wiring Endpoint running at %s\n", TAG, admin->url);

            status = wiringEndpointDescription_create(NULL, props, wEndpointDescription);

            properties_set(props, WIRING_ADMIN_PROPERTIES_CONFIG_KEY, WIRING_ADMIN_PROPERTIES_CONFIG_VALUE);
            properties_set(props, WIRING_ENDPOINT_DESCRIPTION_HTTP_URL_KEY, admin->url);
            properties_set(props, (char*) OSGI_RSA_ENDPOINT_FRAMEWORK_UUID, fwuuid);

            wireId = properties_get(props, WIRING_ENDPOINT_DESCRIPTION_WIRE_ID_KEY);

            printf("%s: wiringEndpointDescription_create w/ wireId %s started\n", TAG, wireId);

            if (status == CELIX_SUCCESS) {
                service_tracker_pt tracker = NULL;
                status = wiringAdmin_createWiringReceiveTracker(admin, &tracker, wireId);

                if (status == CELIX_SUCCESS) {
                    status = serviceTracker_open(tracker);

                    if (status == CELIX_SUCCESS) {
                        hashMap_put(admin->wiringReceiveTracker, *wEndpointDescription, tracker);
                        printf("%s: WiringReceiveTracker w/ wireId %s started\n", TAG, wireId);
                    } else {
                        serviceTracker_destroy(tracker);
                    }
                }
            }
        }
    } else {
        printf("%s: Cannot export Wiring Endpoint\n", TAG);
    }

    celixThreadMutex_unlock(&admin->exportedWiringEndpointLock);

    return status;
}
Beispiel #8
0
const gchar *network_get_uuid(Network *self, GError **error)
{
	g_assert(NETWORK_IS(self));
	g_assert(self->priv->properties != NULL);
	GVariant *prop = properties_get(self->priv->properties, NETWORK_DBUS_INTERFACE, "UUID", error);
	if(prop == NULL)
		return NULL;
	const gchar *ret = g_variant_get_string(prop, NULL);
	g_variant_unref(prop);
	return ret;
}
Beispiel #9
0
const gchar *proximity_monitor_get_signal_level(ProximityMonitor *self, GError **error)
{
	g_assert(PROXIMITY_MONITOR_IS(self));
	g_assert(self->priv->properties != NULL);
	GVariant *prop = properties_get(self->priv->properties, PROXIMITY_MONITOR_DBUS_INTERFACE, "SignalLevel", error);
	if(prop == NULL)
		return NULL;
	const gchar *ret = g_variant_get_string(prop, NULL);
	g_variant_unref(prop);
	return ret;
}
Beispiel #10
0
const gchar *health_device_get_main_channel(HealthDevice *self, GError **error)
{
	g_assert(HEALTH_DEVICE_IS(self));
	g_assert(self->priv->properties != NULL);
	GVariant *prop = properties_get(self->priv->properties, HEALTH_DEVICE_DBUS_INTERFACE, "MainChannel", error);
	if(prop == NULL)
		return NULL;
	const gchar *ret = g_variant_get_string(prop, NULL);
	g_variant_unref(prop);
	return ret;
}
Beispiel #11
0
guint8 obex_session_get_channel(ObexSession *self, GError **error)
{
	g_assert(OBEX_SESSION_IS(self));
	g_assert(self->priv->properties != NULL);
	GVariant *prop = properties_get(self->priv->properties, OBEX_SESSION_DBUS_INTERFACE, "Channel", error);
	if(prop == NULL)
		return 0;
	guchar ret = g_variant_get_byte(prop);
	g_variant_unref(prop);
	return ret;
}
Beispiel #12
0
gboolean network_get_connected(Network *self, GError **error)
{
	g_assert(NETWORK_IS(self));
	g_assert(self->priv->properties != NULL);
	GVariant *prop = properties_get(self->priv->properties, NETWORK_DBUS_INTERFACE, "Connected", error);
	if(prop == NULL)
		return FALSE;
	gboolean ret = g_variant_get_boolean(prop);
	g_variant_unref(prop);
	return ret;
}
Beispiel #13
0
const gchar *obex_session_get_target(ObexSession *self, GError **error)
{
	g_assert(OBEX_SESSION_IS(self));
	g_assert(self->priv->properties != NULL);
	GVariant *prop = properties_get(self->priv->properties, OBEX_SESSION_DBUS_INTERFACE, "Target", error);
	if(prop == NULL)
		return NULL;
	const gchar *ret = g_variant_get_string(prop, NULL);
	g_variant_unref(prop);
	return ret;
}
Beispiel #14
0
celix_status_t etcdWatcher_addOwnNode(etcd_watcher_pt watcher) {
    celix_status_t status = CELIX_BUNDLE_EXCEPTION;
    char localNodePath[MAX_LOCALNODE_LENGTH];
    char* ttlStr = NULL;
    int ttl;

    node_discovery_pt node_discovery = watcher->node_discovery;
    bundle_context_pt context = node_discovery->context;
    node_description_pt ownNodeDescription = node_discovery->ownNode;

    // register own framework
    status = etcdWatcher_getLocalNodePath(context, ownNodeDescription, &localNodePath[0]);

    // determine ttl
    if ((bundleContext_getProperty(context, CFG_ETCD_TTL, &ttlStr) != CELIX_SUCCESS) || !ttlStr) {
        ttl = DEFAULT_ETCD_TTL;
    } else {
        char* endptr = ttlStr;
        errno = 0;
        ttl = strtol(ttlStr, &endptr, 10);
        if (*endptr || errno != 0) {
            ttl = DEFAULT_ETCD_TTL;
        }
    }

    // register every wiring endpoint
    array_list_iterator_pt endpointIter = arrayListIterator_create(ownNodeDescription->wiring_ep_descriptions_list);

    while (status == CELIX_SUCCESS && arrayListIterator_hasNext(endpointIter)) {
        wiring_endpoint_description_pt wiringEndpointDesc = arrayListIterator_next(endpointIter);

        if (wiringEndpointDesc == NULL) {
            status = CELIX_ILLEGAL_ARGUMENT;
        } else {
            char etcdKey[MAX_LOCALNODE_LENGTH];
            char etcdValue[MAX_LOCALNODE_LENGTH];
            char* wireId = properties_get(wiringEndpointDesc->properties, WIRING_ENDPOINT_DESCRIPTION_WIRE_ID_KEY);

            wiringEndpoint_properties_store(wiringEndpointDesc->properties, &etcdValue[0]);

            snprintf(etcdKey, MAX_LOCALNODE_LENGTH, "%s/%s", localNodePath, wireId);

            // TODO : implement update
            etcd_set(etcdKey, etcdValue, ttl, false);
        }
    }

    arrayListIterator_destroy(endpointIter);

    return status;
}
Beispiel #15
0
celix_status_t deploymentPackage_processEntries(deployment_package_pt package) {
	celix_status_t status = CELIX_SUCCESS;

	hash_map_pt entries = NULL;
	manifest_getEntries(package->manifest, &entries);
	hash_map_iterator_pt iter = hashMapIterator_create(entries);
	while (hashMapIterator_hasNext(iter)) {
		hash_map_entry_pt entry = hashMapIterator_nextEntry(iter);
		char *name = hashMapEntry_getKey(entry);
		properties_pt values = hashMapEntry_getValue(entry);

		bool isBundleResource;
		deploymentPackage_isBundleResource(values, &isBundleResource);
		if (isBundleResource) {
			bundle_info_pt info = apr_palloc(package->pool, sizeof(*info));
			info->path = name;
			info->attributes = values;
			info->symbolicName = properties_get(values, (char *) OSGI_FRAMEWORK_BUNDLE_SYMBOLICNAME);
			char *version = properties_get(values, (char *) OSGI_FRAMEWORK_BUNDLE_VERSION);
			info->version = NULL;
			status = version_createVersionFromString(version, &info->version);
			char *customizer = properties_get(values, (char *) DEPLOYMENTPACKAGE_CUSTOMIZER);
			deploymentPackage_parseBooleanHeader(customizer, &info->customizer);

			arrayList_add(package->bundleInfos, info);
		} else {
			resource_info_pt info = apr_palloc(package->pool, sizeof(*info));
			info->path = name;
			info->attributes = values;
			info->resourceProcessor = properties_get(values, (char *) RESOURCE_PROCESSOR);

			arrayList_add(package->resourceInfos, info);
		}
	}
	hashMapIterator_destroy(iter);

	return status;
}
Beispiel #16
0
celix_status_t eventAdmin_containsProperty( event_pt *event, char *property, bool *result){
	celix_status_t status = CELIX_SUCCESS;
	if((*event)==NULL || property == NULL){
		status = CELIX_BUNDLE_EXCEPTION;
	}else {
		char * propertyValue = properties_get((*event)->properties,property);
		if(propertyValue == NULL){
			(*result)= false;
		}else {
			(*result) = true;
		}
	}
	return status;
}
static celix_status_t wiringAdmin_send(wiring_send_service_pt sendService, char *request, char **reply, int* replyStatus) {

    celix_status_t status = CELIX_SUCCESS;

    struct post post;
    post.readptr = request;
    post.size = strlen(request);

    struct get get;
    get.size = 0;
    get.writeptr = malloc(1);

    char* url = properties_get(sendService->wiringEndpointDescription->properties, WIRING_ENDPOINT_DESCRIPTION_HTTP_URL_KEY);

    CURL *curl;
    CURLcode res;

    curl = curl_easy_init();
    if (!curl) {
        status = CELIX_ILLEGAL_STATE;
    } else {
        long http_code = 0;

        curl_easy_setopt(curl, CURLOPT_URL, url);
        curl_easy_setopt(curl, CURLOPT_POST, 1L);
        curl_easy_setopt(curl, CURLOPT_READFUNCTION, wiringAdmin_HTTPReqReadCallback);
        curl_easy_setopt(curl, CURLOPT_READDATA, &post);
        curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, wiringAdmin_HTTPReqWrite);
        curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)&get);
        curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 2L);
        curl_easy_setopt(curl, CURLOPT_TIMEOUT, 2L);
        curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, (curl_off_t)post.size);
        res = curl_easy_perform(curl);

        curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &http_code);

        if (http_code == 200 && res != CURLE_ABORTED_BY_CALLBACK) {
            *replyStatus = res;
            *reply = get.writeptr;
        } else {
            *replyStatus = http_code;
            free(get.writeptr);
        }

        curl_easy_cleanup(curl);
    }

    return status;
}
static DBusMessage *
properties_get_or_set(DBusMessage *message, DBusMessageIter *iter,
		      char *interface,
		      struct wpa_dbus_object_desc *obj_dsc)
{
	const struct wpa_dbus_property_desc *property_dsc;
	char *property;
	const char *method;

	method = dbus_message_get_member(message);
	property_dsc = obj_dsc->properties;

	/* Second argument: property name (DBUS_TYPE_STRING) */
	if (!dbus_message_iter_next(iter) ||
	    dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_STRING) {
		return dbus_message_new_error(message, DBUS_ERROR_INVALID_ARGS,
					      NULL);
	}
	dbus_message_iter_get_basic(iter, &property);

	while (property_dsc && property_dsc->dbus_property) {
		/* compare property names and
		 * interfaces */
		if (!os_strncmp(property_dsc->dbus_property, property,
				WPAS_DBUS_METHOD_SIGNAL_PROP_MAX) &&
		    !os_strncmp(property_dsc->dbus_interface, interface,
				WPAS_DBUS_INTERFACE_MAX))
			break;

		property_dsc++;
	}
	if (property_dsc == NULL || property_dsc->dbus_property == NULL) {
		wpa_printf(MSG_DEBUG, "no property handler for %s.%s on %s",
			   interface, property,
			   dbus_message_get_path(message));
		return dbus_message_new_error(message, DBUS_ERROR_INVALID_ARGS,
					      "No such property");
	}

	if (os_strncmp(WPA_DBUS_PROPERTIES_GET, method,
		       WPAS_DBUS_METHOD_SIGNAL_PROP_MAX) == 0) {
		wpa_printf(MSG_MSGDUMP, "%s: Get(%s)", __func__, property);
		return properties_get(message, property_dsc,
				      obj_dsc->user_data);
	}

	wpa_printf(MSG_MSGDUMP, "%s: Set(%s)", __func__, property);
	return properties_set(message, property_dsc, obj_dsc->user_data);
}
Beispiel #19
0
celix_status_t serviceRegistry_removeHook(service_registry_pt registry, service_registration_pt registration) {
	celix_status_t status = CELIX_SUCCESS;
	char *serviceName = NULL;

	properties_pt props = NULL;
	serviceRegistration_getProperties(registration, &props);
	serviceName = properties_get(props, (char *) OSGI_FRAMEWORK_OBJECTCLASS);
	if (strcmp(OSGI_FRAMEWORK_LISTENER_HOOK_SERVICE_NAME, serviceName) == 0) {
	    celixThreadMutex_lock(&registry->mutex);
		arrayList_removeElement(registry->listenerHooks, registration);
		celixThreadMutex_unlock(&registry->mutex);
	}

	return status;
}
Beispiel #20
0
celix_status_t deviceManager_noDriverFound(device_manager_pt manager, void *service, service_reference_pt reference) {
	celix_status_t status = CELIX_SUCCESS;
	service_registration_pt registration = NULL;
	status = serviceReference_getServiceRegistration(reference, &registration);
	if (status == CELIX_SUCCESS) {
		properties_pt properties = NULL;
		status = serviceRegistration_getProperties(registration, &properties);
		if (status == CELIX_SUCCESS) {
			char *objectClass = properties_get(properties, (char *) OSGI_FRAMEWORK_OBJECTCLASS);
			if (strcmp(objectClass, OSGI_DEVICEACCESS_DRIVER_SERVICE_NAME) == 0) {
				device_service_pt device = service;
				status = device->noDriverFound(device->device);
			}
		}
	}
	return status;
}
celix_status_t wiringAdmin_removeImportedWiringEndpoint(wiring_admin_pt admin, wiring_endpoint_description_pt wEndpointDescription) {
    celix_status_t status;

    celixThreadMutex_lock(&admin->importedWiringEndpointLock);
    char* wireId = properties_get(wEndpointDescription->properties, WIRING_ENDPOINT_DESCRIPTION_WIRE_ID_KEY);

    printf("%s: remove Wiring Endpoint w/ wireId %s\n", TAG, wireId);

    wiring_send_service_pt wiringSendService = hashMap_remove(admin->wiringSendServices, wEndpointDescription);
    service_registration_pt wiringSendRegistration = hashMap_remove(admin->wiringSendRegistrations, wEndpointDescription);

    status = serviceRegistration_unregister(wiringSendRegistration);

    if (status == CELIX_SUCCESS) {
        free(wiringSendService);
    }

    celixThreadMutex_unlock(&admin->importedWiringEndpointLock);

    return status;
}
Beispiel #22
0
celix_status_t consumingDriver_match(void *driverHandler, service_reference_pt reference, int *value) {
	printf("CONSUMING_DRIVER: match called\n");
	int match=0;
	celix_status_t status = CELIX_SUCCESS;
	consuming_driver_pt driver = driverHandler;

	service_registration_pt registration = NULL;
	properties_pt properties = NULL;
	status = serviceReference_getServiceRegistration(reference, &registration);
	if (status == CELIX_SUCCESS) {
		status = serviceRegistration_getProperties(registration, &properties);
		if (status == CELIX_SUCCESS) {
			char *category = properties_get(properties, OSGI_DEVICEACCESS_DEVICE_CATEGORY);
			if (strcmp(category, REFINING_DRIVER_DEVICE_CATEGORY) == 0) {
				match = 10;
			}
		}
	}

	(*value) = match;
	return status;
}
static celix_status_t benchmarkRunner_addedService(void * handle, service_reference_pt reference, void * service) {
    celix_status_t status = CELIX_SUCCESS;
    struct activator * activator = handle;

    service_registration_pt registration = NULL;
    properties_pt properties = NULL;
    char *serviceName = NULL;
    serviceReference_getServiceRegistration(reference, &registration);
    serviceRegistration_getProperties(registration, &properties);
    serviceName = properties_get(properties, "objectClass");
    if (strcmp(serviceName, BENCHMARK_SERVICE_NAME) == 0) {
        pthread_mutex_lock(&activator->mutex);
        activator->benchmark = service;
        pthread_mutex_unlock(&activator->mutex);
    } else if (strcmp(serviceName, FREQUENCY_SERVICE_NAME) == 0 ) {
        pthread_mutex_lock(&activator->mutex);
        activator->freqService = service;
        pthread_mutex_unlock(&activator->mutex);
    }

    return status;
}
celix_status_t wiringTopologyManager_waAdded(void * handle, service_reference_pt reference, void * service) {
    celix_status_t status = CELIX_SUCCESS;
    wiring_topology_manager_pt manager = handle;
    wiring_admin_service_pt wiringAdminService = (wiring_admin_service_pt) service;

    celixThreadMutex_lock(&manager->waListLock);
    arrayList_add(manager->waList, wiringAdminService);
    celixThreadMutex_unlock(&manager->waListLock);

    /* check whether one of the exported Wires can be exported via the newly available wiringAdmin */
    celixThreadMutex_lock(&manager->exportedWiringEndpointsLock);
    hash_map_iterator_pt iter = hashMapIterator_create(manager->exportedWiringEndpoints);

    // is the properties_match missing here>
    while (hashMapIterator_hasNext(iter)) {
        hash_map_entry_pt entry = hashMapIterator_nextEntry(iter);
        properties_pt exportedWireProperties = hashMapEntry_getKey(entry);
        hash_map_pt wiringAdminList = hashMapEntry_getValue(entry);
        wiring_endpoint_description_pt wEndpoint = NULL;

        char* serviceId = properties_get(exportedWireProperties, "service.id");

        printf("WTM: wiringTopologyManager_waAdded export Wire for %s \n", serviceId);

        status = wiringTopologyManager_WiringAdminServiceExportWiringEndpoint(manager, wiringAdminService, exportedWireProperties, &wEndpoint);

        if (status == CELIX_SUCCESS) {
            hashMap_put(wiringAdminList, wiringAdminService, wEndpoint);
        } else {
            printf("WTM: Could not export wire with new WA\n");
        }
    }
    hashMapIterator_destroy(iter);

    /* check whether the waiting exports can be exported */

    array_list_iterator_pt waitList = arrayListIterator_create(manager->waitingForExport);

    while (arrayListIterator_hasNext(waitList)) {
        properties_pt srvcProperties = arrayListIterator_next(waitList);
        char* serviceId = properties_get(srvcProperties, "service.id");

        printf("WTM: wiringTopologyManager_waAdded export Wire for %s \n", serviceId);
        wiring_endpoint_description_pt wEndpoint = NULL;

        status = wiringTopologyManager_WiringAdminServiceExportWiringEndpoint(manager, wiringAdminService, srvcProperties, &wEndpoint);

        if (status == CELIX_SUCCESS) {
            arrayListIterator_remove(waitList);

            arrayListIterator_destroy(waitList);
            waitList = arrayListIterator_create(manager->waitingForExport);

            hash_map_pt wiringAdminList = hashMap_create(NULL, NULL, NULL, NULL);
            hashMap_put(wiringAdminList, wiringAdminService, wEndpoint);
            hashMap_put(manager->exportedWiringEndpoints, srvcProperties, wiringAdminList);
        } else {
            printf("WTM: Could not export wire with new WA\n");
        }
    }

    arrayListIterator_destroy(waitList);

    celixThreadMutex_unlock(&manager->exportedWiringEndpointsLock);

    /* Check if the added WA can match one of the imported WiringEndpoints */
    celixThreadMutex_lock(&manager->importedWiringEndpointsLock);
    iter = hashMapIterator_create(manager->importedWiringEndpoints);
    while (hashMapIterator_hasNext(iter)) {
        hash_map_entry_pt entry = hashMapIterator_nextEntry(iter);
        wiring_endpoint_description_pt wEndpoint = hashMapEntry_getKey(entry);
        array_list_pt wiringAdminList = hashMapEntry_getValue(entry);

        status = wiringTopologyManager_checkWiringAdminForImportWiringEndpoint(manager, wiringAdminService, wEndpoint);

        if (status == CELIX_SUCCESS) {
            arrayList_add(wiringAdminList, wiringAdminService);
        }

    }
    hashMapIterator_destroy(iter);


    /* check wether waiting service can be exported */
    wiringTopologyManager_checkWaitingForImportServices(manager);

    celixThreadMutex_unlock(&manager->importedWiringEndpointsLock);

    printf("WTM: Added WA\n");

    return status;
}
Beispiel #25
0
celix_status_t deviceManager_matchAttachDriver(device_manager_pt manager, apr_pool_t *attachPool, driver_loader_pt loader,
		array_list_pt driverIds, array_list_pt included, array_list_pt excluded, void *service, service_reference_pt reference) {
	celix_status_t status = CELIX_SUCCESS;

	array_list_pt references = NULL;

	int i;
	for (i = 0; i < arrayList_size(excluded); i++) {
		void *exclude = arrayList_get(excluded, i);
		arrayList_removeElement(included, exclude);
	}

	for (i = 0; i < arrayList_size(driverIds); i++) {
		char *id = arrayList_get(driverIds, i);
		printf("DEVICE_MANAGER: Driver found: %s\n", id);
	}

	status = driverLoader_loadDrivers(loader, attachPool, manager->locators, driverIds, &references);
	if (status == CELIX_SUCCESS) {
		for (i = 0; i < arrayList_size(references); i++) {
			service_reference_pt reference = arrayList_get(references, i);
			driver_attributes_pt attributes = hashMap_get(manager->drivers, reference);
			if (attributes != NULL) {
				arrayList_add(included, attributes);
			}
		}

		driver_matcher_pt matcher = NULL;
		status = driverMatcher_create(attachPool, manager->context, &matcher);
		if (status == CELIX_SUCCESS) {
			for (i = 0; i < arrayList_size(included); i++) {
				driver_attributes_pt attributes = arrayList_get(included, i);

				int match = 0;
				celix_status_t substatus = driverAttributes_match(attributes, reference, &match);
				if (substatus == CELIX_SUCCESS) {
					printf("DEVICE_MANAGER: Found match: %d\n", match);
					if (match <= OSGI_DEVICEACCESS_DEVICE_MATCH_NONE) {
						continue;
					}
					driverMatcher_add(matcher, match, attributes);
				} else {
					// Ignore
				}
			}

			match_pt match = NULL;
			status = driverMatcher_getBestMatch(matcher, attachPool, reference, &match);
			if (status == CELIX_SUCCESS) {
				if (match == NULL) {
					status = deviceManager_noDriverFound(manager, service, reference);
				} else {
					service_registration_pt registration = NULL;
					status = serviceReference_getServiceRegistration(match->reference, &registration);
					if (status == CELIX_SUCCESS) {
						properties_pt properties = NULL;
						status = serviceRegistration_getProperties(registration, &properties);
						if (status == CELIX_SUCCESS) {
							char *driverId = properties_get(properties, (char *) OSGI_DEVICEACCESS_DRIVER_ID);
							driver_attributes_pt finalAttributes = hashMap_get(manager->drivers, match->reference);
							if (finalAttributes == NULL) {
								status = deviceManager_noDriverFound(manager, service, reference);
							} else {
								char *newDriverId = NULL;
								status = driverAttributes_attach(finalAttributes, reference, &newDriverId);
								if (status == CELIX_SUCCESS) {
									if (newDriverId != NULL) {
										array_list_pt ids = NULL;
										arrayList_create(&ids);
										arrayList_add(ids, newDriverId);
										arrayList_add(excluded, finalAttributes);
										status = deviceManager_matchAttachDriver(manager, attachPool, loader,
												ids, included, excluded, service, reference);
									} else {
										// Attached, unload unused drivers
										status = driverLoader_unloadDrivers(loader, finalAttributes);
									}
								}
							}
						}
					}
				}
			}
		}
	}

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

	return status;
}
Beispiel #26
0
char * properties_getWithDefault(properties_pt properties, char * key, char * defaultValue) {
	char * value = properties_get(properties, key);
	return value == NULL ? defaultValue : value;
}
Beispiel #27
0
celix_status_t configuration_create2(configuration_admin_factory_pt factory, configuration_store_pt store,
                                     properties_pt dictionary,
                                     configuration_pt *configuration) {

    configuration_pt config;
    configuration_impl_pt conf_impl;

    celix_thread_mutexattr_t	mutex_attr;
    char *value;

    config = calloc(1, sizeof(struct configuration));
    if (config == NULL) return CELIX_ENOMEM;
    conf_impl = calloc(1, sizeof(struct configuration_impl));
    if (conf_impl == NULL) {
        free (config);
        return CELIX_ENOMEM;
    }

    config->configuration_delete = configuration_delete;
    config->configuration_equals = configuration_equals;
    config->configuration_getBundleLocation = configuration_getBundleLocation;
    config->configuration_getFactoryPid = configuration_getFactoryPid;
    config->configuration_getPid = configuration_getPid;
    config->configuration_getProperties = configuration_getProperties;
    config->configuration_hashCode = configuration_hashCode;
    config->configuration_setBundleLocation = configuration_setBundleLocation;
    config->configuration_update = configuration_update;

    conf_impl->configurationAdminFactory  = factory;
    conf_impl->configurationStore = store;

    value = properties_get(dictionary,(char *)SERVICE_FACTORYPID);
    if (value != NULL)
        conf_impl->factoryPid = strdup(value);
    else
        conf_impl->factoryPid = NULL;
    value = properties_get(dictionary, (char *)OSGI_FRAMEWORK_SERVICE_PID);
    if (value != NULL)
        conf_impl->pid = strdup(value);
    else
        conf_impl->pid = NULL;
    value = properties_get(dictionary, (char *)SERVICE_BUNDLELOCATION);
    if (value != NULL)
        conf_impl->bundleLocation = strdup(value);
    else
        conf_impl->bundleLocation = NULL;
    conf_impl->dictionary = NULL;

    conf_impl->deleted = false;
    conf_impl->boundBundle = NULL;

    celixThreadMutexAttr_create(&mutex_attr);
    celixThreadMutexAttr_settype(&mutex_attr, CELIX_THREAD_MUTEX_RECURSIVE);  // why recursive?
    if( celixThreadMutex_create(&conf_impl->mutex, &mutex_attr) != CELIX_SUCCESS ) {
        printf("[ ERROR ]: Configuration{PID=%s} - Not created (MUTEX) \n", conf_impl->pid);
        return CELIX_ILLEGAL_ARGUMENT;
    }
    celixThreadMutexAttr_destroy(&mutex_attr);
    configuration_updateDictionary(conf_impl, dictionary);

    conf_impl->configuration_interface = config;
    config->handle = conf_impl;
    *configuration = config;
    return CELIX_SUCCESS;

}
Beispiel #28
0
celix_status_t driverMatcher_getBestMatchInternal(driver_matcher_pt matcher, apr_pool_t *pool, match_pt *match) {
	celix_status_t status = CELIX_SUCCESS;

	if (!hashMap_isEmpty(matcher->attributes)) {
		match_key_t matchKey = NULL;
		hash_map_iterator_pt iter = hashMapIterator_create(matcher->attributes);
		while (hashMapIterator_hasNext(iter)) {
			hash_map_entry_pt entry = hashMapIterator_nextEntry(iter);
			match_key_t key = hashMapEntry_getKey(entry);
			if (matchKey == NULL || matchKey->matchValue < key->matchValue) {
				matchKey = key;
			}
		}
		hashMapIterator_destroy(iter);

		array_list_pt das = hashMap_get(matcher->attributes, matchKey);
		service_reference_pt best = NULL;
		int i;
		for (i = 0; i < arrayList_size(das); i++) {
			driver_attributes_pt attributes = arrayList_get(das, i);
			service_reference_pt reference = NULL;

			celix_status_t substatus = driverAttributes_getReference(attributes, &reference);
			if (substatus == CELIX_SUCCESS) {
				if (best != NULL) {
					printf("DRIVER_MATCHER: Compare ranking\n");
					char *rank1Str, *rank2Str;
					int rank1, rank2;
					service_registration_pt registration = NULL;
					substatus = serviceReference_getServiceRegistration(reference, &registration);
					if (substatus == CELIX_SUCCESS) {
						properties_pt properties = NULL;
						status = serviceRegistration_getProperties(registration, &properties);
						if (status == CELIX_SUCCESS) {

							rank1Str = properties_getWithDefault(properties, (char *) OSGI_FRAMEWORK_SERVICE_RANKING, "0");
							rank2Str = properties_getWithDefault(properties, (char *) OSGI_FRAMEWORK_SERVICE_RANKING, "0");

							rank1 = atoi(rank1Str);
							rank2 = atoi(rank2Str);

							if (rank1 != rank2) {
								if (rank1 > rank2) {
									best = reference;
								}
							} else {
								printf("DRIVER_MATCHER: Compare id's\n");
								char *id1Str, *id2Str;
								long id1, id2;

								id1Str = properties_get(properties, (char *) OSGI_FRAMEWORK_SERVICE_ID);
								id2Str = properties_get(properties, (char *) OSGI_FRAMEWORK_SERVICE_ID);

								id1 = atol(id1Str);
								id2 = atol(id2Str);

								if (id1 < id2) {
									best = reference;
								}
							}
						}
					}
				} else {
					best = reference;
				}
			}

		}

		*match = apr_palloc(pool, sizeof(**match));
		if (!*match) {
			status = CELIX_ENOMEM;
		} else {
			(*match)->matchValue = matchKey->matchValue;
			(*match)->reference = best;
		}
	}

	return status;
}
Beispiel #29
0
char * manifest_getValue(manifest_pt manifest, const char * name) {
	char * val = properties_get(manifest->mainAttributes, (char *) name);
	bool isEmpty = utils_isStringEmptyOrNull(val);
	return isEmpty ? NULL : val;
}
Beispiel #30
0
static celix_status_t deploymentPackage_isBundleResource(properties_pt attributes, bool *isBundleResource) {
	*isBundleResource = properties_get(attributes, (char *) OSGI_FRAMEWORK_BUNDLE_SYMBOLICNAME) != NULL;
	return CELIX_SUCCESS;
}