celix_status_t serviceRegistry_create(framework_pt framework, serviceChanged_function_pt serviceChanged, service_registry_pt *registry) { celix_status_t status = CELIX_SUCCESS; *registry = malloc(sizeof(**registry)); if (!*registry) { status = CELIX_ENOMEM; } else { (*registry)->serviceChanged = serviceChanged; (*registry)->inUseMap = hashMap_create(NULL, NULL, NULL, NULL); (*registry)->serviceRegistrations = hashMap_create(NULL, NULL, NULL, NULL); (*registry)->framework = framework; (*registry)->currentServiceId = 1l; (*registry)->serviceReferences = hashMap_create(NULL, NULL, NULL, NULL);; arrayList_create(&(*registry)->listenerHooks); status = celixThreadMutexAttr_create(&(*registry)->mutexAttr); status = CELIX_DO_IF(status, celixThreadMutexAttr_settype(&(*registry)->mutexAttr, CELIX_THREAD_MUTEX_RECURSIVE)); status = CELIX_DO_IF(status, celixThreadMutex_create(&(*registry)->mutex, &(*registry)->mutexAttr)); status = CELIX_DO_IF(status, celixThreadMutex_create(&(*registry)->referencesMapMutex, NULL)); } framework_logIfError(logger, status, NULL, "Cannot create service registry"); return status; }
celix_status_t configuration_create( configuration_admin_factory_pt factory, configuration_store_pt store, char *factoryPid, char *pid, char *bundleLocation, configuration_pt *configuration) { struct configuration *config; struct configuration_impl *conf_impl; celix_thread_mutexattr_t mutex_attr; 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; /* config = calloc(1,sizeof(struct configuration)); if(!config){ printf("[ ERROR ]: Configuration{PID=%s} - Not created (ENOMEM) \n",pid); return CELIX_ENOMEM; } */ conf_impl->configurationAdminFactory = factory; conf_impl->configurationStore = store; if (factoryPid != NULL) conf_impl->factoryPid = strdup(factoryPid); else conf_impl->factoryPid = NULL; if (pid != NULL) conf_impl->pid = strdup(pid); else conf_impl->pid = NULL; if (bundleLocation != NULL) conf_impl->bundleLocation = strdup(bundleLocation); 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",pid); return CELIX_ILLEGAL_ARGUMENT; } conf_impl->configuration_interface = config; config->handle = conf_impl; *configuration = config; return CELIX_SUCCESS; }
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; }
celix_status_t pubsubAdmin_create(bundle_context_pt context, pubsub_admin_pt *admin) { celix_status_t status = CELIX_SUCCESS; #ifdef BUILD_WITH_ZMQ_SECURITY if (!zsys_has_curve()){ printf("PSA_ZMQ: zeromq curve unsupported\n"); return CELIX_SERVICE_EXCEPTION; } #endif *admin = calloc(1, sizeof(**admin)); if (!*admin) { status = CELIX_ENOMEM; } else{ const char *ip = NULL; char *detectedIp = NULL; (*admin)->bundle_context= context; (*admin)->localPublications = hashMap_create(utils_stringHash, NULL, utils_stringEquals, NULL); (*admin)->subscriptions = hashMap_create(utils_stringHash, NULL, utils_stringEquals, NULL); (*admin)->pendingSubscriptions = hashMap_create(utils_stringHash, NULL, utils_stringEquals, NULL); (*admin)->externalPublications = hashMap_create(utils_stringHash, NULL, utils_stringEquals, NULL); (*admin)->topicSubscriptionsPerSerializer = hashMap_create(NULL, NULL, NULL, NULL); (*admin)->topicPublicationsPerSerializer = hashMap_create(NULL, NULL, NULL, NULL); arrayList_create(&((*admin)->noSerializerSubscriptions)); arrayList_create(&((*admin)->noSerializerPublications)); arrayList_create(&((*admin)->serializerList)); celixThreadMutex_create(&(*admin)->localPublicationsLock, NULL); celixThreadMutex_create(&(*admin)->subscriptionsLock, NULL); celixThreadMutex_create(&(*admin)->externalPublicationsLock, NULL); celixThreadMutex_create(&(*admin)->serializerListLock, NULL); celixThreadMutex_create(&(*admin)->usedSerializersLock, NULL); celixThreadMutexAttr_create(&(*admin)->noSerializerPendingsAttr); celixThreadMutexAttr_settype(&(*admin)->noSerializerPendingsAttr, CELIX_THREAD_MUTEX_RECURSIVE); celixThreadMutex_create(&(*admin)->noSerializerPendingsLock, &(*admin)->noSerializerPendingsAttr); celixThreadMutexAttr_create(&(*admin)->pendingSubscriptionsAttr); celixThreadMutexAttr_settype(&(*admin)->pendingSubscriptionsAttr, CELIX_THREAD_MUTEX_RECURSIVE); celixThreadMutex_create(&(*admin)->pendingSubscriptionsLock, &(*admin)->pendingSubscriptionsAttr); if (logHelper_create(context, &(*admin)->loghelper) == CELIX_SUCCESS) { logHelper_start((*admin)->loghelper); } bundleContext_getProperty(context,PSA_IP , &ip); #ifndef ANDROID if (ip == NULL) { const char *interface = NULL; bundleContext_getProperty(context, PSA_ITF, &interface); if (pubsubAdmin_getIpAdress(interface, &detectedIp) != CELIX_SUCCESS) { logHelper_log((*admin)->loghelper, OSGI_LOGSERVICE_WARNING, "PSA_ZMQ: Could not retrieve IP adress for interface %s", interface); } ip = detectedIp; } #endif if (ip != NULL) { logHelper_log((*admin)->loghelper, OSGI_LOGSERVICE_INFO, "PSA_ZMQ: Using %s for service annunciation", ip); (*admin)->ipAddress = strdup(ip); } else { logHelper_log((*admin)->loghelper, OSGI_LOGSERVICE_WARNING, "PSA_ZMQ: No IP address for service annunciation set. Using %s", DEFAULT_IP); (*admin)->ipAddress = strdup(DEFAULT_IP); } if (detectedIp != NULL) { free(detectedIp); } const char* basePortStr = NULL; const char* maxPortStr = NULL; char* endptrBase = NULL; char* endptrMax = NULL; bundleContext_getPropertyWithDefault(context, PSA_ZMQ_BASE_PORT, "PSA_ZMQ_DEFAULT_BASE_PORT", &basePortStr); bundleContext_getPropertyWithDefault(context, PSA_ZMQ_MAX_PORT, "PSA_ZMQ_DEFAULT_MAX_PORT", &maxPortStr); (*admin)->basePort = strtol(basePortStr, &endptrBase, 10); (*admin)->maxPort = strtol(maxPortStr, &endptrMax, 10); if (*endptrBase != '\0') { (*admin)->basePort = PSA_ZMQ_DEFAULT_BASE_PORT; } if (*endptrMax != '\0') { (*admin)->maxPort = PSA_ZMQ_DEFAULT_MAX_PORT; } printf("PSA Using base port %u to max port %u\n", (*admin)->basePort, (*admin)->maxPort); // Disable Signal Handling by CZMQ setenv("ZSYS_SIGHANDLER", "false", true); const char *nrZmqThreads = NULL; bundleContext_getProperty(context, "PSA_NR_ZMQ_THREADS", &nrZmqThreads); if(nrZmqThreads != NULL) { char *endPtr = NULL; unsigned int nrThreads = strtoul(nrZmqThreads, &endPtr, 10); if(endPtr != nrZmqThreads && nrThreads > 0 && nrThreads < 50) { zsys_set_io_threads(nrThreads); logHelper_log((*admin)->loghelper, OSGI_LOGSERVICE_INFO, "PSA_ZMQ: Using %d threads for ZMQ", nrThreads); printf("PSA_ZMQ: Using %d threads for ZMQ\n", nrThreads); } } #ifdef BUILD_WITH_ZMQ_SECURITY // Setup authenticator zactor_t* auth = zactor_new (zauth, NULL); zstr_sendx(auth, "VERBOSE", NULL); // Load all public keys of subscribers into the application // This step is done for authenticating subscribers char curve_folder_path[MAX_KEY_FOLDER_PATH_LENGTH]; char* keys_bundle_dir = pubsub_getKeysBundleDir(context); snprintf(curve_folder_path, MAX_KEY_FOLDER_PATH_LENGTH, "%s/META-INF/keys/subscriber/public", keys_bundle_dir); zstr_sendx (auth, "CURVE", curve_folder_path, NULL); free(keys_bundle_dir); (*admin)->zmq_auth = auth; #endif } return status; }