BActivationTransaction: Make BArchivable
This commit is contained in:
parent
d4f9c465fd
commit
56b1376090
@ -9,6 +9,7 @@
|
||||
#define _PACKAGE__PRIVATE__ACTIVATION_TRANSACTION_H_
|
||||
|
||||
|
||||
#include <Archivable.h>
|
||||
#include <package/PackageDefs.h>
|
||||
#include <StringList.h>
|
||||
|
||||
@ -17,10 +18,12 @@ namespace BPackageKit {
|
||||
namespace BPrivate {
|
||||
|
||||
|
||||
class BActivationTransaction {
|
||||
class BActivationTransaction : public BArchivable {
|
||||
public:
|
||||
BActivationTransaction();
|
||||
~BActivationTransaction();
|
||||
BActivationTransaction(BMessage* archive,
|
||||
status_t* _error = NULL);
|
||||
virtual ~BActivationTransaction();
|
||||
|
||||
status_t SetTo(BPackageInstallationLocation location,
|
||||
int64 changeCount,
|
||||
@ -49,6 +52,14 @@ public:
|
||||
const BStringList& packages);
|
||||
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:
|
||||
BPackageInstallationLocation fLocation;
|
||||
int64 fChangeCount;
|
||||
|
@ -9,6 +9,10 @@
|
||||
|
||||
#include <package/ActivationTransaction.h>
|
||||
|
||||
#include <new>
|
||||
|
||||
#include <Message.h>
|
||||
|
||||
|
||||
namespace BPackageKit {
|
||||
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()
|
||||
{
|
||||
}
|
||||
@ -41,6 +76,7 @@ BActivationTransaction::InitCheck() const
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
BActivationTransaction::SetTo(BPackageInstallationLocation location,
|
||||
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 BPackageKit
|
||||
|
@ -221,17 +221,9 @@ BDaemonClient::_CommitTransaction(const BActivationTransaction& transaction,
|
||||
|
||||
// send the request
|
||||
BMessage request(B_MESSAGE_COMMIT_TRANSACTION);
|
||||
if ((error = request.AddInt32("location", transaction.Location())) != B_OK
|
||||
|| (error = request.AddInt64("change count",
|
||||
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) {
|
||||
error = transaction.Archive(&request);
|
||||
if (error != B_OK)
|
||||
return error;
|
||||
}
|
||||
|
||||
BMessage reply;
|
||||
fDaemonMessenger.SendMessage(&request, &reply);
|
||||
|
Loading…
x
Reference in New Issue
Block a user