2013-02-14 14:58:26 +01:00
|
|
|
/******************************************************************************
|
|
|
|
* Icinga 2 *
|
2014-03-19 01:02:29 +01:00
|
|
|
* Copyright (C) 2012-2014 Icinga Development Team (http://www.icinga.org) *
|
2013-02-14 14:58:26 +01:00
|
|
|
* *
|
|
|
|
* 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
#ifndef PYTHONLANGUAGE_H
|
|
|
|
#define PYTHONLANGUAGE_H
|
|
|
|
|
2013-03-18 11:02:18 +01:00
|
|
|
#include <Python.h>
|
|
|
|
#include "base/scriptlanguage.h"
|
|
|
|
|
2013-02-14 14:58:26 +01:00
|
|
|
namespace icinga
|
|
|
|
{
|
|
|
|
|
2013-02-16 07:49:36 +01:00
|
|
|
class PythonInterpreter;
|
|
|
|
|
2013-02-14 14:58:26 +01:00
|
|
|
/**
|
|
|
|
* The Python scripting language.
|
|
|
|
*
|
|
|
|
* @ingroup base
|
|
|
|
*/
|
2013-03-18 11:02:18 +01:00
|
|
|
class PythonLanguage : public ScriptLanguage
|
2013-02-14 14:58:26 +01:00
|
|
|
{
|
|
|
|
public:
|
2013-07-09 08:42:08 +02:00
|
|
|
DECLARE_PTR_TYPEDEFS(PythonLanguage);
|
2013-02-14 14:58:26 +01:00
|
|
|
|
|
|
|
PythonLanguage(void);
|
|
|
|
~PythonLanguage(void);
|
|
|
|
|
|
|
|
virtual ScriptInterpreter::Ptr CreateInterpreter(const Script::Ptr& script);
|
|
|
|
|
|
|
|
PyThreadState *GetMainThreadState(void) const;
|
2013-02-15 16:34:33 +01:00
|
|
|
|
2013-02-16 07:49:36 +01:00
|
|
|
static PythonInterpreter *GetCurrentInterpreter(void);
|
|
|
|
static void SetCurrentInterpreter(PythonInterpreter *interpreter);
|
|
|
|
|
|
|
|
static PyObject *MarshalToPython(const Value& value);
|
|
|
|
static Value MarshalFromPython(PyObject *value);
|
|
|
|
|
2013-02-16 11:28:34 +01:00
|
|
|
String ExceptionInfoToString(PyObject *type, PyObject *exc, PyObject *tb) const;
|
2013-02-16 12:36:25 +01:00
|
|
|
|
2013-02-14 14:58:26 +01:00
|
|
|
private:
|
2013-02-16 12:36:25 +01:00
|
|
|
bool m_Initialized;
|
2013-02-14 14:58:26 +01:00
|
|
|
PyThreadState *m_MainThreadState;
|
2013-02-15 16:34:33 +01:00
|
|
|
PyObject *m_NativeModule;
|
2013-02-16 11:28:34 +01:00
|
|
|
PyObject *m_TracebackModule;
|
2013-02-16 07:49:36 +01:00
|
|
|
static PythonInterpreter *m_CurrentInterpreter;
|
2013-02-15 16:34:33 +01:00
|
|
|
|
2013-03-14 14:00:10 +01:00
|
|
|
void RegisterNativeFunction(const String& name);
|
2013-02-15 16:34:33 +01:00
|
|
|
void UnregisterNativeFunction(const String& name);
|
|
|
|
|
2013-02-16 07:49:36 +01:00
|
|
|
static PyObject *PyCallNativeFunction(PyObject *self, PyObject *args);
|
|
|
|
static PyObject *PyRegisterFunction(PyObject *self, PyObject *args);
|
2013-02-15 16:34:33 +01:00
|
|
|
|
2013-02-16 07:49:36 +01:00
|
|
|
static PyMethodDef m_NativeMethodDef[];
|
2013-02-16 12:36:25 +01:00
|
|
|
|
|
|
|
void InitializeOnce(void);
|
2013-02-14 14:58:26 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* PYTHONLANGUAGE_H */
|