static celix_status_t remoteProxyFactory_registerProxyService()

in bundles/remote_services/rsa_common/src/remote_proxy_factory_impl.c [159:217]


static celix_status_t remoteProxyFactory_registerProxyService(remote_proxy_factory_t *remote_proxy_factory_ptr, endpoint_description_t *endpointDescription, remote_service_admin_t *rsa, sendToHandle sendToCallback) {
	celix_status_t status = CELIX_SUCCESS;
	proxy_instance_pt proxy_instance_ptr = NULL;

	if (!remote_proxy_factory_ptr || !remote_proxy_factory_ptr->create_proxy_service_ptr) {
		status = CELIX_ILLEGAL_ARGUMENT;
	}

	if (status == CELIX_SUCCESS) {
		proxy_instance_ptr = calloc(1, sizeof(*proxy_instance_ptr));
		if (!proxy_instance_ptr) {
			status = CELIX_ENOMEM;
		}
	}

	if (status == CELIX_SUCCESS) {
		proxy_instance_ptr->properties = celix_properties_create();
		if (!proxy_instance_ptr->properties) {
			status = CELIX_ENOMEM;
		}
	}

	if (status == CELIX_SUCCESS) {
		status = remote_proxy_factory_ptr->create_proxy_service_ptr(remote_proxy_factory_ptr->handle, endpointDescription, rsa, sendToCallback, proxy_instance_ptr->properties, &proxy_instance_ptr->service);
	}

	if (status == CELIX_SUCCESS) {
		celix_properties_set(proxy_instance_ptr->properties, "proxy.interface", remote_proxy_factory_ptr->service);

		hash_map_iterator_pt iter = hashMapIterator_create(endpointDescription->properties);
		while (hashMapIterator_hasNext(iter)) {
			hash_map_entry_pt entry = hashMapIterator_nextEntry(iter);
			char *key = hashMapEntry_getKey(entry);
			char *value = hashMapEntry_getValue(entry);

			celix_properties_set(proxy_instance_ptr->properties, key, value);
		}
		hashMapIterator_destroy(iter);
	}

	if (status == CELIX_SUCCESS) {
		status = bundleContext_registerService(remote_proxy_factory_ptr->context_ptr, remote_proxy_factory_ptr->service, proxy_instance_ptr->service, proxy_instance_ptr->properties, &proxy_instance_ptr->registration_ptr);
	}

	if (status == CELIX_SUCCESS) {
		hashMap_put(remote_proxy_factory_ptr->proxy_instances, endpointDescription, proxy_instance_ptr);
	}

	if(status!=CELIX_SUCCESS){
		if(proxy_instance_ptr != NULL){
			if(proxy_instance_ptr->properties != NULL){
				celix_properties_destroy(proxy_instance_ptr->properties);
			}
			free(proxy_instance_ptr);
		}
	}

	return status;
}