Ejemplo n.º 1
0
celix_status_t configuration_getProperties(void *handle, properties_pt *properties) {

    configuration_impl_pt conf = (configuration_impl_pt) handle;

    properties_pt copy = conf->dictionary;

    // (1) configuration.lock
    configuration_lock(conf);

    // (2) configuration.checkDeleted
    if ( configuration_checkDeleted(conf) != CELIX_SUCCESS ) {
        configuration_unlock(conf);
        return CELIX_ILLEGAL_STATE;
    }
    // (3) Have the Configuration properties ?
    if ( conf->dictionary == NULL ) {
        *properties = NULL;
        configuration_unlock(conf);
        return CELIX_SUCCESS;
    }

    // (4) configuration.setAutoProperties
    if ( configuration_setAutoProperties(conf, &copy, false) != CELIX_SUCCESS ) {
        configuration_unlock(conf);
        return CELIX_ILLEGAL_ARGUMENT;
    }

    // (5) return
    *properties = copy;
    configuration_unlock(conf);
    return CELIX_SUCCESS;
}
Ejemplo n.º 2
0
// properties_pt as input and output
celix_status_t configuration_setAutoProperties(configuration_impl_pt configuration, properties_pt *properties, bool withBundleLocation) {

    //(1) configuration.lock
    configuration_lock(configuration);

    // (2) set service.pid
//    if (properties_get(*properties, (char*)OSGI_FRAMEWORK_SERVICE_PID) != NULL) {
    properties_set(*properties, (char*)OSGI_FRAMEWORK_SERVICE_PID, configuration->pid);
//    }

    // (3) set factory.pid
    if ( configuration->factoryPid != NULL ) {
        properties_set(*properties, (char*)SERVICE_FACTORYPID, configuration->factoryPid);
    }

    // (4) set service.bundleLocation
    if ( withBundleLocation ) {

        if ( configuration_setBundleLocationProperty(configuration, properties) != CELIX_SUCCESS ) {
            configuration_unlock(configuration);
            return CELIX_ILLEGAL_ARGUMENT;
        }

    }

    // (5) return
    configuration_unlock(configuration);
    return CELIX_SUCCESS;

}
Ejemplo n.º 3
0
celix_status_t configuration_bind(configuration_impl_pt configuration, bundle_pt bundle, bool *isBind) {

//	printf("[ DEBUG ]: Configuration{PID=%s} - bind(START) \n",configuration->pid);

    char *bundleLocation;

    configuration_lock(configuration);

    /* ----------- BINDING -------------- */

    // (1): it's the configuration already bound?
    if ( configuration->boundBundle == NULL ) { // (1): No

        // (2): it's the configuration located?
        if ( configuration->bundleLocation != NULL ) { //(2): Yes

            if ( bundle_getBundleLocation(bundle, &bundleLocation) != CELIX_SUCCESS) {
                configuration_unlock(configuration);
                return CELIX_ILLEGAL_ARGUMENT;
            }

            // (3): bundle and configuration have the same location?
            if ( strcmp(configuration->bundleLocation, bundleLocation) == 0 ) { // (3): Yes
                // bind up configuration with bundle
                configuration->boundBundle = bundle;
//				printf("[ DEBUG ]: Configuration{PID=%s} - bind (bound with Bundle{%s}) \n",configuration->pid,bundleLocation);
            }
            // (3): No

        } else { // (2): No
            // bind up configuration with bundle
            configuration->boundBundle = bundle;
//			printf("[ DEBUG ]: Configuration{PID=%s}) - bind (not located and now bound with Bundle) \n",configuration->pid);
        }

    }// (1): Yes

    /* ------------ RETURN -------------- */

    bool bind;
    if(configuration->boundBundle == bundle) {
        bind = true;
    } else {
        bind = false;
    }

    /* ------------- END ----------------- */
    configuration_unlock(configuration);

    *isBind = bind;
//	printf("[ DEBUG ]: Configuration{PID=%s} - bind(END) \n",configuration->pid);
    return CELIX_SUCCESS;

}
Ejemplo n.º 4
0
celix_status_t configuration_getPool(configuration_impl_pt configuration, apr_pool_t **pool) {

    printf("[ DEBUG ]: Configuration{PID=%s} - get Pool \n",configuration->pid);

    configuration_lock(configuration);

    *pool = configuration->pool;

    configuration_unlock(configuration);

    return CELIX_SUCCESS;
}
Ejemplo n.º 5
0
celix_status_t configuration_update(void *handle, properties_pt properties) {

    configuration_impl_pt conf = (configuration_impl_pt)handle;


    celix_status_t status;

    // (1)
    configuration_lock(conf);

    // (2)
    if ( configuration_checkDeleted(conf) != CELIX_SUCCESS ) {
        configuration_unlock(conf);
        return CELIX_ILLEGAL_STATE;
    }
    // (3)
    configuration_updateDictionary(conf, properties);

    // (4)
    status = configurationStore_saveConfiguration(conf->configurationStore, conf->pid, conf->configuration_interface);
    if (status != CELIX_SUCCESS) {
        configuration_unlock(conf);
        return status;
    }

    // (5)
    bool isFactory;
    if (conf->factoryPid == NULL) {
        isFactory = false;
    } else {
        isFactory = true;
    }

    status = configurationAdminFactory_notifyConfigurationUpdated(conf->configurationAdminFactory, conf->configuration_interface, isFactory);
    if (status != CELIX_SUCCESS) {
        configuration_unlock(conf);
        return status;
    }

    // (6)
    status = configurationAdminFactory_dispatchEvent(conf->configurationAdminFactory, CONFIGURATION_EVENT_CM_UPDATED, conf->factoryPid, conf->pid);
    if (status != CELIX_SUCCESS) {
        configuration_unlock(conf);
        return status;
    }

    // (7)
    configuration_unlock(conf);
    return CELIX_SUCCESS;
}
Ejemplo n.º 6
0
static celix_status_t configuration_getPid2(configuration_impl_pt configuration, bool checkDeleted, char **pid) {

    configuration_lock(configuration);

    if ( checkDeleted ) {
        if ( configuration_checkDeleted(configuration) != CELIX_SUCCESS ) {
            configuration_unlock(configuration);
            return CELIX_ILLEGAL_STATE;
        }
    }

    *pid = configuration->pid;

    configuration_unlock(configuration);

    return CELIX_SUCCESS;
}
Ejemplo n.º 7
0
// org.eclipse.equinox.internal.cm modified to fit with org.apache.felix.cm.impl
// change due to ConfigurationStore implementation
celix_status_t configuration_getAllProperties(configuration_impl_pt configuration, properties_pt *properties) {

    celix_status_t status;

    properties_pt copy = NULL;

    // (1) configuration.lock
    configuration_lock(configuration);

    // (2) configuration.deleted ?
    if( configuration->deleted ) {
        *properties = NULL;
        configuration_unlock(configuration);
        return CELIX_SUCCESS;
    }

    // (3) configuration.getProps
    if( configuration_getProperties(configuration, &copy) != CELIX_SUCCESS) {
        configuration_unlock(configuration);
        return CELIX_ILLEGAL_ARGUMENT;
    }

    // (4) configuration.setProperties
    if ( copy == NULL ) { //set all the automatic properties

        copy = properties_create();
        status = configuration_setAutoProperties(configuration, &copy, true);

    } else { // copy != NULL - only set service.bundleLocation

        status = configuration_setBundleLocationProperty(configuration, &copy);

    }

    // (5) return
    if (status == CELIX_SUCCESS) {
        *properties = copy;
    } else {
        *properties = NULL;
    }

    configuration_unlock(configuration);
    return status;

}
Ejemplo n.º 8
0
celix_status_t configuration_setBundleLocation(void *handle, char *bundleLocation) {

    configuration_impl_pt	conf = (configuration_impl_pt)handle;
    configuration_lock(conf);

    if ( configuration_checkDeleted(conf) != CELIX_SUCCESS ) {
        configuration_unlock(conf);
        return CELIX_ILLEGAL_STATE;
    }

    //	TODO configurationAdminFactory.checkConfigurationPermission

    conf->bundleLocation = bundleLocation;
    conf->boundBundle = NULL; // always reset the boundBundle when setBundleLocation is called

    configuration_unlock(conf);

    return CELIX_SUCCESS;
}
Ejemplo n.º 9
0
celix_status_t configuration_setBundleLocationProperty(configuration_impl_pt configuration, properties_pt *properties) {

    char *bundleLocation;

    configuration_lock(configuration);

    if( configuration_getBundleLocation(configuration, &bundleLocation) != CELIX_SUCCESS ) {
        configuration_unlock(configuration);
        return CELIX_ILLEGAL_ARGUMENT;
    }

    if ( bundleLocation != NULL ) {
        properties_set(*properties, (char*)SERVICE_BUNDLELOCATION, bundleLocation);
    }

    configuration_unlock(configuration);

    return CELIX_SUCCESS;

}
Ejemplo n.º 10
0
celix_status_t configuration_getBundleLocation2(configuration_impl_pt configuration, bool checkPermission, char **location) {

    celix_status_t status;

    // (1)
    configuration_lock(configuration);

    // (2)
    if( configuration_checkDeleted(configuration) != CELIX_SUCCESS ) {
        configuration_unlock(configuration);
        return CELIX_ILLEGAL_STATE;
    }
    // (3)
    if ( checkPermission ) {

        if ( configurationAdminFactory_checkConfigurationPermission(configuration->configurationAdminFactory) != CELIX_SUCCESS ) {
            return CELIX_ILLEGAL_STATE; // TODO configurationAdmin, not yet implemented
        }
    }

    // (4)
    if ( configuration->bundleLocation ) {
        *location = configuration->bundleLocation;
        configuration_unlock(configuration);
        return CELIX_SUCCESS;
    }

    // (5)
    if ( configuration->boundBundle != NULL ) {
        status = bundle_getBundleLocation(configuration->boundBundle,location);
        configuration_unlock(configuration);
        return status;
    }

    // (6)
    *location = NULL;
    configuration_unlock(configuration);
    return CELIX_SUCCESS;
}
Ejemplo n.º 11
0
// org.eclipse.equinox.internal.cm.ManagedServiceTracker
celix_status_t managedServiceTracker_add(managed_service_tracker_pt tracker, service_reference_pt reference, char *pid, managed_service_service_pt service) {

    celix_status_t status;

    bundle_pt bundle = NULL;
    const char* bundleLocation;

    configuration_pt configuration = NULL;
    properties_pt properties = NULL;

    configurationStore_findConfiguration(tracker->configurationStore, pid, &configuration);

    if (configuration == NULL) {

        if (managedServiceTracker_trackManagedService(tracker, pid, reference, service) == CELIX_SUCCESS) {

            // TODO : this is new code, it hasn't been tested yet

            if (serviceReference_getBundle(reference, &bundle) != CELIX_SUCCESS) {
                return CELIX_ILLEGAL_ARGUMENT;
            }

            if (bundle_getBundleLocation(bundle, &bundleLocation) != CELIX_SUCCESS) {
                return CELIX_ILLEGAL_ARGUMENT;
            }

            // (1) creates a new Configuration for the ManagedService
            if (configurationStore_getConfiguration(tracker->configurationStore, pid, (char*)bundleLocation, &configuration) != CELIX_SUCCESS || configuration == NULL) {
                return CELIX_ILLEGAL_ARGUMENT;
            }

            // (2) bind the Configuration with the ManagedService
            bool dummy;
            if ((configuration_bind(configuration->handle, bundle, &dummy) != CELIX_SUCCESS)) {
                return CELIX_ILLEGAL_ARGUMENT;
            }

            // (3) the new Configuration is persisted and visible for other ConfigAdmin instances
            if (configurationStore_saveConfiguration(tracker->configurationStore, pid, configuration) != CELIX_SUCCESS) {
                return CELIX_ILLEGAL_STATE;
            }

            // End of new code

            // TODO: It must be considered in case of fail if untrack the ManagedService

            return managedServiceTracker_asynchUpdated(tracker, service, NULL);

        } else {
            return CELIX_ILLEGAL_ARGUMENT; // the service was already tracked
        }

    } else {

        configuration_lock(configuration->handle);

        if (managedServiceTracker_trackManagedService(tracker, pid, reference, service) == CELIX_SUCCESS) {

            if (serviceReference_getBundle(reference, &bundle) != CELIX_SUCCESS) {
                configuration_unlock(configuration->handle);
                printf("[ERROR ]: Tracker - Add (Service{PID=%s} Reference - getBundle NULL)", pid);
                return CELIX_ILLEGAL_ARGUMENT;
            }

            // TODO configuration.isDeleted ? - with only using one calling bundle OK

            bool isBind;
            if ((configuration_bind(configuration->handle, bundle, &isBind) == CELIX_SUCCESS) && (isBind == true)) { // config.bind(bundle)

                if (configuration_getProperties(configuration->handle, &properties) != CELIX_SUCCESS) {
                    configuration_unlock(configuration->handle);
                    return CELIX_ILLEGAL_ARGUMENT;
                }

                if (configurationAdminFactory_modifyConfiguration(tracker->configurationAdminfactory, reference, properties) != CELIX_SUCCESS) {
                    configuration_unlock(configuration->handle);
                    return CELIX_ILLEGAL_ARGUMENT;
                }

                status = managedServiceTracker_asynchUpdated(tracker, service, properties);

                configuration_unlock(configuration->handle);

                return status;

            } else {
                configuration_unlock(configuration->handle);
                return CELIX_ILLEGAL_STATE;
            }

        } else {
            configuration_unlock(configuration->handle);
            return CELIX_ILLEGAL_ARGUMENT; // the service was already tracked
        }
    }
}