I am using SWIG to generate Java and C++ wrappers to connect Java and C code: Java code ↔ C++ wrapper code ↔ C code.
C structure is defined like below, with a callback function pointer:
BOOL (STDCALL *sendAsyncRequest)(http_req_params *params, http_req **req); typedef struct http_req_params { CHAR* url; struct { UCHAR name[100]; UCHAR val[100]; } hdrs[10]; plt_http_responseCB rspCallBack; plt_http_type_params *http_type_params; plt_http_req_multipart_info *multipartReqData; } _plt_http_req_params; typedef struct { UINT32 length; VOID *pMultipartContent; CHAR contentType[10]; } http_req_multipart_contents; typedef struct { CHAR multipartBoundaryInfo[10]; UINT32 multipartContentCount; http_req_multipart_contents **multipartContents; } plt_http_req_multipart_info;
Now I want to wrap the above struct in a Java object using SWIG. How do we register for the callback function (
plt_http_responseCB
) with Java layer?This is the response callback definition:
typedef BOOL (STDCALL *plt_http_responseCB)(plt_http_rsp_params *rspInfo); typedef struct _plt_http_rsp_params { UINT16 reqStatus; UINT16 httpStatus; VOID * userData; plt_buf_info rspData; struct { UCHAR name[100]; UCHAR val[100]; } hdrs[10]; } plt_http_rsp_params;
On some OS events, we need to notify the C layer with the callback function (plt_http_responseCB
) which we received as part of C struct.
How can I achieve this using SWIG and generate Java wrappers? How can I apply the “director” feature in this use case?
3
So what is it that you want to accomplish? I have a hard time extracting any meaning out of this Time Cube aesthetic.
The C function pointer will come as parameter to java. I want to call C function pointer back from java. need to generate wrappers accordingly. swig.org/Doc1.3/Java.html#java_directors_faq
Directors is a C++ feature. Do you want to do this using only C?