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.
*/
#ifndef _APPLICATION_H
@@ -21,8 +21,10 @@ class BMessageRunner;
class BResources;
class BServer;
class BWindow;
struct app_info;
namespace BPrivate {
class PortLink;
class ServerMemoryAllocator;
@@ -151,9 +153,11 @@ private:
bool fReadyToRunCalled;
};
// Global Objects
extern BApplication* be_app;
extern BMessenger be_app_messenger;
#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.
*
* Authors:
* Erik Jaesler ([email protected])
* Erik Jaesler, [email protected]
*/
#ifndef _HANDLER_H
#define _HANDLER_H
@@ -55,8 +55,8 @@ public:
void UnlockLooper();
// Scripting
virtual BHandler* ResolveSpecifier(BMessage* msg, int32 index,
BMessage* specifier, int32 form,
virtual BHandler* ResolveSpecifier(BMessage* message, int32 index,
BMessage* specifier, int32 what,
const char* property);
virtual status_t GetSupportedSuites(BMessage* data);
@@ -77,7 +77,8 @@ public:
virtual status_t Perform(perform_code d, void* arg);
// Notifier calls
virtual void SendNotices(uint32 what, const BMessage* notice = NULL);
virtual void SendNotices(uint32 what,
const BMessage* notice = NULL);
bool IsWatched() const;
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.
*
* Authors:
* Erik Jaesler ([email protected])
* Erik Jaesler, [email protected]
*/
#ifndef _LOOPER_H
#define _LOOPER_H
@@ -30,7 +30,7 @@ class BLooper : public BHandler {
public:
BLooper(const char* name = NULL,
int32 priority = B_NORMAL_PRIORITY,
int32 port_capacity
int32 portCapacity
= B_LOOPER_PORT_DEFAULT_CAPACITY);
virtual ~BLooper();
@@ -86,8 +86,8 @@ public:
sem_id Sem() const;
// Scripting
virtual BHandler* ResolveSpecifier(BMessage* msg, int32 index,
BMessage* specifier, int32 form,
virtual BHandler* ResolveSpecifier(BMessage* message, int32 index,
BMessage* specifier, int32 what,
const char* property);
virtual status_t GetSupportedSuites(BMessage* data);
+2 -2
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.
*
* Authors:
* Michael Lotz <[email protected]>
* Michael Lotz, [email protected]
*/
#ifndef _MESSAGE_H
#define _MESSAGE_H
+9 -5
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.
*
* Authors:
* Erik Jaesler ([email protected])
* Erik Jaesler, [email protected]
*/
#ifndef _MESSAGE_FILTER_H
#define _MESSAGE_FILTER_H
@@ -14,17 +14,19 @@
class BMessage;
// filter_hook Return Codes and Protocol ---------------------------------------
// filter_hook Return Codes and Protocol
enum filter_result {
B_SKIP_MESSAGE,
B_DISPATCH_MESSAGE
};
typedef filter_result (*filter_hook)
(BMessage* message, BHandler** target, BMessageFilter* filter);
// BMessageFilter invocation criteria ------------------------------------------
// BMessageFilter invocation criteria
enum message_delivery {
B_ANY_DELIVERY,
B_DROPPED_DELIVERY,
@@ -38,7 +40,6 @@ enum message_source {
};
// BMessageFilter Class --------------------------------------------------------
class BMessageFilter {
public:
BMessageFilter(uint32 what,
@@ -72,13 +73,16 @@ class BMessageFilter {
void SetLooper(BLooper* owner);
filter_hook FilterFunction() const;
bool fFiltersAny;
uint32 fWhat;
message_delivery fDelivery;
message_source fSource;
BLooper* fLooper;
filter_hook fFilterFunction;
uint32 _reserved[3];
};
#endif // _MESSAGE_FILTER_H
+3 -2
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.
*/
#ifndef _MESSAGE_QUEUE_H
@@ -8,7 +8,7 @@
#include <Locker.h>
#include <Message.h>
/* For convenience */
// For convenience
class BMessageQueue {
@@ -54,4 +54,5 @@ class BMessageQueue {
uint32 _reserved[3];
};
#endif // _MESSAGE_QUEUE_H
+130 -110
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.
*
* Authors:
* Erik Jaesler ([email protected])
* Jerome Duval
* Axel Dörfler, [email protected]
* Jerome Duval
* Erik Jaesler, [email protected]
*/
@@ -67,6 +67,7 @@ enum {
kApplication
};
static property_info sPropertyInfo[] = {
{
"Window",
@@ -161,6 +162,7 @@ static property_info sPropertyInfo[] = {
{}
};
// argc/argv
extern const int __libc_argc;
extern const char* const *__libc_argv;
@@ -172,23 +174,95 @@ extern const char * const *__libc_argv;
#define OUT printf
// prototypes of helper functions
static const char* looper_name_for(const char *signature);
static status_t check_app_signature(const char *signature);
// #pragma mark - static helper functions
/*!
\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
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
// #pragma mark - BApplication
BApplication::BApplication(const char* signature)
: BLooper(looper_name_for(signature))
:
BLooper(looper_name_for(signature))
{
_InitData(signature, true, NULL);
}
BApplication::BApplication(const char* signature, status_t* _error)
: BLooper(looper_name_for(signature))
:
BLooper(looper_name_for(signature))
{
_InitData(signature, true, _error);
}
@@ -196,7 +270,8 @@ BApplication::BApplication(const char *signature, status_t *_error)
BApplication::BApplication(const char* signature, bool initGUI,
status_t* _error)
: BLooper(looper_name_for(signature))
:
BLooper(looper_name_for(signature))
{
_InitData(signature, initGUI, _error);
}
@@ -205,7 +280,8 @@ BApplication::BApplication(const char *signature, bool initGUI,
BApplication::BApplication(BMessage* data)
// Note: BeOS calls the private BLooper(int32, port_id, const char*)
// constructor here, test if it's needed
: BLooper(looper_name_for(NULL))
:
BLooper(looper_name_for(NULL))
{
const char* signature = NULL;
data->FindString("mime_sig", &signature);
@@ -291,7 +367,7 @@ BApplication::_InitData(const char *signature, bool initGUI, status_t *_error)
#ifndef RUN_WITHOUT_REGISTRAR
bool isRegistrar = signature
&& !strcasecmp(signature, kRegistrarSignature);
&& strcasecmp(signature, kRegistrarSignature) == 0;
// get team and thread
team_id team = 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);
app_info otherAppInfo;
if (__libc_argc > 1
&& be_roster->GetRunningAppInfo(otherTeam, &otherAppInfo) == B_OK
&& !(otherAppInfo.flags & B_ARGV_ONLY)) {
&& be_roster->GetRunningAppInfo(otherTeam, &otherAppInfo)
== B_OK
&& (otherAppInfo.flags & B_ARGV_ONLY) != 0) {
// create an B_ARGV_RECEIVED message
BMessage argvMessage(B_ARGV_RECEIVED);
fill_argv_message(argvMessage);
@@ -521,8 +598,9 @@ BApplication::Quit()
bool unlock = false;
if (!IsLocked()) {
const char* name = Name();
if (!name)
if (name == NULL)
name = "no-name";
printf("ERROR - you must Lock the application object before calling "
"Quit(), team=%" B_PRId32 ", looper=%s\n", Team(), name);
unlock = true;
@@ -551,6 +629,7 @@ BApplication::Quit()
// message dispatching loop and return from Run().
fTerminating = true;
}
// If we had to lock the object, unlock now.
if (unlock)
Unlock();
@@ -590,9 +669,12 @@ BApplication::MessageReceived(BMessage *message)
BMessage specifier;
int32 what;
const char* property = NULL;
if (message->GetCurrentSpecifier(&index, &specifier, &what, &property) < B_OK
|| !ScriptReceived(message, index, &specifier, what, property))
if (message->GetCurrentSpecifier(&index, &specifier, &what,
&property) < B_OK
|| !ScriptReceived(message, index, &specifier, what,
property)) {
BLooper::MessageReceived(message);
}
break;
}
@@ -619,7 +701,6 @@ BApplication::MessageReceived(BMessage *message)
default:
BLooper::MessageReceived(message);
break;
}
}
@@ -699,7 +780,8 @@ BApplication::ResolveSpecifier(BMessage *message, int32 index,
err = B_NAME_NOT_FOUND;
break;
}
if (window->Title() != NULL && !strcmp(window->Title(), name)) {
if (window->Title() != NULL && !strcmp(window->Title(),
name)) {
message->PopSpecifier();
BMessenger(window).SendMessage(message);
break;
@@ -724,6 +806,7 @@ BApplication::ResolveSpecifier(BMessage *message, int32 index,
BMessenger(looper).SendMessage(message);
} else
err = B_BAD_INDEX;
break;
}
@@ -744,7 +827,8 @@ BApplication::ResolveSpecifier(BMessage *message, int32 index,
err = B_NAME_NOT_FOUND;
break;
}
if (looper->Name() != NULL && !strcmp(looper->Name(), name)) {
if (looper->Name() != NULL
&& strcmp(looper->Name(), name) == 0) {
message->PopSpecifier();
BMessenger(looper).SendMessage(message);
break;
@@ -1027,7 +1111,7 @@ BApplication::SetPulseRate(bigtime_t rate)
status_t
BApplication::GetSupportedSuites(BMessage* data)
{
if (!data)
if (data == NULL)
return B_BAD_VALUE;
status_t status = data->AddString("suites", "suite/vnd.Be-application");
@@ -1091,16 +1175,20 @@ BApplication::ScriptReceived(BMessage *message, int32 index,
err = specifier->FindInt32("index", &index);
if (err != B_OK)
break;
if (what == B_REVERSE_INDEX_SPECIFIER)
index = CountWindows() - index;
err = B_BAD_INDEX;
BWindow *win = WindowAt(index);
if (!win)
BWindow* window = WindowAt(index);
if (window == NULL)
break;
BMessenger messenger(win);
BMessenger messenger(window);
err = reply.AddMessenger("result", messenger);
break;
}
case B_NAME_SPECIFIER:
{
const char* name;
@@ -1129,16 +1217,20 @@ BApplication::ScriptReceived(BMessage *message, int32 index,
err = specifier->FindInt32("index", &index);
if (err != B_OK)
break;
if (what == B_REVERSE_INDEX_SPECIFIER)
index = CountLoopers() - index;
err = B_BAD_INDEX;
BLooper* looper = LooperAt(index);
if (!looper)
if (looper == NULL)
break;
BMessenger messenger(looper);
err = reply.AddMessenger("result", messenger);
break;
}
case B_NAME_SPECIFIER:
{
const char* name;
@@ -1148,8 +1240,8 @@ BApplication::ScriptReceived(BMessage *message, int32 index,
err = B_NAME_NOT_FOUND;
for (int32 i = 0; i < CountLoopers(); i++) {
BLooper* looper = LooperAt(i);
if (looper && looper->Name()
&& !strcmp(looper->Name(), name)) {
if (looper != NULL && looper->Name()
&& strcmp(looper->Name(), name) == 0) {
BMessenger messenger(looper);
err = reply.AddMessenger("result", messenger);
break;
@@ -1157,6 +1249,7 @@ BApplication::ScriptReceived(BMessage *message, int32 index,
}
break;
}
case B_ID_SPECIFIER:
{
// TODO
@@ -1164,16 +1257,17 @@ BApplication::ScriptReceived(BMessage *message, int32 index,
break;
}
}
} else if (strcmp("Name", property) == 0) {
} else if (strcmp("Name", property) == 0)
err = reply.AddString("result", Name());
}
break;
case B_COUNT_PROPERTIES:
if (strcmp("Looper", property) == 0) {
if (strcmp("Looper", property) == 0)
err = reply.AddInt32("result", CountLoopers());
} else if (strcmp("Window", property) == 0) {
else if (strcmp("Window", property) == 0)
err = reply.AddInt32("result", CountWindows());
}
break;
}
if (err == B_BAD_SCRIPT_SYNTAX)
@@ -1185,6 +1279,7 @@ BApplication::ScriptReceived(BMessage *message, int32 index,
}
reply.AddInt32("error", err);
message->SendReply(&reply);
return true;
}
@@ -1301,6 +1396,7 @@ BApplication::_ConnectToServer()
return status;
fServerReadOnlyMemory = base;
return B_OK;
}
@@ -1357,6 +1453,7 @@ BApplication::write_drag(_BSession_ *session, BMessage *message)
}
#endif
bool
BApplication::_WindowQuitLoop(bool quitFilePanels, bool force)
{
@@ -1397,6 +1494,7 @@ BApplication::_WindowQuitLoop(bool quitFilePanels, bool force)
// we need to continue at the start of the list again - it
// might have changed
}
return true;
}
@@ -1547,81 +1645,3 @@ BApplication::_InitAppResources()
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
+41 -33
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.
*
* Authors:
* Erik Jaesler (erik@cgsoftware.com)
* Axel Dörfler, axeld@pinc-software.de
* Erik Jaesler, erik@cgsoftware.com
*/
@@ -184,8 +184,9 @@ BHandler::Archive(BMessage *data, bool deep) const
if (status < B_OK)
return status;
if (!fName)
if (fName == NULL)
return B_OK;
return data->AddString(kArchiveNameField, fName);
}
@@ -202,8 +203,10 @@ BHandler::MessageReceived(BMessage *message)
BMessenger target;
uint32 what;
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;
}
ObserverList* list = _ObserverList();
if (list != NULL) {
@@ -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) {
// we need to apply the next handler's filters here, too
@@ -308,7 +312,7 @@ BHandler::Name() const
void
BHandler::SetNextHandler(BHandler* handler)
{
if (!fLooper) {
if (fLooper == NULL) {
debugger("handler must belong to looper before setting NextHandler");
return;
}
@@ -318,7 +322,7 @@ BHandler::SetNextHandler(BHandler *handler)
return;
}
if (handler && fLooper != handler->Looper()) {
if (handler != NULL && fLooper != handler->Looper()) {
debugger("The handler and its NextHandler must have the same looper");
return;
}
@@ -338,7 +342,7 @@ void
BHandler::AddFilter(BMessageFilter* filter)
{
BLooper* looper = fLooper;
if (looper && !looper->IsLocked()) {
if (looper != NULL && !looper->IsLocked()) {
debugger("Owning Looper must be locked before calling SetFilterList");
return;
}
@@ -346,7 +350,7 @@ BHandler::AddFilter(BMessageFilter *filter)
if (looper != NULL)
filter->SetLooper(looper);
if (!fFilters)
if (fFilters == NULL)
fFilters = new BList;
fFilters->AddItem(filter);
@@ -357,7 +361,7 @@ bool
BHandler::RemoveFilter(BMessageFilter* filter)
{
BLooper* looper = fLooper;
if (looper && !looper->IsLocked()) {
if (looper != NULL && !looper->IsLocked()) {
debugger("Owning Looper must be locked before calling SetFilterList");
return false;
}
@@ -375,7 +379,7 @@ void
BHandler::SetFilterList(BList* filters)
{
BLooper* looper = fLooper;
if (looper && !looper->IsLocked()) {
if (looper != NULL && !looper->IsLocked()) {
debugger("Owning Looper must be locked before calling SetFilterList");
return;
}
@@ -389,7 +393,7 @@ BHandler::SetFilterList(BList* filters)
*/
// TODO: Explore issues with using BObjectList
if (fFilters) {
if (fFilters != NULL) {
fFilters->DoForEach(FilterDeleter);
delete fFilters;
}
@@ -461,18 +465,18 @@ BHandler::UnlockLooper()
BHandler*
BHandler::ResolveSpecifier(BMessage *msg, int32 index,
BMessage *specifier, int32 form, const char *property)
BHandler::ResolveSpecifier(BMessage* message, int32 index,
BMessage* specifier, int32 what, const char* property)
{
// Straight from the BeBook
BPropertyInfo propertyInfo(sHandlerPropInfo);
if (propertyInfo.FindMatch(msg, index, specifier, form, property) >= 0)
if (propertyInfo.FindMatch(message, index, specifier, what, property) >= 0)
return this;
BMessage reply(B_MESSAGE_NOT_UNDERSTOOD);
reply.AddInt32("error", B_BAD_SCRIPT_SYNTAX);
reply.AddString("message", "Didn't understand the specifier(s)");
msg->SendReply(&reply);
message->SendReply(&reply);
return NULL;
}
@@ -507,12 +511,12 @@ BMessage: what = (0x0, or 0)
*/
status_t err = B_OK;
if (!data)
if (data == NULL)
err = B_BAD_VALUE;
if (!err) {
if (err != B_OK) {
err = data->AddString("suites", "suite/vnd.Be-handler");
if (!err) {
if (err != B_OK) {
BPropertyInfo propertyInfo(sHandlerPropInfo);
err = data->AddFlat("messages", &propertyInfo);
}
@@ -602,10 +606,10 @@ BHandler::Perform(perform_code d, void *arg)
void
BHandler::SendNotices(uint32 what, const BMessage *msg)
BHandler::SendNotices(uint32 what, const BMessage* notice)
{
if (fObserverList != NULL)
fObserverList->SendNotices(what, msg);
fObserverList->SendNotices(what, notice);
}
@@ -658,11 +662,14 @@ void
BHandler::SetLooper(BLooper* looper)
{
fLooper = looper;
gDefaultTokens.SetHandlerTarget(fToken, looper ? looper->fDirectTarget : NULL);
gDefaultTokens.SetHandlerTarget(fToken,
looper ? looper->fDirectTarget : NULL);
if (fFilters) {
for (int32 i = 0; i < fFilters->CountItems(); i++)
static_cast<BMessageFilter *>(fFilters->ItemAtFast(i))->SetLooper(looper);
if (fFilters != NULL) {
for (int32 i = 0; i < fFilters->CountItems(); i++) {
static_cast<BMessageFilter*>(
fFilters->ItemAtFast(i))->SetLooper(looper);
}
}
}
@@ -717,9 +724,10 @@ ObserverList::_ValidateHandlers(uint32 what)
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);
// now send it to all messengers we know
@@ -732,20 +740,20 @@ ObserverList::_SendNotices(uint32 what, BMessage* message)
continue;
}
(*iterator).SendMessage(message);
(*iterator).SendMessage(notice);
iterator++;
}
}
status_t
ObserverList::SendNotices(uint32 what, const BMessage* message)
ObserverList::SendNotices(uint32 what, const BMessage* notice)
{
BMessage* copy = NULL;
if (message) {
copy = new BMessage(*message);
if (notice != NULL) {
copy = new BMessage(*notice);
copy->what = B_OBSERVER_NOTICE_CHANGE;
copy->AddInt32(B_OBSERVE_ORIGINAL_WHAT, message->what);
copy->AddInt32(B_OBSERVE_ORIGINAL_WHAT, notice->what);
} else
copy = new BMessage(B_OBSERVER_NOTICE_CHANGE);
@@ -755,6 +763,7 @@ ObserverList::SendNotices(uint32 what, const BMessage* message)
_SendNotices(B_OBSERVER_OBSERVE_ALL, copy);
delete copy;
return B_OK;
}
@@ -863,4 +872,3 @@ FilterDeleter(void *_filter)
delete static_cast<BMessageFilter*>(_filter);
return false;
}
+47 -43
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.
*
* Authors:
* Erik Jaesler (erik@cgsoftware.com)
* DarkWyrm (bpmagic@columbus.rr.com)
* Ingo Weinhold, bonefish@@users.sf.net
* DarkWyrm, bpmagic@columbus.rr.com
* 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>
@@ -106,7 +106,8 @@ struct _loop_data_ {
BLooper::BLooper(const char* name, int32 priority, int32 portCapacity)
: BHandler(name)
:
BHandler(name)
{
_InitData(name, priority, portCapacity);
}
@@ -626,8 +627,8 @@ BLooper::Sem() const
BHandler*
BLooper::ResolveSpecifier(BMessage* msg, int32 index, BMessage* specifier,
int32 form, const char* property)
BLooper::ResolveSpecifier(BMessage* message, int32 index, BMessage* specifier,
int32 what, const char* property)
{
/**
@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;
status_t err = B_OK;
const char* errMsg = "";
if (propertyInfo.FindMatch(msg, index, specifier, form, property, &data)
if (propertyInfo.FindMatch(message, index, specifier, what, property, &data)
>= 0) {
switch (data) {
case BLOOPER_PROCESS_INTERNALLY:
@@ -654,13 +655,13 @@ BLooper::ResolveSpecifier(BMessage* msg, int32 index, BMessage* specifier,
case BLOOPER_HANDLER_BY_INDEX:
{
int32 index = specifier->FindInt32("index");
if (form == B_REVERSE_INDEX_SPECIFIER) {
if (what == B_REVERSE_INDEX_SPECIFIER) {
index = CountHandlers() - index;
}
BHandler* target = HandlerAt(index);
if (target) {
// Specifier has been fully handled
msg->PopSpecifier();
message->PopSpecifier();
return target;
} else {
err = B_BAD_INDEX;
@@ -672,17 +673,16 @@ BLooper::ResolveSpecifier(BMessage* msg, int32 index, BMessage* specifier,
default:
err = B_BAD_SCRIPT_SYNTAX;
errMsg = "Didn't understand the specifier(s)";
break;
}
} else {
return BHandler::ResolveSpecifier(msg, index, specifier, form,
return BHandler::ResolveSpecifier(message, index, specifier, what,
property);
}
BMessage reply(B_MESSAGE_NOT_UNDERSTOOD);
reply.AddInt32("error", err);
reply.AddString("message", errMsg);
msg->SendReply(&reply);
message->SendReply(&reply);
return NULL;
}
@@ -709,7 +709,7 @@ BLooper::GetSupportedSuites(BMessage* data)
void
BLooper::AddCommonFilter(BMessageFilter* filter)
{
if (!filter)
if (filter == NULL)
return;
AssertLocked();
@@ -719,7 +719,7 @@ BLooper::AddCommonFilter(BMessageFilter* filter)
return;
}
if (!fCommonFilters)
if (fCommonFilters == NULL)
fCommonFilters = new BList(FILTER_LIST_BLOCK_SIZE);
filter->SetLooper(this);
@@ -732,7 +732,7 @@ BLooper::RemoveCommonFilter(BMessageFilter* filter)
{
AssertLocked();
if (!fCommonFilters)
if (fCommonFilters == NULL)
return false;
bool result = fCommonFilters->RemoveItem(filter);
@@ -1048,7 +1048,9 @@ BLooper::ReadRawFromPort(int32* msgCode, bigtime_t timeout)
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;
}
@@ -1061,7 +1063,7 @@ BLooper::ReadMessageFromPort(bigtime_t timeout)
BMessage* message = NULL;
void* buffer = ReadRawFromPort(&msgCode, timeout);
if (!buffer)
if (buffer == NULL)
return NULL;
message = ConvertToMessage(buffer, msgCode);
@@ -1076,7 +1078,7 @@ BMessage*
BLooper::ConvertToMessage(void* buffer, int32 code)
{
PRINT(("BLooper::ConvertToMessage()\n"));
if (!buffer)
if (buffer == NULL)
return NULL;
BMessage* message = new BMessage();
@@ -1139,7 +1141,7 @@ BLooper::task_looper()
fLastMessage = message;
if (!fLastMessage) {
if (fLastMessage == NULL) {
// No more messages: Unlock the looper and terminate the
// dispatch loop.
dispatchNextMessage = false;
@@ -1295,24 +1297,25 @@ BHandler*
BLooper::_ApplyFilters(BList* list, BMessage* message, BHandler* target)
{
// This is where the action is!
// Check the parameters
if (!list || !message)
// check the parameters
if (list == NULL || message == NULL)
return target;
// For each filter in the provided list
// for each filter in the provided list
BMessageFilter* filter = NULL;
for (int32 i = 0; i < list->CountItems(); ++i) {
filter = (BMessageFilter*)list->ItemAt(i);
// Check command conditions
// check command conditions
if (filter->FiltersAnyCommand() || filter->Command() == message->what) {
// Check delivery conditions
// check delivery conditions
message_delivery delivery = filter->MessageDelivery();
bool dropped = message->WasDropped();
if (delivery == B_ANY_DELIVERY
|| (delivery == B_DROPPED_DELIVERY && dropped)
|| (delivery == B_PROGRAMMED_DELIVERY && !dropped)) {
// Check source conditions
// check source conditions
message_source source = filter->MessageSource();
bool remote = message->IsSourceRemote();
if (source == B_ANY_SOURCE
@@ -1320,15 +1323,15 @@ BLooper::_ApplyFilters(BList* list, BMessage* message, BHandler* target)
|| (source == B_LOCAL_SOURCE && !remote)) {
// Are we using an "external" function?
filter_result result;
filter_hook func = filter->FilterFunction();
if (func)
result = func(message, &target, filter);
filter_hook filterFunction = filter->FilterFunction();
if (filterFunction != NULL)
result = filterFunction(message, &target, filter);
else
result = filter->Filter(message, &target);
// Is further processing allowed?
if (result == B_SKIP_MESSAGE) {
// No; time to bail out
// no, time to bail out
return NULL;
}
}
@@ -1343,13 +1346,14 @@ BLooper::_ApplyFilters(BList* list, BMessage* message, BHandler* target)
void
BLooper::check_lock()
{
// This is a cheap variant of AssertLocked()
// It is used in situations where it's clear that the looper is valid,
// ie. from handlers
// this is a cheap variant of AssertLocked()
// it is used in situations where it's clear that the looper is valid,
// i.e. from handlers
uint32 stack;
if (((addr_t)&stack & ~(B_PAGE_SIZE - 1)) == fCachedStack
|| fOwner == find_thread(NULL))
|| fOwner == find_thread(NULL)) {
return;
}
debugger("Looper must be locked.");
}
@@ -1358,7 +1362,7 @@ BLooper::check_lock()
BHandler*
BLooper::resolve_specifier(BHandler* target, BMessage* message)
{
// Check params
// check params
if (!target || !message)
return NULL;
@@ -1368,27 +1372,28 @@ BLooper::resolve_specifier(BHandler* target, BMessage* message)
const char* property;
status_t err = B_OK;
BHandler* newTarget = target;
// Loop to deal with nested specifiers
// loop to deal with nested specifiers
// (e.g., the 3rd button on the 4th view)
do {
err = message->GetCurrentSpecifier(&index, &specifier, &form, &property);
err = message->GetCurrentSpecifier(&index, &specifier, &form,
&property);
if (err != B_OK) {
BMessage reply(B_REPLY);
reply.AddInt32("error", err);
message->SendReply(&reply);
return NULL;
}
// Current target gets what was the new target
// current target gets what was the new target
target = newTarget;
newTarget = target->ResolveSpecifier(message, index, &specifier, form,
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
// destruction by another looper)
if (!newTarget || IndexOf(newTarget) < 0)
if (newTarget == NULL || IndexOf(newTarget) < 0)
return NULL;
// Get current specifier index (may change in ResolveSpecifier())
// get current specifier index (may change in ResolveSpecifier())
err = message->GetCurrentSpecifier(&index);
} while (newTarget && newTarget != target && err == B_OK && index >= 0);
@@ -1426,4 +1431,3 @@ _get_looper_port_(const BLooper* looper)
{
return looper->fMsgPort;
}
+10 -11
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.
*
* Authors:
* Michael Lotz <mmlr@mlotz.ch>
* Michael Lotz, mmlr@mlotz.ch
*/
@@ -67,8 +67,9 @@ const char *B_PROPERTY_ENTRY = "property";
const char* B_PROPERTY_NAME_ENTRY = "name";
static status_t handle_reply(port_id replyPort, int32 *pCode, bigtime_t timeout,
BMessage *reply);
static status_t handle_reply(port_id replyPort, int32* pCode,
bigtime_t timeout, BMessage* reply);
extern "C" {
// private os function to set the owning team of an area
@@ -476,8 +477,8 @@ BMessage::GetInfo(type_code typeRequested, int32 index, char **nameFound,
status_t
BMessage::GetInfo(const char *name, type_code *typeFound, int32 *countFound)
const
BMessage::GetInfo(const char* name, type_code* typeFound,
int32* countFound) const
{
DEBUG_FUNCTION_ENTER;
if (countFound != NULL)
@@ -2241,9 +2242,7 @@ BMessage::_SendMessage(port_id port, team_id portOwner, int32 token,
}
/*!
Sends a message and waits synchronously for a reply.
*/
// Sends a message and waits synchronously for a reply.
status_t
BMessage::_SendMessage(port_id port, team_id portOwner, int32 token,
BMessage* reply, bigtime_t sendTimeout, bigtime_t replyTimeout) const
@@ -2895,8 +2894,8 @@ BMessage::FindMessenger(const char *name, BMessenger *messenger) const
status_t
BMessage::FindMessenger(const char *name, int32 index, BMessenger *messenger)
const
BMessage::FindMessenger(const char* name, int32 index,
BMessenger* messenger) const
{
if (messenger == NULL)
return B_BAD_VALUE;
+1 -1
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.
*
* Authors:
+5 -6
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.
*
* Authors:
@@ -7,7 +7,8 @@
* Axel Dörfler, axeld@pinc-software.de
*/
/** Queue for holding BMessages */
// Queue for holding BMessages
#include <MessageQueue.h>
@@ -213,10 +214,8 @@ BMessageQueue::IsNextMessage(const BMessage* message) const
}
/*!
\brief This method is only here for R5 binary compatibility!
It should be dropped as soon as possible (it misses the const qualifier).
*/
// This method is only here for R5 binary compatibility!
// It should be dropped as soon as possible (it misses the const qualifier).
bool
BMessageQueue::IsLocked()
{