2 * Copyright 2013, Haiku, Inc. All Rights Reserved.
3 * Distributed under the terms of the MIT License.
6 * Ingo Weinhold <ingo_weinhold@gmx.de>
10 #include <package/ActivationTransaction.h>
17 namespace BPackageKit
{
21 BActivationTransaction::BActivationTransaction()
23 fLocation(B_PACKAGE_INSTALLATION_LOCATION_ENUM_COUNT
),
25 fTransactionDirectoryName(),
26 fPackagesToActivate(),
27 fPackagesToDeactivate()
32 BActivationTransaction::BActivationTransaction(BMessage
* archive
,
35 fLocation(B_PACKAGE_INSTALLATION_LOCATION_ENUM_COUNT
),
37 fTransactionDirectoryName(),
38 fPackagesToActivate(),
39 fPackagesToDeactivate()
43 if ((error
= archive
->FindInt32("location", &location
)) == B_OK
44 && (error
= archive
->FindInt64("change count", &fChangeCount
)) == B_OK
45 && (error
= archive
->FindString("transaction",
46 &fTransactionDirectoryName
)) == B_OK
47 && (error
= _ExtractStringList(archive
, "activate",
48 fPackagesToActivate
)) == B_OK
49 && (error
= _ExtractStringList(archive
, "deactivate",
50 fPackagesToDeactivate
)) == B_OK
) {
52 && location
<= B_PACKAGE_INSTALLATION_LOCATION_ENUM_COUNT
) {
53 fLocation
= (BPackageInstallationLocation
)location
;
63 BActivationTransaction::~BActivationTransaction()
69 BActivationTransaction::InitCheck() const
71 if (fLocation
< 0 || fLocation
>= B_PACKAGE_INSTALLATION_LOCATION_ENUM_COUNT
72 || fTransactionDirectoryName
.IsEmpty()
73 || (fPackagesToActivate
.IsEmpty() && fPackagesToDeactivate
.IsEmpty())) {
81 BActivationTransaction::SetTo(BPackageInstallationLocation location
,
82 int64 changeCount
, const BString
& directoryName
)
84 if (location
< 0 || location
>= B_PACKAGE_INSTALLATION_LOCATION_ENUM_COUNT
85 || directoryName
.IsEmpty()) {
90 fChangeCount
= changeCount
;
91 fTransactionDirectoryName
= directoryName
;
92 fPackagesToActivate
.MakeEmpty();
93 fPackagesToDeactivate
.MakeEmpty();
99 BPackageInstallationLocation
100 BActivationTransaction::Location() const
107 BActivationTransaction::SetLocation(BPackageInstallationLocation location
)
109 fLocation
= location
;
114 BActivationTransaction::ChangeCount() const
121 BActivationTransaction::SetChangeCount(int64 changeCount
)
123 fChangeCount
= changeCount
;
128 BActivationTransaction::TransactionDirectoryName() const
130 return fTransactionDirectoryName
;
135 BActivationTransaction::SetTransactionDirectoryName(
136 const BString
& directoryName
)
138 fTransactionDirectoryName
= directoryName
;
143 BActivationTransaction::PackagesToActivate() const
145 return fPackagesToActivate
;
150 BActivationTransaction::SetPackagesToActivate(const BStringList
& packages
)
152 fPackagesToActivate
= packages
;
153 return fPackagesToActivate
.CountStrings() == packages
.CountStrings();
158 BActivationTransaction::AddPackageToActivate(const BString
& package
)
160 return fPackagesToActivate
.Add(package
);
165 BActivationTransaction::PackagesToDeactivate() const
167 return fPackagesToDeactivate
;
172 BActivationTransaction::SetPackagesToDeactivate(const BStringList
& packages
)
174 fPackagesToDeactivate
= packages
;
175 return fPackagesToDeactivate
.CountStrings() == packages
.CountStrings();
180 BActivationTransaction::AddPackageToDeactivate(const BString
& package
)
182 return fPackagesToDeactivate
.Add(package
);
187 BActivationTransaction::Archive(BMessage
* archive
, bool deep
) const
189 status_t error
= BArchivable::Archive(archive
, deep
);
193 if ((error
= archive
->AddInt32("location", fLocation
)) != B_OK
194 || (error
= archive
->AddInt64("change count", fChangeCount
)) != B_OK
195 || (error
= archive
->AddString("transaction",
196 fTransactionDirectoryName
)) != B_OK
197 || (error
= archive
->AddStrings("activate", fPackagesToActivate
))
199 || (error
= archive
->AddStrings("deactivate", fPackagesToDeactivate
))
208 /*static*/ BArchivable
*
209 BActivationTransaction::Instantiate(BMessage
* archive
)
211 if (validate_instantiation(archive
, "BActivationTransaction"))
212 return new(std::nothrow
) BActivationTransaction(archive
);
218 BActivationTransaction::_ExtractStringList(BMessage
* archive
, const char* field
,
221 status_t error
= archive
->FindStrings(field
, &_list
);
222 return error
== B_NAME_NOT_FOUND
? B_OK
: error
;
223 // If the field doesn't exist, that's OK.
227 } // namespace BPrivate
228 } // namespace BPackageKit