The following example demonstrates using asynchronous function PrlSrv_GetSrvConfig synchronously, and the steps involved in obtaining a handle to an object of type PHT_SERVER_CONFIG (which is returned by PrlSrv_GetSrvConfig):
PRL_HANDLE hJob = PrlSrv_GetSrvConfig(hServer); // Step 1 - emulate a synchronous call using PrlJob_Wait. PRL_RESULT ret = PrlJob_Wait(hJob, 10000); if (PRL_FAILED(ret)) { printf("PrlJob_Wait for job PrlSrv_GetSrvConfig returned error: %s\n", PRL_RESULT_TO_STRING(ret)); PrlHandle_Free(hJob); PrlHandle_Free(hServer); PrlApi_Deinit(); SdkWrap_Unload(); return -1; } // Step 2 - determine if PrlSrv_GetSrvConfig succeeded or failed // using PrlJob_GetRetCode. PrlJob_GetRetCode(hJob, &nJobResult); if (PRL_FAILED(nJobResult)) { printf("PrlSrv_GetSrvConfig returned error: %s\n", PRL_RESULT_TO_STRING(ret)); PrlHandle_Free(hJob); PrlHandle_Free(hServer); PrlApi_Deinit(); SdkWrap_Unload(); return -1; } // Step 3 - Obtain a handle to the result object (a handle // of type PHT_RESULT) using PrlJob_GetResult. PRL_HANDLE hResult; ret = PrlJob_GetResult(hJob, &hResult); PrlHandle_Free(hJob); // hJob no longer needed, free it. if (PRL_FAILED(ret)) { printf("PrlJob_GetResult for job PrlSrv_GetSrvConfig returned error: %s\n", PRL_RESULT_TO_STRING(ret)); PrlHandle_Free(hResult); PrlHandle_Free(hServer); PrlApi_Deinit(); SdkWrap_Unload(); return -1; } // Step 4 - Get a handle to the final result (in this case, // a handle of type PHT_SERVER_CONFIG) using PrlResult_GetParam. // For PHT_RESULT handles that contain more than one result, first use // PrlResult_GetParamsCount, then use PrlResult_GetParamByIndex. PRL_HANDLE hServerConfig; ret = PrlResult_GetParam(hResult, &hServerConfig); PrlHandle_Free(hResult); // hResult no longer needed, free it. if (PRL_FAILED(ret)) { printf("PrlResult_GetParam for job PrlSrv_GetSrvConfig returned error: %s\n", PRL_RESULT_TO_STRING(ret)); PrlHandle_Free(hServerConfig); PrlHandle_Free(hServer); PrlApi_Deinit(); SdkWrap_Unload(); return -1; } // At this point, a handle of type PHT_SERVER_CONFIG is available, and // functions that operate on PHT_SERVER_CONFIG handles can be used on // the handle. PRL_UINT32 nCpuCount = 0; PrlSrvCfg_GetCpuCount(hServerConfig, &nCpuCount); printf("Number of CPUs: %d\n", nCpuCount); PRL_CPU_MODE CpuMode; PrlSrvCfg_GetCpuMode(hServerConfig, &CpuMode); printf("CPU Mode: %d bit\n", CpuMode == PCM_CPU_MODE_32 ? 32 : 64); PRL_CHAR szCpuModel[1024]; PRL_UINT32 nCpuModelSize = sizeof(szCpuModel); memset(szCpuModel, 0, nCpuModelSize); PrlSrvCfg_GetCpuModel(hServerConfig, szCpuModel, &nCpuModelSize); printf("CPU Model: %s\n", szCpuModel); PRL_UINT32 nCpuSpeed = 0; PrlSrvCfg_GetCpuSpeed(hServerConfig, &nCpuSpeed); printf("CPU Speed: %.3f MHz\n", nCpuSpeed / 1000.0); PRL_CHAR szHostOsString[1024]; PRL_UINT32 nHostOsStringSize = sizeof(szHostOsString); PrlSrvCfg_GetHostOsStrPresentation(hServerConfig, szHostOsString, &nHostOsStringSize); printf("Host OS: %s\n", szHostOsString); PrlHandle_Free(hServerConfig);