Jarkko Poyry | 3c82736 | 2014-09-02 11:48:52 +0300 | [diff] [blame] | 1 | #ifndef _XSEXECUTIONSERVER_HPP |
| 2 | #define _XSEXECUTIONSERVER_HPP |
| 3 | /*------------------------------------------------------------------------- |
| 4 | * drawElements Quality Program Execution Server |
| 5 | * --------------------------------------------- |
| 6 | * |
| 7 | * Copyright 2014 The Android Open Source Project |
| 8 | * |
| 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 |
| 12 | * |
| 13 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 14 | * |
| 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. |
| 20 | * |
| 21 | *//*! |
| 22 | * \file |
| 23 | * \brief Test Execution Server. |
| 24 | *//*--------------------------------------------------------------------*/ |
| 25 | |
| 26 | #include "xsDefs.hpp" |
| 27 | #include "xsTcpServer.hpp" |
| 28 | #include "xsTestDriver.hpp" |
| 29 | #include "xsProtocol.hpp" |
| 30 | #include "xsTestProcess.hpp" |
| 31 | |
| 32 | #include <vector> |
| 33 | |
| 34 | namespace xs |
| 35 | { |
| 36 | |
| 37 | class ExecutionServer : public TcpServer |
| 38 | { |
| 39 | public: |
| 40 | enum RunMode |
| 41 | { |
| 42 | RUNMODE_SINGLE_EXEC = 0, |
| 43 | RUNMODE_FOREVER, |
| 44 | |
| 45 | RUNMODE_LAST |
| 46 | }; |
| 47 | |
| 48 | ExecutionServer (xs::TestProcess* testProcess, deSocketFamily family, int port, RunMode runMode); |
| 49 | ~ExecutionServer (void); |
| 50 | |
| 51 | ConnectionHandler* createHandler (de::Socket* socket, const de::SocketAddress& clientAddress); |
| 52 | |
| 53 | TestDriver* acquireTestDriver (void); |
| 54 | void releaseTestDriver (TestDriver* driver); |
| 55 | |
| 56 | void connectionDone (ConnectionHandler* handler); |
| 57 | |
| 58 | private: |
| 59 | TestDriver m_testDriver; |
| 60 | de::Mutex m_testDriverLock; |
| 61 | RunMode m_runMode; |
| 62 | }; |
| 63 | |
| 64 | class MessageBuilder |
| 65 | { |
| 66 | public: |
| 67 | MessageBuilder (void) { clear(); } |
| 68 | ~MessageBuilder (void) {} |
| 69 | |
| 70 | void read (ByteBuffer& buffer); |
| 71 | void clear (void); |
| 72 | |
| 73 | bool isComplete (void) const; |
| 74 | MessageType getMessageType (void) const { return m_messageType; } |
Jarkko Pöyry | 745d7c6 | 2015-05-19 12:24:51 -0700 | [diff] [blame] | 75 | size_t getMessageSize (void) const { return m_messageSize; } |
Jarkko Poyry | 3c82736 | 2014-09-02 11:48:52 +0300 | [diff] [blame] | 76 | const deUint8* getMessageData (void) const; |
Jarkko Pöyry | 745d7c6 | 2015-05-19 12:24:51 -0700 | [diff] [blame] | 77 | size_t getMessageDataSize (void) const; |
Jarkko Poyry | 3c82736 | 2014-09-02 11:48:52 +0300 | [diff] [blame] | 78 | |
| 79 | private: |
| 80 | std::vector<deUint8> m_buffer; |
| 81 | MessageType m_messageType; |
Jarkko Pöyry | 745d7c6 | 2015-05-19 12:24:51 -0700 | [diff] [blame] | 82 | size_t m_messageSize; |
Jarkko Poyry | 3c82736 | 2014-09-02 11:48:52 +0300 | [diff] [blame] | 83 | }; |
| 84 | |
| 85 | class ExecutionRequestHandler : public ConnectionHandler |
| 86 | { |
| 87 | public: |
| 88 | ExecutionRequestHandler (ExecutionServer* server, de::Socket* socket); |
| 89 | ~ExecutionRequestHandler (void); |
| 90 | |
| 91 | protected: |
| 92 | void handle (void); |
| 93 | |
| 94 | private: |
| 95 | ExecutionRequestHandler (const ExecutionRequestHandler& handler); |
| 96 | ExecutionRequestHandler& operator= (const ExecutionRequestHandler& handler); |
| 97 | |
| 98 | void processSession (void); |
Jarkko Pöyry | 745d7c6 | 2015-05-19 12:24:51 -0700 | [diff] [blame] | 99 | void processMessage (MessageType type, const deUint8* data, size_t dataSize); |
Jarkko Poyry | 3c82736 | 2014-09-02 11:48:52 +0300 | [diff] [blame] | 100 | |
| 101 | inline TestDriver* getTestDriver (void) { if (!m_testDriver) acquireTestDriver(); return m_testDriver; } |
| 102 | void acquireTestDriver (void); |
| 103 | |
| 104 | void initKeepAlives (void); |
| 105 | void keepAliveReceived (void); |
| 106 | void pollKeepAlives (void); |
| 107 | |
| 108 | bool receive (void); |
| 109 | bool send (void); |
| 110 | |
| 111 | ExecutionServer* m_execServer; |
| 112 | TestDriver* m_testDriver; |
| 113 | |
| 114 | ByteBuffer m_bufferIn; |
| 115 | ByteBuffer m_bufferOut; |
| 116 | |
| 117 | bool m_run; |
| 118 | MessageBuilder m_msgBuilder; |
| 119 | |
| 120 | // \todo [2011-09-30 pyry] Move to some watchdog class instead. |
| 121 | deUint64 m_lastKeepAliveSent; |
| 122 | deUint64 m_lastKeepAliveReceived; |
| 123 | |
| 124 | std::vector<deUint8> m_sendRecvTmpBuf; |
| 125 | }; |
| 126 | |
| 127 | } // xs |
| 128 | |
| 129 | #endif // _XSEXECUTIONSERVER_HPP |