1e5c31af7Sopenharmony_ci#ifndef _XSTCPSERVER_HPP 2e5c31af7Sopenharmony_ci#define _XSTCPSERVER_HPP 3e5c31af7Sopenharmony_ci/*------------------------------------------------------------------------- 4e5c31af7Sopenharmony_ci * drawElements Quality Program Execution Server 5e5c31af7Sopenharmony_ci * --------------------------------------------- 6e5c31af7Sopenharmony_ci * 7e5c31af7Sopenharmony_ci * Copyright 2014 The Android Open Source Project 8e5c31af7Sopenharmony_ci * 9e5c31af7Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 10e5c31af7Sopenharmony_ci * you may not use this file except in compliance with the License. 11e5c31af7Sopenharmony_ci * You may obtain a copy of the License at 12e5c31af7Sopenharmony_ci * 13e5c31af7Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 14e5c31af7Sopenharmony_ci * 15e5c31af7Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 16e5c31af7Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 17e5c31af7Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18e5c31af7Sopenharmony_ci * See the License for the specific language governing permissions and 19e5c31af7Sopenharmony_ci * limitations under the License. 20e5c31af7Sopenharmony_ci * 21e5c31af7Sopenharmony_ci *//*! 22e5c31af7Sopenharmony_ci * \file 23e5c31af7Sopenharmony_ci * \brief TCP Server. 24e5c31af7Sopenharmony_ci *//*--------------------------------------------------------------------*/ 25e5c31af7Sopenharmony_ci 26e5c31af7Sopenharmony_ci#include "xsDefs.hpp" 27e5c31af7Sopenharmony_ci#include "deSocket.hpp" 28e5c31af7Sopenharmony_ci#include "deThread.hpp" 29e5c31af7Sopenharmony_ci#include "deMutex.hpp" 30e5c31af7Sopenharmony_ci 31e5c31af7Sopenharmony_ci#include <vector> 32e5c31af7Sopenharmony_ci 33e5c31af7Sopenharmony_cinamespace xs 34e5c31af7Sopenharmony_ci{ 35e5c31af7Sopenharmony_ci 36e5c31af7Sopenharmony_ciclass ConnectionHandler; 37e5c31af7Sopenharmony_ci 38e5c31af7Sopenharmony_ciclass TcpServer 39e5c31af7Sopenharmony_ci{ 40e5c31af7Sopenharmony_cipublic: 41e5c31af7Sopenharmony_ci TcpServer (deSocketFamily family, int port); 42e5c31af7Sopenharmony_ci virtual ~TcpServer (void); 43e5c31af7Sopenharmony_ci 44e5c31af7Sopenharmony_ci virtual ConnectionHandler* createHandler (de::Socket* socket, const de::SocketAddress& clientAddress) = DE_NULL; 45e5c31af7Sopenharmony_ci 46e5c31af7Sopenharmony_ci virtual void runServer (void); 47e5c31af7Sopenharmony_ci void stopServer (void); 48e5c31af7Sopenharmony_ci 49e5c31af7Sopenharmony_ci virtual void connectionDone (ConnectionHandler* handler); 50e5c31af7Sopenharmony_ci 51e5c31af7Sopenharmony_ciprotected: 52e5c31af7Sopenharmony_ci de::Socket m_socket; 53e5c31af7Sopenharmony_ci 54e5c31af7Sopenharmony_ciprivate: 55e5c31af7Sopenharmony_ci TcpServer (const TcpServer& other); 56e5c31af7Sopenharmony_ci TcpServer& operator= (const TcpServer& other); 57e5c31af7Sopenharmony_ci 58e5c31af7Sopenharmony_ci void addLiveConnection (ConnectionHandler* handler); 59e5c31af7Sopenharmony_ci void deleteDoneConnections (void); 60e5c31af7Sopenharmony_ci 61e5c31af7Sopenharmony_ci de::Mutex m_connectionListLock; 62e5c31af7Sopenharmony_ci std::vector<ConnectionHandler*> m_liveConnections; 63e5c31af7Sopenharmony_ci std::vector<ConnectionHandler*> m_doneConnections; 64e5c31af7Sopenharmony_ci}; 65e5c31af7Sopenharmony_ci 66e5c31af7Sopenharmony_ciclass ConnectionHandler : public de::Thread 67e5c31af7Sopenharmony_ci{ 68e5c31af7Sopenharmony_cipublic: 69e5c31af7Sopenharmony_ci ConnectionHandler (TcpServer* server, de::Socket* socket) : m_server(server), m_socket(socket) {} 70e5c31af7Sopenharmony_ci virtual ~ConnectionHandler (void); 71e5c31af7Sopenharmony_ci 72e5c31af7Sopenharmony_ci void run (void); 73e5c31af7Sopenharmony_ci 74e5c31af7Sopenharmony_ciprotected: 75e5c31af7Sopenharmony_ci virtual void handle (void) = DE_NULL; 76e5c31af7Sopenharmony_ci 77e5c31af7Sopenharmony_ciprotected: 78e5c31af7Sopenharmony_ci TcpServer* m_server; 79e5c31af7Sopenharmony_ci de::Socket* m_socket; 80e5c31af7Sopenharmony_ci}; 81e5c31af7Sopenharmony_ci 82e5c31af7Sopenharmony_ci} // xs 83e5c31af7Sopenharmony_ci 84e5c31af7Sopenharmony_ci#endif // _XSTCPSERVER_HPP 85