[Freeswitch-branches] [commit] r3436 - freeswitch/branches/mishehu/src/mod/event_handlers/mod_cdr
Freeswitch SVN
mishehu at freeswitch.org
Wed Nov 22 00:43:07 EST 2006
Author: mishehu
Date: Wed Nov 22 00:43:05 2006
New Revision: 3436
Modified:
freeswitch/branches/mishehu/src/mod/event_handlers/mod_cdr/cdrcontainer.cpp
freeswitch/branches/mishehu/src/mod/event_handlers/mod_cdr/cdrcontainer.h
freeswitch/branches/mishehu/src/mod/event_handlers/mod_cdr/mod_cdr.cpp
freeswitch/branches/mishehu/src/mod/event_handlers/mod_cdr/mysqlcdr.cpp
freeswitch/branches/mishehu/src/mod/event_handlers/mod_cdr/pddcdr.cpp
Log:
Made a reload capability for mod_cdr (depends on changes yet unpublished to apr-util's apr_queue), but have not yet tested it. Also fixed lingering ani2's in mysqlcdr.cpp that somehow stuck around in this branch.
Modified: freeswitch/branches/mishehu/src/mod/event_handlers/mod_cdr/cdrcontainer.cpp
==============================================================================
--- freeswitch/branches/mishehu/src/mod/event_handlers/mod_cdr/cdrcontainer.cpp (original)
+++ freeswitch/branches/mishehu/src/mod/event_handlers/mod_cdr/cdrcontainer.cpp Wed Nov 22 00:43:05 2006
@@ -45,8 +45,7 @@
// Create the APR threadsafe queue, though I don't know if this is the current memory pool.
switch_queue_create(&cdrqueue,5224288, module_pool);
- char *configfile = "mod_cdr.conf";
- switch_xml_t cfg, xml, settings, param;
+ strcpy(configfile,"mod_cdr.conf");
switch_mod_cdr_newchannel_t *newchannel; // = new switch_mod_cdr_newchannel_t;
newchannel = 0;
@@ -89,6 +88,45 @@
}
switch_console_printf(SWITCH_CHANNEL_LOG,"mod_cdr shutdown gracefully.");
+}
+
+void CDRContainer::reload()
+{
+ // Something tells me I still need to figure out what to do if there are items still in queue after reload that are no longer active in the configuration.
+ switch_queue_isempty(cdrqueue); // Waits for the queue to be empty
+
+ switch_mod_cdr_newchannel_t *newchannel; // = new switch_mod_cdr_newchannel_t;
+ newchannel = 0;
+
+ if (!(xml = switch_xml_open_cfg(configfile, &cfg, NULL)))
+ switch_console_printf(SWITCH_CHANNEL_LOG,"open of %s failed\n", configfile);
+ else
+ {
+ BaseRegistry& registry(BaseRegistry::get());
+ registry.reset_active();
+ for(BaseRegistry::iterator it = registry.active_begin(); it != registry.active_end(); ++it)
+ {
+ basecdr_creator func = *it;
+ BaseCDR* _ptr = func(newchannel);
+ std::auto_ptr<BaseCDR> ptr(_ptr);
+ ptr->disconnect();
+ }
+
+ for(BaseRegistry::iterator it = registry.begin(); it != registry.end(); ++it)
+ {
+ basecdr_creator func = *it;
+ BaseCDR* _ptr = func(newchannel);
+ std::auto_ptr<BaseCDR> ptr(_ptr);
+ ptr->connect(cfg,xml,settings,param);
+
+ if(ptr->is_activated())
+ registry.add_active(it);
+ }
+ }
+
+ switch_xml_free(xml);
+ switch_queue_unblockpop(cdrqueue);
+ switch_console_printf(SWITCH_CHANNEL_LOG,"mod_cdr configuration reloaded.");
}
void CDRContainer::add_cdr(switch_core_session_t *session)
Modified: freeswitch/branches/mishehu/src/mod/event_handlers/mod_cdr/cdrcontainer.h
==============================================================================
--- freeswitch/branches/mishehu/src/mod/event_handlers/mod_cdr/cdrcontainer.h (original)
+++ freeswitch/branches/mishehu/src/mod/event_handlers/mod_cdr/cdrcontainer.h Wed Nov 22 00:43:05 2006
@@ -58,10 +58,13 @@
~CDRContainer();
void add_cdr(switch_core_session_t *session);
void process_records();
+ void reload();
protected:
private:
+ switch_xml_t cfg, xml, settings, param;
switch_queue_t *cdrqueue;
std::string tempfilepath;
+ char configfile[13];
};
#ifdef __cplusplus
Modified: freeswitch/branches/mishehu/src/mod/event_handlers/mod_cdr/mod_cdr.cpp
==============================================================================
--- freeswitch/branches/mishehu/src/mod/event_handlers/mod_cdr/mod_cdr.cpp (original)
+++ freeswitch/branches/mishehu/src/mod/event_handlers/mod_cdr/mod_cdr.cpp Wed Nov 22 00:43:05 2006
@@ -44,6 +44,8 @@
static CDRContainer *newcdrcontainer;
static switch_memory_pool_t *module_pool;
static switch_status_t my_on_hangup(switch_core_session_t *session);
+static switch_status_t modcdr_reload(char *dest, switch_core_session_t *isession, switch_stream_handle_t *stream);
+static switch_thread_rwlock_t *cdr_rwlock;
/* Now begins the glue that will tie this into the system.
*/
@@ -57,18 +59,29 @@
/*.on_transmit */ NULL
};
+static switch_api_interface_t modcdr_reload_interface = {
+ /*.interface_name */ "modcdr_reload",
+ /*.desc */ "Reload mod_cdr's configuration",
+ /*.function */ modcdr_reload,
+ /*.syntax */ "modcdr_reload",
+ /*.next */ 0
+};
+
static const switch_loadable_module_interface_t cdr_module_interface = {
/*.module_name */ modname,
/*.endpoint_interface */ NULL,
/*.timer_interface */ NULL,
/*.dialplan_interface */ NULL,
/*.codec_interface */ NULL,
- /*.application_interface */ NULL
+ /*.application_interface */ NULL,
+ /* api_interface */ &modcdr_reload_interface
};
static switch_status_t my_on_hangup(switch_core_session_t *session)
{
+ switch_thread_rwlock_rdlock(cdr_rwlock);
newcdrcontainer->add_cdr(session);
+ switch_thread_rwlock_unlock(cdr_rwlock);
return SWITCH_STATUS_SUCCESS;
}
@@ -85,6 +98,7 @@
return SWITCH_STATUS_TERM;
}
+ switch_thread_rwlock_create(&cdr_rwlock,module_pool);
newcdrcontainer = new CDRContainer(module_pool); // Instantiates the new object, automatically loads config
/* indicate that the module should continue to be loaded */
@@ -100,8 +114,17 @@
return RUNNING ? SWITCH_STATUS_SUCCESS : SWITCH_STATUS_TERM;
}
+static switch_status_t modcdr_reload(char *dest=0, switch_core_session_t *isession=0, switch_stream_handle_t *stream=0)
+{
+ switch_thread_rwlock_wrlock(cdr_rwlock);
+ newcdrcontainer->reload();
+ switch_thread_rwlock_unlock(cdr_rwlock);
+ return SWITCH_STATUS_SUCCESS;
+}
+
SWITCH_MOD_DECLARE(switch_status_t) switch_module_shutdown(void)
{
delete newcdrcontainer;
+ switch_thread_rwlock_destroy(cdr_rwlock);
return SWITCH_STATUS_SUCCESS;
}
Modified: freeswitch/branches/mishehu/src/mod/event_handlers/mod_cdr/mysqlcdr.cpp
==============================================================================
--- freeswitch/branches/mishehu/src/mod/event_handlers/mod_cdr/mysqlcdr.cpp (original)
+++ freeswitch/branches/mishehu/src/mod/event_handlers/mod_cdr/mysqlcdr.cpp Wed Nov 22 00:43:05 2006
@@ -54,7 +54,7 @@
src_length = (long unsigned int)strlen(src);
dst_length = (long unsigned int)strlen(dst);
ani_length = (long unsigned int)strlen(ani);
- ani2_length = (long unsigned int)strlen(ani2);
+ aniii_length = (long unsigned int)strlen(aniii);
dialplan_length = (long unsigned int)strlen(dialplan);
myuuid_length = (long unsigned int)strlen(myuuid);
destuuid_length = (long unsigned int)strlen(destuuid);
@@ -181,7 +181,7 @@
if(activated)
{
- tmp_sql_query = "INSERT INTO freeswitchcdr (callstartdate,callanswerdate,callenddate,originated,clid,src,dst,ani,ani2,dialplan,myuuid,destuuid,srcchannel,dstchannel,lastapp,lastdata,billusec,disposition,hangupcause,amaflags";
+ tmp_sql_query = "INSERT INTO freeswitchcdr (callstartdate,callanswerdate,callenddate,originated,clid,src,dst,ani,aniii,dialplan,myuuid,destuuid,srcchannel,dstchannel,lastapp,lastdata,billusec,disposition,hangupcause,amaflags";
int items_appended = 0;
@@ -324,7 +324,7 @@
add_string_parameter(src,src_length,MYSQL_TYPE_VAR_STRING,0);
add_string_parameter(dst,dst_length,MYSQL_TYPE_VAR_STRING,0);
add_string_parameter(ani,ani_length,MYSQL_TYPE_VAR_STRING,0);
- add_string_parameter(ani2,ani2_length,MYSQL_TYPE_VAR_STRING,0);
+ add_string_parameter(aniii,aniii_length,MYSQL_TYPE_VAR_STRING,0);
add_string_parameter(dialplan,dialplan_length,MYSQL_TYPE_VAR_STRING,0);
add_string_parameter(myuuid,myuuid_length,MYSQL_TYPE_VAR_STRING,0);
add_string_parameter(destuuid,destuuid_length,MYSQL_TYPE_VAR_STRING,0);
Modified: freeswitch/branches/mishehu/src/mod/event_handlers/mod_cdr/pddcdr.cpp
==============================================================================
--- freeswitch/branches/mishehu/src/mod/event_handlers/mod_cdr/pddcdr.cpp (original)
+++ freeswitch/branches/mishehu/src/mod/event_handlers/mod_cdr/pddcdr.cpp Wed Nov 22 00:43:05 2006
@@ -210,6 +210,11 @@
void PddCDR::disconnect()
{
+ activated = 0;
+ connectionstate = 0;
+ logchanvars = 0;
+ outputfile_path.clear();
+ chanvars_supp_list.clear();
switch_console_printf(SWITCH_CHANNEL_LOG,"Shutting down PddCDR... Done!");
}
More information about the Freeswitch-branches
mailing list