13c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#ifndef _XSEXECUTIONSERVER_HPP 23c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#define _XSEXECUTIONSERVER_HPP 33c827367444ee418f129b2c238299f49d3264554Jarkko Poyry/*------------------------------------------------------------------------- 43c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * drawElements Quality Program Execution Server 53c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * --------------------------------------------- 63c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * 73c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Copyright 2014 The Android Open Source Project 83c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * 93c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Licensed under the Apache License, Version 2.0 (the "License"); 103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * you may not use this file except in compliance with the License. 113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * You may obtain a copy of the License at 123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * 133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * http://www.apache.org/licenses/LICENSE-2.0 143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * 153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Unless required by applicable law or agreed to in writing, software 163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * distributed under the License is distributed on an "AS IS" BASIS, 173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * See the License for the specific language governing permissions and 193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * limitations under the License. 203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * 213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *//*! 223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * \file 233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * \brief Test Execution Server. 243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *//*--------------------------------------------------------------------*/ 253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "xsDefs.hpp" 273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "xsTcpServer.hpp" 283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "xsTestDriver.hpp" 293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "xsProtocol.hpp" 303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "xsTestProcess.hpp" 313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include <vector> 333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 343c827367444ee418f129b2c238299f49d3264554Jarkko Poyrynamespace xs 353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 373c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass ExecutionServer : public TcpServer 383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 393c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic: 403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry enum RunMode 413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry RUNMODE_SINGLE_EXEC = 0, 433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry RUNMODE_FOREVER, 443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry RUNMODE_LAST 463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry }; 473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ExecutionServer (xs::TestProcess* testProcess, deSocketFamily family, int port, RunMode runMode); 493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ~ExecutionServer (void); 503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ConnectionHandler* createHandler (de::Socket* socket, const de::SocketAddress& clientAddress); 523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry TestDriver* acquireTestDriver (void); 543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry void releaseTestDriver (TestDriver* driver); 553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry void connectionDone (ConnectionHandler* handler); 573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 583c827367444ee418f129b2c238299f49d3264554Jarkko Poyryprivate: 593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry TestDriver m_testDriver; 603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry de::Mutex m_testDriverLock; 613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry RunMode m_runMode; 623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}; 633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 643c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass MessageBuilder 653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 663c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic: 673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry MessageBuilder (void) { clear(); } 683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ~MessageBuilder (void) {} 693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry void read (ByteBuffer& buffer); 713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry void clear (void); 723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry bool isComplete (void) const; 743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry MessageType getMessageType (void) const { return m_messageType; } 75745d7c616351405cfb6d2a7133d261eb4989d626Jarkko Pöyry size_t getMessageSize (void) const { return m_messageSize; } 763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const deUint8* getMessageData (void) const; 77745d7c616351405cfb6d2a7133d261eb4989d626Jarkko Pöyry size_t getMessageDataSize (void) const; 783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 793c827367444ee418f129b2c238299f49d3264554Jarkko Poyryprivate: 803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry std::vector<deUint8> m_buffer; 813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry MessageType m_messageType; 82745d7c616351405cfb6d2a7133d261eb4989d626Jarkko Pöyry size_t m_messageSize; 833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}; 843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 853c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass ExecutionRequestHandler : public ConnectionHandler 863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 873c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic: 883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ExecutionRequestHandler (ExecutionServer* server, de::Socket* socket); 893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ~ExecutionRequestHandler (void); 903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 913c827367444ee418f129b2c238299f49d3264554Jarkko Poyryprotected: 923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry void handle (void); 933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 943c827367444ee418f129b2c238299f49d3264554Jarkko Poyryprivate: 953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ExecutionRequestHandler (const ExecutionRequestHandler& handler); 963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ExecutionRequestHandler& operator= (const ExecutionRequestHandler& handler); 973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry void processSession (void); 99745d7c616351405cfb6d2a7133d261eb4989d626Jarkko Pöyry void processMessage (MessageType type, const deUint8* data, size_t dataSize); 1003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry inline TestDriver* getTestDriver (void) { if (!m_testDriver) acquireTestDriver(); return m_testDriver; } 1023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry void acquireTestDriver (void); 1033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry void initKeepAlives (void); 1053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry void keepAliveReceived (void); 1063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry void pollKeepAlives (void); 1073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry bool receive (void); 1093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry bool send (void); 1103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ExecutionServer* m_execServer; 1123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry TestDriver* m_testDriver; 1133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ByteBuffer m_bufferIn; 1153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ByteBuffer m_bufferOut; 1163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry bool m_run; 1183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry MessageBuilder m_msgBuilder; 1193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // \todo [2011-09-30 pyry] Move to some watchdog class instead. 1213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deUint64 m_lastKeepAliveSent; 1223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deUint64 m_lastKeepAliveReceived; 1233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry std::vector<deUint8> m_sendRecvTmpBuf; 1253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}; 1263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} // xs 1283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#endif // _XSEXECUTIONSERVER_HPP 130