VPTissue Reference Manual
Connection.h
Go to the documentation of this file.
1 #ifndef SIMPT_PAREX_CONNECTION_H_
2 #define SIMPT_PAREX_CONNECTION_H_
3 /*
4  * Copyright 2011-2016 Universiteit Antwerpen
5  *
6  * Licensed under the EUPL, Version 1.1 or as soon they will be approved by
7  * the European Commission - subsequent versions of the EUPL (the "Licence");
8  * You may not use this work except in compliance with the Licence.
9  * You may obtain a copy of the Licence at: http://ec.europa.eu/idabc/eupl5
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the Licence is distributed on an "AS IS" basis,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the Licence for the specific language governing
15  * permissions and limitations under the Licence.
16  */
22 #include <QObject>
23 #include <QTcpSocket>
24 #include <string>
25 
26 namespace SimPT_Parex {
27 
31 class Connection: public QObject
32 {
33  Q_OBJECT
34 public:
41  Connection(QTcpSocket *socket, QObject *parent = 0);
42 
46  virtual ~Connection();
47 
51  bool IsConnected();
52 
53  std::string GetPeerAddress() const;
54 
55  int GetPeerPort() const ;
56 
57 public slots:
63  void SendMessage(const QByteArray &message);
64 
65 signals:
71  void ReceivedMessage(const QByteArray &message);
72 
76  void ConnectionClosed();
77 
83  void Error(const std::string &error);
84 
85 private slots:
89  void ReadMessage();
90 
94  void HandleError(QAbstractSocket::SocketError socketError);
95 
96 private:
100  Connection(const Connection&);
101  Connection &operator=(const Connection&);
102 
103  QTcpSocket *m_socket;
104  quint32 m_size;
105 };
106 
107 } // namespace
108 
109 #endif // end-of-include-guard
void SendMessage(const QByteArray &message)
Sends a message over the connection.
Definition: Connection.cpp:63
bool IsConnected()
Check if still connected.
Definition: Connection.cpp:49
void ReceivedMessage(const QByteArray &message)
Signal emitted when a message is received over the connection.
void Error(const std::string &error)
Signal emitted when an error occurred in the connection.
Connection(QTcpSocket *socket, QObject *parent=0)
Constructor.
Definition: Connection.cpp:31
void ConnectionClosed()
Signal emitted when the remote host closed the connection.
Class managing a TCP stream of messages.
Definition: Connection.h:31
Namespace for SimPT parameter explorer package.
Definition: Client.cpp:52
virtual ~Connection()
Destructor, closes the connection.
Definition: Connection.cpp:43
see the online Qt documentation