2007-03-29 18:34:40 -04:00
|
|
|
/*
|
|
|
|
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
|
|
|
|
* Copyright (C) 2005/2006, Anthony Minessale II <anthmct@yahoo.com>
|
|
|
|
*
|
|
|
|
* Version: MPL 1.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Anthony Minessale II <anthmct@yahoo.com>
|
|
|
|
* Portions created by the Initial Developer are Copyright (C)
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
*
|
|
|
|
* Anthony Minessale II <anthmct@yahoo.com>
|
|
|
|
* Michael Jerris <mike@jerris.com>
|
|
|
|
* Paul D. Tinsley <pdt at jackhammer.org>
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* switch_core_timer.c -- Main Core Library (timer interface)
|
|
|
|
*
|
|
|
|
*/
|
2008-01-27 12:36:53 -05:00
|
|
|
|
2007-03-29 18:34:40 -04:00
|
|
|
#include <switch.h>
|
2007-05-14 13:10:46 -04:00
|
|
|
#include "private/switch_core_pvt.h"
|
2007-03-29 18:34:40 -04:00
|
|
|
|
2007-11-01 07:28:26 -04:00
|
|
|
SWITCH_DECLARE(switch_status_t) switch_core_timer_init(switch_timer_t *timer, const char *timer_name, int interval, int samples, switch_memory_pool_t *pool)
|
2007-03-29 18:34:40 -04:00
|
|
|
{
|
|
|
|
switch_timer_interface_t *timer_interface;
|
|
|
|
switch_status_t status;
|
|
|
|
memset(timer, 0, sizeof(*timer));
|
|
|
|
if ((timer_interface = switch_loadable_module_get_timer_interface(timer_name)) == 0) {
|
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "invalid timer %s!\n", timer_name);
|
|
|
|
return SWITCH_STATUS_GENERR;
|
|
|
|
}
|
|
|
|
|
|
|
|
timer->interval = interval;
|
|
|
|
timer->samples = samples;
|
|
|
|
timer->samplecount = 0;
|
|
|
|
timer->timer_interface = timer_interface;
|
|
|
|
|
|
|
|
if (pool) {
|
|
|
|
timer->memory_pool = pool;
|
|
|
|
} else {
|
|
|
|
if ((status = switch_core_new_memory_pool(&timer->memory_pool)) != SWITCH_STATUS_SUCCESS) {
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
switch_set_flag(timer, SWITCH_TIMER_FLAG_FREE_POOL);
|
|
|
|
}
|
|
|
|
|
|
|
|
timer->timer_interface->timer_init(timer);
|
|
|
|
return SWITCH_STATUS_SUCCESS;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
SWITCH_DECLARE(switch_status_t) switch_core_timer_next(switch_timer_t *timer)
|
|
|
|
{
|
|
|
|
if (!timer->timer_interface) {
|
2008-01-07 06:21:24 -05:00
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Timer is not initialized!\n");
|
2007-03-29 18:34:40 -04:00
|
|
|
return SWITCH_STATUS_GENERR;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (timer->timer_interface->timer_next(timer) == SWITCH_STATUS_SUCCESS) {
|
|
|
|
return SWITCH_STATUS_SUCCESS;
|
|
|
|
} else {
|
|
|
|
return SWITCH_STATUS_GENERR;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
SWITCH_DECLARE(switch_status_t) switch_core_timer_step(switch_timer_t *timer)
|
|
|
|
{
|
|
|
|
if (!timer->timer_interface) {
|
2008-01-07 06:21:24 -05:00
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Timer is not initialized!\n");
|
2007-03-29 18:34:40 -04:00
|
|
|
return SWITCH_STATUS_GENERR;
|
|
|
|
}
|
|
|
|
|
|
|
|
return timer->timer_interface->timer_step(timer);
|
|
|
|
}
|
|
|
|
|
|
|
|
SWITCH_DECLARE(switch_status_t) switch_core_timer_check(switch_timer_t *timer)
|
|
|
|
{
|
|
|
|
if (!timer->timer_interface) {
|
2008-01-07 06:21:24 -05:00
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Timer is not initialized!\n");
|
2007-03-29 18:34:40 -04:00
|
|
|
return SWITCH_STATUS_GENERR;
|
|
|
|
}
|
|
|
|
|
|
|
|
return timer->timer_interface->timer_check(timer);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SWITCH_DECLARE(switch_status_t) switch_core_timer_destroy(switch_timer_t *timer)
|
|
|
|
{
|
|
|
|
if (!timer->timer_interface) {
|
2008-01-07 06:21:24 -05:00
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Timer is not initialized!\n");
|
2007-03-29 18:34:40 -04:00
|
|
|
return SWITCH_STATUS_GENERR;
|
|
|
|
}
|
|
|
|
|
|
|
|
timer->timer_interface->timer_destroy(timer);
|
|
|
|
|
|
|
|
if (switch_test_flag(timer, SWITCH_TIMER_FLAG_FREE_POOL)) {
|
|
|
|
switch_core_destroy_memory_pool(&timer->memory_pool);
|
|
|
|
}
|
|
|
|
|
|
|
|
return SWITCH_STATUS_SUCCESS;
|
|
|
|
}
|
2008-01-27 00:02:52 -05:00
|
|
|
|
|
|
|
/* For Emacs:
|
|
|
|
* Local Variables:
|
|
|
|
* mode:c
|
2008-01-27 15:01:02 -05:00
|
|
|
* indent-tabs-mode:nil
|
2008-01-27 00:02:52 -05:00
|
|
|
* tab-width:4
|
|
|
|
* c-basic-offset:4
|
|
|
|
* End:
|
|
|
|
* For VIM:
|
|
|
|
* vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab:
|
|
|
|
*/
|