File: publishingengine.h

package info (click to toggle)
classified-ads 0.13-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 6,772 kB
  • sloc: cpp: 34,291; tcl: 1,175; xml: 64; makefile: 40
file content (93 lines) | stat: -rw-r--r-- 3,200 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/*     -*-C++-*- -*-coding: utf-8-unix;-*-
    Classified Ads is Copyright (c) Antti Järvinen 2013.

    This file is part of Classified Ads.

    Classified Ads is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
    License as published by the Free Software Foundation; either
    version 2.1 of the License, or (at your option) any later version.

    Classified Ads is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public
    License along with Classified Ads; if not, write to the Free Software
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/



#ifndef PUBLISHING_ENG_H
#define PUBLISHING_ENG_H

#include <QHostAddress>
#include <QPair>
#include "connection.h" // for ConnectionObserver
#include "../controller.h"
#include "../datamodel/model.h"

/**
 * @brief Network-connection logic relating content publish demands
 *
 * Class that will ask for connections to nodes destined to
 *        be holders of stuff published in this node. Once
 *       connection is established, stuff to be published
 *       is copied into send-queue of the newly-connected
 *       node.
 */
class PublishingEngine : public QTimer {
    Q_OBJECT
public:
    /**
     * Constructor
     * @param aController application controller. not owned
     * @param aModel persistent storage.
     */
    PublishingEngine(Controller* aController,
                     Model& aModel ) ;
    /**
     * Destructor
     */
    ~PublishingEngine() ;
signals:
    void error(QTcpSocket::SocketError socketError);
public slots:
    /** when connection is attempted, @ref NetworkListener will
     * emit the status (failed or success) of the connection,
     * emitted signal is connected here
     */
    void nodeConnectionAttemptStatus(Connection::ConnectionState aStatus,
                                     const Hash aHashOfAttemptedNode );
    /**
     * this class is a not a thread, but QTimer, thus run.
     */
    void run();
private:
    void emptyNodeCandidateList() ;
    void askConnectionsForNodesOnPublishList() ;
    enum StageOfPublish {
        InitialStage,
        AwaitingConnection
    } ;
    void sendPublishItemToAlreadyConnectedNodes() ;
    void publishToNode(const Hash& aNode) ;
    void checkForSuccessfullyConnectedNodes() ;
    void checkForUnSuccessfullyConnectedNodes() ;
public:
    /** when this is set to false, thread will terminate and run() return */
    bool iNeedsToRun ;
private: // data
    Controller* iController ; /**< application controller */
    Model &iModel ; /**< persistent storage */
    PublishItem iWorkItem ; /**< what we're trying to publish */
    /** list of nodes where iWorkItem might be pushed to */
    QList<Node *> iNodeCandidatesToTryPush ;
    QList<Hash> iNodesSuccessfullyConnected ;
    QList<Hash> iNodesFailurefullyConnected ;
    StageOfPublish iStageOfPublish ;
    bool iNowRunning ;
} ;
#endif