xref: /aosp_15_r20/external/deqp/execserver/xsExecutionServer.hpp (revision 35238bce31c2a825756842865a792f8cf7f89930)
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:
MessageBuilder(void)67     MessageBuilder(void)
68     {
69         clear();
70     }
~MessageBuilder(void)71     ~MessageBuilder(void)
72     {
73     }
74 
75     void read(ByteBuffer &buffer);
76     void clear(void);
77 
78     bool isComplete(void) const;
getMessageType(void) const79     MessageType getMessageType(void) const
80     {
81         return m_messageType;
82     }
getMessageSize(void) const83     size_t getMessageSize(void) const
84     {
85         return m_messageSize;
86     }
87     const uint8_t *getMessageData(void) const;
88     size_t getMessageDataSize(void) const;
89 
90 private:
91     std::vector<uint8_t> m_buffer;
92     MessageType m_messageType;
93     size_t m_messageSize;
94 };
95 
96 class ExecutionRequestHandler : public ConnectionHandler
97 {
98 public:
99     ExecutionRequestHandler(ExecutionServer *server, de::Socket *socket);
100     ~ExecutionRequestHandler(void);
101 
102 protected:
103     void handle(void);
104 
105 private:
106     ExecutionRequestHandler(const ExecutionRequestHandler &handler);
107     ExecutionRequestHandler &operator=(const ExecutionRequestHandler &handler);
108 
109     void processSession(void);
110     void processMessage(MessageType type, const uint8_t *data, size_t dataSize);
111 
getTestDriver(void)112     inline TestDriver *getTestDriver(void)
113     {
114         if (!m_testDriver)
115             acquireTestDriver();
116         return m_testDriver;
117     }
118     void acquireTestDriver(void);
119 
120     void initKeepAlives(void);
121     void keepAliveReceived(void);
122     void pollKeepAlives(void);
123 
124     bool receive(void);
125     bool send(void);
126 
127     ExecutionServer *m_execServer;
128     TestDriver *m_testDriver;
129 
130     ByteBuffer m_bufferIn;
131     ByteBuffer m_bufferOut;
132 
133     bool m_run;
134     MessageBuilder m_msgBuilder;
135 
136     // \todo [2011-09-30 pyry] Move to some watchdog class instead.
137     uint64_t m_lastKeepAliveSent;
138     uint64_t m_lastKeepAliveReceived;
139 
140     std::vector<uint8_t> m_sendRecvTmpBuf;
141 };
142 
143 } // namespace xs
144 
145 #endif // _XSEXECUTIONSERVER_HPP
146