mirror of
https://github.com/profanity-im/profanity.git
synced 2025-02-02 15:08:15 -05:00
Separated python api and plugins code
This commit is contained in:
parent
8d2d71bacb
commit
dded9e954f
@ -22,7 +22,8 @@ profanity_SOURCES = \
|
|||||||
src/config/accounts.c src/config/accounts.h \
|
src/config/accounts.c src/config/accounts.h \
|
||||||
src/config/preferences.c src/config/preferences.h \
|
src/config/preferences.c src/config/preferences.h \
|
||||||
src/config/theme.c src/config/theme.h \
|
src/config/theme.c src/config/theme.h \
|
||||||
src/plugins/plugins.h src/plugins/plugins.c
|
src/plugins/plugins.h src/plugins/plugins.c \
|
||||||
|
src/plugins/api.h src/plugins/api.c
|
||||||
|
|
||||||
TESTS = tests/testsuite
|
TESTS = tests/testsuite
|
||||||
check_PROGRAMS = tests/testsuite
|
check_PROGRAMS = tests/testsuite
|
||||||
@ -50,6 +51,7 @@ tests_testsuite_SOURCES = \
|
|||||||
src/config/preferences.c src/config/preferences.h \
|
src/config/preferences.c src/config/preferences.h \
|
||||||
src/config/theme.c src/config/theme.h \
|
src/config/theme.c src/config/theme.h \
|
||||||
src/plugins/plugins.h src/plugins/plugins.c \
|
src/plugins/plugins.h src/plugins/plugins.c \
|
||||||
|
src/plugins/api.h src/plugins/api.c \
|
||||||
tests/test_roster.c tests/test_common.c tests/test_history.c \
|
tests/test_roster.c tests/test_common.c tests/test_history.c \
|
||||||
tests/test_autocomplete.c tests/testsuite.c tests/test_parser.c \
|
tests/test_autocomplete.c tests/testsuite.c tests/test_parser.c \
|
||||||
tests/test_jid.c
|
tests/test_jid.c
|
||||||
|
49
src/plugins/api.c
Normal file
49
src/plugins/api.c
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
/*
|
||||||
|
* api.c
|
||||||
|
*
|
||||||
|
* Copyright (C) 2012, 2013 James Booth <boothj5@gmail.com>
|
||||||
|
*
|
||||||
|
* This file is part of Profanity.
|
||||||
|
*
|
||||||
|
* Profanity 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 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Profanity 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 Profanity. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <Python.h>
|
||||||
|
|
||||||
|
#include "ui/ui.h"
|
||||||
|
|
||||||
|
// API functions
|
||||||
|
|
||||||
|
static PyObject*
|
||||||
|
api_cons_show(PyObject *self, PyObject *args)
|
||||||
|
{
|
||||||
|
const char *message = NULL;
|
||||||
|
if (!PyArg_ParseTuple(args, "s", &message)) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
cons_show("%s", message);
|
||||||
|
return Py_BuildValue("");
|
||||||
|
}
|
||||||
|
|
||||||
|
static PyMethodDef apiMethods[] = {
|
||||||
|
{ "cons_show", api_cons_show, METH_VARARGS, "Print a line to the console." },
|
||||||
|
{ NULL, NULL, 0, NULL }
|
||||||
|
};
|
||||||
|
|
||||||
|
void
|
||||||
|
api_init(void)
|
||||||
|
{
|
||||||
|
Py_InitModule("prof", apiMethods);
|
||||||
|
}
|
28
src/plugins/api.h
Normal file
28
src/plugins/api.h
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
/*
|
||||||
|
* api.h
|
||||||
|
*
|
||||||
|
* Copyright (C) 2012, 2013 James Booth <boothj5@gmail.com>
|
||||||
|
*
|
||||||
|
* This file is part of Profanity.
|
||||||
|
*
|
||||||
|
* Profanity 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 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Profanity 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 Profanity. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef API_H
|
||||||
|
#define API_H
|
||||||
|
|
||||||
|
void api_init(void);
|
||||||
|
|
||||||
|
#endif
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* api.c
|
* plugins.c
|
||||||
*
|
*
|
||||||
* Copyright (C) 2012, 2013 James Booth <boothj5@gmail.com>
|
* Copyright (C) 2012, 2013 James Booth <boothj5@gmail.com>
|
||||||
*
|
*
|
||||||
@ -22,6 +22,7 @@
|
|||||||
|
|
||||||
#include <Python.h>
|
#include <Python.h>
|
||||||
|
|
||||||
|
#include "plugins/api.h"
|
||||||
#include "plugins/plugins.h"
|
#include "plugins/plugins.h"
|
||||||
#include "ui/ui.h"
|
#include "ui/ui.h"
|
||||||
|
|
||||||
@ -31,25 +32,6 @@ static void _on_start(void);
|
|||||||
static void _run_plugins(const char * const function, PyObject *p_args);
|
static void _run_plugins(const char * const function, PyObject *p_args);
|
||||||
|
|
||||||
static GSList* plugins;
|
static GSList* plugins;
|
||||||
static PyObject *prof_module;
|
|
||||||
// API
|
|
||||||
|
|
||||||
static PyObject*
|
|
||||||
api_cons_show(PyObject *self, PyObject *args)
|
|
||||||
{
|
|
||||||
const char *message = NULL;
|
|
||||||
if (!PyArg_ParseTuple(args, "s", &message)) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
cons_show("%s", message);
|
|
||||||
return Py_BuildValue("");
|
|
||||||
}
|
|
||||||
|
|
||||||
static PyMethodDef apiMethods[] = {
|
|
||||||
{ "cons_show", api_cons_show, METH_VARARGS, "Print a line to the console." },
|
|
||||||
{ NULL, NULL, 0, NULL }
|
|
||||||
};
|
|
||||||
|
|
||||||
void
|
void
|
||||||
plugins_init(void)
|
plugins_init(void)
|
||||||
{
|
{
|
||||||
@ -59,7 +41,7 @@ plugins_init(void)
|
|||||||
GSList *module_names = _get_module_names();
|
GSList *module_names = _get_module_names();
|
||||||
|
|
||||||
Py_Initialize();
|
Py_Initialize();
|
||||||
prof_module = Py_InitModule("prof", apiMethods);
|
api_init();
|
||||||
|
|
||||||
// TODO change to use XDG spec
|
// TODO change to use XDG spec
|
||||||
PySys_SetPath("$PYTHONPATH:./plugins/");
|
PySys_SetPath("$PYTHONPATH:./plugins/");
|
||||||
@ -93,6 +75,12 @@ plugins_shutdown(void)
|
|||||||
Py_Finalize();
|
Py_Finalize();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
plugins_on_connect(void)
|
||||||
|
{
|
||||||
|
_run_plugins("prof_on_connect", NULL);
|
||||||
|
}
|
||||||
|
|
||||||
static GSList *
|
static GSList *
|
||||||
_get_module_names(void)
|
_get_module_names(void)
|
||||||
{
|
{
|
||||||
@ -131,12 +119,6 @@ _on_start(void)
|
|||||||
_run_plugins("prof_on_start", NULL);
|
_run_plugins("prof_on_start", NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
|
||||||
plugins_on_connect(void)
|
|
||||||
{
|
|
||||||
_run_plugins("prof_on_connect", NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
_run_plugins(const char * const function, PyObject *p_args)
|
_run_plugins(const char * const function, PyObject *p_args)
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user