1 #ifndef _XETCPIPLINK_HPP
2 #define _XETCPIPLINK_HPP
3 /*-------------------------------------------------------------------------
4 * drawElements Quality Program Test Executor
5 * ------------------------------------------
7 * Copyright 2014 The Android Open Source Project
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
23 * \brief Tcp/Ip communication link.
24 *//*--------------------------------------------------------------------*/
27 #include "xeCommLink.hpp"
28 #include "deSocket.hpp"
29 #include "deRingBuffer.hpp"
30 #include "deBlockBuffer.hpp"
31 #include "xsProtocol.hpp"
32 #include "deThread.hpp"
43 TcpIpLinkState (CommLinkState initialState, const char* initialErr);
44 ~TcpIpLinkState (void);
46 CommLinkState getState (void) const;
47 CommLinkState getState (std::string& error) const;
49 void setCallbacks (CommLink::StateChangedFunc stateChangedCallback, CommLink::LogDataFunc testLogDataCallback, CommLink::LogDataFunc infoLogDataCallback, void* userPtr);
51 void setState (CommLinkState state, const char* error = "");
52 void onTestLogData (const deUint8* bytes, size_t numBytes) const;
53 void onInfoLogData (const deUint8* bytes, size_t numBytes) const;
55 void onKeepaliveReceived (void);
56 deUint64 getLastKeepaliveRecevied (void) const;
59 mutable de::Mutex m_lock;
60 volatile CommLinkState m_state;
63 volatile deUint64 m_lastKeepaliveReceived;
65 volatile CommLink::StateChangedFunc m_stateChangedCallback;
66 volatile CommLink::LogDataFunc m_testLogDataCallback;
67 volatile CommLink::LogDataFunc m_infoLogDataCallback;
68 void* volatile m_userPtr;
71 class TcpIpSendThread : public de::Thread
74 TcpIpSendThread (de::Socket& socket, TcpIpLinkState& state);
75 ~TcpIpSendThread (void);
81 bool isRunning (void) const { return m_isRunning; }
83 de::BlockBuffer<deUint8>& getBuffer (void) { return m_buffer; }
87 TcpIpLinkState& m_state;
89 de::BlockBuffer<deUint8> m_buffer;
94 class TcpIpRecvThread : public de::Thread
97 TcpIpRecvThread (de::Socket& socket, TcpIpLinkState& state);
98 ~TcpIpRecvThread (void);
104 bool isRunning (void) const { return m_isRunning; }
107 void handleMessage (xs::MessageType messageType, const deUint8* data, size_t dataSize);
109 de::Socket& m_socket;
110 TcpIpLinkState& m_state;
112 std::vector<deUint8> m_curMsgBuf;
118 class TcpIpLink : public CommLink
124 // TcpIpLink -specific API
125 void connect (const de::SocketAddress& address);
126 void disconnect (void);
131 CommLinkState getState (void) const;
132 CommLinkState getState (std::string& error) const;
134 void setCallbacks (StateChangedFunc stateChangedCallback, LogDataFunc testLogDataCallback, LogDataFunc infoLogDataCallback, void* userPtr);
136 void startTestProcess (const char* name, const char* params, const char* workingDir, const char* caseList);
137 void stopTestProcess (void);
140 void closeConnection (void);
142 static void keepaliveTimerCallback (void* ptr);
145 TcpIpLinkState m_state;
147 TcpIpSendThread m_sendThread;
148 TcpIpRecvThread m_recvThread;
150 deTimer* m_keepaliveTimer;
155 #endif // _XETCPIPLINK_HPP