Reputation: 61
I'm attempting to build a test framework in TCL that will allow me to perform scripted tests on a remote device over a TCP socket. There already exists a Visual Basic interface and with SWIG in Ubuntu I'm reusing the C functions that it calls to build a shared library that will work as an extension to TCL.
The device is controlled via C remote procedure calls. I'm able to send complex structures to and from TCL using SWIG to wrap the functions that call these RPCs. SWIG will even give me accessor functions to allow me create pointers to these structs which I can feed into the RPC functions. However I'm stuck when I want to create a pointer to primitives, or single data elements. SWIG does not create accessor functions in this case. For example, a RPC function may have a prototype of the following form:
rpc_testDefaults ( testDefaults_t, *testDefaults, dataValid_t, *validStatus );
Here *testDefaults
is a pointer to a complex structure, and SWIG generates accessor functions of the form new_testDefaults_t
, delete_testDefaults_t
, testDefaults_t_firstElement_set
, testDefaults_t_firstElement_get
etc.
*validStatus
is a pointer to a single data element (uint32_t), but no accessor functions are generated.
My interface file is of the form:
// rpcTest.i
%module rpcTest
%include <stdint.h>
%{
#include "header.h"
}%
%include "header.h"
My header.h defines the types for testDefaults_t
and dataValid_t
.
Ideally I'd be able to include a flag or something in the SWIG interface file which would tell SWIG to treat all pointers the same as structs, from the point of view of creating accessors.
I've been able to access the data in *validStatus
by either defining the typedef for dataValid_t
as a single element struct, which gives me the regular accessor functions, or using cpointer.i and defining the type in the interface file, which gives me a different set of accessor functions. I would prefer to not have to go either of these routes as this problem will occur hundreds of times in the full api, which is subject to change. I've also got it to work using typemaps and assigning the pointer as an output, but again I feel this is adding tedious code and I would prefer to use the same set of accessor functions to manage this data.
So, is there a way to automate the detection of these pointers and give them accessor functions without having to write hundreds of lines of regularly redundant code?
Any help is much appreciated.
Upvotes: 3
Views: 240
Reputation: 61
Eventually I found a solution:
%pointer_functions(dataValid_t,validStatus)
generates the new_, delete_, _assign, and _value functions for the single piece of data called validStatus. I thought this was only for structures. I have to do this every time I encounter this problem but is far preferable to modifying the source.
Upvotes: 1