2 * Copyright 2013-2015, Haiku, Inc. All Rights Reserved.
3 * Distributed under the terms of the MIT License.
6 * Ingo Weinhold <ingo_weinhold@gmx.de>
7 * Rene Gollent <rene@gollent.com>
9 #ifndef _PACKAGE__MANAGER__PRIVATE__PACKAGE_MANAGER_H_
10 #define _PACKAGE__MANAGER__PRIVATE__PACKAGE_MANAGER_H_
16 #include <Directory.h>
17 #include <ObjectList.h>
18 #include <package/Context.h>
19 #include <package/PackageDefs.h>
20 #include <package/PackageRoster.h>
21 #include <package/RepositoryConfig.h>
22 #include <package/solver/Solver.h>
23 #include <package/solver/SolverRepository.h>
25 #include <package/ActivationTransaction.h>
26 #include <package/DaemonClient.h>
27 #include <package/Job.h>
30 namespace BPackageKit
{
33 class BCommitTransactionResult
;
41 using BPackageKit::BPrivate::BActivationTransaction
;
42 using BPackageKit::BPrivate::BDaemonClient
;
45 class BPackageManager
: protected BSupportKit::BJobStateListener
{
47 class RemoteRepository
;
48 class LocalRepository
;
49 class MiscLocalRepository
;
50 class InstalledRepository
;
52 class InstallationInterface
;
53 class ClientInstallationInterface
;
54 class UserInteractionHandler
;
56 typedef BObjectList
<RemoteRepository
> RemoteRepositoryList
;
57 typedef BObjectList
<InstalledRepository
> InstalledRepositoryList
;
58 typedef BObjectList
<BSolverPackage
> PackageList
;
59 typedef BObjectList
<Transaction
> TransactionList
;
62 B_ADD_INSTALLED_REPOSITORIES
= 0x01,
63 B_ADD_REMOTE_REPOSITORIES
= 0x02,
64 B_REFRESH_REPOSITORIES
= 0x04,
69 BPackageInstallationLocation location
,
70 InstallationInterface
*
71 installationInterface
,
72 UserInteractionHandler
*
73 userInteractionHandler
);
74 virtual ~BPackageManager();
76 void Init(uint32 flags
);
78 void SetDebugLevel(int32 level
);
79 // 0 - 10 (passed to libsolv)
81 BSolver
* Solver() const
84 const InstalledRepository
* SystemRepository() const
85 { return fSystemRepository
; }
86 const InstalledRepository
* HomeRepository() const
87 { return fHomeRepository
; }
88 const InstalledRepositoryList
& InstalledRepositories() const
89 { return fInstalledRepositories
; }
90 const RemoteRepositoryList
& OtherRepositories() const
91 { return fOtherRepositories
; }
93 void Install(const char* const* packages
,
95 void Install(const BSolverPackageSpecifierList
&
97 void Uninstall(const char* const* packages
,
99 void Uninstall(const BSolverPackageSpecifierList
&
101 void Update(const char* const* packages
,
103 void Update(const BSolverPackageSpecifierList
&
107 void VerifyInstallation();
110 virtual status_t
DownloadPackage(const BString
& fileURL
,
111 const BEntry
& targetEntry
,
112 const BString
& checksum
);
113 virtual status_t
RefreshRepository(
114 const BRepositoryConfig
& repoConfig
);
117 InstalledRepository
& InstallationRepository();
121 virtual void JobStarted(BSupportKit::BJob
* job
);
122 virtual void JobProgress(BSupportKit::BJob
* job
);
123 virtual void JobSucceeded(BSupportKit::BJob
* job
);
126 void _HandleProblems();
127 void _AnalyzeResult();
128 void _ConfirmChanges(bool fromMostSpecific
= false);
129 void _ApplyPackageChanges(
130 bool fromMostSpecific
= false);
131 void _PreparePackageChanges(
133 installationRepository
);
134 void _CommitPackageChanges(Transaction
& transaction
);
136 void _ClonePackageFile(
137 LocalRepository
* repository
,
138 BSolverPackage
* package
,
139 const BEntry
& entry
);
140 int32
_FindBasePackage(const PackageList
& packages
,
141 const BPackageInfo
& info
);
143 void _AddInstalledRepository(
144 InstalledRepository
* repository
);
145 void _AddRemoteRepository(BPackageRoster
& roster
,
146 const char* name
, bool refresh
);
147 status_t
_GetRepositoryCache(BPackageRoster
& roster
,
148 const BRepositoryConfig
& config
,
149 bool refresh
, BRepositoryCache
& _cache
);
151 void _AddPackageSpecifiers(
152 const char* const* searchStrings
,
153 int searchStringCount
,
154 BSolverPackageSpecifierList
& specifierList
);
155 bool _IsLocalPackage(const char* fileName
);
156 BSolverPackage
* _AddLocalPackage(const char* fileName
);
158 bool _NextSpecificInstallationLocation();
162 BPackageInstallationLocation fLocation
;
164 InstalledRepository
* fSystemRepository
;
165 InstalledRepository
* fHomeRepository
;
166 InstalledRepositoryList fInstalledRepositories
;
167 RemoteRepositoryList fOtherRepositories
;
168 MiscLocalRepository
* fLocalRepository
;
169 TransactionList fTransactions
;
171 // must be set by the derived class
172 InstallationInterface
* fInstallationInterface
;
173 UserInteractionHandler
* fUserInteractionHandler
;
177 class BPackageManager::RemoteRepository
: public BSolverRepository
{
180 const BRepositoryConfig
& config
);
182 const BRepositoryConfig
& Config() const;
185 BRepositoryConfig fConfig
;
189 class BPackageManager::LocalRepository
: public BSolverRepository
{
192 LocalRepository(const BString
& name
);
194 virtual void GetPackagePath(BSolverPackage
* package
,
199 class BPackageManager::MiscLocalRepository
: public LocalRepository
{
201 MiscLocalRepository();
203 BSolverPackage
* AddLocalPackage(const char* fileName
);
205 virtual void GetPackagePath(BSolverPackage
* package
,
209 typedef std::map
<BSolverPackage
*, std::string
> PackagePathMap
;
211 PackagePathMap fPackagePaths
;
215 class BPackageManager::InstalledRepository
: public LocalRepository
{
217 typedef BObjectList
<BSolverPackage
> PackageList
;
220 InstalledRepository(const char* name
,
221 BPackageInstallationLocation location
,
224 BPackageInstallationLocation
Location() const
225 { return fLocation
; }
226 const char* InitialName() const
227 { return fInitialName
; }
228 int32
InitialPriority() const
229 { return fInitialPriority
; }
231 virtual void GetPackagePath(BSolverPackage
* package
,
234 void DisablePackage(BSolverPackage
* package
);
235 // throws, if already disabled
236 bool EnablePackage(BSolverPackage
* package
);
237 // returns whether it was disabled
239 PackageList
& PackagesToActivate()
240 { return fPackagesToActivate
; }
241 PackageList
& PackagesToDeactivate()
242 { return fPackagesToDeactivate
; }
244 bool HasChanges() const;
248 PackageList fDisabledPackages
;
249 PackageList fPackagesToActivate
;
250 PackageList fPackagesToDeactivate
;
251 const char* fInitialName
;
252 BPackageInstallationLocation fLocation
;
253 int32 fInitialPriority
;
257 class BPackageManager::Transaction
{
259 Transaction(InstalledRepository
& repository
);
262 InstalledRepository
& Repository()
263 { return fRepository
; }
264 BActivationTransaction
& ActivationTransaction()
265 { return fTransaction
; }
266 BDirectory
& TransactionDirectory()
267 { return fTransactionDirectory
; }
270 InstalledRepository
& fRepository
;
271 BActivationTransaction fTransaction
;
272 BDirectory fTransactionDirectory
;
276 class BPackageManager::InstallationInterface
{
278 virtual ~InstallationInterface();
280 virtual void InitInstalledRepository(
281 InstalledRepository
& repository
) = 0;
282 virtual void ResultComputed(InstalledRepository
& repository
);
284 virtual status_t
PrepareTransaction(Transaction
& transaction
)
286 virtual status_t
CommitTransaction(Transaction
& transaction
,
287 BCommitTransactionResult
& _result
) = 0;
291 class BPackageManager::ClientInstallationInterface
292 : public InstallationInterface
{
294 ClientInstallationInterface();
295 virtual ~ClientInstallationInterface();
297 virtual void InitInstalledRepository(
298 InstalledRepository
& repository
);
300 virtual status_t
PrepareTransaction(Transaction
& transaction
);
301 virtual status_t
CommitTransaction(Transaction
& transaction
,
302 BCommitTransactionResult
& _result
);
305 BDaemonClient fDaemonClient
;
309 class BPackageManager::UserInteractionHandler
{
311 virtual ~UserInteractionHandler();
313 virtual void HandleProblems();
314 virtual void ConfirmChanges(bool fromMostSpecific
);
316 virtual void Warn(status_t error
, const char* format
, ...);
318 virtual void ProgressPackageDownloadStarted(
319 const char* packageName
);
320 virtual void ProgressPackageDownloadActive(
321 const char* packageName
,
322 float completionPercentage
,
323 off_t bytes
, off_t totalBytes
);
324 virtual void ProgressPackageDownloadComplete(
325 const char* packageName
);
326 virtual void ProgressPackageChecksumStarted(
328 virtual void ProgressPackageChecksumComplete(
331 virtual void ProgressStartApplyingChanges(
332 InstalledRepository
& repository
);
333 virtual void ProgressTransactionCommitted(
334 InstalledRepository
& repository
,
335 const BCommitTransactionResult
& result
);
336 virtual void ProgressApplyingChangesDone(
337 InstalledRepository
& repository
);
341 } // namespace BPrivate
343 } // namespace BManager
345 } // namespace BPackageKit
348 #endif // _PACKAGE__MANAGER__PRIVATE__PACKAGE_MANAGER_H_