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); }
GIL_FORCEINLINE F transform_pixels_locator_progress( const View1& src1, const OfxRectI& src1Rod, const View2& src2, const OfxRectI& src2Rod, const View2& src3, const OfxRectI& src3Rod, const ViewDst& dst, const OfxRectI& dstRod, const OfxRectI& renderWin, const F& fun, IProgress& p ) { const std::ptrdiff_t renderWidth = renderWin.x2 - renderWin.x1; typename View1::xy_locator s1loc = src1.xy_at( renderWin.x1-src1Rod.x1, renderWin.y1-src1Rod.y1 ); typename View2::xy_locator s2loc = src2.xy_at( renderWin.x1-src2Rod.x1, renderWin.y1-src2Rod.y1 ); typename View3::xy_locator s3loc = src3.xy_at( renderWin.x1-src3Rod.x1, renderWin.y1-src3Rod.y1 ); for( std::ptrdiff_t y = renderWin.y1; y < renderWin.y2; ++y ) { typename ViewDst::x_iterator dstIt = dst.x_at( dstRod.x1, y-dstRod.y1 ); for( std::ptrdiff_t x = renderWin.x1; x < renderWin.x2; ++x, ++s1loc.x(), ++s2loc.x(), ++s3loc.x(), ++dstIt ) { *dstIt = fun( s1loc, s2loc, s3loc ); } s1loc.x() -= renderWidth; ++s1loc.y(); s2loc.x() -= renderWidth; ++s2loc.y(); s3loc.x() -= renderWidth; ++s3loc.y(); if( p.progressForward( renderWidth ) ) return fun; } return fun; }
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; }
GIL_FORCEINLINE F transform_pixels_progress( const View& dst, const F& fun, IProgress& p ) { for( std::ptrdiff_t y = 0; y < dst.height(); ++y ) { typename View::x_iterator dstIt = dst.row_begin( y ); for( std::ptrdiff_t x = 0; x < dst.width(); ++x ) fun( dstIt[x] ); if( p.progressForward( dst.width() ) ) return fun; } return fun; }
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); }
GIL_FORCEINLINE F transform_pixels_progress( const View1& src, const View2& dst, const F& fun, IProgress& p ) { assert( src.dimensions() == dst.dimensions() ); for( std::ptrdiff_t y = 0; y < src.height(); ++y ) { typename View1::x_iterator srcIt = src.row_begin( y ); typename View2::x_iterator dstIt = dst.row_begin( y ); for( std::ptrdiff_t x = 0; x < src.width(); ++x ) dstIt[x] = fun( srcIt[x] ); if( p.progressForward( dst.width() ) ) return fun; } return fun; }
GIL_FORCEINLINE F transform_pixels_progress( const View1& src1, const View2& src2, const View3& src3, const View4& dst, const F& fun, IProgress& p ) { assert( src1.dimensions() == dst.dimensions() ); assert( src2.dimensions() == dst.dimensions() ); assert( src3.dimensions() == dst.dimensions() ); for( std::ptrdiff_t y = 0; y < dst.height(); ++y ) { typename View1::x_iterator srcIt1 = src1.row_begin( y ); typename View2::x_iterator srcIt2 = src2.row_begin( y ); typename View3::x_iterator srcIt3 = src3.row_begin( y ); typename View4::x_iterator dstIt = dst.row_begin( y ); for( std::ptrdiff_t x = 0; x < dst.width(); ++x ) dstIt[x] = fun( srcIt1[x], srcIt2[x], srcIt3[x] ); if( p.progressForward( dst.width() ) ) return fun; } return fun; }
GIL_FORCEINLINE F transform_pixels_locator_progress( const View& dst, const OfxRectI& dstRod, const OfxRectI& renderWin, const F& fun, IProgress& p ) { const std::ptrdiff_t renderWidth = renderWin.x2 - renderWin.x1; typename View::xy_locator dloc = dst.xy_at( renderWin.x1-dstRod.x1, renderWin.y1-dstRod.y1 ); for( std::ptrdiff_t y = renderWin.y1; y < renderWin.y2; ++y ) { for( std::ptrdiff_t x = renderWin.x1; x < renderWin.x2; ++x, ++dloc.x() ) { fun( dloc ); } dloc.x() -= renderWidth; ++dloc.y(); if( p.progressForward( renderWidth ) ) return fun; } return fun; }
GIL_FORCEINLINE F transform_pixels_locator_progress( const View& src, const OfxRectI& srcRod, const ViewDst& dst, const OfxRectI& dstRod, const OfxRectI& renderWin, F& fun, IProgress& p ) { const std::ptrdiff_t renderWidth = renderWin.x2 - renderWin.x1; typename View::xy_locator sloc = src.xy_at( renderWin.x1-srcRod.x1, renderWin.y1-srcRod.y1 ); for( std::ptrdiff_t y = renderWin.y1; y < renderWin.y2; ++y ) { typename ViewDst::x_iterator dstIt = dst.x_at( renderWin.x1-dstRod.x1, y-dstRod.y1 ); for( std::ptrdiff_t x = renderWin.x1; x < renderWin.x2; ++x, ++sloc.x(), ++dstIt ) { *dstIt = fun( sloc ); } sloc.x() -= renderWidth; ++sloc.y(); if( p.progressForward( renderWidth ) ) return fun; } return fun; }
IMachine *VirtualBoxBridge::cloneVM(QString qName, bool reInitIfaces, IMachine *m) { nsXPIDLString name; name.AssignWithConversion(qName.toStdString().c_str()); nsXPIDLString osTypeId; nsresult rc; m->GetOSTypeId(getter_Copies(osTypeId)); IMachine *new_machine; IProgress *progress; NS_CHECK_AND_DEBUG_ERROR(virtualBox, FindMachine(name, &new_machine), rc); if(rc != VBOX_E_OBJECT_NOT_FOUND) { std::cout << "machine: " << &new_machine << std::endl; return NULL; } nsXPIDLString settingsFile; virtualBox->ComposeMachineFilename(name, NULL, NULL, NULL, getter_Copies(settingsFile)); std::cout << "Predicted settings file name: " << returnQStringValue(settingsFile).toStdString() << std::endl; QFile file(returnQStringValue(settingsFile)); QFile file_prev(returnQStringValue(settingsFile).append("-prev")); if(file.exists()) { if(file.remove()) std::cerr << "Deleted old settings file: " << file.fileName().toStdString() << std::endl; else std::cerr << "Error while deleting old settings file: " << file.fileName().toStdString() << std::endl; } if(file_prev.exists()) { if(file_prev.remove()) std::cerr << "Deleted old backup settings file: " << file_prev.fileName().toStdString() << std::endl; else std::cerr << "Error while deleting old backup settings file: " << file_prev.fileName().toStdString() << std::endl; } QString label = QString::fromUtf8("Creazione macchina \"").append(qName).append("\"..."); ProgressDialog p(label); p.ui->progressBar->setValue(0); p.ui->label->setText(label); p.open(); NS_CHECK_AND_DEBUG_ERROR(virtualBox, CreateMachine(NULL, name, 0, NULL, osTypeId, NULL, &new_machine), rc); if(NS_FAILED(rc)) return NULL; std::cout << "Machine " << qName.toStdString() << " created" << std::endl; if(!reInitIfaces) { uint32_t clone_options[1]; clone_options[0] = CloneOptions::KeepAllMACs; NS_CHECK_AND_DEBUG_ERROR(m, CloneTo(new_machine, CloneMode::MachineState, 1, clone_options, &progress), rc); } else NS_CHECK_AND_DEBUG_ERROR(m, CloneTo(new_machine, CloneMode::MachineState, 0, NULL, &progress), rc); if(NS_FAILED(rc)) return NULL; int32_t resultCode; PRBool progress_completed; do { uint32_t percent; progress->GetCompleted(&progress_completed); progress->GetPercent(&percent); p.ui->progressBar->setValue(percent); p.refresh(); usleep(750000); } while(!progress_completed); progress->GetResultCode(&resultCode); if (resultCode != 0) // check success { std::cout << "Error during clone process: " << resultCode << std::endl; return NULL; } std::cout << "Machine " << qName.toStdString() << " cloned" << std::endl; p.ui->label->setText(QString::fromUtf8("Registrazione macchina \"").append(qName).append("\"...")); NS_CHECK_AND_DEBUG_ERROR(virtualBox, RegisterMachine(new_machine), rc); if(NS_FAILED(rc)) return NULL; std::cout << "Machine " << qName.toStdString() << " registered" << std::endl; return new_machine; }