VirtualBox

Changeset 94700 in vbox for trunk/src/VBox/Main


Ignore:
Timestamp:
Apr 25, 2022 7:53:34 AM (3 years ago)
Author:
vboxsync
Message:

Main/Update check: Also expose IUpdateAgent::isCheckNeeded() in base class (as a convenience function). ​​bugref:7983

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

Legend:

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

    r94684 r94700  
    1134511345  <interface
    1134611346    name="IUpdateAgent" extends="$unknown"
    11347     uuid="ca37acc8-420f-4c17-8131-04f07e5834c5"
     11347    uuid="d6c683f2-489e-4701-aa6a-d490f7bc0d7e"
    1134811348    wsmap="managed"
    1134911349    reservedMethods="2" reservedAttributes="4"
     
    1152811528      </desc>
    1152911529    </attribute>
     11530
     11531    <attribute name="isCheckNeeded" type="boolean" readonly="yes">
     11532      <desc>
     11533        Returns @c TRUE if an update check is needed, or @c FALSE if not.
     11534
     11535        <note>Compares the system's current date with the last
     11536          update check date and currently set check frequency.</note>
     11537      </desc>
     11538    </attribute>
     11539
    1153011540  </interface>
    1153111541
  • trunk/src/VBox/Main/include/UpdateAgentImpl.h

    r94685 r94700  
    165165    HRESULT setProxyURL(const com::Utf8Str &aAddress);
    166166    HRESULT getLastCheckDate(com::Utf8Str &aData);
     167    HRESULT getIsCheckNeeded(BOOL *aCheckNeeded);
    167168    /** @} */
    168169};
  • trunk/src/VBox/Main/src-server/UpdateAgentImpl.cpp

    r94686 r94700  
    370370
    371371    aDate = m->strLastCheckDate;
     372
     373    return S_OK;
     374}
     375
     376HRESULT UpdateAgent::getIsCheckNeeded(BOOL *aCheckNeeded)
     377{
     378    AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
     379
     380    /*
     381     * Is update checking enabled at all?
     382     */
     383    if (!m->fEnabled)
     384    {
     385        *aCheckNeeded = FALSE;
     386        return S_OK;
     387    }
     388
     389    /*
     390     * When was the last update?
     391     */
     392    if (m->strLastCheckDate.isEmpty()) /* No prior update check performed -- do so now. */
     393    {
     394        *aCheckNeeded = TRUE;
     395        return S_OK;
     396    }
     397
     398    RTTIMESPEC LastCheckTime;
     399    if (!RTTimeSpecFromString(&LastCheckTime, Utf8Str(m->strLastCheckDate).c_str()))
     400    {
     401        *aCheckNeeded = TRUE; /* Invalid date set or error? Perform check. */
     402        return S_OK;
     403    }
     404
     405    /*
     406     * Compare last update with how often we are supposed to check for updates.
     407     */
     408    if (   !m->uCheckFreqSeconds                /* Paranoia */
     409        ||  m->uCheckFreqSeconds < RT_SEC_1DAY) /* This is the minimum we currently allow. */
     410    {
     411        /* Consider config (enable, 0 day interval) as checking once but never again.
     412           We've already check since we've got a date. */
     413        *aCheckNeeded = FALSE;
     414        return S_OK;
     415    }
     416
     417    uint64_t const cCheckFreqDays = m->uCheckFreqSeconds / RT_SEC_1DAY_64;
     418
     419    RTTIMESPEC TimeDiff;
     420    RTTimeSpecSub(RTTimeNow(&TimeDiff), &LastCheckTime);
     421
     422    int64_t const diffLastCheckSecs = RTTimeSpecGetSeconds(&TimeDiff);
     423    int64_t const diffLastCheckDays = diffLastCheckSecs / RT_SEC_1DAY_64;
     424
     425    /* Be as accurate as possible. */
     426    *aCheckNeeded = diffLastCheckSecs >= (int64_t)m->uCheckFreqSeconds ? TRUE : FALSE;
     427
     428    LogRel2(("Update agent (%s): Last update %RU64 days (%RU64 seconds) ago, check frequency is every %RU64 days (%RU64 seconds) -> Check %s\n",
     429             mData.m_strName.c_str(), diffLastCheckDays, diffLastCheckSecs, cCheckFreqDays, m->uCheckFreqSeconds,
     430             *aCheckNeeded ? "needed" : "not needed"));
    372431
    373432    return S_OK;
     
    613672}
    614673
    615 #if 0
    616 HRESULT UpdateAgent::getUpdateCheckNeeded(BOOL *aUpdateCheckNeeded)
    617 {
    618     AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
    619 
    620     HRESULT rc;
    621     ComPtr<ISystemProperties> pSystemProperties;
    622     rc = m_VirtualBox->COMGETTER(SystemProperties)(pSystemProperties.asOutParam());
    623     if (FAILED(rc))
    624         return rc;
    625 
    626     /*
    627      * Is update checking enabled?
    628      */
    629     BOOL fVBoxUpdateEnabled;
    630     rc = pSystemProperties->COMGETTER(VBoxUpdateEnabled)(&fVBoxUpdateEnabled);
    631     if (FAILED(rc))
    632         return rc;
    633 
    634     if (!fVBoxUpdateEnabled)
    635     {
    636         *aUpdateCheckNeeded = false;
    637         return S_OK;
    638     }
    639 
    640     /*
    641      * When was the last update?
    642      */
    643     Bstr strVBoxUpdateLastCheckDate;
    644     rc = pSystemProperties->COMGETTER(VBoxUpdateLastCheckDate)(strVBoxUpdateLastCheckDate.asOutParam());
    645     if (FAILED(rc))
    646         return rc;
    647 
    648     // No prior update check performed so do so now
    649     if (strVBoxUpdateLastCheckDate.isEmpty())
    650     {
    651         *aUpdateCheckNeeded = true;
    652         return S_OK;
    653     }
    654 
    655     // convert stored timestamp to time spec
    656     RTTIMESPEC LastCheckTime;
    657     if (!RTTimeSpecFromString(&LastCheckTime, Utf8Str(strVBoxUpdateLastCheckDate).c_str()))
    658     {
    659         *aUpdateCheckNeeded = true;
    660         return S_OK;
    661     }
    662 
    663     /*
    664      * Compare last update with how often we are supposed to check for updates.
    665      */
    666     ULONG uVBoxUpdateFrequency = 0;  // value in days
    667     rc = pSystemProperties->COMGETTER(VBoxUpdateFrequency)(&uVBoxUpdateFrequency);
    668     if (FAILED(rc))
    669         return rc;
    670 
    671     if (!uVBoxUpdateFrequency)
    672     {
    673         /* Consider config (enable, 0 day interval) as checking once but never again.
    674            We've already check since we've got a date. */
    675         *aUpdateCheckNeeded = false;
    676         return S_OK;
    677     }
    678     uint64_t const cSecsInXDays = uVBoxUpdateFrequency * RT_SEC_1DAY_64;
    679 
    680     RTTIMESPEC TimeDiff;
    681     RTTimeSpecSub(RTTimeNow(&TimeDiff), &LastCheckTime);
    682 
    683     LogRelFunc(("Checking if seconds since last check (%lld) >= Number of seconds in %lu day%s (%lld)\n",
    684                 RTTimeSpecGetSeconds(&TimeDiff), uVBoxUpdateFrequency, uVBoxUpdateFrequency > 1 ? "s" : "", cSecsInXDays));
    685 
    686     if (RTTimeSpecGetSeconds(&TimeDiff) >= (int64_t)cSecsInXDays)
    687         *aUpdateCheckNeeded = true;
    688 
    689     return S_OK;
    690 }
    691 #endif
    692 
    693674
    694675/*********************************************************************************************************************************
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