Author: sayer Date: 2009-05-07 00:50:04 +0200 (Thu, 07 May 2009) New Revision: 1367
Added: trunk/apps/dsm/mods/mod_py/ trunk/apps/dsm/mods/mod_py/Makefile trunk/apps/dsm/mods/mod_py/ModPy.cpp trunk/apps/dsm/mods/mod_py/ModPy.h trunk/apps/dsm/mods/mod_py/PyDSM.cpp trunk/apps/dsm/mods/mod_py/PyDSM.h trunk/apps/dsm/mods/mod_py/PyDSMSession.cpp trunk/apps/dsm/mods/mod_py/PyDSMSession.h trunk/apps/dsm/mods/mod_py/python_inc.py trunk/apps/dsm/mods/mod_py/python_lib.py Log: mod_py : module with py(...) action and condition Added: trunk/apps/dsm/mods/mod_py/Makefile =================================================================== --- trunk/apps/dsm/mods/mod_py/Makefile 2009-05-06 16:46:38 UTC (rev 1366) +++ trunk/apps/dsm/mods/mod_py/Makefile 2009-05-06 22:50:04 UTC (rev 1367) @@ -0,0 +1,34 @@ +plug_in_name = mod_py + +PYTHON_VERSION ?= $(shell python -c 'import sys;print sys.version[0:3]') +PY_VER = $(PYTHON_VERSION) +PY_EXE = python$(PY_VER) + +DSMPATH ?= ../.. + +PYTHON_DIR = $(shell $(PY_EXE) ./python_inc.py) +PYTHON_LIBDIR = $(shell $(PY_EXE) ./python_lib.py) + +PYTHON_module_cflags = -I$(PYTHON_DIR) -fno-strict-aliasing + +PYTHON_module_ldflags = -L$(PYTHON_LIBDIR)/config \ + -lpython$(PY_VER) + +module_ldflags = -lutil \ + $(PYTHON_module_ldflags) \ + +module_cflags = \ + $(PYTHON_module_cflags) \ + $(module_additional_cflags) \ + -DMOD_NAME=\"$(plug_in_name)\" -I$(DSMPATH) + +py_src = $(notdir $(wildcard py/*.py)) +py_obj = $(py_src:.py=.pyc) + +COREPATH ?=$(DSMPATH)/../../core +lib_full_name = $(DSMPATH)/mods/lib/$(lib_name) +include $(DSMPATH)/mods/Makefile.dsm_module + +ifneq ($(OS),darwin) +PYTHON_module_ldflags += -Xlinker --export-dynamic +endif \ No newline at end of file Property changes on: trunk/apps/dsm/mods/mod_py/Makefile ___________________________________________________________________ Name: svn:eol-style + native Added: trunk/apps/dsm/mods/mod_py/ModPy.cpp =================================================================== --- trunk/apps/dsm/mods/mod_py/ModPy.cpp 2009-05-06 16:46:38 UTC (rev 1366) +++ trunk/apps/dsm/mods/mod_py/ModPy.cpp 2009-05-06 22:50:04 UTC (rev 1367) @@ -0,0 +1,234 @@ +/* + * $Id$ + * + * Copyright (C) 2009 IPTEGO GmbH + * + * 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 "ModPy.h" +#include "log.h" +#include "AmUtils.h" + +#include "DSMSession.h" +#include "AmSession.h" +#include "PyDSMSession.h" +#include "PyDSM.h" + +struct PythonGIL +{ + PyGILState_STATE gst; + + PythonGIL() { gst = PyGILState_Ensure(); } + ~PythonGIL(){ PyGILState_Release(gst); } +}; +#define PYLOCK PythonGIL _py_gil + +SC_EXPORT(SCPyModule); + +PyObject* SCPyModule::dsm_module = NULL; +PyObject* SCPyModule::session_module = NULL; + +SCPyModule::SCPyModule() { + if(!Py_IsInitialized()){ + Py_Initialize(); + DBG("Python version %s\n", Py_GetVersion()); + } + + PyImport_AddModule("dsm"); + dsm_module = Py_InitModule("dsm",mod_py_methods); + PyModule_AddIntConstant(dsm_module, "Any", DSMCondition::Any); + PyModule_AddIntConstant(dsm_module, "Invite", DSMCondition::Invite); + PyModule_AddIntConstant(dsm_module, "SessionStart", DSMCondition::SessionStart); + PyModule_AddIntConstant(dsm_module, "Key", DSMCondition::Key); + PyModule_AddIntConstant(dsm_module, "Timer", DSMCondition::Timer); + PyModule_AddIntConstant(dsm_module, "NoAudio", DSMCondition::NoAudio); + PyModule_AddIntConstant(dsm_module, "Hangup", DSMCondition::Hangup); + PyModule_AddIntConstant(dsm_module, "Hold", DSMCondition::Hold); + PyModule_AddIntConstant(dsm_module, "UnHold", DSMCondition::UnHold); + PyModule_AddIntConstant(dsm_module, "XmlrpcResponse", DSMCondition::XmlrpcResponse); + PyModule_AddIntConstant(dsm_module, "DSMEvent", DSMCondition::DSMEvent); + PyModule_AddIntConstant(dsm_module, "PlaylistSeparator", DSMCondition::PlaylistSeparator); + PyModule_AddIntConstant(dsm_module, "B2BOtherReply", DSMCondition::B2BOtherReply); + PyModule_AddIntConstant(dsm_module, "B2BOtherBye", DSMCondition::B2BOtherBye); + + PyImport_AddModule("session"); + session_module = Py_InitModule("session",session_methods); +} + +SCPyModule::~SCPyModule() { +} + + +DSMAction* SCPyModule::getAction(const string& from_str) { + string cmd; + string params; + splitCmd(from_str, cmd, params); + + DEF_CMD("py", SCPyPyAction); + + return NULL; +} + +DSMCondition* SCPyModule::getCondition(const string& from_str) { + string cmd; + string params; + splitCmd(from_str, cmd, params); + + if (cmd == "py") { + return new PyPyCondition(params); + } + + return NULL; +} + +SCPyPyAction::SCPyPyAction(const string& arg) { + py_func = Py_CompileString(arg.c_str(), "<mod_py>", Py_file_input); + if (NULL == py_func) { + ERROR("compiling python code '%s'\n", + arg.c_str()); + if(PyErr_Occurred()) + PyErr_Print(); + + throw string("compiling python code '" + arg +"'"); + } +} + +EXEC_ACTION_START(SCPyPyAction) { + // do we need to acquire the lock? but it crashes... + // PYLOCK; + + PyObject* m = PyImport_AddModule("__main__"); + if (m == NULL) { + ERROR("getting main module\n"); + return false; + } + PyObject*d = PyModule_GetDict(m); + + PyObject* locals = PyDict_New(); + PyDict_SetItemString(locals, "dsm", SCPyModule::dsm_module); + PyDict_SetItemString(locals, "session", SCPyModule::session_module); + + PyObject* params = PyDict_New(); + if (NULL != event_params) { + for (map<string,string>::iterator it=event_params->begin(); + it != event_params->end(); it++) { + PyDict_SetItemString(params, it->first.c_str(), PyString_FromString(it->second.c_str())); + } + } + PyDict_SetItemString(locals, "params", params); + PyDict_SetItemString(locals, "type", PyInt_FromLong(event)); + + PyObject* py_sc_sess = PyCObject_FromVoidPtr(sc_sess,NULL); + PyObject* ts_dict = PyThreadState_GetDict(); + PyDict_SetItemString(ts_dict, "_dsm_sess_", py_sc_sess); + + + // call the function + PyObject* res = PyEval_EvalCode((PyCodeObject*)py_func, d, locals); + + if(PyErr_Occurred()){ + PyErr_Print(); + } + + ts_dict = PyThreadState_GetDict(); // should be the same as before + py_sc_sess = PyDict_GetItemString(ts_dict, "_dsm_sess_"); // should be the same as before + Py_XDECREF(py_sc_sess); + + PyDict_DelItemString(ts_dict, "_dsm_sess_"); + + Py_DECREF(locals); + if (NULL == res) { + ERROR("evaluating python code\n"); + } else { + Py_XDECREF(res); + } + +} EXEC_ACTION_END; + + +PyPyCondition::PyPyCondition(const string& arg) { + py_func = Py_CompileString(arg.c_str(), "<mod_py>", Py_eval_input); + if (NULL == py_func) { + ERROR("compiling python code '%s'\n", + arg.c_str()); + if(PyErr_Occurred()) + PyErr_Print(); + + throw string("compiling python code '" + arg +"'"); + } +} + +MATCH_CONDITION_START(PyPyCondition) { + // probably we need to acquire the lock? but it crashes.. + // PYLOCK; + + bool cond_res = false; + + PyObject* m = PyImport_AddModule("__main__"); + if (m == NULL) { + ERROR("getting main module\n"); + return false; + } + PyObject*d = PyModule_GetDict(m); + + PyObject* locals = PyDict_New(); + PyDict_SetItem(locals, PyString_FromString("dsm"), SCPyModule::dsm_module); + PyDict_SetItem(locals, PyString_FromString("session"), SCPyModule::session_module); + + PyObject* params = PyDict_New(); + if (NULL != event_params) { + for (map<string,string>::iterator it=event_params->begin(); + it != event_params->end(); it++) { + PyDict_SetItemString(params, it->first.c_str(), PyString_FromString(it->second.c_str())); + } + } + PyDict_SetItemString(locals, "params", params); + PyDict_SetItemString(locals, "type", PyInt_FromLong(event)); + + PyObject* py_sc_sess = PyCObject_FromVoidPtr(sc_sess,NULL); + PyObject* ts_dict = PyThreadState_GetDict(); + PyDict_SetItemString(ts_dict, "_dsm_sess_", py_sc_sess); + + // call the function + PyObject* res = PyEval_EvalCode((PyCodeObject*)py_func, d, locals); + + if(PyErr_Occurred()) + PyErr_Print(); + + ts_dict = PyThreadState_GetDict(); // should be the same as before + py_sc_sess = PyDict_GetItemString(ts_dict, "_dsm_sess_"); // should be the same as before + Py_XDECREF(py_sc_sess); + + PyDict_DelItemString(ts_dict, "_dsm_sess_"); + + Py_DECREF(locals); + if (NULL == res) { + ERROR("evaluating python code\n"); + } else if (PyBool_Check(res)) { + cond_res = PyInt_AsLong(res); + } else { + ERROR("unknown result from python code\n"); + } + + return cond_res; +} MATCH_CONDITION_END; Property changes on: trunk/apps/dsm/mods/mod_py/ModPy.cpp ___________________________________________________________________ Name: svn:keywords + Id Name: svn:eol-style + native Added: trunk/apps/dsm/mods/mod_py/ModPy.h =================================================================== --- trunk/apps/dsm/mods/mod_py/ModPy.h 2009-05-06 16:46:38 UTC (rev 1366) +++ trunk/apps/dsm/mods/mod_py/ModPy.h 2009-05-06 22:50:04 UTC (rev 1367) @@ -0,0 +1,70 @@ +/* + * $Id$ + * + * Copyright (C) 2009 TelTech Systems + * + * 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_PY_H +#define _MOD_PY_H +#include "DSMModule.h" +#include "DSMSession.h" + +#include <Python.h> + + +class SCPyModule +: public DSMModule { + + + public: + SCPyModule(); + ~SCPyModule(); + + DSMAction* getAction(const string& from_str); + DSMCondition* getCondition(const string& from_str); + static PyObject* dsm_module; + static PyObject* session_module; +}; + +class SCPyPyAction + : public DSMAction { + PyObject* py_func; + public: + SCPyPyAction(const string& arg); + bool execute(AmSession* sess, + DSMCondition::EventType event, + map<string,string>* event_params); + }; + +class PyPyCondition +: public DSMCondition { + + PyObject* py_func; + public: + + PyPyCondition(const string& arg); + bool match(AmSession* sess, DSMCondition::EventType event, + map<string,string>* event_params); + }; + +#endif Property changes on: trunk/apps/dsm/mods/mod_py/ModPy.h ___________________________________________________________________ Name: svn:keywords + Id Name: svn:eol-style + native Added: trunk/apps/dsm/mods/mod_py/PyDSM.cpp =================================================================== --- trunk/apps/dsm/mods/mod_py/PyDSM.cpp 2009-05-06 16:46:38 UTC (rev 1366) +++ trunk/apps/dsm/mods/mod_py/PyDSM.cpp 2009-05-06 22:50:04 UTC (rev 1367) @@ -0,0 +1,94 @@ +/* + * $Id$ + * + * Copyright (C) 2009 IPTEGO GmbH + * + * 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 "PyDSM.h" +#include "log.h" + + +extern "C" { + + static PyObject* mod_py_log(PyObject*, PyObject* args) + { + int level; + char *msg; + + if(!PyArg_ParseTuple(args,"is",&level,&msg)) + return NULL; + + if((level)<=log_level) { + if(log_stderr) + log_print( level, msg ); + else { + switch(level){ + case L_ERR: + syslog(LOG_ERR, "Error: %s", msg); + break; + case L_WARN: + syslog(LOG_WARNING, "Warning: %s", msg); + break; + case L_INFO: + syslog(LOG_INFO, "Info: %s", msg); + break; + case L_DBG: + syslog(LOG_DEBUG, "Debug: %s", msg); + break; + } + } + } + + Py_INCREF(Py_None); + return Py_None; + } + +#define DEF_LOG_FNC(suffix, func) \ + static PyObject* mod_py_##suffix(PyObject*, PyObject* args) \ + { \ + char *msg; \ + \ + if(!PyArg_ParseTuple(args,"s",&msg)) \ + return NULL; \ + func("%s", msg); \ + \ + Py_INCREF(Py_None); \ + return Py_None; \ + } + + DEF_LOG_FNC(dbg, DBG); + DEF_LOG_FNC(info, INFO); + DEF_LOG_FNC(warn, WARN); + DEF_LOG_FNC(error, ERROR); + + PyMethodDef mod_py_methods[] = { + {"log", (PyCFunction)mod_py_log, METH_VARARGS,"Log a message using SEMS' logging system"}, + {"DBG", (PyCFunction)mod_py_dbg, METH_VARARGS,"Log a message using SEMS' logging system, level debug"}, + {"INFO", (PyCFunction)mod_py_info, METH_VARARGS,"Log a message using SEMS' logging system, level info"}, + {"WARN", (PyCFunction)mod_py_warn, METH_VARARGS,"Log a message using SEMS' logging system, level warning"}, + {"ERROR", (PyCFunction)mod_py_error, METH_VARARGS,"Log a message using SEMS' logging system, level error"}, + {NULL} /* Sentinel */ + }; + +} Property changes on: trunk/apps/dsm/mods/mod_py/PyDSM.cpp ___________________________________________________________________ Name: svn:keywords + Id Name: svn:eol-style + native Added: trunk/apps/dsm/mods/mod_py/PyDSM.h =================================================================== --- trunk/apps/dsm/mods/mod_py/PyDSM.h 2009-05-06 16:46:38 UTC (rev 1366) +++ trunk/apps/dsm/mods/mod_py/PyDSM.h 2009-05-06 22:50:04 UTC (rev 1367) @@ -0,0 +1,37 @@ +/* + * $Id$ + * + * Copyright (C) 2009 IPTEGO GmbH + * + * 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 _PyDSM_H_ +#define _PyDSM_H_ + +#include "Python.h" + +extern "C" { + extern PyMethodDef mod_py_methods[]; +}; + +#endif Property changes on: trunk/apps/dsm/mods/mod_py/PyDSM.h ___________________________________________________________________ Name: svn:keywords + Id Name: svn:eol-style + native Added: trunk/apps/dsm/mods/mod_py/PyDSMSession.cpp =================================================================== --- trunk/apps/dsm/mods/mod_py/PyDSMSession.cpp 2009-05-06 16:46:38 UTC (rev 1366) +++ trunk/apps/dsm/mods/mod_py/PyDSMSession.cpp 2009-05-06 22:50:04 UTC (rev 1367) @@ -0,0 +1,300 @@ +/* + * $Id$ + * + * Copyright (C) 2009 IPTEGO GmbH + * + * 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 "PyDSMSession.h" +#include "log.h" +#include "DSMSession.h" + +extern "C" { + +#define GET_SESS_PTR \ + PyObject* ts_dict = PyThreadState_GetDict(); \ + PyObject* py_sc_sess = PyDict_GetItemString(ts_dict, "_dsm_sess_"); \ + if (NULL == py_sc_sess) { \ + ERROR("retrieving the session pointer from TL dict\n"); \ + return NULL; \ + } \ + \ + DSMSession* sess = (DSMSession*)PyCObject_AsVoidPtr(py_sc_sess); \ + if (NULL == sess) { \ + ERROR("retrieving the session pointer from TL dict\n"); \ + return NULL; \ + } + + static PyObject* mod_py_setvar(PyObject*, PyObject* args) + { + char *varname; + char *val; + if(!PyArg_ParseTuple(args,"ss",&varname,&val)) + return NULL; + + GET_SESS_PTR; + + DBG("set '%s' = '%s'\n", varname, val); + sess->var[varname] = val; + + Py_INCREF(Py_None); + return Py_None; + } + + static PyObject* mod_py_getvar(PyObject*, PyObject* args) + { + char *varname; + if(!PyArg_ParseTuple(args,"s",&varname)) + return NULL; + + GET_SESS_PTR; + + DBG("returning '%s'\n", sess->var[varname].c_str()); + + return PyString_FromString(sess->var[varname].c_str()); + } + + static PyObject* mod_py_seterror(PyObject*, PyObject* args) + { + int errno; + if(!PyArg_ParseTuple(args,"i",&errno)) + return NULL; + + GET_SESS_PTR; + + DBG("setting errno '%i'\n", errno); + sess->SET_ERRNO(errno); + + Py_INCREF(Py_None); + return Py_None; + } + + static PyObject* playPrompt(PyObject*, PyObject* args) + { + char *name; + int loop = 0; + + if(!PyArg_ParseTuple(args,"s|i",&name, &loop)) + return NULL; + + GET_SESS_PTR; + + DBG("playPrompt('%s', loop=%s)\n", name, loop?"true":"false"); + sess->playPrompt(name, loop); + Py_INCREF(Py_None); + return Py_None; + } + + static PyObject* playFile(PyObject*, PyObject* args) + { + char *name; + int loop = 0; + int front = 0; + + if(!PyArg_ParseTuple(args,"s|ii",&name, &loop)) + return NULL; + + GET_SESS_PTR; + + DBG("playPrompt('%s', loop=%s, front=%s)\n", name, + loop?"true":"false", front?"true":"false"); + sess->playFile(name, loop, front); + Py_INCREF(Py_None); + return Py_None; + } + + static PyObject* recordFile(PyObject*, PyObject* args) + { + char *name; + if(!PyArg_ParseTuple(args,"s",&name)) + return NULL; + + GET_SESS_PTR; + + DBG("recordFile('%s')\n", name); + sess->recordFile(name); + Py_INCREF(Py_None); + return Py_None; + } + + static PyObject* getRecordLength(PyObject*, PyObject* args) + { + GET_SESS_PTR; + unsigned int res = sess->getRecordLength(); + DBG("record length %d\n",res); + return PyInt_FromLong(res); + } + + static PyObject* getRecordDataSize(PyObject*, PyObject* args) + { + GET_SESS_PTR; + unsigned int res = sess->getRecordDataSize(); + DBG("record data size %d\n",res); + return PyInt_FromLong(res); + } + + static PyObject* stopRecord(PyObject*, PyObject* args) + { + GET_SESS_PTR; + DBG("stopping record."); + sess->stopRecord(); + Py_INCREF(Py_None); + return Py_None; + } + + static PyObject* closePlaylist(PyObject*, PyObject* args) + { + int notify = 0; + + if(!PyArg_ParseTuple(args,"i",¬ify)) + return NULL; + + GET_SESS_PTR; + + DBG("playFile(notify=%s)\n", notify?"true":"false"); + sess->closePlaylist(notify); + Py_INCREF(Py_None); + return Py_None; + } + + static PyObject* setPromptSet(PyObject*, PyObject* args) + { + char *name; + if(!PyArg_ParseTuple(args,"s",&name)) + return NULL; + + GET_SESS_PTR; + + DBG("setPromptSet('%s')\n", name); + sess->setPromptSet(name); + Py_INCREF(Py_None); + return Py_None; + } + + static PyObject* addSeparator(PyObject*, PyObject* args) + { + char *name; + int front = 0; + + if(!PyArg_ParseTuple(args,"s|i",&name, &front)) + return NULL; + + GET_SESS_PTR; + + DBG("addSeparator('%s', front=%s)\n", name, front?"true":"false"); + sess->addSeparator(name, front); + Py_INCREF(Py_None); + return Py_None; + } + + static PyObject* connectMedia(PyObject*, PyObject* args) + { + GET_SESS_PTR; + DBG("connectMedia."); + sess->connectMedia(); + Py_INCREF(Py_None); + return Py_None; + } + + static PyObject* disconnectMedia(PyObject*, PyObject* args) + { + GET_SESS_PTR; + DBG("disconnectMedia."); + sess->disconnectMedia(); + Py_INCREF(Py_None); + return Py_None; + } + + static PyObject* mute(PyObject*, PyObject* args) + { + GET_SESS_PTR; + DBG("mute."); + sess->mute(); + Py_INCREF(Py_None); + return Py_None; + } + + static PyObject* unmute(PyObject*, PyObject* args) + { + GET_SESS_PTR; + DBG("unmute."); + sess->unmute(); + Py_INCREF(Py_None); + return Py_None; + } + + static PyObject* B2BconnectCallee(PyObject*, PyObject* args) + { + char *remote_party; + char *remote_uri; + int relayed_invite = 0; + + if(!PyArg_ParseTuple(args,"ss|i", &remote_party, + &remote_uri, &relayed_invite)) + return NULL; + + GET_SESS_PTR; + + DBG("B2BconnectCallee('%s', '%s', relayed_invite=%s)\n", remote_party, + remote_uri, relayed_invite?"true":"false"); + sess->B2BconnectCallee(remote_party, remote_uri, relayed_invite); + Py_INCREF(Py_None); + return Py_None; + } + + + static PyObject* B2BterminateOtherLeg(PyObject*, PyObject* args) + { + GET_SESS_PTR; + DBG("B2BterminateOtherLeg."); + sess->B2BterminateOtherLeg(); + Py_INCREF(Py_None); + return Py_None; + } + + + PyMethodDef session_methods[] = { + {"setvar", (PyCFunction)mod_py_setvar, METH_VARARGS,"set a session's variable"}, + {"var", (PyCFunction)mod_py_getvar, METH_VARARGS,"get a session's variable"}, + {"setError", (PyCFunction)mod_py_seterror, METH_VARARGS,"set error (errno)"}, + + {"playPrompt", (PyCFunction)playPrompt, METH_VARARGS,"play a prompt"}, + {"playFile", (PyCFunction)playFile, METH_VARARGS,"play a file"}, + {"recordFile", (PyCFunction)recordFile, METH_VARARGS,"start recording to a file"}, + {"getRecordLength", (PyCFunction)getRecordLength, METH_VARARGS,"get the length of the current recording"}, + {"getRecordDataSize",(PyCFunction)getRecordDataSize, METH_VARARGS,"get the data size of the current recording"}, + {"stopRecord", (PyCFunction)stopRecord, METH_NOARGS,"stop the running recording"}, + {"closePlaylist", (PyCFunction)closePlaylist, METH_VARARGS,"close the playlist"}, + {"setPromptSet", (PyCFunction)setPromptSet, METH_VARARGS,"set prompt set"}, + {"addSeparator", (PyCFunction)addSeparator, METH_VARARGS,"add a named separator to playlist"}, + {"connectMedia", (PyCFunction)connectMedia, METH_NOARGS,"connect media (RTP processing)"}, + {"disconnectMedia", (PyCFunction)disconnectMedia, METH_NOARGS,"disconnect media (RTP processing)"}, + {"mute", (PyCFunction)mute, METH_NOARGS,"mute RTP)"}, + {"unmute", (PyCFunction)unmute, METH_NOARGS,"unmute RTP"}, + {"B2BconnectCallee", (PyCFunction)B2BconnectCallee, METH_VARARGS,"connect callee of B2B leg"}, + {"B2BterminateOtherLeg", (PyCFunction)B2BterminateOtherLeg, METH_VARARGS,"terminate other leg of B2B call"}, + + {NULL} /* Sentinel */ + }; + +} Property changes on: trunk/apps/dsm/mods/mod_py/PyDSMSession.cpp ___________________________________________________________________ Name: svn:keywords + Id Name: svn:eol-style + native Added: trunk/apps/dsm/mods/mod_py/PyDSMSession.h =================================================================== --- trunk/apps/dsm/mods/mod_py/PyDSMSession.h 2009-05-06 16:46:38 UTC (rev 1366) +++ trunk/apps/dsm/mods/mod_py/PyDSMSession.h 2009-05-06 22:50:04 UTC (rev 1367) @@ -0,0 +1,37 @@ +/* + * $Id$ + * + * Copyright (C) 2009 IPTEGO GmbH + * + * 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 _PyDSMSession_h_ +#define _PyDSMSession_h_ + +#include "Python.h" + +extern "C" { + extern PyMethodDef session_methods[]; +}; + +#endif Property changes on: trunk/apps/dsm/mods/mod_py/PyDSMSession.h ___________________________________________________________________ Name: svn:keywords + Id Name: svn:eol-style + native Added: trunk/apps/dsm/mods/mod_py/python_inc.py =================================================================== --- trunk/apps/dsm/mods/mod_py/python_inc.py 2009-05-06 16:46:38 UTC (rev 1366) +++ trunk/apps/dsm/mods/mod_py/python_inc.py 2009-05-06 22:50:04 UTC (rev 1367) @@ -0,0 +1,3 @@ +import distutils.sysconfig + +print distutils.sysconfig.get_python_inc(True) Added: trunk/apps/dsm/mods/mod_py/python_lib.py =================================================================== --- trunk/apps/dsm/mods/mod_py/python_lib.py 2009-05-06 16:46:38 UTC (rev 1366) +++ trunk/apps/dsm/mods/mod_py/python_lib.py 2009-05-06 22:50:04 UTC (rev 1367) @@ -0,0 +1,3 @@ +import distutils.sysconfig + +print distutils.sysconfig.get_python_lib(True,True) _______________________________________________ Semsdev mailing list [email protected] http://lists.iptel.org/mailman/listinfo/semsdev
