Commit 883ed988 authored by Sebastien Decugis's avatar Sebastien Decugis
Browse files

Very very early python interactive extension, using SWIG

parent 8bf9199a
......@@ -85,6 +85,7 @@ FD_EXTENSION_SUBDIR(dbg_monitor "Outputs periodical status information"
FD_EXTENSION_SUBDIR(dbg_rt "Routing extension for debugging the routing module" OFF)
FD_EXTENSION_SUBDIR(test_app "Testing application to send dummy message to another peer, like a Diameter 'ping'" OFF)
FD_EXTENSION_SUBDIR(test_sip "Testing application to simulate Diameter-SIP client (RFC4740)" OFF)
FD_EXTENSION_SUBDIR(dbg_interactive "Python-interpreter based module" OFF)
# The following extension have very little use except for specific tests, so we disable them except in Debug configurations.
......
# The rt_debug extension
PROJECT("Interactive debug facility based on SWIG" C)
# This module is using Python
FIND_PACKAGE(PythonLibs)
INCLUDE_DIRECTORIES(${PYTHON_INCLUDE_PATH})
#####
# Wrapper to fD in python
FIND_PACKAGE(SWIG REQUIRED)
INCLUDE(${SWIG_USE_FILE})
SET(CMAKE_SWIG_FLAGS "")
# We create the module even if we don't use it, so that intermediate values are defined
SWIG_ADD_MODULE(diwrap python diwrap.i)
#####
# Extension that embeds the python interpreter
FD_ADD_EXTENSION(dbg_interactive dbg_interactive.c ${swig_generated_sources} ${swig_other_sources})
TARGET_LINK_LIBRARIES(dbg_interactive ${PYTHON_LIBRARIES})
/*********************************************************************************************************
* Software License Agreement (BSD License) *
* Author: Sebastien Decugis <sdecugis@nict.go.jp> *
* *
* Copyright (c) 2010, WIDE Project and NICT *
* All rights reserved. *
* *
* Redistribution and use of this software in source and binary forms, with or without modification, are *
* permitted provided that the following conditions are met: *
* *
* * Redistributions of source code must retain the above *
* copyright notice, this list of conditions and the *
* following disclaimer. *
* *
* * Redistributions in binary form must reproduce the above *
* copyright notice, this list of conditions and the *
* following disclaimer in the documentation and/or other *
* materials provided with the distribution. *
* *
* * Neither the name of the WIDE Project or NICT nor the *
* names of its contributors may be used to endorse or *
* promote products derived from this software without *
* specific prior written permission of WIDE Project and *
* NICT. *
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED *
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR *
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT *
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS *
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR *
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF *
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
*********************************************************************************************************/
#include <Python.h>
#include <freeDiameter/extension.h>
/* wrapper generated by SWIG */
extern void init_diwrap(void);
/* Run an interactive interpreter in a separate thread */
static pthread_t pyinterp = (pthread_t)NULL;
static void * myinterp (void * arg)
{
char * dum[2] = { arg, NULL };
TRACE_ENTRY("%p", arg);
sleep(1);
fd_log_debug("\nStarting python interpreter [experimental].\n");
fd_log_debug("Example syntax:\n>>> print fd_config_cnf_diamid_get(cvar.fd_g_config)\n\n");
Py_Main(arg ? 1 : 0, dum);
/* Upon exit, issue the order of terminating to fD */
CHECK_FCT_DO(fd_event_send(fd_g_config->cnf_main_ev, FDEV_TERMINATE, 0, NULL), );
return NULL;
}
/* Register the callbacks to the daemon */
static int di_main(char * conffile)
{
TRACE_ENTRY("%p", conffile);
Py_Initialize();
init_diwrap();
PyRun_SimpleString("from _diwrap import *\n");
if (TRACE_BOOL(INFO)) {
PyRun_SimpleString("print \"[dbg_interactive] fD \",FD_PROJECT_VERSION_MAJOR,\".\",FD_PROJECT_VERSION_MINOR,\".\",FD_PROJECT_VERSION_REV\n");
}
/*
PyRun_SimpleString("config = cvar.fd_g_config\n");
PyRun_SimpleString("dict = fd_config_cnf_dict_get(config)\n");
PyRun_SimpleString("fd_dict_dump(dict)\n");
*/
CHECK_POSIX( pthread_create(&pyinterp, NULL, myinterp, conffile) );
return 0;
}
/* Terminate the extension */
void fd_ext_fini(void)
{
TRACE_ENTRY();
CHECK_FCT_DO(fd_thr_term(&pyinterp), );
/* Cleanup the python interpreter */
Py_Finalize();
return ;
}
/* Define the entry point function */
EXTENSION_ENTRY("dbg_interactive", di_main);
/*********************************************************************************************************
* Software License Agreement (BSD License) *
* Author: Sebastien Decugis <sdecugis@nict.go.jp> *
* *
* Copyright (c) 2010, WIDE Project and NICT *
* All rights reserved. *
* *
* Redistribution and use of this software in source and binary forms, with or without modification, are *
* permitted provided that the following conditions are met: *
* *
* * Redistributions of source code must retain the above *
* copyright notice, this list of conditions and the *
* following disclaimer. *
* *
* * Redistributions in binary form must reproduce the above *
* copyright notice, this list of conditions and the *
* following disclaimer in the documentation and/or other *
* materials provided with the distribution. *
* *
* * Neither the name of the WIDE Project or NICT nor the *
* names of its contributors may be used to endorse or *
* promote products derived from this software without *
* specific prior written permission of WIDE Project and *
* NICT. *
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED *
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR *
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT *
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS *
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR *
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF *
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
*********************************************************************************************************/
%module diwrap
%{
/* include the header in the wrapper code */
#include <freeDiameter/extension.h>
%}
/* Parse the header to generate the wrappers */
%include "freeDiameter/freeDiameter-host.h"
%include "freeDiameter/libfreeDiameter.h"
%include "freeDiameter/freeDiameter.h"
......@@ -569,6 +569,7 @@ int fd_breakhere(void);
/*============================================================*/
/* THREADS */
/*============================================================*/
#ifndef SWIG
/* Terminate a thread */
static __inline__ int fd_thr_term(pthread_t * th)
......@@ -632,6 +633,7 @@ static __inline__ void fd_cleanup_socket(void * sockptr)
}
}
#endif /* SWIG */
/*============================================================*/
/* SIGNALS */
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment