Moved over to the new live query notification API.

Fixed a stupid bug in Query::LiveUpdate() that prevented it to work correctly before:
instead of the file name, the attribute value was passed to send_notification().


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@11225 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2005-02-02 17:04:58 +00:00
parent f0c7cb8c12
commit 0d3a7fe9b1
+40 -22
View File
@@ -4,7 +4,7 @@
* by J. Kercheval, and on code written by Kenneth Almquist, though * by J. Kercheval, and on code written by Kenneth Almquist, though
* it shares no code. * it shares no code.
* *
* Copyright 2001-2004, Axel Dörfler, [email protected]. * Copyright 2001-2005, Axel Dörfler, [email protected].
* This file may be used under the terms of the MIT License. * This file may be used under the terms of the MIT License.
*/ */
@@ -1573,29 +1573,47 @@ Query::LiveUpdate(Inode *inode, const char *attribute, int32 type, const uint8 *
status_t oldStatus = fExpression->Root()->Match(inode, attribute, type, oldKey, oldLength); status_t oldStatus = fExpression->Root()->Match(inode, attribute, type, oldKey, oldLength);
status_t newStatus = fExpression->Root()->Match(inode, attribute, type, newKey, newLength); status_t newStatus = fExpression->Root()->Match(inode, attribute, type, newKey, newLength);
int32 op; const char *name = NULL;
if (oldStatus == MATCH_OK && newStatus == MATCH_OK) { bool entryCreated;
// only send out a notification if the name was changed
if (oldStatus != MATCH_OK) {
if (newStatus != MATCH_OK) {
// nothing has changed
return;
}
entryCreated = true;
} else if (newStatus != MATCH_OK) {
// entry got removed
entryCreated = false;
} else {
// the entry stays in the query - only notify in case the name of the inode was changed
if (oldKey == NULL || strcmp(attribute, "name")) if (oldKey == NULL || strcmp(attribute, "name"))
return; return;
send_notification(fPort, fToken, B_QUERY_UPDATE, B_ENTRY_REMOVED, fVolume->ID(), 0, notify_query_entry_removed(fPort, fToken, fVolume->ID(),
fVolume->ToVnode(inode->Parent()), 0, inode->ID(), (const char *)oldKey); fVolume->ToVnode(inode->Parent()), (const char *)oldKey, inode->ID());
op = B_ENTRY_CREATED; name = (const char *)newKey;
} else if (oldStatus != MATCH_OK && newStatus != MATCH_OK) { entryCreated = true;
// nothing has changed }
return;
} else if (oldStatus == MATCH_OK && newStatus != MATCH_OK) // we may need to get the name of the inode
op = B_ENTRY_REMOVED;
else char nameBuffer[B_FILE_NAME_LENGTH];
op = B_ENTRY_CREATED;
if (name == NULL) {
// if "value" is NULL, send_notification() crashes... if (inode->GetName(nameBuffer) != B_OK)
const char *value = (const char *)newKey; nameBuffer[0] = '\0';
if (type != B_STRING_TYPE || value == NULL) name = nameBuffer;
value = ""; }
send_notification(fPort, fToken, B_QUERY_UPDATE, op, fVolume->ID(), 0, // notify query listeners
fVolume->ToVnode(inode->Parent()), 0, inode->ID(), value);
if (entryCreated) {
notify_query_entry_created(fPort, fToken, fVolume->ID(),
fVolume->ToVnode(inode->Parent()), name, inode->ID());
} else {
notify_query_entry_removed(fPort, fToken, fVolume->ID(),
fVolume->ToVnode(inode->Parent()), name, inode->ID());
}
} }