diff --git a/src/apps/installer/BlockingQueue.h b/src/apps/installer/BlockingQueue.h index fa5d0fc909..1d7ee6e4f7 100644 --- a/src/apps/installer/BlockingQueue.h +++ b/src/apps/installer/BlockingQueue.h @@ -1,17 +1,17 @@ // BlockingQueue.h -// +// // Copyright (c) 2004, Ingo Weinhold (bonefish@cs.tu-berlin.de) -// +// // 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 +// 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 @@ -19,7 +19,7 @@ // 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. -// +// // Except as contained in this notice, the name of a copyright holder shall // not be used in advertising or otherwise to promote the sale, use or other // dealings in this Software without prior written authorization of the @@ -33,7 +33,9 @@ #include #include "AutoLocker.h" -#include "Vector.h" +#include + +using std::vector; typedef BLocker Locker; @@ -46,7 +48,7 @@ public: status_t InitCheck() const; status_t Close(bool deleteElements, - const Vector** elements = NULL); + const vector** elements = NULL); status_t Push(Element* element); status_t Pop(Element** element, @@ -54,10 +56,10 @@ public: status_t Peek(Element** element); status_t Remove(Element* element); - int32 Size(); + int32 Size(); private: - Vector fElements; + vector fElements; sem_id fElementSemaphore; }; @@ -90,7 +92,7 @@ BlockingQueue::InitCheck() const template status_t BlockingQueue::Close(bool deleteElements, - const Vector** elements) + const vector** elements) { AutoLocker _(this); status_t error = delete_sem(fElementSemaphore); @@ -100,9 +102,9 @@ BlockingQueue::Close(bool deleteElements, if (elements) *elements = &fElements; if (deleteElements) { - int32 count = fElements.Count(); + int32 count = fElements.size(); for (int32 i = 0; i < count; i++) - delete fElements.ElementAt(i); + delete fElements[i]; } return error; } @@ -115,12 +117,14 @@ BlockingQueue::Push(Element* element) AutoLocker _(this); if (fElementSemaphore < 0) return B_NO_INIT; - status_t error = fElements.PushBack(element); + try { + fElements.push_back(element); + } catch (std::bad_alloc) { + return B_NO_MEMORY; + } + status_t error = release_sem(fElementSemaphore); if (error != B_OK) - return error; - error = release_sem(fElementSemaphore); - if (error != B_OK) - fElements.Erase(fElements.Count() - 1); + fElements.erase(fElements.begin() + fElements.size() - 1); return error; } @@ -136,11 +140,11 @@ BlockingQueue::Pop(Element** element, bigtime_t timeout) AutoLocker _(this); if (fElementSemaphore < 0) return B_NO_INIT; - int32 count = fElements.Count(); + int32 count = fElements.size(); if (count == 0) return B_ERROR; - *element = fElements.ElementAt(0); - fElements.Erase(0); + *element = fElements[0]; + fElements.erase(fElements.begin()); return B_OK; } @@ -152,10 +156,10 @@ BlockingQueue::Peek(Element** element) AutoLocker _(this); if (fElementSemaphore < 0) return B_NO_INIT; - int32 count = fElements.Count(); + int32 count = fElements.size(); if (count == 0) return B_ENTRY_NOT_FOUND; - *element = fElements.ElementAt(0); + *element = fElements[0]; return B_OK; } @@ -171,15 +175,24 @@ BlockingQueue::Remove(Element* element) AutoLocker _(this); if (fElementSemaphore < 0) return B_NO_INIT; - int32 count = fElements.Remove(element); + + int32 count = 0; + for (int32 i = fElements.size() - 1; i >= 0; i--) { + if (fElements[i] == element) { + fElements.erase(fElements.begin() + i); + count++; + } + } if (count == 0) { release_sem(fElementSemaphore); return B_ENTRY_NOT_FOUND; } +#if 0 if (count > 1) { ERROR(("ERROR: BlockingQueue::Remove(): Removed %ld elements!\n", count)); } +#endif return error; } @@ -189,7 +202,7 @@ int32 BlockingQueue::Size() { AutoLocker _(this); - return (fElements.Count()); + return (fElements.size()); } #endif // BLOCKING_QUEUE_H diff --git a/src/apps/installer/CopyEngine.cpp b/src/apps/installer/CopyEngine.cpp index d737d2135c..bea20295bc 100644 --- a/src/apps/installer/CopyEngine.cpp +++ b/src/apps/installer/CopyEngine.cpp @@ -135,7 +135,7 @@ CopyEngine::MessageReceived(BMessage* message) void -CopyEngine::SetStatusMessage(char *status) +CopyEngine::SetStatusMessage(const char *status) { BMessage msg(STATUS_MESSAGE); msg.AddString("status", status); @@ -297,7 +297,7 @@ bigtime_t now; // Something besides Trash entries++; } - + if (entries > 0) break; } @@ -324,7 +324,7 @@ bigtime_t now; err = B_CANCELED; goto error; } - + LaunchInitScript(targetDirectory); @@ -386,7 +386,7 @@ CopyEngine::CopyFolder(BDirectory &srcDir, BDirectory &targetDir) && !fControl->CheckUserCanceled()) { StatStruct statbuf; entry.GetStat(&statbuf); - + Undo undo; if (S_ISDIR(statbuf.st_mode)) { char name[B_FILE_NAME_LENGTH]; diff --git a/src/apps/installer/CopyEngine.h b/src/apps/installer/CopyEngine.h index 8de3ccc342..e408c1ced0 100644 --- a/src/apps/installer/CopyEngine.h +++ b/src/apps/installer/CopyEngine.h @@ -34,7 +34,7 @@ class CopyEngine : public BLooper { private: void LaunchInitScript(BPath &path); void LaunchFinishScript(BPath &path); - void SetStatusMessage(char *status); + void SetStatusMessage(const char *status); void Start(BMenu *srcMenu, BMenu *targetMenu); status_t CopyFolder(BDirectory &srcDir, BDirectory &targetDir); diff --git a/src/apps/installer/CopyEngine2.h b/src/apps/installer/CopyEngine2.h index 11578821eb..4cc7f45e9c 100644 --- a/src/apps/installer/CopyEngine2.h +++ b/src/apps/installer/CopyEngine2.h @@ -2,6 +2,8 @@ #define COPY_ENGINE_2_H +#include + #include #include #include