私はこの質問回答フォーラムで非常に新しく、swigでも同じです。 swigインターフェイスファイルを使用してJavaおよびC用のラッパーを生成する正しい手順に従っているかどうかはわかりません。SWIGの構造体の関数ポインタを処理します
私のヘッダexample.h
ファイルが
#ifndef INCLUDE_ARTIK_WEBSOCKET_H_
#define INCLUDE_ARTIK_WEBSOCKET_H_
#ifdef __cplusplus
extern "C" {
#endif
typedef enum {
SAMPLE_WEBSOCKET_CLOSED = 1,
SAMPLE_WEBSOCKET_CONNECTED,
SAMPLE_WEBSOCKET_HANDSHAKE_ERROR
} sample_websocket_connection_state;
typedef void *sample_websocket_handle;
typedef struct {
char *uri;
void *private_data;
} sample_websocket_config;
typedef struct {
void(*websocket_request) (
sample_websocket_handle * handle,
sample_websocket_config * config
);
} sample_websocket_module;
extern const sample_websocket_module websocket_module;
#ifdef __cplusplus
}
#endif
#endif
以下のようになります。そして、私のインターフェイスファイルtest_app.i
は、以下のようになります。
%module test_app
%{
#include "example.h"
%}
%include "example.h"
そして、私は、ファイルに
-
を次生成するコマンド
- sample_websocket_config.jav
- sample_websocket_module.java
- SWIGTYPE_p_void.java
- test_app.java
- test_app_wrap.c
- sample_websocket_connection_state.java
- SWIGTYPE_p_f_p_p_void_p_sample_websocket_config__void.java
test_appJNI.java
typedef struct { void(*websocket_request) ( sample_websocket_handle * handle, sample_websocket_config * config );
} sample_websocket_module;上記のコード
swig -java test_app.i
を使用してラッパーを生成
は
public class sample_websocket_module {
private transient long swigCPtr;
protected transient boolean swigCMemOwn;
protected sample_websocket_module(long cPtr, boolean cMemoryOwn) {
swigCMemOwn = cMemoryOwn;
swigCPtr = cPtr;
}
protected static long getCPtr(sample_websocket_module obj) {
return (obj == null) ? 0 : obj.swigCPtr;
}
protected void finalize() {
delete();
}
public synchronized void delete() {
if (swigCPtr != 0) {
if (swigCMemOwn) {
swigCMemOwn = false;
test_appJNI.delete_sample_websocket_module(swigCPtr);
}
swigCPtr = 0;
}
}
public void setWebsocket_request(SWIGTYPE_p_f_p_p_void_p_sample_websocket_config__void value) {
test_appJNI.sample_websocket_module_websocket_request_set(swigCPtr, this, SWIGTYPE_p_f_p_p_void_p_sample_websocket_config__void.getCPtr(value));
}
public SWIGTYPE_p_f_p_p_void_p_sample_websocket_config__void getWebsocket_request() {
long cPtr = test_appJNI.sample_websocket_module_websocket_request_get(swigCPtr, this);
return (cPtr == 0) ? null : new SWIGTYPE_p_f_p_p_void_p_sample_websocket_config__void(cPtr, false);
}
public sample_websocket_module() {
this(test_appJNI.new_sample_websocket_module(), true);
}
}
下回っだから私はそれが両方の引数を合併し、別のクラスSWIGTYPE_p_f_p_p_void_p_sample_websocket_config__void.java
を作成しているように、この関数に引数をどのように提供するかを確認していないように見えるsample_websocket_module.java
クラスを生成します。
public class SWIGTYPE_p_f_p_p_void_p_sample_websocket_config__void {
private transient long swigCPtr;
protected SWIGTYPE_p_f_p_p_void_p_sample_websocket_config__void(long cPtr, @SuppressWarnings("unused") boolean futureUse) {
swigCPtr = cPtr;
}
protected SWIGTYPE_p_f_p_p_void_p_sample_websocket_config__void() {
swigCPtr = 0;
}
protected static long getCPtr(SWIGTYPE_p_f_p_p_void_p_sample_websocket_config__void obj) {
return (obj == null) ? 0 : obj.swigCPtr;
}
}
これは上記のクラスを使用している関数です。では、この関数にどのように値を与えることができますか?
public void setWebsocket_request(SWIGTYPE_p_f_p_p_void_p_sample_websocket_config__void value) {
test_appJNI.sample_websocket_module_websocket_request_set(swigCPtr, this, SWIGTYPE_p_f_p_p_void_p_sample_websocket_config__void.getCPtr(value));
}
ありがとうございます。