2 * Copyright 2001-2015 Haiku, Inc. All rights reserved.
3 * Distributed under the terms of the MIT License.
6 * Erik Jaesler, erik@cgsoftware.com
21 class BDirectMessageTarget
;
25 // Port (Message Queue) Capacity
26 #define B_LOOPER_PORT_DEFAULT_CAPACITY 200
29 class BLooper
: public BHandler
{
31 BLooper(const char* name
= NULL
,
32 int32 priority
= B_NORMAL_PRIORITY
,
34 = B_LOOPER_PORT_DEFAULT_CAPACITY
);
38 BLooper(BMessage
* data
);
39 static BArchivable
* Instantiate(BMessage
* data
);
40 virtual status_t
Archive(BMessage
* data
, bool deep
= true) const;
42 // Message transmission
43 status_t
PostMessage(uint32 command
);
44 status_t
PostMessage(BMessage
* message
);
45 status_t
PostMessage(uint32 command
, BHandler
* handler
,
46 BHandler
* replyTo
= NULL
);
47 status_t
PostMessage(BMessage
* message
, BHandler
* handler
,
48 BHandler
* replyTo
= NULL
);
50 virtual void DispatchMessage(BMessage
* message
,
52 virtual void MessageReceived(BMessage
* message
);
53 BMessage
* CurrentMessage() const;
54 BMessage
* DetachCurrentMessage();
55 void DispatchExternalMessage(BMessage
* message
,
56 BHandler
* handler
, bool& _detached
);
57 BMessageQueue
* MessageQueue() const;
58 bool IsMessageWaiting() const;
61 void AddHandler(BHandler
* handler
);
62 bool RemoveHandler(BHandler
* handler
);
63 int32
CountHandlers() const;
64 BHandler
* HandlerAt(int32 index
) const;
65 int32
IndexOf(BHandler
* handler
) const;
67 BHandler
* PreferredHandler() const;
68 void SetPreferredHandler(BHandler
* handler
);
71 virtual thread_id
Run();
73 virtual bool QuitRequested();
76 bool IsLocked() const;
77 status_t
LockWithTimeout(bigtime_t timeout
);
78 thread_id
Thread() const;
80 static BLooper
* LooperForThread(thread_id thread
);
83 thread_id
LockingThread() const;
84 int32
CountLocks() const;
85 int32
CountLockRequests() const;
89 virtual BHandler
* ResolveSpecifier(BMessage
* message
, int32 index
,
90 BMessage
* specifier
, int32 what
,
91 const char* property
);
92 virtual status_t
GetSupportedSuites(BMessage
* data
);
94 // Message filters (also see BHandler).
95 virtual void AddCommonFilter(BMessageFilter
* filter
);
96 virtual bool RemoveCommonFilter(BMessageFilter
* filter
);
97 virtual void SetCommonFilterList(BList
* filters
);
98 BList
* CommonFilterList() const;
100 // Private or reserved
101 virtual status_t
Perform(perform_code d
, void* arg
);
104 // called from overridden task_looper
105 BMessage
* MessageFromPort(bigtime_t
= B_INFINITE_TIMEOUT
);
108 typedef BHandler _inherited
;
109 friend class BWindow
;
110 friend class BApplication
;
111 friend class BMessenger
;
113 friend class BHandler
;
114 friend class ::BPrivate::BLooperList
;
115 friend port_id
_get_looper_port_(const BLooper
* );
117 virtual void _ReservedLooper1();
118 virtual void _ReservedLooper2();
119 virtual void _ReservedLooper3();
120 virtual void _ReservedLooper4();
121 virtual void _ReservedLooper5();
122 virtual void _ReservedLooper6();
124 BLooper(const BLooper
&);
125 BLooper
& operator=(const BLooper
&);
127 BLooper(int32 priority
, port_id port
,
130 status_t
_PostMessage(BMessage
* msg
, BHandler
* handler
,
133 static status_t
_Lock(BLooper
* loop
, port_id port
,
135 static status_t
_LockComplete(BLooper
* loop
, int32 old
,
136 thread_id this_tid
, sem_id sem
,
138 void _InitData(const char* name
, int32 priority
,
139 port_id port
, int32 capacity
);
140 void AddMessage(BMessage
* msg
);
141 void _AddMessagePriv(BMessage
* msg
);
142 static status_t
_task0_(void* arg
);
144 void* ReadRawFromPort(int32
* code
,
145 bigtime_t timeout
= B_INFINITE_TIMEOUT
);
146 BMessage
* ReadMessageFromPort(
147 bigtime_t timeout
= B_INFINITE_TIMEOUT
);
148 virtual BMessage
* ConvertToMessage(void* raw
, int32 code
);
149 virtual void task_looper();
150 void _QuitRequested(BMessage
* msg
);
151 bool AssertLocked() const;
152 BHandler
* _TopLevelFilter(BMessage
* msg
, BHandler
* target
);
153 BHandler
* _HandlerFilter(BMessage
* msg
, BHandler
* target
);
154 BHandler
* _ApplyFilters(BList
* list
, BMessage
* msg
,
157 BHandler
* resolve_specifier(BHandler
* target
, BMessage
* msg
);
160 ::BPrivate::BDirectMessageTarget
* fDirectTarget
;
161 BMessage
* fLastMessage
;
170 BHandler
* fPreferred
;
172 BList
* fCommonFilters
;
176 uint32 _reserved
[11];