xref: /aosp_15_r20/external/deqp/execserver/xsDefs.hpp (revision 35238bce31c2a825756842865a792f8cf7f89930)
1 #ifndef _XSDEFS_HPP
2 #define _XSDEFS_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 ExecServer defines.
24  *//*--------------------------------------------------------------------*/
25 
26 #include "deDefs.hpp"
27 #include "deRingBuffer.hpp"
28 #include "deBlockBuffer.hpp"
29 
30 #include <stdexcept>
31 
32 namespace xs
33 {
34 
35 // Configuration.
36 enum
37 {
38     // Times are in milliseconds.
39     LOG_FILE_TIMEOUT  = 5000,
40     READ_DATA_TIMEOUT = 500,
41 
42     SERVER_IDLE_THRESHOLD = 10,
43     SERVER_IDLE_SLEEP     = 50,
44     FILEREADER_IDLE_SLEEP = 100,
45 
46     LOG_BUFFER_BLOCK_SIZE = 1024,
47     LOG_BUFFER_NUM_BLOCKS = 512,
48 
49     INFO_BUFFER_BLOCK_SIZE = 64,
50     INFO_BUFFER_NUM_BLOCKS = 128,
51 
52     SEND_BUFFER_SIZE = 16 * 1024,
53     RECV_BUFFER_SIZE = 4 * 1024,
54 
55     FILEREADER_TMP_BUFFER_SIZE = 1024,
56     SEND_RECV_TMP_BUFFER_SIZE  = 4 * 1024,
57 
58     MIN_MSG_PAYLOAD_SIZE = 32
59 };
60 
61 typedef de::RingBuffer<uint8_t> ByteBuffer;
62 typedef de::BlockBuffer<uint8_t> ThreadedByteBuffer;
63 
64 class Error : public std::runtime_error
65 {
66 public:
Error(const std::string & message)67     Error(const std::string &message) : std::runtime_error(message)
68     {
69     }
70     Error(const char *message, const char *expr, const char *file, int line);
71 };
72 
73 class ConnectionError : public Error
74 {
75 public:
ConnectionError(const std::string & message)76     ConnectionError(const std::string &message) : Error(message)
77     {
78     }
79 };
80 
81 class ProtocolError : public ConnectionError
82 {
83 public:
ProtocolError(const std::string & message)84     ProtocolError(const std::string &message) : ConnectionError(message)
85     {
86     }
87 };
88 
89 } // namespace xs
90 
91 #define XS_FAIL(MSG) throw xs::Error(MSG, "", __FILE__, __LINE__)
92 #define XS_CHECK(X)                                        \
93     do                                                     \
94     {                                                      \
95         if ((!false && (X)) ? false : true)                \
96             throw xs::Error(NULL, #X, __FILE__, __LINE__); \
97     } while (false)
98 #define XS_CHECK_MSG(X, MSG)                              \
99     do                                                    \
100     {                                                     \
101         if ((!false && (X)) ? false : true)               \
102             throw xs::Error(MSG, #X, __FILE__, __LINE__); \
103     } while (false)
104 
105 #endif // _XSDEFS_HPP
106