Changeset 45434 in vbox for trunk/src/VBox/Main
- Timestamp:
- Apr 9, 2013 1:51:55 PM (12 years ago)
- svn:sync-xref-src-repo-rev:
- 84865
- Location:
- trunk/src/VBox/Main
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/include/GuestFileImpl.h
r45426 r45434 94 94 static HRESULT setErrorExternal(VirtualBoxBase *pInterface, int guestRc); 95 95 int setFileStatus(FileStatus_T fileStatus, int fileRc); 96 int waitForEvents(uint32_t uTimeoutMS, ComSafeArrayIn(VBoxEventType_T, pEvents), VBoxEventType_T *pType, IEvent **ppEvent); 96 97 int waitForOffsetChange(uint32_t uTimeoutMS, uint64_t *puOffset); 97 int waitForRead(uint32_t uTimeoutMS, void *pvData, size_t cbData, uint32_t *pcbRead);98 int waitForRead(uint32_t uTimeoutMS, void *pvData, size_t cbData, uint32_t *pcbRead); 98 99 int waitForStatusChange(uint32_t uTimeoutMS, FileStatus_T *pFileStatus); 99 100 int waitForWrite(uint32_t uTimeoutMS, uint32_t *pcbWritten); -
trunk/src/VBox/Main/src-client/GuestFileImpl.cpp
r45426 r45434 74 74 * @param openInfo File opening information. 75 75 */ 76 int GuestFile::init(Console *pConsole, GuestSession *pSession, ULONG uFileID, const GuestFileOpenInfo &openInfo) 76 int GuestFile::init(Console *pConsole, GuestSession *pSession, 77 ULONG uFileID, const GuestFileOpenInfo &openInfo) 77 78 { 78 79 LogFlowThisFunc(("pConsole=%p, pSession=%p, uFileID=%RU32, strPath=%s\n", … … 86 87 AssertReturn(autoInitSpan.isOk(), VERR_OBJECT_DESTROYED); 87 88 89 #ifndef VBOX_WITH_GUEST_CONTROL 90 autoInitSpan.setSucceeded(); 91 return VINF_SUCCESS; 92 #else 88 93 int vrc = bindToSession(pConsole, pSession, uFileID /* Object ID */); 89 94 if (RT_SUCCESS(vrc)) … … 109 114 LogFlowFuncLeaveRC(vrc); 110 115 return vrc; 116 #endif /* VBOX_WITH_GUEST_CONTROL */ 111 117 } 112 118 … … 173 179 STDMETHODIMP GuestFile::COMGETTER(EventSource)(IEventSource ** aEventSource) 174 180 { 181 #ifndef VBOX_WITH_GUEST_CONTROL 182 ReturnComNotImplemented(); 183 #else 175 184 CheckComArgOutPointerValid(aEventSource); 176 185 … … 182 191 183 192 return S_OK; 193 #endif /* VBOX_WITH_GUEST_CONTROL */ 184 194 } 185 195 … … 605 615 void* pvData, uint32_t cbData, uint32_t* pcbRead) 606 616 { 617 AssertPtrReturn(pvData, VERR_INVALID_POINTER); 618 AssertReturn(cbData, VERR_INVALID_PARAMETER); 619 607 620 LogFlowThisFunc(("uSize=%RU32, uTimeoutMS=%RU32, pvData=%p, cbData=%zu\n", 608 621 uSize, uTimeoutMS, pvData, cbData)); … … 739 752 } 740 753 741 int GuestFile::waitForOffsetChange(uint32_t uTimeoutMS, uint64_t *puOffset) 742 { 743 return VINF_SUCCESS; 744 } 745 746 int GuestFile::waitForRead(uint32_t uTimeoutMS, void* pvData, size_t cbData, uint32_t *pcbRead) 747 { 748 return VINF_SUCCESS; 749 } 750 751 int GuestFile::waitForStatusChange(uint32_t uTimeoutMS, FileStatus_T *pFileStatus) 752 { 754 int GuestFile::waitForEvents(uint32_t uTimeoutMS, ComSafeArrayIn(VBoxEventType_T, pEvents), 755 VBoxEventType_T *pType, IEvent **ppEvent) 756 { 757 AssertPtrReturn(pType, VERR_INVALID_POINTER); 758 AssertPtrReturn(ppEvent, VERR_INVALID_POINTER); 759 753 760 int vrc; 754 761 755 762 /** @todo Parameter validation. */ 763 764 com::SafeArray <VBoxEventType_T> arrEventTypes(ComSafeArrayInArg(pEvents)); 756 765 757 766 ComPtr<IEventListener> pListener; … … 759 768 if (SUCCEEDED(hr)) 760 769 { 761 com::SafeArray <VBoxEventType_T> eventTypes(1);762 eventTypes.push_back(VBoxEventType_OnGuestFileStateChanged);763 hr = mEventSource->RegisterListener(pListener, ComSafeArrayAsInParam(eventTypes), false);770 arrEventTypes.push_back(VBoxEventType_OnGuestFileStateChanged); 771 hr = mEventSource->RegisterListener(pListener, ComSafeArrayAsInParam(arrEventTypes), 772 TRUE /* Passive listener */); 764 773 } 765 774 else … … 768 777 if (SUCCEEDED(hr)) 769 778 { 770 LogFlowThisFunc(("Waiting for guest file status change event (timeout=%RU32ms) ...\n",771 uTimeoutMS ));779 LogFlowThisFunc(("Waiting for guest file event(s) (timeout=%RU32ms, %zu events) ...\n", 780 uTimeoutMS, arrEventTypes.size())); 772 781 773 782 vrc = VINF_SUCCESS; … … 788 797 } 789 798 790 ComPtr<IEvent> p Event;791 hr = mEventSource->GetEvent(pListener, cMsWait, p Event.asOutParam());799 ComPtr<IEvent> pThisEvent; 800 hr = mEventSource->GetEvent(pListener, cMsWait, pThisEvent.asOutParam()); 792 801 if ( SUCCEEDED(hr) 793 && !p Event.isNull())802 && !pThisEvent.isNull()) 794 803 { 795 VBoxEventType_T aType;796 hr = p Event->COMGETTER(Type)(&aType);804 VBoxEventType_T type; 805 hr = pThisEvent->COMGETTER(Type)(&type); 797 806 ComAssertComRC(hr); 798 switch (aType) 807 808 for (size_t i = 0; i < arrEventTypes.size() && !fSignalled; i++) 799 809 { 800 case VBoxEventType_OnGuestFileStateChanged:810 if (type == arrEventTypes[i]) 801 811 { 802 ComPtr<IGuestFileStateChangedEvent> pChangedEvent = pEvent; 803 Assert(!pChangedEvent.isNull()); 804 805 ComPtr<IGuestFile> pFile; 806 pChangedEvent->COMGETTER(File)(pFile.asOutParam()); 807 Assert(!pFile.isNull()); 808 809 if (pFile != this) 810 continue; 812 switch (type) 813 { 814 case VBoxEventType_OnGuestFileStateChanged: 815 case VBoxEventType_OnGuestFileOffsetChanged: 816 case VBoxEventType_OnGuestFileRead: 817 case VBoxEventType_OnGuestFileWrite: 818 { 819 ComPtr<IGuestFileEvent> pFileEvent = pThisEvent; 820 Assert(!pFileEvent.isNull()); 821 822 ComPtr<IGuestFile> pFile; 823 pFileEvent->COMGETTER(File)(pFile.asOutParam()); 824 Assert(!pFile.isNull()); 825 826 fSignalled = (pFile == this); 827 break; 828 } 829 830 default: 831 AssertMsgFailed(("Unhandled event %ld\n", type)); 832 break; 833 } 834 835 if (fSignalled) 836 { 837 if (pType) 838 *pType = type; 839 if (ppEvent) 840 pThisEvent.queryInterfaceTo(ppEvent); 841 if ( type == VBoxEventType_OnGuestFileStateChanged 842 && RT_SUCCESS(vrc)) 843 vrc = VWRN_GSTCTL_OBJECTSTATE_CHANGED; 844 break; 845 } 811 846 } 812 813 default:814 AssertMsgFailed(("Unhandled event type %ld\n", aType));815 break;816 847 } 817 818 fSignalled = true;819 break;820 848 } 849 else 850 vrc = VERR_COM_UNEXPECTED; 821 851 822 852 } while (!fSignalled); … … 828 858 } 829 859 830 mEventSource->UnregisterListener(pListener); 860 hr = mEventSource->UnregisterListener(pListener); 861 ComAssertComRC(hr); 831 862 } 832 863 else … … 837 868 } 838 869 870 int GuestFile::waitForOffsetChange(uint32_t uTimeoutMS, uint64_t *puOffset) 871 { 872 VBoxEventType_T evtType; 873 ComPtr<IEvent> pEvent; 874 com::SafeArray<VBoxEventType_T> eventTypes; 875 eventTypes.push_back(VBoxEventType_OnGuestFileOffsetChanged); 876 int vrc = waitForEvents(uTimeoutMS, ComSafeArrayAsInParam(eventTypes), 877 &evtType, pEvent.asOutParam()); 878 if ( vrc == VINF_SUCCESS /* Can also return VWRN_GSTCTL_OBJECTSTATE_CHANGED. */ 879 && puOffset) 880 { 881 Assert(evtType == VBoxEventType_OnGuestFileOffsetChanged); 882 ComPtr<IGuestFileOffsetChangedEvent> pFileEvent = pEvent; 883 Assert(!pFileEvent.isNull()); 884 885 HRESULT hr = pFileEvent->COMGETTER(Offset)((LONG64*)puOffset); 886 ComAssertComRC(hr); 887 } 888 889 return vrc; 890 } 891 892 int GuestFile::waitForRead(uint32_t uTimeoutMS, void *pvData, size_t cbData, uint32_t *pcbRead) 893 { 894 VBoxEventType_T evtType; 895 ComPtr<IEvent> pEvent; 896 com::SafeArray<VBoxEventType_T> eventTypes; 897 eventTypes.push_back(VBoxEventType_OnGuestFileRead); 898 int vrc = waitForEvents(uTimeoutMS, ComSafeArrayAsInParam(eventTypes), 899 &evtType, pEvent.asOutParam()); 900 if (vrc == VINF_SUCCESS) /* Can also return VWRN_GSTCTL_OBJECTSTATE_CHANGED. */ 901 { 902 Assert(evtType == VBoxEventType_OnGuestFileRead); 903 ComPtr<IGuestFileReadEvent> pFileEvent = pEvent; 904 Assert(!pFileEvent.isNull()); 905 906 HRESULT hr; 907 if (pvData) 908 { 909 com::SafeArray <BYTE> data; 910 hr = pFileEvent->COMGETTER(Data)(ComSafeArrayAsOutParam(data)); 911 ComAssertComRC(hr); 912 size_t cbRead = data.size(); 913 if ( cbRead 914 && cbRead <= cbData) 915 { 916 memcpy(pvData, data.raw(), data.size()); 917 } 918 else 919 vrc = VERR_BUFFER_OVERFLOW; 920 } 921 if (pcbRead) 922 { 923 hr = pFileEvent->COMGETTER(Processed)((ULONG*)pcbRead); 924 ComAssertComRC(hr); 925 } 926 } 927 928 return vrc; 929 } 930 931 int GuestFile::waitForStatusChange(uint32_t uTimeoutMS, FileStatus_T *pFileStatus) 932 { 933 VBoxEventType_T evtType; 934 ComPtr<IEvent> pEvent; 935 com::SafeArray<VBoxEventType_T> eventTypes; 936 /* No own event types needed. VBoxEventType_OnGuestFileStateChanged already will 937 * part of the array when processed in waitForEvents. */ 938 int vrc = waitForEvents(uTimeoutMS, ComSafeArrayAsInParam(eventTypes), 939 &evtType, pEvent.asOutParam()); 940 if ( vrc == VINF_SUCCESS /* Can also return VWRN_GSTCTL_OBJECTSTATE_CHANGED. */ 941 && pFileStatus) 942 { 943 Assert(evtType == VBoxEventType_OnGuestFileStateChanged); 944 ComPtr<IGuestFileStateChangedEvent> pFileEvent = pEvent; 945 Assert(!pFileEvent.isNull()); 946 947 HRESULT hr = pFileEvent->COMGETTER(Status)(pFileStatus); 948 ComAssertComRC(hr); 949 } 950 951 return vrc; 952 } 953 839 954 int GuestFile::waitForWrite(uint32_t uTimeoutMS, uint32_t *pcbWritten) 840 955 { 841 return VINF_SUCCESS; 956 VBoxEventType_T evtType; 957 ComPtr<IEvent> pEvent; 958 com::SafeArray<VBoxEventType_T> eventTypes; 959 eventTypes.push_back(VBoxEventType_OnGuestFileWrite); 960 int vrc = waitForEvents(uTimeoutMS, ComSafeArrayAsInParam(eventTypes), 961 &evtType, pEvent.asOutParam()); 962 if ( vrc == VINF_SUCCESS /* Can also return VWRN_GSTCTL_OBJECTSTATE_CHANGED. */ 963 && pcbWritten) 964 { 965 Assert(evtType == VBoxEventType_OnGuestFileWrite); 966 ComPtr<IGuestFileWriteEvent> pFileEvent = pEvent; 967 Assert(!pFileEvent.isNull()); 968 969 HRESULT hr = pFileEvent->COMGETTER(Processed)((ULONG*)pcbWritten); 970 ComAssertComRC(hr); 971 } 972 973 return vrc; 842 974 } 843 975 … … 904 1036 paParms[i++].setPointer(pvData, cbData); 905 1037 1038 uint32_t cbWritten; 906 1039 vrc = sendCommand(HOST_FILE_WRITE_AT, i, paParms); 907 1040 if (RT_SUCCESS(vrc)) 908 { 909 uint32_t cbWritten; 910 vrc = sendCommand(HOST_FILE_WRITE, i, paParms); 911 if (RT_SUCCESS(vrc)) 912 vrc = waitForWrite(uTimeoutMS, &cbWritten); 913 914 if (RT_SUCCESS(vrc)) 915 { 916 LogFlowThisFunc(("cbWritten=%RU32\n", cbWritten)); 917 918 if (cbWritten) 919 *pcbWritten = cbWritten; 920 } 1041 vrc = waitForWrite(uTimeoutMS, &cbWritten); 1042 1043 if (RT_SUCCESS(vrc)) 1044 { 1045 LogFlowThisFunc(("cbWritten=%RU32\n", cbWritten)); 1046 1047 if (cbWritten) 1048 *pcbWritten = cbWritten; 921 1049 } 922 1050 } … … 1021 1149 } 1022 1150 1023 LogFlowThisFunc(("rc=%Rrc, cbRead=%RU64\n", vrc, cbRead));1024 1025 1151 LogFlowFuncLeaveRC(vrc); 1026 1152 return hr; … … 1066 1192 } 1067 1193 1068 LogFlowThisFunc(("rc=%Rrc, cbRead=%RU64\n", vrc, cbRead));1069 1070 1194 LogFlowFuncLeaveRC(vrc); 1071 1195 return hr; … … 1155 1279 default: 1156 1280 hr = setError(VBOX_E_IPRT_ERROR, 1157 tr("Writing to file \"%s\" failed: %Rrc"),1158 mData.mOpenInfo.mFileName.c_str(), vrc);1281 tr("Writing %zubytes to file \"%s\" failed: %Rrc"), 1282 data.size(), mData.mOpenInfo.mFileName.c_str(), vrc); 1159 1283 break; 1160 1284 } 1161 1285 } 1162 1163 LogFlowThisFunc(("rc=%Rrc, aWritten=%RU32\n", vrc, aWritten));1164 1286 1165 1287 LogFlowFuncLeaveRC(vrc); … … 1191 1313 default: 1192 1314 hr = setError(VBOX_E_IPRT_ERROR, 1193 tr("Writing to file \"%s\" (at offset %RU64) failed: %Rrc"),1194 mData.mOpenInfo.mFileName.c_str(), aOffset, vrc);1315 tr("Writing %zubytes to file \"%s\" (at offset %RU64) failed: %Rrc"), 1316 data.size(), mData.mOpenInfo.mFileName.c_str(), aOffset, vrc); 1195 1317 break; 1196 1318 } 1197 1319 } 1198 1320 1199 LogFlowThisFunc(("rc=%Rrc, aWritten=%RU32\n", vrc, aWritten));1200 1201 1321 LogFlowFuncLeaveRC(vrc); 1202 1322 return hr; -
trunk/src/VBox/Main/src-client/GuestSessionImpl.cpp
r45426 r45434 867 867 868 868 Assert(mData.mNumObjects); 869 LogFlowThisFunc(("Removing file \"%s\" (Session: %RU32) (now total %ld files, %ld objects)\n",869 LogFlowThisFunc(("Removing guest file \"%s\" (Session: %RU32) (now total %ld files, %ld objects)\n", 870 870 Utf8Str(strName).c_str(), mData.mSession.mID, mData.mFiles.size() - 1, mData.mNumObjects - 1)); 871 #ifdef DEBUG 872 ULONG cRefs = pFile->AddRef(); 873 LogFlowThisFunc(("pObject=%p, cRefs=%RU32\n", pFile, cRefs)); 874 pFile->Release(); 875 #endif 871 876 872 mData.mFiles.erase(itFiles); 877 873 mData.mNumObjects--; 874 875 fireGuestFileRegisteredEvent(mEventSource, this, pFile, 876 false /* Unregistered */); 878 877 return VINF_SUCCESS; 879 878 } … … 974 973 Assert(mData.mNumObjects <= VBOX_GUESTCTRL_MAX_OBJECTS); 975 974 976 LogFlowFunc(("Added new file \"%s\" (Session: %RU32) (now total %ld files, %ld objects)\n",975 LogFlowFunc(("Added new guest file \"%s\" (Session: %RU32) (now total %ld files, %ld objects)\n", 977 976 openInfo.mFileName.c_str(), mData.mSession.mID, mData.mFiles.size(), mData.mNumObjects)); 977 978 fireGuestFileRegisteredEvent(mEventSource, this, pFile, 979 true /* Registered */); 978 980 } 979 981
Note:
See TracChangeset
for help on using the changeset viewer.