"Fossies" - the Fresh Open Source Software Archive

Member "netxms-3.8.166/src/libnxpython/extensions.cpp" (23 Feb 2021, 2416 Bytes) of package /linux/misc/netxms-3.8.166.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "extensions.cpp" see the Fossies "Dox" file reference documentation and the last Fossies "Diffs" side-by-side code changes report: 3.6.300_vs_3.7.95.

    1 /*
    2 ** NetXMS - Network Management System
    3 ** Copyright (C) 2003-2018 Raden Solutions
    4 **
    5 ** This program is free software; you can redistribute it and/or modify
    6 ** it under the terms of the GNU General Public License as published by
    7 ** the Free Software Foundation; either version 2 of the License, or
    8 ** (at your option) any later version.
    9 **
   10 ** This program is distributed in the hope that it will be useful,
   11 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
   12 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   13 ** GNU General Public License for more details.
   14 **
   15 ** You should have received a copy of the GNU General Public License
   16 ** along with this program; if not, write to the Free Software
   17 ** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
   18 **
   19 ** File: extensions.cpp
   20 **
   21 **/
   22 
   23 #include "libnxpython.h"
   24 #include <netxms-version.h>
   25 
   26 /**
   27  * Method netxms.trace()
   28  */
   29 static PyObject *M_trace(PyObject *self, PyObject *args)
   30 {
   31    int level;
   32    Py_UNICODE *text;
   33    if (!PyArg_ParseTuple(args, "iu", &level, &text))
   34       return NULL;
   35 
   36 #ifdef UNICODE
   37    nxlog_debug(level, _T("%s"), text);
   38 #else
   39    char *mbtext = MBStringFromWideString(text);
   40    nxlog_debug(level, _T("%s"), mbtext);
   41    free(mbtext);
   42 #endif
   43 
   44    Py_INCREF(Py_None);
   45    return Py_None;
   46 }
   47 
   48 /**
   49  * Method netxms.version()
   50  */
   51 static PyObject *M_version(PyObject *self, PyObject *args)
   52 {
   53    return PyUnicode_FromString(NETXMS_VERSION_STRING_A);
   54 }
   55 
   56 /**
   57  * Method netxms.buildTag()
   58  */
   59 static PyObject *M_buildTag(PyObject *self, PyObject *args)
   60 {
   61    return PyUnicode_FromString(NETXMS_BUILD_TAG_A);
   62 }
   63 
   64 /**
   65  * Methods in module "netxms"
   66  */
   67 static PyMethodDef s_methods[] =
   68 {
   69    { "buildTag", M_buildTag, METH_NOARGS, "Return NetXMS build tag" },
   70    { "trace", M_trace, METH_VARARGS, "Write debug message to NetXMS log file" },
   71    { "version", M_version, METH_NOARGS, "Return NetXMS version" },
   72    { NULL, NULL, 0, NULL }
   73 };
   74 
   75 /**
   76  * Module definition
   77  */
   78 static PyModuleDef s_module =
   79 {
   80    PyModuleDef_HEAD_INIT,
   81    "netxms",   // name
   82    NULL,       // documentation
   83    -1,         // state struct size
   84    s_methods,  // methods
   85    NULL,       // slots
   86    NULL,       // traverse
   87    NULL,       // clear
   88    NULL        // free
   89 };
   90 
   91 /**
   92  * Module initialization
   93  */
   94 PyObject *PyInit_netxms()
   95 {
   96    PyObject *mod = PyModule_Create(&s_module);
   97    PyModule_AddObject(mod, "__path__", Py_BuildValue("()"));
   98    return mod;
   99 }