summaryrefslogtreecommitdiffstats
path: root/src/net/pvsMsg.h
blob: 6fbcd999e2f32808aa856e6bdf36e41c313ccf90 (plain) (blame)
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
/*
 * pvsMsg.h
 *
 *  Created on: 08.01.2010
 *      Author: sr
 */

#ifndef PVSMSG_H_
#define PVSMSG_H_


#include <QtCore/QString>

enum PVSMsgType
{
    PVSCOMMAND = 'C',
    PVSMESSAGE = 'M',
    PVSLOGIN = 'L',
    PVSDAEMON = 'D',
    PVSUNKNOWN = 'U'
};

class PVSServerConnection;
class PVSListenServer;
class PVSClientConnection;
class QAbstractSocket;

class PVSMsg
{
public:
    friend class PVSServerConnection;
    friend class PVSListenServer;
    friend class PVSClientConnection;

    PVSMsg();
    PVSMsg(PVSMsgType type, QString _ident, QString msg, int recID = 0);
    PVSMsg(PVSMsg const& copyMe);
    ~PVSMsg();

    int readMessage(QAbstractSocket* sock, bool udp = false); ///< -1 = error, 0 = incomplete, 1 = complete
    unsigned int getLength()
    {
        return _msgString.size();
    };
    void setIdent(QString ident);
    QString getIdent();
    void setMessage(QString text);
    QString getMessage();
    PVSMsgType getType() { return _msgType; }
    bool getBinaryData(char*& data, int& dataLen); ///< get binary representation of this PVSmsg

    unsigned int getRecID() { return _recID; }
    int getSndID() { return _sndID; }
    QString getRemoteIp() { return _remoteIp; }
    bool isMsgComplete() { return _buffFill > 0 && _buffFill == _buffLen; }

private:
    void setSndID(int id);
    void setRecID(int id);
    bool makeSndBuff();
    PVSMsgType _msgType; ///< type of message (command, message, login, daemon)
    QString _msgIdent; ///< message ident
    QString _msgString; ///< message string
    char *_buffer; ///< receive buffer
    int _buffLen; ///< size of complete message in bytes
    int _buffFill; ///< actual number of bytes in buffer

    int _sndID;
    int _recID;
    QString _remoteIp;
};

#endif /* PVSMSG_H_ */