- Timestamp:
- Oct 16, 2008 6:44:34 PM (16 years ago)
- Location:
- trunk/src/VBox/Main
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/MachineImpl.cpp
r13346 r13356 2724 2724 } 2725 2725 2726 STDMETHODIMP Machine::GetGuestProperty (INPTR BSTR a Key, BSTR *aValue, ULONG64 *aTimestamp, BSTR *aFlags)2726 STDMETHODIMP Machine::GetGuestProperty (INPTR BSTR aName, BSTR *aValue, ULONG64 *aTimestamp, BSTR *aFlags) 2727 2727 { 2728 2728 #if !defined (VBOX_WITH_GUEST_PROPS) 2729 2729 return E_NOTIMPL; 2730 2730 #else 2731 if (!VALID_PTR (a Key))2731 if (!VALID_PTR (aName)) 2732 2732 return E_INVALIDARG; 2733 2733 if (!VALID_PTR (aValue)) … … 2752 2752 (it != mHWData->mGuestProperties.end()) && !found; ++it) 2753 2753 { 2754 if (it->mName == a Key)2754 if (it->mName == aName) 2755 2755 { 2756 char szFlags[MAX_FLAGS_LEN + 1]; 2756 2757 it->mValue.cloneTo(aValue); 2757 2758 *aTimestamp = it->mTimestamp; 2758 it->mFlags.cloneTo(aFlags); 2759 writeFlags(it->mFlags, szFlags); 2760 Bstr(szFlags).cloneTo(aFlags); 2759 2761 found = true; 2760 2762 } … … 2770 2772 alock.unlock(); 2771 2773 2772 rc = directControl->AccessGuestProperty (a Key, NULL, NULL,2774 rc = directControl->AccessGuestProperty (aName, NULL, NULL, 2773 2775 false /* isSetter */, 2774 2776 aValue, aTimestamp, aFlags); … … 2778 2780 } 2779 2781 2780 STDMETHODIMP Machine::GetGuestPropertyValue (INPTR BSTR a Key, BSTR *aValue)2782 STDMETHODIMP Machine::GetGuestPropertyValue (INPTR BSTR aName, BSTR *aValue) 2781 2783 { 2782 2784 ULONG64 dummyTimestamp; 2783 2785 BSTR dummyFlags; 2784 return GetGuestProperty(a Key, aValue, &dummyTimestamp, &dummyFlags);2785 } 2786 2787 STDMETHODIMP Machine::GetGuestPropertyTimestamp (INPTR BSTR a Key, ULONG64 *aTimestamp)2786 return GetGuestProperty(aName, aValue, &dummyTimestamp, &dummyFlags); 2787 } 2788 2789 STDMETHODIMP Machine::GetGuestPropertyTimestamp (INPTR BSTR aName, ULONG64 *aTimestamp) 2788 2790 { 2789 2791 BSTR dummyValue; 2790 2792 BSTR dummyFlags; 2791 return GetGuestProperty(a Key, &dummyValue, aTimestamp, &dummyFlags);2793 return GetGuestProperty(aName, &dummyValue, aTimestamp, &dummyFlags); 2792 2794 } 2793 2795 … … 2797 2799 return E_NOTIMPL; 2798 2800 #else 2801 using namespace guestProp; 2802 2799 2803 if (!VALID_PTR (aName)) 2800 2804 return E_INVALIDARG; … … 2803 2807 if ((aFlags != NULL) && !VALID_PTR (aFlags)) 2804 2808 return E_INVALIDARG; 2809 uint32_t fFlags = NILFLAG; 2810 if (RT_FAILURE (validateFlags (Utf8Str(aFlags).raw(), &fFlags))) 2811 return setError (E_INVALIDARG, tr ("Invalid flag values: '%ls'"), 2812 aFlags); 2805 2813 2806 2814 AutoCaller autoCaller (this); … … 2812 2820 CheckComRCReturnRC (rc); 2813 2821 2814 using namespace guestProp; 2815 rc = E_FAIL; 2822 rc = S_OK; 2816 2823 2817 2824 if (!mHWData->mPropertyServiceActive) … … 2819 2826 bool found = false; 2820 2827 HWData::GuestProperty property; 2821 for (HWData::GuestPropertyList::iterator it = mHWData->mGuestProperties.begin(); 2822 (it != mHWData->mGuestProperties.end()) && !found; ++it) 2823 if (it->mName == aName) 2824 { 2825 property = *it; 2826 mHWData.backup(); 2827 /* The backup() operation invalidates our iterator, so get a 2828 * new one. */ 2829 for (it = mHWData->mGuestProperties.begin(); 2830 it->mName != aName; ++it) 2831 ; 2832 mHWData->mGuestProperties.erase(it); 2833 found = true; 2834 } 2835 if (found) 2836 { 2837 if (NULL != aValue) 2828 property.mFlags = NILFLAG; 2829 if (fFlags & TRANSIENT) 2830 rc = setError (E_INVALIDARG, tr ("Cannot set a transient property when the machine is not running")); 2831 if (SUCCEEDED (rc)) 2832 { 2833 for (HWData::GuestPropertyList::iterator it = mHWData->mGuestProperties.begin(); 2834 (it != mHWData->mGuestProperties.end()) && !found; ++it) 2835 if (it->mName == aName) 2836 { 2837 property = *it; 2838 if (it->mFlags & (GUESTWRITE | READONLY)) 2839 rc = setError (E_ACCESSDENIED, tr ("The property '%ls' cannot be changed by the host"), aName); 2840 else 2841 { 2842 mHWData.backup(); 2843 /* The backup() operation invalidates our iterator, so get a 2844 * new one. */ 2845 for (it = mHWData->mGuestProperties.begin(); 2846 it->mName != aName; ++it) 2847 ; 2848 mHWData->mGuestProperties.erase(it); 2849 } 2850 found = true; 2851 } 2852 } 2853 if (found && SUCCEEDED (rc)) 2854 { 2855 if (aValue != NULL) 2838 2856 { 2839 2857 RTTIMESPEC time; … … 2841 2859 property.mTimestamp = RTTimeSpecGetNano(RTTimeNow(&time)); 2842 2860 if (aFlags != NULL) 2843 property.mFlags = aFlags;2861 property.mFlags = fFlags; 2844 2862 mHWData->mGuestProperties.push_back(property); 2845 2863 } 2846 2864 } 2847 else if ( aValue != NULL)2865 else if (SUCCEEDED (rc) && (aValue != NULL)) 2848 2866 { 2849 2867 RTTIMESPEC time; … … 2852 2870 property.mValue = aValue; 2853 2871 property.mTimestamp = RTTimeSpecGetNano(RTTimeNow(&time)); 2854 property.mFlags = (aFlags != NULL ? Bstr(aFlags) : Bstr(""));2872 property.mFlags = fFlags; 2855 2873 mHWData->mGuestProperties.push_back(property); 2856 2874 } 2857 rc = S_OK;2858 2875 } 2859 2876 else … … 3034 3051 it != propList.end(); ++it) 3035 3052 { 3053 char szFlags[MAX_FLAGS_LEN + 1]; 3036 3054 it->mName.cloneTo(&names[iProp]); 3037 3055 it->mValue.cloneTo(&values[iProp]); 3038 3056 timestamps[iProp] = it->mTimestamp; 3039 it->mFlags.cloneTo(&flags[iProp]); 3057 writeFlags(it->mFlags, szFlags); 3058 Bstr(szFlags).cloneTo(&flags[iProp]); 3040 3059 ++iProp; 3041 3060 } … … 5020 5039 } 5021 5040 5041 #ifdef VBOX_WITH_GUEST_PROPS 5022 5042 /* Guest properties (optional) */ 5023 5043 { 5044 using namespace guestProp; 5045 5024 5046 Key guestPropertiesNode = aNode.findKey ("GuestProperties"); 5025 5047 if (!guestPropertiesNode.isNull()) … … 5029 5051 it != properties.end(); ++ it) 5030 5052 { 5053 uint32_t fFlags = NILFLAG; 5054 5031 5055 /* property name (required) */ 5032 5056 Bstr name = (*it).stringValue ("name"); … … 5037 5061 /* property flags (optional, defaults to empty) */ 5038 5062 Bstr flags = (*it).stringValue ("flags"); 5039 5040 HWData::GuestProperty property = { name, value, timestamp, f lags };5063 validateFlags (Utf8Str (flags).raw(), &fFlags); 5064 HWData::GuestProperty property = { name, value, timestamp, fFlags }; 5041 5065 mHWData->mGuestProperties.push_back(property); 5042 5066 } … … 5044 5068 mHWData->mPropertyServiceActive = false; 5045 5069 } 5070 #endif /* VBOX_WITH_GUEST_PROPS defined */ 5046 5071 5047 5072 AssertComRC (rc); … … 6405 6430 } 6406 6431 6432 #ifdef VBOX_WITH_GUEST_PROPS 6407 6433 /* Guest properties */ 6408 6434 { 6435 using namespace guestProp; 6436 6409 6437 Key guestPropertiesNode = aNode.createKey ("GuestProperties"); 6410 6438 … … 6416 6444 6417 6445 Key propertyNode = guestPropertiesNode.appendKey ("GuestProperty"); 6446 char szFlags[MAX_FLAGS_LEN + 1]; 6418 6447 6419 6448 propertyNode.setValue <Bstr> ("name", property.mName); 6420 6449 propertyNode.setValue <Bstr> ("value", property.mValue); 6421 6450 propertyNode.setValue <ULONG64> ("timestamp", property.mTimestamp); 6422 propertyNode.setValue <Bstr> ("flags", property.mFlags); 6423 } 6424 } 6451 writeFlags(property.mFlags, szFlags); 6452 propertyNode.setValue <Bstr> ("flags", Bstr(szFlags)); 6453 } 6454 } 6455 #endif /* VBOX_WITH_GUEST_PROPS defined */ 6425 6456 6426 6457 AssertComRC (rc); … … 8976 9007 8977 9008 #ifdef VBOX_WITH_GUEST_PROPS 9009 using namespace guestProp; 9010 8978 9011 AutoCaller autoCaller (this); 8979 9012 AssertComRCReturn (autoCaller.rc(), autoCaller.rc()); … … 8995 9028 it != mHWData->mGuestProperties.end(); ++it) 8996 9029 { 9030 char szFlags[MAX_FLAGS_LEN + 1]; 8997 9031 it->mName.cloneTo(&names[i]); 8998 9032 it->mValue.cloneTo(&values[i]); 8999 9033 timestamps[i] = it->mTimestamp; 9000 it->mFlags.cloneTo(&flags[i]); 9034 writeFlags(it->mFlags, szFlags); 9035 Bstr(szFlags).cloneTo(&flags[i]); 9001 9036 ++i; 9002 9037 } … … 9008 9043 return S_OK; 9009 9044 #else 9010 return VERR_NOT_IMPLEMENTED;9045 return E_NOTIMPL; 9011 9046 #endif 9012 9047 } … … 9020 9055 9021 9056 #ifdef VBOX_WITH_GUEST_PROPS 9057 using namespace guestProp; 9058 9022 9059 AutoCaller autoCaller (this); 9023 9060 AssertComRCReturn (autoCaller.rc(), autoCaller.rc()); … … 9052 9089 for (unsigned i = 0; i < names.size(); ++i) 9053 9090 { 9054 HWData::GuestProperty property = { names[i], values[i], timestamps[i], flags[i] }; 9091 uint32_t fFlags = NILFLAG; 9092 validateFlags (Utf8Str(flags[i]).raw(), &fFlags); 9093 HWData::GuestProperty property = { names[i], values[i], timestamps[i], fFlags }; 9055 9094 mHWData->mGuestProperties.push_back(property); 9056 9095 } … … 9062 9101 return S_OK; 9063 9102 #else 9064 return VERR_NOT_IMPLEMENTED;9103 return E_NOTIMPL; 9065 9104 #endif 9066 9105 } … … 9072 9111 9073 9112 #ifdef VBOX_WITH_GUEST_PROPS 9113 using namespace guestProp; 9114 9074 9115 if (!VALID_PTR(aName)) 9116 return E_POINTER; 9117 if ((aValue != NULL) && (!VALID_PTR(aValue) || !VALID_PTR(aFlags))) 9118 return E_POINTER; /* aValue can be NULL to indicate deletion */ 9119 9120 uint32_t fFlags = NILFLAG; 9121 if (RT_FAILURE (validateFlags (Utf8Str(aFlags).raw(), &fFlags))) 9075 9122 return E_INVALIDARG; 9076 if ((aValue != NULL) && (!VALID_PTR(aValue) || !VALID_PTR(aFlags)))9077 return E_INVALIDARG; /* aValue can be NULL to indicate deletion */9078 9123 9079 9124 AutoCaller autoCaller (this); … … 9095 9140 if (aValue != NULL) 9096 9141 { 9097 HWData::GuestProperty property = { aName, aValue, aTimestamp, aFlags };9142 HWData::GuestProperty property = { aName, aValue, aTimestamp, fFlags }; 9098 9143 mHWData->mGuestProperties.push_back(property); 9099 9144 } … … 9105 9150 return S_OK; 9106 9151 #else 9107 return VERR_NOT_IMPLEMENTED;9152 return E_NOTIMPL; 9108 9153 #endif 9109 9154 } -
trunk/src/VBox/Main/include/MachineImpl.h
r13221 r13356 240 240 ULONG64 mTimestamp; 241 241 /** Property flags */ 242 BstrmFlags;242 ULONG mFlags; 243 243 }; 244 244
Note:
See TracChangeset
for help on using the changeset viewer.