2005-07-23 22:30:48 +04:00
|
|
|
/*
|
|
|
|
* Copyright 2005, Haiku.
|
|
|
|
* Distributed under the terms of the MIT License.
|
|
|
|
*
|
|
|
|
* Authors:
|
|
|
|
* Axel Dörfler, axeld@pinc-software.de
|
|
|
|
*/
|
|
|
|
#ifndef MESSAGE_LOOPER_H
|
|
|
|
#define MESSAGE_LOOPER_H
|
|
|
|
|
|
|
|
|
|
|
|
#include <PortLink.h>
|
|
|
|
#include <Locker.h>
|
|
|
|
#include <OS.h>
|
|
|
|
|
|
|
|
|
|
|
|
class MessageLooper : public BLocker {
|
|
|
|
public:
|
|
|
|
MessageLooper(const char* name);
|
|
|
|
virtual ~MessageLooper();
|
|
|
|
|
|
|
|
virtual bool Run();
|
|
|
|
virtual void Quit();
|
|
|
|
|
2005-11-25 16:49:29 +03:00
|
|
|
status_t PostMessage(int32 code);
|
2005-07-23 22:30:48 +04:00
|
|
|
thread_id Thread() const { return fThread; }
|
2005-07-26 01:53:48 +04:00
|
|
|
bool IsQuitting() const { return fQuitting; }
|
2005-11-25 16:49:29 +03:00
|
|
|
sem_id DeathSemaphore() const { return fDeathSemaphore; }
|
2005-07-26 01:53:48 +04:00
|
|
|
|
2005-07-26 01:08:34 +04:00
|
|
|
virtual port_id MessagePort() const = 0;
|
2005-07-23 22:30:48 +04:00
|
|
|
|
2005-11-25 16:49:29 +03:00
|
|
|
static status_t WaitForQuit(sem_id semaphore,
|
|
|
|
bigtime_t timeout = B_INFINITE_TIMEOUT);
|
|
|
|
|
2005-07-23 22:30:48 +04:00
|
|
|
private:
|
2005-07-24 21:13:02 +04:00
|
|
|
virtual void _PrepareQuit();
|
2005-07-23 22:30:48 +04:00
|
|
|
virtual void _GetLooperName(char* name, size_t length);
|
|
|
|
virtual void _DispatchMessage(int32 code, BPrivate::LinkReceiver &link);
|
|
|
|
virtual void _MessageLooper();
|
|
|
|
|
2005-07-26 01:53:48 +04:00
|
|
|
protected:
|
2005-07-23 22:30:48 +04:00
|
|
|
static int32 _message_thread(void *_looper);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
thread_id fThread;
|
|
|
|
BPrivate::PortLink fLink;
|
|
|
|
bool fQuitting;
|
2005-11-25 16:49:29 +03:00
|
|
|
sem_id fDeathSemaphore;
|
2005-07-23 22:30:48 +04:00
|
|
|
};
|
|
|
|
|
2005-07-26 01:08:34 +04:00
|
|
|
static const int32 kMsgQuitLooper = 'quit';
|
2005-07-24 21:13:02 +04:00
|
|
|
|
2005-07-23 22:30:48 +04:00
|
|
|
#endif /* MESSAGE_LOOPER_H */
|