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 10 class CommonTestApp; 11 12 class EventHandler { 13 public: 14 EventHandler() {} 15 virtual ~EventHandler() {} 16 17 virtual void HandleEvent(CommonTestApp *app) = 0; 18 }; 19 20 class CommonTestApp : public BApplication { 21 public: 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 40 private: 41 static int32 _EventThreadEntry(void *data); 42 int32 _EventLoop(); 43 44 private: 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 54 status_t init_connection(); 55 void report(const char *format,...); 56 void vreport(const char *format, va_list args); 57 58 #endif // COMMON_TEST_APP_H 59