1be074227SIngo Weinhold // LaunchTesterHelper.h 2be074227SIngo Weinhold 3be074227SIngo Weinhold #ifndef LAUNCH_TESTER_HELPER_H 4be074227SIngo Weinhold #define LAUNCH_TESTER_HELPER_H 5be074227SIngo Weinhold 6be074227SIngo Weinhold #include <Application.h> 701cf44b7SIngo Weinhold #include <List.h> 8be074227SIngo Weinhold #include <Locker.h> 9be074227SIngo Weinhold #include <MessageQueue.h> 10be074227SIngo Weinhold #include <OS.h> 11be074227SIngo Weinhold 1201cf44b7SIngo Weinhold enum { 1301cf44b7SIngo Weinhold MSG_1 = 'msg1', 1401cf44b7SIngo Weinhold MSG_2 = 'msg2', 1501cf44b7SIngo Weinhold MSG_3 = 'msg3', 1601cf44b7SIngo Weinhold }; 1701cf44b7SIngo Weinhold 18be074227SIngo Weinhold // LaunchCaller 19be074227SIngo Weinhold class LaunchCaller { 20be074227SIngo Weinhold public: 2148bf189fSIngo Weinhold LaunchCaller() : fNext(NULL) {} 2248bf189fSIngo Weinhold virtual ~LaunchCaller() { if (fNext) delete fNext;} 2348bf189fSIngo Weinhold 2401cf44b7SIngo Weinhold virtual status_t operator()(const char *type, BList *messages, int32 argc, 2501cf44b7SIngo Weinhold const char **argv, team_id *team) = 0; 2601cf44b7SIngo Weinhold virtual int32 SupportsMessages() const { return 1; } 2701cf44b7SIngo Weinhold virtual bool SupportsArgv() const { return SupportsMessages() == 0; } 2801cf44b7SIngo Weinhold virtual bool SupportsRefs() const { return false; } 2901cf44b7SIngo Weinhold virtual const entry_ref *Ref() const { return NULL; } 3048bf189fSIngo Weinhold 3148bf189fSIngo Weinhold virtual LaunchCaller &Clone() 3248bf189fSIngo Weinhold { 3348bf189fSIngo Weinhold LaunchCaller *newCaller = CloneInternal(); 3448bf189fSIngo Weinhold newCaller->fNext = fNext; 3548bf189fSIngo Weinhold fNext = newCaller; 3648bf189fSIngo Weinhold return *newCaller; 3748bf189fSIngo Weinhold } 3848bf189fSIngo Weinhold 3948bf189fSIngo Weinhold virtual LaunchCaller *CloneInternal() = 0; 4048bf189fSIngo Weinhold 4148bf189fSIngo Weinhold private: 4248bf189fSIngo Weinhold LaunchCaller *fNext; 43be074227SIngo Weinhold }; 44be074227SIngo Weinhold 45be074227SIngo Weinhold // LaunchContext 46be074227SIngo Weinhold class LaunchContext { 47be074227SIngo Weinhold public: 4848bf189fSIngo Weinhold LaunchContext(); 49be074227SIngo Weinhold ~LaunchContext(); 50be074227SIngo Weinhold 5148bf189fSIngo Weinhold status_t operator()(LaunchCaller &caller, const char *type, team_id *team); 5248bf189fSIngo Weinhold status_t operator()(LaunchCaller &caller, const char *type, 5348bf189fSIngo Weinhold BList *messages, int32 argc, const char **argv, 5448bf189fSIngo Weinhold team_id *team); 55be074227SIngo Weinhold 56be074227SIngo Weinhold void HandleMessage(BMessage *message); 57be074227SIngo Weinhold 58be074227SIngo Weinhold void Terminate(); 59be074227SIngo Weinhold 60be074227SIngo Weinhold team_id TeamAt(int32 index) const; 61be074227SIngo Weinhold 62be074227SIngo Weinhold BMessage *NextMessageFrom(team_id team, int32 &cookie, 63be074227SIngo Weinhold bigtime_t *time = NULL); 6448bf189fSIngo Weinhold bool CheckNextMessage(LaunchCaller &caller, team_id team, int32 &cookie, 6548bf189fSIngo Weinhold uint32 what); 66*94737946SIngo Weinhold bool CheckMainArgsMessage(LaunchCaller &caller, team_id team, 67*94737946SIngo Weinhold int32 &cookie, const entry_ref *appRef, 68*94737946SIngo Weinhold bool useRef = true); 69*94737946SIngo Weinhold bool CheckMainArgsMessage(LaunchCaller &caller, team_id team, 70*94737946SIngo Weinhold int32 &cookie, const entry_ref *appRef, 71*94737946SIngo Weinhold int32 argc, const char **argv, 72*94737946SIngo Weinhold bool useRef = true); 7348bf189fSIngo Weinhold bool CheckArgvMessage(LaunchCaller &caller, team_id team, int32 &cookie, 7401cf44b7SIngo Weinhold const entry_ref *appRef, bool useRef = true); 7548bf189fSIngo Weinhold bool CheckArgvMessage(LaunchCaller &caller, team_id team, int32 &cookie, 7648bf189fSIngo Weinhold const entry_ref *appRef, 7701cf44b7SIngo Weinhold int32 argc, const char **argv, bool useRef = true); 7848bf189fSIngo Weinhold bool CheckArgvMessage(LaunchCaller &caller, team_id team, int32 &cookie, 7948bf189fSIngo Weinhold const entry_ref *appRef, const entry_ref *ref, 8048bf189fSIngo Weinhold int32 argc, const char **argv); 81*94737946SIngo Weinhold bool CheckArgsMessage(LaunchCaller &caller, team_id team, int32 &cookie, 82*94737946SIngo Weinhold const entry_ref *appRef, const entry_ref *ref, 83*94737946SIngo Weinhold int32 argc, const char **argv, uint32 messageCode); 8448bf189fSIngo Weinhold bool CheckMessageMessages(LaunchCaller &caller, team_id team, 8548bf189fSIngo Weinhold int32 &cookie); 8648bf189fSIngo Weinhold bool CheckMessageMessage(LaunchCaller &caller, team_id team, int32 &cookie, 8748bf189fSIngo Weinhold int32 index); 8848bf189fSIngo Weinhold bool CheckMessageMessage(LaunchCaller &caller, team_id team, int32 &cookie, 8901cf44b7SIngo Weinhold const BMessage *message); 9048bf189fSIngo Weinhold bool CheckRefsMessage(LaunchCaller &caller, team_id team, int32 &cookie); 9148bf189fSIngo Weinhold bool CheckRefsMessage(LaunchCaller &caller, team_id team, int32 &cookie, 9248bf189fSIngo Weinhold const entry_ref *refs, int32 count = 1); 9348bf189fSIngo Weinhold 9448bf189fSIngo Weinhold bool WaitForMessage(uint32 messageCode, bool fromNow = false, 9548bf189fSIngo Weinhold bigtime_t timeout = B_INFINITE_TIMEOUT); 9648bf189fSIngo Weinhold bool WaitForMessage(team_id team, uint32 messageCode, bool fromNow = false, 9748bf189fSIngo Weinhold bigtime_t timeout = B_INFINITE_TIMEOUT); 9801cf44b7SIngo Weinhold 9901cf44b7SIngo Weinhold BList *StandardMessages(); 10001cf44b7SIngo Weinhold 10101cf44b7SIngo Weinhold public: 10201cf44b7SIngo Weinhold static const char *kStandardArgv[]; 10301cf44b7SIngo Weinhold static const int32 kStandardArgc; 104be074227SIngo Weinhold 105be074227SIngo Weinhold private: 106be074227SIngo Weinhold class Message; 10748bf189fSIngo Weinhold class Sleeper; 108be074227SIngo Weinhold class AppInfo; 109be074227SIngo Weinhold 110be074227SIngo Weinhold private: 111be074227SIngo Weinhold AppInfo *AppInfoAt(int32 index) const; 112be074227SIngo Weinhold AppInfo *AppInfoFor(team_id team) const; 113be074227SIngo Weinhold AppInfo *CreateAppInfo(team_id team, const BMessenger *messenger = NULL); 114be074227SIngo Weinhold AppInfo *CreateAppInfo(BMessenger messenger); 115be074227SIngo Weinhold void TerminateApp(AppInfo *info); 116be074227SIngo Weinhold 11748bf189fSIngo Weinhold Message *FindMessage(uint32 messageCode); 11848bf189fSIngo Weinhold void AddSleeper(Sleeper *sleeper); 11948bf189fSIngo Weinhold void RemoveSleeper(Sleeper *sleeper); 12048bf189fSIngo Weinhold void NotifySleepers(uint32 messageCode); 12148bf189fSIngo Weinhold 122be074227SIngo Weinhold int32 Terminator(); 123be074227SIngo Weinhold 124be074227SIngo Weinhold static int32 AppThreadEntry(void *data); 125be074227SIngo Weinhold static int32 TerminatorEntry(void *data); 126be074227SIngo Weinhold 127be074227SIngo Weinhold private: 128be074227SIngo Weinhold BList fAppInfos; 12948bf189fSIngo Weinhold BList fSleepers; 130be074227SIngo Weinhold mutable BLocker fLock; 131be074227SIngo Weinhold thread_id fAppThread; 132be074227SIngo Weinhold thread_id fTerminator; 133be074227SIngo Weinhold bool fTerminating; 13401cf44b7SIngo Weinhold BList fStandardMessages; 135be074227SIngo Weinhold }; 136be074227SIngo Weinhold 137be074227SIngo Weinhold // RosterLaunchApp 138be074227SIngo Weinhold class RosterLaunchApp : public BApplication { 139be074227SIngo Weinhold public: 140be074227SIngo Weinhold RosterLaunchApp(const char *signature); 141be074227SIngo Weinhold 142be074227SIngo Weinhold virtual void MessageReceived(BMessage *message); 143be074227SIngo Weinhold 144be074227SIngo Weinhold BMessageQueue &MessageQueue(); 145be074227SIngo Weinhold 146be074227SIngo Weinhold void SetLaunchContext(LaunchContext *context); 147be074227SIngo Weinhold LaunchContext *GetLaunchContext() const; 148be074227SIngo Weinhold 149be074227SIngo Weinhold private: 150be074227SIngo Weinhold BMessageQueue fMessageQueue; 151be074227SIngo Weinhold LaunchContext *fLaunchContext; 152be074227SIngo Weinhold }; 153be074227SIngo Weinhold 154be074227SIngo Weinhold #endif // LAUNCH_TESTER_HELPER_H 155