Author: sayer Date: 2009-03-25 20:48:58 +0100 (Wed, 25 Mar 2009) New Revision: 1337
Added: trunk/apps/dsm/mods/mod_utils/ trunk/apps/dsm/mods/mod_utils/Makefile trunk/apps/dsm/mods/mod_utils/ModUtils.cpp trunk/apps/dsm/mods/mod_utils/ModUtils.h trunk/apps/dsm/mods/mod_utils/Readme.mod_utils.txt Log: Module with some smaller heler functions: getNewId playCount This work was kindly sponsored by Teltech Systems Inc. Added: trunk/apps/dsm/mods/mod_utils/Makefile =================================================================== --- trunk/apps/dsm/mods/mod_utils/Makefile 2009-03-25 19:47:42 UTC (rev 1336) +++ trunk/apps/dsm/mods/mod_utils/Makefile 2009-03-25 19:48:58 UTC (rev 1337) @@ -0,0 +1,10 @@ +plug_in_name = mod_utils + +DSMPATH ?= ../.. + +module_ldflags = +module_cflags = -DMOD_NAME=\"$(plug_in_name)\" -I$(DSMPATH) + +COREPATH ?=$(DSMPATH)/../../core +lib_full_name = $(DSMPATH)/mods/lib/$(lib_name) +include $(DSMPATH)/mods/Makefile.dsm_module Property changes on: trunk/apps/dsm/mods/mod_utils/Makefile ___________________________________________________________________ Name: svn:eol-style + native Added: trunk/apps/dsm/mods/mod_utils/ModUtils.cpp =================================================================== --- trunk/apps/dsm/mods/mod_utils/ModUtils.cpp 2009-03-25 19:47:42 UTC (rev 1336) +++ trunk/apps/dsm/mods/mod_utils/ModUtils.cpp 2009-03-25 19:48:58 UTC (rev 1337) @@ -0,0 +1,145 @@ +/* + * $Id$ + * + * Copyright (C) 2009 Teltech Systems Inc. + * + * This file is part of SEMS, a free SIP media server. + * + * sems is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version + * + * For a license to use the SEMS software under conditions + * other than those described here, or to purchase support for this + * software, please contact iptel.org by e-mail at the following addresses: + * [email protected] + * + * SEMS is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +#include "ModUtils.h" +#include "log.h" +#include "AmUtils.h" +#include <math.h> + +#include "DSMSession.h" +#include "AmSession.h" + +SC_EXPORT(SCUtilsModule); + +SCUtilsModule::SCUtilsModule() { +} + +SCUtilsModule::~SCUtilsModule() { +} + +void splitCmd(const string& from_str, + string& cmd, string& params) { + size_t b_pos = from_str.find('('); + if (b_pos != string::npos) { + cmd = from_str.substr(0, b_pos); + params = from_str.substr(b_pos + 1, from_str.rfind(')') - b_pos -1); + } else + cmd = from_str; +} + +DSMAction* SCUtilsModule::getAction(const string& from_str) { + string cmd; + string params; + splitCmd(from_str, cmd, params); + + DEF_CMD("utils.playCountRight", SCUPlayCountRightAction); + DEF_CMD("utils.playCountLeft", SCUPlayCountLeftAction); + DEF_CMD("utils.getNewId", SCGetNewIdAction); + + return NULL; +} + +DSMCondition* SCUtilsModule::getCondition(const string& from_str) { + string cmd; + string params; + splitCmd(from_str, cmd, params); + + return NULL; +} + +bool utils_play_count(DSMSession* sc_sess, unsigned int cnt, + const string& basedir, const string& suffix, bool right) { + + if (cnt <= 20) { + sc_sess->playFile(basedir+int2str(cnt)+suffix, false); + return false; + } + + for (int i=9;i>1;i--) { + div_t num = div(cnt, (int)exp10(i)); + if (num.quot) { + sc_sess->playFile(basedir+int2str(int(num.quot * exp10(i)))+suffix, false); + } + cnt = num.rem; + } + + if (!cnt) + return false; + + if ((cnt <= 20) || (!(cnt%10))) { + sc_sess->playFile(basedir+int2str(cnt)+suffix, false); + return false; + } + + div_t num = div(cnt, 10); + if (right) { + // language has single digits before 10s + sc_sess->playFile(basedir+int2str(num.quot * 10)+suffix, false); + sc_sess->playFile(basedir+("x"+int2str(num.rem))+suffix, false); + } else { + // language has single digits before 10s + sc_sess->playFile(basedir+("x"+int2str(num.rem))+suffix, false); + sc_sess->playFile(basedir+int2str(num.quot * 10)+suffix, false); + } + + return false; +} + +CONST_ACTION_2P(SCUPlayCountRightAction, ',', true); +EXEC_ACTION_START(SCUPlayCountRightAction) { + string basedir = resolveVars(par2, sess, sc_sess, event_params); + + unsigned int cnt = 0; + if (str2i(resolveVars(par1, sess, sc_sess, event_params),cnt)) { + ERROR("could not parse count '%s'\n", + resolveVars(par1, sess, sc_sess, event_params).c_str()); + sc_sess->SET_ERRNO(DSM_ERRNO_UNKNOWN_ARG); + return false; + } + + return utils_play_count(sc_sess, cnt, basedir, ".wav", true); +} EXEC_ACTION_END; + + +CONST_ACTION_2P(SCUPlayCountLeftAction, ',', true); +EXEC_ACTION_START(SCUPlayCountLeftAction) { + string basedir = resolveVars(par2, sess, sc_sess, event_params); + + unsigned int cnt = 0; + if (str2i(resolveVars(par1, sess, sc_sess, event_params),cnt)) { + ERROR("could not parse count '%s'\n", + resolveVars(par1, sess, sc_sess, event_params).c_str()); + sc_sess->SET_ERRNO(DSM_ERRNO_UNKNOWN_ARG); + return false; + } + + return utils_play_count(sc_sess, cnt, basedir, ".wav", false); +} EXEC_ACTION_END; + +EXEC_ACTION_START(SCGetNewIdAction) { + string d = resolveVars(arg, sess, sc_sess, event_params); + sc_sess->var[d]=AmSession::getNewId(); +} EXEC_ACTION_END; Property changes on: trunk/apps/dsm/mods/mod_utils/ModUtils.cpp ___________________________________________________________________ Name: svn:keywords + Id Name: svn:eol-style + native Added: trunk/apps/dsm/mods/mod_utils/ModUtils.h =================================================================== --- trunk/apps/dsm/mods/mod_utils/ModUtils.h 2009-03-25 19:47:42 UTC (rev 1336) +++ trunk/apps/dsm/mods/mod_utils/ModUtils.h 2009-03-25 19:48:58 UTC (rev 1337) @@ -0,0 +1,46 @@ +/* + * $Id$ + * + * Copyright (C) 2009 Teltech Systems Inc. + * + * This file is part of SEMS, a free SIP media server. + * + * sems is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version + * + * For a license to use the SEMS software under conditions + * other than those described here, or to purchase support for this + * software, please contact iptel.org by e-mail at the following addresses: + * [email protected] + * + * SEMS is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +#ifndef _MOD_UTILS_H +#define _MOD_UTILS_H +#include "DSMModule.h" + +class SCUtilsModule +: public DSMModule { + + public: + SCUtilsModule(); + ~SCUtilsModule(); + + DSMAction* getAction(const string& from_str); + DSMCondition* getCondition(const string& from_str); +}; + +DEF_ACTION_2P(SCUPlayCountRightAction); +DEF_ACTION_2P(SCUPlayCountLeftAction); +DEF_ACTION_1P(SCGetNewIdAction); + +#endif Property changes on: trunk/apps/dsm/mods/mod_utils/ModUtils.h ___________________________________________________________________ Name: svn:keywords + Id Name: svn:eol-style + native Added: trunk/apps/dsm/mods/mod_utils/Readme.mod_utils.txt =================================================================== --- trunk/apps/dsm/mods/mod_utils/Readme.mod_utils.txt 2009-03-25 19:47:42 UTC (rev 1336) +++ trunk/apps/dsm/mods/mod_utils/Readme.mod_utils.txt 2009-03-25 19:48:58 UTC (rev 1337) @@ -0,0 +1,8 @@ +Actions: + utils.getNewId(string varname) + -- play count for laguages that have single digits after the 10s (like english) + utils.playCountRight(int cnt [, string basedir) + -- play count for laguages that have single digits befire the 10s (like german) + utils.playCountLeft(int cnt [, string basedir) + +Conditions: Property changes on: trunk/apps/dsm/mods/mod_utils/Readme.mod_utils.txt ___________________________________________________________________ Name: svn:eol-style + native _______________________________________________ Semsdev mailing list [email protected] http://lists.iptel.org/mailman/listinfo/semsdev
