Use new node monitor fields in the index_server.

* remove unnecessary modified query hack
This commit is contained in:
czeidler 2012-01-22 17:51:46 +13:00
parent 610ef6c007
commit d3ff06683a
5 changed files with 41 additions and 164 deletions

View File

@ -10,7 +10,6 @@ Server index_server :
main.cpp
IndexServer.cpp
IndexServerAddOn.cpp
ModifiedNotifications.cpp
VolumeWatcher.cpp
# storage

View File

@ -1,86 +0,0 @@
/*
* Copyright 2010, Haiku.
* Distributed under the terms of the MIT License.
*
* Authors:
* Clemens Zeidler <haiku@clemens-zeidler.de>
*/
#include "ModifiedNotifications.h"
#include "fs_query.h"
#include <MessengerPrivate.h>
#include <syscalls.h>
#include "query_private.h"
NotifyAllQuery::NotifyAllQuery()
:
fQueryFd(-1)
{
}
NotifyAllQuery::~NotifyAllQuery()
{
StopWatching();
}
status_t
NotifyAllQuery::StartWatching(const BVolume& volume, const char* query,
const BMessenger& target)
{
if (fQueryFd >= 0)
return B_NOT_ALLOWED;
BMessenger::Private messengerPrivate(const_cast<BMessenger&>(target));
port_id port = messengerPrivate.Port();
long token = (messengerPrivate.IsPreferredTarget() ? -1
: messengerPrivate.Token());
fQueryFd = _kern_open_query(volume.Device(), query, strlen(query),
B_LIVE_QUERY | B_ATTR_CHANGE_NOTIFICATION, port, token);
if (fQueryFd < 0)
return fQueryFd;
return B_OK;
}
status_t
NotifyAllQuery::StopWatching()
{
status_t error = B_OK;
if (fQueryFd >= 0) {
error = _kern_close(fQueryFd);
fQueryFd = -1;
}
return error;
}
ModfiedNotifications::~ModfiedNotifications()
{
StopWatching();
}
status_t
ModfiedNotifications::StartWatching(const BVolume& volume, time_t startTime,
const BMessenger& target)
{
BString string = "(last_modified>=";
string << startTime;
string << ")";
return fQuery.StartWatching(volume, string.String(), target);
}
status_t
ModfiedNotifications::StopWatching()
{
return fQuery.StopWatching();
}

View File

@ -1,44 +0,0 @@
/*
* Copyright 2010, Haiku.
* Distributed under the terms of the MIT License.
*
* Authors:
* Clemens Zeidler <haiku@clemens-zeidler.de>
*/
#ifndef MODIFIED_NOTIFICATIONS_H
#define MODIFIED_NOTIFICATIONS_H
#include <String.h>
#include <Volume.h>
#include <Messenger.h>
class NotifyAllQuery {
public:
NotifyAllQuery();
~NotifyAllQuery();
status_t StartWatching(const BVolume& volume,
const char* query,
const BMessenger& target);
status_t StopWatching();
private:
int fQueryFd;
};
class ModfiedNotifications {
public:
~ModfiedNotifications();
status_t StartWatching(const BVolume& volume,
time_t startTime, const BMessenger& target);
status_t StopWatching();
private:
NotifyAllQuery fQuery;
};
#endif // MODIFIED_NOTIFICATIONS_H

View File

@ -74,6 +74,44 @@ WatchNameHandler::StatChanged(ino_t node, dev_t device, int32 statFields)
}
void
WatchNameHandler::MessageReceived(BMessage* msg)
{
if (msg->what == B_NODE_MONITOR) {
int32 opcode;
if (msg->FindInt32("opcode", &opcode) == B_OK) {
switch (opcode) {
case B_STAT_CHANGED: {
BString name;
entry_ref ref;
ino_t node;
int32 statFields;
msg->FindInt32("fields", &statFields);
if ((statFields & B_STAT_MODIFICATION_TIME) == 0)
break;
msg->FindInt32("device", &ref.device);
msg->FindInt64("node", &node);
msg->FindInt64("directory", &ref.directory);
msg->FindString("name", &name);
ref.set_name(name);
BPath path(&ref);
printf("stat changed node %i name %s %s\n", (int)node,
name.String(), path.Path());
fVolumeWatcher->fModifiedList.CurrentList()->push_back(ref);
fVolumeWatcher->_NewEntriesArrived();
break;
}
}
}
}
NodeMonitorHandler::MessageReceived(msg);
}
AnalyserDispatcher::AnalyserDispatcher(const char* name)
:
BLooper(name, B_LOW_PRIORITY),
@ -408,33 +446,6 @@ VolumeWatcher::~VolumeWatcher()
}
void
VolumeWatcher::MessageReceived(BMessage *message)
{
int32 opcode;
switch (message->what) {
case B_QUERY_UPDATE:
message->FindInt32("opcode", &opcode);
if (opcode == B_ATTR_CHANGED || opcode == B_ENTRY_CREATED) {
const char *name;
ino_t directory;
dev_t device;
if ((message->FindString("name", &name) != B_OK) ||
(message->FindInt64("directory", &directory) != B_OK) ||
(message->FindInt32("device", &device) != B_OK))
break;
entry_ref ref(device, directory, name);
fModifiedList.CurrentList()->push_back(ref);
_NewEntriesArrived();
}
break;
default:
BLooper::MessageReceived(message);
}
}
bool
VolumeWatcher::StartWatching()
{
@ -442,9 +453,7 @@ VolumeWatcher::StartWatching()
watch_volume(fVolume.Device(), B_WATCH_NAME | B_WATCH_STAT,
&fWatchNameHandler);
if (fModfiedNotifications.StartWatching(fVolume.Device(), real_time_clock(),
this) != B_OK)
return false;
// set the time after start watching to not miss anything
fVolumeWorker->SetWatchingStart(real_time_clock_usecs());

View File

@ -21,7 +21,6 @@
#include "AnalyserDispatcher.h"
#include "CatchUpManager.h"
#include "IndexServerAddOn.h"
#include "ModifiedNotifications.h"
class VolumeWatcher;
@ -41,6 +40,8 @@ public:
ino_t node, dev_t nodeDevice);
void StatChanged(ino_t node, dev_t device,
int32 statFields);
void MessageReceived(BMessage* msg);
private:
VolumeWatcher* fVolumeWatcher;
};
@ -127,7 +128,6 @@ public:
VolumeWatcher(const BVolume& volume);
~VolumeWatcher();
void MessageReceived(BMessage *message);
bool StartWatching();
void Stop();
@ -157,7 +157,6 @@ private:
VolumeWorker* fVolumeWorker;
CatchUpManager fCatchUpManager;
ModfiedNotifications fModfiedNotifications;
};