const pds_session_t * pds_session_alloc(pdict_t *pd, void (*pd_lock)(void *), void (*pd_unlock)(void *), void *pd_lock_arg, int readfd, int(*readfunc)(int, void *, unsigned int, char *errdesc, int edlen), int writefd, int(*writefunc)(int, const void *, unsigned int, char *errdesc, int edlen), int (*closefunc)(int, char *errdesc, int edlen), void (*logfunc)(pu_log_level_t, int s, const char *, ...), void(*cleanupfunc)(void), int(*authfunc)(pds_session_t *pdss), char *errdesc, int edlen) { pds_session_t *pdss; static int id = 1; pds_init(); if (!pd_lock || !pd_unlock) { snprintf(errdesc, edlen, "dictionary locking functions invalid"); return 0; } if (!(pdss = malloc(sizeof (*pdss)))) return NULL; memset(pdss, 0, sizeof (*pdss)); pdss->pdss_id = id++; pdss->pdss_rfd = readfd; pdss->pdss_read = readfunc; pdss->pdss_wfd = writefd; pdss->pdss_write = writefunc; pdss->pdss_close = closefunc; pdss->pdss_log = logfunc; pdss->pdss_cleanup = cleanupfunc; pdss->pdss_auth = authfunc; pthread_mutex_init(&pdss->pdss_lock, NULL); pthread_cond_init(&pdss->pdss_report_cv, NULL); pdss->pdss_pd = pd; pdss->pdss_pd_lock_arg = pd_lock_arg; pdss->pdss_pd_lock = pd_lock; pdss->pdss_pd_unlock = pd_unlock; pdss->cb_threads_count = 0; return pdss; }
ret_code_t pm_init(void) { ret_code_t err_code; err_code = pds_init(); if (err_code != NRF_SUCCESS) { return NRF_ERROR_INTERNAL; } err_code = pdb_init(); if (err_code != NRF_SUCCESS) { return NRF_ERROR_INTERNAL; } err_code = sm_init(); if (err_code != NRF_SUCCESS) { return NRF_ERROR_INTERNAL; } err_code = smd_init(); if (err_code != NRF_SUCCESS) { return NRF_ERROR_INTERNAL; } err_code = gcm_init(); if (err_code != NRF_SUCCESS) { return NRF_ERROR_INTERNAL; } err_code = gscm_init(); if (err_code != NRF_SUCCESS) { return NRF_ERROR_INTERNAL; } err_code = im_init(); if (err_code != NRF_SUCCESS) { return NRF_ERROR_INTERNAL; } internal_state_reset(); m_pairing_flag_id = ble_conn_state_user_flag_acquire(); if (m_pairing_flag_id == BLE_CONN_STATE_USER_FLAG_INVALID) { return NRF_ERROR_INTERNAL; } m_bonding_flag_id = ble_conn_state_user_flag_acquire(); if (m_bonding_flag_id == BLE_CONN_STATE_USER_FLAG_INVALID) { return NRF_ERROR_INTERNAL; } m_peer_rank_initialized = false; m_module_initialized = true; return NRF_SUCCESS; }