Collapse All
Virtuozzo Virtualization SDK C API Reference
ContentsIndex
PreviousUpNext
PrlSrv_LookupParallelsServers@PRL_UINT32@PRL_EVENT_HANDLER_PTR@PRL_VOID_PTR
PHT_SERVER  Example
Example

The following example illustrates how to call the PrlSrv_LookupParallelsServers synchronously.

hJob =
PrlSrv_LookupParallelsServers(
    10000,  // timeout
    NULL,   // callback function (not used)
    NULL    // user object pointer (not used)
);

printf("Searching for Virtuozzo Services...\n");

nRetCode =
PrlJob_Wait(hJob, 100000);

if (PRL_FAILED(nRetCode))
{
    fprintf(stderr, "PrlJob_Wait returned with error: %s.\n",
        PRL_RESULT_TO_STRING( nRetCode));
    PrlApi_Deinit();
    SdkWrap_Unload();
    return nRetCode;
}

PrlJob_GetResult(hJob, &hJobResult);
PrlHandle_Free(hJob);

PRL_UINT32 nIndex, nCount;
PrlResult_GetParamsCount(hJobResult, &nCount);

for (nIndex = 0; nIndex < nCount ; nIndex++)
{
    PRL_HANDLE hParam;
    PrlResult_GetParamByIndex(hJobResult, nIndex, &hParam);

    PRL_CHAR sBuf[1024];
    PRL_UINT32 nBufSize = sizeof(sBuf);

    nRetCode =
    PrlSrvInfo_GetHostName(hParam, sBuf, &nBufSize);

    if (PRL_SUCCEEDED(nRetCode))
        printf("Found Service: %s.\n", &sBuf[0]);
    else
        fprintf(stderr, "PrlSrvInfo_GetHostName failed, error: %s. \n",
            PRL_RESULT_TO_STRING(nRetCode));

    PrlHandle_Free(hParam);
}

PrlHandle_Free(hJobResult);

In the following example, the PrlSrv_LookupParallelsServers is called asynchronously. In order to that, we first have to implement a callback function (let's call it ourCallback):

static PRL_RESULT ourCallback(PRL_HANDLE hEvent, PRL_VOID_PTR pUserData)
{
    printf("%s: ", pUserData);

    // Get the name of the host machine.
    PRL_UINT32 nBufSize = 1024;
    PRL_CHAR sBuf[nBufSize];
    PrlSrvInfo_GetHostName(hEvent, sBuf, &nBufSize);

    // Get the other properties and process them here...

    // The handle must be freed.
    PrlHandle_Free(hEvent);
    return rc;
}

The PrlSrv_LookupParallelsServers function can now be called as follows:

hJob =
PrlSrv_LookupParallelsServers(
    1000,
    &ourCallback,
    (PRL_VOID_PTR)("callback")
);
Links
Copyright ©2016-2017 Parallels International GmbH. All rights reserved.