eventPump.c
Copyright © 2008 VMware, Inc. All rights reserved.
// This demonstrates how to integrate Vix with a poll loop. This
// is useful if you write an application that has a single thread, and
// you do not want Vix to create its own threads. For example, you want
// to receive asynchronous callbacks, but you can only be called on your
// main UI thread.
//
// This uses the VixJob_Wait function to block after starting each
// asynchronous function. This effectively makes the asynchronous
// functions synchronous, because VixJob_Wait will not return until the
// asynchronous function has completed.
//
#include "stdafx.h"
#include "windows.h"
#include "vix.h"
DWORD WINAPI TestThread(LPVOID threadParameter);
VixHandle hostHandle = VIX_INVALID_HANDLE;
////////////////////////////////////////////////////////////////////////////////
int _tmain(int argc, _TCHAR* argv[])
{
VixError err;
VixHandle jobHandle = VIX_INVALID_HANDLE;
VixHandle vmHandle = VIX_INVALID_HANDLE;
DWORD threadHandle;
CreateThread(NULL, 0, TestThread, NULL, 0, &threadHandle);
jobHandle = VixHost_Connect(VIX_API_VERSION,
VIX_SERVICEPROVIDER_VMWARE_SERVER,
NULL, // *hostName,
0, // hostPort,
NULL, // *userName,
NULL, // *password,
VIX_HOSTOPTION_USE_EVENT_PUMP, // options,
VIX_INVALID_HANDLE, // propertyListHandle,
NULL, // *callbackProc,
NULL); // *clientData);
err = VixJob_Wait(jobHandle,
VIX_PROPERTY_JOB_RESULT_HANDLE,
&hostHandle,
VIX_PROPERTY_NONE);
if (VIX_OK != err) {
goto abort;
}
Vix_ReleaseHandle(jobHandle);
jobHandle = VixVM_Open(hostHandle,
"C:\\Virtual Machines\\Windows XP Pro\\Windows XP Professional.vmx",
NULL, // VixEventProc *callbackProc,
NULL); // void *clientData);
err = VixJob_Wait(jobHandle,
VIX_PROPERTY_JOB_RESULT_HANDLE,
&vmHandle,
VIX_PROPERTY_NONE);
if (VIX_OK != err) {
goto abort;
}
Vix_ReleaseHandle(jobHandle);
jobHandle = VixVM_PowerOn(vmHandle,
VIX_VMPOWEROP_NORMAL,
VIX_INVALID_HANDLE,
NULL, // *callbackProc,
NULL); // *clientData);
err = VixJob_Wait(jobHandle, VIX_PROPERTY_NONE);
if (VIX_OK != err) {
goto abort;
}
Vix_ReleaseHandle(jobHandle);
jobHandle = VixVM_PowerOff(vmHandle,
VIX_VMPOWEROP_NORMAL,
NULL, // *callbackProc,
NULL); // *clientData);
err = VixJob_Wait(jobHandle, VIX_PROPERTY_NONE);
if (VIX_OK != err) {
goto abort;
}
VixHost_Disconnect(hostHandle);
goto done;
abort:
return 0;
done:
Vix_ReleaseHandle(jobHandle);
Vix_ReleaseHandle(vmHandle);
}
////////////////////////////////////////////////////////////////////////////////
DWORD WINAPI
TestThread(LPVOID threadParameter)
{
while (1) {
Vix_PumpEvents(hostHandle, VIX_PUMPEVENTOPTION_NONE);
}
return(0);
} // Rayon_ThreadMainLoop
If you have obtained this sample code as part of the VMware Server 1.0 SDK, or are using this sample code in conjunction with the VMware Server 1.0 SDK, the license terms of that SDK will govern your use of this sample code.
Otherwise, the sample code is provided "AS-IS" for use, modification, and redistribution in source and binary forms, provided that the copyright notice and this following list of conditions are retained and/or reproduced in your distribution. To the maximum extent permitted by law, VMware, Inc., its subsidiaries and affiliates hereby disclaim all express, implied and/or statutory warranties, including duties or conditions of merchantability, fitness for a particular purpose, and non-infringement of intellectual property rights. IN NO EVENT WILL VMWARE, ITS SUBSIDIARIES OR AFFILIATES BE LIABLE TO ANY OTHER PARTY FOR THE COST OF PROCURING SUBSTITUTE GOODS OR SERVICES, LOST PROFITS, LOSS OF USE, LOSS OF DATA, OR ANY INCIDENTAL, CONSEQUENTIAL, DIRECT, INDIRECT, OR SPECIAL DAMAGES, ARISING OUT OF THIS OR ANY OTHER AGREEMENT RELATING TO THE SAMPLE CODE.
You agree to defend, indemnify and hold harmless VMware, and any of its directors, officers, employees, agents, affiliates, or subsidiaries from and against all losses, damages, costs and liabilities arising from your use, modification and distribution of the sample code.
VMware does not certify or endorse your use of the sample code, nor is any support or other service provided in connection with the sample code.