App Kit: style changes.

No functional change intended.

Focused on documented classes only.

* Update copyright information.
* whitespace fixes.
* pointer style
* Rename some variables, msg => message, form => what
* Need consistent variable names to make documentation easier,
  allows us to use \copydoc or \copydetails instead of repeating
  ourselves over and over again.
This commit is contained in:
John Scipione
2014-06-11 16:24:02 -04:00
parent 151ef32f45
commit be902ac4db
12 changed files with 706 additions and 666 deletions
+5 -1
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright 2001-2009, Haiku Inc. * Copyright 2001-2014 Haiku, Inc. All rights reserved.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
*/ */
#ifndef _APPLICATION_H #ifndef _APPLICATION_H
@@ -21,8 +21,10 @@ class BMessageRunner;
class BResources; class BResources;
class BServer; class BServer;
class BWindow; class BWindow;
struct app_info; struct app_info;
namespace BPrivate { namespace BPrivate {
class PortLink; class PortLink;
class ServerMemoryAllocator; class ServerMemoryAllocator;
@@ -151,9 +153,11 @@ private:
bool fReadyToRunCalled; bool fReadyToRunCalled;
}; };
// Global Objects // Global Objects
extern BApplication* be_app; extern BApplication* be_app;
extern BMessenger be_app_messenger; extern BMessenger be_app_messenger;
#endif // _APPLICATION_H #endif // _APPLICATION_H
+6 -5
View File
@@ -1,9 +1,9 @@
/* /*
* Copyright 2001-2007, Haiku Inc. All Rights Reserved. * Copyright 2001-2014 Haiku, Inc. All rights reserved.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
* Erik Jaesler ([email protected]) * Erik Jaesler, [email protected]
*/ */
#ifndef _HANDLER_H #ifndef _HANDLER_H
#define _HANDLER_H #define _HANDLER_H
@@ -55,8 +55,8 @@ public:
void UnlockLooper(); void UnlockLooper();
// Scripting // Scripting
virtual BHandler* ResolveSpecifier(BMessage* msg, int32 index, virtual BHandler* ResolveSpecifier(BMessage* message, int32 index,
BMessage* specifier, int32 form, BMessage* specifier, int32 what,
const char* property); const char* property);
virtual status_t GetSupportedSuites(BMessage* data); virtual status_t GetSupportedSuites(BMessage* data);
@@ -77,7 +77,8 @@ public:
virtual status_t Perform(perform_code d, void* arg); virtual status_t Perform(perform_code d, void* arg);
// Notifier calls // Notifier calls
virtual void SendNotices(uint32 what, const BMessage* notice = NULL); virtual void SendNotices(uint32 what,
const BMessage* notice = NULL);
bool IsWatched() const; bool IsWatched() const;
private: private:
+5 -5
View File
@@ -1,9 +1,9 @@
/* /*
* Copyright 2001-2008, Haiku Inc. All Rights Reserved. * Copyright 2001-2014 Haiku, Inc. All rights reserved.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
* Erik Jaesler ([email protected]) * Erik Jaesler, [email protected]
*/ */
#ifndef _LOOPER_H #ifndef _LOOPER_H
#define _LOOPER_H #define _LOOPER_H
@@ -30,7 +30,7 @@ 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 int32 portCapacity
= B_LOOPER_PORT_DEFAULT_CAPACITY); = B_LOOPER_PORT_DEFAULT_CAPACITY);
virtual ~BLooper(); virtual ~BLooper();
@@ -86,8 +86,8 @@ public:
sem_id Sem() const; sem_id Sem() const;
// Scripting // Scripting
virtual BHandler* ResolveSpecifier(BMessage* msg, int32 index, virtual BHandler* ResolveSpecifier(BMessage* message, int32 index,
BMessage* specifier, int32 form, BMessage* specifier, int32 what,
const char* property); const char* property);
virtual status_t GetSupportedSuites(BMessage* data); virtual status_t GetSupportedSuites(BMessage* data);
+3 -3
View File
@@ -1,9 +1,9 @@
/* /*
* Copyright 2005-2012, Haiku Inc. All Rights Reserved. * Copyright 2005-2014 Haiku, Inc. All rights reserved.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
* Michael Lotz <[email protected]> * Michael Lotz, [email protected]
*/ */
#ifndef _MESSAGE_H #ifndef _MESSAGE_H
#define _MESSAGE_H #define _MESSAGE_H
@@ -141,7 +141,7 @@ public:
status_t AddString(const char* name, const char* string); status_t AddString(const char* name, const char* string);
status_t AddString(const char* name, status_t AddString(const char* name,
const BString& string); const BString& string);
status_t AddStrings(const char *name, status_t AddStrings(const char* name,
const BStringList& list); const BStringList& list);
status_t AddInt8(const char* name, int8 value); status_t AddInt8(const char* name, int8 value);
status_t AddUInt8(const char* name, uint8 value); status_t AddUInt8(const char* name, uint8 value);
+42 -38
View File
@@ -1,9 +1,9 @@
/* /*
* Copyright 2001-2005, Haiku. * Copyright 2001-2014 Haiku, Inc. All rights reserved.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
* Erik Jaesler ([email protected]) * Erik Jaesler, [email protected]
*/ */
#ifndef _MESSAGE_FILTER_H #ifndef _MESSAGE_FILTER_H
#define _MESSAGE_FILTER_H #define _MESSAGE_FILTER_H
@@ -14,17 +14,19 @@
class BMessage; class BMessage;
// filter_hook Return Codes and Protocol ---------------------------------------
// filter_hook Return Codes and Protocol
enum filter_result { enum filter_result {
B_SKIP_MESSAGE, B_SKIP_MESSAGE,
B_DISPATCH_MESSAGE B_DISPATCH_MESSAGE
}; };
typedef filter_result (*filter_hook) typedef filter_result (*filter_hook)
(BMessage* message, BHandler** target, BMessageFilter* filter); (BMessage* message, BHandler** target, BMessageFilter* filter);
// BMessageFilter invocation criteria ------------------------------------------ // BMessageFilter invocation criteria
enum message_delivery { enum message_delivery {
B_ANY_DELIVERY, B_ANY_DELIVERY,
B_DROPPED_DELIVERY, B_DROPPED_DELIVERY,
@@ -38,47 +40,49 @@ enum message_source {
}; };
// BMessageFilter Class --------------------------------------------------------
class BMessageFilter { class BMessageFilter {
public: public:
BMessageFilter(uint32 what, BMessageFilter(uint32 what,
filter_hook func = NULL); filter_hook func = NULL);
BMessageFilter(message_delivery delivery, BMessageFilter(message_delivery delivery,
message_source source, filter_hook func = NULL); message_source source, filter_hook func = NULL);
BMessageFilter(message_delivery delivery, BMessageFilter(message_delivery delivery,
message_source source, uint32 what, message_source source, uint32 what,
filter_hook func = NULL); filter_hook func = NULL);
BMessageFilter(const BMessageFilter& filter); BMessageFilter(const BMessageFilter& filter);
BMessageFilter(const BMessageFilter* filter); BMessageFilter(const BMessageFilter* filter);
virtual ~BMessageFilter(); virtual ~BMessageFilter();
BMessageFilter& operator=(const BMessageFilter& from); BMessageFilter& operator=(const BMessageFilter& from);
// Hook function; ignored if filter_hook is non-NULL // Hook function; ignored if filter_hook is non-NULL
virtual filter_result Filter(BMessage* message, BHandler** _target); virtual filter_result Filter(BMessage* message, BHandler** _target);
message_delivery MessageDelivery() const; message_delivery MessageDelivery() const;
message_source MessageSource() const; message_source MessageSource() const;
uint32 Command() const; uint32 Command() const;
bool FiltersAnyCommand() const; bool FiltersAnyCommand() const;
BLooper* Looper() const; BLooper* Looper() const;
private: private:
friend class BLooper; friend class BLooper;
friend class BHandler; friend class BHandler;
virtual void _ReservedMessageFilter1(); virtual void _ReservedMessageFilter1();
virtual void _ReservedMessageFilter2(); virtual void _ReservedMessageFilter2();
void SetLooper(BLooper* owner); void SetLooper(BLooper* owner);
filter_hook FilterFunction() const; filter_hook FilterFunction() const;
bool fFiltersAny;
uint32 fWhat; bool fFiltersAny;
message_delivery fDelivery; uint32 fWhat;
message_source fSource; message_delivery fDelivery;
BLooper *fLooper; message_source fSource;
filter_hook fFilterFunction; BLooper* fLooper;
uint32 _reserved[3]; filter_hook fFilterFunction;
uint32 _reserved[3];
}; };
#endif // _MESSAGE_FILTER_H #endif // _MESSAGE_FILTER_H
+35 -34
View File
@@ -1,57 +1,58 @@
/* /*
* Copyright 2001-2007, Haiku, Inc. All Rights Reserved. * Copyright 2001-2014 Haiku, Inc. All rights reserved.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
*/ */
#ifndef _MESSAGE_QUEUE_H #ifndef _MESSAGE_QUEUE_H
#define _MESSAGE_QUEUE_H #define _MESSAGE_QUEUE_H
#include <Locker.h> #include <Locker.h>
#include <Message.h> #include <Message.h>
/* For convenience */ // For convenience
class BMessageQueue { class BMessageQueue {
public: public:
BMessageQueue(); BMessageQueue();
virtual ~BMessageQueue(); virtual ~BMessageQueue();
void AddMessage(BMessage* message); void AddMessage(BMessage* message);
void RemoveMessage(BMessage* message); void RemoveMessage(BMessage* message);
int32 CountMessages() const; int32 CountMessages() const;
bool IsEmpty() const; bool IsEmpty() const;
BMessage* FindMessage(int32 index) const; BMessage* FindMessage(int32 index) const;
BMessage* FindMessage(uint32 what, int32 index = 0) const; BMessage* FindMessage(uint32 what, int32 index = 0) const;
bool Lock(); bool Lock();
void Unlock(); void Unlock();
bool IsLocked() const; bool IsLocked() const;
BMessage *NextMessage(); BMessage* NextMessage();
bool IsNextMessage(const BMessage* message) const; bool IsNextMessage(const BMessage* message) const;
private: private:
// Reserved space in the vtable for future changes to BMessageQueue // Reserved space in the vtable for future changes to BMessageQueue
virtual void _ReservedMessageQueue1(); virtual void _ReservedMessageQueue1();
virtual void _ReservedMessageQueue2(); virtual void _ReservedMessageQueue2();
virtual void _ReservedMessageQueue3(); virtual void _ReservedMessageQueue3();
BMessageQueue(const BMessageQueue &); BMessageQueue(const BMessageQueue &);
BMessageQueue &operator=(const BMessageQueue &); BMessageQueue& operator=(const BMessageQueue &);
bool IsLocked(); bool IsLocked();
// this needs to be exported for R5 compatibility and should // this needs to be exported for R5 compatibility and should
// be dropped as soon as possible // be dropped as soon as possible
private: private:
BMessage* fHead; BMessage* fHead;
BMessage* fTail; BMessage* fTail;
int32 fMessageCount; int32 fMessageCount;
mutable BLocker fLock; mutable BLocker fLock;
uint32 _reserved[3]; uint32 _reserved[3];
}; };
#endif // _MESSAGE_QUEUE_H #endif // _MESSAGE_QUEUE_H
+189 -169
View File
@@ -1,11 +1,11 @@
/* /*
* Copyright 2001-2012, Haiku. * Copyright 2001-2014 Haiku, inc. All rights reserved.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
* Erik Jaesler ([email protected])
* Jerome Duval
* Axel Dörfler, [email protected] * Axel Dörfler, [email protected]
* Jerome Duval
* Erik Jaesler, [email protected]
*/ */
@@ -51,11 +51,11 @@
using namespace BPrivate; using namespace BPrivate;
BApplication *be_app = NULL; BApplication* be_app = NULL;
BMessenger be_app_messenger; BMessenger be_app_messenger;
pthread_once_t sAppResourcesInitOnce = PTHREAD_ONCE_INIT; pthread_once_t sAppResourcesInitOnce = PTHREAD_ONCE_INIT;
BResources *BApplication::sAppResources = NULL; BResources* BApplication::sAppResources = NULL;
enum { enum {
@@ -67,6 +67,7 @@ enum {
kApplication kApplication
}; };
static property_info sPropertyInfo[] = { static property_info sPropertyInfo[] = {
{ {
"Window", "Window",
@@ -161,9 +162,10 @@ static property_info sPropertyInfo[] = {
{} {}
}; };
// argc/argv // argc/argv
extern const int __libc_argc; extern const int __libc_argc;
extern const char * const *__libc_argv; extern const char* const *__libc_argv;
// debugging // debugging
@@ -172,42 +174,116 @@ extern const char * const *__libc_argv;
#define OUT printf #define OUT printf
// prototypes of helper functions // #pragma mark - static helper functions
static const char* looper_name_for(const char *signature);
static status_t check_app_signature(const char *signature);
/*!
\brief Checks whether the supplied string is a valid application signature.
An error message is printed, if the string is no valid app signature.
\param signature The string to be checked.
\return A status code.
\retval B_OK \a signature is a valid app signature.
\retval B_BAD_VALUE \a signature is \c NULL or no valid app signature.
*/
static status_t
check_app_signature(const char* signature)
{
bool isValid = false;
BMimeType type(signature);
if (type.IsValid() && !type.IsSupertypeOnly()
&& BMimeType("application").Contains(&type)) {
isValid = true;
}
if (!isValid) {
printf("bad signature (%s), must begin with \"application/\" and "
"can't conflict with existing registered mime types inside "
"the \"application\" media type.\n", signature);
}
return (isValid ? B_OK : B_BAD_VALUE);
}
// Returns the looper name for a given signature.
// Normally this is "AppLooperPort", but in case of the registrar it gets a
// special name.
static const char*
looper_name_for(const char* signature)
{
if (signature != NULL && !strcasecmp(signature, kRegistrarSignature))
return BPrivate::get_roster_port_name();
return "AppLooperPort";
}
#ifndef RUN_WITHOUT_REGISTRAR #ifndef RUN_WITHOUT_REGISTRAR
static void fill_argv_message(BMessage &message); // Fills the passed BMessage with B_ARGV_RECEIVED infos.
static void
fill_argv_message(BMessage &message)
{
message.what = B_ARGV_RECEIVED;
int32 argc = __libc_argc;
const char* const *argv = __libc_argv;
// add argc
message.AddInt32("argc", argc);
// add argv
for (int32 i = 0; i < argc; i++) {
if (argv[i] != NULL)
message.AddString("argv", argv[i]);
}
// add current working directory
char cwd[B_PATH_NAME_LENGTH];
if (getcwd(cwd, B_PATH_NAME_LENGTH))
message.AddString("cwd", cwd);
}
#endif #endif
BApplication::BApplication(const char *signature) // #pragma mark - BApplication
: BLooper(looper_name_for(signature))
BApplication::BApplication(const char* signature)
:
BLooper(looper_name_for(signature))
{ {
_InitData(signature, true, NULL); _InitData(signature, true, NULL);
} }
BApplication::BApplication(const char *signature, status_t *_error) BApplication::BApplication(const char* signature, status_t* _error)
: BLooper(looper_name_for(signature)) :
BLooper(looper_name_for(signature))
{ {
_InitData(signature, true, _error); _InitData(signature, true, _error);
} }
BApplication::BApplication(const char *signature, bool initGUI, BApplication::BApplication(const char* signature, bool initGUI,
status_t *_error) status_t* _error)
: BLooper(looper_name_for(signature)) :
BLooper(looper_name_for(signature))
{ {
_InitData(signature, initGUI, _error); _InitData(signature, initGUI, _error);
} }
BApplication::BApplication(BMessage *data) BApplication::BApplication(BMessage* data)
// Note: BeOS calls the private BLooper(int32, port_id, const char *) // Note: BeOS calls the private BLooper(int32, port_id, const char*)
// constructor here, test if it's needed // constructor here, test if it's needed
: BLooper(looper_name_for(NULL)) :
BLooper(looper_name_for(NULL))
{ {
const char *signature = NULL; const char* signature = NULL;
data->FindString("mime_sig", &signature); data->FindString("mime_sig", &signature);
_InitData(signature, true, NULL); _InitData(signature, true, NULL);
@@ -260,7 +336,7 @@ BApplication::~BApplication()
} }
BApplication & BApplication&
BApplication::operator=(const BApplication &rhs) BApplication::operator=(const BApplication &rhs)
{ {
return *this; return *this;
@@ -268,7 +344,7 @@ BApplication::operator=(const BApplication &rhs)
void void
BApplication::_InitData(const char *signature, bool initGUI, status_t *_error) BApplication::_InitData(const char* signature, bool initGUI, status_t* _error)
{ {
DBG(OUT("BApplication::InitData(`%s', %p)\n", signature, _error)); DBG(OUT("BApplication::InitData(`%s', %p)\n", signature, _error));
// check whether there exists already an application // check whether there exists already an application
@@ -291,7 +367,7 @@ BApplication::_InitData(const char *signature, bool initGUI, status_t *_error)
#ifndef RUN_WITHOUT_REGISTRAR #ifndef RUN_WITHOUT_REGISTRAR
bool isRegistrar = signature bool isRegistrar = signature
&& !strcasecmp(signature, kRegistrarSignature); && strcasecmp(signature, kRegistrarSignature) == 0;
// get team and thread // get team and thread
team_id team = Team(); team_id team = Team();
thread_id thread = BPrivate::main_thread_for(team); thread_id thread = BPrivate::main_thread_for(team);
@@ -380,8 +456,9 @@ BApplication::_InitData(const char *signature, bool initGUI, status_t *_error)
BMessenger otherApp(NULL, otherTeam); BMessenger otherApp(NULL, otherTeam);
app_info otherAppInfo; app_info otherAppInfo;
if (__libc_argc > 1 if (__libc_argc > 1
&& be_roster->GetRunningAppInfo(otherTeam, &otherAppInfo) == B_OK && be_roster->GetRunningAppInfo(otherTeam, &otherAppInfo)
&& !(otherAppInfo.flags & B_ARGV_ONLY)) { == B_OK
&& (otherAppInfo.flags & B_ARGV_ONLY) != 0) {
// create an B_ARGV_RECEIVED message // create an B_ARGV_RECEIVED message
BMessage argvMessage(B_ARGV_RECEIVED); BMessage argvMessage(B_ARGV_RECEIVED);
fill_argv_message(argvMessage); fill_argv_message(argvMessage);
@@ -457,8 +534,8 @@ DBG(OUT("BApplication::InitData() done\n"));
} }
BArchivable * BArchivable*
BApplication::Instantiate(BMessage *data) BApplication::Instantiate(BMessage* data)
{ {
if (validate_instantiation(data, "BApplication")) if (validate_instantiation(data, "BApplication"))
return new BApplication(data); return new BApplication(data);
@@ -468,7 +545,7 @@ BApplication::Instantiate(BMessage *data)
status_t status_t
BApplication::Archive(BMessage *data, bool deep) const BApplication::Archive(BMessage* data, bool deep) const
{ {
status_t status = BLooper::Archive(data, deep); status_t status = BLooper::Archive(data, deep);
if (status < B_OK) if (status < B_OK)
@@ -520,9 +597,10 @@ BApplication::Quit()
{ {
bool unlock = false; bool unlock = false;
if (!IsLocked()) { if (!IsLocked()) {
const char *name = Name(); const char* name = Name();
if (!name) if (name == NULL)
name = "no-name"; name = "no-name";
printf("ERROR - you must Lock the application object before calling " printf("ERROR - you must Lock the application object before calling "
"Quit(), team=%" B_PRId32 ", looper=%s\n", Team(), name); "Quit(), team=%" B_PRId32 ", looper=%s\n", Team(), name);
unlock = true; unlock = true;
@@ -551,6 +629,7 @@ BApplication::Quit()
// message dispatching loop and return from Run(). // message dispatching loop and return from Run().
fTerminating = true; fTerminating = true;
} }
// If we had to lock the object, unlock now. // If we had to lock the object, unlock now.
if (unlock) if (unlock)
Unlock(); Unlock();
@@ -579,7 +658,7 @@ BApplication::ReadyToRun()
void void
BApplication::MessageReceived(BMessage *message) BApplication::MessageReceived(BMessage* message)
{ {
switch (message->what) { switch (message->what) {
case B_COUNT_PROPERTIES: case B_COUNT_PROPERTIES:
@@ -589,10 +668,13 @@ BApplication::MessageReceived(BMessage *message)
int32 index; int32 index;
BMessage specifier; BMessage specifier;
int32 what; int32 what;
const char *property = NULL; const char* property = NULL;
if (message->GetCurrentSpecifier(&index, &specifier, &what, &property) < B_OK if (message->GetCurrentSpecifier(&index, &specifier, &what,
|| !ScriptReceived(message, index, &specifier, what, property)) &property) < B_OK
|| !ScriptReceived(message, index, &specifier, what,
property)) {
BLooper::MessageReceived(message); BLooper::MessageReceived(message);
}
break; break;
} }
@@ -619,13 +701,12 @@ BApplication::MessageReceived(BMessage *message)
default: default:
BLooper::MessageReceived(message); BLooper::MessageReceived(message);
break;
} }
} }
void void
BApplication::ArgvReceived(int32 argc, char **argv) BApplication::ArgvReceived(int32 argc, char** argv)
{ {
// supposed to be implemented by subclasses // supposed to be implemented by subclasses
} }
@@ -639,7 +720,7 @@ BApplication::AppActivated(bool active)
void void
BApplication::RefsReceived(BMessage *message) BApplication::RefsReceived(BMessage* message)
{ {
// supposed to be implemented by subclasses // supposed to be implemented by subclasses
} }
@@ -650,16 +731,16 @@ BApplication::AboutRequested()
{ {
thread_info info; thread_info info;
if (get_thread_info(Thread(), &info) == B_OK) { if (get_thread_info(Thread(), &info) == B_OK) {
BAlert *alert = new BAlert("_about_", info.name, "OK"); BAlert* alert = new BAlert("_about_", info.name, "OK");
alert->SetFlags(alert->Flags() | B_CLOSE_ON_ESCAPE); alert->SetFlags(alert->Flags() | B_CLOSE_ON_ESCAPE);
alert->Go(NULL); alert->Go(NULL);
} }
} }
BHandler * BHandler*
BApplication::ResolveSpecifier(BMessage *message, int32 index, BApplication::ResolveSpecifier(BMessage* message, int32 index,
BMessage *specifier, int32 what, const char *property) BMessage* specifier, int32 what, const char* property)
{ {
BPropertyInfo propInfo(sPropertyInfo); BPropertyInfo propInfo(sPropertyInfo);
status_t err = B_OK; status_t err = B_OK;
@@ -677,7 +758,7 @@ BApplication::ResolveSpecifier(BMessage *message, int32 index,
if (what == B_REVERSE_INDEX_SPECIFIER) if (what == B_REVERSE_INDEX_SPECIFIER)
index = CountWindows() - index; index = CountWindows() - index;
BWindow *window = WindowAt(index); BWindow* window = WindowAt(index);
if (window != NULL) { if (window != NULL) {
message->PopSpecifier(); message->PopSpecifier();
BMessenger(window).SendMessage(message); BMessenger(window).SendMessage(message);
@@ -688,18 +769,19 @@ BApplication::ResolveSpecifier(BMessage *message, int32 index,
case kWindowByName: case kWindowByName:
{ {
const char *name; const char* name;
err = specifier->FindString("name", &name); err = specifier->FindString("name", &name);
if (err != B_OK) if (err != B_OK)
break; break;
for (int32 i = 0;; i++) { for (int32 i = 0;; i++) {
BWindow *window = WindowAt(i); BWindow* window = WindowAt(i);
if (window == NULL) { if (window == NULL) {
err = B_NAME_NOT_FOUND; err = B_NAME_NOT_FOUND;
break; break;
} }
if (window->Title() != NULL && !strcmp(window->Title(), name)) { if (window->Title() != NULL && !strcmp(window->Title(),
name)) {
message->PopSpecifier(); message->PopSpecifier();
BMessenger(window).SendMessage(message); BMessenger(window).SendMessage(message);
break; break;
@@ -718,12 +800,13 @@ BApplication::ResolveSpecifier(BMessage *message, int32 index,
if (what == B_REVERSE_INDEX_SPECIFIER) if (what == B_REVERSE_INDEX_SPECIFIER)
index = CountLoopers() - index; index = CountLoopers() - index;
BLooper *looper = LooperAt(index); BLooper* looper = LooperAt(index);
if (looper != NULL) { if (looper != NULL) {
message->PopSpecifier(); message->PopSpecifier();
BMessenger(looper).SendMessage(message); BMessenger(looper).SendMessage(message);
} else } else
err = B_BAD_INDEX; err = B_BAD_INDEX;
break; break;
} }
@@ -733,18 +816,19 @@ BApplication::ResolveSpecifier(BMessage *message, int32 index,
case kLooperByName: case kLooperByName:
{ {
const char *name; const char* name;
err = specifier->FindString("name", &name); err = specifier->FindString("name", &name);
if (err != B_OK) if (err != B_OK)
break; break;
for (int32 i = 0;; i++) { for (int32 i = 0;; i++) {
BLooper *looper = LooperAt(i); BLooper* looper = LooperAt(i);
if (looper == NULL) { if (looper == NULL) {
err = B_NAME_NOT_FOUND; err = B_NAME_NOT_FOUND;
break; break;
} }
if (looper->Name() != NULL && !strcmp(looper->Name(), name)) { if (looper->Name() != NULL
&& strcmp(looper->Name(), name) == 0) {
message->PopSpecifier(); message->PopSpecifier();
BMessenger(looper).SendMessage(message); BMessenger(looper).SendMessage(message);
break; break;
@@ -813,7 +897,7 @@ BApplication::IsCursorHidden() const
void void
BApplication::SetCursor(const void *cursorData) BApplication::SetCursor(const void* cursorData)
{ {
BCursor cursor(cursorData); BCursor cursor(cursorData);
SetCursor(&cursor, true); SetCursor(&cursor, true);
@@ -822,7 +906,7 @@ BApplication::SetCursor(const void *cursorData)
void void
BApplication::SetCursor(const BCursor *cursor, bool sync) BApplication::SetCursor(const BCursor* cursor, bool sync)
{ {
BPrivate::AppServerLink link; BPrivate::AppServerLink link;
link.StartMessage(AS_SET_CURSOR); link.StartMessage(AS_SET_CURSOR);
@@ -845,7 +929,7 @@ BApplication::CountWindows() const
} }
BWindow * BWindow*
BApplication::WindowAt(int32 index) const BApplication::WindowAt(int32 index) const
{ {
return _WindowAt(index, false); return _WindowAt(index, false);
@@ -865,10 +949,10 @@ BApplication::CountLoopers() const
} }
BLooper * BLooper*
BApplication::LooperAt(int32 index) const BApplication::LooperAt(int32 index) const
{ {
BLooper *looper = NULL; BLooper* looper = NULL;
AutoLocker<BLooperList> listLock(gLooperList); AutoLocker<BLooperList> listLock(gLooperList);
if (listLock.IsLocked()) if (listLock.IsLocked())
looper = gLooperList.LooperAt(index); looper = gLooperList.LooperAt(index);
@@ -885,7 +969,7 @@ BApplication::IsLaunching() const
status_t status_t
BApplication::GetAppInfo(app_info *info) const BApplication::GetAppInfo(app_info* info) const
{ {
if (be_app == NULL || be_roster == NULL) if (be_app == NULL || be_roster == NULL)
return B_NO_INIT; return B_NO_INIT;
@@ -893,7 +977,7 @@ BApplication::GetAppInfo(app_info *info) const
} }
BResources * BResources*
BApplication::AppResources() BApplication::AppResources()
{ {
if (sAppResources == NULL) if (sAppResources == NULL)
@@ -904,7 +988,7 @@ BApplication::AppResources()
void void
BApplication::DispatchMessage(BMessage *message, BHandler *handler) BApplication::DispatchMessage(BMessage* message, BHandler* handler)
{ {
if (handler != this) { if (handler != this) {
// it's not ours to dispatch // it's not ours to dispatch
@@ -1025,9 +1109,9 @@ BApplication::SetPulseRate(bigtime_t rate)
status_t status_t
BApplication::GetSupportedSuites(BMessage *data) BApplication::GetSupportedSuites(BMessage* data)
{ {
if (!data) if (data == NULL)
return B_BAD_VALUE; return B_BAD_VALUE;
status_t status = data->AddString("suites", "suite/vnd.Be-application"); status_t status = data->AddString("suites", "suite/vnd.Be-application");
@@ -1043,7 +1127,7 @@ BApplication::GetSupportedSuites(BMessage *data)
status_t status_t
BApplication::Perform(perform_code d, void *arg) BApplication::Perform(perform_code d, void* arg)
{ {
return BLooper::Perform(d, arg); return BLooper::Perform(d, arg);
} }
@@ -1060,8 +1144,8 @@ void BApplication::_ReservedApplication8() {}
bool bool
BApplication::ScriptReceived(BMessage *message, int32 index, BApplication::ScriptReceived(BMessage* message, int32 index,
BMessage *specifier, int32 what, const char *property) BMessage* specifier, int32 what, const char* property)
{ {
BMessage reply(B_REPLY); BMessage reply(B_REPLY);
status_t err = B_BAD_SCRIPT_SYNTAX; status_t err = B_BAD_SCRIPT_SYNTAX;
@@ -1091,19 +1175,23 @@ BApplication::ScriptReceived(BMessage *message, int32 index,
err = specifier->FindInt32("index", &index); err = specifier->FindInt32("index", &index);
if (err != B_OK) if (err != B_OK)
break; break;
if (what == B_REVERSE_INDEX_SPECIFIER) if (what == B_REVERSE_INDEX_SPECIFIER)
index = CountWindows() - index; index = CountWindows() - index;
err = B_BAD_INDEX; err = B_BAD_INDEX;
BWindow *win = WindowAt(index); BWindow* window = WindowAt(index);
if (!win) if (window == NULL)
break; break;
BMessenger messenger(win);
BMessenger messenger(window);
err = reply.AddMessenger("result", messenger); err = reply.AddMessenger("result", messenger);
break; break;
} }
case B_NAME_SPECIFIER: case B_NAME_SPECIFIER:
{ {
const char *name; const char* name;
err = specifier->FindString("name", &name); err = specifier->FindString("name", &name);
if (err != B_OK) if (err != B_OK)
break; break;
@@ -1129,27 +1217,31 @@ BApplication::ScriptReceived(BMessage *message, int32 index,
err = specifier->FindInt32("index", &index); err = specifier->FindInt32("index", &index);
if (err != B_OK) if (err != B_OK)
break; break;
if (what == B_REVERSE_INDEX_SPECIFIER) if (what == B_REVERSE_INDEX_SPECIFIER)
index = CountLoopers() - index; index = CountLoopers() - index;
err = B_BAD_INDEX; err = B_BAD_INDEX;
BLooper *looper = LooperAt(index); BLooper* looper = LooperAt(index);
if (!looper) if (looper == NULL)
break; break;
BMessenger messenger(looper); BMessenger messenger(looper);
err = reply.AddMessenger("result", messenger); err = reply.AddMessenger("result", messenger);
break; break;
} }
case B_NAME_SPECIFIER: case B_NAME_SPECIFIER:
{ {
const char *name; const char* name;
err = specifier->FindString("name", &name); err = specifier->FindString("name", &name);
if (err != B_OK) if (err != B_OK)
break; break;
err = B_NAME_NOT_FOUND; err = B_NAME_NOT_FOUND;
for (int32 i = 0; i < CountLoopers(); i++) { for (int32 i = 0; i < CountLoopers(); i++) {
BLooper *looper = LooperAt(i); BLooper* looper = LooperAt(i);
if (looper && looper->Name() if (looper != NULL && looper->Name()
&& !strcmp(looper->Name(), name)) { && strcmp(looper->Name(), name) == 0) {
BMessenger messenger(looper); BMessenger messenger(looper);
err = reply.AddMessenger("result", messenger); err = reply.AddMessenger("result", messenger);
break; break;
@@ -1157,6 +1249,7 @@ BApplication::ScriptReceived(BMessage *message, int32 index,
} }
break; break;
} }
case B_ID_SPECIFIER: case B_ID_SPECIFIER:
{ {
// TODO // TODO
@@ -1164,16 +1257,17 @@ BApplication::ScriptReceived(BMessage *message, int32 index,
break; break;
} }
} }
} else if (strcmp("Name", property) == 0) { } else if (strcmp("Name", property) == 0)
err = reply.AddString("result", Name()); err = reply.AddString("result", Name());
}
break; break;
case B_COUNT_PROPERTIES: case B_COUNT_PROPERTIES:
if (strcmp("Looper", property) == 0) { if (strcmp("Looper", property) == 0)
err = reply.AddInt32("result", CountLoopers()); err = reply.AddInt32("result", CountLoopers());
} else if (strcmp("Window", property) == 0) { else if (strcmp("Window", property) == 0)
err = reply.AddInt32("result", CountWindows()); err = reply.AddInt32("result", CountWindows());
}
break; break;
} }
if (err == B_BAD_SCRIPT_SYNTAX) if (err == B_BAD_SCRIPT_SYNTAX)
@@ -1185,6 +1279,7 @@ BApplication::ScriptReceived(BMessage *message, int32 index,
} }
reply.AddInt32("error", err); reply.AddInt32("error", err);
message->SendReply(&reply); message->SendReply(&reply);
return true; return true;
} }
@@ -1261,7 +1356,7 @@ BApplication::_ConnectToServer()
// 2) port_id - looper port for this BApplication // 2) port_id - looper port for this BApplication
// 3) team_id - team identification field // 3) team_id - team identification field
// 4) int32 - handler ID token of the app // 4) int32 - handler ID token of the app
// 5) char * - signature of the regular app // 5) char* - signature of the regular app
fServerLink->StartMessage(AS_CREATE_APP); fServerLink->StartMessage(AS_CREATE_APP);
fServerLink->Attach<port_id>(fServerLink->ReceiverPort()); fServerLink->Attach<port_id>(fServerLink->ReceiverPort());
@@ -1301,6 +1396,7 @@ BApplication::_ConnectToServer()
return status; return status;
fServerReadOnlyMemory = base; fServerReadOnlyMemory = base;
return B_OK; return B_OK;
} }
@@ -1335,34 +1431,35 @@ BApplication::_ReconnectToServer()
#if 0 #if 0
void void
BApplication::send_drag(BMessage *message, int32 vs_token, BPoint offset, BApplication::send_drag(BMessage* message, int32 vs_token, BPoint offset,
BRect dragRect, BHandler *replyTo) BRect dragRect, BHandler* replyTo)
{ {
// TODO: implement // TODO: implement
} }
void void
BApplication::send_drag(BMessage *message, int32 vs_token, BPoint offset, BApplication::send_drag(BMessage* message, int32 vs_token, BPoint offset,
int32 bitmapToken, drawing_mode dragMode, BHandler *replyTo) int32 bitmapToken, drawing_mode dragMode, BHandler* replyTo)
{ {
// TODO: implement // TODO: implement
} }
void void
BApplication::write_drag(_BSession_ *session, BMessage *message) BApplication::write_drag(_BSession_* session, BMessage* message)
{ {
// TODO: implement // TODO: implement
} }
#endif #endif
bool bool
BApplication::_WindowQuitLoop(bool quitFilePanels, bool force) BApplication::_WindowQuitLoop(bool quitFilePanels, bool force)
{ {
int32 index = 0; int32 index = 0;
while (true) { while (true) {
BWindow *window = WindowAt(index); BWindow* window = WindowAt(index);
if (window == NULL) if (window == NULL)
break; break;
@@ -1397,6 +1494,7 @@ BApplication::_WindowQuitLoop(bool quitFilePanels, bool force)
// we need to continue at the start of the list again - it // we need to continue at the start of the list again - it
// might have changed // might have changed
} }
return true; return true;
} }
@@ -1421,14 +1519,14 @@ BApplication::_QuitAllWindows(bool force)
void void
BApplication::_ArgvReceived(BMessage *message) BApplication::_ArgvReceived(BMessage* message)
{ {
ASSERT(message != NULL); ASSERT(message != NULL);
// build the argv vector // build the argv vector
status_t error = B_OK; status_t error = B_OK;
int32 argc = 0; int32 argc = 0;
char **argv = NULL; char** argv = NULL;
if (message->FindInt32("argc", &argc) == B_OK && argc > 0) { if (message->FindInt32("argc", &argc) == B_OK && argc > 0) {
// allocate a NULL terminated array // allocate a NULL terminated array
argv = new(std::nothrow) char*[argc + 1]; argv = new(std::nothrow) char*[argc + 1];
@@ -1437,7 +1535,7 @@ BApplication::_ArgvReceived(BMessage *message)
// copy the arguments // copy the arguments
for (int32 i = 0; error == B_OK && i < argc; i++) { for (int32 i = 0; error == B_OK && i < argc; i++) {
const char *arg = NULL; const char* arg = NULL;
error = message->FindString("argv", i, &arg); error = message->FindString("argv", i, &arg);
if (error == B_OK && arg) { if (error == B_OK && arg) {
argv[i] = strdup(arg); argv[i] = strdup(arg);
@@ -1482,7 +1580,7 @@ BApplication::_CountWindows(bool includeMenus) const
for (int32 i = 0; i < gLooperList.CountLoopers(); i++) { for (int32 i = 0; i < gLooperList.CountLoopers(); i++) {
BWindow* window = dynamic_cast<BWindow*>(gLooperList.LooperAt(i)); BWindow* window = dynamic_cast<BWindow*>(gLooperList.LooperAt(i));
if (window != NULL && !window->fOffscreen && (includeMenus if (window != NULL && !window->fOffscreen && (includeMenus
|| dynamic_cast<BMenuWindow *>(window) == NULL)) { || dynamic_cast<BMenuWindow*>(window) == NULL)) {
count++; count++;
} }
} }
@@ -1491,7 +1589,7 @@ BApplication::_CountWindows(bool includeMenus) const
} }
BWindow * BWindow*
BApplication::_WindowAt(uint32 index, bool includeMenus) const BApplication::_WindowAt(uint32 index, bool includeMenus) const
{ {
AutoLocker<BLooperList> listLock(gLooperList); AutoLocker<BLooperList> listLock(gLooperList);
@@ -1502,7 +1600,7 @@ BApplication::_WindowAt(uint32 index, bool includeMenus) const
for (uint32 i = 0; i < count && index < count; i++) { for (uint32 i = 0; i < count && index < count; i++) {
BWindow* window = dynamic_cast<BWindow*>(gLooperList.LooperAt(i)); BWindow* window = dynamic_cast<BWindow*>(gLooperList.LooperAt(i));
if (window == NULL || (window != NULL && window->fOffscreen) if (window == NULL || (window != NULL && window->fOffscreen)
|| (!includeMenus && dynamic_cast<BMenuWindow *>(window) != NULL)) { || (!includeMenus && dynamic_cast<BMenuWindow*>(window) != NULL)) {
index++; index++;
continue; continue;
} }
@@ -1547,81 +1645,3 @@ BApplication::_InitAppResources()
sAppResources = resources; sAppResources = resources;
} }
// #pragma mark -
/*!
\brief Checks whether the supplied string is a valid application signature.
An error message is printed, if the string is no valid app signature.
\param signature The string to be checked.
\return
- \c B_OK: \a signature is a valid app signature.
- \c B_BAD_VALUE: \a signature is \c NULL or no valid app signature.
*/
static status_t
check_app_signature(const char *signature)
{
bool isValid = false;
BMimeType type(signature);
if (type.IsValid() && !type.IsSupertypeOnly()
&& BMimeType("application").Contains(&type)) {
isValid = true;
}
if (!isValid) {
printf("bad signature (%s), must begin with \"application/\" and "
"can't conflict with existing registered mime types inside "
"the \"application\" media type.\n", signature);
}
return (isValid ? B_OK : B_BAD_VALUE);
}
/*!
\brief Returns the looper name for a given signature.
Normally this is "AppLooperPort", but in case of the registrar a
special name.
\return The looper name.
*/
static const char *
looper_name_for(const char *signature)
{
if (signature && !strcasecmp(signature, kRegistrarSignature))
return BPrivate::get_roster_port_name();
return "AppLooperPort";
}
/*!
\brief Fills the passed BMessage with B_ARGV_RECEIVED infos.
*/
#ifndef RUN_WITHOUT_REGISTRAR
static void
fill_argv_message(BMessage &message)
{
message.what = B_ARGV_RECEIVED;
int32 argc = __libc_argc;
const char * const *argv = __libc_argv;
// add argc
message.AddInt32("argc", argc);
// add argv
for (int32 i = 0; i < argc; i++) {
if (argv[i] != NULL)
message.AddString("argv", argv[i]);
}
// add current working directory
char cwd[B_PATH_NAME_LENGTH];
if (getcwd(cwd, B_PATH_NAME_LENGTH))
message.AddString("cwd", cwd);
}
#endif
+77 -69
View File
@@ -1,10 +1,10 @@
/* /*
* Copyright 2001-2007, Haiku. * Copyright 2001-2014 Haiku, Inc. All rights reserved.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
* Erik Jaesler ([email protected])
* Axel Dörfler, [email protected] * Axel Dörfler, [email protected]
* Erik Jaesler, [email protected]
*/ */
@@ -86,7 +86,7 @@ static property_info sHandlerPropInfo[] = {
{} {}
}; };
bool FilterDeleter(void *filter); bool FilterDeleter(void* filter);
namespace BPrivate { namespace BPrivate {
@@ -103,7 +103,7 @@ class ObserverList {
bool IsEmpty(); bool IsEmpty();
private: private:
typedef map<uint32, vector<const BHandler *> > HandlerObserverMap; typedef map<uint32, vector<const BHandler*> > HandlerObserverMap;
typedef map<uint32, vector<BMessenger> > MessengerObserverMap; typedef map<uint32, vector<BMessenger> > MessengerObserverMap;
void _ValidateHandlers(uint32 what); void _ValidateHandlers(uint32 what);
@@ -121,7 +121,7 @@ using namespace BPrivate;
// #pragma mark - // #pragma mark -
BHandler::BHandler(const char *name) BHandler::BHandler(const char* name)
: BArchivable(), : BArchivable(),
fName(NULL) fName(NULL)
{ {
@@ -154,11 +154,11 @@ BHandler::~BHandler()
} }
BHandler::BHandler(BMessage *data) BHandler::BHandler(BMessage* data)
: BArchivable(data), : BArchivable(data),
fName(NULL) fName(NULL)
{ {
const char *name = NULL; const char* name = NULL;
if (data) if (data)
data->FindString(kArchiveNameField, &name); data->FindString(kArchiveNameField, &name);
@@ -167,8 +167,8 @@ BHandler::BHandler(BMessage *data)
} }
BArchivable * BArchivable*
BHandler::Instantiate(BMessage *data) BHandler::Instantiate(BMessage* data)
{ {
if (!validate_instantiation(data, "BHandler")) if (!validate_instantiation(data, "BHandler"))
return NULL; return NULL;
@@ -178,20 +178,21 @@ BHandler::Instantiate(BMessage *data)
status_t status_t
BHandler::Archive(BMessage *data, bool deep) const BHandler::Archive(BMessage* data, bool deep) const
{ {
status_t status = BArchivable::Archive(data, deep); status_t status = BArchivable::Archive(data, deep);
if (status < B_OK) if (status < B_OK)
return status; return status;
if (!fName) if (fName == NULL)
return B_OK; return B_OK;
return data->AddString(kArchiveNameField, fName); return data->AddString(kArchiveNameField, fName);
} }
void void
BHandler::MessageReceived(BMessage *message) BHandler::MessageReceived(BMessage* message)
{ {
BMessage reply(B_REPLY); BMessage reply(B_REPLY);
@@ -202,8 +203,10 @@ BHandler::MessageReceived(BMessage *message)
BMessenger target; BMessenger target;
uint32 what; uint32 what;
if (message->FindMessenger(kObserveTarget, &target) != B_OK if (message->FindMessenger(kObserveTarget, &target) != B_OK
|| message->FindInt32(B_OBSERVE_WHAT_CHANGE, (int32*)&what) != B_OK) || message->FindInt32(B_OBSERVE_WHAT_CHANGE, (int32*)&what)
!= B_OK) {
break; break;
}
ObserverList* list = _ObserverList(); ObserverList* list = _ObserverList();
if (list != NULL) { if (list != NULL) {
@@ -220,7 +223,7 @@ BHandler::MessageReceived(BMessage *message)
int32 cur; int32 cur;
BMessage specifier; BMessage specifier;
int32 form; int32 form;
const char *prop; const char* prop;
status_t err = message->GetCurrentSpecifier(&cur, &specifier, status_t err = message->GetCurrentSpecifier(&cur, &specifier,
&form, &prop); &form, &prop);
@@ -257,7 +260,8 @@ BHandler::MessageReceived(BMessage *message)
} }
} }
// ToDo: there is some more work needed here (someone in the know should fill in)! // ToDo: there is some more work needed here
// (someone in the know should fill in)!
if (fNextHandler) { if (fNextHandler) {
// we need to apply the next handler's filters here, too // we need to apply the next handler's filters here, too
@@ -278,7 +282,7 @@ BHandler::MessageReceived(BMessage *message)
} }
BLooper * BLooper*
BHandler::Looper() const BHandler::Looper() const
{ {
return fLooper; return fLooper;
@@ -286,7 +290,7 @@ BHandler::Looper() const
void void
BHandler::SetName(const char *name) BHandler::SetName(const char* name)
{ {
if (fName != NULL) { if (fName != NULL) {
free(fName); free(fName);
@@ -298,7 +302,7 @@ BHandler::SetName(const char *name)
} }
const char * const char*
BHandler::Name() const BHandler::Name() const
{ {
return fName; return fName;
@@ -306,9 +310,9 @@ BHandler::Name() const
void void
BHandler::SetNextHandler(BHandler *handler) BHandler::SetNextHandler(BHandler* handler)
{ {
if (!fLooper) { if (fLooper == NULL) {
debugger("handler must belong to looper before setting NextHandler"); debugger("handler must belong to looper before setting NextHandler");
return; return;
} }
@@ -318,7 +322,7 @@ BHandler::SetNextHandler(BHandler *handler)
return; return;
} }
if (handler && fLooper != handler->Looper()) { if (handler != NULL && fLooper != handler->Looper()) {
debugger("The handler and its NextHandler must have the same looper"); debugger("The handler and its NextHandler must have the same looper");
return; return;
} }
@@ -327,7 +331,7 @@ BHandler::SetNextHandler(BHandler *handler)
} }
BHandler * BHandler*
BHandler::NextHandler() const BHandler::NextHandler() const
{ {
return fNextHandler; return fNextHandler;
@@ -335,10 +339,10 @@ BHandler::NextHandler() const
void void
BHandler::AddFilter(BMessageFilter *filter) BHandler::AddFilter(BMessageFilter* filter)
{ {
BLooper* looper = fLooper; BLooper* looper = fLooper;
if (looper && !looper->IsLocked()) { if (looper != NULL && !looper->IsLocked()) {
debugger("Owning Looper must be locked before calling SetFilterList"); debugger("Owning Looper must be locked before calling SetFilterList");
return; return;
} }
@@ -346,7 +350,7 @@ BHandler::AddFilter(BMessageFilter *filter)
if (looper != NULL) if (looper != NULL)
filter->SetLooper(looper); filter->SetLooper(looper);
if (!fFilters) if (fFilters == NULL)
fFilters = new BList; fFilters = new BList;
fFilters->AddItem(filter); fFilters->AddItem(filter);
@@ -354,15 +358,15 @@ BHandler::AddFilter(BMessageFilter *filter)
bool bool
BHandler::RemoveFilter(BMessageFilter *filter) BHandler::RemoveFilter(BMessageFilter* filter)
{ {
BLooper* looper = fLooper; BLooper* looper = fLooper;
if (looper && !looper->IsLocked()) { if (looper != NULL && !looper->IsLocked()) {
debugger("Owning Looper must be locked before calling SetFilterList"); debugger("Owning Looper must be locked before calling SetFilterList");
return false; return false;
} }
if (fFilters != NULL && fFilters->RemoveItem((void *)filter)) { if (fFilters != NULL && fFilters->RemoveItem((void*)filter)) {
filter->SetLooper(NULL); filter->SetLooper(NULL);
return true; return true;
} }
@@ -375,7 +379,7 @@ void
BHandler::SetFilterList(BList* filters) BHandler::SetFilterList(BList* filters)
{ {
BLooper* looper = fLooper; BLooper* looper = fLooper;
if (looper && !looper->IsLocked()) { if (looper != NULL && !looper->IsLocked()) {
debugger("Owning Looper must be locked before calling SetFilterList"); debugger("Owning Looper must be locked before calling SetFilterList");
return; return;
} }
@@ -389,7 +393,7 @@ BHandler::SetFilterList(BList* filters)
*/ */
// TODO: Explore issues with using BObjectList // TODO: Explore issues with using BObjectList
if (fFilters) { if (fFilters != NULL) {
fFilters->DoForEach(FilterDeleter); fFilters->DoForEach(FilterDeleter);
delete fFilters; delete fFilters;
} }
@@ -397,8 +401,8 @@ BHandler::SetFilterList(BList* filters)
fFilters = filters; fFilters = filters;
if (fFilters) { if (fFilters) {
for (int32 i = 0; i < fFilters->CountItems(); ++i) { for (int32 i = 0; i < fFilters->CountItems(); ++i) {
BMessageFilter *filter = BMessageFilter* filter =
static_cast<BMessageFilter *>(fFilters->ItemAt(i)); static_cast<BMessageFilter*>(fFilters->ItemAt(i));
if (filter != NULL) if (filter != NULL)
filter->SetLooper(looper); filter->SetLooper(looper);
} }
@@ -406,7 +410,7 @@ BHandler::SetFilterList(BList* filters)
} }
BList * BList*
BHandler::FilterList() BHandler::FilterList()
{ {
return fFilters; return fFilters;
@@ -416,7 +420,7 @@ BHandler::FilterList()
bool bool
BHandler::LockLooper() BHandler::LockLooper()
{ {
BLooper *looper = fLooper; BLooper* looper = fLooper;
// Locking the looper also makes sure that the looper is valid // Locking the looper also makes sure that the looper is valid
if (looper != NULL && looper->Lock()) { if (looper != NULL && looper->Lock()) {
// Have we locked the right looper? That's as far as the // Have we locked the right looper? That's as far as the
@@ -435,7 +439,7 @@ BHandler::LockLooper()
status_t status_t
BHandler::LockLooperWithTimeout(bigtime_t timeout) BHandler::LockLooperWithTimeout(bigtime_t timeout)
{ {
BLooper *looper = fLooper; BLooper* looper = fLooper;
if (looper == NULL) if (looper == NULL)
return B_BAD_VALUE; return B_BAD_VALUE;
@@ -460,26 +464,26 @@ BHandler::UnlockLooper()
} }
BHandler * BHandler*
BHandler::ResolveSpecifier(BMessage *msg, int32 index, BHandler::ResolveSpecifier(BMessage* message, int32 index,
BMessage *specifier, int32 form, const char *property) BMessage* specifier, int32 what, const char* property)
{ {
// Straight from the BeBook // Straight from the BeBook
BPropertyInfo propertyInfo(sHandlerPropInfo); BPropertyInfo propertyInfo(sHandlerPropInfo);
if (propertyInfo.FindMatch(msg, index, specifier, form, property) >= 0) if (propertyInfo.FindMatch(message, index, specifier, what, property) >= 0)
return this; return this;
BMessage reply(B_MESSAGE_NOT_UNDERSTOOD); BMessage reply(B_MESSAGE_NOT_UNDERSTOOD);
reply.AddInt32("error", B_BAD_SCRIPT_SYNTAX); reply.AddInt32("error", B_BAD_SCRIPT_SYNTAX);
reply.AddString("message", "Didn't understand the specifier(s)"); reply.AddString("message", "Didn't understand the specifier(s)");
msg->SendReply(&reply); message->SendReply(&reply);
return NULL; return NULL;
} }
status_t status_t
BHandler::GetSupportedSuites(BMessage *data) BHandler::GetSupportedSuites(BMessage* data)
{ {
/** /**
@note This is the output from the original implementation (calling @note This is the output from the original implementation (calling
@@ -507,12 +511,12 @@ BMessage: what = (0x0, or 0)
*/ */
status_t err = B_OK; status_t err = B_OK;
if (!data) if (data == NULL)
err = B_BAD_VALUE; err = B_BAD_VALUE;
if (!err) { if (err != B_OK) {
err = data->AddString("suites", "suite/vnd.Be-handler"); err = data->AddString("suites", "suite/vnd.Be-handler");
if (!err) { if (err != B_OK) {
BPropertyInfo propertyInfo(sHandlerPropInfo); BPropertyInfo propertyInfo(sHandlerPropInfo);
err = data->AddFlat("messages", &propertyInfo); err = data->AddFlat("messages", &propertyInfo);
} }
@@ -588,24 +592,24 @@ BHandler::StopWatching(BHandler* handler, uint32 what)
status_t status_t
BHandler::StopWatchingAll(BHandler *handler) BHandler::StopWatchingAll(BHandler* handler)
{ {
return StopWatching(handler, B_OBSERVER_OBSERVE_ALL); return StopWatching(handler, B_OBSERVER_OBSERVE_ALL);
} }
status_t status_t
BHandler::Perform(perform_code d, void *arg) BHandler::Perform(perform_code d, void* arg)
{ {
return BArchivable::Perform(d, arg); return BArchivable::Perform(d, arg);
} }
void void
BHandler::SendNotices(uint32 what, const BMessage *msg) BHandler::SendNotices(uint32 what, const BMessage* notice)
{ {
if (fObserverList != NULL) if (fObserverList != NULL)
fObserverList->SendNotices(what, msg); fObserverList->SendNotices(what, notice);
} }
@@ -617,7 +621,7 @@ BHandler::IsWatched() const
void void
BHandler::_InitData(const char *name) BHandler::_InitData(const char* name)
{ {
SetName(name); SetName(name);
@@ -655,14 +659,17 @@ BHandler::operator=(const BHandler &)
void void
BHandler::SetLooper(BLooper *looper) BHandler::SetLooper(BLooper* looper)
{ {
fLooper = looper; fLooper = looper;
gDefaultTokens.SetHandlerTarget(fToken, looper ? looper->fDirectTarget : NULL); gDefaultTokens.SetHandlerTarget(fToken,
looper ? looper->fDirectTarget : NULL);
if (fFilters) { if (fFilters != NULL) {
for (int32 i = 0; i < fFilters->CountItems(); i++) for (int32 i = 0; i < fFilters->CountItems(); i++) {
static_cast<BMessageFilter *>(fFilters->ItemAtFast(i))->SetLooper(looper); static_cast<BMessageFilter*>(
fFilters->ItemAtFast(i))->SetLooper(looper);
}
} }
} }
@@ -700,8 +707,8 @@ ObserverList::~ObserverList()
void void
ObserverList::_ValidateHandlers(uint32 what) ObserverList::_ValidateHandlers(uint32 what)
{ {
vector<const BHandler *>& handlers = fHandlerMap[what]; vector<const BHandler*>& handlers = fHandlerMap[what];
vector<const BHandler *>::iterator iterator = handlers.begin(); vector<const BHandler*>::iterator iterator = handlers.begin();
while (iterator != handlers.end()) { while (iterator != handlers.end()) {
BMessenger target(*iterator); BMessenger target(*iterator);
@@ -717,9 +724,10 @@ ObserverList::_ValidateHandlers(uint32 what)
void void
ObserverList::_SendNotices(uint32 what, BMessage* message) ObserverList::_SendNotices(uint32 what, BMessage* notice)
{ {
// first iterate over the list of handlers and try to make valid messengers out of them // first iterate over the list of handlers and try to make valid
// messengers out of them
_ValidateHandlers(what); _ValidateHandlers(what);
// now send it to all messengers we know // now send it to all messengers we know
@@ -732,20 +740,20 @@ ObserverList::_SendNotices(uint32 what, BMessage* message)
continue; continue;
} }
(*iterator).SendMessage(message); (*iterator).SendMessage(notice);
iterator++; iterator++;
} }
} }
status_t status_t
ObserverList::SendNotices(uint32 what, const BMessage* message) ObserverList::SendNotices(uint32 what, const BMessage* notice)
{ {
BMessage *copy = NULL; BMessage* copy = NULL;
if (message) { if (notice != NULL) {
copy = new BMessage(*message); copy = new BMessage(*notice);
copy->what = B_OBSERVER_NOTICE_CHANGE; copy->what = B_OBSERVER_NOTICE_CHANGE;
copy->AddInt32(B_OBSERVE_ORIGINAL_WHAT, message->what); copy->AddInt32(B_OBSERVE_ORIGINAL_WHAT, notice->what);
} else } else
copy = new BMessage(B_OBSERVER_NOTICE_CHANGE); copy = new BMessage(B_OBSERVER_NOTICE_CHANGE);
@@ -755,12 +763,13 @@ ObserverList::SendNotices(uint32 what, const BMessage* message)
_SendNotices(B_OBSERVER_OBSERVE_ALL, copy); _SendNotices(B_OBSERVER_OBSERVE_ALL, copy);
delete copy; delete copy;
return B_OK; return B_OK;
} }
status_t status_t
ObserverList::Add(const BHandler *handler, uint32 what) ObserverList::Add(const BHandler* handler, uint32 what)
{ {
if (handler == NULL) if (handler == NULL)
return B_BAD_HANDLER; return B_BAD_HANDLER;
@@ -802,7 +811,7 @@ ObserverList::Add(const BMessenger &messenger, uint32 what)
status_t status_t
ObserverList::Remove(const BHandler *handler, uint32 what) ObserverList::Remove(const BHandler* handler, uint32 what)
{ {
if (handler == NULL) if (handler == NULL)
return B_BAD_HANDLER; return B_BAD_HANDLER;
@@ -858,9 +867,8 @@ ObserverList::IsEmpty()
bool bool
FilterDeleter(void *_filter) FilterDeleter(void* _filter)
{ {
delete static_cast<BMessageFilter *>(_filter); delete static_cast<BMessageFilter*>(_filter);
return false; return false;
} }
+59 -55
View File
@@ -1,16 +1,16 @@
/* /*
* Copyright 2001-2013, Haiku. * Copyright 2001-2013 Haiku, Inc. All rights reserved
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
* Erik Jaesler (erik@cgsoftware.com) * DarkWyrm, bpmagic@columbus.rr.com
* DarkWyrm (bpmagic@columbus.rr.com)
* Ingo Weinhold, bonefish@@users.sf.net
* Axel Dörfler, axeld@pinc-software.de * Axel Dörfler, axeld@pinc-software.de
* Erik Jaesler, erik@cgsoftware.com
* Ingo Weinhold, bonefish@@users.sf.net
*/ */
/*! BLooper class spawns a thread that runs a message loop. */ // BLooper class spawns a thread that runs a message loop.
#include <AppMisc.h> #include <AppMisc.h>
@@ -106,7 +106,8 @@ struct _loop_data_ {
BLooper::BLooper(const char* name, int32 priority, int32 portCapacity) BLooper::BLooper(const char* name, int32 priority, int32 portCapacity)
: BHandler(name) :
BHandler(name)
{ {
_InitData(name, priority, portCapacity); _InitData(name, priority, portCapacity);
} }
@@ -626,8 +627,8 @@ BLooper::Sem() const
BHandler* BHandler*
BLooper::ResolveSpecifier(BMessage* msg, int32 index, BMessage* specifier, BLooper::ResolveSpecifier(BMessage* message, int32 index, BMessage* specifier,
int32 form, const char* property) int32 what, const char* property)
{ {
/** /**
@note When I was first dumping the results of GetSupportedSuites() from @note When I was first dumping the results of GetSupportedSuites() from
@@ -645,7 +646,7 @@ BLooper::ResolveSpecifier(BMessage* msg, int32 index, BMessage* specifier,
uint32 data; uint32 data;
status_t err = B_OK; status_t err = B_OK;
const char* errMsg = ""; const char* errMsg = "";
if (propertyInfo.FindMatch(msg, index, specifier, form, property, &data) if (propertyInfo.FindMatch(message, index, specifier, what, property, &data)
>= 0) { >= 0) {
switch (data) { switch (data) {
case BLOOPER_PROCESS_INTERNALLY: case BLOOPER_PROCESS_INTERNALLY:
@@ -654,13 +655,13 @@ BLooper::ResolveSpecifier(BMessage* msg, int32 index, BMessage* specifier,
case BLOOPER_HANDLER_BY_INDEX: case BLOOPER_HANDLER_BY_INDEX:
{ {
int32 index = specifier->FindInt32("index"); int32 index = specifier->FindInt32("index");
if (form == B_REVERSE_INDEX_SPECIFIER) { if (what == B_REVERSE_INDEX_SPECIFIER) {
index = CountHandlers() - index; index = CountHandlers() - index;
} }
BHandler* target = HandlerAt(index); BHandler* target = HandlerAt(index);
if (target) { if (target) {
// Specifier has been fully handled // Specifier has been fully handled
msg->PopSpecifier(); message->PopSpecifier();
return target; return target;
} else { } else {
err = B_BAD_INDEX; err = B_BAD_INDEX;
@@ -672,17 +673,16 @@ BLooper::ResolveSpecifier(BMessage* msg, int32 index, BMessage* specifier,
default: default:
err = B_BAD_SCRIPT_SYNTAX; err = B_BAD_SCRIPT_SYNTAX;
errMsg = "Didn't understand the specifier(s)"; errMsg = "Didn't understand the specifier(s)";
break;
} }
} else { } else {
return BHandler::ResolveSpecifier(msg, index, specifier, form, return BHandler::ResolveSpecifier(message, index, specifier, what,
property); property);
} }
BMessage reply(B_MESSAGE_NOT_UNDERSTOOD); BMessage reply(B_MESSAGE_NOT_UNDERSTOOD);
reply.AddInt32("error", err); reply.AddInt32("error", err);
reply.AddString("message", errMsg); reply.AddString("message", errMsg);
msg->SendReply(&reply); message->SendReply(&reply);
return NULL; return NULL;
} }
@@ -709,7 +709,7 @@ BLooper::GetSupportedSuites(BMessage* data)
void void
BLooper::AddCommonFilter(BMessageFilter* filter) BLooper::AddCommonFilter(BMessageFilter* filter)
{ {
if (!filter) if (filter == NULL)
return; return;
AssertLocked(); AssertLocked();
@@ -719,7 +719,7 @@ BLooper::AddCommonFilter(BMessageFilter* filter)
return; return;
} }
if (!fCommonFilters) if (fCommonFilters == NULL)
fCommonFilters = new BList(FILTER_LIST_BLOCK_SIZE); fCommonFilters = new BList(FILTER_LIST_BLOCK_SIZE);
filter->SetLooper(this); filter->SetLooper(this);
@@ -732,7 +732,7 @@ BLooper::RemoveCommonFilter(BMessageFilter* filter)
{ {
AssertLocked(); AssertLocked();
if (!fCommonFilters) if (fCommonFilters == NULL)
return false; return false;
bool result = fCommonFilters->RemoveItem(filter); bool result = fCommonFilters->RemoveItem(filter);
@@ -879,7 +879,7 @@ BLooper::_Lock(BLooper* looper, port_id port, bigtime_t timeout)
return B_BAD_VALUE; return B_BAD_VALUE;
} }
} else if (!gLooperList.IsLooperValid(looper)) { } else if (!gLooperList.IsLooperValid(looper)) {
// Check looper validity // Check looper validity
PRINT(("BLooper::_Lock() done 4\n")); PRINT(("BLooper::_Lock() done 4\n"));
return B_BAD_VALUE; return B_BAD_VALUE;
} }
@@ -908,7 +908,7 @@ BLooper::_Lock(BLooper* looper, port_id port, bigtime_t timeout)
status_t status_t
BLooper::_LockComplete(BLooper *looper, int32 oldCount, thread_id thread, BLooper::_LockComplete(BLooper* looper, int32 oldCount, thread_id thread,
sem_id sem, bigtime_t timeout) sem_id sem, bigtime_t timeout)
{ {
status_t err = B_OK; status_t err = B_OK;
@@ -934,7 +934,7 @@ BLooper::_LockComplete(BLooper *looper, int32 oldCount, thread_id thread,
void void
BLooper::_InitData(const char *name, int32 priority, int32 portCapacity) BLooper::_InitData(const char* name, int32 priority, int32 portCapacity)
{ {
fOwner = B_ERROR; fOwner = B_ERROR;
fCachedStack = 0; fCachedStack = 0;
@@ -1001,7 +1001,7 @@ BLooper::_AddMessagePriv(BMessage* message)
status_t status_t
BLooper::_task0_(void* arg) BLooper::_task0_(void* arg)
{ {
BLooper* looper = (BLooper *)arg; BLooper* looper = (BLooper*)arg;
PRINT(("LOOPER: _task0_()\n")); PRINT(("LOOPER: _task0_()\n"));
@@ -1017,11 +1017,11 @@ BLooper::_task0_(void* arg)
} }
void * void*
BLooper::ReadRawFromPort(int32* msgCode, bigtime_t timeout) BLooper::ReadRawFromPort(int32* msgCode, bigtime_t timeout)
{ {
PRINT(("BLooper::ReadRawFromPort()\n")); PRINT(("BLooper::ReadRawFromPort()\n"));
uint8 *buffer = NULL; uint8* buffer = NULL;
ssize_t bufferSize; ssize_t bufferSize;
do { do {
@@ -1034,7 +1034,7 @@ BLooper::ReadRawFromPort(int32* msgCode, bigtime_t timeout)
} }
if (bufferSize > 0) if (bufferSize > 0)
buffer = (uint8 *)malloc(bufferSize); buffer = (uint8*)malloc(bufferSize);
// we don't want to wait again here, since that can only mean // we don't want to wait again here, since that can only mean
// that someone else has read our message and our bufferSize // that someone else has read our message and our bufferSize
@@ -1048,7 +1048,9 @@ BLooper::ReadRawFromPort(int32* msgCode, bigtime_t timeout)
return NULL; return NULL;
} }
PRINT(("BLooper::ReadRawFromPort() read: %.4s, %p (%d bytes)\n", (char *)msgCode, buffer, bufferSize)); PRINT(("BLooper::ReadRawFromPort() read: %.4s, %p (%d bytes)\n",
(char*)msgCode, buffer, bufferSize));
return buffer; return buffer;
} }
@@ -1058,10 +1060,10 @@ BLooper::ReadMessageFromPort(bigtime_t timeout)
{ {
PRINT(("BLooper::ReadMessageFromPort()\n")); PRINT(("BLooper::ReadMessageFromPort()\n"));
int32 msgCode; int32 msgCode;
BMessage *message = NULL; BMessage* message = NULL;
void *buffer = ReadRawFromPort(&msgCode, timeout); void* buffer = ReadRawFromPort(&msgCode, timeout);
if (!buffer) if (buffer == NULL)
return NULL; return NULL;
message = ConvertToMessage(buffer, msgCode); message = ConvertToMessage(buffer, msgCode);
@@ -1076,7 +1078,7 @@ BMessage*
BLooper::ConvertToMessage(void* buffer, int32 code) BLooper::ConvertToMessage(void* buffer, int32 code)
{ {
PRINT(("BLooper::ConvertToMessage()\n")); PRINT(("BLooper::ConvertToMessage()\n"));
if (!buffer) if (buffer == NULL)
return NULL; return NULL;
BMessage* message = new BMessage(); BMessage* message = new BMessage();
@@ -1109,7 +1111,7 @@ BLooper::task_looper()
// TODO: timeout determination algo // TODO: timeout determination algo
// Read from message port (how do we determine what the timeout is?) // Read from message port (how do we determine what the timeout is?)
PRINT(("LOOPER: MessageFromPort()...\n")); PRINT(("LOOPER: MessageFromPort()...\n"));
BMessage *msg = MessageFromPort(); BMessage* msg = MessageFromPort();
PRINT(("LOOPER: ...done\n")); PRINT(("LOOPER: ...done\n"));
// Did we get a message? // Did we get a message?
@@ -1139,7 +1141,7 @@ BLooper::task_looper()
fLastMessage = message; fLastMessage = message;
if (!fLastMessage) { if (fLastMessage == NULL) {
// No more messages: Unlock the looper and terminate the // No more messages: Unlock the looper and terminate the
// dispatch loop. // dispatch loop.
dispatchNextMessage = false; dispatchNextMessage = false;
@@ -1149,7 +1151,7 @@ BLooper::task_looper()
DBG(fLastMessage->PrintToStream()); DBG(fLastMessage->PrintToStream());
// Get the target handler // Get the target handler
BHandler *handler = NULL; BHandler* handler = NULL;
BMessage::Private messagePrivate(fLastMessage); BMessage::Private messagePrivate(fLastMessage);
bool usePreferred = messagePrivate.UsePreferredTarget(); bool usePreferred = messagePrivate.UsePreferredTarget();
@@ -1160,7 +1162,7 @@ BLooper::task_looper()
handler = this; handler = this;
} else { } else {
gDefaultTokens.GetToken(messagePrivate.GetTarget(), gDefaultTokens.GetToken(messagePrivate.GetTarget(),
B_HANDLER_TOKEN, (void **)&handler); B_HANDLER_TOKEN, (void**)&handler);
// if this handler doesn't belong to us, we drop the message // if this handler doesn't belong to us, we drop the message
if (handler != NULL && handler->Looper() != this) if (handler != NULL && handler->Looper() != this)
@@ -1295,24 +1297,25 @@ BHandler*
BLooper::_ApplyFilters(BList* list, BMessage* message, BHandler* target) BLooper::_ApplyFilters(BList* list, BMessage* message, BHandler* target)
{ {
// This is where the action is! // This is where the action is!
// Check the parameters
if (!list || !message) // check the parameters
if (list == NULL || message == NULL)
return target; return target;
// For each filter in the provided list // for each filter in the provided list
BMessageFilter* filter = NULL; BMessageFilter* filter = NULL;
for (int32 i = 0; i < list->CountItems(); ++i) { for (int32 i = 0; i < list->CountItems(); ++i) {
filter = (BMessageFilter*)list->ItemAt(i); filter = (BMessageFilter*)list->ItemAt(i);
// Check command conditions // check command conditions
if (filter->FiltersAnyCommand() || filter->Command() == message->what) { if (filter->FiltersAnyCommand() || filter->Command() == message->what) {
// Check delivery conditions // check delivery conditions
message_delivery delivery = filter->MessageDelivery(); message_delivery delivery = filter->MessageDelivery();
bool dropped = message->WasDropped(); bool dropped = message->WasDropped();
if (delivery == B_ANY_DELIVERY if (delivery == B_ANY_DELIVERY
|| (delivery == B_DROPPED_DELIVERY && dropped) || (delivery == B_DROPPED_DELIVERY && dropped)
|| (delivery == B_PROGRAMMED_DELIVERY && !dropped)) { || (delivery == B_PROGRAMMED_DELIVERY && !dropped)) {
// Check source conditions // check source conditions
message_source source = filter->MessageSource(); message_source source = filter->MessageSource();
bool remote = message->IsSourceRemote(); bool remote = message->IsSourceRemote();
if (source == B_ANY_SOURCE if (source == B_ANY_SOURCE
@@ -1320,15 +1323,15 @@ BLooper::_ApplyFilters(BList* list, BMessage* message, BHandler* target)
|| (source == B_LOCAL_SOURCE && !remote)) { || (source == B_LOCAL_SOURCE && !remote)) {
// Are we using an "external" function? // Are we using an "external" function?
filter_result result; filter_result result;
filter_hook func = filter->FilterFunction(); filter_hook filterFunction = filter->FilterFunction();
if (func) if (filterFunction != NULL)
result = func(message, &target, filter); result = filterFunction(message, &target, filter);
else else
result = filter->Filter(message, &target); result = filter->Filter(message, &target);
// Is further processing allowed? // Is further processing allowed?
if (result == B_SKIP_MESSAGE) { if (result == B_SKIP_MESSAGE) {
// No; time to bail out // no, time to bail out
return NULL; return NULL;
} }
} }
@@ -1343,13 +1346,14 @@ BLooper::_ApplyFilters(BList* list, BMessage* message, BHandler* target)
void void
BLooper::check_lock() BLooper::check_lock()
{ {
// This is a cheap variant of AssertLocked() // this is a cheap variant of AssertLocked()
// It is used in situations where it's clear that the looper is valid, // it is used in situations where it's clear that the looper is valid,
// ie. from handlers // i.e. from handlers
uint32 stack; uint32 stack;
if (((addr_t)&stack & ~(B_PAGE_SIZE - 1)) == fCachedStack if (((addr_t)&stack & ~(B_PAGE_SIZE - 1)) == fCachedStack
|| fOwner == find_thread(NULL)) || fOwner == find_thread(NULL)) {
return; return;
}
debugger("Looper must be locked."); debugger("Looper must be locked.");
} }
@@ -1358,7 +1362,7 @@ BLooper::check_lock()
BHandler* BHandler*
BLooper::resolve_specifier(BHandler* target, BMessage* message) BLooper::resolve_specifier(BHandler* target, BMessage* message)
{ {
// Check params // check params
if (!target || !message) if (!target || !message)
return NULL; return NULL;
@@ -1368,27 +1372,28 @@ BLooper::resolve_specifier(BHandler* target, BMessage* message)
const char* property; const char* property;
status_t err = B_OK; status_t err = B_OK;
BHandler* newTarget = target; BHandler* newTarget = target;
// Loop to deal with nested specifiers // loop to deal with nested specifiers
// (e.g., the 3rd button on the 4th view) // (e.g., the 3rd button on the 4th view)
do { do {
err = message->GetCurrentSpecifier(&index, &specifier, &form, &property); err = message->GetCurrentSpecifier(&index, &specifier, &form,
&property);
if (err != B_OK) { if (err != B_OK) {
BMessage reply(B_REPLY); BMessage reply(B_REPLY);
reply.AddInt32("error", err); reply.AddInt32("error", err);
message->SendReply(&reply); message->SendReply(&reply);
return NULL; return NULL;
} }
// Current target gets what was the new target // current target gets what was the new target
target = newTarget; target = newTarget;
newTarget = target->ResolveSpecifier(message, index, &specifier, form, newTarget = target->ResolveSpecifier(message, index, &specifier, form,
property); property);
// Check that new target is owned by looper; use IndexOf() to avoid // check that new target is owned by looper; use IndexOf() to avoid
// dereferencing newTarget (possible race condition with object // dereferencing newTarget (possible race condition with object
// destruction by another looper) // destruction by another looper)
if (!newTarget || IndexOf(newTarget) < 0) if (newTarget == NULL || IndexOf(newTarget) < 0)
return NULL; return NULL;
// Get current specifier index (may change in ResolveSpecifier()) // get current specifier index (may change in ResolveSpecifier())
err = message->GetCurrentSpecifier(&index); err = message->GetCurrentSpecifier(&index);
} while (newTarget && newTarget != target && err == B_OK && index >= 0); } while (newTarget && newTarget != target && err == B_OK && index >= 0);
@@ -1426,4 +1431,3 @@ _get_looper_port_(const BLooper* looper)
{ {
return looper->fMsgPort; return looper->fMsgPort;
} }
+269 -270
View File
File diff suppressed because it is too large Load Diff
+2 -2
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright 2001-2005, Haiku. * Copyright 2001-2014 Haiku, Inc. All rights reserved.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
@@ -115,7 +115,7 @@ BMessageFilter::FiltersAnyCommand() const
} }
BLooper * BLooper*
BMessageFilter::Looper() const BMessageFilter::Looper() const
{ {
return fLooper; return fLooper;
+13 -14
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright 2001-2007, Haiku, Inc. All Rights Reserved. * Copyright 2001-2014 Haiku, Inc. All rights reserved.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
@@ -7,7 +7,8 @@
* Axel Dörfler, axeld@pinc-software.de * Axel Dörfler, axeld@pinc-software.de
*/ */
/** Queue for holding BMessages */
// Queue for holding BMessages
#include <MessageQueue.h> #include <MessageQueue.h>
@@ -18,9 +19,9 @@
BMessageQueue::BMessageQueue() BMessageQueue::BMessageQueue()
: :
fHead(NULL), fHead(NULL),
fTail(NULL), fTail(NULL),
fMessageCount(0), fMessageCount(0),
fLock("BMessageQueue Lock") fLock("BMessageQueue Lock")
{ {
} }
@@ -32,7 +33,7 @@ BMessageQueue::~BMessageQueue()
BMessage* message = fHead; BMessage* message = fHead;
while (message != NULL) { while (message != NULL) {
BMessage *next = message->fQueueLink; BMessage* next = message->fQueueLink;
delete message; delete message;
message = next; message = next;
@@ -111,7 +112,7 @@ BMessageQueue::IsEmpty() const
} }
BMessage * BMessage*
BMessageQueue::FindMessage(int32 index) const BMessageQueue::FindMessage(int32 index) const
{ {
BAutolock _(fLock); BAutolock _(fLock);
@@ -133,7 +134,7 @@ BMessageQueue::FindMessage(int32 index) const
} }
BMessage * BMessage*
BMessageQueue::FindMessage(uint32 what, int32 index) const BMessageQueue::FindMessage(uint32 what, int32 index) const
{ {
BAutolock _(fLock); BAutolock _(fLock);
@@ -178,7 +179,7 @@ BMessageQueue::IsLocked() const
} }
BMessage * BMessage*
BMessageQueue::NextMessage() BMessageQueue::NextMessage()
{ {
BAutolock _(fLock); BAutolock _(fLock);
@@ -201,7 +202,7 @@ BMessageQueue::NextMessage()
fTail = NULL; fTail = NULL;
} }
return head; return head;
} }
@@ -213,10 +214,8 @@ BMessageQueue::IsNextMessage(const BMessage* message) const
} }
/*! // This method is only here for R5 binary compatibility!
\brief This method is only here for R5 binary compatibility! // It should be dropped as soon as possible (it misses the const qualifier).
It should be dropped as soon as possible (it misses the const qualifier).
*/
bool bool
BMessageQueue::IsLocked() BMessageQueue::IsLocked()
{ {