2007-03-29 22:34:40 +00:00
|
|
|
/*
|
|
|
|
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
|
2010-02-06 03:38:24 +00:00
|
|
|
* Copyright (C) 2005-2010, Anthony Minessale II <anthm@freeswitch.org>
|
2007-03-29 22:34:40 +00:00
|
|
|
*
|
|
|
|
* 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
|
2009-02-04 21:20:54 +00:00
|
|
|
* Anthony Minessale II <anthm@freeswitch.org>
|
2007-03-29 22:34:40 +00:00
|
|
|
* Portions created by the Initial Developer are Copyright (C)
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
*
|
2009-02-04 21:20:54 +00:00
|
|
|
* Anthony Minessale II <anthm@freeswitch.org>
|
2007-03-29 22:34:40 +00:00
|
|
|
* Michael Jerris <mike@jerris.com>
|
|
|
|
* Paul D. Tinsley <pdt at jackhammer.org>
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* switch_core_timer.c -- Main Core Library (timer interface)
|
|
|
|
*
|
|
|
|
*/
|
2008-01-27 17:36:53 +00:00
|
|
|
|
2007-03-29 22:34:40 +00:00
|
|
|
#include <switch.h>
|
2007-05-14 17:10:46 +00:00
|
|
|
#include "private/switch_core_pvt.h"
|
2007-03-29 22:34:40 +00:00
|
|
|
|
2008-05-27 04:30:03 +00: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 22:34:40 +00:00
|
|
|
{
|
|
|
|
switch_timer_interface_t *timer_interface;
|
|
|
|
switch_status_t status;
|
|
|
|
memset(timer, 0, sizeof(*timer));
|
2008-03-11 16:55:58 +00:00
|
|
|
if ((timer_interface = switch_loadable_module_get_timer_interface(timer_name)) == 0 || !timer_interface->timer_init) {
|
2007-03-29 22:34:40 +00:00
|
|
|
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;
|
2010-07-29 22:41:23 +00:00
|
|
|
timer->samplecount = samples;
|
2007-03-29 22:34:40 +00:00
|
|
|
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) {
|
2008-11-12 19:28:05 +00:00
|
|
|
UNPROTECT_INTERFACE(timer->timer_interface);
|
2007-03-29 22:34:40 +00:00
|
|
|
return status;
|
|
|
|
}
|
|
|
|
switch_set_flag(timer, SWITCH_TIMER_FLAG_FREE_POOL);
|
|
|
|
}
|
|
|
|
|
2009-10-23 16:33:55 +00:00
|
|
|
return timer->timer_interface->timer_init(timer);
|
2007-03-29 22:34:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SWITCH_DECLARE(switch_status_t) switch_core_timer_next(switch_timer_t *timer)
|
|
|
|
{
|
2008-03-11 16:55:58 +00:00
|
|
|
if (!timer->timer_interface || !timer->timer_interface->timer_next) {
|
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Timer is not properly configured.\n");
|
2007-03-29 22:34:40 +00: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)
|
|
|
|
{
|
2008-03-11 16:55:58 +00:00
|
|
|
if (!timer->timer_interface || !timer->timer_interface->timer_step) {
|
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Timer is not properly configured.\n");
|
2007-03-29 22:34:40 +00:00
|
|
|
return SWITCH_STATUS_GENERR;
|
|
|
|
}
|
|
|
|
|
|
|
|
return timer->timer_interface->timer_step(timer);
|
|
|
|
}
|
|
|
|
|
2008-03-11 16:55:58 +00:00
|
|
|
|
|
|
|
SWITCH_DECLARE(switch_status_t) switch_core_timer_sync(switch_timer_t *timer)
|
|
|
|
{
|
|
|
|
if (!timer->timer_interface || !timer->timer_interface->timer_sync) {
|
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Timer is not properly configured.\n");
|
|
|
|
return SWITCH_STATUS_GENERR;
|
|
|
|
}
|
|
|
|
|
|
|
|
return timer->timer_interface->timer_sync(timer);
|
|
|
|
}
|
|
|
|
|
|
|
|
SWITCH_DECLARE(switch_status_t) switch_core_timer_check(switch_timer_t *timer, switch_bool_t step)
|
2007-03-29 22:34:40 +00:00
|
|
|
{
|
2008-03-11 16:55:58 +00:00
|
|
|
if (!timer->timer_interface || !timer->timer_interface->timer_check) {
|
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Timer is not properly configured.\n");
|
2007-03-29 22:34:40 +00:00
|
|
|
return SWITCH_STATUS_GENERR;
|
|
|
|
}
|
|
|
|
|
2008-03-11 16:55:58 +00:00
|
|
|
return timer->timer_interface->timer_check(timer, step);
|
2007-03-29 22:34:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SWITCH_DECLARE(switch_status_t) switch_core_timer_destroy(switch_timer_t *timer)
|
|
|
|
{
|
2008-03-11 16:55:58 +00:00
|
|
|
if (!timer->timer_interface || !timer->timer_interface->timer_destroy) {
|
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Timer is not properly configured.\n");
|
2007-03-29 22:34:40 +00:00
|
|
|
return SWITCH_STATUS_GENERR;
|
|
|
|
}
|
|
|
|
|
|
|
|
timer->timer_interface->timer_destroy(timer);
|
2008-11-12 19:28:05 +00:00
|
|
|
UNPROTECT_INTERFACE(timer->timer_interface);
|
2007-03-29 22:34:40 +00:00
|
|
|
|
|
|
|
if (switch_test_flag(timer, SWITCH_TIMER_FLAG_FREE_POOL)) {
|
|
|
|
switch_core_destroy_memory_pool(&timer->memory_pool);
|
|
|
|
}
|
|
|
|
|
2008-10-30 12:46:09 +00:00
|
|
|
memset(timer, 0, sizeof(*timer));
|
|
|
|
|
2007-03-29 22:34:40 +00:00
|
|
|
return SWITCH_STATUS_SUCCESS;
|
|
|
|
}
|
2008-01-27 05:02:52 +00:00
|
|
|
|
|
|
|
/* For Emacs:
|
|
|
|
* Local Variables:
|
|
|
|
* mode:c
|
2008-02-03 22:14:57 +00:00
|
|
|
* indent-tabs-mode:t
|
2008-01-27 05:02:52 +00:00
|
|
|
* tab-width:4
|
|
|
|
* c-basic-offset:4
|
|
|
|
* End:
|
|
|
|
* For VIM:
|
2008-07-03 19:12:26 +00:00
|
|
|
* vim:set softtabstop=4 shiftwidth=4 tabstop=4:
|
2008-01-27 05:02:52 +00:00
|
|
|
*/
|