static celix_status_t rsaShmClientManager_createMsgControl()

in bundles/remote_services/remote_service_admin_shm_v2/rsa_shm/src/rsa_shm_client.c [87:185]


static celix_status_t rsaShmClientManager_createMsgControl(rsa_shm_client_manager_t *clientManager,
        rsa_shm_msg_control_alloc_t* alloc);
static void rsaShmClientManager_destroyMsgControl(rsa_shm_msg_control_alloc_t* alloc);

CELIX_DEFINE_AUTO_CLEANUP_CLEAR_FUNC(rsa_shm_msg_control_alloc_t, rsaShmClientManager_destroyMsgControl)

static void *rsaShmClientManager_exceptionMsgHandlerThread(void *data);
static celix_status_t rsaShmClientManager_createClient(rsa_shm_client_manager_t *clientManager,
        const char *peerServerName, rsa_shm_client_t **clientOut);
static void rsaShmClientManager_destroyClient(rsa_shm_client_t *client);
static rsa_shm_client_t * rsaShmClientManager_getClient(rsa_shm_client_manager_t *clientManager,
        const char *peerServerName);
static void rsaShmClientManager_ungetClient(rsa_shm_client_t *client);

CELIX_DEFINE_AUTOPTR_CLEANUP_FUNC(rsa_shm_client_t, rsaShmClientManager_ungetClient)

static void rsaShmClientManager_markSvcCallFailed(rsa_shm_client_manager_t *clientManager,
        const char *peerServerName, long serviceId);
static void rsaShmClientManager_markSvcCallFinished(rsa_shm_client_manager_t *clientManager,
        const char *peerServerName, long serviceId);
static celix_status_t rsaShmClientManager_receiveResponse(rsa_shm_client_manager_t *clientManager,
        rsa_shm_msg_control_t *msgCtrl, char *msgBuffer, size_t bufSize,
        struct iovec *response, bool *replied);
static void rsaShmClient_destroyOrDetachSvcDiagInfo(rsa_shm_client_t *client, long serviceId);
static void rsaShmClient_createOrAttachSvcDiagInfo(rsa_shm_client_t *client, long serviceId);
static bool rsaShmClient_shouldBreakInvocation(rsa_shm_client_t *client, long serviceId);

celix_status_t rsaShmClientManager_create(celix_bundle_context_t *ctx,
        celix_log_helper_t *loghelper, rsa_shm_client_manager_t **clientManagerOut) {
    celix_status_t status = CELIX_SUCCESS;
    if (loghelper == NULL || ctx == NULL || clientManagerOut == NULL) {
        return CELIX_ILLEGAL_ARGUMENT;
    }
    celix_autofree rsa_shm_client_manager_t* clientManager = (rsa_shm_client_manager_t *)malloc(sizeof(*clientManager));
    if (clientManager == NULL) {
        return CELIX_ENOMEM;
    }

    clientManager->ctx = ctx;
    clientManager->logHelper = loghelper;
    clientManager->maxConcurrentNum = celix_bundleContext_getPropertyAsLong(ctx,
            RSA_SHM_MAX_CONCURRENT_INVOCATIONS_KEY, RSA_SHM_MAX_CONCURRENT_INVOCATIONS_DEFAULT);
    clientManager->msgTimeOutInSec = celix_bundleContext_getPropertyAsLong(ctx,
            RSA_SHM_MSG_TIMEOUT_KEY, RSA_SHM_MSG_TIMEOUT_DEFAULT_IN_S);

    long shmPoolSize = celix_bundleContext_getPropertyAsLong(ctx, RSA_SHM_MEMORY_POOL_SIZE_KEY,
            RSA_SHM_MEMORY_POOL_SIZE_DEFAULT);

    celix_autoptr(shm_pool_t) shmPool = NULL;
    status = shmPool_create(shmPoolSize, &shmPool);
    if (status != CELIX_SUCCESS) {
        celix_logHelper_logTssErrors(loghelper, CELIX_LOG_LEVEL_ERROR);
        celix_logHelper_error(loghelper, "RsaShmClient: Error Creating shared memory shmPool.");
        return status;
    }
    clientManager->shmPool = shmPool;

    status = celixThreadMutex_create(&clientManager->clientsMutex, NULL);
    if (status != CELIX_SUCCESS) {
        celix_logHelper_error(loghelper, "RsaShmClient: Error creating clients mutex.");
        return status;
    }
    celix_autoptr(celix_thread_mutex_t) clientsMutex = &clientManager->clientsMutex;
    celix_autoptr(celix_string_hash_map_t) clients = clientManager->clients = celix_stringHashMap_create();
    assert(clientManager->clients != NULL);

    status = celixThreadMutex_create(&clientManager->exceptionMsgListMutex, NULL);
    if (status != CELIX_SUCCESS) {
        celix_logHelper_error(loghelper, "RsaShmClient: Error creating msg list mutex.");
        return status;
    }
    celix_autoptr(celix_thread_mutex_t) exceptionMsgListMutex = &clientManager->exceptionMsgListMutex;
    status = celixThreadCondition_init(&clientManager->exceptionMsgListNotEmpty, NULL);
    if (status != CELIX_SUCCESS) {
        celix_logHelper_error(loghelper, "RsaShmClient: Error creating msg list signal.");
        return status;
    }
    celix_autoptr(celix_thread_cond_t) exceptionMsgListNotEmpty = &clientManager->exceptionMsgListNotEmpty;
    celix_autoptr(celix_array_list_t) exceptionMsgList = clientManager->exceptionMsgList = celix_arrayList_create();
    assert(clientManager->exceptionMsgList != NULL);

    clientManager->threadActive = true;
    status = celixThread_create(&clientManager->msgExceptionHandlerThread, NULL,
            rsaShmClientManager_exceptionMsgHandlerThread, clientManager);
    if (status != CELIX_SUCCESS) {
        celix_logHelper_error(loghelper, "RsaShmClient: Error creating msg list management thread.");
        return status;
    }
    celixThread_setName(&clientManager->msgExceptionHandlerThread, "rsaShmMsgLifeManager");

    celix_steal_ptr(exceptionMsgList);
    celix_steal_ptr(exceptionMsgListNotEmpty);
    celix_steal_ptr(exceptionMsgListMutex);
    celix_steal_ptr(clients);
    celix_steal_ptr(clientsMutex);
    celix_steal_ptr(shmPool);
    *clientManagerOut = celix_steal_ptr(clientManager);
    return CELIX_SUCCESS;
}