Navigation



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

Finally got the proxy aka shadow class to work

File:
1 moved

Legend:

Unmodified
Added
Removed
  • extensions/dbg_interactive/dbg_interactive.i

    r623 r624  
    11/* This interface file is processed by SWIG to create a python wrapper interface to freeDiameter framework. */
    2 %module diwrap
     2%module fDpy
    33%begin %{
    44/*********************************************************************************************************
     
    3838%}
    3939
    40 
    41 %init %{
    42 /* TODO: How to load the proxy classes here? */
    43 %}
    44 
    4540%{
    46 /* Define types etc. */
     41/* This text is included in the generated wrapper verbatim */
    4742#define SWIG
    4843#include <freeDiameter/extension.h>
     
    5348%include <stdint.i>
    5449%include <cpointer.i>
     50%include <cdata.i>
     51%include <cstring.i>
    5552%include <typemaps.i>
    5653
     
    8077*/
    8178
    82 
    8379/* Retrieve the compile-time definitions of freeDiameter */
    8480%include "freeDiameter/freeDiameter-host.h"
     
    8884
    8985/* 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);
     86%pointer_functions(int, int_ptr);
     87%pointer_functions(uint8_t *, uint8_t_pptr);
     88%pointer_cast(char *, void *, char_to_void);
    9489
     90%pointer_functions(struct fd_list *, fd_list_pptr);
    9591
     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);
    96106
    97107
     
    103113                if (!li) {
    104114                        fd_log_debug("Out of memory!\n");
     115                        PyErr_SetString(PyExc_MemoryError,"Not enough memory");
    105116                        return NULL;
    106117                }
     
    121132};
    122133
    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                 }
     134%inline %{
     135void 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");
    136148        }
    137149}
     150%}
    138151
    139 %inline %{
    140 void 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;
     152%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) {
     157                        fd_log_debug("Out of memory!\n");
     158                        PyErr_SetString(PyExc_MemoryError,"Not enough memory");
     159                        $self->len = 0;
     160                        return;
     161                }
     162                $self->len = strlen(string);
    147163        }
    148         fd_log_debug("%s\n", sid);
     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 {
     173                        fd_log_debug("Out of memory!\n");
     174                        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};     
     185
     186%cstring_output_allocate_size(char ** swig_buffer, size_t * swig_len, free(*$1))
     187%inline %{
     188int fd_msg_bufferize_py ( struct msg * msg, char ** swig_buffer, size_t * swig_len ) {
     189        return fd_msg_bufferize(msg, (void *)swig_buffer, swig_len);
    149190}
    150 %}
     191%};
     192
Note: See TracChangeset for help on using the changeset viewer.