VirtualBox

Changeset 94704 in vbox


Ignore:
Timestamp:
Apr 25, 2022 10:28:46 AM (3 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
151077
Message:

Main/Update check: Implemented and expose update agent events. ​​bugref:7983

Location:
trunk/src/VBox/Main
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/idl/VirtualBox.xidl

    r94700 r94704  
    1134511345  <interface
    1134611346    name="IUpdateAgent" extends="$unknown"
    11347     uuid="d6c683f2-489e-4701-aa6a-d490f7bc0d7e"
     11347    uuid="4cef7347-ed89-470b-9ac2-524ae889e17c"
    1134811348    wsmap="managed"
    1134911349    reservedMethods="2" reservedAttributes="4"
     
    1140111401      <desc>
    1140211402        Name of the update component.
     11403      </desc>
     11404    </attribute>
     11405
     11406    <attribute name="eventSource" type="IEventSource" readonly="yes">
     11407      <desc>
     11408        Event source for update agent events.
    1140311409      </desc>
    1140411410    </attribute>
     
    1155111557    </desc>
    1155211558    <attribute name="midlDoesNotLikeEmptyInterfaces" readonly="yes" type="boolean"/>
    11553   </interface>
    11554 
    11555   <interface
    11556     name="IUpdateAgentEvent" extends="$unknown"
    11557     uuid="aa1987dc-6402-4e3c-a0e9-68e87d301a83"
    11558     wsmap="managed"
    11559     reservedAttributes="4"
    11560     >
    11561     <desc>
    11562       Abstract base interface for update agent events.
    11563     </desc>
    11564 
    11565     <attribute name="eventSource" type="IEventSource" readonly="yes">
    11566       <desc>
    11567         Event source for update agent events.
    11568       </desc>
    11569     </attribute>
    11570 
    11571   </interface>
    11572 
    11573   <interface
    11574     name="IUpdateAgentSettingsChangedEvent" extends="IUpdateAgentEvent"
    11575     uuid="a3537480-a15f-404c-b540-abae5f6b25a0"
    11576     wsmap="managed"
    11577     reservedAttributes="4"
    11578     >
    11579     <desc>
    11580       Notification when update agent settings have been changed.
    11581     </desc>
    11582   </interface>
    11583 
    11584   <interface
    11585     name="IUpdateAgentErrorEvent" extends="IUpdateAgentEvent"
    11586     uuid="2dad1ad8-78be-441d-b4fa-9cff25ee16b2"
    11587     wsmap="managed"
    11588     reservedAttributes="4"
    11589     >
    11590     <desc>
    11591       Notification when an update agent error occurred.
    11592     </desc>
    11593 
    11594     <attribute name="msg" type="wstring" readonly="yes">
    11595       <desc>
    11596         Error message in human readable format.
    11597       </desc>
    11598     </attribute>
    11599 
    11600     <attribute name="rcError" type="long" readonly="yes">
    11601       <desc>
    11602         IPRT-style error code.
    11603       </desc>
    11604     </attribute>
    11605 
    11606   </interface>
    11607 
    11608   <interface
    11609     name="IUpdateAgentAvailableEvent" extends="IUpdateAgentEvent"
    11610     uuid="7b931bfa-3b2b-4220-87ce-86cb0dee7ed1"
    11611     wsmap="managed"
    11612     reservedAttributes="4"
    11613     >
    11614     <desc>
    11615       Notification when an update is available.
    11616     </desc>
    11617 
    11618     <attribute name="version" type="wstring" readonly="yes">
    11619       <desc>
    11620         Version of the update.
    11621       </desc>
    11622     </attribute>
    11623 
    11624     <attribute name="channel" type="UpdateChannel" readonly="yes">
    11625       <desc>
    11626         Channel containing the update.
    11627       </desc>
    11628     </attribute>
    11629 
    11630     <attribute name="severity" type="UpdateSeverity" readonly="yes">
    11631       <desc>
    11632         Severity of the update.
    11633       </desc>
    11634     </attribute>
    11635 
    11636     <attribute name="downloadURL" type="wstring" readonly="yes">
    11637       <desc>
    11638         Download URL of the update.
    11639       </desc>
    11640     </attribute>
    11641 
    11642     <attribute name="webURL" type="wstring" readonly="yes">
    11643       <desc>
    11644         Web URL of the update.
    11645       </desc>
    11646     </attribute>
    11647 
    11648     <attribute name="releaseNotes" type="wstring" readonly="yes">
    11649       <desc>
    11650         Release notes of the update.
    11651       </desc>
    11652     </attribute>
    11653 
    11654   </interface>
    11655 
    11656   <interface
    11657     name="IUpdateAgentStateChangedEvent" extends="IUpdateAgentEvent"
    11658     uuid="7da1b997-10ea-4690-99ff-df78bf309164"
    11659     wsmap="managed"
    11660     reservedAttributes="4"
    11661     >
    11662     <desc>
    11663       Notification when an update agent state has been changed.
    11664     </desc>
    11665 
    11666     <attribute name="state" type="UpdateState" readonly="yes">
    11667       <desc>
    11668         New update agent state.
    11669       </desc>
    11670     </attribute>
    11671 
    1167211559  </interface>
    1167311560
     
    2573725624  <enum
    2573825625    name="VBoxEventType"
    25739     uuid="c88a66ed-fbce-4c21-9196-12354bd96b89"
     25626    uuid="08cc6ebb-1e55-4b78-8fb1-1e06f5b4dbe9"
    2574025627    >
    2574125628
     
    2620126088      </desc>
    2620226089    </const>
     26090    <const name="OnUpdateAgentAvailable" value="112">
     26091      <desc>
     26092        See <link to="IUpdateAgentAvailableEvent">IUpdateAgentAvailableEvent</link>.
     26093      </desc>
     26094    </const>
     26095    <const name="OnUpdateAgentError" value="113">
     26096      <desc>
     26097        See <link to="IUpdateAgentErrorEvent">IUpdateAgentErrorEvent</link>.
     26098      </desc>
     26099    </const>
     26100    <const name="OnUpdateAgentSettingsChanged" value="114">
     26101      <desc>
     26102        See <link to="IUpdateAgentSettingsChangedEvent">IUpdateAgentSettingsChangedEvent</link>.
     26103      </desc>
     26104    </const>
     26105    <const name="OnUpdateAgentStateChanged" value="115">
     26106      <desc>
     26107        See <link to="IUpdateAgentStateChangedEvent">IUpdateAgentStateChangedEvent</link>.
     26108      </desc>
     26109    </const>
    2620326110    <!-- End event marker -->
    2620426111    <!-- @todo rename to 'End' as it is exclusive (we use 'last' to be inclusive). -->
    26205     <const name="Last" value="112">
     26112    <const name="Last" value="116">
    2620626113      <desc>
    2620726114        Must be last event, used for iterations and structures relying on numerical event values.
     
    2838128288      <desc>The virtual display output on which the monitor has changed.</desc>
    2838228289    </attribute>
     28290  </interface>
     28291
     28292  <interface
     28293    name="IUpdateAgentEvent" extends="IEvent"
     28294    uuid="0e33366a-670e-4e1f-9ddc-41c8a346cafd"
     28295    wsmap="managed">
     28296    <desc>
     28297      Abstract base interface for update agent events.
     28298    </desc>
     28299    <attribute name="midlDoesNotLikeEmptyInterfaces" readonly="yes" type="boolean"/>
     28300  </interface>
     28301
     28302  <interface
     28303    name="IUpdateAgentSettingsChangedEvent" extends="IUpdateAgentEvent"
     28304    uuid="abef51ae-1493-49f4-aa03-efaf106bf086"
     28305    wsmap="managed" autogen="VBoxEvent" id="OnUpdateAgentSettingsChanged"
     28306    >
     28307    <desc>
     28308      Notification when update agent settings have been changed.
     28309    </desc>
     28310    <attribute name="attributeHint" readonly="yes" type="wstring"/>
     28311  </interface>
     28312
     28313  <interface
     28314    name="IUpdateAgentErrorEvent" extends="IUpdateAgentEvent"
     28315    uuid="2a88033d-82db-4ac2-97b5-e786c839420e"
     28316    wsmap="managed" autogen="VBoxEvent" id="OnUpdateAgentError"
     28317    >
     28318    <desc>
     28319      Notification when an update agent error occurred.
     28320    </desc>
     28321
     28322    <attribute name="msg" type="wstring" readonly="yes">
     28323      <desc>
     28324        Error message in human readable format.
     28325      </desc>
     28326    </attribute>
     28327
     28328    <attribute name="rcError" type="long" readonly="yes">
     28329      <desc>
     28330        IPRT-style error code.
     28331      </desc>
     28332    </attribute>
     28333
     28334  </interface>
     28335
     28336  <interface
     28337    name="IUpdateAgentAvailableEvent" extends="IUpdateAgentEvent"
     28338    uuid="243829cb-15b7-42a4-8664-7aa4e34993da"
     28339    wsmap="managed" autogen="VBoxEvent" id="OnUpdateAgentAvailable"
     28340    >
     28341    <desc>
     28342      Notification when an update is available.
     28343    </desc>
     28344
     28345    <attribute name="version" type="wstring" readonly="yes">
     28346      <desc>
     28347        Version of the update.
     28348      </desc>
     28349    </attribute>
     28350
     28351    <attribute name="channel" type="UpdateChannel" readonly="yes">
     28352      <desc>
     28353        Channel containing the update.
     28354      </desc>
     28355    </attribute>
     28356
     28357    <attribute name="severity" type="UpdateSeverity" readonly="yes">
     28358      <desc>
     28359        Severity of the update.
     28360      </desc>
     28361    </attribute>
     28362
     28363    <attribute name="downloadURL" type="wstring" readonly="yes">
     28364      <desc>
     28365        Download URL of the update.
     28366      </desc>
     28367    </attribute>
     28368
     28369    <attribute name="webURL" type="wstring" readonly="yes">
     28370      <desc>
     28371        Web URL of the update.
     28372      </desc>
     28373    </attribute>
     28374
     28375    <attribute name="releaseNotes" type="wstring" readonly="yes">
     28376      <desc>
     28377        Release notes of the update.
     28378      </desc>
     28379    </attribute>
     28380
     28381  </interface>
     28382
     28383  <interface
     28384    name="IUpdateAgentStateChangedEvent" extends="IUpdateAgentEvent"
     28385    uuid="eb000a0e-2079-4f47-bbcc-c6b28a4e50df"
     28386    wsmap="managed" autogen="VBoxEvent" id="OnUpdateAgentStateChanged"
     28387    >
     28388    <desc>
     28389      Notification when an update agent state has been changed.
     28390    </desc>
     28391
     28392    <attribute name="state" type="UpdateState" readonly="yes">
     28393      <desc>
     28394        New update agent state.
     28395      </desc>
     28396    </attribute>
     28397
    2838328398  </interface>
    2838428399
  • trunk/src/VBox/Main/include/UpdateAgentImpl.h

    r94702 r94704  
    2626#include <VBox/settings.h>
    2727
     28#include "EventImpl.h"
    2829#include "UpdateAgentWrap.h"
    2930#include "HostUpdateAgentWrap.h"
     
    4950        , m(new settings::UpdateAgent) { }
    5051
    51     virtual ~UpdateAgentBase() { }
     52    virtual ~UpdateAgentBase() { delete m; }
    5253
    5354public:
     
    7778
    7879protected:
    79     VirtualBox * const m_VirtualBox;
     80    /** The update agent's event source. */
     81    const ComObjPtr<EventSource> m_EventSource;
     82    VirtualBox * const           m_VirtualBox;
    8083
    8184    /** @name Data members.
     
    132135     * @{ */
    133136    HRESULT i_commitSettings(AutoWriteLock &aLock);
     137    HRESULT i_reportError(int vrc, const char *pcszMsgFmt, ...);
    134138    /** @}  */
    135139
     
    143147
    144148    HRESULT getName(com::Utf8Str &aName);
     149    HRESULT getEventSource(ComPtr<IEventSource> &aEventSource);
    145150    HRESULT getOrder(ULONG *aOrder);
    146151    HRESULT getDependsOn(std::vector<com::Utf8Str> &aDeps);
  • trunk/src/VBox/Main/src-server/UpdateAgentImpl.cpp

    r94702 r94704  
    4141#include "LoggingNew.h"
    4242#include "VirtualBoxImpl.h"
     43#include "VBoxEvents.h"
    4344#include "ThreadTask.h"
    44 #include "SystemPropertiesImpl.h"
    4545#include "VirtualBoxBase.h"
    4646
     
    275275UpdateAgent::~UpdateAgent()
    276276{
    277     delete m;
    278 }
    279 
    280 HRESULT UpdateAgent::FinalConstruct()
     277}
     278
     279HRESULT UpdateAgent::FinalConstruct(void)
    281280{
    282281    return BaseFinalConstruct();
    283282}
    284283
    285 void UpdateAgent::FinalRelease()
     284void UpdateAgent::FinalRelease(void)
    286285{
    287286    uninit();
     
    299298    unconst(m_VirtualBox) = aVirtualBox;
    300299
    301     autoInitSpan.setSucceeded();
    302     return S_OK;
    303 }
    304 
    305 void UpdateAgent::uninit()
     300    HRESULT hr = unconst(m_EventSource).createObject();
     301    if (SUCCEEDED(hr))
     302    {
     303        hr = m_EventSource->init();
     304        if (SUCCEEDED(hr))
     305            autoInitSpan.setSucceeded();
     306    }
     307
     308    return hr;
     309}
     310
     311void UpdateAgent::uninit(void)
    306312{
    307313    // Enclose the state transition Ready->InUninit->NotReady.
     
    309315    if (autoUninitSpan.uninitDone())
    310316        return;
     317
     318    unconst(m_EventSource).setNull();
    311319}
    312320
     
    343351    aName = mData.m_strName;
    344352
     353    return S_OK;
     354}
     355
     356HRESULT UpdateAgent::getEventSource(ComPtr<IEventSource> &aEventSource)
     357{
     358    LogFlowThisFuncEnter();
     359
     360    /* No need to lock - lifetime constant. */
     361    m_EventSource.queryInterfaceTo(aEventSource.asOutParam());
     362
     363    LogFlowFuncLeaveRC(S_OK);
    345364    return S_OK;
    346365}
     
    706725    aLock.release();
    707726
     727    ::FireUpdateAgentSettingsChangedEvent(m_EventSource, "" /** @todo Include attribute hints */);
     728
    708729    AutoWriteLock vboxLock(m_VirtualBox COMMA_LOCKVAL_SRC_POS);
    709730    return m_VirtualBox->i_saveSettings();
     731}
     732
     733/**
     734 * Reports an error by setting the error info and also information subscribed listeners.
     735 *
     736 * @returns HRESULT
     737 * @param   vrc                 Result code (IPRT-style) to report.
     738 * @param   pcszMsgFmt          Error message to report.
     739 * @param   ...                 Format string for \a pcszMsgFmt.
     740 */
     741HRESULT UpdateAgent::i_reportError(int vrc, const char *pcszMsgFmt, ...)
     742{
     743    va_list va;
     744    va_start(va, pcszMsgFmt);
     745
     746     char *psz = NULL;
     747     if (RTStrAPrintfV(&psz, pcszMsgFmt, va) <= 0)
     748         return E_OUTOFMEMORY;
     749
     750     LogRel(("Update agent (%s): %s\n", mData.m_strName.c_str(), psz));
     751
     752     ::FireUpdateAgentErrorEvent(m_EventSource, psz, vrc);
     753
     754     HRESULT const rc = setErrorVrc(vrc, pcszMsgFmt, va);
     755
     756     va_end(va);
     757     RTStrFree(psz);
     758
     759     return rc;
    710760}
    711761
     
    897947    }
    898948    else
    899         rc = setErrorVrc(vrc, tr("Update agent (%s): RTHttpCreate() failed: %Rrc"), mData.m_strName.c_str(), vrc);
     949        rc = i_reportError(vrc, tr("RTHttpCreate() failed: %Rrc"), vrc);
    900950
    901951    return rc;
     
    915965    int vrc = RTHttpAddHeader(hHttp, "User-Agent", strUserAgent.c_str(), strUserAgent.length(), RTHTTPADDHDR_F_BACK);
    916966    if (RT_FAILURE(vrc))
    917         return setErrorVrc(vrc, tr("Update agent (%s): RTHttpAddHeader() failed: %Rrc (on User-Agent)"),
    918                                    mData.m_strName.c_str(), vrc);
     967        return i_reportError(vrc, tr("RTHttpAddHeader() failed: %Rrc (user agent)"), vrc);
    919968
    920969    /*
     
    925974        vrc = RTHttpSetProxyByUrl(hHttp, m->strProxyUrl.c_str());
    926975        if (RT_FAILURE(vrc))
    927             return setErrorVrc(vrc, tr("Update agent (%s): RTHttpSetProxyByUrl() failed: %Rrc"), mData.m_strName.c_str(), vrc);
     976            return i_reportError(vrc, tr("RTHttpSetProxyByUrl() failed: %Rrc"), vrc);
    928977    }
    929978    else if (m->enmProxyMode == ProxyMode_System)
     
    931980        vrc = RTHttpUseSystemProxySettings(hHttp);
    932981        if (RT_FAILURE(vrc))
    933             return setErrorVrc(vrc, tr("Update agent (%s): RTHttpUseSystemProxySettings() failed: %Rrc"),
    934                                        mData.m_strName.c_str(), vrc);
     982            return i_reportError(vrc, tr("RTHttpUseSystemProxySettings() failed: %Rrc"), vrc);
    935983    }
    936984    else
     
    944992    vrc = RTHttpGetBinary(hHttp, strUrl.c_str(), &pvResponse, &cbResponse);
    945993    if (RT_FAILURE(vrc))
    946         return setErrorVrc(vrc, tr("Update agent (%s): RTHttpGetBinary() failed: %Rrc"), mData.m_strName.c_str(), vrc);
     994        return i_reportError(vrc, tr("RTHttpGetBinary() failed: %Rrc"), vrc);
    947995
    948996    /* Note! We can do nothing that might throw exceptions till we call RTHttpFreeResponse! */
     
    9731021    HRESULT rc;
    9741022
    975     AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
    976 
    9771023    /* Decode the two word: */
    9781024    static char const s_szUpToDate[] = "UPTODATE";
     
    9801026        && memcmp(pchWord0, s_szUpToDate, sizeof(s_szUpToDate) - 1) == 0)
    9811027    {
     1028        AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
     1029
    9821030        mData.m_enmState = UpdateState_NotAvailable;
    9831031        rc = S_OK;
     1032
     1033        alock.release(); /* Release lock before firing off event. */
     1034
     1035        ::FireUpdateAgentStateChangedEvent(m_EventSource, UpdateState_NotAvailable);
    9841036    }
    9851037    else
     
    9971049                rc = mData.m_lastResult.strDownloadUrl.assignEx(pchWord1, cchWord1);
    9981050
    999             if (RT_SUCCESS(vrc))
     1051            if (SUCCEEDED(rc))
    10001052            {
     1053                AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
     1054
    10011055                /** @todo Implement this on the backend first.
    10021056                 *        We also could do some guessing based on the installed version vs. reported update version? */
    10031057                mData.m_lastResult.enmSeverity = UpdateSeverity_Invalid;
    10041058                mData.m_enmState               = UpdateState_Available;
     1059
     1060                alock.release(); /* Release lock before firing off events. */
     1061
     1062                ::FireUpdateAgentStateChangedEvent(m_EventSource, UpdateState_Available);
     1063                ::FireUpdateAgentAvailableEvent(m_EventSource, mData.m_lastResult.strVer, m->enmChannel,
     1064                                                mData.m_lastResult.enmSeverity, mData.m_lastResult.strDownloadUrl,
     1065                                                mData.m_lastResult.strWebUrl, mData.m_lastResult.strReleaseNotes);
    10051066            }
     1067            else
     1068                rc = i_reportError(VERR_GENERAL_FAILURE /** @todo Use a better rc */,
     1069                                   tr("Invalid server response [1]: %Rhrc (%.*Rhxs -- %.*Rhxs)"),
     1070                                   rc, cchWord0, pchWord0, cchWord1, pchWord1);
    10061071
    10071072            LogRel(("Update agent (%s): HTTP server replied: %.*s %.*s\n",
     
    10091074        }
    10101075        else
    1011             rc = setErrorVrc(vrc, tr("Update agent (%s): Invalid server response: %Rrc (%.*Rhxs -- %.*Rhxs)"),
    1012                              mData.m_strName.c_str(), vrc, cchWord0, pchWord0, cchWord1, pchWord1);
     1076            rc = i_reportError(vrc, tr("Invalid server response [2]: %Rrc (%.*Rhxs -- %.*Rhxs)"),
     1077                               vrc, cchWord0, pchWord0, cchWord1, pchWord1);
    10131078    }
    10141079
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