Some cleanup.

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@17840 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2006-06-14 18:31:15 +00:00
parent 7477c792d5
commit a6c9722d73
2 changed files with 139 additions and 226 deletions
+8 -48
View File
@@ -1,46 +1,17 @@
//------------------------------------------------------------------------------ /*
// Copyright (c) 2001-2002, OpenBeOS * Copyright 2001-2006, Haiku Inc. All Rights Reserved.
// * Distributed under the terms of the MIT License.
// Permission is hereby granted, free of charge, to any person obtaining a *
// copy of this software and associated documentation files (the "Software"), * Authors:
// to deal in the Software without restriction, including without limitation * Erik Jaesler ([email protected])
// the rights to use, copy, modify, merge, publish, distribute, sublicense, */
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
// File Name: Handler.cpp
// Author: Erik Jaesler ([email protected])
// Description: BHandler defines the message-handling protocol.
// MessageReceived() is its lynchpin.
//------------------------------------------------------------------------------
#ifndef _HANDLER_H #ifndef _HANDLER_H
#define _HANDLER_H #define _HANDLER_H
// Standard Includes -----------------------------------------------------------
// System Includes -------------------------------------------------------------
#include <BeBuild.h> #include <BeBuild.h>
#include <Archivable.h> #include <Archivable.h>
// Project Includes ------------------------------------------------------------
// Local Includes --------------------------------------------------------------
// Local Defines ---------------------------------------------------------------
// Globals ---------------------------------------------------------------------
class BLooper; class BLooper;
class BMessageFilter; class BMessageFilter;
@@ -52,9 +23,8 @@ class _ObserverList;
#define B_OBSERVE_ORIGINAL_WHAT "be:observe_orig_what" #define B_OBSERVE_ORIGINAL_WHAT "be:observe_orig_what"
const uint32 B_OBSERVER_OBSERVE_ALL = 0xffffffff; const uint32 B_OBSERVER_OBSERVE_ALL = 0xffffffff;
// BHandler class --------------------------------------------------------------
class BHandler : public BArchivable {
class BHandler : public BArchivable {
public: public:
BHandler(const char* name = NULL); BHandler(const char* name = NULL);
virtual ~BHandler(); virtual ~BHandler();
@@ -110,7 +80,6 @@ public:
virtual void SendNotices(uint32 what, const BMessage* = 0); virtual void SendNotices(uint32 what, const BMessage* = 0);
bool IsWatched() const; bool IsWatched() const;
//----- Private or reserved -----------------------------------------
private: private:
typedef BArchivable _inherited; typedef BArchivable _inherited;
friend inline int32 _get_object_token_(const BHandler* ); friend inline int32 _get_object_token_(const BHandler* );
@@ -135,14 +104,5 @@ private:
_ObserverList* fObserverList; _ObserverList* fObserverList;
uint32 _reserved[3]; uint32 _reserved[3];
}; };
//------------------------------------------------------------------------------
#endif // _HANDLER_H #endif // _HANDLER_H
/*
* $Log $
*
* $Id $
*
*/
+131 -178
View File
@@ -1,138 +1,103 @@
//------------------------------------------------------------------------------ /*
// Copyright (c) 2001-2002, OpenBeOS * Copyright 2001-2006, Haiku Inc. All Rights Reserved.
// * Distributed under the terms of the MIT License.
// Permission is hereby granted, free of charge, to any person obtaining a *
// copy of this software and associated documentation files (the "Software"), * Authors:
// to deal in the Software without restriction, including without limitation * Erik Jaesler ([email protected])
// the rights to use, copy, modify, merge, publish, distribute, sublicense, */
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
// File Name: Looper.h
// Author(s): Erik Jaesler ([email protected])
// DarkWyrm ([email protected])
// Description: BLooper class spawns a thread that runs a message loop.
//------------------------------------------------------------------------------
#ifndef _LOOPER_H #ifndef _LOOPER_H
#define _LOOPER_H #define _LOOPER_H
// Standard Includes -----------------------------------------------------------
// System Includes -------------------------------------------------------------
#include <BeBuild.h> #include <BeBuild.h>
#include <Handler.h> #include <Handler.h>
#include <List.h> #include <List.h>
#include <OS.h> #include <OS.h>
// Project Includes ------------------------------------------------------------
// Local Includes --------------------------------------------------------------
// Local Defines ---------------------------------------------------------------
// Globals ---------------------------------------------------------------------
class BMessage; class BMessage;
class BMessageQueue; class BMessageQueue;
namespace BPrivate { namespace BPrivate {
class BLooperList; class BLooperList;
} }
struct _loop_data_;
// Port (Message Queue) Capacity ----------------------------------------------- // Port (Message Queue) Capacity
#define B_LOOPER_PORT_DEFAULT_CAPACITY 100 #define B_LOOPER_PORT_DEFAULT_CAPACITY 100
// BLooper class ---------------------------------------------------------------
class BLooper : public BHandler { class BLooper : public BHandler {
public: public:
BLooper(const char* name = NULL, BLooper(const char* name = NULL,
int32 priority = B_NORMAL_PRIORITY, int32 priority = B_NORMAL_PRIORITY,
int32 port_capacity = B_LOOPER_PORT_DEFAULT_CAPACITY); int32 port_capacity = B_LOOPER_PORT_DEFAULT_CAPACITY);
virtual ~BLooper(); virtual ~BLooper();
// Archiving // Archiving
BLooper(BMessage* data); BLooper(BMessage* data);
static BArchivable* Instantiate(BMessage* data); static BArchivable* Instantiate(BMessage* data);
virtual status_t Archive(BMessage* data, bool deep = true) const; virtual status_t Archive(BMessage* data, bool deep = true) const;
// Message transmission // Message transmission
status_t PostMessage(uint32 command); status_t PostMessage(uint32 command);
status_t PostMessage(BMessage* message); status_t PostMessage(BMessage* message);
status_t PostMessage(uint32 command, status_t PostMessage(uint32 command, BHandler* handler,
BHandler* handler, BHandler* reply_to = NULL);
BHandler* reply_to = NULL); status_t PostMessage(BMessage* message, BHandler* handler,
status_t PostMessage(BMessage* message, BHandler* reply_to = NULL);
BHandler* handler,
BHandler* reply_to = NULL);
virtual void DispatchMessage(BMessage* message, BHandler* handler); virtual void DispatchMessage(BMessage* message, BHandler* handler);
virtual void MessageReceived(BMessage* msg); virtual void MessageReceived(BMessage* msg);
BMessage* CurrentMessage() const; BMessage* CurrentMessage() const;
BMessage* DetachCurrentMessage(); BMessage* DetachCurrentMessage();
BMessageQueue* MessageQueue() const; BMessageQueue* MessageQueue() const;
bool IsMessageWaiting() const; bool IsMessageWaiting() const;
// Message handlers // Message handlers
void AddHandler(BHandler* handler); void AddHandler(BHandler* handler);
bool RemoveHandler(BHandler* handler); bool RemoveHandler(BHandler* handler);
int32 CountHandlers() const; int32 CountHandlers() const;
BHandler* HandlerAt(int32 index) const; BHandler* HandlerAt(int32 index) const;
int32 IndexOf(BHandler* handler) const; int32 IndexOf(BHandler* handler) const;
BHandler* PreferredHandler() const; BHandler* PreferredHandler() const;
void SetPreferredHandler(BHandler* handler); void SetPreferredHandler(BHandler* handler);
// Loop control // Loop control
virtual thread_id Run(); virtual thread_id Run();
virtual void Quit(); virtual void Quit();
virtual bool QuitRequested(); virtual bool QuitRequested();
bool Lock(); bool Lock();
void Unlock(); void Unlock();
bool IsLocked() const; bool IsLocked() const;
status_t LockWithTimeout(bigtime_t timeout); status_t LockWithTimeout(bigtime_t timeout);
thread_id Thread() const; thread_id Thread() const;
team_id Team() const; team_id Team() const;
static BLooper* LooperForThread(thread_id tid); static BLooper* LooperForThread(thread_id tid);
// Loop debugging // Loop debugging
thread_id LockingThread() const; thread_id LockingThread() const;
int32 CountLocks() const; int32 CountLocks() const;
int32 CountLockRequests() const; int32 CountLockRequests() const;
sem_id Sem() const; sem_id Sem() const;
// Scripting // Scripting
virtual BHandler* ResolveSpecifier(BMessage* msg, virtual BHandler* ResolveSpecifier(BMessage* msg, int32 index,
int32 index, BMessage* specifier, int32 form,
BMessage* specifier, const char* property);
int32 form, virtual status_t GetSupportedSuites(BMessage* data);
const char* property);
virtual status_t GetSupportedSuites(BMessage* data);
// Message filters (also see BHandler).
virtual void AddCommonFilter(BMessageFilter* filter);
virtual bool RemoveCommonFilter(BMessageFilter* filter);
virtual void SetCommonFilterList(BList* filters);
BList* CommonFilterList() const;
// Private or reserved --------------------------------------------------------- // Message filters (also see BHandler).
virtual status_t Perform(perform_code d, void* arg); virtual void AddCommonFilter(BMessageFilter* filter);
virtual bool RemoveCommonFilter(BMessageFilter* filter);
virtual void SetCommonFilterList(BList* filters);
BList* CommonFilterList() const;
// Private or reserved ---------------------------------------------------------
virtual status_t Perform(perform_code d, void* arg);
protected: protected:
// called from overridden task_looper // called from overridden task_looper
BMessage* MessageFromPort(bigtime_t = B_INFINITE_TIMEOUT); BMessage* MessageFromPort(bigtime_t = B_INFINITE_TIMEOUT);
private: private:
typedef BHandler _inherited; typedef BHandler _inherited;
@@ -146,92 +111,80 @@ private:
friend status_t _safe_get_server_token_(const BLooper* , int32* ); friend status_t _safe_get_server_token_(const BLooper* , int32* );
friend team_id _find_cur_team_id_(); friend team_id _find_cur_team_id_();
virtual void _ReservedLooper1(); virtual void _ReservedLooper1();
virtual void _ReservedLooper2(); virtual void _ReservedLooper2();
virtual void _ReservedLooper3(); virtual void _ReservedLooper3();
virtual void _ReservedLooper4(); virtual void _ReservedLooper4();
virtual void _ReservedLooper5(); virtual void _ReservedLooper5();
virtual void _ReservedLooper6(); virtual void _ReservedLooper6();
BLooper(const BLooper&); BLooper(const BLooper&);
BLooper& operator=(const BLooper&); BLooper& operator=(const BLooper&);
BLooper(int32 priority, port_id port, const char* name); BLooper(int32 priority, port_id port,
const char* name);
status_t _PostMessage(BMessage* msg, status_t _PostMessage(BMessage* msg, BHandler* handler,
BHandler* handler, BHandler* reply_to);
BHandler* reply_to);
static status_t _Lock(BLooper* loop, static status_t _Lock(BLooper* loop, port_id port,
port_id port, bigtime_t timeout);
bigtime_t timeout); static status_t _LockComplete(BLooper* loop, int32 old,
static status_t _LockComplete(BLooper* loop, thread_id this_tid, sem_id sem,
int32 old, bigtime_t timeout);
thread_id this_tid, void InitData();
sem_id sem, void InitData(const char* name, int32 prio, int32 capacity);
bigtime_t timeout); void AddMessage(BMessage* msg);
void InitData(); void _AddMessagePriv(BMessage* msg);
void InitData(const char* name, int32 prio, int32 capacity); static status_t _task0_(void* arg);
void AddMessage(BMessage* msg);
void _AddMessagePriv(BMessage* msg);
static status_t _task0_(void* arg);
void* ReadRawFromPort(int32* code, void* ReadRawFromPort(int32* code,
bigtime_t tout = B_INFINITE_TIMEOUT); bigtime_t tout = B_INFINITE_TIMEOUT);
BMessage* ReadMessageFromPort(bigtime_t tout = B_INFINITE_TIMEOUT); BMessage* ReadMessageFromPort(bigtime_t tout = B_INFINITE_TIMEOUT);
virtual BMessage* ConvertToMessage(void* raw, int32 code); virtual BMessage* ConvertToMessage(void* raw, int32 code);
virtual void task_looper(); virtual void task_looper();
void _QuitRequested(BMessage* msg); void _QuitRequested(BMessage* msg);
bool AssertLocked() const; bool AssertLocked() const;
BHandler* _TopLevelFilter(BMessage* msg, BHandler* target); BHandler* _TopLevelFilter(BMessage* msg, BHandler* target);
BHandler* _HandlerFilter(BMessage* msg, BHandler* target); BHandler* _HandlerFilter(BMessage* msg, BHandler* target);
BHandler* _ApplyFilters(BList* list, BMessage* msg, BHandler* _ApplyFilters(BList* list, BMessage* msg,
BHandler* target); BHandler* target);
void check_lock(); void check_lock();
BHandler* resolve_specifier(BHandler* target, BMessage* msg); BHandler* resolve_specifier(BHandler* target, BMessage* msg);
void UnlockFully(); void UnlockFully();
static uint32 sLooperID; static uint32 sLooperID;
static team_id sTeamID; static team_id sTeamID;
// DEPRECATED // DEPRECATED
static void AddLooper(BLooper* l); static void AddLooper(BLooper* l);
static bool IsLooperValid(const BLooper* l); static bool IsLooperValid(const BLooper* l);
static void RemoveLooper(BLooper* l); static void RemoveLooper(BLooper* l);
static void GetLooperList(BList* list); static void GetLooperList(BList* list);
static BLooper* LooperForName(const char* name); static BLooper* LooperForName(const char* name);
static BLooper* LooperForPort(port_id port); static BLooper* LooperForPort(port_id port);
uint32 fLooperID; uint32 fLooperID;
BMessageQueue* fQueue; BMessageQueue* fQueue;
BMessage* fLastMessage; BMessage* fLastMessage;
port_id fMsgPort; port_id fMsgPort;
long fAtomicCount; long fAtomicCount;
sem_id fLockSem; sem_id fLockSem;
long fOwnerCount; long fOwnerCount;
thread_id fOwner; thread_id fOwner;
thread_id fTaskID; thread_id fTaskID;
uint32 _unused1; uint32 _unused1;
int32 fInitPriority; int32 fInitPriority;
BHandler* fPreferred; BHandler* fPreferred;
BList fHandlers; BList fHandlers;
BList* fCommonFilters; BList* fCommonFilters;
bool fTerminating; bool fTerminating;
bool fRunCalled; bool fRunCalled;
thread_id fCachedPid; thread_id fCachedPid;
size_t fCachedStack; size_t fCachedStack;
void* fMsgBuffer; void* fMsgBuffer;
size_t fMsgBufferSize; size_t fMsgBufferSize;
uint32 _reserved[6]; uint32 _reserved[6];
}; };
//------------------------------------------------------------------------------
#endif // _LOOPER_H #endif // _LOOPER_H
/*
* $Log $
*
* $Id $
*
*/