Changeset 33417 in vbox for trunk/src/VBox/Main/ApplianceImpl.cpp
- Timestamp:
- Oct 25, 2010 12:32:50 PM (14 years ago)
- svn:sync-xref-src-repo-rev:
- 67007
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/ApplianceImpl.cpp
r33289 r33417 854 854 } 855 855 856 void Appliance::parseURI(Utf8Str strUri, LocationInfo &locInfo) const 856 void Appliance::parseBucket(Utf8Str &aPath, Utf8Str &aBucket) 857 { 858 /* Buckets are S3 specific. So parse the bucket out of the file path */ 859 if (!aPath.startsWith("/")) 860 throw setError(E_INVALIDARG, 861 tr("The path '%s' must start with /"), aPath.c_str()); 862 size_t bpos = aPath.find("/", 1); 863 if (bpos != Utf8Str::npos) 864 { 865 aBucket = aPath.substr(1, bpos - 1); /* The bucket without any slashes */ 866 aPath = aPath.substr(bpos); /* The rest of the file path */ 867 } 868 /* If there is no bucket name provided reject it */ 869 if (aBucket.isEmpty()) 870 throw setError(E_INVALIDARG, 871 tr("You doesn't provide a bucket name in the URI '%s'"), aPath.c_str()); 872 } 873 874 /** 875 * 876 * @return 877 */ 878 int Appliance::TaskOVF::startThread() 879 { 880 int vrc = RTThreadCreate(NULL, Appliance::taskThreadImportOrExport, this, 881 0, RTTHREADTYPE_MAIN_HEAVY_WORKER, 0, 882 "Appliance::Task"); 883 884 if (RT_FAILURE(vrc)) 885 return Appliance::setErrorStatic(E_FAIL, 886 Utf8StrFmt("Could not create OVF task thread (%Rrc)\n", vrc)); 887 888 return S_OK; 889 } 890 891 /** 892 * Thread function for the thread started in Appliance::readImpl() and Appliance::importImpl() 893 * and Appliance::writeImpl(). 894 * This will in turn call Appliance::readFS() or Appliance::readS3() or Appliance::importFS() 895 * or Appliance::importS3() or Appliance::writeFS() or Appliance::writeS3(). 896 * 897 * @param aThread 898 * @param pvUser 899 */ 900 /* static */ 901 DECLCALLBACK(int) Appliance::taskThreadImportOrExport(RTTHREAD /* aThread */, void *pvUser) 902 { 903 std::auto_ptr<TaskOVF> task(static_cast<TaskOVF*>(pvUser)); 904 AssertReturn(task.get(), VERR_GENERAL_FAILURE); 905 906 Appliance *pAppliance = task->pAppliance; 907 908 LogFlowFuncEnter(); 909 LogFlowFunc(("Appliance %p\n", pAppliance)); 910 911 HRESULT taskrc = S_OK; 912 913 switch (task->taskType) 914 { 915 case TaskOVF::Read: 916 if (task->locInfo.storageType == VFSType_File) 917 taskrc = pAppliance->readFS(task.get()); 918 else if (task->locInfo.storageType == VFSType_S3) 919 taskrc = pAppliance->readS3(task.get()); 920 break; 921 922 case TaskOVF::Import: 923 if (task->locInfo.storageType == VFSType_File) 924 taskrc = pAppliance->importFS(task.get()); 925 else if (task->locInfo.storageType == VFSType_S3) 926 taskrc = pAppliance->importS3(task.get()); 927 break; 928 929 case TaskOVF::Write: 930 if (task->locInfo.storageType == VFSType_File) 931 taskrc = pAppliance->writeFS(task.get()); 932 else if (task->locInfo.storageType == VFSType_S3) 933 taskrc = pAppliance->writeS3(task.get()); 934 break; 935 } 936 937 task->rc = taskrc; 938 939 if (!task->pProgress.isNull()) 940 task->pProgress->notifyComplete(taskrc); 941 942 LogFlowFuncLeave(); 943 944 return VINF_SUCCESS; 945 } 946 947 /* static */ 948 int Appliance::TaskOVF::updateProgress(unsigned uPercent, void *pvUser) 949 { 950 Appliance::TaskOVF* pTask = *(Appliance::TaskOVF**)pvUser; 951 952 if ( pTask 953 && !pTask->pProgress.isNull()) 954 { 955 BOOL fCanceled; 956 pTask->pProgress->COMGETTER(Canceled)(&fCanceled); 957 if (fCanceled) 958 return -1; 959 pTask->pProgress->SetCurrentOperationProgress(uPercent); 960 } 961 return VINF_SUCCESS; 962 } 963 964 void parseURI(Utf8Str strUri, LocationInfo &locInfo) 857 965 { 858 966 /* Check the URI for the protocol */ … … 901 1009 } 902 1010 903 void Appliance::parseBucket(Utf8Str &aPath, Utf8Str &aBucket)904 {905 /* Buckets are S3 specific. So parse the bucket out of the file path */906 if (!aPath.startsWith("/"))907 throw setError(E_INVALIDARG,908 tr("The path '%s' must start with /"), aPath.c_str());909 size_t bpos = aPath.find("/", 1);910 if (bpos != Utf8Str::npos)911 {912 aBucket = aPath.substr(1, bpos - 1); /* The bucket without any slashes */913 aPath = aPath.substr(bpos); /* The rest of the file path */914 }915 /* If there is no bucket name provided reject it */916 if (aBucket.isEmpty())917 throw setError(E_INVALIDARG,918 tr("You doesn't provide a bucket name in the URI '%s'"), aPath.c_str());919 }920 921 /**922 *923 * @return924 */925 int Appliance::TaskOVF::startThread()926 {927 int vrc = RTThreadCreate(NULL, Appliance::taskThreadImportOrExport, this,928 0, RTTHREADTYPE_MAIN_HEAVY_WORKER, 0,929 "Appliance::Task");930 931 if (RT_FAILURE(vrc))932 return Appliance::setErrorStatic(E_FAIL,933 Utf8StrFmt("Could not create OVF task thread (%Rrc)\n", vrc));934 935 return S_OK;936 }937 938 /**939 * Thread function for the thread started in Appliance::readImpl() and Appliance::importImpl()940 * and Appliance::writeImpl().941 * This will in turn call Appliance::readFS() or Appliance::readS3() or Appliance::importFS()942 * or Appliance::importS3() or Appliance::writeFS() or Appliance::writeS3().943 *944 * @param aThread945 * @param pvUser946 */947 /* static */948 DECLCALLBACK(int) Appliance::taskThreadImportOrExport(RTTHREAD /* aThread */, void *pvUser)949 {950 std::auto_ptr<TaskOVF> task(static_cast<TaskOVF*>(pvUser));951 AssertReturn(task.get(), VERR_GENERAL_FAILURE);952 953 Appliance *pAppliance = task->pAppliance;954 955 LogFlowFuncEnter();956 LogFlowFunc(("Appliance %p\n", pAppliance));957 958 HRESULT taskrc = S_OK;959 960 switch (task->taskType)961 {962 case TaskOVF::Read:963 if (task->locInfo.storageType == VFSType_File)964 taskrc = pAppliance->readFS(task.get());965 else if (task->locInfo.storageType == VFSType_S3)966 taskrc = pAppliance->readS3(task.get());967 break;968 969 case TaskOVF::Import:970 if (task->locInfo.storageType == VFSType_File)971 taskrc = pAppliance->importFS(task.get());972 else if (task->locInfo.storageType == VFSType_S3)973 taskrc = pAppliance->importS3(task.get());974 break;975 976 case TaskOVF::Write:977 if (task->locInfo.storageType == VFSType_File)978 taskrc = pAppliance->writeFS(task.get());979 else if (task->locInfo.storageType == VFSType_S3)980 taskrc = pAppliance->writeS3(task.get());981 break;982 }983 984 task->rc = taskrc;985 986 if (!task->pProgress.isNull())987 task->pProgress->notifyComplete(taskrc);988 989 LogFlowFuncLeave();990 991 return VINF_SUCCESS;992 }993 994 /* static */995 int Appliance::TaskOVF::updateProgress(unsigned uPercent, void *pvUser)996 {997 Appliance::TaskOVF* pTask = *(Appliance::TaskOVF**)pvUser;998 999 if ( pTask1000 && !pTask->pProgress.isNull())1001 {1002 BOOL fCanceled;1003 pTask->pProgress->COMGETTER(Canceled)(&fCanceled);1004 if (fCanceled)1005 return -1;1006 pTask->pProgress->SetCurrentOperationProgress(uPercent);1007 }1008 return VINF_SUCCESS;1009 }1010 1011 1011 //////////////////////////////////////////////////////////////////////////////// 1012 1012 //
Note:
See TracChangeset
for help on using the changeset viewer.