From e2fe7e2fe0a9f0ae8e2a1e36960f1b96d23a5202 Mon Sep 17 00:00:00 2001 From: Stefano Ceccherini Date: Mon, 12 May 2008 13:27:56 +0000 Subject: [PATCH] Removed PortQueue since it's not used. Small style (old) changes here and there. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@25468 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- headers/private/app/PortQueue.h | 58 ------------------ src/kits/app/Application.cpp | 25 ++++---- src/kits/app/LinkReceiver.cpp | 15 ++--- src/kits/app/LinkSender.cpp | 5 +- src/kits/app/PortQueue.cpp | 105 -------------------------------- 5 files changed, 21 insertions(+), 187 deletions(-) delete mode 100644 headers/private/app/PortQueue.h delete mode 100644 src/kits/app/PortQueue.cpp diff --git a/headers/private/app/PortQueue.h b/headers/private/app/PortQueue.h deleted file mode 100644 index b769e02695..0000000000 --- a/headers/private/app/PortQueue.h +++ /dev/null @@ -1,58 +0,0 @@ -//------------------------------------------------------------------------------ -// Copyright (c) 2001-2002, OpenBeOS -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the "Software"), -// to deal in the Software without restriction, including without limitation -// the rights to use, copy, modify, merge, publish, distribute, sublicense, -// and/or sell copies of the Software, and to permit persons to whom the -// Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// -// File Name: PortQueue.h -// Author: DarkWyrm -// Description: Facilitation class for reading and queueing messages from ports -// -//------------------------------------------------------------------------------ -#ifndef PORTQUEUE_H_ -#define PORTQUEUE_H_ - -#include -#include - -class PortMessage; - -class PortQueue -{ -public: - PortQueue(const port_id &port); - ~PortQueue(void); - bool IsInitialized(void) { return _init; } - - bool SetPort(const port_id &port); - port_id GetPort(void) { return _port; } - - bool MessagesWaiting(void) { return !_q.empty(); } - - void GetMessagesFromPort(bool wait_for_messages=false); - PortMessage *GetMessageFromQueue(void); - - void MakeEmpty(void); - -private: - std::queue _q; - bool _init; - port_id _port; -}; - -#endif diff --git a/src/kits/app/Application.cpp b/src/kits/app/Application.cpp index dccea30962..79aa6b40b2 100644 --- a/src/kits/app/Application.cpp +++ b/src/kits/app/Application.cpp @@ -208,7 +208,6 @@ BApplication::BApplication(BMessage *data) bigtime_t pulseRate; if (data->FindInt64("_pulse", &pulseRate) == B_OK) SetPulseRate(pulseRate); - } @@ -861,6 +860,8 @@ BApplication::IsLaunching() const status_t BApplication::GetAppInfo(app_info *info) const { + if (be_app == NULL || be_roster == NULL) + return B_NO_INIT; return be_roster->GetRunningAppInfo(be_app->Team(), info); } @@ -879,9 +880,9 @@ BApplication::AppResources() bool found = false; // App is already running. Get its entry ref with - // GetRunningAppInfo() + // GetAppInfo() app_info appInfo; - if (be_app && be_roster->GetRunningAppInfo(be_app->Team(), &appInfo) == B_OK) { + if (be_app && be_app->GetAppInfo(&appInfo) == B_OK) { ref = appInfo.ref; found = true; } else { @@ -889,14 +890,16 @@ BApplication::AppResources() found = BPrivate::get_app_ref(&ref) == B_OK; } - if (found) { - BFile file(&ref, B_READ_ONLY); - if (file.InitCheck() == B_OK) { - BResources *resources = new BResources(); - if (resources->SetTo(&file, false) < B_OK) - delete resources; - else - sAppResources = resources; + if (!found) + return NULL; + + BFile file(&ref, B_READ_ONLY); + if (file.InitCheck() == B_OK) { + sAppResources = new (nothrow) BResources(&file, false); + if (sAppResources != NULL + && sAppResources->InitCheck() != B_OK) { + delete sAppResources; + sAppResources = NULL; } } diff --git a/src/kits/app/LinkReceiver.cpp b/src/kits/app/LinkReceiver.cpp index 3a7b0e1793..b2929a3250 100644 --- a/src/kits/app/LinkReceiver.cpp +++ b/src/kits/app/LinkReceiver.cpp @@ -58,11 +58,9 @@ LinkReceiver::SetPort(port_id port) status_t LinkReceiver::GetNextMessage(int32 &code, bigtime_t timeout) { - int32 remaining; - fReadError = B_OK; - remaining = fDataSize - (fRecvStart + fReplySize); + int32 remaining = fDataSize - (fRecvStart + fReplySize); STRACE(("info: LinkReceiver GetNextReply() reports %ld bytes remaining in buffer.\n", remaining)); // find the position of the next message header in the buffer @@ -277,14 +275,12 @@ status_t LinkReceiver::ReadString(char** _string, size_t* _length) { int32 length = 0; - status_t status; + status_t status = Read(&length); - status = Read(&length); if (status < B_OK) return status; char *string; - if (length < 0) { status = B_ERROR; goto err; @@ -309,6 +305,7 @@ LinkReceiver::ReadString(char** _string, size_t* _length) if (_length) *_length = length; + *_string = string; return B_OK; @@ -324,9 +321,8 @@ status_t LinkReceiver::ReadString(BString &string, size_t* _length) { int32 length = 0; - status_t status; + status_t status = Read(&length); - status = Read(&length); if (status < B_OK) return status; @@ -370,9 +366,8 @@ status_t LinkReceiver::ReadString(char *buffer, size_t bufferLength) { int32 length = 0; - status_t status; + status_t status = Read(&length); - status = Read(&length); if (status < B_OK) return status; diff --git a/src/kits/app/LinkSender.cpp b/src/kits/app/LinkSender.cpp index 1b65d8349f..18c3de2895 100644 --- a/src/kits/app/LinkSender.cpp +++ b/src/kits/app/LinkSender.cpp @@ -195,8 +195,7 @@ LinkSender::AdjustBuffer(size_t newSize, char **_oldBuffer) return B_BUFFER_OVERFLOW; else if (newSize > kInitialBufferSize) newSize = (newSize + B_PAGE_SIZE - 1) & ~(B_PAGE_SIZE - 1); - - char *buffer = NULL; + if (newSize == fBufferSize) { // keep existing buffer if (_oldBuffer) @@ -205,7 +204,7 @@ LinkSender::AdjustBuffer(size_t newSize, char **_oldBuffer) } // create new larger buffer - buffer = (char *)malloc(newSize); + char *buffer = (char *)malloc(newSize); if (buffer == NULL) return B_NO_MEMORY; diff --git a/src/kits/app/PortQueue.cpp b/src/kits/app/PortQueue.cpp deleted file mode 100644 index b04dc3c8a8..0000000000 --- a/src/kits/app/PortQueue.cpp +++ /dev/null @@ -1,105 +0,0 @@ -//------------------------------------------------------------------------------ -// Copyright (c) 2001-2002, OpenBeOS -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the "Software"), -// to deal in the Software without restriction, including without limitation -// the rights to use, copy, modify, merge, publish, distribute, sublicense, -// and/or sell copies of the Software, and to permit persons to whom the -// Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// -// File Name: PortQueue.cpp -// Author: DarkWyrm -// Description: Facilitation class for reading and queueing messages from ports -// -//------------------------------------------------------------------------------ -#include "PortQueue.h" -#include "PortMessage.h" - -PortQueue::PortQueue(const port_id &port) -{ - port_info pi; - _init=(get_port_info(port,&pi)==B_OK)?true:false; - _port=port; -} - -PortQueue::~PortQueue(void) -{ - MakeEmpty(); -} - -bool PortQueue::SetPort(const port_id &port) -{ - port_info pi; - _init=(get_port_info(port,&pi)==B_OK)?true:false; - _port=port; - - return _init; -} - -void PortQueue::GetMessagesFromPort(bool wait_for_messages) -{ - if(_init) - { - PortMessage *msg; - ssize_t size; - port_info pi; - get_port_info(_port, &pi); - status_t stat; - - if(pi.queue_count==0 && wait_for_messages) - { - size=port_buffer_size(_port); - // now that there is a message, we'll just fall through to the - // port-emptying loop - get_port_info(_port, &pi); - } - - for(int32 i=0; iReadFromPort(_port,0); - - if(stat!=B_OK) - { - delete msg; - break; - } - _q.push(msg); - } - - } -} - -PortMessage *PortQueue::GetMessageFromQueue(void) -{ - if(_q.empty()) - return NULL; - - PortMessage *msg=_q.front(); - _q.pop(); - return msg; -} - -void PortQueue::MakeEmpty(void) -{ - PortMessage *msg; - while(!_q.empty()) - { - msg=_q.front(); - _q.pop(); - delete msg; - } -} -