1 #ifndef _XSPROTOCOL_HPP
2 #define _XSPROTOCOL_HPP
3 /*-------------------------------------------------------------------------
4 * drawElements Quality Program Execution Server
5 * ---------------------------------------------
7 * Copyright 2014 The Android Open Source Project
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
13 * http://www.apache.org/licenses/LICENSE-2.0
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.
23 * \brief Execution Server Protocol.
24 *//*--------------------------------------------------------------------*/
37 PROTOCOL_VERSION = 18,
38 MESSAGE_HEADER_SIZE = 8,
40 // Times are in milliseconds.
41 KEEPALIVE_SEND_INTERVAL = 5000,
42 KEEPALIVE_TIMEOUT = 30000,
47 MESSAGETYPE_NONE = 0, //!< Not valid.
49 // Commands (from Client to ExecServer).
50 MESSAGETYPE_HELLO = 100, //!< First message from client, specifies the protocol version
51 MESSAGETYPE_TEST = 101, //!< Debug only
52 MESSAGETYPE_EXECUTE_BINARY = 111, //!< Request execution of a test package binary.
53 MESSAGETYPE_STOP_EXECUTION = 112, //!< Request cancellation of the currently executing binary.
55 // Responses (from ExecServer to Client)
56 MESSAGETYPE_PROCESS_STARTED = 200, //!< Requested process has started.
57 MESSAGETYPE_PROCESS_LAUNCH_FAILED = 201, //!< Requested process failed to launch.
58 MESSAGETYPE_PROCESS_FINISHED = 202, //!< Requested process has finished (for any reason).
59 MESSAGETYPE_PROCESS_LOG_DATA = 203, //!< Unprocessed log data from TestResults.qpa.
60 MESSAGETYPE_INFO = 204, //!< Generic info message from ExecServer (for debugging purposes).
62 MESSAGETYPE_KEEPALIVE = 102 //!< Keep-alive packet
72 Message (MessageType type_) : type(type_) {}
73 virtual ~Message (void) {}
75 virtual void write (std::vector<deUint8>& buf) const = DE_NULL;
77 static void parseHeader (const deUint8* data, size_t dataSize, MessageType& type, size_t& messageSize);
78 static void writeHeader (MessageType type, size_t messageSize, deUint8* dst, size_t bufSize);
81 void writeNoData (std::vector<deUint8>& buf) const;
83 Message (const Message& other);
84 Message& operator= (const Message& other);
87 // Simple messages without any data.
88 template <int MsgType>
89 class SimpleMessage : public Message
92 SimpleMessage (const deUint8* data, size_t dataSize) : Message((MessageType)MsgType) { DE_UNREF(data); XS_CHECK_MSG(dataSize == 0, "No payload expected"); }
93 SimpleMessage (void) : Message((MessageType)MsgType) {}
94 ~SimpleMessage (void) {}
96 void write (std::vector<deUint8>& buf) const { writeNoData(buf); }
99 typedef SimpleMessage<MESSAGETYPE_STOP_EXECUTION> StopExecutionMessage;
100 typedef SimpleMessage<MESSAGETYPE_PROCESS_STARTED> ProcessStartedMessage;
101 typedef SimpleMessage<MESSAGETYPE_KEEPALIVE> KeepAliveMessage;
103 class HelloMessage : public Message
108 HelloMessage (const deUint8* data, size_t dataSize);
109 HelloMessage (void) : Message(MESSAGETYPE_HELLO), version(PROTOCOL_VERSION) {}
110 ~HelloMessage (void) {}
112 void write (std::vector<deUint8>& buf) const;
115 class ExecuteBinaryMessage : public Message
121 std::string caseList;
123 ExecuteBinaryMessage (const deUint8* data, size_t dataSize);
124 ExecuteBinaryMessage (void) : Message(MESSAGETYPE_EXECUTE_BINARY) {}
125 ~ExecuteBinaryMessage (void) {};
127 void write (std::vector<deUint8>& buf) const;
130 class ProcessLogDataMessage : public Message
135 ProcessLogDataMessage (const deUint8* data, size_t dataSize);
136 ~ProcessLogDataMessage (void) {}
138 void write (std::vector<deUint8>& buf) const;
141 class ProcessLaunchFailedMessage : public Message
146 ProcessLaunchFailedMessage (const deUint8* data, size_t dataSize);
147 ProcessLaunchFailedMessage (const char* reason_) : Message(MESSAGETYPE_PROCESS_LAUNCH_FAILED), reason(reason_) {}
148 ~ProcessLaunchFailedMessage (void) {}
150 void write (std::vector<deUint8>& buf) const;
153 class ProcessFinishedMessage : public Message
158 ProcessFinishedMessage (const deUint8* data, size_t dataSize);
159 ProcessFinishedMessage (int exitCode_) : Message(MESSAGETYPE_PROCESS_FINISHED), exitCode(exitCode_) {}
160 ~ProcessFinishedMessage (void) {}
162 void write (std::vector<deUint8>& buf) const;
165 class InfoMessage : public Message
170 InfoMessage (const deUint8* data, size_t dataSize);
171 ~InfoMessage (void) {}
173 void write (std::vector<deUint8>& buf) const;
176 // For debug purposes only.
177 class TestMessage : public Message
182 TestMessage (const deUint8* data, size_t dataSize);
183 ~TestMessage (void) {}
185 void write (std::vector<deUint8>& buf) const;
190 #endif // _XSPROTOCOL_HPP