Separate notification from deletion in repository-handlers.

* Add NotifyDone() to all repository-attribute handlers and invoke that
  to notify any listeners.
* Unify deletion to a single implementation of Delete() in the base
  class. Before, the root handler for a repository didn't do that, but
  just triggered the notification.
This commit is contained in:
Oliver Tappe 2013-09-18 20:20:43 +02:00
parent b162bdaf1d
commit 0a345af77e
3 changed files with 63 additions and 33 deletions

View File

@ -243,6 +243,8 @@ public:
const AttributeValue& value,
AttributeHandler** _handler);
virtual status_t NotifyDone(AttributeHandlerContext* context);
virtual status_t Delete(AttributeHandlerContext* context);
protected:
@ -256,12 +258,14 @@ class ReaderImplBase::IgnoreAttributeHandler : public AttributeHandler {
class ReaderImplBase::PackageInfoAttributeHandlerBase
: public AttributeHandler {
private:
typedef AttributeHandler super;
public:
PackageInfoAttributeHandlerBase(
BPackageInfoAttributeValue&
packageInfoValue);
virtual status_t Delete(AttributeHandlerContext* context);
virtual status_t NotifyDone(AttributeHandlerContext* context);
protected:
BPackageInfoAttributeValue& fPackageInfoValue;
@ -270,6 +274,8 @@ protected:
class ReaderImplBase::PackageVersionAttributeHandler
: public PackageInfoAttributeHandlerBase {
private:
typedef PackageInfoAttributeHandlerBase super;
public:
PackageVersionAttributeHandler(
BPackageInfoAttributeValue&
@ -282,7 +288,7 @@ public:
const AttributeValue& value,
AttributeHandler** _handler);
virtual status_t Delete(AttributeHandlerContext* context);
virtual status_t NotifyDone(AttributeHandlerContext* context);
private:
BPackageVersionData& fPackageVersionData;
@ -292,6 +298,8 @@ private:
class ReaderImplBase::PackageResolvableAttributeHandler
: public PackageInfoAttributeHandlerBase {
private:
typedef PackageInfoAttributeHandlerBase super;
public:
PackageResolvableAttributeHandler(
BPackageInfoAttributeValue&
@ -306,6 +314,8 @@ public:
class ReaderImplBase::PackageResolvableExpressionAttributeHandler
: public PackageInfoAttributeHandlerBase {
private:
typedef PackageInfoAttributeHandlerBase super;
public:
PackageResolvableExpressionAttributeHandler(
BPackageInfoAttributeValue&
@ -320,6 +330,8 @@ public:
class ReaderImplBase::GlobalWritableFileInfoAttributeHandler
: public PackageInfoAttributeHandlerBase {
private:
typedef PackageInfoAttributeHandlerBase super;
public:
GlobalWritableFileInfoAttributeHandler(
BPackageInfoAttributeValue&
@ -334,6 +346,8 @@ public:
class ReaderImplBase::UserSettingsFileInfoAttributeHandler
: public PackageInfoAttributeHandlerBase {
private:
typedef PackageInfoAttributeHandlerBase super;
public:
UserSettingsFileInfoAttributeHandler(
BPackageInfoAttributeValue&
@ -348,6 +362,8 @@ public:
class ReaderImplBase::UserAttributeHandler
: public PackageInfoAttributeHandlerBase {
private:
typedef PackageInfoAttributeHandlerBase super;
public:
UserAttributeHandler(
BPackageInfoAttributeValue&
@ -358,7 +374,7 @@ public:
const AttributeValue& value,
AttributeHandler** _handler);
virtual status_t Delete(AttributeHandlerContext* context);
virtual status_t NotifyDone(AttributeHandlerContext* context);
private:
Array<const char*> fGroups;
@ -366,6 +382,8 @@ private:
class ReaderImplBase::PackageAttributeHandler : public AttributeHandler {
private:
typedef AttributeHandler super;
public:
virtual status_t HandleAttribute(
AttributeHandlerContext* context, uint8 id,
@ -378,6 +396,8 @@ private:
class ReaderImplBase::LowLevelAttributeHandler : public AttributeHandler {
private:
typedef AttributeHandler super;
public:
LowLevelAttributeHandler();
LowLevelAttributeHandler(uint8 id,
@ -388,7 +408,8 @@ public:
AttributeHandlerContext* context, uint8 id,
const AttributeValue& value,
AttributeHandler** _handler);
virtual status_t Delete(AttributeHandlerContext* context);
virtual status_t NotifyDone(AttributeHandlerContext* context);
private:
void* fParentToken;

View File

@ -103,6 +103,14 @@ ReaderImplBase::AttributeHandler::HandleAttribute(
}
status_t
ReaderImplBase::AttributeHandler::NotifyDone(
AttributeHandlerContext* context)
{
return B_OK;
}
status_t
ReaderImplBase::AttributeHandler::Delete(AttributeHandlerContext* context)
{
@ -124,14 +132,12 @@ ReaderImplBase::PackageInfoAttributeHandlerBase
status_t
ReaderImplBase::PackageInfoAttributeHandlerBase::Delete(
ReaderImplBase::PackageInfoAttributeHandlerBase::NotifyDone(
AttributeHandlerContext* context)
{
status_t error = context->packageContentHandler->HandlePackageAttribute(
fPackageInfoValue);
fPackageInfoValue.Clear();
delete this;
return error;
}
@ -143,7 +149,7 @@ ReaderImplBase::PackageVersionAttributeHandler::PackageVersionAttributeHandler(
BPackageInfoAttributeValue& packageInfoValue,
BPackageVersionData& versionData, bool notify)
:
PackageInfoAttributeHandlerBase(packageInfoValue),
super(packageInfoValue),
fPackageVersionData(versionData),
fNotify(notify)
{
@ -187,19 +193,14 @@ ReaderImplBase::PackageVersionAttributeHandler::HandleAttribute(
status_t
ReaderImplBase::PackageVersionAttributeHandler::Delete(
ReaderImplBase::PackageVersionAttributeHandler::NotifyDone(
AttributeHandlerContext* context)
{
status_t error = B_OK;
if (fNotify) {
fPackageInfoValue.attributeID = B_PACKAGE_INFO_VERSION;
error = context->packageContentHandler->HandlePackageAttribute(
fPackageInfoValue);
fPackageInfoValue.Clear();
}
if (!fNotify)
return B_OK;
delete this;
return error;
fPackageInfoValue.attributeID = B_PACKAGE_INFO_VERSION;
return super::NotifyDone(context);
}
@ -210,7 +211,7 @@ ReaderImplBase::PackageResolvableAttributeHandler
::PackageResolvableAttributeHandler(
BPackageInfoAttributeValue& packageInfoValue)
:
PackageInfoAttributeHandlerBase(packageInfoValue)
super(packageInfoValue)
{
}
@ -268,7 +269,7 @@ ReaderImplBase::PackageResolvableExpressionAttributeHandler
::PackageResolvableExpressionAttributeHandler(
BPackageInfoAttributeValue& packageInfoValue)
:
PackageInfoAttributeHandlerBase(packageInfoValue)
super(packageInfoValue)
{
}
@ -328,7 +329,7 @@ ReaderImplBase::GlobalWritableFileInfoAttributeHandler
::GlobalWritableFileInfoAttributeHandler(
BPackageInfoAttributeValue& packageInfoValue)
:
PackageInfoAttributeHandlerBase(packageInfoValue)
super(packageInfoValue)
{
}
@ -378,7 +379,7 @@ ReaderImplBase::UserSettingsFileInfoAttributeHandler
::UserSettingsFileInfoAttributeHandler(
BPackageInfoAttributeValue& packageInfoValue)
:
PackageInfoAttributeHandlerBase(packageInfoValue)
super(packageInfoValue)
{
}
@ -419,7 +420,7 @@ ReaderImplBase::UserSettingsFileInfoAttributeHandler::HandleAttribute(
ReaderImplBase::UserAttributeHandler::UserAttributeHandler(
BPackageInfoAttributeValue& packageInfoValue)
:
PackageInfoAttributeHandlerBase(packageInfoValue),
super(packageInfoValue),
fGroups()
{
}
@ -464,14 +465,15 @@ ReaderImplBase::UserAttributeHandler::HandleAttribute(
status_t
ReaderImplBase::UserAttributeHandler::Delete(AttributeHandlerContext* context)
ReaderImplBase::UserAttributeHandler::NotifyDone(
AttributeHandlerContext* context)
{
if (!fGroups.IsEmpty()) {
fPackageInfoValue.user.groups = fGroups.Elements();
fPackageInfoValue.user.groupCount = fGroups.Count();
}
return PackageInfoAttributeHandlerBase::Delete(context);
return super::NotifyDone(context);
}
@ -740,17 +742,16 @@ ReaderImplBase::LowLevelAttributeHandler::HandleAttribute(
status_t
ReaderImplBase::LowLevelAttributeHandler::Delete(
ReaderImplBase::LowLevelAttributeHandler::NotifyDone(
AttributeHandlerContext* context)
{
status_t error = B_OK;
if (fID != B_HPKG_ATTRIBUTE_ID_ENUM_COUNT) {
error = context->lowLevelHandler->HandleAttributeDone(
status_t error = context->lowLevelHandler->HandleAttributeDone(
(BHPKGAttributeID)fID, fValue, fParentToken, fToken);
if (error != B_OK)
return error;
}
delete this;
return error;
return super::NotifyDone(context);
}
@ -1082,6 +1083,9 @@ ReaderImplBase::_ParseAttributeTree(AttributeHandlerContext* context)
if (tag == 0) {
AttributeHandler* handler = PopAttributeHandler();
error = handler->NotifyDone(context);
if (error != B_OK)
return error;
if (level-- == 0)
return B_OK;

View File

@ -45,6 +45,8 @@ static const size_t kMaxPackageAttributesSize = 64 * 1024 * 1024;
class RepositoryReaderImpl::PackagesAttributeHandler
: public AttributeHandler {
private:
typedef AttributeHandler super;
public:
PackagesAttributeHandler(BRepositoryContentHandler* contentHandler)
:
@ -92,9 +94,12 @@ public:
return B_OK;
}
virtual status_t Delete(AttributeHandlerContext* context)
virtual status_t NotifyDone(AttributeHandlerContext* context)
{
return _NotifyPackageDone();
status_t result = _NotifyPackageDone();
if (result == B_OK)
result = super::NotifyDone(context);
return result;
}
private: