Changeset 116 in pacpusframework for trunk/include/Pacpus/PacpusTools/AsyncWorkerBase.h


Ignore:
Timestamp:
06/25/13 13:44:25 (11 years ago)
Author:
Marek Kurdej
Message:

Added: PacpusException - base class for all exceptions. DbiteExceptions inherits from it.
Added: PacpusLibConfig.h - dllimport/dllexport clauses separated from pacpus.h.
Update: comments.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/Pacpus/PacpusTools/AsyncWorkerBase.h

    r106 r116  
    2222namespace pacpus
    2323{
    24   /**
    25    * @brief A simple base class for asynchronous workers able to partake in the
    26    * Qt slot / signal mechanism
    27    *
    28    * This class represents an asynchronous event-based worker able to receive and
    29    * send Qt signals to other workers or threads. The rationale is to be able to
    30    * define stateful objects that perform calculations asynchronously, triggered
    31    * by external user-defined messages.
    32    */
    33   class PACPUSTOOLS_API AsyncWorkerBase
     24
     25/// A simple base class for asynchronous workers able to partake in the
     26/// Qt slot / signal mechanism
     27///
     28/// This class represents an asynchronous event-based worker able to receive and
     29/// send Qt signals to other workers or threads. The rationale is to be able to
     30/// define stateful objects that perform calculations asynchronously, triggered
     31/// by external user-defined messages.
     32class PACPUSTOOLS_API AsyncWorkerBase
    3433    : public QObject
    3534    , private boost::noncopyable
    36   {
     35{
    3736    Q_OBJECT
    38     public:
    39       /** Constructor. */
    40       AsyncWorkerBase();
    4137
    42       /** Destructor. */
    43       virtual ~AsyncWorkerBase();
     38public:
     39    /// Constructor.
     40    AsyncWorkerBase();
    4441
    45       /** Starts the worker by creating a new thread for it, and calling the setup() virtual method. */
    46       void start();
     42    /// Destructor.
     43    virtual ~AsyncWorkerBase();
    4744
    48       /** Terminates the worker as soon as there are no more requests pending and its current processing
    49        *  is finished.
    50        *
    51        *        This method tries to end the worker gracefully. All pending signals sent before the stop() request will
    52        *        be honored.
    53        *        It is safe to call this method from any thread.
    54        *
    55        *  @param autoDelete if true, deletes the worker as soon as its event loop has finished processing.
    56        */
    57       void stop(bool autoDelete);
     45    /// Starts the worker by creating a new thread for it, and calling the setup() virtual method. */
     46    void start();
    5847
    59       /** Returns true if the worker is active. */
    60       bool isActive() const { return active_; }
     48    /// Terminates the worker as soon as there are no more requests pending and its current processing
     49    /// is finished.
     50    ///
     51    /// This method tries to end the worker gracefully. All pending signals sent before the stop() request will
     52    /// be honored.
     53    /// It is safe to call this method from any thread.
     54    ///
     55    ///  @param autoDelete if true, deletes the worker as soon as its event loop has finished processing.
     56    void stop(bool autoDelete);
    6157
    62     Q_SIGNALS:
    63        /// @todo Documentation
    64        void finished();
    65        /// @todo Documentation
    66        void stopped();
     58    /// @returns @b true if the worker is active, @b false otherwise.
     59    bool isActive() const
     60    {
     61        return active_;
     62    }
    6763
    68     protected:
    69        /// @todo Documentation
    70        virtual void setup();
    71        /// @todo Documentation
    72        virtual void process();
    73        /// @todo Documentation
    74        virtual void cleanup();
     64Q_SIGNALS:
     65    /// @todo Documentation
     66    void finished();
     67    /// @todo Documentation
     68    void stopped();
    7569
    76        /** Returns true if the worker is stopping. */
    77        bool isStopping() const { return stopping_; }
     70protected:
     71    /// @todo Documentation
     72    virtual void setup();
     73    /// @todo Documentation
     74    virtual void process();
     75    /// @todo Documentation
     76    virtual void cleanup();
    7877
    79     private Q_SLOTS:
    80       /// @todo Documentation
    81       void doSetup();
    82       /// @todo Documentation
    83       void doFinish();
     78    /// Returns true if the worker is stopping.
     79    bool isStopping() const { return stopping_; }
    8480
    85     private:
    86       /*! \brief Ends the worker, asking the underlying thread to terminate
    87        *
    88        * This method signals the end of processing and requests the underlying thread to terminate. Actual termination
    89        * will occur as soon as all pending signals (including those that may come from other workers during the
    90        * finish request handling) have been processed.
    91        */
    92       void finish();
     81private Q_SLOTS:
     82    /// @todo Documentation
     83    void doSetup();
     84    /// @todo Documentation
     85    void doFinish();
    9386
    94       // Attributes
    95       bool active_;
    96       bool stopping_;
    97   };
     87private:
     88    /// Ends the worker, asking the underlying thread to terminate
     89    ///
     90    /// This method signals the end of processing and requests the underlying thread to terminate. Actual termination
     91    /// will occur as soon as all pending signals (including those that may come from other workers during the
     92    /// finish request handling) have been processed.
     93    void finish();
     94
     95    // Attributes
     96    bool active_;
     97    bool stopping_;
     98};
     99
    98100} // namespace pacpus
    99101
Note: See TracChangeset for help on using the changeset viewer.