xref: /haiku/src/tests/kits/app/common/AppRunner.h (revision a46169b50939085c733d30580437ea5073476767)
1cb19e5d2SIngo Weinhold // AppRunner.h
2cb19e5d2SIngo Weinhold 
3cb19e5d2SIngo Weinhold #ifndef APP_RUNNER_H
4cb19e5d2SIngo Weinhold #define APP_RUNNER_H
5cb19e5d2SIngo Weinhold 
6cb19e5d2SIngo Weinhold #include <stdio.h>
7cb19e5d2SIngo Weinhold 
8cb19e5d2SIngo Weinhold #include <DataIO.h>
9*a46169b5SIngo Weinhold #include <Entry.h>
10cb19e5d2SIngo Weinhold #include <Locker.h>
11cb19e5d2SIngo Weinhold 
12cb19e5d2SIngo Weinhold class AppRunner {
13cb19e5d2SIngo Weinhold public:
14cb19e5d2SIngo Weinhold 	AppRunner(bool requestQuitOnDestruction = false);
15cb19e5d2SIngo Weinhold 	~AppRunner();
16cb19e5d2SIngo Weinhold 
17cb19e5d2SIngo Weinhold 	status_t Run(const char *command, const char *args = NULL,
18cb19e5d2SIngo Weinhold 				 bool findCommand = true);
19cb19e5d2SIngo Weinhold 	bool HasQuitted();
20cb19e5d2SIngo Weinhold 	void WaitFor(bool requestQuit = false);
21cb19e5d2SIngo Weinhold 	team_id Team();
22*a46169b5SIngo Weinhold 	port_id AppLooperPort();
23*a46169b5SIngo Weinhold 	status_t GetRef(entry_ref *ref);
24cb19e5d2SIngo Weinhold 	status_t RequestQuit();
25cb19e5d2SIngo Weinhold 
26cb19e5d2SIngo Weinhold 	status_t GetOutput(BString *buffer);
27cb19e5d2SIngo Weinhold 	ssize_t ReadOutput(void *buffer, size_t size);
28cb19e5d2SIngo Weinhold 	ssize_t ReadOutputAt(off_t position, void *buffer, size_t size);
29cb19e5d2SIngo Weinhold 
30cb19e5d2SIngo Weinhold private:
31cb19e5d2SIngo Weinhold 	static int32 _ReaderEntry(void *data);
32cb19e5d2SIngo Weinhold 	int32 _ReaderLoop();
33cb19e5d2SIngo Weinhold 
34cb19e5d2SIngo Weinhold 	static bool _LockTeamPort();
35cb19e5d2SIngo Weinhold 	static void _UnlockTeamPort();
36cb19e5d2SIngo Weinhold 	static port_id _ReadPortID(BMessenger &messenger);
37cb19e5d2SIngo Weinhold 
38cb19e5d2SIngo Weinhold private:
39cb19e5d2SIngo Weinhold 	BLocker		fOutputLock;
40cb19e5d2SIngo Weinhold 	port_id		fRemotePort;
41cb19e5d2SIngo Weinhold 	BMallocIO	fOutput;
42cb19e5d2SIngo Weinhold 	thread_id	fReader;
43cb19e5d2SIngo Weinhold 	team_id		fTeam;
44*a46169b5SIngo Weinhold 	entry_ref	fRef;
45cb19e5d2SIngo Weinhold 	BMessenger	fMessenger;
46cb19e5d2SIngo Weinhold 	bool		fRequestQuitOnDestruction;
47cb19e5d2SIngo Weinhold 
48cb19e5d2SIngo Weinhold 	static port_id	fTeamPort;
49cb19e5d2SIngo Weinhold 	static BLocker	fTeamPortLock;
50cb19e5d2SIngo Weinhold };
51cb19e5d2SIngo Weinhold 
52c2e8b557SIngo Weinhold status_t find_test_app(const char *testApp, BString *path);
53c2e8b557SIngo Weinhold status_t find_test_app(const char *testApp, entry_ref *ref);
54c2e8b557SIngo Weinhold 
55cb19e5d2SIngo Weinhold #endif	// APP_RUNNER_H
56