From be902ac4db5c9d0be72f6d54aa67b66e3dcc7eca Mon Sep 17 00:00:00 2001 From: John Scipione Date: Wed, 11 Jun 2014 16:11:14 -0400 Subject: [PATCH] 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. --- headers/os/app/Application.h | 6 +- headers/os/app/Handler.h | 11 +- headers/os/app/Looper.h | 10 +- headers/os/app/Message.h | 6 +- headers/os/app/MessageFilter.h | 80 ++--- headers/os/app/MessageQueue.h | 69 ++--- src/kits/app/Application.cpp | 358 +++++++++++----------- src/kits/app/Handler.cpp | 146 ++++----- src/kits/app/Looper.cpp | 114 +++---- src/kits/app/Message.cpp | 539 ++++++++++++++++----------------- src/kits/app/MessageFilter.cpp | 4 +- src/kits/app/MessageQueue.cpp | 29 +- 12 files changed, 706 insertions(+), 666 deletions(-) diff --git a/headers/os/app/Application.h b/headers/os/app/Application.h index b206e28890..8ab5d9f700 100644 --- a/headers/os/app/Application.h +++ b/headers/os/app/Application.h @@ -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 diff --git a/headers/os/app/Handler.h b/headers/os/app/Handler.h index 9f691aca84..800bd822a3 100644 --- a/headers/os/app/Handler.h +++ b/headers/os/app/Handler.h @@ -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 (erik@cgsoftware.com) + * Erik Jaesler, erik@cgsoftware.com */ #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: diff --git a/headers/os/app/Looper.h b/headers/os/app/Looper.h index 5aa7eadec8..a4bf958f18 100644 --- a/headers/os/app/Looper.h +++ b/headers/os/app/Looper.h @@ -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 (erik@cgsoftware.com) + * Erik Jaesler, erik@cgsoftware.com */ #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); diff --git a/headers/os/app/Message.h b/headers/os/app/Message.h index df5455226c..05488c2c63 100644 --- a/headers/os/app/Message.h +++ b/headers/os/app/Message.h @@ -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 + * Michael Lotz, mmlr@mlotz.ch */ #ifndef _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 BString& string); - status_t AddStrings(const char *name, + status_t AddStrings(const char* name, const BStringList& list); status_t AddInt8(const char* name, int8 value); status_t AddUInt8(const char* name, uint8 value); diff --git a/headers/os/app/MessageFilter.h b/headers/os/app/MessageFilter.h index 539f38b882..1621a7a16a 100644 --- a/headers/os/app/MessageFilter.h +++ b/headers/os/app/MessageFilter.h @@ -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 (erik@cgsoftware.com) + * Erik Jaesler, erik@cgsoftware.com */ #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,47 +40,49 @@ enum message_source { }; -// BMessageFilter Class -------------------------------------------------------- class BMessageFilter { - public: - BMessageFilter(uint32 what, - filter_hook func = NULL); - BMessageFilter(message_delivery delivery, - message_source source, filter_hook func = NULL); - BMessageFilter(message_delivery delivery, - message_source source, uint32 what, - filter_hook func = NULL); - BMessageFilter(const BMessageFilter& filter); - BMessageFilter(const BMessageFilter* filter); - virtual ~BMessageFilter(); +public: + BMessageFilter(uint32 what, + filter_hook func = NULL); + BMessageFilter(message_delivery delivery, + message_source source, filter_hook func = NULL); + BMessageFilter(message_delivery delivery, + message_source source, uint32 what, + filter_hook func = NULL); + BMessageFilter(const BMessageFilter& filter); + BMessageFilter(const BMessageFilter* filter); + virtual ~BMessageFilter(); - BMessageFilter& operator=(const BMessageFilter& from); + BMessageFilter& operator=(const BMessageFilter& from); - // Hook function; ignored if filter_hook is non-NULL - virtual filter_result Filter(BMessage* message, BHandler** _target); + // Hook function; ignored if filter_hook is non-NULL + virtual filter_result Filter(BMessage* message, BHandler** _target); - message_delivery MessageDelivery() const; - message_source MessageSource() const; - uint32 Command() const; - bool FiltersAnyCommand() const; - BLooper* Looper() const; + message_delivery MessageDelivery() const; + message_source MessageSource() const; + uint32 Command() const; + bool FiltersAnyCommand() const; + BLooper* Looper() const; - private: - friend class BLooper; - friend class BHandler; +private: + friend class BLooper; + friend class BHandler; - virtual void _ReservedMessageFilter1(); - virtual void _ReservedMessageFilter2(); + virtual void _ReservedMessageFilter1(); + virtual void _ReservedMessageFilter2(); - 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]; + 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 diff --git a/headers/os/app/MessageQueue.h b/headers/os/app/MessageQueue.h index eeea3eb23e..b4005b515a 100644 --- a/headers/os/app/MessageQueue.h +++ b/headers/os/app/MessageQueue.h @@ -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. */ -#ifndef _MESSAGE_QUEUE_H -#define _MESSAGE_QUEUE_H +#ifndef _MESSAGE_QUEUE_H +#define _MESSAGE_QUEUE_H #include #include - /* For convenience */ + // For convenience class BMessageQueue { - public: - BMessageQueue(); - virtual ~BMessageQueue(); +public: + BMessageQueue(); + virtual ~BMessageQueue(); - void AddMessage(BMessage* message); - void RemoveMessage(BMessage* message); + void AddMessage(BMessage* message); + void RemoveMessage(BMessage* message); - int32 CountMessages() const; - bool IsEmpty() const; + int32 CountMessages() const; + bool IsEmpty() const; - BMessage* FindMessage(int32 index) const; - BMessage* FindMessage(uint32 what, int32 index = 0) const; + BMessage* FindMessage(int32 index) const; + BMessage* FindMessage(uint32 what, int32 index = 0) const; - bool Lock(); - void Unlock(); - bool IsLocked() const; + bool Lock(); + void Unlock(); + bool IsLocked() const; - BMessage *NextMessage(); - bool IsNextMessage(const BMessage* message) const; + BMessage* NextMessage(); + bool IsNextMessage(const BMessage* message) const; - private: - // Reserved space in the vtable for future changes to BMessageQueue - virtual void _ReservedMessageQueue1(); - virtual void _ReservedMessageQueue2(); - virtual void _ReservedMessageQueue3(); +private: + // Reserved space in the vtable for future changes to BMessageQueue + virtual void _ReservedMessageQueue1(); + virtual void _ReservedMessageQueue2(); + virtual void _ReservedMessageQueue3(); - BMessageQueue(const BMessageQueue &); - BMessageQueue &operator=(const BMessageQueue &); + BMessageQueue(const BMessageQueue &); + BMessageQueue& operator=(const BMessageQueue &); - bool IsLocked(); - // this needs to be exported for R5 compatibility and should - // be dropped as soon as possible + bool IsLocked(); + // this needs to be exported for R5 compatibility and should + // be dropped as soon as possible - private: - BMessage* fHead; - BMessage* fTail; - int32 fMessageCount; - mutable BLocker fLock; +private: + BMessage* fHead; + BMessage* fTail; + int32 fMessageCount; + mutable BLocker fLock; - uint32 _reserved[3]; + uint32 _reserved[3]; }; + #endif // _MESSAGE_QUEUE_H diff --git a/src/kits/app/Application.cpp b/src/kits/app/Application.cpp index b2704e9f20..0e6a20abff 100644 --- a/src/kits/app/Application.cpp +++ b/src/kits/app/Application.cpp @@ -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 (erik@cgsoftware.com) - * Jerome Duval * Axel Dörfler, axeld@pinc-software.de + * Jerome Duval + * Erik Jaesler, erik@cgsoftware.com */ @@ -51,11 +51,11 @@ using namespace BPrivate; -BApplication *be_app = NULL; +BApplication* be_app = NULL; BMessenger be_app_messenger; pthread_once_t sAppResourcesInitOnce = PTHREAD_ONCE_INIT; -BResources *BApplication::sAppResources = NULL; +BResources* BApplication::sAppResources = NULL; enum { @@ -67,6 +67,7 @@ enum { kApplication }; + static property_info sPropertyInfo[] = { { "Window", @@ -161,9 +162,10 @@ static property_info sPropertyInfo[] = { {} }; + // argc/argv extern const int __libc_argc; -extern const char * const *__libc_argv; +extern const char* const *__libc_argv; // debugging @@ -172,42 +174,116 @@ 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 -BApplication::BApplication(const char *signature) - : BLooper(looper_name_for(signature)) +// #pragma mark - BApplication + + +BApplication::BApplication(const char* signature) + : + BLooper(looper_name_for(signature)) { _InitData(signature, true, NULL); } -BApplication::BApplication(const char *signature, status_t *_error) - : BLooper(looper_name_for(signature)) +BApplication::BApplication(const char* signature, status_t* _error) + : + BLooper(looper_name_for(signature)) { _InitData(signature, true, _error); } -BApplication::BApplication(const char *signature, bool initGUI, - status_t *_error) - : BLooper(looper_name_for(signature)) +BApplication::BApplication(const char* signature, bool initGUI, + status_t* _error) + : + BLooper(looper_name_for(signature)) { _InitData(signature, initGUI, _error); } -BApplication::BApplication(BMessage *data) - // Note: BeOS calls the private BLooper(int32, port_id, const char *) +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; + const char* signature = NULL; data->FindString("mime_sig", &signature); _InitData(signature, true, NULL); @@ -260,7 +336,7 @@ BApplication::~BApplication() } -BApplication & +BApplication& BApplication::operator=(const BApplication &rhs) { return *this; @@ -268,7 +344,7 @@ BApplication::operator=(const BApplication &rhs) 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)); // 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 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); @@ -457,8 +534,8 @@ DBG(OUT("BApplication::InitData() done\n")); } -BArchivable * -BApplication::Instantiate(BMessage *data) +BArchivable* +BApplication::Instantiate(BMessage* data) { if (validate_instantiation(data, "BApplication")) return new BApplication(data); @@ -468,7 +545,7 @@ BApplication::Instantiate(BMessage *data) status_t -BApplication::Archive(BMessage *data, bool deep) const +BApplication::Archive(BMessage* data, bool deep) const { status_t status = BLooper::Archive(data, deep); if (status < B_OK) @@ -520,9 +597,10 @@ BApplication::Quit() { bool unlock = false; if (!IsLocked()) { - const char *name = Name(); - if (!name) + const char* name = 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(); @@ -579,7 +658,7 @@ BApplication::ReadyToRun() void -BApplication::MessageReceived(BMessage *message) +BApplication::MessageReceived(BMessage* message) { switch (message->what) { case B_COUNT_PROPERTIES: @@ -589,10 +668,13 @@ BApplication::MessageReceived(BMessage *message) int32 index; BMessage specifier; int32 what; - const char *property = NULL; - if (message->GetCurrentSpecifier(&index, &specifier, &what, &property) < B_OK - || !ScriptReceived(message, index, &specifier, what, property)) + const char* property = NULL; + if (message->GetCurrentSpecifier(&index, &specifier, &what, + &property) < B_OK + || !ScriptReceived(message, index, &specifier, what, + property)) { BLooper::MessageReceived(message); + } break; } @@ -619,13 +701,12 @@ BApplication::MessageReceived(BMessage *message) default: BLooper::MessageReceived(message); - break; } } void -BApplication::ArgvReceived(int32 argc, char **argv) +BApplication::ArgvReceived(int32 argc, char** argv) { // supposed to be implemented by subclasses } @@ -639,7 +720,7 @@ BApplication::AppActivated(bool active) void -BApplication::RefsReceived(BMessage *message) +BApplication::RefsReceived(BMessage* message) { // supposed to be implemented by subclasses } @@ -650,16 +731,16 @@ BApplication::AboutRequested() { thread_info info; 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->Go(NULL); } } -BHandler * -BApplication::ResolveSpecifier(BMessage *message, int32 index, - BMessage *specifier, int32 what, const char *property) +BHandler* +BApplication::ResolveSpecifier(BMessage* message, int32 index, + BMessage* specifier, int32 what, const char* property) { BPropertyInfo propInfo(sPropertyInfo); status_t err = B_OK; @@ -677,7 +758,7 @@ BApplication::ResolveSpecifier(BMessage *message, int32 index, if (what == B_REVERSE_INDEX_SPECIFIER) index = CountWindows() - index; - BWindow *window = WindowAt(index); + BWindow* window = WindowAt(index); if (window != NULL) { message->PopSpecifier(); BMessenger(window).SendMessage(message); @@ -688,18 +769,19 @@ BApplication::ResolveSpecifier(BMessage *message, int32 index, case kWindowByName: { - const char *name; + const char* name; err = specifier->FindString("name", &name); if (err != B_OK) break; for (int32 i = 0;; i++) { - BWindow *window = WindowAt(i); + BWindow* window = WindowAt(i); if (window == NULL) { 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; @@ -718,12 +800,13 @@ BApplication::ResolveSpecifier(BMessage *message, int32 index, if (what == B_REVERSE_INDEX_SPECIFIER) index = CountLoopers() - index; - BLooper *looper = LooperAt(index); + BLooper* looper = LooperAt(index); if (looper != NULL) { message->PopSpecifier(); BMessenger(looper).SendMessage(message); } else err = B_BAD_INDEX; + break; } @@ -733,18 +816,19 @@ BApplication::ResolveSpecifier(BMessage *message, int32 index, case kLooperByName: { - const char *name; + const char* name; err = specifier->FindString("name", &name); if (err != B_OK) break; for (int32 i = 0;; i++) { - BLooper *looper = LooperAt(i); + BLooper* looper = LooperAt(i); if (looper == NULL) { 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; @@ -813,7 +897,7 @@ BApplication::IsCursorHidden() const void -BApplication::SetCursor(const void *cursorData) +BApplication::SetCursor(const void* cursorData) { BCursor cursor(cursorData); SetCursor(&cursor, true); @@ -822,7 +906,7 @@ BApplication::SetCursor(const void *cursorData) void -BApplication::SetCursor(const BCursor *cursor, bool sync) +BApplication::SetCursor(const BCursor* cursor, bool sync) { BPrivate::AppServerLink link; link.StartMessage(AS_SET_CURSOR); @@ -845,7 +929,7 @@ BApplication::CountWindows() const } -BWindow * +BWindow* BApplication::WindowAt(int32 index) const { return _WindowAt(index, false); @@ -865,10 +949,10 @@ BApplication::CountLoopers() const } -BLooper * +BLooper* BApplication::LooperAt(int32 index) const { - BLooper *looper = NULL; + BLooper* looper = NULL; AutoLocker listLock(gLooperList); if (listLock.IsLocked()) looper = gLooperList.LooperAt(index); @@ -885,7 +969,7 @@ BApplication::IsLaunching() const status_t -BApplication::GetAppInfo(app_info *info) const +BApplication::GetAppInfo(app_info* info) const { if (be_app == NULL || be_roster == NULL) return B_NO_INIT; @@ -893,7 +977,7 @@ BApplication::GetAppInfo(app_info *info) const } -BResources * +BResources* BApplication::AppResources() { if (sAppResources == NULL) @@ -904,7 +988,7 @@ BApplication::AppResources() void -BApplication::DispatchMessage(BMessage *message, BHandler *handler) +BApplication::DispatchMessage(BMessage* message, BHandler* handler) { if (handler != this) { // it's not ours to dispatch @@ -1025,9 +1109,9 @@ BApplication::SetPulseRate(bigtime_t rate) status_t -BApplication::GetSupportedSuites(BMessage *data) +BApplication::GetSupportedSuites(BMessage* data) { - if (!data) + if (data == NULL) return B_BAD_VALUE; status_t status = data->AddString("suites", "suite/vnd.Be-application"); @@ -1043,7 +1127,7 @@ BApplication::GetSupportedSuites(BMessage *data) status_t -BApplication::Perform(perform_code d, void *arg) +BApplication::Perform(perform_code d, void* arg) { return BLooper::Perform(d, arg); } @@ -1060,8 +1144,8 @@ void BApplication::_ReservedApplication8() {} bool -BApplication::ScriptReceived(BMessage *message, int32 index, - BMessage *specifier, int32 what, const char *property) +BApplication::ScriptReceived(BMessage* message, int32 index, + BMessage* specifier, int32 what, const char* property) { BMessage reply(B_REPLY); status_t err = B_BAD_SCRIPT_SYNTAX; @@ -1091,19 +1175,23 @@ 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; + const char* name; err = specifier->FindString("name", &name); if (err != B_OK) break; @@ -1129,27 +1217,31 @@ 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) + BLooper* looper = LooperAt(index); + if (looper == NULL) break; + BMessenger messenger(looper); err = reply.AddMessenger("result", messenger); break; } + case B_NAME_SPECIFIER: { - const char *name; + const char* name; err = specifier->FindString("name", &name); if (err != B_OK) break; err = B_NAME_NOT_FOUND; for (int32 i = 0; i < CountLoopers(); i++) { - BLooper *looper = LooperAt(i); - if (looper && looper->Name() - && !strcmp(looper->Name(), name)) { + BLooper* looper = LooperAt(i); + 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; } @@ -1261,7 +1356,7 @@ BApplication::_ConnectToServer() // 2) port_id - looper port for this BApplication // 3) team_id - team identification field // 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->Attach(fServerLink->ReceiverPort()); @@ -1301,6 +1396,7 @@ BApplication::_ConnectToServer() return status; fServerReadOnlyMemory = base; + return B_OK; } @@ -1335,34 +1431,35 @@ BApplication::_ReconnectToServer() #if 0 void -BApplication::send_drag(BMessage *message, int32 vs_token, BPoint offset, - BRect dragRect, BHandler *replyTo) +BApplication::send_drag(BMessage* message, int32 vs_token, BPoint offset, + BRect dragRect, BHandler* replyTo) { // TODO: implement } void -BApplication::send_drag(BMessage *message, int32 vs_token, BPoint offset, - int32 bitmapToken, drawing_mode dragMode, BHandler *replyTo) +BApplication::send_drag(BMessage* message, int32 vs_token, BPoint offset, + int32 bitmapToken, drawing_mode dragMode, BHandler* replyTo) { // TODO: implement } void -BApplication::write_drag(_BSession_ *session, BMessage *message) +BApplication::write_drag(_BSession_* session, BMessage* message) { // TODO: implement } #endif + bool BApplication::_WindowQuitLoop(bool quitFilePanels, bool force) { int32 index = 0; while (true) { - BWindow *window = WindowAt(index); + BWindow* window = WindowAt(index); if (window == NULL) break; @@ -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; } @@ -1421,14 +1519,14 @@ BApplication::_QuitAllWindows(bool force) void -BApplication::_ArgvReceived(BMessage *message) +BApplication::_ArgvReceived(BMessage* message) { ASSERT(message != NULL); // build the argv vector status_t error = B_OK; int32 argc = 0; - char **argv = NULL; + char** argv = NULL; if (message->FindInt32("argc", &argc) == B_OK && argc > 0) { // allocate a NULL terminated array argv = new(std::nothrow) char*[argc + 1]; @@ -1437,7 +1535,7 @@ BApplication::_ArgvReceived(BMessage *message) // copy the arguments for (int32 i = 0; error == B_OK && i < argc; i++) { - const char *arg = NULL; + const char* arg = NULL; error = message->FindString("argv", i, &arg); if (error == B_OK && arg) { argv[i] = strdup(arg); @@ -1482,7 +1580,7 @@ BApplication::_CountWindows(bool includeMenus) const for (int32 i = 0; i < gLooperList.CountLoopers(); i++) { BWindow* window = dynamic_cast(gLooperList.LooperAt(i)); if (window != NULL && !window->fOffscreen && (includeMenus - || dynamic_cast(window) == NULL)) { + || dynamic_cast(window) == NULL)) { count++; } } @@ -1491,7 +1589,7 @@ BApplication::_CountWindows(bool includeMenus) const } -BWindow * +BWindow* BApplication::_WindowAt(uint32 index, bool includeMenus) const { AutoLocker listLock(gLooperList); @@ -1502,7 +1600,7 @@ BApplication::_WindowAt(uint32 index, bool includeMenus) const for (uint32 i = 0; i < count && index < count; i++) { BWindow* window = dynamic_cast(gLooperList.LooperAt(i)); if (window == NULL || (window != NULL && window->fOffscreen) - || (!includeMenus && dynamic_cast(window) != NULL)) { + || (!includeMenus && dynamic_cast(window) != NULL)) { index++; continue; } @@ -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 - diff --git a/src/kits/app/Handler.cpp b/src/kits/app/Handler.cpp index f7fbb79828..f4443ca757 100644 --- a/src/kits/app/Handler.cpp +++ b/src/kits/app/Handler.cpp @@ -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 */ @@ -86,7 +86,7 @@ static property_info sHandlerPropInfo[] = { {} }; -bool FilterDeleter(void *filter); +bool FilterDeleter(void* filter); namespace BPrivate { @@ -103,7 +103,7 @@ class ObserverList { bool IsEmpty(); private: - typedef map > HandlerObserverMap; + typedef map > HandlerObserverMap; typedef map > MessengerObserverMap; void _ValidateHandlers(uint32 what); @@ -121,7 +121,7 @@ using namespace BPrivate; // #pragma mark - -BHandler::BHandler(const char *name) +BHandler::BHandler(const char* name) : BArchivable(), fName(NULL) { @@ -154,11 +154,11 @@ BHandler::~BHandler() } -BHandler::BHandler(BMessage *data) +BHandler::BHandler(BMessage* data) : BArchivable(data), fName(NULL) { - const char *name = NULL; + const char* name = NULL; if (data) data->FindString(kArchiveNameField, &name); @@ -167,8 +167,8 @@ BHandler::BHandler(BMessage *data) } -BArchivable * -BHandler::Instantiate(BMessage *data) +BArchivable* +BHandler::Instantiate(BMessage* data) { if (!validate_instantiation(data, "BHandler")) return NULL; @@ -178,20 +178,21 @@ BHandler::Instantiate(BMessage *data) status_t -BHandler::Archive(BMessage *data, bool deep) const +BHandler::Archive(BMessage* data, bool deep) const { status_t status = BArchivable::Archive(data, deep); if (status < B_OK) return status; - if (!fName) + if (fName == NULL) return B_OK; + return data->AddString(kArchiveNameField, fName); } void -BHandler::MessageReceived(BMessage *message) +BHandler::MessageReceived(BMessage* message) { BMessage reply(B_REPLY); @@ -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) { @@ -220,7 +223,7 @@ BHandler::MessageReceived(BMessage *message) int32 cur; BMessage specifier; int32 form; - const char *prop; + const char* prop; status_t err = message->GetCurrentSpecifier(&cur, &specifier, &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) { // we need to apply the next handler's filters here, too @@ -278,7 +282,7 @@ BHandler::MessageReceived(BMessage *message) } -BLooper * +BLooper* BHandler::Looper() const { return fLooper; @@ -286,7 +290,7 @@ BHandler::Looper() const void -BHandler::SetName(const char *name) +BHandler::SetName(const char* name) { if (fName != NULL) { free(fName); @@ -298,7 +302,7 @@ BHandler::SetName(const char *name) } -const char * +const char* BHandler::Name() const { return fName; @@ -306,9 +310,9 @@ BHandler::Name() const void -BHandler::SetNextHandler(BHandler *handler) +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; } @@ -327,7 +331,7 @@ BHandler::SetNextHandler(BHandler *handler) } -BHandler * +BHandler* BHandler::NextHandler() const { return fNextHandler; @@ -335,10 +339,10 @@ BHandler::NextHandler() const void -BHandler::AddFilter(BMessageFilter *filter) +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); @@ -354,15 +358,15 @@ BHandler::AddFilter(BMessageFilter *filter) bool -BHandler::RemoveFilter(BMessageFilter *filter) +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; } - if (fFilters != NULL && fFilters->RemoveItem((void *)filter)) { + if (fFilters != NULL && fFilters->RemoveItem((void*)filter)) { filter->SetLooper(NULL); return true; } @@ -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; } @@ -397,8 +401,8 @@ BHandler::SetFilterList(BList* filters) fFilters = filters; if (fFilters) { for (int32 i = 0; i < fFilters->CountItems(); ++i) { - BMessageFilter *filter = - static_cast(fFilters->ItemAt(i)); + BMessageFilter* filter = + static_cast(fFilters->ItemAt(i)); if (filter != NULL) filter->SetLooper(looper); } @@ -406,7 +410,7 @@ BHandler::SetFilterList(BList* filters) } -BList * +BList* BHandler::FilterList() { return fFilters; @@ -416,7 +420,7 @@ BHandler::FilterList() bool BHandler::LockLooper() { - BLooper *looper = fLooper; + BLooper* looper = fLooper; // Locking the looper also makes sure that the looper is valid if (looper != NULL && looper->Lock()) { // Have we locked the right looper? That's as far as the @@ -435,7 +439,7 @@ BHandler::LockLooper() status_t BHandler::LockLooperWithTimeout(bigtime_t timeout) { - BLooper *looper = fLooper; + BLooper* looper = fLooper; if (looper == NULL) return B_BAD_VALUE; @@ -460,26 +464,26 @@ BHandler::UnlockLooper() } -BHandler * -BHandler::ResolveSpecifier(BMessage *msg, int32 index, - BMessage *specifier, int32 form, const char *property) +BHandler* +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; } status_t -BHandler::GetSupportedSuites(BMessage *data) +BHandler::GetSupportedSuites(BMessage* data) { /** @note This is the output from the original implementation (calling @@ -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); } @@ -588,24 +592,24 @@ BHandler::StopWatching(BHandler* handler, uint32 what) status_t -BHandler::StopWatchingAll(BHandler *handler) +BHandler::StopWatchingAll(BHandler* handler) { return StopWatching(handler, B_OBSERVER_OBSERVE_ALL); } status_t -BHandler::Perform(perform_code d, void *arg) +BHandler::Perform(perform_code d, void* arg) { return BArchivable::Perform(d, 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); } @@ -617,7 +621,7 @@ BHandler::IsWatched() const void -BHandler::_InitData(const char *name) +BHandler::_InitData(const char* name) { SetName(name); @@ -655,14 +659,17 @@ BHandler::operator=(const BHandler &) void -BHandler::SetLooper(BLooper *looper) +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(fFilters->ItemAtFast(i))->SetLooper(looper); + if (fFilters != NULL) { + for (int32 i = 0; i < fFilters->CountItems(); i++) { + static_cast( + fFilters->ItemAtFast(i))->SetLooper(looper); + } } } @@ -700,8 +707,8 @@ ObserverList::~ObserverList() void ObserverList::_ValidateHandlers(uint32 what) { - vector& handlers = fHandlerMap[what]; - vector::iterator iterator = handlers.begin(); + vector& handlers = fHandlerMap[what]; + vector::iterator iterator = handlers.begin(); while (iterator != handlers.end()) { BMessenger target(*iterator); @@ -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); + BMessage* copy = NULL; + 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,12 +763,13 @@ ObserverList::SendNotices(uint32 what, const BMessage* message) _SendNotices(B_OBSERVER_OBSERVE_ALL, copy); delete copy; + return B_OK; } status_t -ObserverList::Add(const BHandler *handler, uint32 what) +ObserverList::Add(const BHandler* handler, uint32 what) { if (handler == NULL) return B_BAD_HANDLER; @@ -802,7 +811,7 @@ ObserverList::Add(const BMessenger &messenger, uint32 what) status_t -ObserverList::Remove(const BHandler *handler, uint32 what) +ObserverList::Remove(const BHandler* handler, uint32 what) { if (handler == NULL) return B_BAD_HANDLER; @@ -858,9 +867,8 @@ ObserverList::IsEmpty() bool -FilterDeleter(void *_filter) +FilterDeleter(void* _filter) { - delete static_cast(_filter); + delete static_cast(_filter); return false; } - diff --git a/src/kits/app/Looper.cpp b/src/kits/app/Looper.cpp index 4af20167fa..a47236b770 100644 --- a/src/kits/app/Looper.cpp +++ b/src/kits/app/Looper.cpp @@ -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 @@ -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); @@ -879,7 +879,7 @@ BLooper::_Lock(BLooper* looper, port_id port, bigtime_t timeout) return B_BAD_VALUE; } } else if (!gLooperList.IsLooperValid(looper)) { - // Check looper validity + // Check looper validity PRINT(("BLooper::_Lock() done 4\n")); return B_BAD_VALUE; } @@ -908,7 +908,7 @@ BLooper::_Lock(BLooper* looper, port_id port, bigtime_t timeout) 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) { status_t err = B_OK; @@ -934,7 +934,7 @@ BLooper::_LockComplete(BLooper *looper, int32 oldCount, thread_id thread, void -BLooper::_InitData(const char *name, int32 priority, int32 portCapacity) +BLooper::_InitData(const char* name, int32 priority, int32 portCapacity) { fOwner = B_ERROR; fCachedStack = 0; @@ -1001,7 +1001,7 @@ BLooper::_AddMessagePriv(BMessage* message) status_t BLooper::_task0_(void* arg) { - BLooper* looper = (BLooper *)arg; + BLooper* looper = (BLooper*)arg; PRINT(("LOOPER: _task0_()\n")); @@ -1017,11 +1017,11 @@ BLooper::_task0_(void* arg) } -void * +void* BLooper::ReadRawFromPort(int32* msgCode, bigtime_t timeout) { PRINT(("BLooper::ReadRawFromPort()\n")); - uint8 *buffer = NULL; + uint8* buffer = NULL; ssize_t bufferSize; do { @@ -1034,7 +1034,7 @@ BLooper::ReadRawFromPort(int32* msgCode, bigtime_t timeout) } if (bufferSize > 0) - buffer = (uint8 *)malloc(bufferSize); + buffer = (uint8*)malloc(bufferSize); // we don't want to wait again here, since that can only mean // that someone else has read our message and our bufferSize @@ -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; } @@ -1058,10 +1060,10 @@ BLooper::ReadMessageFromPort(bigtime_t timeout) { PRINT(("BLooper::ReadMessageFromPort()\n")); int32 msgCode; - BMessage *message = NULL; + BMessage* message = NULL; - void *buffer = ReadRawFromPort(&msgCode, timeout); - if (!buffer) + void* buffer = ReadRawFromPort(&msgCode, timeout); + 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(); @@ -1109,7 +1111,7 @@ BLooper::task_looper() // TODO: timeout determination algo // Read from message port (how do we determine what the timeout is?) PRINT(("LOOPER: MessageFromPort()...\n")); - BMessage *msg = MessageFromPort(); + BMessage* msg = MessageFromPort(); PRINT(("LOOPER: ...done\n")); // Did we get a message? @@ -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; @@ -1149,7 +1151,7 @@ BLooper::task_looper() DBG(fLastMessage->PrintToStream()); // Get the target handler - BHandler *handler = NULL; + BHandler* handler = NULL; BMessage::Private messagePrivate(fLastMessage); bool usePreferred = messagePrivate.UsePreferredTarget(); @@ -1160,7 +1162,7 @@ BLooper::task_looper() handler = this; } else { 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 (handler != NULL && handler->Looper() != this) @@ -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; } - diff --git a/src/kits/app/Message.cpp b/src/kits/app/Message.cpp index eaa01d7c1f..7c6efae8ea 100644 --- a/src/kits/app/Message.cpp +++ b/src/kits/app/Message.cpp @@ -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 + * Michael Lotz, mmlr@mlotz.ch */ @@ -44,7 +44,7 @@ #define DEBUG_FUNCTION_ENTER \ debug_printf("msg thread: %ld; this: %p; header: %p; fields: %p;" \ " data: %p; what: 0x%08lx '%.4s'; line: %d; func: %s\n", \ - find_thread(NULL), this, fHeader, fFields, fData, what, (char *)&what, \ + find_thread(NULL), this, fHeader, fFields, fData, what, (char*)&what, \ __LINE__, __PRETTY_FUNCTION__); #define DEBUG_FUNCTION_ENTER2 \ @@ -62,56 +62,57 @@ #endif -const char *B_SPECIFIER_ENTRY = "specifiers"; -const char *B_PROPERTY_ENTRY = "property"; -const char *B_PROPERTY_NAME_ENTRY = "name"; +const char* B_SPECIFIER_ENTRY = "specifiers"; +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 - status_t _kern_transfer_area(area_id area, void **_address, + status_t _kern_transfer_area(area_id area, void** _address, uint32 addressSpec, team_id target); } -BBlockCache *BMessage::sMsgCache = NULL; +BBlockCache* BMessage::sMsgCache = NULL; port_id BMessage::sReplyPorts[sNumReplyPorts]; int32 BMessage::sReplyPortInUse[sNumReplyPorts]; template static void -print_to_stream_type(uint8 *pointer) +print_to_stream_type(uint8* pointer) { - Type *item = (Type *)pointer; + Type* item = (Type*)pointer; item->PrintToStream(); } template static void -print_type(const char *format, uint8 *pointer) +print_type(const char* format, uint8* pointer) { - Type *item = (Type *)pointer; - printf(format, *item, *item); + Type* item = (Type*)pointer; + printf(format,* item,* item); } template static void -print_type3(const char *format, uint8 *pointer) +print_type3(const char* format, uint8* pointer) { - Type *item = (Type *)pointer; + Type* item = (Type*)pointer; printf(format, *item, *item, *item); } static status_t -handle_reply(port_id replyPort, int32 *_code, bigtime_t timeout, - BMessage *reply) +handle_reply(port_id replyPort, int32* _code, bigtime_t timeout, + BMessage* reply) { DEBUG_FUNCTION_ENTER2; ssize_t size; @@ -123,7 +124,7 @@ handle_reply(port_id replyPort, int32 *_code, bigtime_t timeout, return size; status_t result; - char *buffer = (char *)malloc(size); + char* buffer = (char*)malloc(size); if (buffer == NULL) return B_NO_MEMORY; @@ -152,7 +153,7 @@ BMessage::BMessage() } -BMessage::BMessage(BMessage *other) +BMessage::BMessage(BMessage* other) { DEBUG_FUNCTION_ENTER; _InitCommon(false); @@ -168,7 +169,7 @@ BMessage::BMessage(uint32 _what) } -BMessage::BMessage(const BMessage &other) +BMessage::BMessage(const BMessage& other) { DEBUG_FUNCTION_ENTER; _InitCommon(false); @@ -183,8 +184,8 @@ BMessage::~BMessage() } -BMessage & -BMessage::operator=(const BMessage &other) +BMessage& +BMessage::operator=(const BMessage& other) { DEBUG_FUNCTION_ENTER; @@ -193,7 +194,7 @@ BMessage::operator=(const BMessage &other) _Clear(); - fHeader = (message_header *)malloc(sizeof(message_header)); + fHeader = (message_header*)malloc(sizeof(message_header)); if (fHeader == NULL) return *this; @@ -212,7 +213,7 @@ BMessage::operator=(const BMessage &other) if (fHeader->field_count > 0) { size_t fieldsSize = fHeader->field_count * sizeof(field_header); if (other.fFields != NULL) - fFields = (field_header *)malloc(fieldsSize); + fFields = (field_header*)malloc(fieldsSize); if (fFields == NULL) { fHeader->field_count = 0; @@ -223,7 +224,7 @@ BMessage::operator=(const BMessage &other) if (fHeader->data_size > 0) { if (other.fData != NULL) - fData = (uint8 *)malloc(fHeader->data_size); + fData = (uint8*)malloc(fHeader->data_size); if (fData == NULL) { fHeader->field_count = 0; @@ -242,7 +243,7 @@ BMessage::operator=(const BMessage &other) } -void * +void* BMessage::operator new(size_t size) { DEBUG_FUNCTION_ENTER2; @@ -250,16 +251,16 @@ BMessage::operator new(size_t size) } -void * -BMessage::operator new(size_t size, const std::nothrow_t &noThrow) +void* +BMessage::operator new(size_t size, const std::nothrow_t& noThrow) { DEBUG_FUNCTION_ENTER2; return sMsgCache->Get(size); } -void * -BMessage::operator new(size_t, void *pointer) +void* +BMessage::operator new(size_t, void* pointer) { DEBUG_FUNCTION_ENTER2; return pointer; @@ -267,7 +268,7 @@ BMessage::operator new(size_t, void *pointer) void -BMessage::operator delete(void *pointer, size_t size) +BMessage::operator delete(void* pointer, size_t size) { DEBUG_FUNCTION_ENTER2; if (pointer == NULL) @@ -277,7 +278,7 @@ BMessage::operator delete(void *pointer, size_t size) bool -BMessage::HasSameData(const BMessage &other, bool ignoreFieldOrder, +BMessage::HasSameData(const BMessage& other, bool ignoreFieldOrder, bool deep) const { if (this == &other) @@ -290,10 +291,10 @@ BMessage::HasSameData(const BMessage &other, bool ignoreFieldOrder, return false; for (uint32 i = 0; i < fHeader->field_count; i++) { - field_header *field = &fFields[i]; - field_header *otherField = NULL; + field_header* field = &fFields[i]; + field_header* otherField = NULL; - const char *name = (const char *)fData + field->offset; + const char* name = (const char*)fData + field->offset; if (ignoreFieldOrder) { if (other._FindField(name, B_ANY_TYPE, &otherField) != B_OK) return false; @@ -302,7 +303,7 @@ BMessage::HasSameData(const BMessage &other, bool ignoreFieldOrder, if (otherField->name_length != field->name_length) return false; - const char *otherName = (const char *)other.fData + const char* otherName = (const char*)other.fData + otherField->offset; if (strncmp(name, otherName, field->name_length) != 0) return false; @@ -313,15 +314,15 @@ BMessage::HasSameData(const BMessage &other, bool ignoreFieldOrder, return false; } - uint8 *data = fData + field->offset + field->name_length; - uint8 *otherData = other.fData + otherField->offset + uint8* data = fData + field->offset + field->name_length; + uint8* otherData = other.fData + otherField->offset + otherField->name_length; bool needsMemCompare = true; if (deep && field->type == B_MESSAGE_TYPE) { BMessage message, otherMessage; - if (message.Unflatten((const char *)data) == B_OK - && otherMessage.Unflatten((const char *)otherData) == B_OK) { + if (message.Unflatten((const char*)data) == B_OK + && otherMessage.Unflatten((const char*)otherData) == B_OK) { if (!message.HasSameData(ignoreFieldOrder, deep)) return false; needsMemCompare = false; @@ -370,7 +371,7 @@ BMessage::_InitHeader() { DEBUG_FUNCTION_ENTER; if (fHeader == NULL) { - fHeader = (message_header *)malloc(sizeof(message_header)); + fHeader = (message_header*)malloc(sizeof(message_header)); if (fHeader == NULL) return B_NO_MEMORY; } @@ -431,8 +432,8 @@ BMessage::_Clear() status_t -BMessage::GetInfo(type_code typeRequested, int32 index, char **nameFound, - type_code *typeFound, int32 *countFound) const +BMessage::GetInfo(type_code typeRequested, int32 index, char** nameFound, + type_code* typeFound, int32* countFound) const { DEBUG_FUNCTION_ENTER; if (fHeader == NULL) @@ -443,7 +444,7 @@ BMessage::GetInfo(type_code typeRequested, int32 index, char **nameFound, if (typeRequested == B_ANY_TYPE) { if (nameFound != NULL) - *nameFound = (char *)fData + fFields[index].offset; + *nameFound = (char*)fData + fFields[index].offset; if (typeFound != NULL) *typeFound = fFields[index].type; if (countFound != NULL) @@ -452,14 +453,14 @@ BMessage::GetInfo(type_code typeRequested, int32 index, char **nameFound, } int32 counter = -1; - field_header *field = fFields; + field_header* field = fFields; for (uint32 i = 0; i < fHeader->field_count; i++, field++) { if (field->type == typeRequested) counter++; if (counter == index) { if (nameFound != NULL) - *nameFound = (char *)fData + field->offset; + *nameFound = (char*)fData + field->offset; if (typeFound != NULL) *typeFound = field->type; if (countFound != NULL) @@ -476,14 +477,14 @@ 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) *countFound = 0; - field_header *field = NULL; + field_header* field = NULL; status_t result = _FindField(name, B_ANY_TYPE, &field); if (result != B_OK) return result; @@ -498,11 +499,11 @@ BMessage::GetInfo(const char *name, type_code *typeFound, int32 *countFound) status_t -BMessage::GetInfo(const char *name, type_code *typeFound, bool *fixedSize) +BMessage::GetInfo(const char* name, type_code* typeFound, bool* fixedSize) const { DEBUG_FUNCTION_ENTER; - field_header *field = NULL; + field_header* field = NULL; status_t result = _FindField(name, B_ANY_TYPE, &field); if (result != B_OK) return result; @@ -517,11 +518,11 @@ BMessage::GetInfo(const char *name, type_code *typeFound, bool *fixedSize) status_t -BMessage::GetInfo(const char *name, type_code *typeFound, int32 *countFound, - bool *fixedSize) const +BMessage::GetInfo(const char* name, type_code* typeFound, int32* countFound, + bool* fixedSize) const { DEBUG_FUNCTION_ENTER; - field_header *field = NULL; + field_header* field = NULL; status_t result = _FindField(name, B_ANY_TYPE, &field); if (result != B_OK) return result; @@ -548,7 +549,7 @@ BMessage::CountNames(type_code type) const return fHeader->field_count; int32 count = 0; - field_header *field = fFields; + field_header* field = fFields; for (uint32 i = 0; i < fHeader->field_count; i++, field++) { if (field->type == type) count++; @@ -605,14 +606,14 @@ BMessage::PrintToStream() const void -BMessage::_PrintToStream(const char *indent) const +BMessage::_PrintToStream(const char* indent) const { DEBUG_FUNCTION_ENTER; int32 value = B_BENDIAN_TO_HOST_INT32(what); printf("BMessage("); - if (isprint(*(char *)&value)) - printf("'%.4s'", (char *)&value); + if (isprint(*(char*)&value)) + printf("'%.4s'", (char*)&value); else printf("0x%" B_PRIx32, what); printf(") {\n"); @@ -620,25 +621,25 @@ BMessage::_PrintToStream(const char *indent) const if (fHeader == NULL || fFields == NULL || fData == NULL) return; - field_header *field = fFields; + field_header* field = fFields; for (uint32 i = 0; i < fHeader->field_count; i++, field++) { value = B_BENDIAN_TO_HOST_INT32(field->type); ssize_t size = 0; if ((field->flags & FIELD_FLAG_FIXED_SIZE) != 0 && field->count > 0) size = field->data_size / field->count; - uint8 *pointer = fData + field->offset + field->name_length; + uint8* pointer = fData + field->offset + field->name_length; for (uint32 j = 0; j < field->count; j++) { if (field->count == 1) { printf("%s %s = ", indent, - (char *)(fData + field->offset)); + (char*)(fData + field->offset)); } else { printf("%s %s[%" B_PRIu32 "] = ", indent, - (char *)(fData + field->offset), j); + (char*)(fData + field->offset), j); } if ((field->flags & FIELD_FLAG_FIXED_SIZE) == 0) { - size = *(uint32 *)pointer; + size = *(uint32*)pointer; pointer += sizeof(uint32); } @@ -653,7 +654,7 @@ BMessage::_PrintToStream(const char *indent) const case B_STRING_TYPE: printf("string(\"%.*s\", %ld bytes)\n", (int)size, - (char *)pointer, (long)size); + (char*)pointer, (long)size); break; case B_INT8_TYPE: @@ -691,7 +692,7 @@ BMessage::_PrintToStream(const char *indent) const break; case B_BOOL_TYPE: - printf("bool(%s)\n", *((bool *)pointer) != 0 + printf("bool(%s)\n", *((bool*)pointer) != 0 ? "true" : "false"); break; @@ -706,7 +707,7 @@ BMessage::_PrintToStream(const char *indent) const case B_REF_TYPE: { entry_ref ref; - BPrivate::entry_ref_unflatten(&ref, (char *)pointer, size); + BPrivate::entry_ref_unflatten(&ref, (char*)pointer, size); printf("entry_ref(device=%d, directory=%" B_PRIdINO ", name=\"%s\", ", (int)ref.device, ref.directory, @@ -723,7 +724,7 @@ BMessage::_PrintToStream(const char *indent) const snprintf(buffer, sizeof(buffer), "%s ", indent); BMessage message; - status_t result = message.Unflatten((const char *)pointer); + status_t result = message.Unflatten((const char*)pointer); if (result != B_OK) { printf("failed unflatten: %s\n", strerror(result)); break; @@ -736,7 +737,7 @@ BMessage::_PrintToStream(const char *indent) const default: { - printf("(type = '%.4s')(size = %ld)\n", (char *)&value, + printf("(type = '%.4s')(size = %ld)\n", (char*)&value, (long)size); break; } @@ -749,7 +750,7 @@ BMessage::_PrintToStream(const char *indent) const status_t -BMessage::Rename(const char *oldEntry, const char *newEntry) +BMessage::Rename(const char* oldEntry, const char* newEntry) { DEBUG_FUNCTION_ENTER; if (oldEntry == NULL || newEntry == NULL) @@ -762,12 +763,12 @@ BMessage::Rename(const char *oldEntry, const char *newEntry) _CopyForWrite(); uint32 hash = _HashName(oldEntry) % fHeader->hash_table_size; - int32 *nextField = &fHeader->hash_table[hash]; + int32* nextField = &fHeader->hash_table[hash]; while (*nextField >= 0) { - field_header *field = &fFields[*nextField]; + field_header* field = &fFields[*nextField]; - if (strncmp((const char *)(fData + field->offset), oldEntry, + if (strncmp((const char*)(fData + field->offset), oldEntry, field->name_length) == 0) { // nextField points to the field for oldEntry, save it and unlink int32 index = *nextField; @@ -841,7 +842,7 @@ BMessage::ReturnAddress() const } -const BMessage * +const BMessage* BMessage::Previous() const { DEBUG_FUNCTION_ENTER; @@ -869,7 +870,7 @@ BMessage::WasDropped() const BPoint -BMessage::DropPoint(BPoint *offset) const +BMessage::DropPoint(BPoint* offset) const { DEBUG_FUNCTION_ENTER; if (offset != NULL) @@ -880,7 +881,7 @@ BMessage::DropPoint(BPoint *offset) const status_t -BMessage::SendReply(uint32 command, BHandler *replyTo) +BMessage::SendReply(uint32 command, BHandler* replyTo) { DEBUG_FUNCTION_ENTER; BMessage message(command); @@ -889,7 +890,7 @@ BMessage::SendReply(uint32 command, BHandler *replyTo) status_t -BMessage::SendReply(BMessage *reply, BHandler *replyTo, bigtime_t timeout) +BMessage::SendReply(BMessage* reply, BHandler* replyTo, bigtime_t timeout) { DEBUG_FUNCTION_ENTER; BMessenger messenger(replyTo); @@ -898,7 +899,7 @@ BMessage::SendReply(BMessage *reply, BHandler *replyTo, bigtime_t timeout) status_t -BMessage::SendReply(BMessage *reply, BMessenger replyTo, bigtime_t timeout) +BMessage::SendReply(BMessage* reply, BMessenger replyTo, bigtime_t timeout) { DEBUG_FUNCTION_ENTER; if (fHeader == NULL) @@ -942,7 +943,7 @@ BMessage::SendReply(BMessage *reply, BMessenger replyTo, bigtime_t timeout) status_t -BMessage::SendReply(uint32 command, BMessage *replyToReply) +BMessage::SendReply(uint32 command, BMessage* replyToReply) { DEBUG_FUNCTION_ENTER; BMessage message(command); @@ -951,7 +952,7 @@ BMessage::SendReply(uint32 command, BMessage *replyToReply) status_t -BMessage::SendReply(BMessage *reply, BMessage *replyToReply, +BMessage::SendReply(BMessage* reply, BMessage* replyToReply, bigtime_t sendTimeout, bigtime_t replyTimeout) { DEBUG_FUNCTION_ENTER; @@ -1010,7 +1011,7 @@ BMessage::FlattenedSize() const status_t -BMessage::Flatten(char *buffer, ssize_t size) const +BMessage::Flatten(char* buffer, ssize_t size) const { DEBUG_FUNCTION_ENTER; if (buffer == NULL || size < 0) @@ -1039,7 +1040,7 @@ BMessage::Flatten(char *buffer, ssize_t size) const status_t -BMessage::Flatten(BDataIO *stream, ssize_t *size) const +BMessage::Flatten(BDataIO* stream, ssize_t* size) const { DEBUG_FUNCTION_ENTER; if (stream == NULL) @@ -1107,13 +1108,13 @@ BMessage::Flatten(BDataIO *stream, ssize_t *size) const */ status_t -BMessage::_FlattenToArea(message_header **_header) const +BMessage::_FlattenToArea(message_header** _header) const { DEBUG_FUNCTION_ENTER; if (fHeader == NULL) return B_NO_INIT; - message_header *header = (message_header *)malloc(sizeof(message_header)); + message_header* header = (message_header*)malloc(sizeof(message_header)); if (header == NULL) return B_NO_MEMORY; @@ -1126,11 +1127,11 @@ BMessage::_FlattenToArea(message_header **_header) const if (header->field_count == 0 && header->data_size == 0) return B_OK; - char *address = NULL; + char* address = NULL; size_t fieldsSize = header->field_count * sizeof(field_header); size_t size = fieldsSize + header->data_size; size = (size + B_PAGE_SIZE) & ~(B_PAGE_SIZE - 1); - area_id area = create_area("BMessage data", (void **)&address, + area_id area = create_area("BMessage data", (void**)&address, B_ANY_ADDRESS, size, B_NO_LOCK, B_READ_AREA | B_WRITE_AREA); if (area < 0) { @@ -1165,9 +1166,9 @@ BMessage::_Reference() if (result != B_OK) return result; - uint8 *address = (uint8 *)areaInfo.address; + uint8* address = (uint8*)areaInfo.address; - fFields = (field_header *)address; + fFields = (field_header*)address; fData = address + fHeader->field_count * sizeof(field_header); return B_OK; } @@ -1195,12 +1196,12 @@ BMessage::_CopyForWrite() if (fHeader == NULL) return B_NO_INIT; - field_header *newFields = NULL; - uint8 *newData = NULL; + field_header* newFields = NULL; + uint8* newData = NULL; if (fHeader->field_count > 0) { size_t fieldsSize = fHeader->field_count * sizeof(field_header); - newFields = (field_header *)malloc(fieldsSize); + newFields = (field_header*)malloc(fieldsSize); if (newFields == NULL) return B_NO_MEMORY; @@ -1208,7 +1209,7 @@ BMessage::_CopyForWrite() } if (fHeader->data_size > 0) { - newData = (uint8 *)malloc(fHeader->data_size); + newData = (uint8*)malloc(fHeader->data_size); if (newData == NULL) { free(newFields); return B_NO_MEMORY; @@ -1242,7 +1243,7 @@ BMessage::_ValidateMessage() return B_NO_INIT; for (uint32 i = 0; i < fHeader->field_count; i++) { - field_header *field = &fFields[i]; + field_header* field = &fFields[i]; if ((field->next_field >= 0 && (uint32)field->next_field > fHeader->field_count) || (field->offset + field->name_length + field->data_size @@ -1258,13 +1259,13 @@ BMessage::_ValidateMessage() status_t -BMessage::Unflatten(const char *flatBuffer) +BMessage::Unflatten(const char* flatBuffer) { DEBUG_FUNCTION_ENTER; if (flatBuffer == NULL) return B_BAD_VALUE; - uint32 format = *(uint32 *)flatBuffer; + uint32 format = *(uint32*)flatBuffer; if (format != MESSAGE_FORMAT_HAIKU) return BPrivate::MessageAdapter::Unflatten(format, this, flatBuffer); @@ -1272,7 +1273,7 @@ BMessage::Unflatten(const char *flatBuffer) _Clear(); - fHeader = (message_header *)malloc(sizeof(message_header)); + fHeader = (message_header*)malloc(sizeof(message_header)); if (fHeader == NULL) return B_NO_MEMORY; @@ -1297,7 +1298,7 @@ BMessage::Unflatten(const char *flatBuffer) if (fHeader->field_count > 0) { size_t fieldsSize = fHeader->field_count * sizeof(field_header); - fFields = (field_header *)malloc(fieldsSize); + fFields = (field_header*)malloc(fieldsSize); if (fFields == NULL) { _InitHeader(); return B_NO_MEMORY; @@ -1308,7 +1309,7 @@ BMessage::Unflatten(const char *flatBuffer) } if (fHeader->data_size > 0) { - fData = (uint8 *)malloc(fHeader->data_size); + fData = (uint8*)malloc(fHeader->data_size); if (fData == NULL) { free(fFields); fFields = NULL; @@ -1325,7 +1326,7 @@ BMessage::Unflatten(const char *flatBuffer) status_t -BMessage::Unflatten(BDataIO *stream) +BMessage::Unflatten(BDataIO* stream) { DEBUG_FUNCTION_ENTER; if (stream == NULL) @@ -1340,12 +1341,12 @@ BMessage::Unflatten(BDataIO *stream) _Clear(); - fHeader = (message_header *)malloc(sizeof(message_header)); + fHeader = (message_header*)malloc(sizeof(message_header)); if (fHeader == NULL) return B_NO_MEMORY; fHeader->format = format; - uint8 *header = (uint8 *)fHeader; + uint8* header = (uint8*)fHeader; ssize_t result = stream->Read(header + sizeof(uint32), sizeof(message_header) - sizeof(uint32)); if (result != sizeof(message_header) - sizeof(uint32) @@ -1360,7 +1361,7 @@ BMessage::Unflatten(BDataIO *stream) if (fHeader->field_count > 0) { ssize_t fieldsSize = fHeader->field_count * sizeof(field_header); - fFields = (field_header *)malloc(fieldsSize); + fFields = (field_header*)malloc(fieldsSize); if (fFields == NULL) { _InitHeader(); return B_NO_MEMORY; @@ -1372,7 +1373,7 @@ BMessage::Unflatten(BDataIO *stream) } if (fHeader->data_size > 0) { - fData = (uint8 *)malloc(fHeader->data_size); + fData = (uint8*)malloc(fHeader->data_size); if (fData == NULL) { free(fFields); fFields = NULL; @@ -1390,7 +1391,7 @@ BMessage::Unflatten(BDataIO *stream) status_t -BMessage::AddSpecifier(const char *property) +BMessage::AddSpecifier(const char* property) { DEBUG_FUNCTION_ENTER; BMessage message(B_DIRECT_SPECIFIER); @@ -1403,7 +1404,7 @@ BMessage::AddSpecifier(const char *property) status_t -BMessage::AddSpecifier(const char *property, int32 index) +BMessage::AddSpecifier(const char* property, int32 index) { DEBUG_FUNCTION_ENTER; BMessage message(B_INDEX_SPECIFIER); @@ -1420,7 +1421,7 @@ BMessage::AddSpecifier(const char *property, int32 index) status_t -BMessage::AddSpecifier(const char *property, int32 index, int32 range) +BMessage::AddSpecifier(const char* property, int32 index, int32 range) { DEBUG_FUNCTION_ENTER; if (range < 0) @@ -1444,7 +1445,7 @@ BMessage::AddSpecifier(const char *property, int32 index, int32 range) status_t -BMessage::AddSpecifier(const char *property, const char *name) +BMessage::AddSpecifier(const char* property, const char* name) { DEBUG_FUNCTION_ENTER; BMessage message(B_NAME_SPECIFIER); @@ -1461,7 +1462,7 @@ BMessage::AddSpecifier(const char *property, const char *name) status_t -BMessage::AddSpecifier(const BMessage *specifier) +BMessage::AddSpecifier(const BMessage* specifier) { DEBUG_FUNCTION_ENTER; status_t result = AddMessage(B_SPECIFIER_ENTRY, specifier); @@ -1496,8 +1497,8 @@ BMessage::SetCurrentSpecifier(int32 index) status_t -BMessage::GetCurrentSpecifier(int32 *index, BMessage *specifier, int32 *_what, - const char **property) const +BMessage::GetCurrentSpecifier(int32* index, BMessage* specifier, int32* _what, + const char** property) const { DEBUG_FUNCTION_ENTER; if (fHeader == NULL) @@ -1563,7 +1564,7 @@ BMessage::_ResizeData(uint32 offset, int32 change) /* optimize for the most usual case: appending data */ if (offset < fHeader->data_size) { - field_header *field = fFields; + field_header* field = fFields; for (uint32 i = 0; i < fHeader->field_count; i++, field++) { if (field->offset >= offset) field->offset += change; @@ -1586,7 +1587,7 @@ BMessage::_ResizeData(uint32 offset, int32 change) size = min_c(size, fHeader->data_size + MAX_DATA_PREALLOCATION); size = max_c(size, fHeader->data_size + change); - uint8 *newData = (uint8 *)realloc(fData, size); + uint8* newData = (uint8*)realloc(fData, size); if (size > 0 && newData == NULL) return B_NO_MEMORY; @@ -1610,7 +1611,7 @@ BMessage::_ResizeData(uint32 offset, int32 change) if (fDataAvailable > MAX_DATA_PREALLOCATION) { ssize_t available = MAX_DATA_PREALLOCATION / 2; ssize_t size = fHeader->data_size + available; - uint8 *newData = (uint8 *)realloc(fData, size); + uint8* newData = (uint8*)realloc(fData, size); if (size > 0 && newData == NULL) { // this is strange, but not really fatal return B_OK; @@ -1626,7 +1627,7 @@ BMessage::_ResizeData(uint32 offset, int32 change) uint32 -BMessage::_HashName(const char *name) const +BMessage::_HashName(const char* name) const { char ch; uint32 result = 0; @@ -1642,7 +1643,7 @@ BMessage::_HashName(const char *name) const status_t -BMessage::_FindField(const char *name, type_code type, field_header **result) +BMessage::_FindField(const char* name, type_code type, field_header** result) const { if (name == NULL) @@ -1658,11 +1659,11 @@ BMessage::_FindField(const char *name, type_code type, field_header **result) int32 nextField = fHeader->hash_table[hash]; while (nextField >= 0) { - field_header *field = &fFields[nextField]; + field_header* field = &fFields[nextField]; if ((field->flags & FIELD_FLAG_VALID) == 0) break; - if (strncmp((const char *)(fData + field->offset), name, + if (strncmp((const char*)(fData + field->offset), name, field->name_length) == 0) { if (type != B_ANY_TYPE && field->type != type) return B_BAD_TYPE; @@ -1679,8 +1680,8 @@ BMessage::_FindField(const char *name, type_code type, field_header **result) status_t -BMessage::_AddField(const char *name, type_code type, bool isFixedSize, - field_header **result) +BMessage::_AddField(const char* name, type_code type, bool isFixedSize, + field_header** result) { if (fHeader == NULL) return B_NO_INIT; @@ -1689,7 +1690,7 @@ BMessage::_AddField(const char *name, type_code type, bool isFixedSize, uint32 count = fHeader->field_count * 2 + 1; count = min_c(count, fHeader->field_count + MAX_FIELD_PREALLOCATION); - field_header *newFields = (field_header *)realloc(fFields, + field_header* newFields = (field_header*)realloc(fFields, count * sizeof(field_header)); if (count > 0 && newFields == NULL) return B_NO_MEMORY; @@ -1699,12 +1700,12 @@ BMessage::_AddField(const char *name, type_code type, bool isFixedSize, } uint32 hash = _HashName(name) % fHeader->hash_table_size; - int32 *nextField = &fHeader->hash_table[hash]; + int32* nextField = &fHeader->hash_table[hash]; while (*nextField >= 0) nextField = &fFields[*nextField].next_field; *nextField = fHeader->field_count; - field_header *field = &fFields[fHeader->field_count]; + field_header* field = &fFields[fHeader->field_count]; field->type = type; field->count = 0; field->data_size = 0; @@ -1728,19 +1729,19 @@ BMessage::_AddField(const char *name, type_code type, bool isFixedSize, status_t -BMessage::_RemoveField(field_header *field) +BMessage::_RemoveField(field_header* field) { status_t result = _ResizeData(field->offset, -(field->data_size + field->name_length)); if (result != B_OK) return result; - int32 index = ((uint8 *)field - (uint8 *)fFields) / sizeof(field_header); + int32 index = ((uint8*)field - (uint8*)fFields) / sizeof(field_header); int32 nextField = field->next_field; if (nextField > index) nextField--; - int32 *value = fHeader->hash_table; + int32* value = fHeader->hash_table; for (uint32 i = 0; i < fHeader->hash_table_size; i++, value++) { if (*value > index) *value -= 1; @@ -1748,7 +1749,7 @@ BMessage::_RemoveField(field_header *field) *value = nextField; } - field_header *other = fFields; + field_header* other = fFields; for (uint32 i = 0; i < fHeader->field_count; i++, other++) { if (other->next_field > index) other->next_field--; @@ -1764,7 +1765,7 @@ BMessage::_RemoveField(field_header *field) if (fFieldsAvailable > MAX_FIELD_PREALLOCATION) { ssize_t available = MAX_FIELD_PREALLOCATION / 2; size = (fHeader->field_count + available) * sizeof(field_header); - field_header *newFields = (field_header *)realloc(fFields, size); + field_header* newFields = (field_header*)realloc(fFields, size); if (size > 0 && newFields == NULL) { // this is strange, but not really fatal return B_OK; @@ -1779,7 +1780,7 @@ BMessage::_RemoveField(field_header *field) status_t -BMessage::AddData(const char *name, type_code type, const void *data, +BMessage::AddData(const char* name, type_code type, const void* data, ssize_t numBytes, bool isFixedSize, int32 count) { // Note that the "count" argument is only a hint at how many items @@ -1795,7 +1796,7 @@ BMessage::AddData(const char *name, type_code type, const void *data, if (fHeader->message_area >= 0) _CopyForWrite(); - field_header *field = NULL; + field_header* field = NULL; status_t result = _FindField(name, type, &field); if (result == B_NAME_NOT_FOUND) result = _AddField(name, type, isFixedSize, &field); @@ -1844,7 +1845,7 @@ BMessage::AddData(const char *name, type_code type, const void *data, status_t -BMessage::RemoveData(const char *name, int32 index) +BMessage::RemoveData(const char* name, int32 index) { DEBUG_FUNCTION_ENTER; if (index < 0) @@ -1856,7 +1857,7 @@ BMessage::RemoveData(const char *name, int32 index) if (fHeader->message_area >= 0) _CopyForWrite(); - field_header *field = NULL; + field_header* field = NULL; status_t result = _FindField(name, B_ANY_TYPE, &field); if (result != B_OK) return result; @@ -1876,13 +1877,13 @@ BMessage::RemoveData(const char *name, int32 index) field->data_size -= size; } else { - uint8 *pointer = fData + offset; + uint8* pointer = fData + offset; for (int32 i = 0; i < index; i++) { - offset += *(uint32 *)pointer + sizeof(uint32); + offset += *(uint32*)pointer + sizeof(uint32); pointer = fData + offset; } - size_t currentSize = *(uint32 *)pointer + sizeof(uint32); + size_t currentSize = *(uint32*)pointer + sizeof(uint32); result = _ResizeData(offset, -currentSize); if (result != B_OK) return result; @@ -1896,7 +1897,7 @@ BMessage::RemoveData(const char *name, int32 index) status_t -BMessage::RemoveName(const char *name) +BMessage::RemoveName(const char* name) { DEBUG_FUNCTION_ENTER; if (fHeader == NULL) @@ -1905,7 +1906,7 @@ BMessage::RemoveName(const char *name) if (fHeader->message_area >= 0) _CopyForWrite(); - field_header *field = NULL; + field_header* field = NULL; status_t result = _FindField(name, B_ANY_TYPE, &field); if (result != B_OK) return result; @@ -1924,15 +1925,15 @@ BMessage::MakeEmpty() status_t -BMessage::FindData(const char *name, type_code type, int32 index, - const void **data, ssize_t *numBytes) const +BMessage::FindData(const char* name, type_code type, int32 index, + const void** data, ssize_t* numBytes) const { DEBUG_FUNCTION_ENTER; if (data == NULL) return B_BAD_VALUE; *data = NULL; - field_header *field = NULL; + field_header* field = NULL; status_t result = _FindField(name, type, &field); if (result != B_OK) return result; @@ -1946,13 +1947,13 @@ BMessage::FindData(const char *name, type_code type, int32 index, if (numBytes != NULL) *numBytes = bytes; } else { - uint8 *pointer = fData + field->offset + field->name_length; + uint8* pointer = fData + field->offset + field->name_length; for (int32 i = 0; i < index; i++) - pointer += *(uint32 *)pointer + sizeof(uint32); + pointer += *(uint32*)pointer + sizeof(uint32); *data = pointer + sizeof(uint32); if (numBytes != NULL) - *numBytes = *(uint32 *)pointer; + *numBytes = *(uint32*)pointer; } return B_OK; @@ -1960,14 +1961,14 @@ BMessage::FindData(const char *name, type_code type, int32 index, status_t -BMessage::ReplaceData(const char *name, type_code type, int32 index, - const void *data, ssize_t numBytes) +BMessage::ReplaceData(const char* name, type_code type, int32 index, + const void* data, ssize_t numBytes) { DEBUG_FUNCTION_ENTER; if (numBytes <= 0 || data == NULL) return B_BAD_VALUE; - field_header *field = NULL; + field_header* field = NULL; status_t result = _FindField(name, type, &field); if (result != B_OK) return result; @@ -1987,14 +1988,14 @@ BMessage::ReplaceData(const char *name, type_code type, int32 index, size); } else { uint32 offset = field->offset + field->name_length; - uint8 *pointer = fData + offset; + uint8* pointer = fData + offset; for (int32 i = 0; i < index; i++) { - offset += *(uint32 *)pointer + sizeof(uint32); + offset += *(uint32*)pointer + sizeof(uint32); pointer = fData + offset; } - size_t currentSize = *(uint32 *)pointer; + size_t currentSize = *(uint32*)pointer; int32 change = numBytes - currentSize; result = _ResizeData(offset, change); if (result != B_OK) @@ -2011,10 +2012,10 @@ BMessage::ReplaceData(const char *name, type_code type, int32 index, bool -BMessage::HasData(const char *name, type_code type, int32 index) const +BMessage::HasData(const char* name, type_code type, int32 index) const { DEBUG_FUNCTION_ENTER; - field_header *field = NULL; + field_header* field = NULL; status_t result = _FindField(name, type, &field); if (result != B_OK) return false; @@ -2104,16 +2105,16 @@ BMessage::_StaticGetCachedReplyPort() status_t BMessage::_SendMessage(port_id port, team_id portOwner, int32 token, - bigtime_t timeout, bool replyRequired, BMessenger &replyTo) const + bigtime_t timeout, bool replyRequired, BMessenger& replyTo) const { DEBUG_FUNCTION_ENTER; ssize_t size = 0; - char *buffer = NULL; - message_header *header = NULL; + char* buffer = NULL; + message_header* header = NULL; status_t result = B_OK; BPrivate::BDirectMessageTarget* direct = NULL; - BMessage *copy = NULL; + BMessage* copy = NULL; if (portOwner == BPrivate::current_team()) BPrivate::gDefaultTokens.AcquireHandlerTarget(token, &direct); @@ -2137,7 +2138,7 @@ BMessage::_SendMessage(port_id port, team_id portOwner, int32 token, if (result != B_OK) return result; - buffer = (char *)header; + buffer = (char*)header; size = sizeof(message_header); if (header->message_area >= 0) { @@ -2152,7 +2153,7 @@ BMessage::_SendMessage(port_id port, team_id portOwner, int32 token, target = info.team; } - void *address = NULL; + void* address = NULL; area_id transfered = _kern_transfer_area(header->message_area, &address, B_ANY_ADDRESS, target); if (transfered < 0) { @@ -2166,7 +2167,7 @@ BMessage::_SendMessage(port_id port, team_id portOwner, int32 token, #endif } else { size = FlattenedSize(); - buffer = (char *)malloc(size); + buffer = (char*)malloc(size); if (buffer == NULL) return B_NO_MEMORY; @@ -2176,7 +2177,7 @@ BMessage::_SendMessage(port_id port, team_id portOwner, int32 token, return result; } - header = (message_header *)buffer; + header = (message_header*)buffer; } if (!replyTo.IsValid()) { @@ -2206,7 +2207,7 @@ BMessage::_SendMessage(port_id port, team_id portOwner, int32 token, char(what >> 24), char(what >> 16), char(what >> 8), (char)what); do { - result = write_port_etc(port, kPortMessageCode, (void *)buffer, + result = write_port_etc(port, kPortMessageCode, (void*)buffer, size, B_RELATIVE_TIMEOUT, timeout); } while (result == B_INTERRUPTED); } @@ -2241,12 +2242,10 @@ 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 + BMessage* reply, bigtime_t sendTimeout, bigtime_t replyTimeout) const { if (IsSourceWaiting()) { // we can't forward this message synchronously when it's already @@ -2356,29 +2355,29 @@ error: status_t -BMessage::_SendFlattenedMessage(void *data, int32 size, port_id port, +BMessage::_SendFlattenedMessage(void* data, int32 size, port_id port, int32 token, bigtime_t timeout) { DEBUG_FUNCTION_ENTER2; if (data == NULL) return B_BAD_VALUE; - uint32 magic = *(uint32 *)data; + uint32 magic = *(uint32*)data; if (magic == MESSAGE_FORMAT_HAIKU || magic == MESSAGE_FORMAT_HAIKU_SWAPPED) { - message_header *header = (message_header *)data; + message_header* header = (message_header*)data; header->target = token; header->flags |= MESSAGE_FLAG_WAS_DELIVERED; } else if (magic == MESSAGE_FORMAT_R5) { - uint8 *header = (uint8 *)data; + uint8* header = (uint8*)data; header += sizeof(uint32) /* magic */ + sizeof(uint32) /* checksum */ + sizeof(ssize_t) /* flattenedSize */ + sizeof(int32) /* what */ + sizeof(uint8) /* flags */; - *(int32 *)header = token; - } else if (((KMessage::Header *)data)->magic + *(int32*)header = token; + } else if (((KMessage::Header*)data)->magic == KMessage::kMessageHeaderMagic) { - KMessage::Header *header = (KMessage::Header *)data; + KMessage::Header* header = (KMessage::Header*)data; header->targetToken = token; } else { return B_NOT_A_MESSAGE; @@ -2408,21 +2407,21 @@ void BMessage::_ReservedMessage3() {} #define DEFINE_FUNCTIONS(type, typeName, typeCode) \ status_t \ -BMessage::Add##typeName(const char *name, type val) \ +BMessage::Add##typeName(const char* name, type val) \ { \ return AddData(name, typeCode, &val, sizeof(type), true); \ } \ \ \ status_t \ -BMessage::Find##typeName(const char *name, type *p) const \ +BMessage::Find##typeName(const char* name, type* p) const \ { \ - void *ptr = NULL; \ + void* ptr = NULL; \ ssize_t bytes = 0; \ status_t error = B_OK; \ \ *p = type(); \ - error = FindData(name, typeCode, 0, (const void **)&ptr, &bytes); \ + error = FindData(name, typeCode, 0, (const void**)&ptr, &bytes); \ \ if (error == B_OK) \ memcpy(p, ptr, sizeof(type)); \ @@ -2432,14 +2431,14 @@ BMessage::Find##typeName(const char *name, type *p) const \ \ \ status_t \ -BMessage::Find##typeName(const char *name, int32 index, type *p) const \ +BMessage::Find##typeName(const char* name, int32 index, type* p) const \ { \ - void *ptr = NULL; \ + void* ptr = NULL; \ ssize_t bytes = 0; \ status_t error = B_OK; \ \ *p = type(); \ - error = FindData(name, typeCode, index, (const void **)&ptr, &bytes); \ + error = FindData(name, typeCode, index, (const void**)&ptr, &bytes); \ \ if (error == B_OK) \ memcpy(p, ptr, sizeof(type)); \ @@ -2449,21 +2448,21 @@ BMessage::Find##typeName(const char *name, int32 index, type *p) const \ \ \ status_t \ -BMessage::Replace##typeName(const char *name, type value) \ +BMessage::Replace##typeName(const char* name, type value) \ { \ return ReplaceData(name, typeCode, 0, &value, sizeof(type)); \ } \ \ \ status_t \ -BMessage::Replace##typeName(const char *name, int32 index, type value) \ +BMessage::Replace##typeName(const char* name, int32 index, type value) \ { \ return ReplaceData(name, typeCode, index, &value, sizeof(type)); \ } \ \ \ bool \ -BMessage::Has##typeName(const char *name, int32 index) const \ +BMessage::Has##typeName(const char* name, int32 index) const \ { \ return HasData(name, typeCode, index); \ } @@ -2487,7 +2486,7 @@ DEFINE_FUNCTIONS(double, Double, B_DOUBLE_TYPE); #define DEFINE_HAS_FUNCTION(typeName, typeCode) \ bool \ -BMessage::Has##typeName(const char *name, int32 index) const \ +BMessage::Has##typeName(const char* name, int32 index) const \ { \ return HasData(name, typeCode, index); \ } @@ -2505,7 +2504,7 @@ DEFINE_HAS_FUNCTION(Message, B_MESSAGE_TYPE); #define DEFINE_LAZY_FIND_FUNCTION(type, typeName, initialize) \ type \ -BMessage::Find##typeName(const char *name, int32 index) const \ +BMessage::Find##typeName(const char* name, int32 index) const \ { \ type val = initialize; \ Find##typeName(name, index, &val); \ @@ -2515,7 +2514,7 @@ BMessage::Find##typeName(const char *name, int32 index) const \ DEFINE_LAZY_FIND_FUNCTION(BRect, Rect, BRect()); DEFINE_LAZY_FIND_FUNCTION(BPoint, Point, BPoint()); -DEFINE_LAZY_FIND_FUNCTION(const char *, String, NULL); +DEFINE_LAZY_FIND_FUNCTION(const char*, String, NULL); DEFINE_LAZY_FIND_FUNCTION(int8, Int8, 0); DEFINE_LAZY_FIND_FUNCTION(int16, Int16, 0); DEFINE_LAZY_FIND_FUNCTION(int32, Int32, 0); @@ -2529,14 +2528,14 @@ DEFINE_LAZY_FIND_FUNCTION(double, Double, 0); #define DEFINE_SET_GET_FUNCTIONS(type, typeName, typeCode) \ type \ -BMessage::Get##typeName(const char *name, type defaultValue) const \ +BMessage::Get##typeName(const char* name, type defaultValue) const \ { \ return Get##typeName(name, 0, defaultValue); \ } \ \ \ type \ -BMessage::Get##typeName(const char *name, int32 index, \ +BMessage::Get##typeName(const char* name, int32 index, \ type defaultValue) const \ { \ type value; \ @@ -2548,7 +2547,7 @@ BMessage::Get##typeName(const char *name, int32 index, \ \ \ status_t \ -BMessage::Set##typeName(const char *name, type value) \ +BMessage::Set##typeName(const char* name, type value) \ { \ return SetData(name, typeCode, &value, sizeof(type)); \ } \ @@ -2571,14 +2570,14 @@ DEFINE_SET_GET_FUNCTIONS(double, Double, B_DOUBLE_TYPE); #define DEFINE_SET_GET_BY_REFERENCE_FUNCTIONS(type, typeName, typeCode) \ type \ -BMessage::Get##typeName(const char *name, const type& defaultValue) const \ +BMessage::Get##typeName(const char* name, const type& defaultValue) const \ { \ return Get##typeName(name, 0, defaultValue); \ } \ \ \ type \ -BMessage::Get##typeName(const char *name, int32 index, \ +BMessage::Get##typeName(const char* name, int32 index, \ const type& defaultValue) const \ { \ type value; \ @@ -2590,7 +2589,7 @@ BMessage::Get##typeName(const char *name, int32 index, \ \ \ status_t \ -BMessage::Set##typeName(const char *name, const type& value) \ +BMessage::Set##typeName(const char* name, const type& value) \ { \ return SetData(name, typeCode, &value, sizeof(type)); \ } \ @@ -2604,7 +2603,7 @@ DEFINE_SET_GET_BY_REFERENCE_FUNCTIONS(BSize, Size, B_SIZE_TYPE); status_t -BMessage::AddAlignment(const char *name, const BAlignment &alignment) +BMessage::AddAlignment(const char* name, const BAlignment& alignment) { int32 data[2] = { alignment.horizontal, alignment.vertical }; return AddData(name, B_ALIGNMENT_TYPE, data, sizeof(data)); @@ -2612,7 +2611,7 @@ BMessage::AddAlignment(const char *name, const BAlignment &alignment) status_t -BMessage::AddString(const char *name, const char *string) +BMessage::AddString(const char* name, const char* string) { return AddData(name, B_STRING_TYPE, string, string ? strlen(string) + 1 : 0, false); @@ -2620,7 +2619,7 @@ BMessage::AddString(const char *name, const char *string) status_t -BMessage::AddString(const char *name, const BString &string) +BMessage::AddString(const char* name, const BString& string) { return AddData(name, B_STRING_TYPE, string.String(), string.Length() + 1, false); @@ -2628,7 +2627,7 @@ BMessage::AddString(const char *name, const BString &string) status_t -BMessage::AddStrings(const char *name, const BStringList &list) +BMessage::AddStrings(const char* name, const BStringList& list) { int32 count = list.CountStrings(); for (int32 i = 0; i < count; i++) { @@ -2642,21 +2641,21 @@ BMessage::AddStrings(const char *name, const BStringList &list) status_t -BMessage::AddPointer(const char *name, const void *pointer) +BMessage::AddPointer(const char* name, const void* pointer) { return AddData(name, B_POINTER_TYPE, &pointer, sizeof(pointer), true); } status_t -BMessage::AddMessenger(const char *name, BMessenger messenger) +BMessage::AddMessenger(const char* name, BMessenger messenger) { return AddData(name, B_MESSENGER_TYPE, &messenger, sizeof(messenger), true); } status_t -BMessage::AddRef(const char *name, const entry_ref *ref) +BMessage::AddRef(const char* name, const entry_ref* ref) { size_t size = sizeof(entry_ref) + B_PATH_NAME_LENGTH; char buffer[size]; @@ -2671,7 +2670,7 @@ BMessage::AddRef(const char *name, const entry_ref *ref) status_t -BMessage::AddMessage(const char *name, const BMessage *message) +BMessage::AddMessage(const char* name, const BMessage* message) { if (message == NULL) return B_BAD_VALUE; @@ -2683,9 +2682,9 @@ BMessage::AddMessage(const char *name, const BMessage *message) char stackBuffer[16384]; ssize_t size = message->FlattenedSize(); - char *buffer; + char* buffer; if (size > (ssize_t)sizeof(stackBuffer)) { - buffer = (char *)malloc(size); + buffer = (char*)malloc(size); if (buffer == NULL) return B_NO_MEMORY; } else @@ -2704,7 +2703,7 @@ BMessage::AddMessage(const char *name, const BMessage *message) status_t -BMessage::AddFlat(const char *name, BFlattenable *object, int32 count) +BMessage::AddFlat(const char* name, BFlattenable* object, int32 count) { if (object == NULL) return B_BAD_VALUE; @@ -2712,9 +2711,9 @@ BMessage::AddFlat(const char *name, BFlattenable *object, int32 count) char stackBuffer[16384]; ssize_t size = object->FlattenedSize(); - char *buffer; + char* buffer; if (size > (ssize_t)sizeof(stackBuffer)) { - buffer = (char *)malloc(size); + buffer = (char*)malloc(size); if (buffer == NULL) return B_NO_MEMORY; } else @@ -2733,20 +2732,20 @@ BMessage::AddFlat(const char *name, BFlattenable *object, int32 count) status_t -BMessage::Append(const BMessage &other) +BMessage::Append(const BMessage& other) { - field_header *field = other.fFields; + field_header* field = other.fFields; for (uint32 i = 0; i < other.fHeader->field_count; i++, field++) { - const char *name = (const char *)(other.fData + field->offset); - const void *data = (const void *)(other.fData + field->offset + const char* name = (const char*)(other.fData + field->offset); + const void* data = (const void*)(other.fData + field->offset + field->name_length); bool isFixed = (field->flags & FIELD_FLAG_FIXED_SIZE) != 0; size_t size = field->data_size / field->count; for (uint32 j = 0; j < field->count; j++) { if (!isFixed) { - size = *(uint32 *)data; - data = (const void *)((const char *)data + sizeof(uint32)); + size = *(uint32*)data; + data = (const void*)((const char*)data + sizeof(uint32)); } status_t status = AddData(name, field->type, data, size, @@ -2754,7 +2753,7 @@ BMessage::Append(const BMessage &other) if (status != B_OK) return status; - data = (const void *)((const char *)data + size); + data = (const void*)((const char*)data + size); } } return B_OK; @@ -2762,20 +2761,20 @@ BMessage::Append(const BMessage &other) status_t -BMessage::FindAlignment(const char *name, BAlignment *alignment) const +BMessage::FindAlignment(const char* name, BAlignment* alignment) const { return FindAlignment(name, 0, alignment); } status_t -BMessage::FindAlignment(const char *name, int32 index, BAlignment *alignment) +BMessage::FindAlignment(const char* name, int32 index, BAlignment* alignment) const { if (!alignment) return B_BAD_VALUE; - int32 *data; + int32* data; ssize_t bytes; status_t err = FindData(name, B_ALIGNMENT_TYPE, index, @@ -2794,34 +2793,34 @@ BMessage::FindAlignment(const char *name, int32 index, BAlignment *alignment) status_t -BMessage::FindString(const char *name, const char **string) const +BMessage::FindString(const char* name, const char** string) const { return FindString(name, 0, string); } status_t -BMessage::FindString(const char *name, int32 index, const char **string) const +BMessage::FindString(const char* name, int32 index, const char** string) const { ssize_t bytes; - return FindData(name, B_STRING_TYPE, index, (const void **)string, &bytes); + return FindData(name, B_STRING_TYPE, index, (const void**)string, &bytes); } status_t -BMessage::FindString(const char *name, BString *string) const +BMessage::FindString(const char* name, BString* string) const { return FindString(name, 0, string); } status_t -BMessage::FindString(const char *name, int32 index, BString *string) const +BMessage::FindString(const char* name, int32 index, BString* string) const { if (string == NULL) return B_BAD_VALUE; - const char *value; + const char* value; status_t error = FindString(name, index, &value); // Find*() clobbers the object even on failure @@ -2831,7 +2830,7 @@ BMessage::FindString(const char *name, int32 index, BString *string) const status_t -BMessage::FindStrings(const char *name, BStringList *list) const +BMessage::FindStrings(const char* name, BStringList* list) const { if (list == NULL) return B_BAD_VALUE; @@ -2861,22 +2860,22 @@ BMessage::FindStrings(const char *name, BStringList *list) const status_t -BMessage::FindPointer(const char *name, void **pointer) const +BMessage::FindPointer(const char* name, void** pointer) const { return FindPointer(name, 0, pointer); } status_t -BMessage::FindPointer(const char *name, int32 index, void **pointer) const +BMessage::FindPointer(const char* name, int32 index, void** pointer) const { if (pointer == NULL) return B_BAD_VALUE; - void **data = NULL; + void** data = NULL; ssize_t size = 0; status_t error = FindData(name, B_POINTER_TYPE, index, - (const void **)&data, &size); + (const void**)&data, &size); if (error == B_OK) *pointer = *data; @@ -2888,23 +2887,23 @@ BMessage::FindPointer(const char *name, int32 index, void **pointer) const status_t -BMessage::FindMessenger(const char *name, BMessenger *messenger) const +BMessage::FindMessenger(const char* name, BMessenger* messenger) const { return FindMessenger(name, 0, messenger); } 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; - void *data = NULL; + void* data = NULL; ssize_t size = 0; status_t error = FindData(name, B_MESSENGER_TYPE, index, - (const void **)&data, &size); + (const void**)&data, &size); if (error == B_OK) memcpy(messenger, data, sizeof(BMessenger)); @@ -2916,25 +2915,25 @@ BMessage::FindMessenger(const char *name, int32 index, BMessenger *messenger) status_t -BMessage::FindRef(const char *name, entry_ref *ref) const +BMessage::FindRef(const char* name, entry_ref* ref) const { return FindRef(name, 0, ref); } status_t -BMessage::FindRef(const char *name, int32 index, entry_ref *ref) const +BMessage::FindRef(const char* name, int32 index, entry_ref* ref) const { if (ref == NULL) return B_BAD_VALUE; - void *data = NULL; + void* data = NULL; ssize_t size = 0; status_t error = FindData(name, B_REF_TYPE, index, - (const void **)&data, &size); + (const void**)&data, &size); if (error == B_OK) - error = BPrivate::entry_ref_unflatten(ref, (char *)data, size); + error = BPrivate::entry_ref_unflatten(ref, (char*)data, size); else *ref = entry_ref(); @@ -2943,25 +2942,25 @@ BMessage::FindRef(const char *name, int32 index, entry_ref *ref) const status_t -BMessage::FindMessage(const char *name, BMessage *message) const +BMessage::FindMessage(const char* name, BMessage* message) const { return FindMessage(name, 0, message); } status_t -BMessage::FindMessage(const char *name, int32 index, BMessage *message) const +BMessage::FindMessage(const char* name, int32 index, BMessage* message) const { if (message == NULL) return B_BAD_VALUE; - void *data = NULL; + void* data = NULL; ssize_t size = 0; status_t error = FindData(name, B_MESSAGE_TYPE, index, - (const void **)&data, &size); + (const void**)&data, &size); if (error == B_OK) - error = message->Unflatten((const char *)data); + error = message->Unflatten((const char*)data); else *message = BMessage(); @@ -2970,22 +2969,22 @@ BMessage::FindMessage(const char *name, int32 index, BMessage *message) const status_t -BMessage::FindFlat(const char *name, BFlattenable *object) const +BMessage::FindFlat(const char* name, BFlattenable* object) const { return FindFlat(name, 0, object); } status_t -BMessage::FindFlat(const char *name, int32 index, BFlattenable *object) const +BMessage::FindFlat(const char* name, int32 index, BFlattenable* object) const { if (object == NULL) return B_BAD_VALUE; - void *data = NULL; + void* data = NULL; ssize_t numBytes = 0; status_t error = FindData(name, object->TypeCode(), index, - (const void **)&data, &numBytes); + (const void**)&data, &numBytes); if (error == B_OK) error = object->Unflatten(object->TypeCode(), data, numBytes); @@ -2995,15 +2994,15 @@ BMessage::FindFlat(const char *name, int32 index, BFlattenable *object) const status_t -BMessage::FindData(const char *name, type_code type, const void **data, - ssize_t *numBytes) const +BMessage::FindData(const char* name, type_code type, const void** data, + ssize_t* numBytes) const { return FindData(name, type, 0, data, numBytes); } status_t -BMessage::ReplaceAlignment(const char *name, const BAlignment &alignment) +BMessage::ReplaceAlignment(const char* name, const BAlignment& alignment) { int32 data[2] = {alignment.horizontal, alignment.vertical}; return ReplaceData(name, B_ALIGNMENT_TYPE, 0, data, sizeof(data)); @@ -3011,8 +3010,8 @@ BMessage::ReplaceAlignment(const char *name, const BAlignment &alignment) status_t -BMessage::ReplaceAlignment(const char *name, int32 index, - const BAlignment &alignment) +BMessage::ReplaceAlignment(const char* name, int32 index, + const BAlignment& alignment) { int32 data[2] = {alignment.horizontal, alignment.vertical}; return ReplaceData(name, B_ALIGNMENT_TYPE, index, data, sizeof(data)); @@ -3020,7 +3019,7 @@ BMessage::ReplaceAlignment(const char *name, int32 index, status_t -BMessage::ReplaceString(const char *name, const char *string) +BMessage::ReplaceString(const char* name, const char* string) { if (string == NULL) return B_BAD_VALUE; @@ -3030,7 +3029,7 @@ BMessage::ReplaceString(const char *name, const char *string) status_t -BMessage::ReplaceString(const char *name, int32 index, const char *string) +BMessage::ReplaceString(const char* name, int32 index, const char* string) { if (string == NULL) return B_BAD_VALUE; @@ -3040,7 +3039,7 @@ BMessage::ReplaceString(const char *name, int32 index, const char *string) status_t -BMessage::ReplaceString(const char *name, const BString &string) +BMessage::ReplaceString(const char* name, const BString& string) { return ReplaceData(name, B_STRING_TYPE, 0, string.String(), string.Length() + 1); @@ -3048,7 +3047,7 @@ BMessage::ReplaceString(const char *name, const BString &string) status_t -BMessage::ReplaceString(const char *name, int32 index, const BString &string) +BMessage::ReplaceString(const char* name, int32 index, const BString& string) { return ReplaceData(name, B_STRING_TYPE, index, string.String(), string.Length() + 1); @@ -3056,21 +3055,21 @@ BMessage::ReplaceString(const char *name, int32 index, const BString &string) status_t -BMessage::ReplacePointer(const char *name, const void *pointer) +BMessage::ReplacePointer(const char* name, const void* pointer) { return ReplaceData(name, B_POINTER_TYPE, 0, &pointer, sizeof(pointer)); } status_t -BMessage::ReplacePointer(const char *name, int32 index, const void *pointer) +BMessage::ReplacePointer(const char* name, int32 index, const void* pointer) { return ReplaceData(name, B_POINTER_TYPE, index, &pointer, sizeof(pointer)); } status_t -BMessage::ReplaceMessenger(const char *name, BMessenger messenger) +BMessage::ReplaceMessenger(const char* name, BMessenger messenger) { return ReplaceData(name, B_MESSENGER_TYPE, 0, &messenger, sizeof(BMessenger)); @@ -3078,7 +3077,7 @@ BMessage::ReplaceMessenger(const char *name, BMessenger messenger) status_t -BMessage::ReplaceMessenger(const char *name, int32 index, BMessenger messenger) +BMessage::ReplaceMessenger(const char* name, int32 index, BMessenger messenger) { return ReplaceData(name, B_MESSENGER_TYPE, index, &messenger, sizeof(BMessenger)); @@ -3086,14 +3085,14 @@ BMessage::ReplaceMessenger(const char *name, int32 index, BMessenger messenger) status_t -BMessage::ReplaceRef(const char *name, const entry_ref *ref) +BMessage::ReplaceRef(const char* name, const entry_ref* ref) { return ReplaceRef(name, 0, ref); } status_t -BMessage::ReplaceRef(const char *name, int32 index, const entry_ref *ref) +BMessage::ReplaceRef(const char* name, int32 index, const entry_ref* ref) { size_t size = sizeof(entry_ref) + B_PATH_NAME_LENGTH; char buffer[size]; @@ -3108,14 +3107,14 @@ BMessage::ReplaceRef(const char *name, int32 index, const entry_ref *ref) status_t -BMessage::ReplaceMessage(const char *name, const BMessage *message) +BMessage::ReplaceMessage(const char* name, const BMessage* message) { return ReplaceMessage(name, 0, message); } status_t -BMessage::ReplaceMessage(const char *name, int32 index, const BMessage *message) +BMessage::ReplaceMessage(const char* name, int32 index, const BMessage* message) { if (message == NULL) return B_BAD_VALUE; @@ -3133,14 +3132,14 @@ BMessage::ReplaceMessage(const char *name, int32 index, const BMessage *message) status_t -BMessage::ReplaceFlat(const char *name, BFlattenable *object) +BMessage::ReplaceFlat(const char* name, BFlattenable* object) { return ReplaceFlat(name, 0, object); } status_t -BMessage::ReplaceFlat(const char *name, int32 index, BFlattenable *object) +BMessage::ReplaceFlat(const char* name, int32 index, BFlattenable* object) { if (object == NULL) return B_BAD_VALUE; @@ -3158,7 +3157,7 @@ BMessage::ReplaceFlat(const char *name, int32 index, BFlattenable *object) status_t -BMessage::ReplaceData(const char *name, type_code type, const void *data, +BMessage::ReplaceData(const char* name, type_code type, const void* data, ssize_t numBytes) { return ReplaceData(name, type, 0, data, numBytes); @@ -3166,14 +3165,14 @@ BMessage::ReplaceData(const char *name, type_code type, const void *data, bool -BMessage::HasFlat(const char *name, const BFlattenable *object) const +BMessage::HasFlat(const char* name, const BFlattenable* object) const { return HasFlat(name, 0, object); } bool -BMessage::HasFlat(const char *name, int32 index, const BFlattenable *object) +BMessage::HasFlat(const char* name, int32 index, const BFlattenable* object) const { return HasData(name, object->TypeCode(), index); @@ -3181,15 +3180,15 @@ BMessage::HasFlat(const char *name, int32 index, const BFlattenable *object) const char* -BMessage::GetString(const char *name, const char *defaultValue) const +BMessage::GetString(const char* name, const char* defaultValue) const { return GetString(name, 0, defaultValue); } const char* -BMessage::GetString(const char *name, int32 index, - const char *defaultValue) const +BMessage::GetString(const char* name, int32 index, + const char* defaultValue) const { const char* value; if (FindString(name, index, &value) == B_OK) @@ -3200,14 +3199,14 @@ BMessage::GetString(const char *name, int32 index, status_t -BMessage::SetString(const char *name, const BString& value) +BMessage::SetString(const char* name, const BString& value) { return SetData(name, B_STRING_TYPE, value.String(), value.Length() + 1); } status_t -BMessage::SetString(const char *name, const char* value) +BMessage::SetString(const char* name, const char* value) { return SetData(name, B_STRING_TYPE, value, strlen(value) + 1); } diff --git a/src/kits/app/MessageFilter.cpp b/src/kits/app/MessageFilter.cpp index 6328f60e86..c78fd32ea4 100644 --- a/src/kits/app/MessageFilter.cpp +++ b/src/kits/app/MessageFilter.cpp @@ -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: @@ -115,7 +115,7 @@ BMessageFilter::FiltersAnyCommand() const } -BLooper * +BLooper* BMessageFilter::Looper() const { return fLooper; diff --git a/src/kits/app/MessageQueue.cpp b/src/kits/app/MessageQueue.cpp index 4b3e5bbfbe..6f481ed668 100644 --- a/src/kits/app/MessageQueue.cpp +++ b/src/kits/app/MessageQueue.cpp @@ -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 @@ -18,9 +19,9 @@ BMessageQueue::BMessageQueue() : fHead(NULL), - fTail(NULL), - fMessageCount(0), - fLock("BMessageQueue Lock") + fTail(NULL), + fMessageCount(0), + fLock("BMessageQueue Lock") { } @@ -32,7 +33,7 @@ BMessageQueue::~BMessageQueue() BMessage* message = fHead; while (message != NULL) { - BMessage *next = message->fQueueLink; + BMessage* next = message->fQueueLink; delete message; message = next; @@ -111,7 +112,7 @@ BMessageQueue::IsEmpty() const } -BMessage * +BMessage* BMessageQueue::FindMessage(int32 index) const { BAutolock _(fLock); @@ -120,7 +121,7 @@ BMessageQueue::FindMessage(int32 index) const if (index < 0 || index >= fMessageCount) return NULL; - + for (BMessage* message = fHead; message != NULL; message = message->fQueueLink) { // If the index reaches zero, then we have found a match. if (index == 0) @@ -133,7 +134,7 @@ BMessageQueue::FindMessage(int32 index) const } -BMessage * +BMessage* BMessageQueue::FindMessage(uint32 what, int32 index) const { BAutolock _(fLock); @@ -178,7 +179,7 @@ BMessageQueue::IsLocked() const } -BMessage * +BMessage* BMessageQueue::NextMessage() { BAutolock _(fLock); @@ -201,7 +202,7 @@ BMessageQueue::NextMessage() fTail = NULL; } - return head; + return head; } @@ -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() {