VirtualBox

Changeset 44970 in vbox


Ignore:
Timestamp:
Mar 11, 2013 9:59:05 AM (12 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
84190
Message:

Main/VirtualBoxClient: add method to perform VM error checking which simplifies client code
com/ErrorInfo: small bugfix (the object where the error information originated was always lost), added a way to inject whole error object structures which needed the bugfix
Frontends/VBoxSDL: sample code how to use the new method

Location:
trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/VBox/com/ErrorInfo.h

    r44528 r44970  
    55
    66/*
    7  * Copyright (C) 2006-2011 Oracle Corporation
     7 * Copyright (C) 2006-2013 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    445445
    446446    /**
     447     *  Constructs a new instance from an ErrorInfo object, to inject a full
     448     *  error info created elsewhere.
     449     *
     450     *  @param aInfo    @c true to prevent fetching error info and leave
     451     *                  the instance uninitialized.
     452     */
     453    ErrorInfoKeeper(const ErrorInfo &aInfo)
     454        : ErrorInfo(false), mForgot(false)
     455    {
     456        copyFrom(aInfo);
     457    }
     458
     459    /**
    447460     *  Destroys this instance and automatically calls #restore() which will
    448461     *  either restore error info fetched by the constructor or do nothing
  • trunk/src/VBox/Frontends/VBoxSDL/VBoxSDL.cpp

    r44528 r44970  
    55
    66/*
    7  * Copyright (C) 2006-2012 Oracle Corporation
     7 * Copyright (C) 2006-2013 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    14461446        else
    14471447        {
    1448             RTPrintf("Error: machine with the given ID not found!\n");
     1448            RTPrintf("Error: machine with the given name not found!\n");
     1449            RTPrintf("Check if this VM has been corrupted and is now inaccessible.");
    14491450            goto leave;
    14501451        }
     
    14541455    vrc = RTSemEventCreate(&g_EventSemSDLEvents);
    14551456    AssertReleaseRC(vrc);
     1457
     1458    rc = pVirtualBoxClient->CheckMachineError(pMachine);
     1459    if (FAILED(rc))
     1460    {
     1461        com::ErrorInfo info;
     1462        if (info.isFullAvailable())
     1463            PrintError("The VM has errors",
     1464                       info.getText().raw(), info.getComponent().raw());
     1465        else
     1466            RTPrintf("Failed to check for VM errors! No error information available (rc=%Rhrc).\n", rc);
     1467        goto leave;
     1468    }
    14561469
    14571470    rc = pMachine->LockMachine(pSession, LockType_VM);
  • trunk/src/VBox/Main/glue/ErrorInfo.cpp

    r44528 r44970  
    77
    88/*
    9  * Copyright (C) 2006-2011 Oracle Corporation
     9 * Copyright (C) 2006-2013 Oracle Corporation
    1010 *
    1111 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    266266    mIsBasicAvailable = gotSomething;
    267267    mIsFullAvailable = gotAll;
     268
     269    mErrorInfo = info;
    268270
    269271    AssertMsg(gotSomething, ("Nothing to fetch!\n"));
  • trunk/src/VBox/Main/idl/VirtualBox.xidl

    r44948 r44970  
    1828518285  <interface
    1828618286    name="IVirtualBoxClient" extends="$unknown"
    18287     uuid="5fe0bd48-1181-40d1-991f-3b02f269a823"
     18287    uuid="d191281f-b0cb-4d83-a8fa-0d9fd6ba234c"
    1828818288    wsmap="suppress"
    1828918289    >
     
    1831518315    </attribute>
    1831618316
     18317    <method name="checkMachineError">
     18318      <desc>
     18319        Perform error checking before using an <link to="IMachine"/> object.
     18320        Generally useful before starting a VM and all other uses. If anything
     18321        is not as it should be then this method will return an appropriate
     18322        error.
     18323      </desc>
     18324
     18325      <param name="machine" type="IMachine" dir="in">
     18326        <desc>The machine object to check.</desc>
     18327      </param>
     18328    </method>
    1831718329  </interface>
    1831818330
  • trunk/src/VBox/Main/include/VirtualBoxClientImpl.h

    r44529 r44970  
    66
    77/*
    8  * Copyright (C) 2010-2011 Oracle Corporation
     8 * Copyright (C) 2010-2013 Oracle Corporation
    99 *
    1010 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    6060    STDMETHOD(COMGETTER(Session))(ISession **aSession);
    6161    STDMETHOD(COMGETTER(EventSource))(IEventSource **aEventSource);
     62    STDMETHOD(CheckMachineError)(IMachine *aMachine);
    6263
    6364private:
  • trunk/src/VBox/Main/src-client/VirtualBoxClientImpl.cpp

    r44529 r44970  
    55
    66/*
    7  * Copyright (C) 2010-2011 Oracle Corporation
     7 * Copyright (C) 2010-2013 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    2121#include "VBoxEvents.h"
    2222#include "Logging.h"
     23#include "VBox/com/ErrorInfo.h"
    2324
    2425#include <iprt/asm.h>
     
    199200
    200201    return mData.m_pEventSource.isNull() ? E_FAIL : S_OK;
     202}
     203
     204/**
     205 * Checks a Machine object for any pending errors.
     206 *
     207 * @returns COM status code
     208 * @param   aMachine    Machine object to check.
     209 */
     210STDMETHODIMP VirtualBoxClient::CheckMachineError(IMachine *aMachine)
     211{
     212    HRESULT rc;
     213    CheckComArgNotNull(aMachine);
     214
     215    BOOL fAccessible = FALSE;
     216    rc = aMachine->COMGETTER(Accessible)(&fAccessible);
     217    if (FAILED(rc))
     218        return setError(rc, tr("Could not check the accessibility status of the VM"));
     219    else if (!fAccessible)
     220    {
     221        ComPtr<IVirtualBoxErrorInfo> pAccessError;
     222        rc = aMachine->COMGETTER(AccessError)(pAccessError.asOutParam());
     223        if (FAILED(rc))
     224            return setError(rc, tr("Could not get the access error message of the VM"));
     225        else
     226        {
     227            ErrorInfo info(pAccessError);
     228            ErrorInfoKeeper eik(info);
     229            return info.getResultCode();
     230        }
     231    }
     232    return S_OK;
    201233}
    202234
Note: See TracChangeset for help on using the changeset viewer.

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