Changeset 58002 in vbox
- Timestamp:
- Oct 2, 2015 10:21:51 AM (9 years ago)
- Location:
- trunk/src/VBox/Main
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/Makefile.kmk
r57996 r58002 359 359 src-all/SharedFolderImpl.cpp \ 360 360 src-all/AutoCaller.cpp \ 361 src-all/ThreadTask.cpp \362 361 src-all/VirtualBoxBase.cpp \ 363 362 src-all/VirtualBoxErrorInfoImpl.cpp \ … … 738 737 src-all/SharedFolderImpl.cpp \ 739 738 src-all/AutoCaller.cpp \ 740 src-all/ThreadTask.cpp \741 739 src-all/VirtualBoxBase.cpp \ 742 740 src-all/VirtualBoxErrorInfoImpl.cpp \ … … 859 857 src-all/Global.cpp \ 860 858 src-all/AutoCaller.cpp \ 861 src-all/ThreadTask.cpp \862 859 src-all/VirtualBoxBase.cpp \ 863 860 src-all/VirtualBoxErrorInfoImpl.cpp \ -
trunk/src/VBox/Main/include/ApplianceImpl.h
r57996 r58002 114 114 115 115 struct ImportStack; 116 classTaskOVF;116 struct TaskOVF; 117 117 struct Data; // opaque, defined in ApplianceImpl.cpp 118 118 Data *m; -
trunk/src/VBox/Main/include/ApplianceImplPrivate.h
r57996 r58002 23 23 #include "ovfreader.h" 24 24 #include "SecretKeyStore.h" 25 #include "ThreadTask.h"26 25 #include <map> 27 26 #include <vector> … … 123 122 }; 124 123 125 class Appliance::TaskOVF: public ThreadTask 126 { 127 public: 124 struct Appliance::TaskOVF 125 { 128 126 enum TaskType 129 127 { … … 137 135 LocationInfo aLocInfo, 138 136 ComObjPtr<Progress> &aProgress) 139 : ThreadTask("TaskOVF"), 140 pAppliance(aThat), 137 : pAppliance(aThat), 141 138 taskType(aType), 142 139 locInfo(aLocInfo), … … 144 141 enFormat(ovf::OVFVersion_unknown), 145 142 rc(S_OK) 146 { 147 switch (taskType) 148 { 149 case TaskOVF::Read: m_strTaskName = "ApplRead"; break; 150 case TaskOVF::Import: m_strTaskName = "ApplImp"; break; 151 case TaskOVF::Write: m_strTaskName = "ApplWrit"; break; 152 default: m_strTaskName = "ApplTask"; break; 153 } 154 } 143 {} 155 144 156 145 static DECLCALLBACK(int) updateProgress(unsigned uPercent, void *pvUser); 146 147 HRESULT startThread(); 157 148 158 149 Appliance *pAppliance; … … 164 155 165 156 HRESULT rc; 166 167 void handler()168 {169 int vrc = Appliance::i_taskThreadImportOrExport(NULL, this);170 }171 157 }; 172 158 -
trunk/src/VBox/Main/include/ConsoleImpl.h
r57996 r58002 563 563 typedef std::map<Utf8Str, ComPtr<IMediumAttachment> > MediumAttachmentMap; 564 564 typedef std::list <USBStorageDevice> USBStorageDeviceList; 565 566 static DECLCALLBACK(int) i_powerUpThread(RTTHREAD Thread, void *pvUser);567 static DECLCALLBACK(int) i_powerDownThread(RTTHREAD Thread, void *pvUser);568 565 569 566 private: … … 742 739 void i_detachAllUSBDevices(bool aDone); 743 740 741 static DECLCALLBACK(int) i_powerUpThread(RTTHREAD Thread, void *pvUser); 742 static DECLCALLBACK(int) i_powerDownThread(RTTHREAD Thread, void *pvUser); 744 743 745 744 static DECLCALLBACK(int) i_vmm2User_SaveState(PCVMM2USERMETHODS pThis, PUVM pUVM); -
trunk/src/VBox/Main/src-client/ConsoleImpl.cpp
r57996 r58002 73 73 #include "AutoCaller.h" 74 74 #include "Logging.h" 75 #include "ThreadTask.h"76 75 77 76 #include <VBox/com/array.h> … … 151 150 * Console::addVMCaller() for more info. 152 151 */ 153 class VMTask: public ThreadTask 154 { 155 public: 152 struct VMTask 153 { 156 154 VMTask(Console *aConsole, 157 155 Progress *aProgress, 158 156 const ComPtr<IProgress> &aServerProgress, 159 157 bool aUsesVMPtr) 160 : ThreadTask("GenericVMTask"), 161 mConsole(aConsole), 158 : mConsole(aConsole), 162 159 mConsoleCaller(aConsole), 163 160 mProgress(aProgress), … … 178 175 } 179 176 180 virtual~VMTask()177 ~VMTask() 181 178 { 182 179 releaseVMCaller(); … … 208 205 209 206 210 class VMPowerUpTask : public VMTask 211 { 212 public: 207 struct VMPowerUpTask : public VMTask 208 { 213 209 VMPowerUpTask(Console *aConsole, 214 210 Progress *aProgress) … … 219 215 mTeleporterEnabled(FALSE), 220 216 mEnmFaultToleranceState(FaultToleranceState_Inactive) 221 { 222 m_strTaskName = "VMPwrUp"; 223 } 217 {} 224 218 225 219 PFNCFGMCONSTRUCTOR mConfigConstructor; … … 233 227 typedef std::list<ComPtr<IProgress> > ProgressList; 234 228 ProgressList hardDiskProgresses; 235 236 void handler()237 {238 int vrc = Console::i_powerUpThread(NULL, this);239 }240 241 229 }; 242 230 243 class VMPowerDownTask : public VMTask 244 { 245 public: 231 struct VMPowerDownTask : public VMTask 232 { 246 233 VMPowerDownTask(Console *aConsole, 247 234 const ComPtr<IProgress> &aServerProgress) 248 235 : VMTask(aConsole, NULL /* aProgress */, aServerProgress, 249 236 true /* aUsesVMPtr */) 250 { 251 m_strTaskName = "VMPwrDwn"; 252 } 253 254 void handler() 255 { 256 int vrc = Console::i_powerDownThread(NULL, this); 257 } 237 {} 258 238 }; 259 239 … … 2156 2136 try 2157 2137 { 2138 /* Setup task object and thread to carry out the operation asynchronously. 2139 * We are going to pass ownership of task pointer to another thread. 2140 * So we are in charge of deletion this task pointer in case if RTThreadCreate 2141 * returns not successful result or in case of any exception 2142 */ 2143 2158 2144 task = new VMPowerDownTask(this, pProgress); 2159 if (!task->isOk()) 2145 AssertBreakStmt(task->isOk(), rc = E_FAIL); 2146 int vrc = RTThreadCreate(NULL, Console::i_powerDownThread, 2147 (void *) task, 0, 2148 RTTHREADTYPE_MAIN_WORKER, 0, 2149 "VMPwrDwn"); 2150 if (RT_FAILURE(vrc)) 2160 2151 { 2161 throw E_FAIL; 2152 rc = setError(E_FAIL, "Could not create VMPowerDown thread (%Rrc)", vrc); 2153 break; 2162 2154 } 2163 } 2164 catch(...) 2165 { 2166 delete task; 2167 rc = setError(E_FAIL, "Could not create VMPowerDownTask object \n"); 2155 /* task is now owned by powerDownThread(), so release it */ 2156 //task.release(); 2157 } 2158 catch(const std::exception &e) 2159 { 2160 rc = setError(E_FAIL, "Cought exception! Could not create VMPowerDown thread (%s)", e.what()); 2168 2161 break; 2169 2162 } 2170 2171 rc = task->createThread();2172 2163 2173 2164 /* pass the progress to the caller */ … … 2178 2169 if (FAILED(rc)) 2179 2170 { 2171 if (task != NULL) 2172 { 2173 //we can delete this pointer because something 2174 //was wrong and we hadn't passed pointer to another thread 2175 LogFlowFunc(("Delete task VMPowerDownTask from Console::powerDown()\n")); 2176 delete task; 2177 } 2180 2178 /* preserve existing error info */ 2181 2179 ErrorInfoKeeper eik; … … 6980 6978 HRESULT Console::i_powerUp(IProgress **aProgress, bool aPaused) 6981 6979 { 6980 6982 6981 LogFlowThisFuncEnter(); 6983 6982 … … 6996 6995 LONG cOperations = 1; 6997 6996 LONG ulTotalOperationsWeight = 1; 6998 VMPowerUpTask* task = NULL;6999 6997 7000 6998 try … … 7112 7110 } 7113 7111 7112 7114 7113 /* Setup task object and thread to carry out the operation 7115 7114 * asynchronously */ 7116 try 7117 { 7118 task = new VMPowerUpTask(this, pPowerupProgress); 7119 if (!task->isOk()) 7120 { 7121 throw E_FAIL; 7122 } 7123 } 7124 catch(...) 7125 { 7126 delete task; 7127 rc = setError(E_FAIL, "Could not create VMPowerUpTask object \n"); 7128 throw rc; 7129 } 7115 std::auto_ptr<VMPowerUpTask> task(new VMPowerUpTask(this, pPowerupProgress)); 7116 ComAssertComRCRetRC(task->rc()); 7130 7117 7131 7118 task->mConfigConstructor = i_configConstructor; … … 7385 7372 #endif // 0 7386 7373 7387 7388 7374 /* setup task object and thread to carry out the operation 7389 7375 * asynchronously */ … … 7393 7379 } 7394 7380 7395 rc = task->createThread(); 7396 7397 if (FAILED(rc)) 7398 throw rc; 7381 int vrc = RTThreadCreate(NULL, Console::i_powerUpThread, 7382 (void *)task.get(), 0, 7383 RTTHREADTYPE_MAIN_WORKER, 0, "VMPwrUp"); 7384 if (RT_FAILURE(vrc)) 7385 throw setError(E_FAIL, "Could not create VMPowerUp thread (%Rrc)", vrc); 7386 7387 /* task is now owned by powerUpThread(), so release it */ 7388 task.release(); 7399 7389 7400 7390 /* finally, set the state: no right to fail in this method afterwards … … 8263 8253 if (!task->isOk()) 8264 8254 { 8265 LogFlowFunc(("Console is already being uninitialized. \n")); 8266 throw E_FAIL; 8255 LogFlowFunc(("Console is already being uninitialized.\n")); 8256 } 8257 else 8258 { 8259 /* 8260 * We are going to pass ownership of task pointer to another thread. 8261 * So we are in charge of deletion this task pointer in case if RTThreadCreate 8262 * returns not successful result or in case of any exception 8263 */ 8264 int vrc = RTThreadCreate(NULL, Console::i_powerDownThread, 8265 (void *) task, 0, 8266 RTTHREADTYPE_MAIN_WORKER, 0, 8267 "VMPwrDwn"); 8268 if (RT_FAILURE(vrc)) 8269 { 8270 rc = E_FAIL; 8271 LogFlowFunc(("Could not create VMPowerDown thread (%Rrc)\n", vrc)); 8272 } 8267 8273 } 8268 8274 } 8269 catch( ...)8275 catch(const std::exception &e) 8270 8276 { 8277 rc = E_FAIL; 8278 LogFlowFunc(("Cought exception! Could not create VMPowerDown thread (%s)\n", e.what())); 8279 } 8280 8281 if(FAILED(rc) || !task->isOk()) 8282 { 8283 LogFlowFunc(("Delete task VMPowerDownTask from Console::i_vmstateChangeCallback()\n")); 8271 8284 delete task; 8272 LogFlowFunc(("Problem with creating VMPowerDownTask object. \n"));8273 8285 } 8274 8275 rc = task->createThread();8276 8277 if (FAILED(rc))8278 {8279 LogFlowFunc(("Problem with creating thread for VMPowerDownTask. \n"));8280 }8281 8282 8286 } 8283 8287 break; … … 9437 9441 LogFlowFuncEnter(); 9438 9442 9439 VMPowerUpTask* task = static_cast<VMPowerUpTask *>(pvUser);9440 AssertReturn(task , VERR_INVALID_PARAMETER);9443 std::auto_ptr<VMPowerUpTask> task(static_cast<VMPowerUpTask *>(pvUser)); 9444 AssertReturn(task.get(), VERR_INVALID_PARAMETER); 9441 9445 9442 9446 AssertReturn(!task->mConsole.isNull(), VERR_INVALID_PARAMETER); … … 10003 10007 } 10004 10008 10009 LogFlowFunc(("Delete task VMPowerDownTask from Console::i_powerDownThread()\n")); 10010 delete task; 10005 10011 LogFlowFuncLeave(); 10006 10012 return rc; 10007 10013 } 10014 10008 10015 10009 10016 /** -
trunk/src/VBox/Main/src-server/ApplianceImpl.cpp
r57996 r58002 1185 1185 1186 1186 /** 1187 * Starts the worker thread for the task. 1188 * 1189 * @return COM status code. 1190 */ 1191 HRESULT Appliance::TaskOVF::startThread() 1192 { 1193 /* Pick a thread name suitable for logging (<= 8 chars). */ 1194 const char *pszTaskNm; 1195 switch (taskType) 1196 { 1197 case TaskOVF::Read: pszTaskNm = "ApplRead"; break; 1198 case TaskOVF::Import: pszTaskNm = "ApplImp"; break; 1199 case TaskOVF::Write: pszTaskNm = "ApplWrit"; break; 1200 default: pszTaskNm = "ApplTask"; break; 1201 } 1202 1203 int vrc = RTThreadCreate(NULL, Appliance::i_taskThreadImportOrExport, this, 1204 0, RTTHREADTYPE_MAIN_HEAVY_WORKER, 0, pszTaskNm); 1205 if (RT_SUCCESS(vrc)) 1206 return S_OK; 1207 return Appliance::i_setErrorStatic(E_FAIL, Utf8StrFmt("Could not create OVF task thread (%Rrc)\n", vrc)); 1208 } 1209 1210 /** 1187 1211 * Thread function for the thread started in Appliance::readImpl() and Appliance::importImpl() 1188 1212 * and Appliance::writeImpl(). … … 1196 1220 DECLCALLBACK(int) Appliance::i_taskThreadImportOrExport(RTTHREAD /* aThread */, void *pvUser) 1197 1221 { 1198 TaskOVF* task = static_cast<TaskOVF*>(pvUser);1199 AssertReturn(task , VERR_GENERAL_FAILURE);1222 std::auto_ptr<TaskOVF> task(static_cast<TaskOVF*>(pvUser)); 1223 AssertReturn(task.get(), VERR_GENERAL_FAILURE); 1200 1224 1201 1225 Appliance *pAppliance = task->pAppliance; … … 1210 1234 case TaskOVF::Read: 1211 1235 if (task->locInfo.storageType == VFSType_File) 1212 taskrc = pAppliance->i_readFS(task );1236 taskrc = pAppliance->i_readFS(task.get()); 1213 1237 else if (task->locInfo.storageType == VFSType_S3) 1214 1238 #ifdef VBOX_WITH_S3 1215 taskrc = pAppliance->i_readS3(task );1239 taskrc = pAppliance->i_readS3(task.get()); 1216 1240 #else 1217 1241 taskrc = VERR_NOT_IMPLEMENTED; … … 1221 1245 case TaskOVF::Import: 1222 1246 if (task->locInfo.storageType == VFSType_File) 1223 taskrc = pAppliance->i_importFS(task );1247 taskrc = pAppliance->i_importFS(task.get()); 1224 1248 else if (task->locInfo.storageType == VFSType_S3) 1225 1249 #ifdef VBOX_WITH_S3 1226 taskrc = pAppliance->i_importS3(task );1250 taskrc = pAppliance->i_importS3(task.get()); 1227 1251 #else 1228 1252 taskrc = VERR_NOT_IMPLEMENTED; … … 1232 1256 case TaskOVF::Write: 1233 1257 if (task->locInfo.storageType == VFSType_File) 1234 taskrc = pAppliance->i_writeFS(task );1258 taskrc = pAppliance->i_writeFS(task.get()); 1235 1259 else if (task->locInfo.storageType == VFSType_S3) 1236 1260 #ifdef VBOX_WITH_S3 1237 taskrc = pAppliance->i_writeS3(task );1261 taskrc = pAppliance->i_writeS3(task.get()); 1238 1262 #else 1239 1263 taskrc = VERR_NOT_IMPLEMENTED; -
trunk/src/VBox/Main/src-server/ApplianceImplExport.cpp
r57997 r58002 28 28 #include "ApplianceImpl.h" 29 29 #include "VirtualBoxImpl.h" 30 30 31 #include "ProgressImpl.h" 31 32 #include "MachineImpl.h" … … 753 754 754 755 /* Initialize our worker task */ 755 TaskOVF* task = NULL; 756 try 757 { 758 task = new TaskOVF(this, TaskOVF::Write, aLocInfo, aProgress); 759 } 760 catch(...) 761 { 762 delete task; 763 throw rc = setError(VBOX_E_OBJECT_NOT_FOUND, 764 tr("Could not create TaskOVF object for for writing out the OVF to disk")); 765 } 766 756 std::auto_ptr<TaskOVF> task(new TaskOVF(this, TaskOVF::Write, aLocInfo, aProgress)); 767 757 /* The OVF version to write */ 768 758 task->enFormat = aFormat; 769 759 770 rc = task-> createThread();760 rc = task->startThread(); 771 761 if (FAILED(rc)) throw rc; 772 762 763 /* Don't destruct on success */ 764 task.release(); 773 765 } 774 766 catch (HRESULT aRC) -
trunk/src/VBox/Main/src-server/ApplianceImplImport.cpp
r57996 r58002 874 874 875 875 /* Initialize our worker task */ 876 TaskOVF* task = NULL; 877 try 878 { 879 task = new TaskOVF(this, TaskOVF::Read, aLocInfo, aProgress); 880 } 881 catch(...) 882 { 883 delete task; 884 throw rc = setError(VBOX_E_OBJECT_NOT_FOUND, 885 tr("Could not create TaskOVF object for reading the OVF from disk")); 886 } 887 888 rc = task->createThread(); 876 std::auto_ptr<TaskOVF> task(new TaskOVF(this, TaskOVF::Read, aLocInfo, aProgress)); 877 878 rc = task->startThread(); 889 879 if (FAILED(rc)) throw rc; 880 881 /* Don't destruct on success */ 882 task.release(); 890 883 891 884 return rc; … … 1378 1371 1379 1372 /* Initialize our worker task */ 1380 TaskOVF* task = NULL; 1381 try 1382 { 1383 task = new TaskOVF(this, TaskOVF::Import, locInfo, progress); 1384 } 1385 catch(...) 1386 { 1387 delete task; 1388 throw rc = setError(VBOX_E_OBJECT_NOT_FOUND, 1389 tr("Could not create TaskOVF object for importing OVF data into VirtualBox")); 1390 } 1391 1392 rc = task->createThread(); 1373 std::auto_ptr<TaskOVF> task(new TaskOVF(this, TaskOVF::Import, locInfo, progress)); 1374 1375 rc = task->startThread(); 1393 1376 if (FAILED(rc)) throw rc; 1377 1378 /* Don't destruct on success */ 1379 task.release(); 1394 1380 1395 1381 return rc;
Note:
See TracChangeset
for help on using the changeset viewer.