Swig java传递函数作为回调

时间:2015-10-10 15:56:23

标签: java callback handler swig

我有C代码,方法定义如下:

//! Definition of the verify appliance notification function.
typedef void (STDCALL *pfNotifyVerifyAppliance)(mdp_sdk_handle_t handle, const char* hostname, bool is_verified, const availableappliance_t* appliance, void* context);
//! Function to specify a function that should be called when an available appliance is verified. Appliance is only valid when is_verified is true.
EXTERN void STDCALL mdp_sdk_notify_verify_appliance(mdp_sdk_handle_t handle, pfNotifyVerifyAppliance NotifyVerifyAppliance);

NotifyVerifyAppliance在C代码示例中是一个函数回调,如下所示:

static void STDCALL NotifyVerifyAppliance(mdp_sdk_handle_t handle, const char* hostname, bool is_verified, const availableappliance_t* appliance, void* context)
{
...
}

我为该函数生成了Java包装器,生成的回调类如下所示:

public class SWIGTYPE_p_f_p_struct_mdp_sdk_handle_dummystruct_p_q_const__char_bool_p_q_const__availableappliance_t_p_void__void {
  private transient long swigCPtr;

  protected SWIGTYPE_p_f_p_struct_mdp_sdk_handle_dummystruct_p_q_const__char_bool_p_q_const__availableappliance_t_p_void__void(long cPtr, @SuppressWarnings("unused") boolean futureUse) {
    swigCPtr = cPtr;
  }

  protected SWIGTYPE_p_f_p_struct_mdp_sdk_handle_dummystruct_p_q_const__char_bool_p_q_const__availableappliance_t_p_void__void() {
    swigCPtr = 0;
  }

  protected static long getCPtr(SWIGTYPE_p_f_p_struct_mdp_sdk_handle_dummystruct_p_q_const__char_bool_p_q_const__availableappliance_t_p_void__void obj) {
    return (obj == null) ? 0 : obj.swigCPtr;
  }
}

我的回调类已实例化,但我不知道要访问数据。原始回调C方法没有参数。我应该如何改进Swig生成以实现这一目标?

0 个答案:

没有答案