如何从JAVA调用C / C ++异步回调(在DLL中)

时间:2014-07-19 09:21:32

标签: java c dll asynccallback

我想通过信息技术开发平台(LMapi),v9.1

从自定义Java程序监控Informatica ETL工作流程

我已经有了C程序,它工作正常,但它对Java来说是个很棒的端口。

我们得到了许多具有异步功能的C DLL,例如:JavaLMApi.dll,INFA_LMMonitorServerA(具有详细的事件日志可能性)

在标题中我们可以看到:

PMLM_API_EXTSPEC INFA_API_STATUS

INFA_LMMonitorServerA (   INFA_UINT32 connectionId,   struct INFA_LMAPI_MONITOR_SERVER_REQUEST_PARAMS *请求,   void * clientContext,   INFA_UINT32 * requestId );

此问题没有任何文档,只有这些信息才能用于解析。

问题是:如何在Java中调用/使用INFA_LMMonitorServerA? (使用JNA / JNI加载DLL并不是问题,只有回调)。

static INFA_UINT32 nConnectionId = 0;

/* C-"skeleton": */
void GetSrvDetailcallback(struct INFA_API_REPLY_CONTEXT* GetSrvDetailReplyCtxt)
{
    INFA_API_STATUS apiRet;
    struct INFA_LMAPI_SERVER_DETAILS *serverDetails = NULL;
    char *serverStatus = NULL;

    /* Check if the return status is Acknowledgement */
    if (GetSrvDetailReplyCtxt->returnStatus == INFA_REQUEST_ACKNOWLEDGED)
    {
        fprintf(stdout, "\nINFA REQUEST ACKNOWLEDGED \n\n",NULL);
        return;
    }

    apiRet = INFA_LMGetServerDetailsResults(GetSrvDetailReplyCtxt, &serverDetails);
    /* Check the return code if if is an error */
    if (INFA_SUCCESS != apiRet)
    {
        fprintf(stderr, "Error: INFA_LMGetServerDetailsResults returns %d\n", apiRet);
        return;
    }

    printResults(serverDetails);
}

static void myServer()
{
    struct INFA_LMAPI_CONNECT_SERVER_REQUEST_PARAMS_EX connectParamsex;
    INFA_API_STATUS apiRet;
    struct INFA_LMAPI_LOGIN_REQUEST_PARAMS loginparams;

    apiRet = INFA_LMLogin(nConnectionId, &loginparams, NULL);
    if (INFA_SUCCESS != apiRet)
    {
        fprintf(stderr, "Error: INFA_LMLogin returns %d\n", apiRet);
        return;
    }

    struct INFA_LMAPI_MONITOR_SERVER_REQUEST_PARAMS strMonitorRequestParams;
    //Only Running Tasks
    strMonitorRequestParams.monitorMode = INFA_LMAPI_MONITOR_RUNNING;
    strMonitorRequestParams.continuous = INFA_TRUE;

    /* Get Server Details */
    INFA_UINT32 GetSrvDetailsrequestId = 0;
    /* Register a callback function. */
    INFA_LMRegisterCallback(INFA_LMAPI_MONITOR_SERVER, &GetSrvDetailcallback);
    apiRet = INFA_LMMonitorServerA(nConnectionId, &strMonitorRequestParams, NULL, &GetSrvDetailsrequestId);
    if (INFA_SUCCESS != apiRet && INFA_REQUEST_PENDING != apiRet)
    {
        fprintf(stderr, "Error: INFA_LMMonitorServerA returns %d\n", apiRet);
        return;
    }
}

0 个答案:

没有答案