/* Chrysalide - Outil d'analyse de fichiers binaires * global.c - équivalent Python du fichier "core/global.c" * * Copyright (C) 2018 Cyrille Bagard * * This file is part of Chrysalide. * * Chrysalide 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. * * Chrysalide 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 "global.h" #include #include #include "../access.h" #include "../helpers.h" #include "../analysis/project.h" /* Fournit l'adresse de l'explorateur de contenus courant. */ static PyObject *py_global_get_content_explorer(PyObject *, PyObject *); /* Fournit l'adresse du résolveur de contenus courant. */ static PyObject *py_global_get_content_resolver(PyObject *, PyObject *); /* Fournit l'adresse du projet courant. */ static PyObject *py_global_get_current_project(PyObject *, PyObject *); /* Définit l'adresse du projet courant. */ static PyObject *py_global_set_current_project(PyObject *, PyObject *); /****************************************************************************** * * * Paramètres : self = objet Python concerné par l'appel. * * args = non utilisé ici. * * * * Description : Fournit l'adresse de l'explorateur de contenus courant. * * * * Retour : Adresse de l'explorateur global ou None si aucun (!). * * * * Remarques : - * * * ******************************************************************************/ static PyObject *py_global_get_content_explorer(PyObject *self, PyObject *args) { PyObject *result; /* Instance Python à retourner */ GContentExplorer *explorer; /* Gestionnaire natif récupéré */ explorer = get_current_content_explorer(); if (explorer != NULL) { result = pygobject_new(G_OBJECT(explorer)); g_object_unref(G_OBJECT(explorer)); } else { result = Py_None; Py_INCREF(result); } return result; } /****************************************************************************** * * * Paramètres : self = objet Python concerné par l'appel. * * args = non utilisé ici. * * * * Description : Fournit l'adresse du résolveur de contenus courant. * * * * Retour : Adresse du résolveur global ou None si aucun (!). * * * * Remarques : - * * * ******************************************************************************/ static PyObject *py_global_get_content_resolver(PyObject *self, PyObject *args) { PyObject *result; /* Instance Python à retourner */ GContentResolver *resolver; /* Gestionnaire natif récupéré */ resolver = get_current_content_resolver(); if (resolver != NULL) { result = pygobject_new(G_OBJECT(resolver)); g_object_unref(G_OBJECT(resolver)); } else { result = Py_None; Py_INCREF(result); } return result; } /****************************************************************************** * * * Paramètres : self = objet Python concerné par l'appel. * * args = non utilisé ici. * * * * Description : Fournit l'adresse du projet courant. * * * * Retour : Adresse du résolveur global ou None si aucun. * * * * Remarques : - * * * ******************************************************************************/ static PyObject *py_global_get_current_project(PyObject *self, PyObject *args) { PyObject *result; /* Instance Python à retourner */ GStudyProject *project; /* Projet courant récupéré */ project = get_current_project(); if (project != NULL) { result = pygobject_new(G_OBJECT(project)); g_object_unref(G_OBJECT(project)); } else { result = Py_None; Py_INCREF(result); } return result; } /****************************************************************************** * * * Paramètres : self = objet Python concerné par l'appel. * * args = valeur fournie à intégrer ou prendre en compte. * * * * Description : Définit l'adresse du projet courant. * * * * Retour : Bilan de l'opération pour Python. * * * * Remarques : - * * * ******************************************************************************/ static PyObject *py_global_set_current_project(PyObject *self, PyObject *args) { GStudyProject *project; /* Version GLib du projet */ int ret; /* Bilan de lecture des args. */ ret = PyArg_ParseTuple(args, "O&", convert_to_study_project, &project); if (!ret) return NULL; g_object_ref(G_OBJECT(project)); set_current_project(project); Py_RETURN_NONE; } /****************************************************************************** * * * Paramètres : - * * * * Description : Définit une extension du module 'core' à compléter. * * * * Retour : Bilan de l'opération. * * * * Remarques : - * * * ******************************************************************************/ bool populate_core_module_with_global(void) { bool result; /* Bilan à retourner */ PyObject *module; /* Module à recompléter */ static PyMethodDef py_global_methods[] = { { "get_content_explorer", py_global_get_content_explorer, METH_NOARGS, "get_content_explorer(, /)\n--\n\nGet the global exploration manager discovering contents." }, { "get_content_resolver", py_global_get_content_resolver, METH_NOARGS, "get_content_resolver(, /)\n--\n\nGet the global resolution manager translating binary contents into loaded contents." }, { "get_current_project", py_global_get_current_project, METH_NOARGS, "get_current_project(, /)\n--\n\nGet the current global project." }, { "set_current_project", py_global_set_current_project, METH_VARARGS, "set_current_project(, /)\n--\n\nSet the current global project." }, { NULL } }; module = get_access_to_python_module("pychrysalide.core"); result = register_python_module_methods(module, py_global_methods); return result; }