VirtualBox

Changeset 58480 in vbox


Ignore:
Timestamp:
Oct 29, 2015 12:58:18 PM (9 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
103794
Message:

FE/Qt: Networking cleanup/rework (part 28): Some refactoring for network-request code.

Location:
trunk/src/VBox/Frontends/VirtualBox/src/net
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/net/UINetworkRequest.cpp

    r58426 r58480  
    11/* $Id$ */
    22/** @file
    3  * VBox Qt GUI - UINetworkRequest stuff implementation.
     3 * VBox Qt GUI - UINetworkRequest class implementation.
    44 */
    55
    66/*
    7  * Copyright (C) 2011-2012 Oracle Corporation
     7 * Copyright (C) 2011-2015 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    3131#endif /* !VBOX_WITH_PRECOMPILED_HEADERS */
    3232
    33 
    3433UINetworkRequest::UINetworkRequest(UINetworkRequestType type,
    3534                                   const QList<QUrl> &urls,
     
    3938    : QObject(pNetworkManager)
    4039    , m_type(type)
    41     , m_uuid(QUuid::createUuid())
    4240    , m_requests(urls)
    4341    , m_requestHeaders(requestHeaders)
     42    , m_pCustomer(pCustomer)
     43    , m_pNetworkManager(pNetworkManager)
     44    , m_uuid(QUuid::createUuid())
    4445    , m_iCurrentRequestIndex(0)
    45     , m_pCustomer(pCustomer)
    4646    , m_fRunning(false)
    4747{
    48     /* Initialize: */
    49     initialize();
     48    /* Prepare: */
     49    prepare();
    5050}
    5151
    5252UINetworkRequest::~UINetworkRequest()
    5353{
    54     /* Destroy network-reply: */
    55     cleanupNetworkReply();
    56 
    57     /* Unregister network-request from network-manager: */
    58     manager()->unregisterNetworkRequest(m_uuid);
    59 }
    60 
    61 UINetworkManager* UINetworkRequest::manager() const
    62 {
    63     AssertPtrReturn(parent(), 0);
    64     return qobject_cast<UINetworkManager*>(parent());
     54    /* Cleanup: */
     55    cleanup();
    6556}
    6657
     
    7061}
    7162
    72 /* Network-reply progress handler: */
    7363void UINetworkRequest::sltHandleNetworkReplyProgress(qint64 iReceived, qint64 iTotal)
    7464{
     
    7969}
    8070
    81 /* Network-reply finish handler: */
    8271void UINetworkRequest::sltHandleNetworkReplyFinish()
    8372{
     
    145134}
    146135
    147 /* Slot to retry network-request: */
    148136void UINetworkRequest::sltRetry()
    149137{
     
    159147}
    160148
    161 /* Slot to cancel network-request: */
    162149void UINetworkRequest::sltCancel()
    163150{
    164151    /* Abort network-reply if present: */
    165     abortNetworkReply();
    166 }
    167 
    168 /* Initialize: */
    169 void UINetworkRequest::initialize()
    170 {
    171     /* Prepare listeners for parent(): */
    172     connect(parent(), SIGNAL(sigCancelNetworkRequests()), this, SLOT(sltCancel()), Qt::QueuedConnection);
     152    if (m_pReply)
     153    {
     154        if (m_fRunning)
     155            m_pReply->abort();
     156        else
     157            emit sigCanceled(m_uuid);
     158    }
     159}
     160
     161void UINetworkRequest::prepare()
     162{
     163    /* Prepare listeners for manager(): */
     164    connect(manager(), SIGNAL(sigCancelNetworkRequests()), this, SLOT(sltCancel()), Qt::QueuedConnection);
    173165
    174166    /* Register network-request in network-manager: */
     
    179171    m_request = m_requests.at(m_iCurrentRequestIndex);
    180172
    181     /* Create network-reply: */
     173    /* Prepare network-reply: */
    182174    prepareNetworkReply();
    183175}
    184176
    185 /* Prepare network-reply: */
    186177void UINetworkRequest::prepareNetworkReply()
    187178{
     
    202193}
    203194
    204 /* Cleanup network-reply: */
    205195void UINetworkRequest::cleanupNetworkReply()
    206196{
     
    212202}
    213203
    214 /* Abort network-reply: */
    215 void UINetworkRequest::abortNetworkReply()
    216 {
    217     /* Abort network-reply if present: */
    218     if (m_pReply)
    219     {
    220         if (m_fRunning)
    221             m_pReply->abort();
    222         else
    223             emit sigCanceled(m_uuid);
    224     }
    225 }
    226 
     204void UINetworkRequest::cleanup()
     205{
     206    /* Cleanup network-reply: */
     207    cleanupNetworkReply();
     208
     209    /* Unregister network-request from network-manager: */
     210    manager()->unregisterNetworkRequest(m_uuid);
     211}
     212
  • trunk/src/VBox/Frontends/VirtualBox/src/net/UINetworkRequest.h

    r58426 r58480  
    11/* $Id$ */
    22/** @file
    3  * VBox Qt GUI - UINetworkRequest stuff declaration.
     3 * VBox Qt GUI - UINetworkRequest class declaration.
    44 */
    55
    66/*
    7  * Copyright (C) 2011-2012 Oracle Corporation
     7 * Copyright (C) 2011-2015 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    1616 */
    1717
    18 #ifndef __UINetworkRequest_h__
    19 #define __UINetworkRequest_h__
     18#ifndef ___UINetworkRequest_h___
     19#define ___UINetworkRequest_h___
    2020
    2121/* Qt includes: */
     
    6464                     UINetworkCustomer *pCustomer,
    6565                     UINetworkManager *pNetworkManager);
    66     /** Destructs network request. */
     66    /** Destructs network-request. */
    6767    ~UINetworkRequest();
    6868
    69     /** Returns parent network-manager. */
    70     UINetworkManager* manager() const;
    7169    /* Getters: */
    72     const QUuid& uuid() const { return m_uuid; }
    7370    const QString description() const;
    7471    UINetworkCustomer* customer() { return m_pCustomer; }
     72    /** Returns parent network-manager. */
     73    UINetworkManager* manager() const { return m_pNetworkManager; }
     74    const QUuid& uuid() const { return m_uuid; }
    7575    UINetworkReply* reply() { return m_pReply; }
    7676
     
    8989private:
    9090
    91     /* Initialize: */
    92     void initialize();
    93 
     91    /* Prepare: */
     92    void prepare();
    9493    /* Prepare network-reply: */
    9594    void prepareNetworkReply();
     95
    9696    /* Cleanup network-reply: */
    9797    void cleanupNetworkReply();
    98     /* Abort network-reply: */
    99     void abortNetworkReply();
     98    /* Cleanup: */
     99    void cleanup();
    100100
    101101    /* Variables: */
    102     UINetworkRequestType m_type;
    103     QUuid m_uuid;
    104     QList<QUrl> m_requests;
     102    const UINetworkRequestType m_type;
     103    const QList<QUrl> m_requests;
    105104    /** Holds the request headers. */
    106105    const UserDictionary m_requestHeaders;
     106    UINetworkCustomer *m_pCustomer;
     107    UINetworkManager *m_pNetworkManager;
     108    const QUuid m_uuid;
     109
    107110    QUrl m_request;
    108111    int m_iCurrentRequestIndex;
    109     QString m_strDescription;
    110     UINetworkCustomer *m_pCustomer;
     112    bool m_fRunning;
     113
    111114    QPointer<UINetworkReply> m_pReply;
    112     bool m_fRunning;
    113115};
    114116
    115 #endif // __UINetworkRequest_h__
     117#endif /* !___UINetworkRequest_h___ */
     118
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