celix_status_t wiringAdmin_create(bundle_context_pt context, wiring_admin_pt *admin) { celix_status_t status = CELIX_SUCCESS; *admin = calloc(1, sizeof(**admin)); if (!*admin) { status = CELIX_ENOMEM; } else { (*admin)->context = context; (*admin)->wiringSendServices = hashMap_create(wiringEndpointDescription_hash, NULL, wiringEndpointDescription_equals, NULL); (*admin)->wiringSendRegistrations = hashMap_create(wiringEndpointDescription_hash, NULL, wiringEndpointDescription_equals, NULL); (*admin)->wiringReceiveServices = hashMap_create(utils_stringHash, NULL, utils_stringEquals, NULL); (*admin)->wiringReceiveTracker = hashMap_create(wiringEndpointDescription_hash, NULL, wiringEndpointDescription_equals, NULL); (*admin)->adminProperties = properties_create(); properties_set((*admin)->adminProperties, WIRING_ADMIN_PROPERTIES_SECURE_KEY, WIRING_ADMIN_PROPERTIES_SECURE_VALUE); properties_set((*admin)->adminProperties, WIRING_ADMIN_PROPERTIES_CONFIG_KEY, WIRING_ADMIN_PROPERTIES_CONFIG_VALUE); celixThreadMutex_create(&(*admin)->exportedWiringEndpointLock, NULL); celixThreadMutex_create(&(*admin)->importedWiringEndpointLock, NULL); } return status; }
celix_status_t importRegistration_create(bundle_context_pt context, endpoint_description_pt endpoint, const char *classObject, import_registration_pt *out) { celix_status_t status = CELIX_SUCCESS; import_registration_pt reg = calloc(1, sizeof(*reg)); if (reg != NULL) { reg->factory = calloc(1, sizeof(*reg->factory)); } if (reg != NULL && reg->factory != NULL) { reg->context = context; reg->endpoint = endpoint; reg->classObject = classObject; reg->proxies = hashMap_create(NULL, NULL, NULL, NULL); celixThreadMutex_create(®->mutex, NULL); celixThreadMutex_create(®->proxiesMutex, NULL); reg->factory->factory = reg; reg->factory->getService = (void *)importRegistration_getService; reg->factory->ungetService = (void *)importRegistration_ungetService; } else { status = CELIX_ENOMEM; } if (status == CELIX_SUCCESS) { printf("IMPORT REGISTRATION IS %p\n", reg); *out = reg; } return status; }
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 shellMediator_create(bundle_context_pt context, shell_mediator_pt *instance) { celix_status_t status = CELIX_SUCCESS; service_tracker_customizer_pt customizer = NULL; (*instance) = (shell_mediator_pt) calloc(1, sizeof(**instance)); if ((*instance) != NULL) { (*instance)->context = context; (*instance)->tracker = NULL; (*instance)->shellService = NULL; status = logHelper_create(context, &(*instance)->loghelper); status = CELIX_DO_IF(status, celixThreadMutex_create(&(*instance)->mutex, NULL)); status = CELIX_DO_IF(status, serviceTrackerCustomizer_create((*instance), shellMediator_addingService, shellMediator_addedService, shellMediator_modifiedService, shellMediator_removedService, &customizer)); status = CELIX_DO_IF(status, serviceTracker_create(context, (char * )OSGI_SHELL_SERVICE_NAME, customizer, &(*instance)->tracker)); if (status == CELIX_SUCCESS) { logHelper_start((*instance)->loghelper); serviceTracker_open((*instance)->tracker); } } else { status = CELIX_ENOMEM; } if (status != CELIX_SUCCESS) { logHelper_log((*instance)->loghelper, OSGI_LOGSERVICE_ERROR, "Error creating shell_mediator, error code is %i\n", status); } return status; }
celix_status_t etcdWatcher_create(node_discovery_pt node_discovery, bundle_context_pt context, etcd_watcher_pt *watcher) { celix_status_t status = CELIX_SUCCESS; char* etcd_server = NULL; char* etcd_port_string = NULL; int etcd_port = 0; if (node_discovery == NULL) { return CELIX_BUNDLE_EXCEPTION; } (*watcher) = calloc(1, sizeof(struct etcd_watcher)); if (*watcher) { (*watcher)->node_discovery = node_discovery; if ((bundleContext_getProperty(context, CFG_ETCD_SERVER_IP, &etcd_server) != CELIX_SUCCESS) || !etcd_server) { etcd_server = DEFAULT_ETCD_SERVER_IP; } if ((bundleContext_getProperty(context, CFG_ETCD_SERVER_PORT, &etcd_port_string) != CELIX_SUCCESS) || !etcd_port_string) { etcd_port = DEFAULT_ETCD_SERVER_PORT; } else { char* endptr = etcd_port_string; errno = 0; etcd_port = strtol(etcd_port_string, &endptr, 10); if (*endptr || errno != 0) { etcd_port = DEFAULT_ETCD_SERVER_PORT; } } if (etcd_init(etcd_server, etcd_port) == false) { status = CELIX_BUNDLE_EXCEPTION; } else { etcdWatcher_addOwnNode(*watcher); if ((status = celixThreadMutex_create(&(*watcher)->watcherLock, NULL)) != CELIX_SUCCESS) { return status; } if ((status = celixThreadMutex_lock(&(*watcher)->watcherLock)) != CELIX_SUCCESS) { return status; } if ((status = celixThread_create(&(*watcher)->watcherThread, NULL, etcdWatcher_run, *watcher)) != CELIX_SUCCESS) { return status; } (*watcher)->running = true; if ((status = celixThreadMutex_unlock(&(*watcher)->watcherLock)) != CELIX_SUCCESS) { return status; } } } else { status = CELIX_ENOMEM; } return status; }
celix_status_t serviceRegistration_createInternal(service_registry_pt registry, bundle_pt bundle, char * serviceName, long serviceId, void * serviceObject, properties_pt dictionary, bool isFactory, service_registration_pt *registration) { celix_status_t status = CELIX_SUCCESS; *registration = malloc(sizeof(**registration)); if (*registration) { (*registration)->services = NULL; (*registration)->nrOfServices = 0; (*registration)->isServiceFactory = isFactory; (*registration)->registry = registry; (*registration)->className = strdup(serviceName); (*registration)->bundle = bundle; (*registration)->serviceId = serviceId; (*registration)->svcObj = serviceObject; if (isFactory) { (*registration)->serviceFactory = (service_factory_pt) (*registration)->svcObj; } else { (*registration)->serviceFactory = NULL; } (*registration)->isUnregistering = false; celixThreadMutex_create(&(*registration)->mutex, NULL); serviceRegistration_initializeProperties(*registration, dictionary); } else { status = CELIX_ENOMEM; } return status; }
phase2b_cmp_t *phase2b_create(void) { phase2b_cmp_t *cmp = calloc(1, sizeof(*cmp)); if (cmp != NULL) { cmp->currentValue = 0.0; cmp->running = false; celixThreadMutex_create(&cmp->mutex, NULL); } return cmp; }
etcd_writer_pt etcdWriter_create(pubsub_discovery_pt disc) { etcd_writer_pt writer = calloc(1, sizeof(*writer)); if(writer) { celixThreadMutex_create(&writer->localPubsLock, NULL); arrayList_create(&writer->localPubs); writer->pubsub_discovery = disc; writer->running = true; celixThread_create(&writer->writerThread, NULL, etcdWriter_run, writer); } return writer; }
/* Discovery activator functions */ celix_status_t pubsub_discovery_create(bundle_context_pt context, pubsub_discovery_pt *ps_discovery) { celix_status_t status = CELIX_SUCCESS; *ps_discovery = calloc(1, sizeof(**ps_discovery)); if (*ps_discovery == NULL) { status = CELIX_ENOMEM; } else{ (*ps_discovery)->context = context; (*ps_discovery)->discoveredPubs = hashMap_create(utils_stringHash, NULL, utils_stringEquals, NULL); (*ps_discovery)->listenerReferences = hashMap_create(serviceReference_hashCode, NULL, serviceReference_equals2, NULL); (*ps_discovery)->watchers = hashMap_create(utils_stringHash,NULL,utils_stringEquals, NULL); celixThreadMutex_create(&(*ps_discovery)->listenerReferencesMutex, NULL); celixThreadMutex_create(&(*ps_discovery)->discoveredPubsMutex, NULL); celixThreadMutex_create(&(*ps_discovery)->watchersMutex, NULL); } return status; }
celix_status_t discovery_create(bundle_context_pt context, discovery_pt *discovery) { celix_status_t status = CELIX_SUCCESS; *discovery = malloc(sizeof(struct discovery)); if (!*discovery) { return CELIX_ENOMEM; } (*discovery)->context = context; (*discovery)->poller = NULL; (*discovery)->server = NULL; (*discovery)->listenerReferences = hashMap_create(serviceReference_hashCode, NULL, serviceReference_equals2, NULL); (*discovery)->discoveredServices = hashMap_create(utils_stringHash, NULL, utils_stringEquals, NULL); status = celixThreadMutex_create(&(*discovery)->listenerReferencesMutex, NULL); status = celixThreadMutex_create(&(*discovery)->discoveredServicesMutex, NULL); logHelper_create(context, &(*discovery)->loghelper); return status; }
celix_status_t serviceDependency_setAutoConfigure(dm_service_dependency_pt dependency, celix_thread_mutex_t *service_lock, void **field) { celix_status_t status = CELIX_SUCCESS; celix_thread_mutex_t lock; if (!dependency) { status = CELIX_ILLEGAL_ARGUMENT; } if (status == CELIX_SUCCESS) { dependency->autoConfigure = field; celixThreadMutex_create(&lock, NULL); *service_lock = lock; dependency->lock = lock; } return status; }
celix_status_t remoteShell_create(shell_mediator_pt mediator, int maximumConnections, remote_shell_pt *instance) { celix_status_t status = CELIX_SUCCESS; (*instance) = calloc(1, sizeof(**instance)); if ((*instance) != NULL) { (*instance)->mediator = mediator; (*instance)->maximumConnections = maximumConnections; (*instance)->connections = NULL; (*instance)->loghelper = &mediator->loghelper; status = celixThreadMutex_create(&(*instance)->mutex, NULL); if (status == CELIX_SUCCESS) { status = arrayList_create(&(*instance)->connections); } } else { status = CELIX_ENOMEM; } return status; }
celix_status_t bundle_create(bundle_pt * bundle, framework_logger_pt logger) { celix_status_t status = CELIX_SUCCESS; bundle_archive_pt archive = NULL; *bundle = (bundle_pt) malloc(sizeof(**bundle)); if (*bundle == NULL) { return CELIX_ENOMEM; } status = bundleArchive_createSystemBundleArchive(logger, &archive); if (status == CELIX_SUCCESS) { module_pt module; (*bundle)->archive = archive; (*bundle)->activator = NULL; (*bundle)->context = NULL; (*bundle)->framework = NULL; (*bundle)->state = OSGI_FRAMEWORK_BUNDLE_INSTALLED; (*bundle)->modules = NULL; arrayList_create(&(*bundle)->modules); (*bundle)->handle = NULL; (*bundle)->manifest = NULL; module = module_createFrameworkModule((*bundle)); bundle_addModule(*bundle, module); // (*bundle)->module = module; status = celixThreadMutex_create(&(*bundle)->lock, NULL); if (status != CELIX_SUCCESS) { status = CELIX_ILLEGAL_STATE; } else { (*bundle)->lockCount = 0; (*bundle)->lockThread = 0; resolver_addModule(module); } } framework_logIfError(logger, status, NULL, "Failed to create bundle"); return status; }
celix_status_t managedServiceTracker_createHandle(bundle_context_pt context, configuration_admin_factory_pt factory, configuration_store_pt store, managed_service_tracker_pt *tracker) { celix_status_t status; updated_thread_pool_pt updatedThreadPool = NULL; managed_service_tracker_pt this = calloc(1, sizeof(*this)); if (!this) { printf("[ ERROR ]: TrackerInstance - Not initialized (ENOMEM) \n"); *tracker = NULL; return CELIX_ENOMEM; } status = updatedThreadPool_create(context, MAX_THREADS, &updatedThreadPool); if (status != CELIX_SUCCESS) { return status; } this->context = context; this->configurationAdminfactory = factory; this->configurationStore = store; this->updatedThreadPool = updatedThreadPool; this->managedServices = hashMap_create(utils_stringHash, NULL, utils_stringEquals, NULL); this->managedServicesReferences = hashMap_create(utils_stringHash, NULL, utils_stringEquals, NULL); celix_status_t mutexStatus = celixThreadMutex_create(&this->managedServicesReferencesMutex, NULL); if (mutexStatus != CELIX_SUCCESS) { printf("[ ERROR ]: TrackerInstance - Not initialized (MUTEX) \n"); // TODO destroy threadpool? return CELIX_ILLEGAL_ARGUMENT; } *tracker = this; return CELIX_SUCCESS; }
celix_status_t bundle_createFromArchive(bundle_pt * bundle, framework_pt framework, bundle_archive_pt archive) { module_pt module; celix_status_t status = CELIX_SUCCESS; *bundle = (bundle_pt) malloc(sizeof(**bundle)); if (*bundle == NULL) { return CELIX_ENOMEM; } (*bundle)->archive = archive; (*bundle)->activator = NULL; (*bundle)->context = NULL; (*bundle)->framework = framework; (*bundle)->state = OSGI_FRAMEWORK_BUNDLE_INSTALLED; (*bundle)->modules = NULL; arrayList_create(&(*bundle)->modules); status = bundle_createModule(*bundle, &module); if (status == CELIX_SUCCESS) { bundle_addModule(*bundle, module); status = celixThreadMutex_create(&(*bundle)->lock, NULL); if (status != CELIX_SUCCESS) { status = CELIX_ILLEGAL_STATE; } else { (*bundle)->lockCount = 0; (*bundle)->lockThread = 0; resolver_addModule(module); } } else { status = CELIX_FILE_IO_EXCEPTION; } framework_logIfError(framework->logger, status, NULL, "Failed to create bundle"); return status; }
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 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 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; }
/* * the ectdWatcher needs to have access to the endpoint_discovery_poller and therefore is only * allowed to be created after the endpoint_discovery_poller */ celix_status_t etcdWatcher_create(discovery_pt discovery, bundle_context_pt context, etcd_watcher_pt *watcher) { celix_status_t status = CELIX_SUCCESS; char* etcd_server = NULL; char* etcd_port_string = NULL; int etcd_port = 0; if (discovery == NULL) { return CELIX_BUNDLE_EXCEPTION; } (*watcher) = calloc(1, sizeof(struct etcd_watcher)); if (!*watcher) { return CELIX_ENOMEM; } else { (*watcher)->discovery = discovery; (*watcher)->loghelper = &discovery->loghelper; (*watcher)->entries = hashMap_create(utils_stringHash, NULL, utils_stringEquals, NULL); } if ((bundleContext_getProperty(context, CFG_ETCD_SERVER_IP, &etcd_server) != CELIX_SUCCESS) || !etcd_server) { etcd_server = DEFAULT_ETCD_SERVER_IP; } if ((bundleContext_getProperty(context, CFG_ETCD_SERVER_PORT, &etcd_port_string) != CELIX_SUCCESS) || !etcd_port_string) { etcd_port = DEFAULT_ETCD_SERVER_PORT; } else { char* endptr = etcd_port_string; errno = 0; etcd_port = strtol(etcd_port_string, &endptr, 10); if (*endptr || errno != 0) { etcd_port = DEFAULT_ETCD_SERVER_PORT; } } status = etcd_init(etcd_server, etcd_port); printf(" ININT\n"); if (status == CELIX_SUCCESS) { etcdWatcher_addOwnFramework(*watcher); status = celixThreadMutex_create(&(*watcher)->watcherLock, NULL); printf(" 111\n"); } if (status == CELIX_SUCCESS) { if (celixThreadMutex_lock(&(*watcher)->watcherLock) == CELIX_SUCCESS) { status = celixThread_create(&(*watcher)->watcherThread, NULL, etcdWatcher_run, *watcher); if (status == CELIX_SUCCESS) { printf(" STARTEDTSTARTED\n"); (*watcher)->running = true; } celixThreadMutex_unlock(&(*watcher)->watcherLock); } } printf(" DONEDONE\n"); return status; }
/** * Allocates memory and initializes a new endpoint_discovery_poller instance. */ celix_status_t endpointDiscoveryPoller_create(discovery_pt discovery, bundle_context_pt context, endpoint_discovery_poller_pt *poller) { celix_status_t status; *poller = malloc(sizeof(struct endpoint_discovery_poller)); if (!*poller) { return CELIX_ENOMEM; } (*poller)->loghelper = &discovery->loghelper; status = celixThreadMutex_create(&(*poller)->pollerLock, NULL); if (status != CELIX_SUCCESS) { return status; } char* interval = NULL; status = bundleContext_getProperty(context, DISCOVERY_POLL_INTERVAL, &interval); if (!interval) { interval = DEFAULT_POLL_INTERVAL; } char* endpoints = NULL; status = bundleContext_getProperty(context, DISCOVERY_POLL_ENDPOINTS, &endpoints); if (!endpoints) { endpoints = DEFAULT_POLL_ENDPOINTS; } // we're going to mutate the string with strtok, so create a copy... endpoints = strdup(endpoints); (*poller)->poll_interval = atoi(interval); (*poller)->discovery = discovery; (*poller)->running = false; (*poller)->entries = hashMap_create(utils_stringHash, NULL, utils_stringEquals, NULL); const char* sep = ","; char *save_ptr = NULL; char* tok = strtok_r(endpoints, sep, &save_ptr); while (tok) { endpointDiscoveryPoller_addDiscoveryEndpoint(*poller, utils_stringTrim(tok)); tok = strtok_r(NULL, sep, &save_ptr); } // Clean up after ourselves... free(endpoints); status = celixThreadMutex_lock(&(*poller)->pollerLock); if (status != CELIX_SUCCESS) { return CELIX_BUNDLE_EXCEPTION; } (*poller)->running = true; status = celixThread_create(&(*poller)->pollerThread, NULL, endpointDiscoveryPoller_performPeriodicPoll, *poller); if (status != CELIX_SUCCESS) { return status; } status = celixThreadMutex_unlock(&(*poller)->pollerLock); return status; }
celix_status_t pubsub_topicSubscriptionCreate(bundle_context_pt bundle_context, char* ifIp,char* scope, char* topic ,pubsub_serializer_service_t *best_serializer, topic_subscription_pt* out){ celix_status_t status = CELIX_SUCCESS; topic_subscription_pt ts = (topic_subscription_pt) calloc(1,sizeof(*ts)); ts->context = bundle_context; ts->ifIpAddress = strdup(ifIp); #if defined(__APPLE__) && defined(__MACH__) //TODO: Use kqueue for OSX #else ts->topicEpollFd = epoll_create1(0); #endif if(ts->topicEpollFd == -1) { status += CELIX_SERVICE_EXCEPTION; } ts->running = false; ts->nrSubscribers = 0; ts->serializer = best_serializer; celixThreadMutex_create(&ts->ts_lock,NULL); arrayList_create(&ts->sub_ep_list); ts->servicesMap = hashMap_create(NULL, NULL, NULL, NULL); ts->socketMap = hashMap_create(utils_stringHash, NULL, utils_stringEquals, NULL); arrayList_create(&ts->pendingConnections); arrayList_create(&ts->pendingDisconnections); celixThreadMutex_create(&ts->pendingConnections_lock, NULL); celixThreadMutex_create(&ts->pendingDisconnections_lock, NULL); celixThreadMutex_create(&ts->socketMap_lock, NULL); ts->largeUdpHandle = largeUdp_create(MAX_UDP_SESSIONS); char filter[128]; memset(filter,0,128); if(strncmp(PUBSUB_SUBSCRIBER_SCOPE_DEFAULT, scope, strlen(PUBSUB_SUBSCRIBER_SCOPE_DEFAULT)) == 0) { // default scope, means that subscriber has not defined a scope property snprintf(filter, 128, "(&(%s=%s)(%s=%s))", (char*) OSGI_FRAMEWORK_OBJECTCLASS, PUBSUB_SUBSCRIBER_SERVICE_NAME, PUBSUB_SUBSCRIBER_TOPIC,topic); } else { snprintf(filter, 128, "(&(%s=%s)(%s=%s)(%s=%s))", (char*) OSGI_FRAMEWORK_OBJECTCLASS, PUBSUB_SUBSCRIBER_SERVICE_NAME, PUBSUB_SUBSCRIBER_TOPIC,topic, PUBSUB_SUBSCRIBER_SCOPE,scope); } service_tracker_customizer_pt customizer = NULL; status += serviceTrackerCustomizer_create(ts,NULL,topicsub_subscriberTracked,NULL,topicsub_subscriberUntracked,&customizer); status += serviceTracker_createWithFilter(bundle_context, filter, customizer, &ts->tracker); struct sigaction actions; memset(&actions, 0, sizeof(actions)); sigemptyset(&actions.sa_mask); actions.sa_flags = 0; actions.sa_handler = sigusr1_sighandler; sigaction(SIGUSR1,&actions,NULL); if (status == CELIX_SUCCESS) { *out=ts; } return status; }
celix_status_t remoteServiceAdmin_create(bundle_context_pt context, remote_service_admin_pt *admin) { celix_status_t status = CELIX_SUCCESS; *admin = calloc(1, sizeof(**admin)); if (!*admin) { status = CELIX_ENOMEM; } else { unsigned int port_counter = 0; char *port = NULL; char *ip = NULL; char *detectedIp = NULL; (*admin)->context = context; (*admin)->exportedServices = hashMap_create(NULL, NULL, NULL, NULL); arrayList_create(&(*admin)->importedServices); celixThreadMutex_create(&(*admin)->exportedServicesLock, NULL); celixThreadMutex_create(&(*admin)->importedServicesLock, NULL); if (logHelper_create(context, &(*admin)->loghelper) == CELIX_SUCCESS) { logHelper_start((*admin)->loghelper); dynCommon_logSetup((void *)remoteServiceAdmin_log, *admin, 1); dynType_logSetup((void *)remoteServiceAdmin_log, *admin, 1); dynFunction_logSetup((void *)remoteServiceAdmin_log, *admin, 1); dynInterface_logSetup((void *)remoteServiceAdmin_log, *admin, 1); jsonSerializer_logSetup((void *)remoteServiceAdmin_log, *admin, 1); jsonRpc_logSetup((void *)remoteServiceAdmin_log, *admin, 1); } bundleContext_getProperty(context, "RSA_PORT", &port); if (port == NULL) { port = (char *)DEFAULT_PORT; } bundleContext_getProperty(context, "RSA_IP", &ip); if (ip == NULL) { char *interface = NULL; bundleContext_getProperty(context, "RSA_INTERFACE", &interface); if ((interface != NULL) && (remoteServiceAdmin_getIpAdress(interface, &detectedIp) != CELIX_SUCCESS)) { logHelper_log((*admin)->loghelper, OSGI_LOGSERVICE_WARNING, "RSA: Could not retrieve IP adress for interface %s", interface); } if (ip == NULL) { remoteServiceAdmin_getIpAdress(NULL, &detectedIp); } ip = detectedIp; } if (ip != NULL) { logHelper_log((*admin)->loghelper, OSGI_LOGSERVICE_INFO, "RSA: Using %s for service annunciation", ip); (*admin)->ip = strdup(ip); } else { logHelper_log((*admin)->loghelper, OSGI_LOGSERVICE_WARNING, "RSA: No IP address for service annunciation set. Using %s", DEFAULT_IP); (*admin)->ip = strdup((char*) DEFAULT_IP); } if (detectedIp != NULL) { free(detectedIp); } // Prepare callbacks structure. We have only one callback, the rest are NULL. struct mg_callbacks callbacks; memset(&callbacks, 0, sizeof(callbacks)); callbacks.begin_request = remoteServiceAdmin_callback; do { char newPort[10]; const char *options[] = { "listening_ports", port, "num_threads", "5", NULL}; (*admin)->ctx = mg_start(&callbacks, (*admin), options); if ((*admin)->ctx != NULL) { logHelper_log((*admin)->loghelper, OSGI_LOGSERVICE_INFO, "RSA: Start webserver: %s", port); (*admin)->port = strdup(port); } else { char* endptr = port; int currentPort = strtol(port, &endptr, 10); errno = 0; if (*endptr || errno != 0) { currentPort = strtol(DEFAULT_PORT, NULL, 10); } port_counter++; snprintf(&newPort[0], 6, "%d", (currentPort+1)); logHelper_log((*admin)->loghelper, OSGI_LOGSERVICE_ERROR, "Error while starting rsa server on port %s - retrying on port %s...", port, newPort); port = newPort; } } while(((*admin)->ctx == NULL) && (port_counter < MAX_NUMBER_OF_RESTARTS)); } return status; }