Beispiel #1
0
static pj_status_t pool_buf_initialize()
{
    pj_atexit(&pool_buf_cleanup);

    stack_based_factory.policy.block_alloc = &stack_alloc;
    return pj_thread_local_alloc(&tls);
}
Beispiel #2
0
PJ_DEF(pj_status_t) pjmedia_srtp_init_lib(void)
{
    if (libsrtp_initialized == PJ_FALSE) {
	err_status_t err;

	err = srtp_init();
	if (err != err_status_ok) { 
	    PJ_LOG(4, (THIS_FILE, "Failed to initialize libsrtp: %s", 
		       get_libsrtp_errstr(err)));
	    return PJMEDIA_ERRNO_FROM_LIBSRTP(err);
	}

	if (pj_atexit(pjmedia_srtp_deinit_lib) != PJ_SUCCESS) {
	    /* There will be memory leak when it fails to schedule libsrtp 
	     * deinitialization, however the memory leak could be harmless,
	     * since in modern OS's memory used by an application is released 
	     * when the application terminates.
	     */
	    PJ_LOG(4, (THIS_FILE, "Failed to register libsrtp deinit."));
	}

	libsrtp_initialized = PJ_TRUE;
    }
    
    return PJ_SUCCESS;
}
Beispiel #3
0
/*
 * Initialize Replaces support in PJSIP. 
 */
PJ_DEF(pj_status_t) pjsip_replaces_init_module(pjsip_endpoint *endpt)
{
    pj_status_t status;
    const pj_str_t STR_REPLACES = { "replaces", 8 };

    the_endpt = endpt;

    if (is_initialized)
	return PJ_SUCCESS;

    /* Register Replaces header parser */
    status = pjsip_register_hdr_parser( "Replaces", NULL, 
				        &parse_hdr_replaces);
    if (status != PJ_SUCCESS)
	return status;

    /* Register "replaces" capability */
    status = pjsip_endpt_add_capability(endpt, NULL, PJSIP_H_SUPPORTED, NULL,
					1, &STR_REPLACES);

    /* Register deinit module to be executed when PJLIB shutdown */
    if (pj_atexit(&pjsip_replaces_deinit_module) != PJ_SUCCESS) {
	/* Failure to register this function may cause this module won't 
	 * work properly when the stack is restarted (without quitting 
	 * application).
	 */
	pj_assert(!"Failed to register Replaces deinit.");
	PJ_LOG(1, (THIS_FILE, "Failed to register Replaces deinit."));
    }

    is_initialized = PJ_TRUE;
    return PJ_SUCCESS;
}
Beispiel #4
0
pj_status_t pj_log_init(void)
{
#if PJ_HAS_THREADS
    if (thread_suspended_tls_id == -1) {
	pj_thread_local_alloc(&thread_suspended_tls_id);
	pj_atexit(&logging_shutdown);
    }
#endif
    return PJ_SUCCESS;
}
Beispiel #5
0
PJ_DEF(void) pj_push_exception_handler_(struct pj_exception_state_t *rec)
{
    struct pj_exception_state_t *parent_handler = NULL;

    if (thread_local_id == -1) {
	pj_thread_local_alloc(&thread_local_id);
	pj_assert(thread_local_id != -1);
	pj_atexit(&exception_cleanup);
    }
    parent_handler = pj_thread_local_get(thread_local_id);
    rec->prev = parent_handler;
    pj_thread_local_set(thread_local_id, rec);
}
Beispiel #6
0
/*
 * Initialize Session Timers support in PJSIP. 
 */
PJ_DEF(pj_status_t) pjsip_timer_init_module(pjsip_endpoint *endpt)
{
    pj_status_t status;

    PJ_ASSERT_RETURN(endpt, PJ_EINVAL);

    if (is_initialized)
	return PJ_SUCCESS;

    /* Register Session-Expires header parser */
    status = pjsip_register_hdr_parser( STR_SE.ptr, STR_SHORT_SE.ptr, 
				        &parse_hdr_se);
    if (status != PJ_SUCCESS)
	return status;

    /* Register Min-SE header parser */
    status = pjsip_register_hdr_parser( STR_MIN_SE.ptr, NULL, 
				        &parse_hdr_min_se);
    if (status != PJ_SUCCESS)
	return status;

    /* Register 'timer' capability to endpoint */
    status = pjsip_endpt_add_capability(endpt, NULL, PJSIP_H_SUPPORTED,
					NULL, 1, &STR_TIMER);
    if (status != PJ_SUCCESS)
	return status;

    /* Register deinit module to be executed when PJLIB shutdown */
    if (pj_atexit(&pjsip_timer_deinit_module) != PJ_SUCCESS) {
	/* Failure to register this function may cause this module won't 
	 * work properly when the stack is restarted (without quitting 
	 * application).
	 */
	pj_assert(!"Failed to register Session Timer deinit.");
	PJ_LOG(1, (THIS_FILE, "Failed to register Session Timer deinit."));
    }

    is_initialized = PJ_TRUE;

    return PJ_SUCCESS;
}
pj_status_t pj_log_init(void)
{
#if PJ_HAS_THREADS
    if (thread_suspended_tls_id == -1) {
	pj_status_t status;
	status = pj_thread_local_alloc(&thread_suspended_tls_id);
	if (status != PJ_SUCCESS)
	    return status;

#  if PJ_LOG_ENABLE_INDENT
	status = pj_thread_local_alloc(&thread_indent_tls_id);
	if (status != PJ_SUCCESS) {
	    pj_thread_local_free(thread_suspended_tls_id);
	    thread_suspended_tls_id = -1;
	    return status;
	}
#  endif
	pj_atexit(&logging_shutdown);
    }
#endif
    g_last_thread = NULL;
    return PJ_SUCCESS;
}