Navigation


Changeset 623:fc4f5815f0aa in freeDiameter


Ignore:
Timestamp:
Dec 7, 2010, 5:24:53 PM (13 years ago)
Author:
Sebastien Decugis <sdecugis@nict.go.jp>
Branch:
default
Phase:
public
Message:

Continued work on dbg_interactive.fdx

Files:
2 edited

Legend:

Unmodified
Added
Removed
  • doc/dbg_interactive.py.sample

    r622 r623  
    2121
    2222
     23# Change the global debug level of the framework (cvar contains all global variables)
     24cvar.fd_g_debug_lvl = FULL
     25
     26
    2327# Turn on debug for a specific function
    2428cvar.fd_debug_one_function = "gc_th_fct"
    2529
    2630
    27 # Use freeDiameter's debug facility
     31# Print messages to freeDiameter's debug facility
    2832fd_log_debug("3 + 4 = %d\n", 7)
    2933# Hum... Currently I get "3 + 4 = 0" output... need some fix...
    3034
    3135
    32 # Change the global debug level of the framework
    33 cvar.fd_g_debug_lvl = FULL
     36# SWIG deals with structures as follow:
     37# Take the structure:
     38# struct foo { int a; }
     39# The following functions are available to python:
     40# s = new_foo()    --> s = calloc(1, sizeof(struct foo))
     41# foo_a_set(s, 2)  --> s->a = 2
     42# foo_a_get(s)     --> returns s->a value
     43# delete_foo(s)    --> free(s)
    3444
    3545
     
    5666
    5767# Lists
    58 mylist = new_fd_list()
    59 fd_list_init(mylist, None)
     68l1 = new_fd_list()
    6069l2 = new_fd_list()
    61 fd_list_init(l2, None)
    62 fd_list_insert_after(mylist, l2)
    63 fd_list_unlink(l2)
     70fd_list_insert_after(l1, l2)
     71fd_list_dump(l1)
     72fd_list_dump(l2)
    6473delete_fd_list(l2)
    65 delete_fd_list(mylist)
     74fd_list_dump(l1)
     75delete_fd_list(l1)
     76
    6677
    6778# Dictionary
    6879gdict = fd_config_cnf_dict_get(cvar.fd_g_config)
    69 @@@ fd_dict_search ( gdict, DICT_APPLICATION, APPLICATION_BY_ID, id, res, -1 )
     80id = new_int_ptr()
     81int_ptr_assign(id, 3)
     82res = new_dict_object_ptr()
     83err = fd_dict_search ( gdict, DICT_APPLICATION, APPLICATION_BY_ID, id, res, -1 )
     84obj = dict_object_ptr_value(res)
     85t = new_dict_object_type_ptr()
     86err = fd_dict_gettype(obj, t)
     87dict_object_type_ptr_dump(t)
     88v = new_dict_application_data()
     89err = fd_dict_getval(obj, v)
     90dict_application_data_application_name_get(v)
    7091
    7192
    7293
    73 
  • extensions/dbg_interactive/diwrap.i

    r621 r623  
     1/* This interface file is processed by SWIG to create a python wrapper interface to freeDiameter framework. */
     2%module diwrap
     3%begin %{
    14/*********************************************************************************************************
    25* Software License Agreement (BSD License)                                                               *
     
    3336* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.                                                             *
    3437*********************************************************************************************************/
     38%}
    3539
    36 /* This interface file is processed by SWIG to create a python wrapper interface to freeDiameter framework. */
    37 %module diwrap
    3840
    39 /* Include standard types & functions used in freeDiameter headers */
    40 %include <stdint.i>
     41%init %{
     42/* TODO: How to load the proxy classes here? */
     43%}
    4144
    4245%{
     
    4649%}
    4750
     51
     52/* Include standard types & functions used in freeDiameter headers */
     53%include <stdint.i>
     54%include <cpointer.i>
     55%include <typemaps.i>
     56
    4857/* Some functions are not available through the wrapper */
    4958%ignore fd_lib_init;
    5059%ignore fd_lib_fini;
    51 %ignore fd_sess_start;
    5260
    5361/* Inline functions seems to give problems to SWIG -- just remove the inline definition */
     
    5563%enddef
    5664
    57 /* Make some global-variables read-only */
     65/* Make some global-variables read-only (mainly to avoid warnings) */
    5866%immutable fd_g_config;
    5967%immutable peer_state_str;
    6068
    61 /* Overwrite a few functions prototypes for usability */
     69/* Overwrite a few functions prototypes for usability: default parameters values, OUTPUT typemaps, ... */
    6270extern void fd_list_init ( struct fd_list * list, void * obj = NULL );
     71
     72
     73/*
     74extern int fd_dict_new ( struct dictionary * dict, enum dict_object_type type, void * data, struct dict_object * parent, struct dict_object ** OUTPUT );
     75extern int fd_dict_search ( struct dictionary * dict, enum dict_object_type type, int criteria, void * what, struct dict_object ** OUTPUT, int retval );
     76extern int fd_dict_get_error_cmd(struct dictionary * dict, struct dict_object ** OUTPUT);
     77extern int fd_dict_getval ( struct dict_object * object, void * INOUT);
     78//extern int fd_dict_gettype ( struct dict_object * object, enum dict_object_type * OUTPUT);
     79extern int fd_dict_getdict ( struct dict_object * object, struct dictionary ** OUTPUT);
     80*/
    6381
    6482
     
    6987
    7088
     89/* Some pointer types that are useful */
     90%pointer_class(int, int_ptr);
     91%pointer_class(enum dict_object_type, dict_object_type_ptr);
     92%pointer_functions(struct dict_object *, dict_object_ptr);
     93%pointer_functions(struct session *, session_ptr);
     94
     95
     96
     97
     98/* Extend some structures for usability/debug in python */
     99%extend fd_list {
     100        fd_list(void * o = NULL) {
     101                struct fd_list * li;
     102                li = (struct fd_list *) malloc(sizeof(struct fd_list));
     103                if (!li) {
     104                        fd_log_debug("Out of memory!\n");
     105                        return NULL;
     106                }
     107                fd_list_init(li, o);
     108                return li;
     109        }
     110        ~fd_list() {
     111                fd_list_unlink($self);
     112                free($self);
     113        }
     114        void dump() {
     115                fd_log_debug("list: %p\n", $self);
     116                fd_log_debug("  - next: %p\n", $self->next);
     117                fd_log_debug("  - prev: %p\n", $self->prev);
     118                fd_log_debug("  - head: %p\n", $self->head);
     119                fd_log_debug("  - o   : %p\n", $self->o);
     120        }
     121};
     122
     123%extend dict_object_type_ptr {
     124        void dump() {
     125                %#define CASE_STR(x)  case x: fd_log_debug(#x "\n"); break;
     126                switch (*$self) {
     127                        CASE_STR(DICT_VENDOR)
     128                        CASE_STR(DICT_APPLICATION)
     129                        CASE_STR(DICT_TYPE)
     130                        CASE_STR(DICT_ENUMVAL)
     131                        CASE_STR(DICT_AVP)
     132                        CASE_STR(DICT_COMMAND)
     133                        CASE_STR(DICT_RULE)
     134                        default: fd_log_debug("Invalid value (%d)", *$self); break;
     135                }
     136        }
     137}
     138
     139%inline %{
     140void session_ptr_showsid(struct session * s) {
     141        char * sid;
     142        int ret = fd_sess_getsid ( s, &sid );
     143        if (ret != 0) {
     144                fd_log_debug("Error %d\n", ret);
     145                /* throw an exception in SWIG? */
     146                return;
     147        }
     148        fd_log_debug("%s\n", sid);
     149}
     150%}
Note: See TracChangeset for help on using the changeset viewer.