BActivationTransaction: Make BArchivable
This commit is contained in:
@@ -9,6 +9,7 @@
|
|||||||
#define _PACKAGE__PRIVATE__ACTIVATION_TRANSACTION_H_
|
#define _PACKAGE__PRIVATE__ACTIVATION_TRANSACTION_H_
|
||||||
|
|
||||||
|
|
||||||
|
#include <Archivable.h>
|
||||||
#include <package/PackageDefs.h>
|
#include <package/PackageDefs.h>
|
||||||
#include <StringList.h>
|
#include <StringList.h>
|
||||||
|
|
||||||
@@ -17,10 +18,12 @@ namespace BPackageKit {
|
|||||||
namespace BPrivate {
|
namespace BPrivate {
|
||||||
|
|
||||||
|
|
||||||
class BActivationTransaction {
|
class BActivationTransaction : public BArchivable {
|
||||||
public:
|
public:
|
||||||
BActivationTransaction();
|
BActivationTransaction();
|
||||||
~BActivationTransaction();
|
BActivationTransaction(BMessage* archive,
|
||||||
|
status_t* _error = NULL);
|
||||||
|
virtual ~BActivationTransaction();
|
||||||
|
|
||||||
status_t SetTo(BPackageInstallationLocation location,
|
status_t SetTo(BPackageInstallationLocation location,
|
||||||
int64 changeCount,
|
int64 changeCount,
|
||||||
@@ -49,6 +52,14 @@ public:
|
|||||||
const BStringList& packages);
|
const BStringList& packages);
|
||||||
bool AddPackageToDeactivate(const BString& package);
|
bool AddPackageToDeactivate(const BString& package);
|
||||||
|
|
||||||
|
virtual status_t Archive(BMessage* archive,
|
||||||
|
bool deep = true) const;
|
||||||
|
static BArchivable* Instantiate(BMessage* archive);
|
||||||
|
|
||||||
|
private:
|
||||||
|
static status_t _ExtractStringList(BMessage* archive,
|
||||||
|
const char* field, BStringList& _list);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
BPackageInstallationLocation fLocation;
|
BPackageInstallationLocation fLocation;
|
||||||
int64 fChangeCount;
|
int64 fChangeCount;
|
||||||
|
|||||||
@@ -9,6 +9,10 @@
|
|||||||
|
|
||||||
#include <package/ActivationTransaction.h>
|
#include <package/ActivationTransaction.h>
|
||||||
|
|
||||||
|
#include <new>
|
||||||
|
|
||||||
|
#include <Message.h>
|
||||||
|
|
||||||
|
|
||||||
namespace BPackageKit {
|
namespace BPackageKit {
|
||||||
namespace BPrivate {
|
namespace BPrivate {
|
||||||
@@ -25,6 +29,37 @@ BActivationTransaction::BActivationTransaction()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
BActivationTransaction::BActivationTransaction(BMessage* archive,
|
||||||
|
status_t* _error)
|
||||||
|
:
|
||||||
|
fLocation(B_PACKAGE_INSTALLATION_LOCATION_ENUM_COUNT),
|
||||||
|
fChangeCount(0),
|
||||||
|
fTransactionDirectoryName(),
|
||||||
|
fPackagesToActivate(),
|
||||||
|
fPackagesToDeactivate()
|
||||||
|
{
|
||||||
|
status_t error;
|
||||||
|
int32 location;
|
||||||
|
if ((error = archive->FindInt32("location", &location)) == B_OK
|
||||||
|
|| (error = archive->FindInt64("change count", &fChangeCount)) == B_OK
|
||||||
|
|| (error = archive->FindString("transaction",
|
||||||
|
&fTransactionDirectoryName)) == B_OK
|
||||||
|
|| (error = _ExtractStringList(archive, "activate",
|
||||||
|
fPackagesToActivate)) == B_OK
|
||||||
|
|| (error = _ExtractStringList(archive, "deactivate",
|
||||||
|
fPackagesToDeactivate)) == B_OK) {
|
||||||
|
if (location >= 0
|
||||||
|
&& location <= B_PACKAGE_INSTALLATION_LOCATION_ENUM_COUNT) {
|
||||||
|
fLocation = (BPackageInstallationLocation)location;
|
||||||
|
} else
|
||||||
|
error = B_BAD_VALUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_error != NULL)
|
||||||
|
*_error = error;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
BActivationTransaction::~BActivationTransaction()
|
BActivationTransaction::~BActivationTransaction()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@@ -41,6 +76,7 @@ BActivationTransaction::InitCheck() const
|
|||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
BActivationTransaction::SetTo(BPackageInstallationLocation location,
|
BActivationTransaction::SetTo(BPackageInstallationLocation location,
|
||||||
int64 changeCount, const BString& directoryName)
|
int64 changeCount, const BString& directoryName)
|
||||||
@@ -147,5 +183,46 @@ BActivationTransaction::AddPackageToDeactivate(const BString& package)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
status_t
|
||||||
|
BActivationTransaction::Archive(BMessage* archive, bool deep) const
|
||||||
|
{
|
||||||
|
status_t error = BArchivable::Archive(archive, deep);
|
||||||
|
if (error != B_OK)
|
||||||
|
return error;
|
||||||
|
|
||||||
|
if ((error = archive->AddInt32("location", fLocation)) != B_OK
|
||||||
|
|| (error = archive->AddInt64("change count", fChangeCount)) != B_OK
|
||||||
|
|| (error = archive->AddString("transaction",
|
||||||
|
fTransactionDirectoryName)) != B_OK
|
||||||
|
|| (error = archive->AddStrings("activate", fPackagesToActivate))
|
||||||
|
!= B_OK
|
||||||
|
|| (error = archive->AddStrings("deactivate", fPackagesToDeactivate))
|
||||||
|
!= B_OK) {
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
|
||||||
|
return B_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*static*/ BArchivable*
|
||||||
|
BActivationTransaction::Instantiate(BMessage* archive)
|
||||||
|
{
|
||||||
|
if (validate_instantiation(archive, "BActivationTransaction"))
|
||||||
|
return new(std::nothrow) BActivationTransaction(archive);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*static*/ status_t
|
||||||
|
BActivationTransaction::_ExtractStringList(BMessage* archive, const char* field,
|
||||||
|
BStringList& _list)
|
||||||
|
{
|
||||||
|
status_t error = archive->FindStrings(field, &_list);
|
||||||
|
return error == B_NAME_NOT_FOUND ? B_OK : error;
|
||||||
|
// If the field doesn't exist, that's OK.
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
} // namespace BPrivate
|
} // namespace BPrivate
|
||||||
} // namespace BPackageKit
|
} // namespace BPackageKit
|
||||||
|
|||||||
@@ -221,17 +221,9 @@ BDaemonClient::_CommitTransaction(const BActivationTransaction& transaction,
|
|||||||
|
|
||||||
// send the request
|
// send the request
|
||||||
BMessage request(B_MESSAGE_COMMIT_TRANSACTION);
|
BMessage request(B_MESSAGE_COMMIT_TRANSACTION);
|
||||||
if ((error = request.AddInt32("location", transaction.Location())) != B_OK
|
error = transaction.Archive(&request);
|
||||||
|| (error = request.AddInt64("change count",
|
if (error != B_OK)
|
||||||
transaction.ChangeCount())) != B_OK
|
|
||||||
|| (error = request.AddString("transaction",
|
|
||||||
transaction.TransactionDirectoryName())) != B_OK
|
|
||||||
|| (error = request.AddStrings("activate",
|
|
||||||
transaction.PackagesToActivate())) != B_OK
|
|
||||||
|| (error = request.AddStrings("deactivate",
|
|
||||||
transaction.PackagesToDeactivate())) != B_OK) {
|
|
||||||
return error;
|
return error;
|
||||||
}
|
|
||||||
|
|
||||||
BMessage reply;
|
BMessage reply;
|
||||||
fDaemonMessenger.SendMessage(&request, &reply);
|
fDaemonMessenger.SendMessage(&request, &reply);
|
||||||
|
|||||||
Reference in New Issue
Block a user