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