Changeset 42566 in vbox for trunk/src/VBox
- Timestamp:
- Aug 3, 2012 8:57:23 AM (12 years ago)
- Location:
- trunk/src/VBox/Main
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/include/GuestSessionImpl.h
r42551 r42566 31 31 32 32 /** 33 * TODO 33 * Abstract base class for a lenghtly per-session operation which 34 * runs in a Main worker thread. 35 */ 36 class GuestSessionTask 37 { 38 public: 39 40 GuestSessionTask(GuestSession *pSession, Progress *pProgress); 41 42 virtual ~GuestSessionTask(void); 43 44 public: 45 46 virtual int Run(void) = 0; 47 virtual int RunAsync(const Utf8Str &strDesc) = 0; 48 49 int setProgress(unsigned uPercent); 50 int setProgressSuccess(void); 51 int setProgressErrorMsg(HRESULT hr, const Utf8Str &strMsg); 52 53 protected: 54 55 Utf8Str mDesc; 56 ComObjPtr<GuestSession> mSession; 57 ComObjPtr<Progress> mProgress; 58 }; 59 60 /** 61 * Task for copying files from host to the guest. 62 */ 63 class SessionTaskCopyTo : public GuestSessionTask 64 { 65 public: 66 67 SessionTaskCopyTo(GuestSession *pSession, Progress *pProgress, 68 const Utf8Str &strSource, const Utf8Str &strDest, uint32_t uFlags); 69 70 virtual ~SessionTaskCopyTo(void); 71 72 public: 73 74 int Run(void); 75 int RunAsync(const Utf8Str &strDesc); 76 static int taskThread(RTTHREAD Thread, void *pvUser); 77 78 protected: 79 80 Utf8Str mSource; 81 Utf8Str mDest; 82 uint32_t mFlags; 83 }; 84 85 /** 86 * Task for copying files from guest to the host. 87 */ 88 class SessionTaskCopyFrom : public GuestSessionTask 89 { 90 public: 91 92 SessionTaskCopyFrom(GuestSession *pSession, Progress *pProgress, 93 const Utf8Str &strSource, const Utf8Str &strDest, uint32_t uFlags); 94 95 virtual ~SessionTaskCopyFrom(void); 96 97 public: 98 99 int Run(void); 100 int RunAsync(const Utf8Str &strDesc); 101 static int taskThread(RTTHREAD Thread, void *pvUser); 102 103 protected: 104 105 Utf8Str mSource; 106 Utf8Str mDest; 107 uint32_t mFlags; 108 }; 109 110 /** 111 * Guest session implementation. 34 112 */ 35 113 class ATL_NO_VTABLE GuestSession : … … 72 150 * @{ */ 73 151 STDMETHOD(Close)(void); 74 STDMETHOD(CopyFrom)(IN_BSTR aSource, IN_BSTR aDest, ComSafeArrayIn( ULONG, aFlags), IProgress **aProgress);75 STDMETHOD(CopyTo)(IN_BSTR aSource, IN_BSTR aDest, ComSafeArrayIn( ULONG, aFlags), IProgress **aProgress);152 STDMETHOD(CopyFrom)(IN_BSTR aSource, IN_BSTR aDest, ComSafeArrayIn(CopyFileFlag_T, aFlags), IProgress **aProgress); 153 STDMETHOD(CopyTo)(IN_BSTR aSource, IN_BSTR aDest, ComSafeArrayIn(CopyFileFlag_T, aFlags), IProgress **aProgress); 76 154 STDMETHOD(DirectoryCreate)(IN_BSTR aPath, ULONG aMode, ComSafeArrayIn(DirectoryCreateFlag_T, aFlags), IGuestDirectory **aDirectory); 77 155 STDMETHOD(DirectoryCreateTemp)(IN_BSTR aTemplate, ULONG aMode, IN_BSTR aName, IGuestDirectory **aDirectory); … … 137 215 inline bool processExists(uint32_t uProcessID, ComObjPtr<GuestProcess> *pProcess); 138 216 inline int processGetByPID(ULONG uPID, ComObjPtr<GuestProcess> *pProcess); 217 int startTaskAsync(const Utf8Str &strTaskDesc, GuestSessionTask *pTask, ComObjPtr<Progress> &pProgress); 139 218 int queryInfo(void); 140 219 /** @} */ -
trunk/src/VBox/Main/src-client/GuestCtrlImpl.cpp
r42546 r42566 2860 2860 while (itSessions != mData.mGuestSessions.end()) 2861 2861 { 2862 if (strName. equals(itSessions->second->getName()))2862 if (strName.contains(itSessions->second->getName())) /** @todo Use a (simple) pattern match (IPRT?). */ 2863 2863 listSessions.push_back(itSessions->second); 2864 2864 itSessions++; -
trunk/src/VBox/Main/src-client/GuestSessionImpl.cpp
r42551 r42566 27 27 #include "Global.h" 28 28 #include "AutoCaller.h" 29 #include "ProgressImpl.h" 29 30 30 31 #include <iprt/env.h> … … 51 52 BaseFinalRelease(); 52 53 LogFlowThisFuncLeave(); 54 } 55 56 // session task classes 57 ///////////////////////////////////////////////////////////////////////////// 58 59 GuestSessionTask::GuestSessionTask(GuestSession *pSession, Progress *pProgress) 60 { 61 mSession = pSession; 62 mProgress = pProgress; 63 } 64 65 GuestSessionTask::~GuestSessionTask(void) 66 { 67 } 68 69 int GuestSessionTask::setProgress(unsigned uPercent) 70 { 71 BOOL fCanceled; 72 mProgress->COMGETTER(Canceled)(&fCanceled); 73 if (fCanceled) 74 return VERR_CANCELLED; 75 mProgress->SetCurrentOperationProgress(uPercent); 76 77 return VINF_SUCCESS; 78 } 79 80 int GuestSessionTask::setProgressSuccess(void) 81 { 82 BOOL fCanceled; 83 BOOL fCompleted; 84 if ( SUCCEEDED(mProgress->COMGETTER(Canceled(&fCanceled))) 85 && !fCanceled 86 && SUCCEEDED(mProgress->COMGETTER(Completed(&fCompleted))) 87 && !fCompleted) 88 { 89 HRESULT hr = mProgress->notifyComplete(S_OK); 90 ComAssertComRC(hr); 91 } 92 93 return VINF_SUCCESS; 94 } 95 96 int GuestSessionTask::setProgressErrorMsg(HRESULT hr, const Utf8Str &strMsg) 97 { 98 BOOL fCanceled; 99 BOOL fCompleted; 100 if ( SUCCEEDED(mProgress->COMGETTER(Canceled(&fCanceled))) 101 && !fCanceled 102 && SUCCEEDED(mProgress->COMGETTER(Completed(&fCompleted))) 103 && !fCompleted) 104 { 105 HRESULT hr = mProgress->notifyComplete(hr, 106 COM_IIDOF(IGuestSession), 107 GuestSession::getStaticComponentName(), 108 strMsg.c_str()); 109 if (FAILED(hr)) 110 return VERR_COM_UNEXPECTED; 111 } 112 return VINF_SUCCESS; 113 } 114 115 SessionTaskCopyTo::SessionTaskCopyTo(GuestSession *pSession, Progress *pProgress, 116 const Utf8Str &strSource, const Utf8Str &strDest, uint32_t uFlags) 117 : GuestSessionTask(pSession, pProgress) 118 { 119 mSource = strSource; 120 mDest = mDest; 121 mFlags = uFlags; 122 } 123 124 SessionTaskCopyTo::~SessionTaskCopyTo(void) 125 { 126 127 } 128 129 int SessionTaskCopyTo::Run(void) 130 { 131 return 0; 132 } 133 134 int SessionTaskCopyTo::RunAsync(const Utf8Str &strDesc) 135 { 136 LogFlowThisFunc(("strDesc=%s, strSource=%s, strDest=%s, uFlags=%x\n", 137 strDesc.c_str(), mSource.c_str(), mDest.c_str(), mFlags)); 138 139 mDesc = strDesc; 140 141 int rc = RTThreadCreate(NULL, SessionTaskCopyTo::taskThread, this, 142 0, RTTHREADTYPE_MAIN_HEAVY_WORKER, 0, 143 "gctlCpyTo"); 144 LogFlowFuncLeaveRC(rc); 145 return rc; 146 } 147 148 /* static */ 149 int SessionTaskCopyTo::taskThread(RTTHREAD Thread, void *pvUser) 150 { 151 std::auto_ptr<SessionTaskCopyTo> task(static_cast<SessionTaskCopyTo*>(pvUser)); 152 AssertReturn(task.get(), VERR_GENERAL_FAILURE); 153 154 LogFlowFunc(("pTask=%p\n", task.get())); 155 return task->Run(); 156 } 157 158 SessionTaskCopyFrom::SessionTaskCopyFrom(GuestSession *pSession, Progress *pProgress, 159 const Utf8Str &strSource, const Utf8Str &strDest, uint32_t uFlags) 160 : GuestSessionTask(pSession, pProgress) 161 { 162 mSource = strSource; 163 mDest = mDest; 164 mFlags = uFlags; 165 } 166 167 SessionTaskCopyFrom::~SessionTaskCopyFrom(void) 168 { 169 170 } 171 172 int SessionTaskCopyFrom::Run(void) 173 { 174 return 0; 175 } 176 177 int SessionTaskCopyFrom::RunAsync(const Utf8Str &strDesc) 178 { 179 LogFlowThisFunc(("strDesc=%s, strSource=%s, strDest=%s, uFlags=%x\n", 180 strDesc.c_str(), mSource.c_str(), mDest.c_str(), mFlags)); 181 182 mDesc = strDesc; 183 184 int rc = RTThreadCreate(NULL, SessionTaskCopyFrom::taskThread, this, 185 0, RTTHREADTYPE_MAIN_HEAVY_WORKER, 0, 186 "gctlCpyFrom"); 187 LogFlowFuncLeaveRC(rc); 188 return rc; 189 } 190 191 /* static */ 192 int SessionTaskCopyFrom::taskThread(RTTHREAD Thread, void *pvUser) 193 { 194 std::auto_ptr<SessionTaskCopyFrom> task(static_cast<SessionTaskCopyFrom*>(pvUser)); 195 AssertReturn(task.get(), VERR_GENERAL_FAILURE); 196 197 LogFlowFunc(("pTask=%p\n", task.get())); 198 return task->Run(); 53 199 } 54 200 … … 761 907 } 762 908 909 int GuestSession::startTaskAsync(const Utf8Str &strTaskDesc, 910 GuestSessionTask *pTask, ComObjPtr<Progress> &pProgress) 911 { 912 LogFlowThisFunc(("strTaskDesc=%s, pTask=%p\n", strTaskDesc.c_str(), pTask)); 913 914 AssertPtrReturn(pTask, VERR_INVALID_POINTER); 915 916 int rc; 917 918 try 919 { 920 /* Create the progress object. */ 921 HRESULT hr = pProgress.createObject(); 922 if (FAILED(hr)) throw VERR_COM_UNEXPECTED; 923 924 hr = pProgress->init(static_cast<IGuestSession*>(this), 925 Bstr(strTaskDesc).raw(), 926 TRUE /* aCancelable */); 927 if (FAILED(hr)) throw VERR_COM_UNEXPECTED; 928 929 /* Initialize our worker task. */ 930 std::auto_ptr<GuestSessionTask> task(pTask); 931 932 rc = task->RunAsync(strTaskDesc); 933 if (FAILED(rc)) throw rc; 934 935 /* Don't destruct on success. */ 936 task.release(); 937 } 938 catch (int rc2) 939 { 940 rc = rc2; 941 } 942 943 LogFlowFuncLeaveRC(rc); 944 return rc; 945 } 946 763 947 /** 764 948 * Queries/collects information prior to establishing a guest session. … … 770 954 int GuestSession::queryInfo(void) 771 955 { 956 #if 1 957 /* Since the new functions were not implemented yet, force Main to use protocol ver 1. */ 958 mData.mProtocolVersion = 1; 959 #else 772 960 /* 773 961 * Try querying the guest control protocol version running on the guest. … … 779 967 uint32_t uVerAdditions = pGuest->getAdditionsVersion(); 780 968 mData.mProtocolVersion = ( VBOX_FULL_VERSION_GET_MAJOR(uVerAdditions) >= 4 781 && VBOX_FULL_VERSION_GET_MINOR(uVerAdditions) >= 2) 969 && VBOX_FULL_VERSION_GET_MINOR(uVerAdditions) >= 2) /** @todo What's about v5.0 ? */ 782 970 ? 2 /* Guest control 2.0. */ 783 971 : 1; /* Legacy guest control (VBox < 4.2). */ … … 789 977 LogRel((tr("Warning: Guest Additions are older (%ld.%ld) than host capabilities for guest control, please upgrade them. Using protocol version %ld now\n"), 790 978 VBOX_FULL_VERSION_GET_MAJOR(uVerAdditions), VBOX_FULL_VERSION_GET_MINOR(uVerAdditions), mData.mProtocolVersion)); 791 979 #endif 792 980 return VINF_SUCCESS; 793 981 } … … 810 998 } 811 999 812 STDMETHODIMP GuestSession::CopyFrom(IN_BSTR aSource, IN_BSTR aDest, ComSafeArrayIn(ULONG, aFlags), IProgress **aProgress) 813 { 814 #ifndef VBOX_WITH_GUEST_CONTROL 815 ReturnComNotImplemented(); 816 #else 817 LogFlowThisFuncEnter(); 818 819 AutoCaller autoCaller(this); 820 if (FAILED(autoCaller.rc())) return autoCaller.rc(); 821 822 ReturnComNotImplemented(); 823 #endif /* VBOX_WITH_GUEST_CONTROL */ 824 } 825 826 STDMETHODIMP GuestSession::CopyTo(IN_BSTR aSource, IN_BSTR aDest, ComSafeArrayIn(ULONG, aFlags), IProgress **aProgress) 827 { 828 #ifndef VBOX_WITH_GUEST_CONTROL 829 ReturnComNotImplemented(); 830 #else 831 LogFlowThisFuncEnter(); 832 833 AutoCaller autoCaller(this); 834 if (FAILED(autoCaller.rc())) return autoCaller.rc(); 835 836 ReturnComNotImplemented(); 1000 STDMETHODIMP GuestSession::CopyFrom(IN_BSTR aSource, IN_BSTR aDest, ComSafeArrayIn(CopyFileFlag_T, aFlags), IProgress **aProgress) 1001 { 1002 #ifndef VBOX_WITH_GUEST_CONTROL 1003 ReturnComNotImplemented(); 1004 #else 1005 CheckComArgStrNotEmptyOrNull(aSource); 1006 CheckComArgStrNotEmptyOrNull(aDest); 1007 CheckComArgOutPointerValid(aProgress); 1008 1009 LogFlowThisFuncEnter(); 1010 1011 if (RT_UNLIKELY((aSource) == NULL || *(aSource) == '\0')) 1012 return setError(E_INVALIDARG, tr("No source specified")); 1013 if (RT_UNLIKELY((aDest) == NULL || *(aDest) == '\0')) 1014 return setError(E_INVALIDARG, tr("No destination specified")); 1015 1016 AutoCaller autoCaller(this); 1017 if (FAILED(autoCaller.rc())) return autoCaller.rc(); 1018 1019 uint32_t fFlags = CopyFileFlag_None; 1020 if (aFlags) 1021 { 1022 com::SafeArray<CopyFileFlag_T> flags(ComSafeArrayInArg(aFlags)); 1023 for (size_t i = 0; i < flags.size(); i++) 1024 fFlags |= flags[i]; 1025 } 1026 1027 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS); 1028 1029 HRESULT hr = S_OK; 1030 1031 ComObjPtr<Progress> pProgress; 1032 SessionTaskCopyFrom *pTask = new SessionTaskCopyFrom(this, pProgress, 1033 Utf8Str(aSource), Utf8Str(aDest), fFlags); 1034 AssertPtrReturn(pTask, VERR_NO_MEMORY); 1035 int rc = startTaskAsync(Utf8StrFmt(tr("Copying \"%ls\" from guest to \"%ls\" on the host"), aSource, aDest), 1036 pTask, pProgress); 1037 if (RT_SUCCESS(rc)) 1038 { 1039 /* Return progress to the caller. */ 1040 hr = pProgress.queryInterfaceTo(aProgress); 1041 } 1042 1043 /** @todo rc -> hr error lookup. */ 1044 return hr; 1045 #endif /* VBOX_WITH_GUEST_CONTROL */ 1046 } 1047 1048 STDMETHODIMP GuestSession::CopyTo(IN_BSTR aSource, IN_BSTR aDest, ComSafeArrayIn(CopyFileFlag_T, aFlags), IProgress **aProgress) 1049 { 1050 #ifndef VBOX_WITH_GUEST_CONTROL 1051 ReturnComNotImplemented(); 1052 #else 1053 CheckComArgStrNotEmptyOrNull(aSource); 1054 CheckComArgStrNotEmptyOrNull(aDest); 1055 CheckComArgOutPointerValid(aProgress); 1056 1057 LogFlowThisFuncEnter(); 1058 1059 if (RT_UNLIKELY((aSource) == NULL || *(aSource) == '\0')) 1060 return setError(E_INVALIDARG, tr("No source specified")); 1061 if (RT_UNLIKELY((aDest) == NULL || *(aDest) == '\0')) 1062 return setError(E_INVALIDARG, tr("No destination specified")); 1063 1064 AutoCaller autoCaller(this); 1065 if (FAILED(autoCaller.rc())) return autoCaller.rc(); 1066 1067 uint32_t fFlags = CopyFileFlag_None; 1068 if (aFlags) 1069 { 1070 com::SafeArray<CopyFileFlag_T> flags(ComSafeArrayInArg(aFlags)); 1071 for (size_t i = 0; i < flags.size(); i++) 1072 fFlags |= flags[i]; 1073 } 1074 1075 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS); 1076 1077 HRESULT hr = S_OK; 1078 1079 ComObjPtr<Progress> pProgress; 1080 SessionTaskCopyTo *pTask = new SessionTaskCopyTo(this, pProgress, 1081 Utf8Str(aSource), Utf8Str(aDest), fFlags); 1082 AssertPtrReturn(pTask, VERR_NO_MEMORY); 1083 int rc = startTaskAsync(Utf8StrFmt(tr("Copying \"%ls\" from host to \"%ls\" on the guest"), aSource, aDest), 1084 pTask, pProgress); 1085 if (RT_SUCCESS(rc)) 1086 { 1087 /* Return progress to the caller. */ 1088 hr = pProgress.queryInterfaceTo(aProgress); 1089 } 1090 1091 /** @todo rc -> hr error lookup. */ 1092 return hr; 837 1093 #endif /* VBOX_WITH_GUEST_CONTROL */ 838 1094 } … … 1302 1558 HRESULT hr = ProcessCreateEx(aCommand, ComSafeArrayInArg(aArguments), ComSafeArrayInArg(aEnvironment), 1303 1559 ComSafeArrayInArg(aFlags), aTimeoutMS, ProcessPriority_Default, ComSafeArrayAsInParam(affinity), aProcess); 1304 LogFlowFuncLeaveRC(hr);1305 1560 return hr; 1306 1561 #endif /* VBOX_WITH_GUEST_CONTROL */ … … 1444 1699 } 1445 1700 1446 #if 01447 STDMETHODIMP GuestSession::SetTimeout(ULONG aTimeoutMS)1448 {1449 #ifndef VBOX_WITH_GUEST_CONTROL1450 ReturnComNotImplemented();1451 #else1452 LogFlowThisFuncEnter();1453 1454 AutoCaller autoCaller(this);1455 if (FAILED(autoCaller.rc())) return autoCaller.rc();1456 1457 if (aTimeoutMS < 1000)1458 return setError(E_INVALIDARG, tr("Invalid timeout value specified"));1459 1460 mData.mTimeout = aTimeoutMS;1461 1462 LogFlowThisFunc(("aTimeoutMS=%RU32\n", mData.mTimeout));1463 return S_OK;1464 #endif /* VBOX_WITH_GUEST_CONTROL */1465 }1466 #endif1467 1468 1701 STDMETHODIMP GuestSession::SymlinkCreate(IN_BSTR aSource, IN_BSTR aTarget, SymlinkType_T aType) 1469 1702 {
Note:
See TracChangeset
for help on using the changeset viewer.