celix_status_t wiringTopologyManager_waRemoved(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; /* check whether one of the exported Wires can be exported here via the newly available wiringAdmin*/ celixThreadMutex_lock(&manager->exportedWiringEndpointsLock); hash_map_iterator_pt iter = hashMapIterator_create(manager->exportedWiringEndpoints); while (hashMapIterator_hasNext(iter)) { hash_map_entry_pt entry = hashMapIterator_nextEntry(iter); hash_map_pt wiringAdminMap = hashMapEntry_getValue(entry); if (hashMap_containsKey(wiringAdminMap, wiringAdminService)) { wiring_endpoint_description_pt wEndpoint = (wiring_endpoint_description_pt) hashMap_remove(wiringAdminMap, wiringAdminService); status = wiringTopologyManager_notifyListenersWiringEndpointRemoved(manager, wEndpoint); if (status == CELIX_SUCCESS) { status = wiringAdminService->removeExportedWiringEndpoint(wiringAdminService->admin, wEndpoint); } else { printf("WTM: failed while removing WiringAdmin.\n"); } } } hashMapIterator_destroy(iter); 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 importedWiringEndpointDesc = hashMapEntry_getKey(entry); array_list_pt wiringAdminList = hashMapEntry_getValue(entry); if (arrayList_contains(wiringAdminList, wiringAdminService)) { status = wiringAdminService->removeImportedWiringEndpoint(wiringAdminService->admin, importedWiringEndpointDesc); arrayList_removeElement(wiringAdminList, wiringAdminService); } if (status == CELIX_SUCCESS) { arrayList_add(wiringAdminList, wiringAdminService); } } hashMapIterator_destroy(iter); celixThreadMutex_unlock(&manager->importedWiringEndpointsLock); celixThreadMutex_lock(&manager->waListLock); arrayList_removeElement(manager->waList, wiringAdminService); celixThreadMutex_unlock(&manager->waListLock); printf("WTM: Removed WA\n"); return status; }
static void *endpointDiscoveryPoller_performPeriodicPoll(void *data) { endpoint_discovery_poller_pt poller = (endpoint_discovery_poller_pt) data; useconds_t interval = (useconds_t) (poller->poll_interval * 1000000L); while (poller->running) { usleep(interval); celix_status_t status = celixThreadMutex_lock(&poller->pollerLock); if (status != CELIX_SUCCESS) { logHelper_log(*poller->loghelper, OSGI_LOGSERVICE_WARNING, "ENDPOINT_POLLER: failed to obtain lock; retrying..."); } else { hash_map_iterator_pt iterator = hashMapIterator_create(poller->entries); while (hashMapIterator_hasNext(iterator)) { hash_map_entry_pt entry = hashMapIterator_nextEntry(iterator); char *url = hashMapEntry_getKey(entry); array_list_pt currentEndpoints = hashMapEntry_getValue(entry); endpointDiscoveryPoller_poll(poller, url, currentEndpoints); } hashMapIterator_destroy(iterator); } status = celixThreadMutex_unlock(&poller->pollerLock); if (status != CELIX_SUCCESS) { logHelper_log(*poller->loghelper, OSGI_LOGSERVICE_WARNING, "ENDPOINT_POLLER: failed to release lock; retrying..."); } } return NULL; }
/** * Destroys and frees up memory for a given endpoint_discovery_poller struct. */ celix_status_t endpointDiscoveryPoller_destroy(endpoint_discovery_poller_pt poller) { celix_status_t status; poller->running = false; celixThread_join(poller->pollerThread, NULL); hash_map_iterator_pt iterator = hashMapIterator_create(poller->entries); while (hashMapIterator_hasNext(iterator)) { hash_map_entry_pt entry = hashMapIterator_nextEntry(iterator); if ( endpointDiscoveryPoller_removeDiscoveryEndpoint(poller, (char*) hashMapEntry_getKey(entry)) == CELIX_SUCCESS) { hashMapIterator_destroy(iterator); iterator = hashMapIterator_create(poller->entries); } } hashMapIterator_destroy(iterator); status = celixThreadMutex_lock(&poller->pollerLock); if (status != CELIX_SUCCESS) { return CELIX_BUNDLE_EXCEPTION; } hashMap_destroy(poller->entries, true, false); status = celixThreadMutex_unlock(&poller->pollerLock); poller->loghelper = NULL; free(poller); return status; }
celix_status_t shell_getCommandReference(shell_pt shell_ptr, char *command_name_str, service_reference_pt *command_reference_ptr) { celix_status_t status = CELIX_SUCCESS; if (!shell_ptr || !command_name_str || !command_reference_ptr) { status = CELIX_ILLEGAL_ARGUMENT; } if (status == CELIX_SUCCESS) { *command_reference_ptr = NULL; hash_map_iterator_pt iter = hashMapIterator_create(shell_ptr->command_reference_map_ptr); while (hashMapIterator_hasNext(iter)) { hash_map_entry_pt entry = hashMapIterator_nextEntry(iter); service_reference_pt reference = hashMapEntry_getKey(entry); char *name_str = NULL; serviceReference_getProperty(reference, "command.name", &name_str); if (strcmp(name_str, command_name_str) == 0) { *command_reference_ptr = (service_reference_pt) hashMapEntry_getKey(entry); break; } } hashMapIterator_destroy(iter); } return status; }
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; }
array_list_pt serviceRegistry_getUsingBundles(service_registry_pt registry, service_reference_pt reference) { array_list_pt bundles = NULL; hash_map_iterator_pt iter; arrayList_create(&bundles); celixThreadMutex_lock(®istry->mutex); iter = hashMapIterator_create(registry->inUseMap); while (hashMapIterator_hasNext(iter)) { hash_map_entry_pt entry = hashMapIterator_nextEntry(iter); bundle_pt bundle = hashMapEntry_getKey(entry); array_list_pt usages = hashMapEntry_getValue(entry); unsigned int i; for (i = 0; i < arrayList_size(usages); i++) { usage_count_pt usage = arrayList_get(usages, i); bool equals = false; serviceReference_equals(usage->reference, reference, &equals); if (equals) { arrayList_add(bundles, bundle); } } } hashMapIterator_destroy(iter); celixThreadMutex_unlock(®istry->mutex); return bundles; }
void properties_destroy(properties_pt properties) { hash_map_iterator_pt iter = hashMapIterator_create(properties); while (hashMapIterator_hasNext(iter)) { hash_map_entry_pt entry = hashMapIterator_nextEntry(iter); free(hashMapEntry_getKey(entry)); free(hashMapEntry_getValue(entry)); } hashMapIterator_destroy(iter); hashMap_destroy(properties, false, false); }
static void process_msg(topic_subscription_pt sub,pubsub_udp_msg_t *msg){ celixThreadMutex_lock(&sub->ts_lock); hash_map_iterator_pt iter = hashMapIterator_create(sub->servicesMap); while (hashMapIterator_hasNext(iter)) { hash_map_entry_pt entry = hashMapIterator_nextEntry(iter); pubsub_subscriber_pt subsvc = hashMapEntry_getKey(entry); hash_map_pt msgTypes = hashMapEntry_getValue(entry); pubsub_msg_serializer_t *msgSer = hashMap_get(msgTypes,(void*)(uintptr_t )msg->header.type); if (msgSer == NULL) { printf("PSA_UDP_MC_TS: Serializer not available for message %d.\n",msg->header.type); } else{ void *msgInst = NULL; bool validVersion = checkVersion(msgSer->msgVersion,&msg->header); if(validVersion){ celix_status_t status = msgSer->deserialize(msgSer, (const void *) msg->payload, 0, &msgInst); if (status == CELIX_SUCCESS) { bool release = true; pubsub_multipart_callbacks_t mp_callbacks; mp_callbacks.handle = sub; mp_callbacks.localMsgTypeIdForMsgType = pubsub_localMsgTypeIdForMsgType; mp_callbacks.getMultipart = NULL; subsvc->receive(subsvc->handle, msgSer->msgName, msg->header.type, msgInst, &mp_callbacks, &release); if(release){ msgSer->freeMsg(msgSer,msgInst); } } else{ printf("PSA_UDP_MC_TS: Cannot deserialize msgType %s.\n",msgSer->msgName); } } else{ int major=0,minor=0; version_getMajor(msgSer->msgVersion,&major); version_getMinor(msgSer->msgVersion,&minor); printf("PSA_UDP_MC_TS: Version mismatch for primary message '%s' (have %d.%d, received %u.%u). NOT sending any part of the whole message.\n", msgSer->msgName,major,minor,msg->header.major,msg->header.minor); } } } hashMapIterator_destroy(iter); celixThreadMutex_unlock(&sub->ts_lock); }
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; }
static void importRegistration_clearProxies(import_registration_pt import) { if (import != NULL) { pthread_mutex_lock(&import->proxiesMutex); if (import->proxies != NULL) { hash_map_iterator_pt iter = hashMapIterator_create(import->proxies); while (hashMapIterator_hasNext(iter)) { hash_map_entry_pt entry = hashMapIterator_nextEntry(iter); struct service_proxy *proxy = hashMapEntry_getValue(entry); importRegistration_destroyProxy(proxy); } hashMapIterator_destroy(iter); } pthread_mutex_unlock(&import->proxiesMutex); } }
static celix_status_t remoteProxyFactory_registerProxyService(remote_proxy_factory_pt remote_proxy_factory_ptr, endpoint_description_pt endpointDescription, remote_service_admin_pt 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 = properties_create(); if (!proxy_instance_ptr->properties) { status = CELIX_BUNDLE_EXCEPTION; } } 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) { 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); properties_set(proxy_instance_ptr->properties, key, value); } } 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); } return status; }
celix_status_t endpointDiscoveryPoller_getDiscoveryEndpoints(endpoint_discovery_poller_pt poller, array_list_pt urls) { celixThreadMutex_lock(&(poller)->pollerLock); hash_map_iterator_pt iterator = hashMapIterator_create(poller->entries); while(hashMapIterator_hasNext(iterator)) { hash_map_entry_pt entry = hashMapIterator_nextEntry(iterator); char* toAdd = strdup((char*) hashMapEntry_getKey(entry)); arrayList_add(urls, toAdd); } hashMapIterator_destroy(iterator); celixThreadMutex_unlock(&(poller)->pollerLock); return CELIX_SUCCESS; }
celix_status_t statistic_tracker_statServiceRemoved(void *handle, service_reference_pt reference, void *service) { celix_status_t status = CELIX_BUNDLE_EXCEPTION; statistic_tracker_pt statTracker = (statistic_tracker_pt) handle; pthread_t* thread_pt = NULL; pthread_rwlock_wrlock(&statTracker->statLock); hash_map_iterator_pt iter = hashMapIterator_create(statTracker->statServices); while (hashMapIterator_hasNext(iter) && thread_pt == NULL) { hash_map_entry_pt entry = hashMapIterator_nextEntry(iter); if (service == hashMapEntry_getValue(entry)) { struct stats_provider_service* statService = (struct stats_provider_service*) service; char* name = NULL; statService->getName(statService->statsProvider, &name); thread_pt = hashMapEntry_getKey(entry); msg(1, "STAT_TRACKER: Service %s Removed. ", name); hashMap_remove(statTracker->statServices, thread_pt); } } hashMapIterator_destroy(iter); pthread_rwlock_unlock(&statTracker->statLock); if (thread_pt != NULL) { pthread_join(*thread_pt, NULL); msg(1, "STAT_TRACKER: Service Removed. Thread %lu stopped.", (unsigned long) *thread_pt); free(thread_pt); status = CELIX_SUCCESS; } return status; }
/** * 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"); } }
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; }
static celix_status_t endpointDescriptorWriter_writeEndpoint(endpoint_descriptor_writer_pt writer, endpoint_description_pt endpoint) { celix_status_t status = CELIX_SUCCESS; if (endpoint == NULL || writer == NULL) { status = CELIX_ILLEGAL_ARGUMENT; } else { xmlTextWriterStartElement(writer->writer, ENDPOINT_DESCRIPTION); hash_map_iterator_pt iter = hashMapIterator_create(endpoint->properties); while (hashMapIterator_hasNext(iter)) { hash_map_entry_pt entry = hashMapIterator_nextEntry(iter); void* propertyName = hashMapEntry_getKey(entry); const xmlChar* propertyValue = (const xmlChar*) hashMapEntry_getValue(entry); xmlTextWriterStartElement(writer->writer, PROPERTY); xmlTextWriterWriteAttribute(writer->writer, NAME, propertyName); if (strcmp(OSGI_FRAMEWORK_OBJECTCLASS, (char*) propertyName) == 0) { // objectClass *must* be represented as array of string values... endpointDescriptorWriter_writeArrayValue(writer->writer, propertyValue); } else if (strcmp(OSGI_RSA_ENDPOINT_SERVICE_ID, (char*) propertyName) == 0) { // endpoint.service.id *must* be represented as long value... endpointDescriptorWriter_writeTypedValue(writer->writer, VALUE_TYPE_LONG, propertyValue); } else { // represent all other values as plain string values... endpointDescriptorWriter_writeUntypedValue(writer->writer, propertyValue); } xmlTextWriterEndElement(writer->writer); } hashMapIterator_destroy(iter); xmlTextWriterEndElement(writer->writer); } return status; }
celix_status_t discovery_stop(discovery_pt discovery) { celix_status_t status; status = etcdWatcher_destroy(discovery->watcher); if (status != CELIX_SUCCESS) { return CELIX_BUNDLE_EXCEPTION; } status = endpointDiscoveryServer_destroy(discovery->server); if (status != CELIX_SUCCESS) { return CELIX_BUNDLE_EXCEPTION; } status = endpointDiscoveryPoller_destroy(discovery->poller); if (status != CELIX_SUCCESS) { return CELIX_BUNDLE_EXCEPTION; } hash_map_iterator_pt iter; celixThreadMutex_lock(&discovery->discoveredServicesMutex); iter = hashMapIterator_create(discovery->discoveredServices); while (hashMapIterator_hasNext(iter)) { hash_map_entry_pt entry = hashMapIterator_nextEntry(iter); endpoint_description_pt endpoint = hashMapEntry_getValue(entry); discovery_informEndpointListeners(discovery, endpoint, false); } hashMapIterator_destroy(iter); celixThreadMutex_unlock(&discovery->discoveredServicesMutex); logHelper_stop(discovery->loghelper); return status; }
celix_status_t pubsub_topicSubscriptionStop(topic_subscription_pt ts){ celix_status_t status = CELIX_SUCCESS; struct epoll_event ev; memset(&ev, 0, sizeof(ev)); ts->running = false; pthread_kill(ts->recv_thread.thread,SIGUSR1); celixThread_join(ts->recv_thread,NULL); status = serviceTracker_close(ts->tracker); celixThreadMutex_lock(&ts->socketMap_lock); hash_map_iterator_pt it = hashMapIterator_create(ts->socketMap); while(hashMapIterator_hasNext(it)) { hash_map_entry_pt entry = hashMapIterator_nextEntry(it); char *url = hashMapEntry_getKey(entry); int *s = hashMapEntry_getValue(entry); memset(&ev, 0, sizeof(ev)); if(epoll_ctl(ts->topicEpollFd, EPOLL_CTL_DEL, *s, &ev) == -1) { printf("in if error()\n"); perror("epoll_ctl() EPOLL_CTL_DEL"); status += CELIX_SERVICE_EXCEPTION; } free(s); free(url); //hashMapIterator_remove(it); } hashMapIterator_destroy(it); hashMap_clear(ts->socketMap, false, false); celixThreadMutex_unlock(&ts->socketMap_lock); return status; }
static int remoteServiceAdmin_callback(struct mg_connection *conn) { int result = 1; // 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) { remote_service_admin_pt rsa = request_info->user_data; if (strncmp(request_info->uri, "/service/", 9) == 0 && strcmp("POST", request_info->request_method) == 0) { // uri = /services/myservice/call const char *uri = request_info->uri; // rest = myservice/call const char *rest = uri+9; char *interfaceStart = strchr(rest, '/'); int pos = interfaceStart - rest; char service[pos+1]; strncpy(service, rest, pos); service[pos] = '\0'; long serviceId = atol(service); celixThreadMutex_lock(&rsa->exportedServicesLock); //find endpoint export_registration_pt export = NULL; hash_map_iterator_pt iter = hashMapIterator_create(rsa->exportedServices); while (hashMapIterator_hasNext(iter)) { hash_map_entry_pt entry = hashMapIterator_nextEntry(iter); array_list_pt exports = hashMapEntry_getValue(entry); int expIt = 0; for (expIt = 0; expIt < arrayList_size(exports); expIt++) { export_registration_pt check = arrayList_get(exports, expIt); export_reference_pt ref = NULL; exportRegistration_getExportReference(check, &ref); endpoint_description_pt checkEndpoint = NULL; exportReference_getExportedEndpoint(ref, &checkEndpoint); if (serviceId == checkEndpoint->serviceId) { export = check; free(ref); break; } free(ref); } } hashMapIterator_destroy(iter); if (export != NULL) { uint64_t datalength = request_info->content_length; char* data = malloc(datalength + 1); mg_read(conn, data, datalength); data[datalength] = '\0'; char *response = NULL; int responceLength = 0; int rc = exportRegistration_call(export, data, -1, &response, &responceLength); if (rc != CELIX_SUCCESS) { RSA_LOG_ERROR(rsa, "Error trying to invoke remove service, got error %i\n", rc); } if (rc == CELIX_SUCCESS && 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 {
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, ®istration); 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; }
celix_status_t pubsubAdmin_destroy(pubsub_admin_pt admin) { celix_status_t status = CELIX_SUCCESS; free(admin->ipAddress); celixThreadMutex_lock(&admin->pendingSubscriptionsLock); hash_map_iterator_pt iter = hashMapIterator_create(admin->pendingSubscriptions); while(hashMapIterator_hasNext(iter)){ hash_map_entry_pt entry = hashMapIterator_nextEntry(iter); free((char*)hashMapEntry_getKey(entry)); arrayList_destroy((array_list_pt)hashMapEntry_getValue(entry)); } hashMapIterator_destroy(iter); hashMap_destroy(admin->pendingSubscriptions,false,false); celixThreadMutex_unlock(&admin->pendingSubscriptionsLock); celixThreadMutex_lock(&admin->subscriptionsLock); hashMap_destroy(admin->subscriptions,false,false); celixThreadMutex_unlock(&admin->subscriptionsLock); celixThreadMutex_lock(&admin->localPublicationsLock); hashMap_destroy(admin->localPublications,true,false); celixThreadMutex_unlock(&admin->localPublicationsLock); celixThreadMutex_lock(&admin->externalPublicationsLock); iter = hashMapIterator_create(admin->externalPublications); while(hashMapIterator_hasNext(iter)){ hash_map_entry_pt entry = hashMapIterator_nextEntry(iter); free((char*)hashMapEntry_getKey(entry)); arrayList_destroy((array_list_pt)hashMapEntry_getValue(entry)); } hashMapIterator_destroy(iter); hashMap_destroy(admin->externalPublications,false,false); celixThreadMutex_unlock(&admin->externalPublicationsLock); celixThreadMutex_lock(&admin->serializerListLock); arrayList_destroy(admin->serializerList); celixThreadMutex_unlock(&admin->serializerListLock); celixThreadMutex_lock(&admin->noSerializerPendingsLock); arrayList_destroy(admin->noSerializerSubscriptions); arrayList_destroy(admin->noSerializerPublications); celixThreadMutex_unlock(&admin->noSerializerPendingsLock); celixThreadMutex_lock(&admin->usedSerializersLock); iter = hashMapIterator_create(admin->topicSubscriptionsPerSerializer); while(hashMapIterator_hasNext(iter)){ arrayList_destroy((array_list_pt)hashMapIterator_nextValue(iter)); } hashMapIterator_destroy(iter); hashMap_destroy(admin->topicSubscriptionsPerSerializer,false,false); iter = hashMapIterator_create(admin->topicPublicationsPerSerializer); while(hashMapIterator_hasNext(iter)){ arrayList_destroy((array_list_pt)hashMapIterator_nextValue(iter)); } hashMapIterator_destroy(iter); hashMap_destroy(admin->topicPublicationsPerSerializer,false,false); celixThreadMutex_unlock(&admin->usedSerializersLock); celixThreadMutex_destroy(&admin->usedSerializersLock); celixThreadMutex_destroy(&admin->serializerListLock); celixThreadMutex_destroy(&admin->pendingSubscriptionsLock); celixThreadMutexAttr_destroy(&admin->noSerializerPendingsAttr); celixThreadMutex_destroy(&admin->noSerializerPendingsLock); celixThreadMutexAttr_destroy(&admin->pendingSubscriptionsAttr); celixThreadMutex_destroy(&admin->subscriptionsLock); celixThreadMutex_destroy(&admin->localPublicationsLock); celixThreadMutex_destroy(&admin->externalPublicationsLock); logHelper_stop(admin->loghelper); logHelper_destroy(&admin->loghelper); #ifdef BUILD_WITH_ZMQ_SECURITY if (admin->zmq_auth != NULL){ zactor_destroy(&(admin->zmq_auth)); } #endif free(admin); return status; }
celix_status_t driverMatcher_getBestMatchInternal(driver_matcher_pt matcher, 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) { char *rank1Str, *rank2Str; int rank1, rank2; rank1Str = "0"; rank2Str = "0"; logHelper_log(matcher->loghelper, OSGI_LOGSERVICE_DEBUG, "DRIVER_MATCHER: Compare ranking"); serviceReference_getProperty(reference, (char *) OSGI_FRAMEWORK_SERVICE_RANKING, &rank1Str); serviceReference_getProperty(reference, (char *) OSGI_FRAMEWORK_SERVICE_RANKING, &rank2Str); rank1 = atoi(rank1Str); rank2 = atoi(rank2Str); if (rank1 != rank2) { if (rank1 > rank2) { best = reference; } } else { char *id1Str, *id2Str; long id1, id2; id1Str = NULL; id2Str = NULL; logHelper_log(matcher->loghelper, OSGI_LOGSERVICE_DEBUG, "DRIVER_MATCHER: Compare id's"); serviceReference_getProperty(reference, (char *) OSGI_FRAMEWORK_SERVICE_ID, &id1Str); serviceReference_getProperty(reference, (char *) OSGI_FRAMEWORK_SERVICE_ID, &id2Str); id1 = atol(id1Str); id2 = atol(id2Str); if (id1 < id2) { best = reference; } } } else { best = reference; } } } *match = calloc(1, sizeof(**match)); if (!*match) { status = CELIX_ENOMEM; } else { (*match)->matchValue = matchKey->matchValue; (*match)->reference = best; } } return status; }
celix_status_t pubsubAdmin_serializerRemoved(void * handle, service_reference_pt reference, void * service){ pubsub_admin_pt admin = (pubsub_admin_pt)handle; int i=0, j=0; const char *serType = NULL; serviceReference_getProperty(reference, PUBSUB_SERIALIZER_TYPE_KEY,&serType); if(serType == NULL){ printf("Serializer serviceReference %p has no pubsub_serializer.type property specified\n",reference); return CELIX_SERVICE_EXCEPTION; } celixThreadMutex_lock(&admin->serializerListLock); /* Remove the serializer from the list */ arrayList_removeElement(admin->serializerList, reference); celixThreadMutex_unlock(&admin->serializerListLock); celixThreadMutex_lock(&admin->usedSerializersLock); array_list_pt topicPubList = (array_list_pt)hashMap_remove(admin->topicPublicationsPerSerializer, service); array_list_pt topicSubList = (array_list_pt)hashMap_remove(admin->topicSubscriptionsPerSerializer, service); celixThreadMutex_unlock(&admin->usedSerializersLock); /* Now destroy the topicPublications, but first put back the pubsub_endpoints back to the noSerializer pending list */ if(topicPubList!=NULL){ for(i=0;i<arrayList_size(topicPubList);i++){ topic_publication_pt topicPub = (topic_publication_pt)arrayList_get(topicPubList,i); /* Stop the topic publication */ pubsub_topicPublicationStop(topicPub); /* Get the endpoints that are going to be orphan */ array_list_pt pubList = pubsub_topicPublicationGetPublisherList(topicPub); for(j=0;j<arrayList_size(pubList);j++){ pubsub_endpoint_pt pubEP = (pubsub_endpoint_pt)arrayList_get(pubList,j); /* Remove the publication */ pubsubAdmin_removePublication(admin, pubEP); /* Reset the endpoint field, so that will be recreated from scratch when a new serializer will be found */ if(pubEP->endpoint!=NULL){ free(pubEP->endpoint); pubEP->endpoint = NULL; } /* Add the orphan endpoint to the noSerializer pending list */ celixThreadMutex_lock(&admin->noSerializerPendingsLock); arrayList_add(admin->noSerializerPublications,pubEP); celixThreadMutex_unlock(&admin->noSerializerPendingsLock); } arrayList_destroy(pubList); /* Cleanup also the localPublications hashmap*/ celixThreadMutex_lock(&admin->localPublicationsLock); hash_map_iterator_pt iter = hashMapIterator_create(admin->localPublications); char *key = NULL; service_factory_pt factory = NULL; while(hashMapIterator_hasNext(iter)){ hash_map_entry_pt entry = hashMapIterator_nextEntry(iter); factory = (service_factory_pt)hashMapEntry_getValue(entry); topic_publication_pt pub = (topic_publication_pt)factory->handle; if(pub==topicPub){ key = (char*)hashMapEntry_getKey(entry); break; } } hashMapIterator_destroy(iter); if(key!=NULL){ hashMap_remove(admin->localPublications, key); free(factory); free(key); } celixThreadMutex_unlock(&admin->localPublicationsLock); /* Finally destroy the topicPublication */ pubsub_topicPublicationDestroy(topicPub); } arrayList_destroy(topicPubList); } /* Now destroy the topicSubscriptions, but first put back the pubsub_endpoints back to the noSerializer pending list */ if(topicSubList!=NULL){ for(i=0;i<arrayList_size(topicSubList);i++){ topic_subscription_pt topicSub = (topic_subscription_pt)arrayList_get(topicSubList,i); /* Stop the topic subscription */ pubsub_topicSubscriptionStop(topicSub); /* Get the endpoints that are going to be orphan */ array_list_pt subList = pubsub_topicSubscriptionGetSubscribersList(topicSub); for(j=0;j<arrayList_size(subList);j++){ pubsub_endpoint_pt subEP = (pubsub_endpoint_pt)arrayList_get(subList,j); /* Remove the subscription */ pubsubAdmin_removeSubscription(admin, subEP); /* Reset the endpoint field, so that will be recreated from scratch when a new serializer will be found */ if(subEP->endpoint!=NULL){ free(subEP->endpoint); subEP->endpoint = NULL; } /* Add the orphan endpoint to the noSerializer pending list */ celixThreadMutex_lock(&admin->noSerializerPendingsLock); arrayList_add(admin->noSerializerSubscriptions,subEP); celixThreadMutex_unlock(&admin->noSerializerPendingsLock); } /* Cleanup also the subscriptions hashmap*/ celixThreadMutex_lock(&admin->subscriptionsLock); hash_map_iterator_pt iter = hashMapIterator_create(admin->subscriptions); char *key = NULL; while(hashMapIterator_hasNext(iter)){ hash_map_entry_pt entry = hashMapIterator_nextEntry(iter); topic_subscription_pt sub = (topic_subscription_pt)hashMapEntry_getValue(entry); if(sub==topicSub){ key = (char*)hashMapEntry_getKey(entry); break; } } hashMapIterator_destroy(iter); if(key!=NULL){ hashMap_remove(admin->subscriptions, key); free(key); } celixThreadMutex_unlock(&admin->subscriptionsLock); /* Finally destroy the topicSubscription */ pubsub_topicSubscriptionDestroy(topicSub); } arrayList_destroy(topicSubList); } printf("PSA_ZMQ: %s serializer removed\n",serType); return CELIX_SUCCESS; }
celix_status_t inspectCommand_printImportedServices(command_pt command, array_list_pt ids, void (*out)(char *), void (*err)(char *)) { celix_status_t status = CELIX_SUCCESS; array_list_pt bundles = NULL; if (arrayList_isEmpty(ids)) { celix_status_t status = bundleContext_getBundles(command->bundleContext, &bundles); } else { unsigned int i; arrayList_create(&bundles); for (i = 0; i < arrayList_size(ids); i++) { char *idStr = (char *) arrayList_get(ids, i); long id = atol(idStr); bundle_pt b = NULL; celix_status_t st = bundleContext_getBundleById(command->bundleContext, id, &b); if (st == CELIX_SUCCESS) { arrayList_add(bundles, b); } else { char line[256]; sprintf(line, "INSPECT: Invalid bundle ID: %ld\n", id); out(line); } } } if (status == CELIX_SUCCESS) { unsigned int i = 0; for (i = 0; i < arrayList_size(bundles); i++) { bundle_pt bundle = (bundle_pt) arrayList_get(bundles, i); if (i > 0) { out("\n"); } if (bundle != NULL) { array_list_pt refs = NULL; if (bundle_getServicesInUse(bundle, &refs) == CELIX_SUCCESS) { char line[256]; module_pt module = NULL; char * name = NULL; status = bundle_getCurrentModule(bundle, &module); if (status == CELIX_SUCCESS) { status = module_getSymbolicName(module, &name); if (status == CELIX_SUCCESS) { sprintf(line, "%s requires services:\n", name); out(line); out("==============\n"); if (refs == NULL || arrayList_size(refs) == 0) { out("Nothing\n"); } else { unsigned int j = 0; for (j = 0; j < arrayList_size(refs); j++) { service_reference_pt ref = (service_reference_pt) arrayList_get(refs, j); service_registration_pt reg = NULL; properties_pt props = NULL; char line[256]; bundle_pt usedBundle = NULL; module_pt usedModule = NULL; char *usedSymbolicName = NULL; long usedBundleId; serviceReference_getBundle(ref, &usedBundle); bundle_getBundleId(usedBundle, &usedBundleId); bundle_getCurrentModule(usedBundle, &usedModule); module_getSymbolicName(usedModule, &usedSymbolicName); sprintf(line, "%s [%ld]\n", usedSymbolicName, usedBundleId); out(line); serviceReference_getServiceRegistration(ref, ®); serviceRegistration_getProperties(reg, &props); hash_map_iterator_pt iter = hashMapIterator_create(props); while (hashMapIterator_hasNext(iter)) { hash_map_entry_pt entry = hashMapIterator_nextEntry(iter); sprintf(line, "%s = %s\n", hashMapEntry_getKey(entry), hashMapEntry_getValue(entry)); out(line); } hashMapIterator_destroy(iter); // objectClass = properties_get(props, (char *) OSGI_FRAMEWORK_OBJECTCLASS); // sprintf(line, "ObjectClass = %s\n", objectClass); if ((j + 1) < arrayList_size(refs)) { out("----\n"); } } } } } } } } } 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; }