Classified ads
networklistener.h
Go to the documentation of this file.
1 /* -*-C++-*- -*-coding: utf-8-unix;-*-
2  Classified Ads is Copyright (c) Antti Järvinen 2013.
3 
4  This file is part of Classified Ads.
5 
6  Classified Ads is free software; you can redistribute it and/or
7  modify it under the terms of the GNU Lesser General Public
8  License as published by the Free Software Foundation; either
9  version 2.1 of the License, or (at your option) any later version.
10 
11  Classified Ads is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  Lesser General Public License for more details.
15 
16  You should have received a copy of the GNU Lesser General Public
17  License along with Classified Ads; if not, write to the Free Software
18  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20 
21 
22 
23 #ifndef NETWORK_LISTENER_H
24 #define NETWORK_LISTENER_H
25 
26 #include <QTcpServer>
27 #include <QList>
28 #include "connection.h" // for ConnectionObserver
29 #include <QUdpSocket>
30 #include <QNetworkSession>
31 
32 class MController ;
33 class Model ;
35 
43  public QTcpServer,
45  Q_OBJECT
46 public:
54  NetworkListener(MController *aController,
55  Model *aModel) ;
68  bool startListen(bool aIpv6) ;
69 
73  virtual bool dataReceived(const QByteArray& aData,
74  Connection& aConnection) ;
79  virtual void connectionClosed(Connection *aDeletee) ;
84  virtual void connectionReady(Connection *aBusinessEntity) ;
88  void stopAccepting() ;
94 protected:
95 #if QT_VERSION >= 0x050000
96  virtual void incomingConnection(qintptr handle);
97 #else
98  void incomingConnection (int aSocketDescriptor ) ;
99 #endif
100 signals:
101  void error(QTcpSocket::SocketError socketError);
110  const Hash aHashOfAttemptedNode );
111 private slots:
112  void broadCastReceived() ;
113  void threadIsDeleted() ;
114  void networkStateChanged( QNetworkSession::State aState ) ;
120  void connectionAttemptFailed(const Hash& aNodeHash) ;
121 private: // data
126  QUdpSocket iBroadCastListener ;
131  bool iCanAccept ;
132  QNetworkConfiguration iConnectionConfig ;
133  QNetworkSession* iNetworkSession ;
134 } ;
135 #endif
Class containing routines for parsing protocol messages. Methods are mainly called from network conne...
Definition: protocol_message_parser.h:40
void stopAccepting()
ProtocolMessageParser * iParser
Definition: networklistener.h:125
void networkStateChanged(QNetworkSession::State aState)
QNetworkSession * iNetworkSession
Definition: networklistener.h:133
void threadIsDeleted()
virtual void connectionClosed(Connection *aDeletee)
virtual void connectionReady(Connection *aBusinessEntity)
void connectionAttemptFailed(const Hash &aNodeHash)
void error(QTcpSocket::SocketError socketError)
QUdpSocket iBroadCastListener
Definition: networklistener.h:126
void nodeConnectionAttemptStatus(Connection::ConnectionState aStatus, const Hash aHashOfAttemptedNode)
Hash is class that carries 160-bit digest.
Definition: hash.h:38
MController * iController
Definition: networklistener.h:122
ConnectionState
Definition: connection.h:47
void broadCastReceived()
QNetworkConfiguration iConnectionConfig
Definition: networklistener.h:132
class for listening to incoming network connections.
Definition: networklistener.h:42
Pure-virtual interface class for controller. This is spammed across parties needing access to applica...
Definition: mcontroller.h:48
M of the MVC pattern. Handles permanent storage.
Definition: model.h:50
Interface for receiving network traffic.
Definition: connection.h:59
void incomingConnection(int aSocketDescriptor)
Model * iModel
Definition: networklistener.h:123
bool iCanAccept
Definition: networklistener.h:131
bool startListen(bool aIpv6)
Class that represents a network connection.
Definition: connection.h:43
NetworkListener(MController *aController, Model *aModel)
void figureOutLocalAddresses()
virtual bool dataReceived(const QByteArray &aData, Connection &aConnection)