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<deUint8>		ByteBuffer;
62 typedef de::BlockBuffer<deUint8>	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 	Error (const char* message, const char* expr, const char* file, int line);
69 };
70 
71 class ConnectionError : public Error
72 {
73 public:
ConnectionError(const std::string & message)74 	ConnectionError (const std::string& message) : Error(message) {}
75 };
76 
77 class ProtocolError : public ConnectionError
78 {
79 public:
ProtocolError(const std::string & message)80 	ProtocolError (const std::string& message) : ConnectionError(message) {}
81 };
82 
83 } // xs
84 
85 #define XS_FAIL(MSG)			throw xs::Error(MSG, "", __FILE__, __LINE__)
86 #define XS_CHECK(X)				do { if ((!deGetFalse() && (X)) ? DE_FALSE : DE_TRUE) throw xs::Error(NULL, #X, __FILE__, __LINE__); } while(deGetFalse())
87 #define XS_CHECK_MSG(X, MSG)	do { if ((!deGetFalse() && (X)) ? DE_FALSE : DE_TRUE) throw xs::Error(MSG, #X, __FILE__, __LINE__); } while(deGetFalse())
88 
89 #endif // _XSDEFS_HPP
90