GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/net/ea/network.h Lines: 0 5 0.0 %
Date: 2017-11-29 Branches: 0 0 0.0 %

Line Branch Exec Source
1
/*
2
 *  The ManaPlus Client
3
 *  Copyright (C) 2004-2009  The Mana World Development Team
4
 *  Copyright (C) 2009-2010  The Mana Developers
5
 *  Copyright (C) 2011-2017  The ManaPlus Developers
6
 *
7
 *  This file is part of The ManaPlus Client.
8
 *
9
 *  This program is free software; you can redistribute it and/or modify
10
 *  it under the terms of the GNU General Public License as published by
11
 *  the Free Software Foundation; either version 2 of the License, or
12
 *  any later version.
13
 *
14
 *  This program is distributed in the hope that it will be useful,
15
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 *  GNU General Public License for more details.
18
 *
19
 *  You should have received a copy of the GNU General Public License
20
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
21
 */
22
23
#ifndef NET_EA_NETWORK_H
24
#define NET_EA_NETWORK_H
25
26
#include "net/serverinfo.h"
27
28
PRAGMACLANG6GCC(GCC diagnostic push)
29
PRAGMACLANG6GCC(GCC diagnostic ignored "-Wold-style-cast")
30
#include "net/sdltcpnet.h"
31
PRAGMACLANG6GCC(GCC diagnostic pop)
32
33
struct PacketInfo;
34
35
namespace Ea
36
{
37
38
class Network notfinal
39
{
40
    public:
41
        Network();
42
43
        A_DELETE_COPY(Network)
44
45
        virtual ~Network();
46
47
        bool connect(const ServerInfo &server);
48
49
        void disconnect();
50
51
        ServerInfo getServer() const A_WARN_UNUSED
52
        { return mServer; }
53
54
        int getState() const A_WARN_UNUSED
55
        { return mState; }
56
57
        const std::string &getError() const A_WARN_UNUSED
58
        { return mError; }
59
60
        bool isConnected() const A_WARN_UNUSED
61
        { return mState == CONNECTED; }
62
63
        int getInSize() const A_WARN_UNUSED
64
        { return mInSize; }
65
66
        void skip(const int len);
67
68
        void flush();
69
70
        void fixSendBuffer();
71
72
        void pauseDispatch()
73
        { mPauseDispatch = true; }
74
75
        // ERROR replaced by NET_ERROR because already defined in Windows
76
        enum
77
        {
78
            IDLE = 0,
79
            CONNECTED,
80
            CONNECTING,
81
            DATA,
82
            NET_ERROR
83
        };
84
85
    protected:
86
        friend int networkThread(void *data);
87
88
        void setError(const std::string &error);
89
90
        uint16_t readWord(const int pos) const A_WARN_UNUSED;
91
92
        bool realConnect();
93
94
        void receive();
95
96
        TcpNet::Socket mSocket;
97
98
        ServerInfo mServer;
99
100
        PacketInfo *mPackets;
101
102
        char *mInBuffer;
103
        char *mOutBuffer;
104
        unsigned int mInSize;
105
        unsigned int mOutSize;
106
107
        unsigned int mToSkip;
108
109
        int mState;
110
        std::string mError;
111
112
        SDL_Thread *mWorkerThread;
113
        SDL_mutex *mMutexIn;
114
        SDL_mutex *mMutexOut;
115
        int mSleep;
116
        bool mPauseDispatch;
117
};
118
119
}  // namespace Ea
120
121
#endif  // NET_EA_NETWORK_H