in bundles/remote_services/remote_service_admin_shm_v2/rsa_shm/src/rsa_shm_impl.c [58:149]
static celix_status_t rsaShm_receiveMsgCB(void *handle, rsa_shm_server_t *shmServer,
celix_properties_t *metadata, const struct iovec *request, struct iovec *response);
static celix_status_t rsaShm_createEndpointDescription(rsa_shm_t *admin,
celix_properties_t *exportedProperties, char *interface, endpoint_description_t **description);
celix_status_t rsaShm_create(celix_bundle_context_t *context, celix_log_helper_t *logHelper,
rsa_shm_t **admin) {
celix_status_t status = CELIX_SUCCESS;
if (context == NULL || admin == NULL || logHelper == NULL) {
return CELIX_ILLEGAL_ARGUMENT;
}
celix_autofree rsa_shm_t* ad = calloc(1, sizeof(*ad));
if (ad == NULL) {
return CELIX_ENOMEM;
}
ad->context = context;
ad->logHelper = logHelper;
ad->reqSenderSvcId = -1;
status = celixThreadMutex_create(&ad->exportedServicesLock, NULL);
if (status != CELIX_SUCCESS) {
celix_logHelper_error(logHelper, "Error creating mutex for exported service. %d", status);
return status;
}
celix_autoptr(celix_thread_mutex_t) exportedServicesLock = &ad->exportedServicesLock;
celix_autoptr(celix_long_hash_map_t) exportedServices = ad->exportedServices = celix_longHashMap_create();
assert(ad->exportedServices);
status = celixThreadMutex_create(&ad->importedServicesLock, NULL);
if (status != CELIX_SUCCESS) {
celix_logHelper_error(logHelper, "Error creating mutex for imported service. %d", status);
return status;
}
celix_autoptr(celix_thread_mutex_t) importedServicesLock = &ad->importedServicesLock;
celix_autoptr(celix_array_list_t) importedServices = ad->importedServices = celix_arrayList_create();
assert(ad->importedServices != NULL);
status = rsaShmClientManager_create(context, logHelper, &ad->shmClientManager);
if (status != CELIX_SUCCESS) {
celix_logHelper_error(logHelper,"Error creating shm client manager. %d", status);
return status;
}
celix_autoptr(rsa_shm_client_manager_t) shmClientManager = ad->shmClientManager;
ad->reqSenderService.handle = ad;
ad->reqSenderService.sendRequest = (void*)rsaShm_send;
celix_service_registration_options_t opts = CELIX_EMPTY_SERVICE_REGISTRATION_OPTIONS;
opts.serviceName = CELIX_RSA_REQUEST_SENDER_SERVICE_NAME;
opts.serviceVersion = CELIX_RSA_REQUEST_SENDER_SERVICE_VERSION;
opts.svc = &ad->reqSenderService;
ad->reqSenderSvcId = celix_bundleContext_registerServiceWithOptionsAsync(context, &opts);
if (ad->reqSenderSvcId < 0) {
celix_logHelper_error(logHelper,"Error registering request sender service.");
return CELIX_BUNDLE_EXCEPTION;
}
celix_auto(celix_service_registration_guard_t) reg =
celix_serviceRegistrationGuard_init(context, ad->reqSenderSvcId);
const char *fwUuid = celix_bundleContext_getProperty(context, CELIX_FRAMEWORK_UUID, NULL);
if (fwUuid == NULL) {
celix_logHelper_error(logHelper,"Error Getting cfw uuid for shm rsa admin.");
return CELIX_BUNDLE_EXCEPTION;
}
long bundleId = celix_bundleContext_getBundleId(context);
if (bundleId < 0) {
celix_logHelper_error(logHelper,"Bundle id is invalid.");
return CELIX_BUNDLE_EXCEPTION;
}
int bytes = asprintf(&ad->shmServerName, "ShmServ_%s_%ld", fwUuid, bundleId);
if (bytes < 0) {
celix_logHelper_error(logHelper,"Failed to alloc memory for shm server name.");
return CELIX_ENOMEM;
}
celix_autofree char* shmServerName = ad->shmServerName;
status = rsaShmServer_create(context, ad->shmServerName,logHelper,
rsaShm_receiveMsgCB, ad, &ad->shmServer);
if (status != CELIX_SUCCESS) {
celix_logHelper_error(logHelper,"Error creating shm server. %d", status);
} else {
celix_steal_ptr(shmServerName);
reg.svcId = -1;
celix_steal_ptr(shmClientManager);
celix_steal_ptr(importedServices);
celix_steal_ptr(importedServicesLock);
celix_steal_ptr(exportedServices);
celix_steal_ptr(exportedServicesLock);
*admin = celix_steal_ptr(ad);
}
return status;
}