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