Example #1
0
int producer_getSampleRate(void* handle) {
    producer_pt producer = (producer_pt) handle;
    int sampleRate = 0;

    pthread_rwlock_rdlock(&producer->queueLock);

    hash_map_iterator_pt iter = hashMapIterator_create(producer->queueServices);

    while (hashMapIterator_hasNext(iter)) {
        producer_thread_data_pt th_data = (producer_thread_data_pt) hashMapIterator_nextValue(iter);

        pthread_rwlock_rdlock(&th_data->sampleRateLock);
        sampleRate += th_data->single_throughput; // + value->burst_throughput
        pthread_rwlock_unlock(&th_data->sampleRateLock);
    }

    hashMapIterator_destroy(iter);

    if (hashMap_size(producer->queueServices) > 0) {
        sampleRate /= hashMap_size(producer->queueServices);
    }

    pthread_rwlock_unlock(&producer->queueLock);

    return sampleRate;
}
Example #2
0
int producer_getUtilizationStatsValue(producer_pt producer, double* statVal) {

    double total_average = 0;

    pthread_rwlock_rdlock(&producer->queueLock);

    hash_map_iterator_pt iter = hashMapIterator_create(producer->queueServices);

    while (hashMapIterator_hasNext(iter)) {

        hash_map_entry_pt entry = hashMapIterator_nextEntry(iter);

        if (entry != NULL) {
            producer_thread_data_pt value = (producer_thread_data_pt) hashMapEntry_getValue(entry);
            if (value != NULL) {
                total_average += (double) (((double) (value->single_throughput + value->burst_throughput)) / ((double) 2.0f));
            }
        }
    }

    hashMapIterator_destroy(iter);

    if (hashMap_size(producer->queueServices) > 0) {
        total_average /= hashMap_size(producer->queueServices);
    }

    pthread_rwlock_unlock(&producer->queueLock);

    (*statVal) = total_average;
    return (int) CELIX_SUCCESS;
}
Example #3
0
celix_status_t eventAdmin_event_equals( event_pt *event, event_pt *compare, bool *result){
	celix_status_t status = CELIX_SUCCESS;
	if(event == compare){
		(*result) = true;
	}else {
		int sizeofEvent = hashMap_size((*event)->properties);
		int sizeofCompare = hashMap_size((*compare)->properties);
		if(sizeofEvent == sizeofCompare){
			(*result) = true;
		}else {

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

    if (wEndpointDescription == NULL) {
        status = CELIX_ILLEGAL_ARGUMENT;
    } else {
        celixThreadMutex_lock(&admin->exportedWiringEndpointLock);
        service_tracker_pt wiringReceiveTracker = NULL;

        wiringReceiveTracker = hashMap_remove(admin->wiringReceiveTracker, wEndpointDescription);

        if (wiringReceiveTracker != NULL) {
            if (serviceTracker_close(wiringReceiveTracker) == CELIX_SUCCESS) {
                serviceTracker_destroy(wiringReceiveTracker);
            }

            if (hashMap_size(admin->wiringReceiveTracker) == 0) {
                wiringAdmin_stopWebserver(admin);
            }
        }

        wiringEndpointDescription_destroy(&wEndpointDescription);

        celixThreadMutex_unlock(&admin->exportedWiringEndpointLock);
    }

    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;
}
Example #6
0
celix_status_t eventAdmin_getPropertyNames( event_pt *event, array_list_pt *names){
	celix_status_t status = CELIX_SUCCESS;
	properties_pt properties =  (*event)->properties;
	if (hashMap_size(properties) > 0) {
		hash_map_iterator_pt iterator = hashMapIterator_create(properties);
		while (hashMapIterator_hasNext(iterator)) {
			hash_map_entry_pt entry = hashMapIterator_nextEntry(iterator);
			char * key =hashMapEntry_getKey(entry);
			arrayList_add((*names),key);
		}
	}
	return status;
}
Example #7
0
/**
 * Header is ignored for now, cannot handle comments yet
 */
void properties_store(properties_pt properties, char * filename, char * header) {
	FILE *file = fopen ( filename, "w+" );
	int i;
	char *str;

	if (file != NULL) {
		if (hashMap_size(properties) > 0) {
			hash_map_iterator_pt iterator = hashMapIterator_create(properties);
			while (hashMapIterator_hasNext(iterator)) {
				hash_map_entry_pt entry = hashMapIterator_nextEntry(iterator);
				str = hashMapEntry_getKey(entry);
				for (int i = 0; i < strlen(str); i += 1) {
					if (str[i] == '#' || str[i] == '!' || str[i] == '=' || str[i] == ':') {
						fputc('\\', file);
					}
					fputc(str[i], file);
				}

				fputc('=', file);

				str = hashMapEntry_getValue(entry);
				for (int i = 0; i < strlen(str); i += 1) {
					if (str[i] == '#' || str[i] == '!' || str[i] == '=' || str[i] == ':') {
						fputc('\\', file);
					}
					fputc(str[i], file);
				}

				fputc('\n', file);

			}
			hashMapIterator_destroy(iterator);
		}
		fclose(file);
	} else {
		perror("File is null");
	}
}
Example #8
0
celix_status_t managedServiceTracker_notifyUpdated(managed_service_tracker_pt tracker, configuration_pt configuration) {


    char *pid;

    service_reference_pt reference = NULL;
    bundle_pt bundle = NULL;
    properties_pt properties = NULL;

    managed_service_service_pt service = NULL;

    // (1) config.checkLocked
    if (configuration_checkLocked(configuration->handle) != CELIX_SUCCESS) { //TODO not yet implemented
        return CELIX_ILLEGAL_ARGUMENT;
    }

    // (2) config.getPid
    if (configuration_getPid(configuration->handle, &pid) != CELIX_SUCCESS) {
        return CELIX_ILLEGAL_ARGUMENT;
    }

    // (3) reference = getManagedServiceReference(pid)
    if (managedServiceTracker_getManagedServiceReference(tracker, pid, &reference) != CELIX_SUCCESS || reference == NULL) {
        printf("[ ERROR ]: Tracker - Notify (NULL Reference Service{PID=%s}) \n", pid);
        return CELIX_ILLEGAL_ARGUMENT; // Eclipse ignores, but according to Specs, callback is delayed
    }

    //  (4.1) reference.getBundle
    if (serviceReference_getBundle(reference, &bundle) != CELIX_SUCCESS || bundle == NULL) {
        printf("[ ERROR ]: Tracker - Notify (NULL Bundle Service{PID=%s}) \n", pid);
        return CELIX_ILLEGAL_ARGUMENT;
    }

    //	(4.2) config.bind(reference.getBundle)
    bool isBind;
    if (configuration_bind(configuration->handle, bundle, &isBind) != CELIX_SUCCESS || isBind == false) {
        printf("[ ERROR ]: Tracker - Notify (Service{PID=%s} Permission Error) \n", pid);
        return CELIX_ILLEGAL_STATE;
    }

    // (5) if (reference != null && config.bind(reference.getBundle()))

    // (5.1) properties = config.getProperties
    if (configuration_getProperties(configuration->handle, &properties) != CELIX_SUCCESS) {
        printf("[ ERROR ]: Tracker - Notify (Service{PID=%s} Wrong Properties) \n", pid);
        return CELIX_ILLEGAL_ARGUMENT;
    }

    // (5.2) modifyConfiguration
    if (configurationAdminFactory_modifyConfiguration(tracker->configurationAdminfactory, reference, properties) != CELIX_SUCCESS) {
        return CELIX_ILLEGAL_ARGUMENT; //TODO no yet implemented modifyConfiguration
    }

    // (5.3) service = getManagedService(pid)
    if (managedServiceTracker_getManagedService(tracker, pid, &service) != CELIX_SUCCESS) {
        printf("[ ERROR ]: Tracker - Notify (NULL Service{PID=%s}) \n", pid);
        return CELIX_ILLEGAL_ARGUMENT;
    }

    // (5.4) asynchUpdate(service,properties)
    if ((properties == NULL) || (properties != NULL && hashMap_size(properties) == 0)) {
        return managedServiceTracker_asynchUpdated(tracker, service, NULL);
    } else {
        return managedServiceTracker_asynchUpdated(tracker, service, properties);
    }
    return CELIX_ILLEGAL_ARGUMENT;
}
static int wiringAdmin_callback(struct mg_connection *conn) {
    int result = 0; // zero means: let civetweb handle it further, any non-zero value means it is handled by us...

    const struct mg_request_info *request_info = mg_get_request_info(conn);

    if (request_info->uri != NULL) {
        wiring_admin_pt admin = request_info->user_data;

        if (hashMap_size(admin->wiringReceiveServices) == 0) {
            printf("%s: No wiringReceiveServices available\n", TAG);
        }

        if (strcmp("POST", request_info->request_method) == 0) {

            celixThreadMutex_lock(&admin->exportedWiringEndpointLock);

            uint64_t datalength = request_info->content_length;
            char* data = malloc(datalength + 1);
            mg_read(conn, data, datalength);
            data[datalength] = '\0';

            char *response = NULL;

            hash_map_iterator_pt iter = hashMapIterator_create(admin->wiringReceiveServices);
            while (hashMapIterator_hasNext(iter)) {
                array_list_pt wiringReceiveServiceList = hashMapIterator_nextValue(iter);

                if (arrayList_size(wiringReceiveServiceList) > 0) {
                    //		printf("WIRING_ADMIN: size of wiringReceiveServiceList is %d\n", arrayList_size(wiringReceiveServiceList));
                    // TODO: we do not support mulitple wiringReceivers?
                    wiring_receive_service_pt wiringReceiveService = (wiring_receive_service_pt) arrayList_get(wiringReceiveServiceList, 0);
                    if (wiringReceiveService->receive(wiringReceiveService->handle, data, &response) != CELIX_SUCCESS) {
                        response = NULL;
                    }

                    break;
                } else {
                    printf("%s: wiringReceiveServiceList is empty\n", TAG);
                }
            }
            hashMapIterator_destroy(iter);

            if (response != NULL) {
                mg_write(conn, data_response_headers, strlen(data_response_headers));
                mg_write(conn, response, strlen(response));

                free(response);
            } else {
                mg_write(conn, no_content_response_headers, strlen(no_content_response_headers));
            }
            result = 1;

            free(data);
        } else {
            printf("%s: Received HTTP Request, but no RSA_Inaetics callback is installed. Discarding request.\n", TAG);
        }

        celixThreadMutex_unlock(&admin->exportedWiringEndpointLock);
    } else {
        printf("%s: Received URI is NULL\n", TAG);
    }

    return result;
}