1#ifndef _TCUANDROIDEXECSERVICE_HPP
2#define _TCUANDROIDEXECSERVICE_HPP
3/*-------------------------------------------------------------------------
4 * drawElements Quality Program Tester Core
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 Android ExecService.
24 *//*--------------------------------------------------------------------*/
25
26#include "tcuDefs.hpp"
27#include "deThread.hpp"
28#include "xsExecutionServer.hpp"
29#include "xsPosixFileReader.hpp"
30
31#include <jni.h>
32
33namespace tcu
34{
35namespace Android
36{
37
38enum
39{
40	DEFAULT_PORT			= 50016,
41	DEFAULT_SOCKETFAMILY	= DE_SOCKETFAMILY_INET4
42};
43
44class TestProcess : public xs::TestProcess
45{
46public:
47							TestProcess			(JavaVM* vm, jobject context);
48							~TestProcess		(void);
49
50	virtual void			start				(const char* name, const char* params, const char* workingDir, const char* caseList);
51	virtual void			terminate			(void);
52	virtual void			cleanup				(void);
53
54	virtual bool			isRunning			(void);
55	virtual int				getExitCode			(void) const;
56
57	virtual int				readTestLog			(deUint8* dst, int numBytes);
58	virtual int				readInfoLog			(deUint8* dst, int numBytes);
59
60private:
61	JNIEnv*					getCurrentThreadEnv	(void);
62
63	JavaVM*					m_vm;
64	jclass					m_remoteCls;
65	jobject					m_remote;
66	jmethodID				m_start;
67	jmethodID				m_kill;
68	jmethodID				m_isRunning;
69
70	deUint64				m_launchTime;
71	deUint64				m_lastQueryTime;
72	bool					m_lastRunningStatus;
73	xs::posix::FileReader	m_logReader;
74};
75
76class ExecutionServer : public xs::ExecutionServer
77{
78public:
79							ExecutionServer			(JavaVM* vm, xs::TestProcess* testProcess, deSocketFamily family, int port, RunMode runMode);
80	xs::ConnectionHandler*	createHandler			(de::Socket* socket, const de::SocketAddress& clientAddress);
81
82private:
83	JavaVM*					m_vm;
84};
85
86class ConnectionHandler : public xs::ExecutionRequestHandler
87{
88public:
89							ConnectionHandler		(JavaVM* vm, xs::ExecutionServer* server, de::Socket* socket);
90	void					run						(void);
91
92private:
93	JavaVM*					m_vm;
94};
95
96class ServerThread : public de::Thread
97{
98public:
99							ServerThread		(JavaVM* vm, xs::TestProcess* testProcess, deSocketFamily family, int port);
100
101	void					run					(void);
102	void					stop				(void);
103
104private:
105	ExecutionServer			m_server;
106};
107
108class ExecService
109{
110public:
111							ExecService			(JavaVM* vm, jobject context, deSocketFamily family = (deSocketFamily)DEFAULT_SOCKETFAMILY, int port = DEFAULT_PORT);
112							~ExecService		(void);
113
114	void					start				(void);
115	void					stop				(void);
116
117private:
118							ExecService			(const ExecService& other);
119	ExecService&			operator=			(const ExecService& other);
120
121	TestProcess				m_process;
122	ServerThread			m_thread;
123};
124
125} // Android
126} // tcu
127
128#endif // _TCUANDROIDEXECSERVICE_HPP
129