1 /*
2 * Copyright (C) 2002-2003 Fhg Fokus
3 *
4 * This file is part of SEMS, a free SIP media server.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21 #ifndef _PY_SEMS_H_
22 #define _PY_SEMS_H_
23
24 #define MOD_NAME "py_sems"
25
26 #include <Python.h>
27
28 #include "AmB2BSession.h"
29 #include "AmPlaylist.h"
30
31 #include <string>
32 #include <map>
33 using std::string;
34 using std::map;
35
36 class PySemsDialogBase;
37
38 struct PySemsScriptDesc
39 {
40 enum DialogType {
41 None = 0,
42 Dialog,
43 B2BDialog,
44 B2ABDialog
45 };
46
47 PyObject* mod;
48 PyObject* dlg_class;
49 DialogType dt;
50
PySemsScriptDescPySemsScriptDesc51 PySemsScriptDesc()
52 : mod(0),
53 dlg_class(0),
54 dt(None)
55 {}
56
PySemsScriptDescPySemsScriptDesc57 PySemsScriptDesc(const PySemsScriptDesc& d)
58 : mod(d.mod),
59 dlg_class(d.dlg_class),
60 dt(d.dt)
61 {}
62
PySemsScriptDescPySemsScriptDesc63 PySemsScriptDesc(PyObject* mod,
64 PyObject* dlg_class,
65 DialogType dt)
66 : mod(mod),
67 dlg_class(dlg_class),
68 dt(dt)
69 {}
70 };
71
72
73 /** \brief Factory for PySems sessions */
74 class PySemsFactory: public AmSessionFactory
75 {
76 PyObject* py_sems_module;
77 /* string script_path; */
78 string default_script;
79
80 map<string,PySemsScriptDesc> mod_reg;
81
82 void init_python_interpreter(const string& script_path);
83 void set_sys_path(const string& script_path);
84 void import_py_sems_builtins();
85
86 PyObject* import_module(const char* modname);
87 void import_object(PyObject* m,
88 char* name,
89 PyTypeObject* type);
90
91 /** @return true if everything ok */
92 bool loadScript(const string& path);
93
94 void setScriptPath(const string& path);
95 bool checkCfg();
96
97 AmSession* newDlg(const string& name);
98
99 public:
100 PySemsFactory(const string& _app_name);
101
102 int onLoad();
103 AmSession* onInvite(const AmSipRequest& req);
104 };
105
106 /** \brief wrapper for pySems dialog bas class */
107 class PySemsDialogBase {
108 PyObject *py_mod;
109 PyObject *py_dlg;
110
111 protected:
112 bool callPyEventHandler(char* name, char* fmt, ...);
113
114 public:
115 PySemsDialogBase();
116 ~PySemsDialogBase();
117
118 // must be called before everything else.
119 void setPyPtrs(PyObject *mod, PyObject *dlg);
120 };
121
122 #endif
123