1e5c31af7Sopenharmony_ci#ifndef _TCUANDROIDEXECSERVICE_HPP
2e5c31af7Sopenharmony_ci#define _TCUANDROIDEXECSERVICE_HPP
3e5c31af7Sopenharmony_ci/*-------------------------------------------------------------------------
4e5c31af7Sopenharmony_ci * drawElements Quality Program Tester Core
5e5c31af7Sopenharmony_ci * ----------------------------------------
6e5c31af7Sopenharmony_ci *
7e5c31af7Sopenharmony_ci * Copyright 2014 The Android Open Source Project
8e5c31af7Sopenharmony_ci *
9e5c31af7Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
10e5c31af7Sopenharmony_ci * you may not use this file except in compliance with the License.
11e5c31af7Sopenharmony_ci * You may obtain a copy of the License at
12e5c31af7Sopenharmony_ci *
13e5c31af7Sopenharmony_ci *      http://www.apache.org/licenses/LICENSE-2.0
14e5c31af7Sopenharmony_ci *
15e5c31af7Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
16e5c31af7Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
17e5c31af7Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18e5c31af7Sopenharmony_ci * See the License for the specific language governing permissions and
19e5c31af7Sopenharmony_ci * limitations under the License.
20e5c31af7Sopenharmony_ci *
21e5c31af7Sopenharmony_ci *//*!
22e5c31af7Sopenharmony_ci * \file
23e5c31af7Sopenharmony_ci * \brief Android ExecService.
24e5c31af7Sopenharmony_ci *//*--------------------------------------------------------------------*/
25e5c31af7Sopenharmony_ci
26e5c31af7Sopenharmony_ci#include "tcuDefs.hpp"
27e5c31af7Sopenharmony_ci#include "deThread.hpp"
28e5c31af7Sopenharmony_ci#include "xsExecutionServer.hpp"
29e5c31af7Sopenharmony_ci#include "xsPosixFileReader.hpp"
30e5c31af7Sopenharmony_ci
31e5c31af7Sopenharmony_ci#include <jni.h>
32e5c31af7Sopenharmony_ci
33e5c31af7Sopenharmony_cinamespace tcu
34e5c31af7Sopenharmony_ci{
35e5c31af7Sopenharmony_cinamespace Android
36e5c31af7Sopenharmony_ci{
37e5c31af7Sopenharmony_ci
38e5c31af7Sopenharmony_cienum
39e5c31af7Sopenharmony_ci{
40e5c31af7Sopenharmony_ci	DEFAULT_PORT			= 50016,
41e5c31af7Sopenharmony_ci	DEFAULT_SOCKETFAMILY	= DE_SOCKETFAMILY_INET4
42e5c31af7Sopenharmony_ci};
43e5c31af7Sopenharmony_ci
44e5c31af7Sopenharmony_ciclass TestProcess : public xs::TestProcess
45e5c31af7Sopenharmony_ci{
46e5c31af7Sopenharmony_cipublic:
47e5c31af7Sopenharmony_ci							TestProcess			(JavaVM* vm, jobject context);
48e5c31af7Sopenharmony_ci							~TestProcess		(void);
49e5c31af7Sopenharmony_ci
50e5c31af7Sopenharmony_ci	virtual void			start				(const char* name, const char* params, const char* workingDir, const char* caseList);
51e5c31af7Sopenharmony_ci	virtual void			terminate			(void);
52e5c31af7Sopenharmony_ci	virtual void			cleanup				(void);
53e5c31af7Sopenharmony_ci
54e5c31af7Sopenharmony_ci	virtual bool			isRunning			(void);
55e5c31af7Sopenharmony_ci	virtual int				getExitCode			(void) const;
56e5c31af7Sopenharmony_ci
57e5c31af7Sopenharmony_ci	virtual int				readTestLog			(deUint8* dst, int numBytes);
58e5c31af7Sopenharmony_ci	virtual int				readInfoLog			(deUint8* dst, int numBytes);
59e5c31af7Sopenharmony_ci
60e5c31af7Sopenharmony_ciprivate:
61e5c31af7Sopenharmony_ci	JNIEnv*					getCurrentThreadEnv	(void);
62e5c31af7Sopenharmony_ci
63e5c31af7Sopenharmony_ci	JavaVM*					m_vm;
64e5c31af7Sopenharmony_ci	jclass					m_remoteCls;
65e5c31af7Sopenharmony_ci	jobject					m_remote;
66e5c31af7Sopenharmony_ci	jmethodID				m_start;
67e5c31af7Sopenharmony_ci	jmethodID				m_kill;
68e5c31af7Sopenharmony_ci	jmethodID				m_isRunning;
69e5c31af7Sopenharmony_ci
70e5c31af7Sopenharmony_ci	deUint64				m_launchTime;
71e5c31af7Sopenharmony_ci	deUint64				m_lastQueryTime;
72e5c31af7Sopenharmony_ci	bool					m_lastRunningStatus;
73e5c31af7Sopenharmony_ci	xs::posix::FileReader	m_logReader;
74e5c31af7Sopenharmony_ci};
75e5c31af7Sopenharmony_ci
76e5c31af7Sopenharmony_ciclass ExecutionServer : public xs::ExecutionServer
77e5c31af7Sopenharmony_ci{
78e5c31af7Sopenharmony_cipublic:
79e5c31af7Sopenharmony_ci							ExecutionServer			(JavaVM* vm, xs::TestProcess* testProcess, deSocketFamily family, int port, RunMode runMode);
80e5c31af7Sopenharmony_ci	xs::ConnectionHandler*	createHandler			(de::Socket* socket, const de::SocketAddress& clientAddress);
81e5c31af7Sopenharmony_ci
82e5c31af7Sopenharmony_ciprivate:
83e5c31af7Sopenharmony_ci	JavaVM*					m_vm;
84e5c31af7Sopenharmony_ci};
85e5c31af7Sopenharmony_ci
86e5c31af7Sopenharmony_ciclass ConnectionHandler : public xs::ExecutionRequestHandler
87e5c31af7Sopenharmony_ci{
88e5c31af7Sopenharmony_cipublic:
89e5c31af7Sopenharmony_ci							ConnectionHandler		(JavaVM* vm, xs::ExecutionServer* server, de::Socket* socket);
90e5c31af7Sopenharmony_ci	void					run						(void);
91e5c31af7Sopenharmony_ci
92e5c31af7Sopenharmony_ciprivate:
93e5c31af7Sopenharmony_ci	JavaVM*					m_vm;
94e5c31af7Sopenharmony_ci};
95e5c31af7Sopenharmony_ci
96e5c31af7Sopenharmony_ciclass ServerThread : public de::Thread
97e5c31af7Sopenharmony_ci{
98e5c31af7Sopenharmony_cipublic:
99e5c31af7Sopenharmony_ci							ServerThread		(JavaVM* vm, xs::TestProcess* testProcess, deSocketFamily family, int port);
100e5c31af7Sopenharmony_ci
101e5c31af7Sopenharmony_ci	void					run					(void);
102e5c31af7Sopenharmony_ci	void					stop				(void);
103e5c31af7Sopenharmony_ci
104e5c31af7Sopenharmony_ciprivate:
105e5c31af7Sopenharmony_ci	ExecutionServer			m_server;
106e5c31af7Sopenharmony_ci};
107e5c31af7Sopenharmony_ci
108e5c31af7Sopenharmony_ciclass ExecService
109e5c31af7Sopenharmony_ci{
110e5c31af7Sopenharmony_cipublic:
111e5c31af7Sopenharmony_ci							ExecService			(JavaVM* vm, jobject context, int port, deSocketFamily family = (deSocketFamily)DEFAULT_SOCKETFAMILY);
112e5c31af7Sopenharmony_ci							~ExecService		(void);
113e5c31af7Sopenharmony_ci
114e5c31af7Sopenharmony_ci	void					start				(void);
115e5c31af7Sopenharmony_ci	void					stop				(void);
116e5c31af7Sopenharmony_ci
117e5c31af7Sopenharmony_ciprivate:
118e5c31af7Sopenharmony_ci							ExecService			(const ExecService& other);
119e5c31af7Sopenharmony_ci	ExecService&			operator=			(const ExecService& other);
120e5c31af7Sopenharmony_ci
121e5c31af7Sopenharmony_ci	TestProcess				m_process;
122e5c31af7Sopenharmony_ci	ServerThread			m_thread;
123e5c31af7Sopenharmony_ci};
124e5c31af7Sopenharmony_ci
125e5c31af7Sopenharmony_ci} // Android
126e5c31af7Sopenharmony_ci} // tcu
127e5c31af7Sopenharmony_ci
128e5c31af7Sopenharmony_ci#endif // _TCUANDROIDEXECSERVICE_HPP
129