Changeset 73716 in vbox for trunk/src/VBox/Main/src-server
- Timestamp:
- Aug 16, 2018 3:58:57 PM (6 years ago)
- Location:
- trunk/src/VBox/Main/src-server
- Files:
-
- 2 edited
- 2 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/src-server/CloudProviderManagerImpl.cpp
r73576 r73716 17 17 18 18 19 #include <iprt/path.h>20 #include <iprt/cpp/utils.h>21 19 #include <VBox/com/array.h> 22 #include <map> 23 24 #include "CloudUserProfileManagerImpl.h" 25 #include "CloudUserProfilesImpl.h" 20 26 21 #include "VirtualBoxImpl.h" 27 #include "ExtPackManagerImpl.h" 28 #include "Global.h" 29 #include "ProgressImpl.h" 30 #include "MachineImpl.h" 22 #include "CloudProviderManagerImpl.h" 23 #ifdef VBOX_WITH_CLOUD_PROVIDERS_IN_EXTPACK 24 # include "ExtPackManagerImpl.h" 25 #else 26 # include "OCIProvider.h" 27 #endif 31 28 #include "AutoCaller.h" 32 29 #include "Logging.h" … … 40 37 // //////////////////////////////////////////////////////////////////////////////// 41 38 CloudProviderManager::CloudProviderManager() 42 : mParent(NULL)43 39 { 44 40 } … … 63 59 HRESULT CloudProviderManager::init(VirtualBox *aParent) 64 60 { 65 / * Enclose the state transition NotReady->InInit->Ready */61 // Enclose the state transition NotReady->InInit->Ready. 66 62 AutoInitSpan autoInitSpan(this); 67 63 AssertReturn(autoInitSpan.isOk(), E_FAIL); 68 64 69 unconst(mParent) = aParent;65 m_apCloudProviders.clear(); 70 66 71 67 #ifdef VBOX_WITH_CLOUD_PROVIDERS_IN_EXTPACK 72 /* 73 * Engage the extension pack manager and get all the implementations of this class. 74 */ 68 // Engage the extension pack manager and get all the implementations of 69 // this class and all implemented cloud providers. 75 70 ExtPackManager *pExtPackMgr = aParent->i_getExtPackManager(); 76 std::vector<ComPtr<IUnknown> > Objects; 77 com::Guid idObj(COM_IIDOF(ICloudProviderManager)); 78 pExtPackMgr->i_queryObjects(idObj.toString(), Objects); 79 for (unsigned i = 0; i < Objects.size(); i++) 80 { 81 ComPtr<ICloudProviderManager> ptrTmp; 82 HRESULT hrc = Objects[i].queryInterfaceTo(ptrTmp.asOutParam()); 83 if (SUCCEEDED(hrc)) 84 mUserProfileManagers.push_back(ptrTmp); 71 mpExtPackMgr = pExtPackMgr; 72 if (pExtPackMgr) 73 { 74 mcExtPackMgrUpdate = pExtPackMgr->i_getUpdateCounter(); 75 // Make sure that the current value doesn't match, forcing a refresh. 76 mcExtPackMgrUpdate--; 77 iRefreshProviders(); 85 78 } 86 79 #else 87 88 mSupportedProviders.clear(); 89 mSupportedProviders.push_back("OCI"); 90 80 ComObjPtr<OCIProvider> pOCIProvider; 81 HRESULT hrc = pOCIProvider.createObject(); 82 if (FAILED(hrc)) 83 return hrc; 84 hrc = pOCIProvider->init(aParent); 85 if (FAILED(hrc)) 86 return hrc; 87 m_apCloudProviders.push_back(pOCIProvider); 91 88 #endif 92 89 … … 97 94 void CloudProviderManager::uninit() 98 95 { 99 / * Enclose the state transition Ready->InUninit->NotReady */96 // Enclose the state transition Ready->InUninit->NotReady. 100 97 AutoUninitSpan autoUninitSpan(this); 101 98 if (autoUninitSpan.uninitDone()) 102 99 return; 103 104 unconst(mParent) = NULL; 105 } 106 107 HRESULT CloudProviderManager::getSupportedProviders(std::vector<Utf8Str> &aSupportedProviders) 108 { 100 } 101 109 102 #ifdef VBOX_WITH_CLOUD_PROVIDERS_IN_EXTPACK 110 /* 111 * Collect all the provider names from all the extension pack objects. 112 */ 113 HRESULT hrc = S_OK; 114 for (unsigned i = 0; i < mUserProfileManagers.size(); i++) 115 { 116 SafeArray<Utf8Str> FromCurrent; 117 HRESULT hrc2 = mUserProfileManagers[i]->COMGETTER(SupportedProviders)(ComSafeArrayAsOutParam(FromCurrent)); 118 if (SUCCEEDED(hrc2)) 119 for (size_t j = 0; j < FromCurrent.size(); j++) 120 aSupportedProviders.push_back(FromCurrent[j]); 121 else if (SUCCEEDED(hrc)) 122 hrc = hrc2; 123 } 124 if (aSupportedProviders.size() > 0) 125 hrc = S_OK; 126 return hrc; 127 #else 128 aSupportedProviders = mSupportedProviders; 103 void CloudProviderManager::i_refreshProviders() 104 { 105 { 106 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS); 107 uint64_t cExtPackMgrUpdate = mpExtPackMgr->i_getUpdateCounter(); 108 if (cExtPackMgrUpdate == mcExtPackMgrUpdate) 109 return; 110 } 111 112 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS); 113 // Reread the current value to figure out if some other thead did the work 114 // already before this thread got hold of the write lock. 115 cExtPackMgrUpdate = pExtPackMgr->i_getUpdateCounter(); 116 if (cExtPackMgrUpdate == mcExtPackMgrUpdate) 117 return; 118 mcExtPackMgrUpdate = cExtPackMgrUpdate; 119 120 if (!m_mapCloudProviderManagers.empty()) 121 { 122 /// @todo The code below will need to be extended to handle extpack 123 // install and uninstall safely (and the latter needs non-trivial 124 // checks if any extpack related cloud activity is pending. 125 return; 126 } 127 128 std::vector<ComPtr<IUnknown> > apObjects; 129 std::vector<com::Utf8Str> astrExtPackNames; 130 com::Guid idObj(COM_IIDOF(ICloudProviderManager)); 131 pExtPackMgr->i_queryObjects(idObj.toString(), apObjects, &astrExtPackNames); 132 for (unsigned i = 0; i < apObjects.size(); i++) 133 { 134 ComPtr<ICloudProviderManager> pTmp; 135 HRESULT hrc = apObjects[i].queryInterfaceTo(pTmp.asOutParam()); 136 if (SUCCEEDED(hrc)) 137 m_mapCloudProviderManagers[astrExtPackNames[i]] = pTmp; 138 SafeIfaceArray<ICloudProvider> apProvidersFromCurrExtPack; 139 hrc = pTmp->COMGETTER(Providers)(ComSafeArrayAsOutParam(apProvidersFromCurrExtPack)); 140 if (SUCCEEDED(hrc)) 141 { 142 for (unsigned j = 0; j < apProvidersFromCurrExtPack.size(); j++) 143 m_apCloudProviders.push_back(apProvidersFromCurrExtPack[i]); 144 } 145 } 146 } 147 #endif 148 149 HRESULT CloudProviderManager::getProviders(std::vector<ComPtr<ICloudProvider> > &aProviders) 150 { 151 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS); 152 aProviders = m_apCloudProviders; 129 153 return S_OK; 130 #endif 131 } 132 133 HRESULT CloudProviderManager::getAllProfiles(std::vector<ComPtr<ICloudProvider> > &aProfilesList) 134 { 135 #ifdef VBOX_WITH_CLOUD_PROVIDERS_IN_EXTPACK 136 /* 137 * Collect all the cloud providers from all the extension pack objects. 138 */ 139 HRESULT hrc = S_OK; 140 for (unsigned i = 0; i < mUserProfileManagers.size(); i++) 141 { 142 SafeIfaceArray<ICloudProvider> FromCurrent; 143 HRESULT hrc2 = mUserProfileManagers[i]->GetAllProfiles(ComSafeArrayAsOutParam(FromCurrent)); 144 if (SUCCEEDED(hrc2)) 145 for (size_t j = 0; j < FromCurrent.size(); j++) 146 aProfilesList.push_back(FromCurrent[j]); 147 else if (SUCCEEDED(hrc)) 148 hrc = hrc2; 149 } 150 if (aProfilesList.size() > 0) 151 hrc = S_OK; 152 return hrc; 153 154 #else 155 HRESULT hrc = S_OK; 156 std::vector<ComPtr<ICloudProvider> > lProfilesList; 157 for (size_t i=0;i<mSupportedProviders.size();++i) 158 { 159 ComPtr<ICloudProvider> lProfiles; 160 hrc = getProfilesByProvider(mSupportedProviders.at(i), lProfiles); 161 if (FAILED(hrc)) 162 break; 163 164 lProfilesList.push_back(lProfiles); 165 } 166 167 if (SUCCEEDED(hrc)) 168 aProfilesList = lProfilesList; 169 170 return hrc; 171 #endif 172 } 173 174 HRESULT CloudProviderManager::getProfilesByProvider(const com::Utf8Str &aProviderName, 175 ComPtr<ICloudProvider> &aProfiles) 176 { 177 #ifdef VBOX_WITH_CLOUD_PROVIDERS_IN_EXTPACK 178 /* 179 * Return the first provider we get. 180 */ 181 HRESULT hrc = VBOX_E_OBJECT_NOT_FOUND; 182 for (unsigned i = 0; i < mUserProfileManagers.size(); i++) 183 { 184 hrc = mUserProfileManagers[i]->GetProfilesByProvider(aProviderType, aProfiles.asOutParam()); 185 if (SUCCEEDED(hrc)) 186 break; 187 } 188 return hrc; 189 190 #else 191 192 ComObjPtr<CloudProvider> ptrCloudProvider; 193 HRESULT hrc = ptrCloudProvider.createObject(); 194 if (aProviderName.equals("OCI")) 195 { 196 ComObjPtr<OCIUserProfiles> ptrOCIUserProfiles; 197 hrc = ptrOCIUserProfiles.createObject(); 198 if (SUCCEEDED(hrc)) 199 { 200 AutoReadLock wlock(this COMMA_LOCKVAL_SRC_POS); 201 202 hrc = ptrOCIUserProfiles->init(mParent); 203 if (SUCCEEDED(hrc)) 204 { 205 char szOciConfigPath[RTPATH_MAX]; 206 int vrc = RTPathUserHome(szOciConfigPath, sizeof(szOciConfigPath)); 207 if (RT_SUCCESS(vrc)) 208 vrc = RTPathAppend(szOciConfigPath, sizeof(szOciConfigPath), ".oci" RTPATH_SLASH_STR "config"); 209 if (RT_SUCCESS(vrc)) 210 { 211 LogRel(("config = %s\n", szOciConfigPath)); 212 if (RTFileExists(szOciConfigPath)) 213 { 214 hrc = ptrOCIUserProfiles->readProfiles(szOciConfigPath); 215 if (SUCCEEDED(hrc)) 216 LogRel(("Reading profiles from %s has been done\n", szOciConfigPath)); 217 else 218 LogRel(("Reading profiles from %s hasn't been done\n", szOciConfigPath)); 219 220 ptrCloudProvider = ptrOCIUserProfiles; 221 hrc = ptrCloudProvider.queryInterfaceTo(aProfiles.asOutParam()); 222 } 223 else 224 hrc = setErrorBoth(E_FAIL, VERR_FILE_NOT_FOUND, tr("Could not locate the config file '%s'"), 225 szOciConfigPath); 226 } 227 else 228 hrc = setErrorVrc(vrc); 229 } 230 } 231 } 232 233 return hrc; 234 #endif 235 } 236 154 } 155 156 HRESULT CloudProviderManager::getProviderById(const com::Guid &aProviderId, 157 ComPtr<ICloudProvider> &aProvider) 158 { 159 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS); 160 for (size_t i = 0; i < m_apCloudProviders.size(); i++) 161 { 162 Bstr bstrId; 163 HRESULT hrc = m_apCloudProviders[i]->COMGETTER(Id)(bstrId.asOutParam()); 164 if (SUCCEEDED(hrc) && aProviderId == bstrId) 165 { 166 aProvider = m_apCloudProviders[i]; 167 return S_OK; 168 } 169 } 170 return setError(VBOX_E_OBJECT_NOT_FOUND, tr("Could not find a cloud provider with UUID {%RTuuid}"), 171 aProviderId.raw()); 172 } 173 174 HRESULT CloudProviderManager::getProviderByShortName(const com::Utf8Str &aProviderName, 175 ComPtr<ICloudProvider> &aProvider) 176 { 177 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS); 178 for (size_t i = 0; i < m_apCloudProviders.size(); i++) 179 { 180 Bstr bstrName; 181 HRESULT hrc = m_apCloudProviders[i]->COMGETTER(ShortName)(bstrName.asOutParam()); 182 if (SUCCEEDED(hrc) && bstrName.equals(aProviderName)) 183 { 184 aProvider = m_apCloudProviders[i]; 185 return S_OK; 186 } 187 } 188 return setError(VBOX_E_OBJECT_NOT_FOUND, tr("Could not find a cloud provider with short name '%s'"), 189 aProviderName.c_str()); 190 } 191 192 HRESULT CloudProviderManager::getProviderByName(const com::Utf8Str &aProviderName, 193 ComPtr<ICloudProvider> &aProvider) 194 { 195 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS); 196 for (size_t i = 0; i < m_apCloudProviders.size(); i++) 197 { 198 Bstr bstrName; 199 HRESULT hrc = m_apCloudProviders[i]->COMGETTER(Name)(bstrName.asOutParam()); 200 if (SUCCEEDED(hrc) && bstrName.equals(aProviderName)) 201 { 202 aProvider = m_apCloudProviders[i]; 203 return S_OK; 204 } 205 } 206 return setError(VBOX_E_OBJECT_NOT_FOUND, tr("Could not find a cloud provider with name '%s'"), 207 aProviderName.c_str()); 208 } 209 -
trunk/src/VBox/Main/src-server/OCIProfile.cpp
r73576 r73716 1 1 /* $Id$ */ 2 2 /** @file 3 * ICloudPro vider COM class implementations.3 * ICloudProfile COM class implementation (OCI). 4 4 */ 5 5 … … 16 16 */ 17 17 18 19 #include <iprt/path.h> 18 #include "OCIProfile.h" 19 #include "OCIProvider.h" 20 #include "CloudClientImpl.h" 21 #include "AutoCaller.h" 22 #define LOG_GROUP_MAIN_OVERRIDE LOG_GROUP_MAIN_CLOUDPROFILE 23 #include "Logging.h" 24 20 25 #include <iprt/cpp/utils.h> 21 #include <VBox/com/array.h> 22 23 #include "CloudUserProfilesImpl.h" 24 #include "VirtualBoxImpl.h" 25 #include "Global.h" 26 #include "ProgressImpl.h" 27 #include "MachineImpl.h" 28 #include "AutoCaller.h" 29 #include "Logging.h" 30 31 using namespace std; 26 32 27 33 28 //////////////////////////////////////////////////////////////////////////////// 34 29 // 35 // SimpleConfigFile implementation30 // OCIProfile implementation 36 31 // 37 32 //////////////////////////////////////////////////////////////////////////////// 38 SimpleConfigFile::SimpleConfigFile(VirtualBoxBase *pSetError, const char *pszFilename) 39 : GeneralTextScript(pSetError, pszFilename) 40 { 41 LogRel(("SimpleConfigFile::SimpleConfigFile(VirtualBoxBase *pSetError,...)\n")); 42 } 43 44 SimpleConfigFile::~SimpleConfigFile() 45 { 46 LogRel(("SimpleConfigFile::~SimpleConfigFile()\n")); 47 } 48 49 HRESULT SimpleConfigFile::parse() 50 { 51 LogRel(("Starting to parse the existing profiles\n")); 52 HRESULT hrc = S_OK; 53 hrc = GeneralTextScript::parse(); 54 if (SUCCEEDED(hrc)) 55 { 56 size_t lines = getLineNumbersOfScript(); 57 LogRel(("Initial parsing (GeneralTextScript::parse()) was succeeded \n")); 58 LogRel(("Read lines is %d \n", lines)); 59 size_t startSectionPos=0; 60 bool fInSection = false; 61 std::map <Utf8Str, Utf8Str> sectionConfiguration; 62 Utf8Str strSectionName("Default section "); 63 64 for (size_t i=0; i<lines; ++i) 65 { 66 //find the beginning of section, it starts from the line like "[section name]" 67 //next find the end of section, it ends up when we find the beginning 68 //of the next section or reach the end of the contents. 69 //Go through the found lines and split each of them up by "=". 70 //Each correct line must look like "key=value" 71 //if there is not the character "=" in the line one is skipped 72 //class Utf8Str contains the function parseKeyValue() for this action 73 LogRel(("Parsing the line %d \n", i)); 74 Utf8Str strLineContent = getContentOfLine(i); 75 if (strLineContent.isEmpty() || strLineContent.startsWith("#")) 76 continue; 77 78 LogRel(("Content of the line %d is %s \n", i, strLineContent.c_str())); 79 80 //strips the white-space characters from the string. It's needed for strings on Windows with "\n\r". 81 strLineContent = strLineContent.strip(); 82 if ( strLineContent.startsWith("[") && strLineContent.endsWith("]") ) 83 { 84 LogRel(("Found section in the line %d\n", i)); 85 if ( fInSection == true ) 86 { 87 if ( i > startSectionPos )//at least we can have here 1 line in the section 88 { 89 LogRel(("Add section \"%s\" to the map \n", strSectionName.c_str())); 90 mSections.insert(make_pair(strSectionName, sectionConfiguration)); 91 sectionConfiguration.clear(); 92 strSectionName.append(Utf8StrFmt("%d",i).c_str()); 93 } 94 } 95 96 strSectionName = strLineContent.substr(strLineContent.find("[")+1, 97 strLineContent.find("]")-1); 98 LogRel(("Section name is \"%s\" \n", strSectionName.c_str())); 99 fInSection = true; 100 startSectionPos = i+1; 101 } 102 else 103 { 104 if ( fInSection == true ) 105 { 106 LogRel(("Continue to parse section \"%s\" \n", strSectionName.c_str())); 107 if ( i >= startSectionPos ) 108 { 109 LogRel(("Extracting key and value:\n")); 110 Utf8Str key, value; 111 size_t offEnd = strLineContent.parseKeyValue(key, value); 112 if (offEnd == strLineContent.length()) 113 { 114 LogRel(("%s=%s \n", key.c_str(), value.c_str())); 115 sectionConfiguration.insert(make_pair(key,value)); 116 } 117 else 118 { 119 //else something goes wrong, skip the line 120 LogRel(("Coudn't extract key and value from the line %d\n", i)); 121 } 122 } 123 } 124 else 125 { 126 LogRel(("Goes to the next line %d\n", i+1)); 127 } 128 } 129 } 130 131 if (fInSection == false)//there is not any section 132 { 133 LogRel(("There are not any sections in the config\n")); 134 hrc = E_FAIL; 135 } 136 else //the last section hasn't a close tag (the close tag is just the beginning of next section) 137 { 138 //just insert the last section into the map 139 LogRel(("Add the last section %s to the map \n", strSectionName.c_str())); 140 mSections.insert(make_pair(strSectionName, sectionConfiguration)); 141 } 142 } 143 144 return hrc; 145 } 146 147 HRESULT SimpleConfigFile::addSection(const Utf8Str &aSectionName, const std::map <Utf8Str, Utf8Str>& section) 148 { 149 HRESULT hrc = S_OK; 150 if (aSectionName.isEmpty()) 151 hrc = E_FAIL; 152 else 153 mSections.insert(make_pair(aSectionName, section)); 154 155 return hrc; 156 } 157 158 std::vector <Utf8Str> SimpleConfigFile::getSectionsNames() const 159 { 160 std::vector <Utf8Str> res; 161 std::map < Utf8Str, std::map <Utf8Str, Utf8Str> >::const_iterator cit = mSections.begin(); 162 while (cit!=mSections.end()) 163 { 164 res.push_back(cit->first); 165 ++cit; 166 } 167 return res; 168 } 169 170 std::map <Utf8Str, Utf8Str> SimpleConfigFile::getSectionByName (const Utf8Str &strSectionName) const 171 { 172 std::map <Utf8Str, Utf8Str> res; 173 std::map < Utf8Str, std::map <Utf8Str, Utf8Str> >::const_iterator cit; 174 if ( (cit=mSections.find(strSectionName)) != mSections.end() ) 175 { 176 res=cit->second; 177 } 178 return res; 179 } 180 181 HRESULT SimpleConfigFile::updateSection (const Utf8Str &strSectionName, 182 const std::map <Utf8Str, Utf8Str> &newSection) 183 { 184 HRESULT hrc = S_OK; 185 std::map <Utf8Str, Utf8Str> oldSection = getSectionByName(strSectionName); 186 if (oldSection.empty()) 187 { 188 //add new section 189 hrc = addSection(strSectionName, newSection); 190 } 191 else 192 { 193 //update old section by new values or add new pair key/value if there isn't such key 194 std::map <Utf8Str, Utf8Str>::const_iterator cit = newSection.begin(); 195 while (cit != newSection.end()) 196 { 197 oldSection[cit->first] = cit->second; 198 ++cit; 199 } 200 201 } 202 return hrc; 203 } 204 205 bool SimpleConfigFile::isSectionExist(const Utf8Str &strSectionName) const 206 { 207 return ((mSections.find(strSectionName) == mSections.end()) ? false : true); 208 } 209 210 //////////////////////////////////////////////////////////////////////////////// 211 // 212 // ICloudProvider implementation 213 // 214 //////////////////////////////////////////////////////////////////////////////// 215 CloudProvider::CloudProvider() 216 : mParent(NULL) 217 { 218 } 219 220 CloudProvider::~CloudProvider() 221 { 222 LogRel(("CloudProvider::~CloudProvider()\n")); 223 unconst(mParent) = NULL; 224 } 225 226 HRESULT CloudProvider::FinalConstruct() 33 OCIProfile::OCIProfile() 34 : mVirtualBox(NULL), mParent(NULL) 35 { 36 } 37 38 OCIProfile::~OCIProfile() 39 { 40 LogRel(("OCIProfile::~OCIProfile()\n")); 41 unconst(mVirtualBox) = NULL; 42 unconst(mParent).setNull(); 43 } 44 45 HRESULT OCIProfile::FinalConstruct() 227 46 { 228 47 return BaseFinalConstruct(); 229 48 } 230 49 231 void CloudProvider::FinalRelease()50 void OCIProfile::FinalRelease() 232 51 { 233 52 uninit(); … … 236 55 } 237 56 238 void CloudProvider::uninit()239 { 240 / * Enclose the state transition Ready->InUninit->NotReady */57 void OCIProfile::uninit() 58 { 59 // Enclose the state transition Ready->InUninit->NotReady. 241 60 AutoUninitSpan autoUninitSpan(this); 242 61 if (autoUninitSpan.uninitDone()) 243 62 return; 244 63 245 unconst(mParent) = NULL; 246 } 247 248 HRESULT CloudProvider::init(VirtualBox *aParent) 249 { 250 /* Enclose the state transition NotReady->InInit->Ready */ 64 unconst(mVirtualBox) = NULL; 65 unconst(mParent).setNull(); 66 } 67 68 HRESULT OCIProfile::initFromConfig(VirtualBox *aVirtualBox, 69 OCIProvider *aParent, 70 const com::Utf8Str &aProfileName) 71 { 72 // Enclose the state transition NotReady->InInit->Ready. 251 73 AutoInitSpan autoInitSpan(this); 252 74 AssertReturn(autoInitSpan.isOk(), E_FAIL); 253 75 #ifndef VBOX_WITH_CLOUD_PROVIDERS_IN_EXTPACK 76 AssertReturn(aVirtualBox, E_INVALIDARG); 77 #endif 78 AssertReturn(aParent, E_INVALIDARG); 79 AssertReturn(!aProfileName.isEmpty(), E_INVALIDARG); 80 81 unconst(mVirtualBox) = aVirtualBox; 254 82 unconst(mParent) = aParent; 83 unconst(mName) = aProfileName; 255 84 256 85 autoInitSpan.setSucceeded(); … … 258 87 } 259 88 260 261 HRESULT CloudProvider::getSupportedPropertiesNames(std::vector<com::Utf8Str> &aPropertiesNames) 262 { 263 LogRel(("CloudProvider::getSupportedPropertiesNames:\n")); 264 aPropertiesNames.clear(); 265 return setErrorBoth(E_FAIL, VERR_NOT_IMPLEMENTED, tr("Not implemented")); 266 } 267 268 HRESULT CloudProvider::readProfiles(const Utf8Str &strConfigPath) 269 { 270 LogRel(("CloudProvider::readProfiles: %s\n", strConfigPath.c_str())); 271 return setErrorBoth(E_FAIL, VERR_NOT_IMPLEMENTED, tr("Not implemented")); 272 } 273 274 HRESULT CloudProvider::getProvider(CloudProviderId_T *aProvider) 275 { 276 *aProvider = CloudProviderId_Unknown; 277 LogRel(("CloudProvider::getProvider: %d\n", *aProvider)); 278 return setErrorBoth(E_FAIL, VERR_NOT_IMPLEMENTED, tr("Not implemented")); 279 } 280 281 HRESULT CloudProvider::createProfile(const com::Utf8Str &aProfileName, 282 const std::vector<com::Utf8Str> &aNames, 283 const std::vector<com::Utf8Str> &aValues) 284 { 285 LogRel(("CloudProvider::createProfile: %s, %d, %d\n", aProfileName.c_str(), aNames.size(), aValues.size())); 286 return setErrorBoth(E_FAIL, VERR_NOT_IMPLEMENTED, tr("Not implemented")); 287 } 288 289 HRESULT CloudProvider::updateProfile(const com::Utf8Str &aProfileName, 290 const std::vector<com::Utf8Str> &aNames, 291 const std::vector<com::Utf8Str> &aValues) 292 { 293 LogRel(("CloudProvider::updateProfile: %s, %d, %d\n", aProfileName.c_str(), aNames.size(), aValues.size())); 294 return setErrorBoth(E_FAIL, VERR_NOT_IMPLEMENTED, tr("Not implemented")); 295 } 296 297 HRESULT CloudProvider::getStoredProfilesNames(std::vector<com::Utf8Str> &aProfilesNames) 298 { 299 300 LogRel(("CloudProvider::getStoredProfilesNames:\n")); 301 aProfilesNames.clear(); 302 return setErrorBoth(E_FAIL, VERR_NOT_IMPLEMENTED, tr("Not implemented")); 303 } 304 305 HRESULT CloudProvider::getProfileProperties(const com::Utf8Str &aProfileName, 306 std::vector<com::Utf8Str> &aReturnNames, 307 std::vector<com::Utf8Str> &aReturnValues) 308 { 309 LogRel(("CloudProvider::getProfileProperties: %s\n", aProfileName.c_str())); 310 aReturnNames.clear(); 311 aReturnValues.clear(); 312 return setErrorBoth(E_FAIL, VERR_NOT_IMPLEMENTED, tr("Not implemented")); 313 } 314 315 HRESULT CloudProvider::getPropertyDescription(const com::Utf8Str &aName, 316 com::Utf8Str &aDescription) 317 { 318 LogRel(("CloudProvider::getPropertyDescription: %s, %s\n", aName.c_str(), aDescription.c_str())); 319 return setErrorBoth(E_FAIL, VERR_NOT_IMPLEMENTED, tr("Not implemented")); 320 } 321 322 HRESULT CloudProvider::createCloudClient(const com::Utf8Str &aProfileName, 323 ComPtr<ICloudClient> &aCloudClient) 324 { 325 LogRel(("CloudProvider::createCloudClient: %s\n", aProfileName.c_str())); 326 327 if (aCloudClient.isNull()) 328 { 329 LogRel(("aCloudClient is NULL\n")); 330 } 331 332 return setErrorBoth(E_FAIL, VERR_NOT_IMPLEMENTED, tr("Not implemented")); 333 } 334 335 //////////////////////////////////////////////////////////////////////////////// 336 // 337 // CloudConnectionOCI implementation 338 // 339 //////////////////////////////////////////////////////////////////////////////// 89 HRESULT OCIProfile::initNew(VirtualBox *aVirtualBox, 90 OCIProvider *aParent, 91 const com::Utf8Str &aProfileName, 92 const std::vector<com::Utf8Str> &aNames, 93 const std::vector<com::Utf8Str> &aValues) 94 { 95 // Enclose the state transition NotReady->InInit->Ready. 96 AutoInitSpan autoInitSpan(this); 97 AssertReturn(autoInitSpan.isOk(), E_FAIL); 98 #ifndef VBOX_WITH_CLOUD_PROVIDERS_IN_EXTPACK 99 AssertReturn(aVirtualBox, E_INVALIDARG); 100 #endif 101 AssertReturn(aParent, E_INVALIDARG); 102 AssertReturn(!aProfileName.isEmpty(), E_INVALIDARG); 103 104 unconst(mVirtualBox) = aVirtualBox; 105 unconst(mParent) = aParent; 106 unconst(mName) = aProfileName; 107 108 HRESULT hrc = S_OK; 109 if (!aParent->i_existsProfile(aProfileName)) 110 hrc = aParent->i_addProfile(aProfileName, aNames, aValues); 111 else 112 hrc = setError(E_FAIL, tr("Profile '%s' already exists"), aProfileName.c_str()); 113 114 if (SUCCEEDED(hrc)) 115 autoInitSpan.setSucceeded(); 116 return hrc; 117 } 118 119 void OCIProfile::i_getProfile(StringMap &aProfile) const 120 { 121 AutoCaller autoCaller(mParent); 122 if (FAILED(autoCaller.rc())) 123 return; 124 AutoReadLock plock(mParent COMMA_LOCKVAL_SRC_POS); 125 126 mParent->i_getProfileMap(mName, aProfile); 127 } 128 129 340 130 static struct 341 131 { … … 355 145 356 146 357 OCIUserProfiles::OCIUserProfiles() 358 { 359 LogRel(("OCIUserProfiles::OCIUserProfiles()\n")); 360 mpProfiles = new SimpleConfigFile(mParent); 361 LogRel(("Succeeded create SimpleConfigFile\n")); 362 } 363 364 OCIUserProfiles::~OCIUserProfiles() 365 { 366 LogRel(("OCIUserProfiles::~OCIUserProfiles()\n")); 367 if (mpProfiles) 368 delete mpProfiles; 369 } 370 371 HRESULT OCIUserProfiles::createCloudClient(const com::Utf8Str &aProfileName, 372 ComPtr<ICloudClient> &aCloudClient) 373 { 374 HRESULT hrc = S_OK; 375 CloudProviderId_T providerId; 376 hrc = getProvider(&providerId); 377 378 ComObjPtr<CloudClient> ptrCloudClient; 379 hrc = ptrCloudClient.createObject(); 380 if (SUCCEEDED(hrc)) 381 { 382 ComObjPtr<CloudClientOCI> ptrCloudClientOCI; 383 hrc = ptrCloudClientOCI.createObject(); 384 AutoReadLock wlock(this COMMA_LOCKVAL_SRC_POS); 385 hrc = ptrCloudClientOCI->initCloudClient(this, mParent, providerId, aProfileName); 386 if (SUCCEEDED(hrc)) 387 { 388 ptrCloudClient = ptrCloudClientOCI; 389 hrc = ptrCloudClient.queryInterfaceTo(aCloudClient.asOutParam()); 390 } 391 } 392 393 return hrc; 394 } 395 396 HRESULT OCIUserProfiles::readProfiles(const Utf8Str &strConfigPath) 397 { 398 LogRel(("Reading profiles from %s\n", strConfigPath.c_str())); 399 HRESULT hrc = S_OK; 400 if ( !strConfigPath.isEmpty() ) 401 { 402 mStrConfigPath = strConfigPath; 403 hrc = mpProfiles->read(mStrConfigPath); 404 if (SUCCEEDED(hrc)) 405 { 406 LogRel(("Successfully read the profiles from the config %s\n", mStrConfigPath.c_str())); 407 hrc = mpProfiles->parse(); 408 if (FAILED(hrc)) 409 { 410 return hrc; 411 } 412 LogRel(("Successfully parsed %d profiles\n", mpProfiles->getNumberOfSections())); 413 } 414 } 415 else 416 { 417 LogRel(("Empty path to config file\n")); 418 hrc = setErrorBoth(E_FAIL, VERR_INVALID_PARAMETER, tr("Empty path to config file")); 419 } 420 421 return hrc; 422 } 423 424 HRESULT OCIUserProfiles::createProfile(const com::Utf8Str &aProfileName, 425 const std::vector<com::Utf8Str> &aNames, 426 const std::vector<com::Utf8Str> &aValues) 427 { 428 HRESULT hrc = S_OK; 429 430 if (!mpProfiles->isSectionExist(aProfileName)) 431 { 432 std::map <Utf8Str, Utf8Str> newProfile; 433 434 for (size_t i=0;i<aNames.size();++i) 435 { 436 com::Utf8Str newValue = (i<aValues.size()) ? aValues.at(i) : ""; 437 newProfile[aNames.at(i)] = newValue; 438 } 439 440 hrc = mpProfiles->addSection(aProfileName, newProfile); 441 } 442 else 443 hrc = setErrorBoth(E_FAIL, VERR_ALREADY_EXISTS, tr("Profile '%s' has already exested"), aProfileName.c_str()); 444 445 return hrc; 446 } 447 448 HRESULT OCIUserProfiles::updateProfile(const com::Utf8Str &aProfileName, 449 const std::vector<com::Utf8Str> &aNames, 450 const std::vector<com::Utf8Str> &aValues) 451 { 452 HRESULT hrc = S_OK; 453 if (mpProfiles->isSectionExist(aProfileName)) 454 { 455 std::map <Utf8Str, Utf8Str> newProfile; 456 457 for (size_t i=0;i<aNames.size();++i) 458 { 459 com::Utf8Str newValue = (i<aValues.size()) ? aValues.at(i) : ""; 460 newProfile[aNames.at(i)] = newValue; 461 } 462 463 hrc = mpProfiles->updateSection(aProfileName, newProfile); 464 } 465 else 466 hrc = setErrorBoth(E_FAIL, VERR_NOT_FOUND, tr("Profile '%s' wasn't found"), aProfileName.c_str()); 467 468 return hrc; 469 } 470 471 HRESULT OCIUserProfiles::getStoredProfilesNames(std::vector<com::Utf8Str> &aProfilesNames) 472 { 473 HRESULT hrc = S_OK; 474 aProfilesNames = mpProfiles->getSectionsNames(); 475 if (aProfilesNames.empty()) 476 hrc = setErrorBoth(E_FAIL, VERR_NOT_FOUND, tr("There aren't any profiles in the config")); 477 478 return hrc; 479 } 480 481 HRESULT OCIUserProfiles::getProfileProperties(const com::Utf8Str &aProfileName, 482 std::vector<com::Utf8Str> &aReturnNames, 483 std::vector<com::Utf8Str> &aReturnValues) 484 { 485 HRESULT hrc = S_OK; 486 487 if (mpProfiles->isSectionExist(aProfileName)) 488 { 489 std::map <Utf8Str, Utf8Str> profile; 490 hrc = i_getProfileProperties(aProfileName, profile); 491 if (SUCCEEDED(hrc)) 492 { 493 aReturnNames.clear(); 494 aReturnValues.clear(); 495 std::map <Utf8Str, Utf8Str>::const_iterator cit = profile.begin(); 496 while (cit!=profile.end()) 497 { 498 aReturnNames.push_back(cit->first); 499 aReturnValues.push_back(cit->second); 500 ++cit; 501 } 502 } 503 } 504 else 505 hrc = setErrorBoth(E_FAIL, VERR_NOT_FOUND, tr("Profile '%s' wasn't found"), aProfileName.c_str()); 506 507 return hrc; 508 } 509 510 HRESULT OCIUserProfiles::getSupportedPropertiesNames(std::vector<com::Utf8Str> &aPropertiesNames) 511 { 512 HRESULT hrc = S_OK; 147 HRESULT OCIProfile::getName(com::Utf8Str &aName) 148 { 149 // mName is constant during life time, no need to lock. 150 aName = mName; 151 return S_OK; 152 } 153 154 HRESULT OCIProfile::getProviderId(com::Guid &aProviderId) 155 { 156 // provider id is constant during life time, no need to lock. 157 aProviderId = mParent->i_getId(); 158 return S_OK; 159 } 160 161 HRESULT OCIProfile::getSupportedPropertyNames(std::vector<com::Utf8Str> &aSupportedPropertyNames) 162 { 163 // g_aOCIConfigEntryToDescription is constant during life time, no need to lock. 513 164 for (size_t i = 0; i < RT_ELEMENTS(g_aOCIConfigEntryToDescription); ++i) 514 aPropertiesNames.push_back(g_aOCIConfigEntryToDescription[i].pszOCIConfigEntry); 515 return hrc; 516 } 517 518 HRESULT OCIUserProfiles::getPropertyDescription(const com::Utf8Str &aName, com::Utf8Str &aDescription) 519 { 520 HRESULT hrc = S_OK; 165 aSupportedPropertyNames.push_back(g_aOCIConfigEntryToDescription[i].pszOCIConfigEntry); 166 return S_OK; 167 } 168 169 HRESULT OCIProfile::getProperty(const com::Utf8Str &aName, 170 Utf8Str &aReturnValue) 171 { 172 AutoCaller autoCaller(mParent); 173 if (FAILED(autoCaller.rc())) 174 return autoCaller.rc(); 175 AutoReadLock alock(mParent COMMA_LOCKVAL_SRC_POS); 176 mParent->i_getProfileProperty(mName, aName, aReturnValue); 177 return S_OK; 178 } 179 180 HRESULT OCIProfile::setProperty(const com::Utf8Str &aName, 181 const com::Utf8Str &aValue) 182 { 183 AutoCaller autoCaller(mParent); 184 if (FAILED(autoCaller.rc())) 185 return autoCaller.rc(); 186 AutoWriteLock alock(mParent COMMA_LOCKVAL_SRC_POS); 187 mParent->i_updateProfileProperty(mName, aName, aValue); 188 return S_OK; 189 } 190 191 HRESULT OCIProfile::getProperties(const com::Utf8Str &aNames, 192 std::vector<com::Utf8Str> &aReturnNames, 193 std::vector<com::Utf8Str> &aReturnValues) 194 { 195 AutoCaller autoCaller(mParent); 196 if (FAILED(autoCaller.rc())) 197 return autoCaller.rc(); 198 AutoReadLock alock(mParent COMMA_LOCKVAL_SRC_POS); 199 /// @todo: implement name filtering (everywhere... lots of similar code in many places handling properties. */ 200 RT_NOREF(aNames); 201 mParent->i_getProfile(mName, aReturnNames, aReturnValues); 202 return S_OK; 203 } 204 205 HRESULT OCIProfile::setProperties(const std::vector<com::Utf8Str> &aNames, 206 const std::vector<com::Utf8Str> &aValues) 207 { 208 AutoCaller autoCaller(mParent); 209 if (FAILED(autoCaller.rc())) 210 return autoCaller.rc(); 211 AutoWriteLock alock(mParent COMMA_LOCKVAL_SRC_POS); 212 return mParent->i_updateProfile(mName, aNames, aValues); 213 } 214 215 HRESULT OCIProfile::getPropertyDescription(const com::Utf8Str &aName, com::Utf8Str &aDescription) 216 { 217 // g_aOCIConfigEntryToDescription is constant during life time, no need to lock. 521 218 for (size_t i = 0; i < RT_ELEMENTS(g_aOCIConfigEntryToDescription); ++i) 522 219 if (aName.contains(g_aOCIConfigEntryToDescription[i].pszOCIConfigEntry, Utf8Str::CaseInsensitive)) … … 524 221 aDescription = g_aOCIConfigEntryToDescription[i].pszDesciption; 525 222 } 223 return S_OK; 224 } 225 226 227 HRESULT OCIProfile::createCloudClient(ComPtr<ICloudClient> &aCloudClient) 228 { 229 ComObjPtr<CloudClientOCI> pCloudClientOCI; 230 HRESULT hrc = pCloudClientOCI.createObject(); 231 if (FAILED(hrc)) 232 return hrc; 233 hrc = pCloudClientOCI->initCloudClient(mVirtualBox, this); 234 if (SUCCEEDED(hrc)) 235 hrc = pCloudClientOCI.queryInterfaceTo(aCloudClient.asOutParam()); 236 526 237 return hrc; 527 238 } 528 529 530 HRESULT OCIUserProfiles::i_createProfile(const com::Utf8Str &aProfileName,531 const std::map <Utf8Str, Utf8Str> &aProfile)532 {533 HRESULT hrc = S_OK;534 535 hrc = mpProfiles->addSection(aProfileName, aProfile);536 537 return hrc;538 }539 540 HRESULT OCIUserProfiles::i_updateProfile(const com::Utf8Str &aProfileName,541 const std::map <Utf8Str, Utf8Str> &aProfile)542 {543 HRESULT hrc = S_OK;544 if (mpProfiles->isSectionExist(aProfileName))545 hrc = mpProfiles->updateSection(aProfileName, aProfile);546 else547 hrc = setErrorBoth(E_FAIL, VERR_NOT_FOUND, tr("Profile '%s' wasn't found"), aProfileName.c_str());548 549 550 return hrc;551 }552 553 HRESULT OCIUserProfiles::i_getProfileProperties(const com::Utf8Str &aProfileName,554 std::map <Utf8Str, Utf8Str> &aProfile)555 {556 HRESULT hrc = S_OK;557 std::map <Utf8Str, Utf8Str> defProfile = mpProfiles->getSectionByName("DEFAULT");558 std::map <Utf8Str, Utf8Str> reqProfile = mpProfiles->getSectionByName(aProfileName);559 560 std::map <Utf8Str, Utf8Str>::iterator itDefProfile = defProfile.begin();561 while (itDefProfile != defProfile.end())562 {563 std::map <Utf8Str, Utf8Str>::iterator itProfile = reqProfile.find(itDefProfile->first);564 if (itProfile == reqProfile.end())565 {566 //Add a key=value pair from defProfile into the reqProfile if the key doesn't exist in the reqProfile.567 reqProfile.insert(*itDefProfile);568 }569 ++itDefProfile;570 }571 572 if (!reqProfile.empty())573 aProfile = reqProfile;574 else575 hrc = setErrorBoth(E_FAIL, VERR_NOT_FOUND, tr("Profile '%s' wasn't found"), aProfileName.c_str());576 577 return hrc;578 }579 -
trunk/src/VBox/Main/src-server/UnattendedScript.cpp
r73505 r73716 196 196 return hrc; 197 197 } 198 199 #ifdef VBOX_WITH_UNATTENDED 198 200 199 201 ////////////////////////////////////////////////////////////////////////////////////////////////////// … … 636 638 } 637 639 640 #endif /* VBOX_WITH_UNATTENDED */ 641 638 642 639 643 ////////////////////////////////////////////////////////////////////////////////////////////////////// -
trunk/src/VBox/Main/src-server/VirtualBoxImpl.cpp
r73571 r73716 80 80 #include "Logging.h" 81 81 82 # include "Cloud UserProfileManagerImpl.h"82 # include "CloudProviderManagerImpl.h" 83 83 84 84 #include <QMTranslator.h> … … 300 300 #endif 301 301 302 /** The reference to the cloud provider manager singleton. */ 303 const ComObjPtr<CloudProviderManager> pCloudProviderManager; 304 302 305 /** The global autostart database for the user. */ 303 306 AutostartDb * const pAutostartDb; … … 472 475 473 476 /* create the system properties object, someone may need it too */ 474 unconst(m->pSystemProperties).createObject(); 475 rc = m->pSystemProperties->init(this); 477 rc = unconst(m->pSystemProperties).createObject(); 478 if (SUCCEEDED(rc)) 479 rc = m->pSystemProperties->init(this); 476 480 ComAssertComRCThrowRC(rc); 477 481 … … 545 549 if (SUCCEEDED(rc = unconst(m->pEventSource).createObject())) 546 550 rc = m->pEventSource->init(); 551 if (FAILED(rc)) throw rc; 552 553 /* cloud provider manager */ 554 rc = unconst(m->pCloudProviderManager).createObject(); 555 if (SUCCEEDED(rc)) 556 rc = m->pCloudProviderManager->init(this); 557 ComAssertComRCThrowRC(rc); 547 558 if (FAILED(rc)) throw rc; 548 559 } … … 807 818 * uninitializing (as for example, mSystemProperties which owns 808 819 * MediumFormat objects which Medium objects refer to) */ 820 if (m->pCloudProviderManager) 821 { 822 m->pCloudProviderManager->uninit(); 823 unconst(m->pCloudProviderManager).setNull(); 824 } 825 809 826 if (m->pSystemProperties) 810 827 { … … 826 843 } 827 844 #endif /* VBOX_WITH_RESOURCE_USAGE_API */ 845 846 #ifdef VBOX_WITH_EXTPACK 847 if (m->ptrExtPackManager) 848 { 849 m->ptrExtPackManager->uninit(); 850 unconst(m->ptrExtPackManager).setNull(); 851 } 852 #endif 828 853 829 854 LogFlowThisFunc(("Terminating the async event handler...\n")); … … 1235 1260 1236 1261 return S_OK; 1262 } 1263 1264 HRESULT VirtualBox::getCloudProviderManager(ComPtr<ICloudProviderManager> &aCloudProviderManager) 1265 { 1266 HRESULT hrc = m->pCloudProviderManager.queryInterfaceTo(aCloudProviderManager.asOutParam()); 1267 return hrc; 1237 1268 } 1238 1269 … … 1820 1851 } 1821 1852 1822 HRESULT VirtualBox::createCloudProviderManager(ComPtr<ICloudProviderManager> &aManager)1823 {1824 ComObjPtr<CloudProviderManager> ptrCloudProviderManager;1825 HRESULT hrc = ptrCloudProviderManager.createObject();1826 if (SUCCEEDED(hrc))1827 {1828 AutoReadLock wlock(this COMMA_LOCKVAL_SRC_POS);1829 hrc = ptrCloudProviderManager->init(this);1830 if (SUCCEEDED(hrc))1831 hrc = ptrCloudProviderManager.queryInterfaceTo(aManager.asOutParam());1832 }1833 return hrc;1834 }1835 1836 1853 HRESULT VirtualBox::createMedium(const com::Utf8Str &aFormat, 1837 1854 const com::Utf8Str &aLocation, … … 5197 5214 return rc; 5198 5215 #else 5199 NOREF(aN ame);5200 NOREF(aN atNetwork);5216 NOREF(aNetworkName); 5217 NOREF(aNetwork); 5201 5218 return E_NOTIMPL; 5202 5219 #endif … … 5233 5250 return rc; 5234 5251 #else 5235 NOREF(aName);5236 5252 NOREF(aNetworkName); 5253 NOREF(aNetwork); 5237 5254 return E_NOTIMPL; 5238 5255 #endif
Note:
See TracChangeset
for help on using the changeset viewer.