Ejemplo n.º 1
0
void VMSaveState()
{
  HRESULT rc;
  IProgress *progress;
  ISession *session;
  IConsole *console;

  rc = CoCreateInstance(CLSID_Session, NULL, CLSCTX_INPROC_SERVER,
      IID_ISession, (void**)&session);
  if (!SUCCEEDED(rc)) {
    ShowError(L"Failed to create session instance for '%s'. rc = 0x%x", name, rc);
    return;
  }
  
  rc = machine->LockMachine(session, LockType_Shared);
  if (!SUCCEEDED(rc)) {
    ShowError(L"Failed to lock '%s'. rc = 0x%x", name, rc);
    return;
  }

  session->get_Console(&console);
  rc = console->SaveState(&progress);
  if (FAILED(rc)) {
    ShowError(L"Failed to save '%s' state. rc = 0x%x", name, rc);
    return;
  }

  progress->WaitForCompletion(-1);
  session->UnlockMachine();
  SAFE_RELEASE(progress);
  SAFE_RELEASE(console);
  SAFE_RELEASE(session);
}
Ejemplo n.º 2
0
bool VirtualBoxBridge::deleteVM(IMachine *m)
{
	uint32_t medias_size;
	IMedium ** medias;
	nsresult rc;

	NS_CHECK_AND_DEBUG_ERROR(m, Unregister(CleanupMode::Full, &medias_size, &medias), rc);
	if(NS_FAILED(rc))
		return false;
	
	std::cout << "medias_size: " << medias_size << std::endl;

	bool succeeded = true;
	for(int i = 0; i < medias_size; i++)
	{
		nsXPIDLString media_name;
		nsXPIDLString media_location;
		medias[i]->GetName(getter_Copies(media_name));
		medias[i]->GetLocation(getter_Copies(media_location));

		std::cout << "Deleting media " << returnQStringValue(media_name).toStdString()
		<< " (" << returnQStringValue(media_location).toStdString() << ")" << std::endl;
		
		IProgress *progress;
		int32_t resultCode;
		medias[i]->DeleteStorage(&progress);
		progress->WaitForCompletion(-1);
		progress->GetResultCode(&resultCode);
		
		if(resultCode != 0)
		{
			succeeded= false;
			std::cerr << "Error while deleting media " << returnQStringValue(media_name).toStdString()
				<< " (" << returnQStringValue(media_location).toStdString() << ")" << std::endl;
		}
		
		if(resultCode == 0)
		{
			QFile media_file(returnQStringValue(media_location));
			if(media_file.exists())
				media_file.remove();
		}
	}
	
	return succeeded;
}
Ejemplo n.º 3
0
void VMStart()
{
  HRESULT rc;
  IProgress *progress;
  ISession *session;
  BSTR stype = SysAllocString(L"headless");

  rc = CoCreateInstance(CLSID_Session, NULL, CLSCTX_INPROC_SERVER,
      IID_ISession, (void**)&session);
  if (!SUCCEEDED(rc)) {
    ShowError(L"Failed to create session instance for '%s'. rc = 0x%x", name, rc);
    return;
  }

  rc = machine->LaunchVMProcess(session, stype, NULL, &progress);
  if (!SUCCEEDED(rc))
    ShowError(L"Failed to start '%s'. rc = 0x%x", name, rc);

  progress->WaitForCompletion(-1);
  session->UnlockMachine();
  SysFreeString(stype);
  SAFE_RELEASE(progress);
  SAFE_RELEASE(session);
}