vfs: check userland buffers before reading them.
[haiku.git] / src / apps / musiccollection / QueryMonitor.cpp
blobb6a586591b16a682a5f13902e72b2249bd5a62cf
1 /*
2 * Copyright 2011, Haiku, Inc. All rights reserved.
3 * Distributed under the terms of the MIT License.
5 * Authors:
6 * Clemens Zeidler <haiku@clemens-zeidler.de>
7 */
10 #include "QueryMonitor.h"
13 QueryHandler::QueryHandler(EntryViewInterface* listener)
15 FileMonitor(listener)
21 void
22 QueryHandler::MessageReceived(BMessage* message)
24 int32 opcode;
25 if (message->what == B_QUERY_UPDATE
26 && message->FindInt32("opcode", &opcode) == B_OK) {
27 switch (opcode) {
28 case B_ENTRY_CREATED:
29 case B_ENTRY_REMOVED:
30 message->what = B_NODE_MONITOR;
31 break;
35 FileMonitor::MessageReceived(message);
39 QueryReader::QueryReader(QueryHandler* handler)
41 ReadThread(handler)
47 QueryReader::~QueryReader()
49 Reset();
53 bool
54 QueryReader::AddQuery(BQuery* query)
56 query->SetTarget(fTarget);
57 query->Fetch();
58 return fQueries.AddItem(query);
62 void
63 QueryReader::Reset()
65 Stop();
66 Wait();
68 for (int32 i = 0; i < fLiveQueries.CountItems(); i++)
69 delete fLiveQueries.ItemAt(i);
70 fLiveQueries.MakeEmpty();
72 for (int32 i = 0; i < fQueries.CountItems(); i++)
73 delete fQueries.ItemAt(i);
74 fQueries.MakeEmpty();
78 bool
79 QueryReader::ReadNextEntry(entry_ref& entry)
81 BQuery* query = fQueries.ItemAt(0);
82 if (query == NULL)
83 return false;
84 if (query->GetNextRef(&entry) != B_OK) {
85 fQueries.RemoveItemAt(0);
86 fLiveQueries.AddItem(query);
87 return ReadNextEntry(entry);
89 return true;