Changeset 39 for caPython


Ignore:
Timestamp:
Feb 26, 2009 9:54:03 PM (16 years ago)
Author:
hammonds
Message:

Change so Callback functions to correctly pass out chid as object. Change callbacks to pass out arrays as lists instead of Tuples to match how unpack functions pass them. Change umpackPlainGet to pass out data as object instead of as a dictionary and change Callbacks to convert this to dictionary as they are passed out.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified caPython/branches/newPointers/ca_internal_functions.c

    r28 r39  
    9494    func = PyTuple_GetItem(pyTup, 0);
    9595    if (PyCallable_Check(func)) {
    96         chidptr = SWIG_NewPointerObj( (void *) &(connect_args.chid),
     96        chidptr = SWIG_NewPointerObj( (chid *) &(connect_args.chid),
    9797        SWIGTYPE_p_chid, 0);
    9898        retVals = Py_BuildValue("(Oi)", chidptr, connect_args.op);
     
    135135   
    136136    /* Create a swigged pointer to the channel identifier */
    137     chidptr = SWIG_NewPointerObj((char *) &(event_args.chid),
     137    chidptr = SWIG_NewPointerObj((chid *) &(event_args.chid),
    138138    SWIGTYPE_p_chid, 0);
    139139    /* Build a dictionary of CA values to return to the callback routine */
    140     retVals = Py_BuildValue("{s:s, s:i, s:i, s:i}",
     140    retVals = Py_BuildValue("{s:O, s:i, s:i, s:i}",
    141141                                GET_CHID, chidptr,
    142142                                GET_TYPE, event_args.type,
     
    255255        switch (dbrType) {
    256256            case DBR_STRING:
    257                 d = Py_BuildValue("{s:s}", PV_VALUE, (char *)pBuf->strval);
     257                d = Py_BuildValue("s", (char *)pBuf->strval);
    258258                break;
    259259            case DBR_CHAR:
    260                 d = Py_BuildValue("{s:b}", PV_VALUE, (int)pBuf->charval);
     260                d = Py_BuildValue("b", (int)pBuf->charval);
    261261                break;
    262262            /* case DBR_SHORT: = DBR_INT */
    263263            case DBR_INT:
    264                 d = Py_BuildValue("{s:h}", PV_VALUE, (int)pBuf->intval);
     264                d = Py_BuildValue("h", (int)pBuf->intval);
    265265                break;
    266266            case DBR_ENUM:
    267                 d = Py_BuildValue("{s:h}", PV_VALUE, (int)pBuf->enmval);
     267                d = Py_BuildValue("h", (int)pBuf->enmval);
    268268                break;
    269269            case DBR_LONG:
    270                 d = Py_BuildValue("{s:i}", PV_VALUE, (int)pBuf->longval);
     270                d = Py_BuildValue("i", (int)pBuf->longval);
    271271                break;
    272272            case DBR_FLOAT:
    273                 d = Py_BuildValue("{s:d}", PV_VALUE, (double)pBuf->fltval);
     273                d = Py_BuildValue("d", (double)pBuf->fltval);
    274274                break;
    275275            case DBR_DOUBLE:
    276                 d = Py_BuildValue("{s:d}", PV_VALUE, (double)pBuf->doubleval);
     276                d = Py_BuildValue("d", (double)pBuf->doubleval);
    277277                break;
    278278            default:
     
    281281    } /* end if */
    282282    else {
    283         t = PyTuple_New(count);
     283        t = PyList_New(count);
    284284        for(i = 0; i < count; ++i) {
    285285            switch (dbrType) {
     
    305305                break;
    306306            } /* end switch */
    307             PyTuple_SetItem(t, i, pyVal);
     307            PyList_SetItem(t, i, pyVal);
    308308        } /* end for */
    309         d = Py_BuildValue("{s:O}", PV_VALUE, t);
    310         Py_XDECREF(t);  /* dictionary now references the tuple */
     309        /*d = Py_BuildValue("{s:O}", PV_VALUE, t);*/
     310        d = t;
     311/*      Py_XDECREF(t); */ /* dictionary now references the tuple */
    311312    } /* end else */
    312313    return d;
     
    429430
    430431        } /* end switch(requestType) */
    431         t = PyTuple_New(count);
     432        t = PyList_New(count);
    432433        for(i = 0; i < count; ++i) {
    433434            switch (dbrType) {
     
    453454                break;
    454455            } /* end switch */
    455             PyTuple_SetItem(t, i, pyVal);
     456            PyList_SetItem(t, i, pyVal);
    456457        } /* end for */
    457458        PyDict_SetItemString(d, PV_VALUE, t);
     
    595596                printf("unpackTimeGet: Unknown DBR type\n");
    596597                } /* end switch(requestType) */
    597         t = PyTuple_New(count);
     598        t = PyList_New(count);
    598599        for(i = 0; i < count; ++i) {
    599600            switch (dbrType) {
     
    618619                break;
    619620            } /* end switch */
    620             PyTuple_SetItem(t, i, pyVal);
     621            PyList_SetItem(t, i, pyVal);
    621622        } /* end for */
    622623        PyDict_SetItemString(d, PV_VALUE, t);
     
    817818                printf("unpackGraphicGet: Unknown DBR type\n");
    818819                } /* end switch(requestType) */
    819         t = PyTuple_New(count);
     820        t = PyList_New(count);
    820821        for(i = 0; i < count; ++i) {
    821822            switch (dbrType) {
     
    840841                break;
    841842            } /* end switch */
    842             PyTuple_SetItem(t, i, pyVal);
     843            PyList_SetItem(t, i, pyVal);
    843844        } /* end for */
    844845        PyDict_SetItemString(d, PV_VALUE, t);
     
    10571058                printf("unpackControlGet: Unknown DBR type\n");
    10581059                } /* end switch(requestType) */                                         
    1059         t = PyTuple_New(count);
     1060        t = PyList_New(count);
    10601061        for(i = 0; i < count; ++i) {
    10611062            switch (dbrType) {
     
    10801081                break;
    10811082            } /* end switch */
    1082             PyTuple_SetItem(t, i, pyVal);
     1083            PyList_SetItem(t, i, pyVal);
    10831084        } /* end for */
    10841085        PyDict_SetItemString(d, PV_VALUE, t);
     
    11031104void getCallback(struct event_handler_args event_args)
    11041105{
    1105     PyObject *func, *args, *pyTup, *d=NULL, *result, *v;
     1106    PyObject *func, *args, *pyTup, *d=NULL, *s=NULL, *result, *v;
    11061107    PyObject *chidptr;
    11071108    /*char _ptemp[STR_LEN];*/
     
    11121113       
    11131114        if(dbr_type_is_plain(event_args.type)) {
    1114             d = unpackPlainGet(pBuf, event_args.type, event_args.count);
     1115            s = unpackPlainGet(pBuf, event_args.type, event_args.count);
     1116            d = Py_BuildValue( "{s:O}", PV_VALUE, s);
    11151117        }
    11161118        else if(dbr_type_is_STS(event_args.type)) {
     
    11301132    }
    11311133
    1132     chidptr = SWIG_NewPointerObj((char *) &(event_args.chid),
     1134    chidptr = SWIG_NewPointerObj((chid *) &(event_args.chid),
    11331135    SWIGTYPE_p_chid, 0);
    1134     v = Py_BuildValue("s", chidptr);
     1136    v = Py_BuildValue("O", chidptr);
    11351137    PyDict_SetItemString(d, GET_CHID, v);
    11361138    Py_XDECREF(v);
     
    11741176void eventCallback(struct event_handler_args event_args)
    11751177{
    1176     PyObject *func, *args, *pyTup, *d=NULL, *result, *v;
     1178    PyObject *func, *args, *pyTup, *d=NULL, *s=NULL, *result, *v;
    11771179    PyObject *chidptr;
    11781180    /*char _ptemp[STR_LEN];*/
     
    11821184        pBuf = (union db_access_val *)event_args.dbr;
    11831185        if(dbr_type_is_plain(event_args.type)) {
    1184             d = unpackPlainGet(pBuf, event_args.type, event_args.count);
     1186            s = unpackPlainGet(pBuf, event_args.type, event_args.count);
     1187            d = Py_BuildValue( "{s:O}", PV_VALUE, s);
    11851188        }
    11861189        else if(dbr_type_is_STS(event_args.type)) {
     
    12011204
    12021205    /* Create a swigged pointer to the channel identifier */
    1203     chidptr = SWIG_NewPointerObj((char *) &(event_args.chid),
     1206    chidptr = SWIG_NewPointerObj((chid *) &(event_args.chid),
    12041207    SWIGTYPE_p_chid, 0);
    12051208
    1206     v = Py_BuildValue("s", chidptr);
     1209    v = Py_BuildValue("O", chidptr);
    12071210    PyDict_SetItemString(d, GET_CHID, v);
    12081211    Py_XDECREF(v);
Note: See TracChangeset for help on using the changeset viewer.