VirtualBox

Changeset 91161 in vbox


Ignore:
Timestamp:
Sep 8, 2021 3:05:23 PM (4 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
146815
Message:

VBoxManageCloudMachine: Refactor to create cloud client once and pass
it around (previously we passed around the profile object instead).
bugref:10065.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VBoxManage/VBoxManageCloudMachine.cpp

    r91157 r91161  
    3434                              const ComPtr<ICloudProvider> &pProvider,
    3535                              const char *pszProviderName);
     36static int getCloudClient(ComPtr<ICloudClient> &aClient,
     37                          HandlerArg *a,
     38                          const char *pcszProviderName,
     39                          const char *pcszProfileName);
    3640
    3741static RTEXITCODE handleCloudMachineImpl(HandlerArg *a, int iFirst,
    38                                          const ComPtr<ICloudProfile> &pProfile);
     42                                         const ComPtr<ICloudClient> &pClient);
    3943
    4044static RTEXITCODE handleCloudMachineConsoleHistory(HandlerArg *a, int iFirst,
    41                                                    const ComPtr<ICloudProfile> &pProfile);
     45                                                   const ComPtr<ICloudClient> &pClient);
    4246static RTEXITCODE listCloudMachinesImpl(HandlerArg *a, int iFirst,
    43                                         const ComPtr<ICloudProfile> &pProfile);
     47                                        const ComPtr<ICloudClient> &pClient);
    4448static RTEXITCODE handleCloudMachineInfo(HandlerArg *a, int iFirst,
    45                                           const ComPtr<ICloudProfile> &pProfile);
     49                                          const ComPtr<ICloudClient> &pClient);
    4650
    4751static HRESULT printMachineInfo(const ComPtr<ICloudMachine> &pMachine);
     
    7074 * in handleCloud).
    7175 */
    72 static int
    73 getCloudProfile(ComPtr<ICloudProfile> &aProfile,
    74                 HandlerArg *a,
    75                 const char *pcszProviderName,
    76                 const char *pcszProfileName)
    77 {
    78     int rc;
    79 
    80     ComPtr<ICloudProvider> pProvider;
    81     rc = selectCloudProvider(pProvider, a->virtualBox, pcszProviderName);
    82     if (RT_FAILURE(rc))
    83         return rc;
    84 
    85     ComPtr<ICloudProfile> pProfile;
    86     rc = selectCloudProfile(pProfile, pProvider, pcszProfileName);
    87     if (RT_FAILURE(rc))
    88         return rc;
    89 
    90     aProfile = pProfile;
    91     return VINF_SUCCESS;
    92 }
    93 
    94 
    9576RTEXITCODE
    9677handleCloudMachine(HandlerArg *a, int iFirst,
     
    9879                   const char *pcszProfileName)
    9980{
    100     ComPtr<ICloudProfile> pProfile;
    101     int rc = getCloudProfile(pProfile, a, pcszProviderName, pcszProfileName);
     81    ComPtr<ICloudClient> pClient;
     82    int rc = getCloudClient(pClient, a, pcszProviderName, pcszProfileName);
    10283    if (RT_FAILURE(rc))
    10384        return RTEXITCODE_FAILURE;
    10485
    105     return handleCloudMachineImpl(a, iFirst, pProfile);
     86    return handleCloudMachineImpl(a, iFirst, pClient);
    10687}
    10788
     
    235216
    236217
     218static int
     219getCloudClient(ComPtr<ICloudClient> &aCloudClient,
     220                HandlerArg *a,
     221                const char *pcszProviderName,
     222                const char *pcszProfileName)
     223{
     224    HRESULT hrc;
     225    int rc;
     226
     227    ComPtr<ICloudProvider> pProvider;
     228    rc = selectCloudProvider(pProvider, a->virtualBox, pcszProviderName);
     229    if (RT_FAILURE(rc))
     230        return rc;
     231
     232    ComPtr<ICloudProfile> pProfile;
     233    rc = selectCloudProfile(pProfile, pProvider, pcszProfileName);
     234    if (RT_FAILURE(rc))
     235        return rc;
     236
     237    ComPtr<ICloudClient> pCloudClient;
     238    CHECK_ERROR2_RET(hrc, pProfile,
     239        CreateCloudClient(pCloudClient.asOutParam()),
     240            VERR_GENERAL_FAILURE);
     241
     242    aCloudClient = pCloudClient;
     243    return VINF_SUCCESS;
     244}
     245
     246
    237247static HRESULT
    238248getMachineById(ComPtr<ICloudMachine> &pMachineOut,
    239                const ComPtr<ICloudProfile> &pProfile,
     249               const ComPtr<ICloudClient> &pClient,
    240250               const char *pcszStrId)
    241251{
    242252    HRESULT hrc;
    243253
    244     ComPtr<ICloudClient> pCloudClient;
    245     CHECK_ERROR2_RET(hrc, pProfile,
    246         CreateCloudClient(pCloudClient.asOutParam()), hrc);
    247 
    248254    ComPtr<ICloudMachine> pMachine;
    249     CHECK_ERROR2_RET(hrc, pCloudClient,
     255    CHECK_ERROR2_RET(hrc, pClient,
    250256        GetCloudMachine(com::Bstr(pcszStrId).raw(),
    251257                        pMachine.asOutParam()), hrc);
     
    284290static RTEXITCODE
    285291handleCloudMachineImpl(HandlerArg *a, int iFirst,
    286                        const ComPtr<ICloudProfile> &pProfile)
     292                       const ComPtr<ICloudClient> &pClient)
    287293{
    288294    /*
     
    325331        {
    326332            case kMachine_ConsoleHistory:
    327                 return handleCloudMachineConsoleHistory(a, OptState.iNext, pProfile);
     333                return handleCloudMachineConsoleHistory(a, OptState.iNext, pClient);
    328334
    329335            case kMachine_Info:
    330                 return handleCloudMachineInfo(a, OptState.iNext, pProfile);
     336                return handleCloudMachineInfo(a, OptState.iNext, pClient);
    331337
    332338            case kMachine_List:
    333                 return listCloudMachinesImpl(a, OptState.iNext, pProfile);
     339                return listCloudMachinesImpl(a, OptState.iNext, pClient);
    334340
    335341
     
    368374    int rc;
    369375
    370     ComPtr<ICloudProvider> pProvider;
    371     rc = selectCloudProvider(pProvider, a->virtualBox, pcszProviderName);
     376    ComPtr<ICloudClient> pClient;
     377    rc = getCloudClient(pClient, a, pcszProviderName, pcszProfileName);
    372378    if (RT_FAILURE(rc))
    373379        return RTEXITCODE_FAILURE;
    374380
    375     ComPtr<ICloudProfile> pProfile;
    376     rc = selectCloudProfile(pProfile, pProvider, pcszProfileName);
    377     if (RT_FAILURE(rc))
    378         return RTEXITCODE_FAILURE;
    379 
    380     return listCloudMachinesImpl(a, iFirst, pProfile);
     381    return listCloudMachinesImpl(a, iFirst, pClient);
    381382}
    382383
     
    388389static RTEXITCODE
    389390listCloudMachinesImpl(HandlerArg *a, int iFirst,
    390                       const ComPtr<ICloudProfile> &pProfile)
     391                      const ComPtr<ICloudClient> &pClient)
    391392{
    392393    /*
     
    448449    }
    449450
    450     ComPtr<ICloudClient> pClient;
    451     CHECK_ERROR2_RET(hrc, pProfile,
    452         CreateCloudClient(pClient.asOutParam()),
    453             RTEXITCODE_FAILURE);
    454 
    455451    ComPtr<IProgress> pListProgress;
    456452    CHECK_ERROR2_RET(hrc, pClient,
     
    554550                      const char *pcszProfileName)
    555551{
    556     ComPtr<ICloudProfile> pProfile;
    557     int rc = getCloudProfile(pProfile, a, pcszProviderName, pcszProfileName);
     552    int rc;
     553
     554    ComPtr<ICloudClient> pClient;
     555    rc = getCloudClient(pClient, a, pcszProviderName, pcszProfileName);
    558556    if (RT_FAILURE(rc))
    559557        return RTEXITCODE_FAILURE;
    560558
    561     return handleCloudMachineInfo(a, iFirst, pProfile);
     559    return handleCloudMachineInfo(a, iFirst, pClient);
    562560}
    563561
     
    568566static RTEXITCODE
    569567handleCloudMachineInfo(HandlerArg *a, int iFirst,
    570                        const ComPtr<ICloudProfile> &pProfile)
     568                       const ComPtr<ICloudClient> &pClient)
    571569{
    572570    HRESULT hrc;
     
    584582    {
    585583        ComPtr<ICloudMachine> pMachine;
    586         hrc = getMachineById(pMachine, pProfile, a->argv[i]);
     584        hrc = getMachineById(pMachine, pClient, a->argv[i]);
    587585        if (FAILED(hrc))
    588586            return RTEXITCODE_FAILURE;
     
    831829static RTEXITCODE
    832830handleCloudMachineConsoleHistory(HandlerArg *a, int iFirst,
    833                                  const ComPtr<ICloudProfile> &pProfile)
     831                                 const ComPtr<ICloudClient> &pClient)
    834832{
    835833    HRESULT hrc;
     
    852850
    853851    ComPtr<ICloudMachine> pMachine;
    854     hrc = getMachineById(pMachine, pProfile, a->argv[iFirst]);
     852    hrc = getMachineById(pMachine, pClient, a->argv[iFirst]);
    855853    if (FAILED(hrc))
    856854        return RTEXITCODE_FAILURE;
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette