* dialout API in IVR.

* createThread function to create additionally running Python threads (e.g. servers)
  This function expects a python callable and executes it in a new thread.
  


git-svn-id: http://svn.berlios.de/svnroot/repos/sems/trunk@74 8eb893ce-cfd4-0310-b710-fb5ebe64c474
sayer/1.4-spce2.6
Stefan Sayer 20 years ago
parent a33978ea3b
commit 389d658135

@ -22,6 +22,7 @@
#include "IvrDialogBase.h"
#include "IvrSipDialog.h"
#include "IvrAudio.h"
#include "IvrUAC.h"
#include "Ivr.h"
#include "AmConfigReader.h"
@ -109,14 +110,42 @@ extern "C" {
return PyString_FromString(res.c_str());
}
static PyObject* ivr_createThread(PyObject*, PyObject* args)
{
PyObject* py_thread_object = NULL;
if(!PyArg_ParseTuple(args,"O",&py_thread_object))
return NULL;
PythonScriptThread* t = new PythonScriptThread(py_thread_object);
t->start();
AmThreadWatcher::instance()->add(t);
return Py_None;
}
static PyMethodDef ivr_methods[] = {
{"log", (PyCFunction)ivr_log, METH_VARARGS,"Log a message using Sems' logging system"},
{"getHeader", (PyCFunction)ivr_getHeader, METH_VARARGS,"Python getHeader wrapper"},
{"createThread", (PyCFunction)ivr_createThread, METH_VARARGS, "Create another interpreter thread"},
{NULL} /* Sentinel */
};
}
void PythonScriptThread::run() {
// PYLOCK;
// PyEval_AcquireLock();
DBG("PythonScriptThread::run - calling python function.\n");
PyObject_CallObject(py_thread_object, NULL);
DBG("PythonScriptThread::run - thread finished..\n");
// PyEval_ReleaseLock();
}
void PythonScriptThread::on_stop() {
DBG("PythonScriptThread::on_stop.\n");
}
IvrFactory::IvrFactory(const string& _app_name)
: AmSessionFactory(_app_name),
user_timer_fact(NULL)
@ -171,9 +200,11 @@ void IvrFactory::import_ivr_builtins()
// IvrAudioFile
import_object(ivr_module,"IvrAudioFile",&IvrAudioFileType);
// IvrUAC
import_object(ivr_module,"IvrUAC",&IvrUACType);
PyModule_AddIntConstant(ivr_module, "AUDIO_READ",AUDIO_READ);
PyModule_AddIntConstant(ivr_module, "AUDIO_WRITE",AUDIO_WRITE);
// ivr module - end
// add log level for the log module
PyModule_AddIntConstant(ivr_module, "SEMS_LOG_LEVEL",log_level);

@ -40,6 +40,17 @@ using std::map;
class IvrDialog;
class PythonScriptThread : public AmThread {
PyObject* py_thread_object;
protected:
void run();
void on_stop();
public:
PythonScriptThread(PyObject* py_thread_object_)
: py_thread_object(py_thread_object_) { }
};
struct IvrScriptDesc
{
PyObject* mod;

@ -0,0 +1,109 @@
/*
* $Id: Ivr.cpp,v 1.26.2.1 2005/09/02 13:47:46 rco Exp $
* Copyright (C) 2006 Stefan Sayer
*
* This file is part of sems, a free SIP media server.
*
* This program 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
*
* This program 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 "IvrUAC.h"
#include "AmUAC.h"
#include "log.h"
static PyObject* IvrUAC_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
{
IvrUAC *self;
self = (IvrUAC *)type->tp_alloc(type, 0);
return (PyObject *)self;
}
static void IvrUAC_dealloc(IvrUAC* self)
{
self->ob_type->tp_free((PyObject*)self);
}
static PyObject* IvrUAC_dialout(IvrUAC* self, PyObject* args)
{
char* user;
char* app_name;
char* r_uri;
char* from;
char* from_uri;
char* to;
if(!PyArg_ParseTuple(args,"ssssss", &user, &app_name, &r_uri,
&from, &from_uri, &to))
return NULL;
//AmSession* newSession =
AmUAC::dialout(user, app_name, r_uri,
from, from_uri, to);
Py_INCREF(Py_None);
return Py_None;
}
static PyMethodDef IvrUAC_methods[] = {
{"dialout", (PyCFunction)IvrUAC_dialout, METH_VARARGS,
"place a new call"
},
{NULL} /* Sentinel */
};
PyTypeObject IvrUACType = {
PyObject_HEAD_INIT(NULL)
0, /*ob_size*/
"ivr.IvrUAC", /*tp_name*/
sizeof(IvrUAC), /*tp_basicsize*/
0, /*tp_itemsize*/
(destructor)IvrUAC_dealloc, /*tp_dealloc*/
0, /*tp_print*/
0, /*tp_getattr*/
0, /*tp_setattr*/
0, /*tp_compare*/
0, /*tp_repr*/
0, /*tp_as_number*/
0, /*tp_as_sequence*/
0, /*tp_as_mapping*/
0, /*tp_hash */
0, /*tp_call*/
0, /*tp_str*/
0, /*tp_getattro*/
0, /*tp_setattro*/
0, /*tp_as_buffer*/
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
"UAC Class", /*tp_doc*/
0, /* tp_traverse */
0, /* tp_clear */
0, /* tp_richcompare */
0, /* tp_weaklistoffset */
0, /* tp_iter */
0, /* tp_iternext */
IvrUAC_methods, /* tp_methods */
0, /* tp_members */
0, /* tp_getset */
0, /* tp_base */
0, /* tp_dict */
0, /* tp_descr_get */
0, /* tp_descr_set */
0, /* tp_dictoffset */
0, /* tp_init */
0, /* tp_alloc */
IvrUAC_new, /* tp_new */
};

@ -0,0 +1,40 @@
/*
* $Id: Ivr.cpp,v 1.26.2.1 2005/09/02 13:47:46 rco Exp $
* Copyright (C) 2002-2003 Fhg Fokus
* Copyright (C) 2006 Stefan Sayer
*
* This file is part of sems, a free SIP media server.
*
* This program 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
*
* This program 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 IvrUAC_h
#define IvrUAC_h
// Python stuff
#include <Python.h>
#include "structmember.h"
// Data definition
typedef struct {
PyObject_HEAD
// AmSession* session;
} IvrUAC;
extern PyTypeObject IvrUACType;
#endif
Loading…
Cancel
Save