Main Page | Modules | Class Hierarchy | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals | Related Pages

switch_core_pvt.h File Reference


Data Structures

struct  switch_core_session
struct  switch_media_bug
struct  switch_runtime

Defines

#define switch_thread_self   apr_os_thread_current
#define DO_EVENTS
#define SWITCH_EVENT_QUEUE_LEN   256
#define SWITCH_MESSAGE_QUEUE_LEN   256
#define SWITCH_SQL_QUEUE_LEN   100000
#define SWITCH_BUFFER_BLOCK_FRAMES   25
#define SWITCH_BUFFER_START_FRAMES   50

Typedefs

typedef apr_os_thread_t switch_thread_id_t

Enumerations

enum  switch_session_flag_t { SSF_NONE = 0, SSF_DESTROYED = (1 << 0), SSF_WARN_TRANSCODE = (1 << 1) }

Functions

void switch_core_sqldb_start (switch_memory_pool_t *pool)
void switch_core_sqldb_stop (void)
void switch_core_session_init (switch_memory_pool_t *pool)
void switch_core_session_uninit (void)
void switch_core_state_machine_init (switch_memory_pool_t *pool)
switch_memory_pool_tswitch_core_memory_init (void)
void switch_core_memory_stop (void)

Variables

switch_runtime runtime


Define Documentation

#define DO_EVENTS
 

#define SWITCH_BUFFER_BLOCK_FRAMES   25
 

#define SWITCH_BUFFER_START_FRAMES   50
 

#define SWITCH_EVENT_QUEUE_LEN   256
 

#define SWITCH_MESSAGE_QUEUE_LEN   256
 

#define SWITCH_SQL_QUEUE_LEN   100000
 

#define switch_thread_self   apr_os_thread_current
 


Typedef Documentation

typedef apr_os_thread_t switch_thread_id_t
 


Enumeration Type Documentation

enum switch_session_flag_t
 

Enumeration values:
SSF_NONE 
SSF_DESTROYED 
SSF_WARN_TRANSCODE 
00086              {
00087         SSF_NONE = 0,
00088         SSF_DESTROYED = (1 << 0),
00089         SSF_WARN_TRANSCODE = (1 << 1)
00090 } switch_session_flag_t;


Function Documentation

switch_memory_pool_t* switch_core_memory_init void   ) 
 

00437 {
00438         switch_thread_t *thread;
00439     switch_threadattr_t *thd_attr;
00440 #ifdef PER_POOL_LOCK
00441         apr_allocator_t *my_allocator = NULL;
00442         apr_thread_mutex_t *my_mutex;
00443 #endif
00444 
00445         memset(&memory_manager, 0, sizeof(memory_manager));
00446 
00447 #ifdef PER_POOL_LOCK
00448                 if ((apr_allocator_create(&my_allocator)) != APR_SUCCESS) {
00449                         abort();
00450                 }
00451 
00452                 if ((apr_pool_create_ex(&memory_manager.memory_pool, NULL, NULL, my_allocator)) != APR_SUCCESS) {
00453                         apr_allocator_destroy(my_allocator);
00454                         my_allocator = NULL;
00455                         abort();
00456                 }
00457 
00458                 if ((apr_thread_mutex_create(&my_mutex, APR_THREAD_MUTEX_DEFAULT, memory_manager.memory_pool)) != APR_SUCCESS) {
00459                         abort();
00460                 }
00461 
00462                 apr_allocator_mutex_set(my_allocator, my_mutex);
00463                 apr_allocator_owner_set(my_allocator, memory_manager.memory_pool);
00464 #else
00465         apr_pool_create(&memory_manager.memory_pool, NULL);
00466         switch_assert(memory_manager.memory_pool != NULL);
00467 #endif
00468 
00469         switch_mutex_init(&memory_manager.mem_lock, SWITCH_MUTEX_NESTED, memory_manager.memory_pool);
00470         switch_queue_create(&memory_manager.pool_queue, 50000, memory_manager.memory_pool);
00471         switch_queue_create(&memory_manager.pool_recycle_queue, 50000, memory_manager.memory_pool);
00472 
00473         switch_threadattr_create(&thd_attr, memory_manager.memory_pool);
00474         switch_threadattr_detach_set(thd_attr, 1);
00475 
00476         switch_threadattr_stacksize_set(thd_attr, SWITCH_THREAD_STACKSIZE);
00477         switch_thread_create(&thread, thd_attr, pool_thread, NULL, memory_manager.memory_pool);
00478         
00479         while (!memory_manager.pool_thread_running) {
00480                 switch_yield(1000);
00481         }
00482 
00483         return memory_manager.memory_pool;
00484 }

Here is the call graph for this function:

void switch_core_memory_stop void   ) 
 

00428 {
00429         switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Stopping memory pool queue.\n");
00430         memory_manager.pool_thread_running = -1;
00431         while(memory_manager.pool_thread_running) {
00432                 switch_yield(1000);
00433         }
00434 }

Here is the call graph for this function:

void switch_core_session_init switch_memory_pool_t pool  ) 
 

00943 {
00944         memset(&session_manager, 0, sizeof(session_manager));
00945         session_manager.session_limit = 1000;
00946         session_manager.session_id = 1;
00947         session_manager.memory_pool = pool;
00948         switch_core_hash_init(&session_manager.session_table, session_manager.memory_pool);
00949 }

Here is the call graph for this function:

void switch_core_session_uninit void   ) 
 

00952 {
00953         switch_core_hash_destroy(&session_manager.session_table);
00954 }

Here is the call graph for this function:

void switch_core_sqldb_start switch_memory_pool_t pool  ) 
 

00369 {
00370         switch_thread_t *thread;
00371         switch_threadattr_t *thd_attr;;
00372 
00373         sql_manager.memory_pool = pool;
00374 
00375         /* Activate SQL database */
00376         if ((sql_manager.db = switch_core_db_handle()) == 0) {
00377                 switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Opening DB!\n");
00378                 switch_clear_flag((&runtime), SCF_USE_SQL);
00379         } else {
00380                 char create_complete_sql[] =
00381                         "CREATE TABLE complete (\n"
00382                         "   sticky  INTEGER,\n" 
00383                         "   a1  VARCHAR(255),\n" 
00384                         "   a2  VARCHAR(255),\n" 
00385                         "   a3  VARCHAR(255),\n" 
00386                         "   a4  VARCHAR(255),\n" 
00387                         "   a5  VARCHAR(255),\n" 
00388                         "   a6  VARCHAR(255),\n" 
00389                         "   a7  VARCHAR(255),\n" 
00390                         "   a8  VARCHAR(255),\n" 
00391                         "   a9  VARCHAR(255),\n" 
00392                         "   a10 VARCHAR(255)\n" 
00393                         ");\n";
00394 
00395                 char create_alias_sql[] =
00396                         "CREATE TABLE aliases (\n"
00397                         "   sticky  INTEGER,\n" 
00398                         "   alias  VARCHAR(255),\n" 
00399                         "   command  VARCHAR(255)\n" 
00400                         ");\n";
00401 
00402                 char create_channels_sql[] =
00403                         "CREATE TABLE channels (\n"
00404                         "   uuid  VARCHAR(255),\n"
00405                         "   created  VARCHAR(255),\n"
00406                         "   created_epoch  INTEGER,\n"
00407                         "   name  VARCHAR(255),\n"
00408                         "   state  VARCHAR(255),\n"
00409                         "   cid_name  VARCHAR(255),\n"
00410                         "   cid_num  VARCHAR(255),\n"
00411                         "   ip_addr  VARCHAR(255),\n"
00412                         "   dest  VARCHAR(255),\n"
00413                         "   application  VARCHAR(255),\n"
00414                         "   application_data  VARCHAR(255),\n"
00415                         "   dialplan VARCHAR(255),\n"
00416                         "   context VARCHAR(255),\n"
00417                         "   read_codec  VARCHAR(255),\n" 
00418                         "   read_rate  VARCHAR(255),\n" 
00419                         "   write_codec  VARCHAR(255),\n" 
00420                         "   write_rate  VARCHAR(255)\n" 
00421                         ");\n";
00422                 char create_calls_sql[] =
00423                         "CREATE TABLE calls (\n"
00424                         "   function  VARCHAR(255),\n"
00425                         "   created  VARCHAR(255),\n"
00426                         "   created_epoch  INTEGER,\n"
00427                         "   caller_cid_name  VARCHAR(255),\n"
00428                         "   caller_cid_num   VARCHAR(255),\n"
00429                         "   caller_dest_num  VARCHAR(255),\n"
00430                         "   caller_chan_name VARCHAR(255),\n"
00431                         "   caller_uuid      VARCHAR(255),\n"
00432                         "   callee_cid_name  VARCHAR(255),\n"
00433                         "   callee_cid_num   VARCHAR(255),\n"
00434                         "   callee_dest_num  VARCHAR(255),\n" 
00435                         "   callee_chan_name VARCHAR(255),\n" 
00436                         "   callee_uuid      VARCHAR(255)\n" 
00437                         ");\n";
00438                 char create_interfaces_sql[] =
00439                         "CREATE TABLE interfaces (\n"
00440                         "   type             VARCHAR(255),\n"
00441                         "   name             VARCHAR(255),\n" 
00442                         "   description      VARCHAR(255),\n" 
00443                         "   syntax           VARCHAR(255)\n" 
00444                         ");\n";
00445                 char create_tasks_sql[] =
00446                         "CREATE TABLE tasks (\n"
00447                         "   task_id             INTEGER(4),\n"
00448                         "   task_desc           VARCHAR(255),\n" 
00449                         "   task_group          VARCHAR(255),\n" 
00450                         "   task_sql_manager    INTEGER(8)\n" 
00451                         ");\n";
00452 
00453                 switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Opening DB\n");
00454                 switch_core_db_exec(sql_manager.db, "drop table channels", NULL, NULL, NULL);
00455                 switch_core_db_exec(sql_manager.db, "drop table calls", NULL, NULL, NULL);
00456                 switch_core_db_exec(sql_manager.db, "drop table interfaces", NULL, NULL, NULL);
00457                 switch_core_db_exec(sql_manager.db, "drop table tasks", NULL, NULL, NULL);
00458                 switch_core_db_exec(sql_manager.db, "PRAGMA synchronous=OFF;", NULL, NULL, NULL);
00459                 switch_core_db_exec(sql_manager.db, "PRAGMA count_changes=OFF;", NULL, NULL, NULL);
00460                 switch_core_db_exec(sql_manager.db, "PRAGMA cache_size=8000", NULL, NULL, NULL);
00461                 switch_core_db_exec(sql_manager.db, "PRAGMA temp_store=MEMORY;", NULL, NULL, NULL);
00462 
00463                 switch_core_db_test_reactive(sql_manager.db, "select sticky from complete", "DROP TABLE complete", create_complete_sql);
00464                 switch_core_db_test_reactive(sql_manager.db, "select sticky from aliases", "DROP TABLE aliases", create_alias_sql);
00465                 switch_core_db_exec(sql_manager.db, "delete from complete where sticky=0", NULL, NULL, NULL);
00466                 switch_core_db_exec(sql_manager.db, "delete from aliases where sticky=0", NULL, NULL, NULL);
00467                 switch_core_db_exec(sql_manager.db, create_channels_sql, NULL, NULL, NULL);
00468                 switch_core_db_exec(sql_manager.db, create_calls_sql, NULL, NULL, NULL);
00469                 switch_core_db_exec(sql_manager.db, create_interfaces_sql, NULL, NULL, NULL);
00470                 switch_core_db_exec(sql_manager.db, create_tasks_sql, NULL, NULL, NULL);
00471                 if (switch_event_bind("core_db", SWITCH_EVENT_ALL, SWITCH_EVENT_SUBCLASS_ANY, core_event_handler, NULL) != SWITCH_STATUS_SUCCESS) {
00472                         switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Couldn't bind event handler!\n");
00473                 }
00474         }
00475 
00476         switch_queue_create(&sql_manager.sql_queue, SWITCH_SQL_QUEUE_LEN, sql_manager.memory_pool);
00477         
00478         switch_threadattr_create(&thd_attr, sql_manager.memory_pool);
00479         switch_threadattr_detach_set(thd_attr, 1);
00480         switch_threadattr_stacksize_set(thd_attr, SWITCH_THREAD_STACKSIZE);
00481         switch_thread_create(&thread, thd_attr, switch_core_sql_thread, NULL, sql_manager.memory_pool);
00482         while (!sql_manager.thread_running) {
00483                 switch_yield(10000);
00484         }
00485 }

Here is the call graph for this function:

void switch_core_sqldb_stop void   ) 
 

00488 {
00489         switch_queue_push(sql_manager.sql_queue, NULL);
00490 
00491         switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Waiting for unfinished SQL transactions\n");
00492         while (switch_queue_size(sql_manager.sql_queue) > 0) {
00493                 switch_yield(10000);
00494         }
00495 
00496         switch_core_db_close(sql_manager.db);
00497         switch_core_db_close(sql_manager.event_db);
00498 
00499 }

Here is the call graph for this function:

void switch_core_state_machine_init switch_memory_pool_t pool  ) 
 

00251 {
00252         
00253         if (switch_test_flag((&runtime), SCF_CRASH_PROT)) {
00254                 sqlite3HashInit(&stack_table, SQLITE_HASH_BINARY, 0);
00255         }
00256 }


Variable Documentation

struct switch_runtime runtime
 


Generated on Mon May 26 22:06:52 2008 for FreeSWITCH by  doxygen 1.3.9.1