Navigation


Changeset 625:2cd2cf7abe2a in freeDiameter


Ignore:
Timestamp:
Dec 14, 2010, 11:52:28 AM (13 years ago)
Author:
Sebastien Decugis <sdecugis@nict.go.jp>
Branch:
default
Phase:
public
Message:

Improvements to usability, still work ongoing

Location:
extensions/dbg_interactive
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • extensions/dbg_interactive/CMakeLists.txt

    r624 r625  
    4242    "fDpy-inc.c"
    4343    MAIN_DEPENDENCY "${swig_extra_generated_files}"
    44     COMMENT "Converting swig proxy class to C string")
     44    COMMENT "Shadow definitions")
    4545
    4646# Ensure that the generated source files are removed
     
    5555TARGET_LINK_LIBRARIES(dbg_interactive ${PYTHON_LIBRARIES})
    5656
     57
     58####
     59## INSTALL section ##
     60
     61INSTALL(TARGETS dbg_interactive
     62        LIBRARY DESTINATION ${INSTALL_EXTENSIONS_SUFFIX}
     63        COMPONENT freeDiameter-debug-tools)
  • extensions/dbg_interactive/dbg_interactive.c

    r624 r625  
    5757        TRACE_ENTRY("%p", arg);
    5858       
    59         fd_log_threadname ( "[dbg_interactive python interpreter]" );
     59        fd_log_threadname ( "fDpy" );
    6060       
    61         sleep(1);
    62         fd_log_debug("\nStarting python interpreter [experimental].\n");
    63         fd_log_debug("Example syntax:\n>>> print fd_config_cnf_diamid_get(cvar.fd_g_config)\n\n");
     61        CHECK_FCT_DO(fd_wait_initialization_complete(), goto end);
     62       
     63        fd_log_debug("\nStarting interactive python interpreter [experimental].\n");
     64        if (!arg)
     65                fd_log_debug("Example syntax:\n   >>> print cvar.fd_g_config.cnf_diamid\n   '%s'\n", fd_g_config->cnf_diamid);
    6466        Py_Main(arg ? 2 : 1, dum);
    6567       
     68end:   
    6669        /* Upon exit, issue the order of terminating to fD */
    6770        CHECK_FCT_DO(fd_event_send(fd_g_config->cnf_main_ev, FDEV_TERMINATE, 0, NULL), );
     
    100103                free(shadow_hlp);
    101104               
    102        
    103         if (TRACE_BOOL(INFO)) {
    104                 PyRun_SimpleString("print \"[dbg_interactive] \",FD_PROJECT_NAME,FD_PROJECT_VERSION_MAJOR,FD_PROJECT_VERSION_MINOR,FD_PROJECT_VERSION_REV\n");
    105         }
    106        
    107105        CHECK_POSIX( pthread_create(&pyinterp, NULL, myinterp, conffile) );
    108106 
  • extensions/dbg_interactive/dbg_interactive.i

    r624 r625  
    4747/* Include standard types & functions used in freeDiameter headers */
    4848%include <stdint.i>
    49 %include <cpointer.i>
    5049%include <cdata.i>
    5150%include <cstring.i>
     
    6463%immutable peer_state_str;
    6564
    66 /* Overwrite a few functions prototypes for usability: default parameters values, OUTPUT typemaps, ... */
    67 extern void fd_list_init ( struct fd_list * list, void * obj = NULL );
    68 
    69 
    70 /*
    71 extern int fd_dict_new ( struct dictionary * dict, enum dict_object_type type, void * data, struct dict_object * parent, struct dict_object ** OUTPUT );
    72 extern int fd_dict_search ( struct dictionary * dict, enum dict_object_type type, int criteria, void * what, struct dict_object ** OUTPUT, int retval );
    73 extern int fd_dict_get_error_cmd(struct dictionary * dict, struct dict_object ** OUTPUT);
    74 extern int fd_dict_getval ( struct dict_object * object, void * INOUT);
    75 //extern int fd_dict_gettype ( struct dict_object * object, enum dict_object_type * OUTPUT);
    76 extern int fd_dict_getdict ( struct dict_object * object, struct dictionary ** OUTPUT);
    77 */
    78 
    79 /* Retrieve the compile-time definitions of freeDiameter */
     65
     66
     67/***********************************
     68 Some types & typemaps for usability
     69 ***********************************/
     70
     71/* for fd_hash */
     72%apply (char *STRING, size_t LENGTH) { ( char * string, size_t len ) };
     73
     74/* for dictionary functions */
     75%typemap(in, numinputs=0,noblock=1) SWIGTYPE ** OUTPUT (void *temp = NULL) {
     76        $1 = (void *)&temp;
     77}
     78%typemap(argout,noblock=1) SWIGTYPE ** OUTPUT {
     79        %append_output(SWIG_NewPointerObj(*$1, $*1_descriptor, 0));
     80}
     81%apply SWIGTYPE ** OUTPUT { struct dict_object ** ref };
     82%apply SWIGTYPE ** OUTPUT { struct dict_object ** result };
     83
     84
     85
     86/*********************************************************
     87 Now, create wrappers for (almost) all objects from fD API
     88 *********************************************************/
    8089%include "freeDiameter/freeDiameter-host.h"
    8190%include "freeDiameter/libfreeDiameter.h"
     
    8392
    8493
    85 /* Some pointer types that are useful */
    86 %pointer_functions(int, int_ptr);
    87 %pointer_functions(uint8_t *, uint8_t_pptr);
    88 %pointer_cast(char *, void *, char_to_void);
    89 
    90 %pointer_functions(struct fd_list *, fd_list_pptr);
    91 
    92 %pointer_functions(enum dict_object_type, dict_object_type_ptr);
    93 %pointer_functions(struct dict_object *, dict_object_pptr);
    94 
    95 %pointer_functions(struct session *, session_pptr);
    96 %pointer_functions(struct session_handler *, session_handler_pptr);
    97 %pointer_functions(session_state *, session_state_pptr);
    98 
    99 %pointer_functions(struct rt_data *, rt_data_pptr);
    100 %pointer_cast(struct fd_list *, struct rtd_candidate *, fd_list_to_rtd_candidate);
    101 
    102 %pointer_functions(struct msg *, msg_pptr);
    103 %pointer_functions(struct msg_hdr *, msg_hdr_pptr);
    104 %pointer_functions(struct avp *, avp_pptr);
    105 %pointer_functions(struct avp_hdr *, avp_hdr_pptr);
    106 
    107 
    108 /* Extend some structures for usability/debug in python */
     94
     95/**********************************************************/
     96/* The remaining of this file allows easier manipulation of
     97the structures and functions of fD by providing wrapper-specific
     98extensions to the freeDiameter API.
     99
     100/****** LISTS *********/
     101
    109102%extend fd_list {
     103        /* allow a parameter in the constructor, and perform the fd_list_init operation */
    110104        fd_list(void * o = NULL) {
    111105                struct fd_list * li;
     
    119113                return li;
    120114        }
     115        /* Unlink before freeing */
    121116        ~fd_list() {
    122117                fd_list_unlink($self);
    123118                free($self);
    124119        }
     120        /* For debug, show the values of the list */
    125121        void dump() {
    126122                fd_log_debug("list: %p\n", $self);
     
    132128};
    133129
     130/****** DICTIONARY *********/
     131
     132struct dictionary {
     133};
     134
     135%extend dictionary {
     136        dictionary() {
     137                struct dictionary * r = NULL;
     138                int ret = fd_dict_init(&r);
     139                if (ret != 0) {
     140                        fd_log_debug("Error: %s\n", strerror(ret));
     141                        PyErr_SetString(PyExc_MemoryError,"Not enough memory");
     142                        return NULL;
     143                }
     144                return r;
     145        }
     146        ~dictionary() {
     147                if (self) {
     148                        struct dictionary *d = self;
     149                        int ret = fd_dict_fini(&d);
     150                        if (ret != 0) {
     151                                fd_log_debug("Error: %s\n", strerror(ret));
     152                        }
     153                        return;
     154                }
     155        }
     156        void dump() {
     157                if ($self) {
     158                        fd_dict_dump($self);
     159                }
     160        }
     161        PyObject * vendors_list() {
     162                uint32_t *list = NULL, *li;
     163                PyObject * ret;
     164                if (!$self) {
     165                        PyErr_SetString(PyExc_SyntaxError,"dict_object cannot be created directly. Use fd_dict_new.");
     166                        return NULL;
     167                }
     168                ret = PyList_New(0);
     169                list = fd_dict_get_vendorid_list($self);
     170                for (li = list; *li != 0; li++) {
     171                        PyList_Append(ret, PyInt_FromLong((long)*li));
     172                }
     173                free(list);
     174                return ret;
     175        }
     176       
     177}
     178
     179struct dict_object {
     180};
     181
     182%extend dict_object {
     183        dict_object() {
     184                fd_log_debug("Error: dict_object cannot be created directly. Use fd_dict_new\n");
     185                PyErr_SetString(PyExc_SyntaxError,"dict_object cannot be created directly. Use fd_dict_new.");
     186                return NULL;
     187        }
     188        ~dict_object() {
     189                fd_log_debug("Error: dict_object cannot be destroyed directly. Destroy the parent dictionary.\n");
     190                return;
     191        }
     192        void dump() {
     193                if ($self) {
     194                        fd_dict_dump_object($self);
     195                }
     196        }
     197}
     198
     199/* overload the search function to allow passing integers & string criteria directly */
     200%rename(fd_dict_search) fd_dict_search_int;
    134201%inline %{
    135 void dict_object_type_ptr_dump(enum dict_object_type * t) {
    136         #define CASE_STR(x)  case x: fd_log_debug(#x "\n"); break;
    137         switch (*t) {
    138                 CASE_STR(DICT_VENDOR)
    139                 CASE_STR(DICT_APPLICATION)
    140                 CASE_STR(DICT_TYPE)
    141                 CASE_STR(DICT_ENUMVAL)
    142                 CASE_STR(DICT_AVP)
    143                 CASE_STR(DICT_COMMAND)
    144                 CASE_STR(DICT_RULE)
    145                 default:
    146                         fd_log_debug("Invalid value (%d)", *t);
    147                         PyErr_SetString(PyExc_IndexError,"Invalid dictionary type object");
    148         }
    149 }
    150 %}
     202int fd_dict_search_int ( struct dictionary * dict, enum dict_object_type type, int criteria, int what_by_val, struct dict_object ** result, int retval ) {
     203        return fd_dict_search ( dict, type, criteria, &what_by_val, result, retval );
     204}
     205%}
     206%rename(fd_dict_search) fd_dict_search_string;
     207%inline %{
     208int fd_dict_search_string ( struct dictionary * dict, enum dict_object_type type, int criteria, char * what_by_string, struct dict_object ** result, int retval ) {
     209        return fd_dict_search ( dict, type, criteria, what_by_string, result, retval );
     210}
     211%}
     212
    151213
    152214%extend avp_value_os {
    153         void fromstr(char * string) {
    154                 if ($self->data) free($self->data);
    155                 $self->data = (uint8_t *)strdup(string);
    156                 if (!$self->data) {
     215        ~avp_value_os() {
     216                if (self)
     217                        free(self->data);
     218        }
     219        void dump() {
     220                if ($self) {
     221                        %#define LEN_MAX 20
     222                        int i, n=LEN_MAX;
     223                        if ($self->len < LEN_MAX)
     224                                n = $self->len;
     225                        fd_log_debug("l:%u, v:[", $self->len);
     226                        for (i=0; i < n; i++)
     227                                fd_log_debug("%02.2X", $self->data[i]);
     228                        fd_log_debug("] '%.*s%s'\n", n, $self->data, n == LEN_MAX ? "..." : "");
     229                }
     230        }
     231}
     232
     233%extend avp_value {
     234        void os_set(char *STRING, size_t LENGTH) {
     235                free($self->os.data);
     236                $self->os.data = malloc(LENGTH);
     237                if (!$self->os.data) {
    157238                        fd_log_debug("Out of memory!\n");
    158239                        PyErr_SetString(PyExc_MemoryError,"Not enough memory");
    159                         $self->len = 0;
    160240                        return;
    161241                }
    162                 $self->len = strlen(string);
    163         }
    164         %newobject as_str;
    165         char * tostr() {
    166                 char * r;
    167                 if ($self->len == 0)
    168                         return NULL;
    169                 r = malloc($self->len + 1);
    170                 if (r) {
    171                         strncpy(r, (char *)$self->data, $self->len + 1);
    172                 } else {
     242                memcpy($self->os.data, STRING, LENGTH);
     243                $self->os.len = LENGTH;
     244        }
     245        void os_set(avp_value_os * os) {
     246                free($self->os.data);
     247                $self->os.data = malloc(os->len);
     248                if (!$self->os.data) {
    173249                        fd_log_debug("Out of memory!\n");
    174250                        PyErr_SetString(PyExc_MemoryError,"Not enough memory");
    175                 }
    176                 return r;
    177         }
    178 };     
    179 
    180 %extend avp_value {
    181         void os_set(void * os) {
    182                 memcpy(&$self->os, os, sizeof($self->os));
    183         }
    184 };     
     251                        return;
     252                }
     253                memcpy($self->os.data, os->data, os->len);
     254                $self->os.len = os->len;
     255        }
     256};
    185257
    186258%cstring_output_allocate_size(char ** swig_buffer, size_t * swig_len, free(*$1))
Note: See TracChangeset for help on using the changeset viewer.