NodeListener::NodeChanged(): Provide old value

* Add interface OldNodeAttributes an instance of which is passed to
  NodeListener::NodeChanged() to provide the old attribute values
  (currently only modification time and file size).
* Also extend PackageLinksListener::PackageLinkNodeChanged() with a
  OldNodeAttributes parameter.
* Add OldNodeAttributes implementations for PackageLinkSymlink (inner
  class OldAttributes) and UnpackingNode (OldUnpackageNodeAttributes).
This commit is contained in:
Ingo Weinhold 2011-07-07 08:38:02 +02:00
parent 9b2a170842
commit 773005292a
12 changed files with 154 additions and 18 deletions

View File

@ -21,6 +21,7 @@ HAIKU_PACKAGE_FS_SOURCES =
NameIndex.cpp NameIndex.cpp
Node.cpp Node.cpp
NodeListener.cpp NodeListener.cpp
OldUnpackingNodeAttributes.cpp
Query.cpp Query.cpp
Package.cpp Package.cpp
PackageDirectory.cpp PackageDirectory.cpp

View File

@ -186,7 +186,8 @@ NameIndex::NodeRemoved(Node* node)
void void
NameIndex::NodeChanged(Node* node, uint32 statFields) NameIndex::NodeChanged(Node* node, uint32 statFields,
const OldNodeAttributes& oldAttributes)
{ {
// nothing to do -- the name remains the same // nothing to do -- the name remains the same
} }

View File

@ -25,7 +25,8 @@ public:
private: private:
virtual void NodeAdded(Node* node); virtual void NodeAdded(Node* node);
virtual void NodeRemoved(Node* node); virtual void NodeRemoved(Node* node);
virtual void NodeChanged(Node* node, uint32 statFields); virtual void NodeChanged(Node* node, uint32 statFields,
const OldNodeAttributes& oldAttributes);
protected: protected:
virtual AbstractIndexIterator* InternalGetIterator(); virtual AbstractIndexIterator* InternalGetIterator();

View File

@ -7,6 +7,17 @@
#include "NodeListener.h" #include "NodeListener.h"
// #pragma mark - OldNodeAttributes
OldNodeAttributes::~OldNodeAttributes()
{
}
// #pragma mark - NodeListener
NodeListener::NodeListener() NodeListener::NodeListener()
: :
fPrevious(this), fPrevious(this),
@ -34,6 +45,7 @@ NodeListener::NodeRemoved(Node* node)
void void
NodeListener::NodeChanged(Node* node, uint32 statFields) NodeListener::NodeChanged(Node* node, uint32 statFields,
const OldNodeAttributes& oldAttributes)
{ {
} }

View File

@ -6,6 +6,8 @@
#define NODE_LISTENER_H #define NODE_LISTENER_H
#include <time.h>
#include <util/DoublyLinkedList.h> #include <util/DoublyLinkedList.h>
#include <util/OpenHashTable.h> #include <util/OpenHashTable.h>
@ -16,6 +18,15 @@ class Node;
#define NOT_LISTENING_NODE ((Node*)~(addr_t)0) #define NOT_LISTENING_NODE ((Node*)~(addr_t)0)
class OldNodeAttributes {
public:
virtual ~OldNodeAttributes();
virtual timespec ModifiedTime() const = 0;
virtual off_t FileSize() const = 0;
};
class NodeListener { class NodeListener {
public: public:
NodeListener(); NodeListener();
@ -23,7 +34,8 @@ public:
virtual void NodeAdded(Node* node); virtual void NodeAdded(Node* node);
virtual void NodeRemoved(Node* node); virtual void NodeRemoved(Node* node);
virtual void NodeChanged(Node* node, uint32 statFields); virtual void NodeChanged(Node* node, uint32 statFields,
const OldNodeAttributes& oldAttributes);
void StartedListening(Node* node) void StartedListening(Node* node)
{ fNode = node; } { fNode = node; }

View File

@ -0,0 +1,35 @@
/*
* Copyright 2011, Ingo Weinhold, ingo_weinhold@gmx.de.
* Distributed under the terms of the MIT License.
*/
#include "OldUnpackingNodeAttributes.h"
#include "PackageNode.h"
OldUnpackingNodeAttributes::OldUnpackingNodeAttributes(
PackageNode* packageNode)
:
fPackageNode(packageNode)
{
}
timespec
OldUnpackingNodeAttributes::ModifiedTime() const
{
if (fPackageNode != NULL)
return fPackageNode->ModifiedTime();
timespec time = { 0, 0 };
return time;
}
off_t
OldUnpackingNodeAttributes::FileSize() const
{
return fPackageNode != NULL ? fPackageNode->FileSize() : 0;
}

View File

@ -0,0 +1,28 @@
/*
* Copyright 2011, Ingo Weinhold, ingo_weinhold@gmx.de.
* Distributed under the terms of the MIT License.
*/
#ifndef OLD_UNPACKING_NODE_ATTRIBUTES_H
#define OLD_UNPACKING_NODE_ATTRIBUTES_H
#include "NodeListener.h"
class PackageNode;
class OldUnpackingNodeAttributes : public OldNodeAttributes {
public:
OldUnpackingNodeAttributes(
PackageNode* packageNode);
virtual timespec ModifiedTime() const;
virtual off_t FileSize() const;
private:
PackageNode* fPackageNode;
};
#endif // OLD_UNPACKING_NODE_ATTRIBUTES_H

View File

@ -12,6 +12,7 @@
#include "EmptyAttributeDirectoryCookie.h" #include "EmptyAttributeDirectoryCookie.h"
#include "DebugSupport.h" #include "DebugSupport.h"
#include "NodeListener.h"
#include "PackageLinksListener.h" #include "PackageLinksListener.h"
#include "Utils.h" #include "Utils.h"
#include "Volume.h" #include "Volume.h"
@ -41,7 +42,34 @@ link_path_for_mount_type(MountType type)
} }
// #pragma mark - // #pragma mark - OldAttributes
struct PackageLinkSymlink::OldAttributes : OldNodeAttributes {
OldAttributes(const timespec& modifiedTime, off_t fileSize)
:
fModifiedTime(modifiedTime),
fFileSize(fileSize)
{
}
virtual timespec ModifiedTime() const
{
return fModifiedTime;
}
virtual off_t FileSize() const
{
return fFileSize;
}
private:
timespec fModifiedTime;
off_t fFileSize;
};
// #pragma mark - PackageLinkSymlink
PackageLinkSymlink::PackageLinkSymlink(Package* package) PackageLinkSymlink::PackageLinkSymlink(Package* package)
@ -61,6 +89,8 @@ PackageLinkSymlink::~PackageLinkSymlink()
void void
PackageLinkSymlink::Update(Package* package, PackageLinksListener* listener) PackageLinkSymlink::Update(Package* package, PackageLinksListener* listener)
{ {
OldAttributes oldAttributes(fModifiedTime, FileSize());
if (package != NULL) { if (package != NULL) {
fLinkPath = link_path_for_mount_type( fLinkPath = link_path_for_mount_type(
package->Domain()->Volume()->MountType()); package->Domain()->Volume()->MountType());
@ -71,7 +101,7 @@ PackageLinkSymlink::Update(Package* package, PackageLinksListener* listener)
if (listener != NULL) { if (listener != NULL) {
listener->PackageLinkNodeChanged(this, listener->PackageLinkNodeChanged(this,
B_STAT_SIZE | B_STAT_MODIFICATION_TIME); B_STAT_SIZE | B_STAT_MODIFICATION_TIME, oldAttributes);
} }
} }

View File

@ -38,6 +38,9 @@ public:
virtual status_t OpenAttribute(const char* name, int openMode, virtual status_t OpenAttribute(const char* name, int openMode,
AttributeCookie*& _cookie); AttributeCookie*& _cookie);
private:
struct OldAttributes;
private: private:
timespec fModifiedTime; timespec fModifiedTime;
const char* fLinkPath; const char* fLinkPath;

View File

@ -10,6 +10,7 @@
class Node; class Node;
class OldNodeAttributes;
class PackageLinksListener { class PackageLinksListener {
@ -19,7 +20,8 @@ public:
virtual void PackageLinkNodeAdded(Node* node) = 0; virtual void PackageLinkNodeAdded(Node* node) = 0;
virtual void PackageLinkNodeRemoved(Node* node) = 0; virtual void PackageLinkNodeRemoved(Node* node) = 0;
virtual void PackageLinkNodeChanged(Node* node, virtual void PackageLinkNodeChanged(Node* node,
uint32 statFields) = 0; uint32 statFields,
const OldNodeAttributes& oldAttributes) = 0;
}; };

View File

@ -33,6 +33,7 @@
#include "DebugSupport.h" #include "DebugSupport.h"
#include "kernel_interface.h" #include "kernel_interface.h"
#include "NameIndex.h" #include "NameIndex.h"
#include "OldUnpackingNodeAttributes.h"
#include "PackageDirectory.h" #include "PackageDirectory.h"
#include "PackageFile.h" #include "PackageFile.h"
#include "PackageFSRoot.h" #include "PackageFSRoot.h"
@ -775,10 +776,11 @@ Volume::PackageLinkNodeRemoved(Node* node)
void void
Volume::PackageLinkNodeChanged(Node* node, uint32 statFields) Volume::PackageLinkNodeChanged(Node* node, uint32 statFields,
const OldNodeAttributes& oldAttributes)
{ {
notify_stat_changed(ID(), node->ID(), statFields); notify_stat_changed(ID(), node->ID(), statFields);
_NotifyNodeChanged(node, statFields); _NotifyNodeChanged(node, statFields, oldAttributes);
} }
@ -1137,6 +1139,7 @@ Volume::_AddPackageNode(Directory* directory, PackageNode* packageNode,
bool newNode = false; bool newNode = false;
UnpackingNode* unpackingNode; UnpackingNode* unpackingNode;
Node* node = directory->FindChild(packageNode->Name()); Node* node = directory->FindChild(packageNode->Name());
PackageNode* oldPackageNode = NULL;
if (node != NULL) { if (node != NULL) {
unpackingNode = dynamic_cast<UnpackingNode*>(node); unpackingNode = dynamic_cast<UnpackingNode*>(node);
@ -1149,6 +1152,7 @@ Volume::_AddPackageNode(Directory* directory, PackageNode* packageNode,
RETURN_ERROR(error); RETURN_ERROR(error);
node = unpackingNode->GetNode(); node = unpackingNode->GetNode();
oldPackageNode = unpackingNode->GetPackageNode();
newNode = true; newNode = true;
} }
@ -1170,10 +1174,12 @@ Volume::_AddPackageNode(Directory* directory, PackageNode* packageNode,
RETURN_ERROR(error); RETURN_ERROR(error);
} }
if (newNode) if (newNode) {
_NotifyNodeAdded(node); _NotifyNodeAdded(node);
else } else if (packageNode == unpackingNode->GetPackageNode()) {
_NotifyNodeChanged(node, kAllStatFields); _NotifyNodeChanged(node, kAllStatFields,
OldUnpackingNodeAttributes(oldPackageNode));
}
if (notify) { if (notify) {
if (newNode) { if (newNode) {
@ -1238,8 +1244,10 @@ Volume::_RemovePackageNode(Directory* directory, PackageNode* packageNode,
if (nodeRemoved) if (nodeRemoved)
_NotifyNodeRemoved(node); _NotifyNodeRemoved(node);
else else if (packageNode == headPackageNode) {
_NotifyNodeChanged(node, kAllStatFields); _NotifyNodeChanged(node, kAllStatFields,
OldUnpackingNodeAttributes(headPackageNode));
}
if (!notify) if (!notify)
return; return;
@ -1716,7 +1724,8 @@ Volume::_NotifyNodeRemoved(Node* node)
void void
Volume::_NotifyNodeChanged(Node* node, uint32 statFields) Volume::_NotifyNodeChanged(Node* node, uint32 statFields,
const OldNodeAttributes& oldAttributes)
{ {
Node* key = node; Node* key = node;
@ -1727,7 +1736,7 @@ Volume::_NotifyNodeChanged(Node* node, uint32 statFields)
while (true) { while (true) {
NodeListener* next = listener->NextNodeListener(); NodeListener* next = listener->NextNodeListener();
listener->NodeChanged(node, statFields); listener->NodeChanged(node, statFields, oldAttributes);
if (listener == last) if (listener == last)
break; break;

View File

@ -97,7 +97,8 @@ private:
virtual void PackageLinkNodeAdded(Node* node); virtual void PackageLinkNodeAdded(Node* node);
virtual void PackageLinkNodeRemoved(Node* node); virtual void PackageLinkNodeRemoved(Node* node);
virtual void PackageLinkNodeChanged(Node* node, virtual void PackageLinkNodeChanged(Node* node,
uint32 statFields); uint32 statFields,
const OldNodeAttributes& oldAttributes);
private: private:
struct Job; struct Job;
@ -183,7 +184,8 @@ private:
void _NotifyNodeAdded(Node* node); void _NotifyNodeAdded(Node* node);
void _NotifyNodeRemoved(Node* node); void _NotifyNodeRemoved(Node* node);
void _NotifyNodeChanged(Node* node, void _NotifyNodeChanged(Node* node,
uint32 statFields); uint32 statFields,
const OldNodeAttributes& oldAttributes);
private: private:
mutable rw_lock fLock; mutable rw_lock fLock;