freeswitch之入口函数

数据结构

该结构包含了若干的哈希表指针,分别指向存放各个接口结构的哈希表。

struct switch_loadable_module_container {
	switch_hash_t *module_hash;
	switch_hash_t *endpoint_hash;
	switch_hash_t *codec_hash;
	switch_hash_t *dialplan_hash;
	switch_hash_t *timer_hash;
	switch_hash_t *application_hash;
	switch_hash_t *chat_application_hash;
	switch_hash_t *api_hash;
	switch_hash_t *json_api_hash;
	switch_hash_t *file_hash;
	switch_hash_t *speech_hash;
	switch_hash_t *asr_hash;
	switch_hash_t *directory_hash
	switch_hash_t *chat_hash;
	switch_hash_t *say_hash;
	switch_hash_t *management_hash;
	switch_hash_t *limit_hash;
	switch_hash_t *database_hash;
	switch_hash_t *secondary_recover_hash;
	switch_mutex_t *mutex;
	switch_memory_pool_t *pool;
};

入口

switch.c

Main

	=>命令行解析
	=>apr_initialize   
	//初始化apr库是由apr_initialize()函数完成的,apr库是apache的可移植动态库,完成相关的内存池,线程管理的跨平台工作
	=>switch_core_set_globals
	//完成全局目录的设置
	=>apr_pool_create
	//创建匿名内存池,供程序整个内存周期所使用。
	=>switch_core_init_and_modload
		=>switch_core_init
		=>switch_loadable_module_init
			=>switch_core_hash_init
			=>switch_loadable_module_load_module_ex   //动态对象的加载
			=>switch_loadable_module_runtime
				=>switch_loadable_module_exec
				=>switch_loadable_module_process(file,new_module)
				//函数主要是将new_module以及module中定义的各个接口结构加入全局哈希表,在插入哈希表的过程中,由loadable_modules.mutex进行临界保护
				=>switch_core_hash_insert(loadable_modules.module_hash, key,new_module);//将new_module 插入loadable_modules.module_hash指向的哈希表。
			至此,模块加载也结束了。各个模块加载后各自进入自己的主线程中循环处理

状态机的初始化

	switch.c  : main
	
	switch_core_init_and_modload
	    => switch_core_init
	        => switch_core_session_init
	            => switch_core_session_thread_pool_manager
	                => check_queue
	                    => switch_core_session_thread_pool_worker
	                        => switch_core_session_thread
	                            => switch_core_session_run
	
	通过调用switch_channel_set_state来实现状态机的状态改变
	当状态发生变化后,通过switch_channel_set_running_state函数来改变running_state,并执行相关的回调来通知其状态已经发生改变:endpoint_interface->io_routines->state_run
	
	以sofia为例:
	在SWITCH_MODULE_LOAD_FUNCTION(mod_sofia_load)中注册回调:
	sofia_endpoint_interface->io_routines = &sofia_io_routines;
	sofia_endpoint_interface->state_handler = &sofia_event_handlers;
	switch_state_handler_table_t sofia_event_handlers = {
		/*.on_init */ sofia_on_init,
		/*.on_routing */ sofia_on_routing,
		/*.on_execute */ sofia_on_execute,
		/*.on_hangup */ sofia_on_hangup,
		/*.on_exchange_media */ sofia_on_exchange_media,
		/*.on_soft_execute */ sofia_on_soft_execute,
		/*.on_consume_media */ NULL,
		/*.on_hibernate */ sofia_on_hibernate,
		/*.on_reset */ sofia_on_reset,
		/*.on_park */ NULL,
		/*.on_reporting */ NULL,
		/*.on_destroy */ sofia_on_destroy
	};

©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页