1// CommonTestApp.h
2
3#ifndef COMMON_TEST_APP_H
4#define COMMON_TEST_APP_H
5
6#include <stdarg.h>
7
8#include <Application.h>
9
10class CommonTestApp;
11
12class EventHandler {
13public:
14	EventHandler() {}
15	virtual ~EventHandler() {}
16
17	virtual void HandleEvent(CommonTestApp *app) = 0;
18};
19
20class CommonTestApp : public BApplication {
21public:
22	CommonTestApp(const char *signature);
23	CommonTestApp(const char *signature, status_t *result);
24	virtual ~CommonTestApp();
25
26	virtual void ArgvReceived(int32 argc, char **argv);
27	virtual void MessageReceived(BMessage *message);
28	virtual bool QuitRequested();
29	virtual void ReadyToRun();
30	thread_id Run();
31
32	void SetQuittingPolicy(bool onSecondTry);
33	void SetReportDestruction(bool reportDestruction);
34
35	status_t RunEventThread(bigtime_t delay, int32 count,
36							EventHandler *handler);
37
38	void SetMessageHandler(BHandler *handler);
39
40private:
41	static int32 _EventThreadEntry(void *data);
42	int32 _EventLoop();
43
44private:
45	bool			fQuitOnSecondTry;
46	thread_id		fEventThread;
47	bigtime_t		fEventDelay;
48	int32			fEventCount;
49	EventHandler	*fEventHandler;
50	BHandler		*fMessageHandler;
51	bool			fReportDestruction;
52};
53
54status_t init_connection();
55void report(const char *format,...);
56void vreport(const char *format, va_list args);
57
58#endif	// COMMON_TEST_APP_H
59