xref: /haiku/src/bin/pkgman/PackageManager.h (revision 225b6382637a7346d5378ee45a6581b4e2616055)
1 /*
2  * Copyright 2013, Haiku, Inc. All Rights Reserved.
3  * Distributed under the terms of the MIT License.
4  *
5  * Authors:
6  *		Ingo Weinhold <ingo_weinhold@gmx.de>
7  */
8 #ifndef PACKAGE_MANAGER_H
9 #define PACKAGE_MANAGER_H
10 
11 
12 #include <ObjectList.h>
13 #include <package/Context.h>
14 #include <package/PackageDefs.h>
15 #include <package/PackageRoster.h>
16 #include <package/RepositoryConfig.h>
17 #include <package/solver/Solver.h>
18 #include <package/solver/SolverRepository.h>
19 
20 #include "DecisionProvider.h"
21 #include "JobStateListener.h"
22 
23 
24 using namespace BPackageKit;
25 
26 
27 class PackageManager {
28 public:
29 			struct Repository;
30 			typedef BObjectList<Repository> RepositoryList;
31 
32 public:
33 								PackageManager(
34 									BPackageInstallationLocation location,
35 									bool addInstalledRepositories,
36 									bool addOtherRepositories);
37 								~PackageManager();
38 
39 			BSolver*			Solver() const
40 									{ return fSolver; }
41 
42 			const BSolverRepository* SystemRepository() const
43 									{ return &fSystemRepository; }
44 			const BSolverRepository* CommonRepository() const
45 									{ return &fCommonRepository; }
46 			const BSolverRepository* HomeRepository() const
47 									{ return &fHomeRepository; }
48 			const BObjectList<BSolverRepository>& InstalledRepositories() const
49 									{ return fInstalledRepositories; }
50 			const RepositoryList& OtherRepositories() const
51 									{ return fOtherRepositories; }
52 
53 			void				Install(const char* const* packages,
54 									int packageCount);
55 			void				Uninstall(const char* const* packages,
56 									int packageCount);
57 			void				Update(const char* const* packages,
58 									int packageCount);
59 
60 private:
61 			typedef BObjectList<BSolverPackage> PackageList;
62 
63 private:
64 			void				_HandleProblems();
65 			void				_AnalyzeResult();
66 			void				_PrintResult();
67 			void				_ApplyPackageChanges();
68 
69 private:
70 			BPackageInstallationLocation fLocation;
71 			BSolver*			fSolver;
72 			BSolverRepository	fSystemRepository;
73 			BSolverRepository	fCommonRepository;
74 			BSolverRepository	fHomeRepository;
75 			BObjectList<BSolverRepository> fInstalledRepositories;
76 			RepositoryList		fOtherRepositories;
77 			DecisionProvider	fDecisionProvider;
78 			JobStateListener	fJobStateListener;
79 			BContext			fContext;
80 			PackageList			fPackagesToActivate;
81 			PackageList			fPackagesToDeactivate;
82 };
83 
84 
85 struct PackageManager::Repository : public BSolverRepository {
86 								Repository();
87 
88 			status_t			Init(BPackageRoster& roster, BContext& context,
89 									const char* name);
90 
91 			const BRepositoryConfig& Config() const;
92 
93 private:
94 			BRepositoryConfig	fConfig;
95 };
96 
97 
98 #endif	// PACKAGE_MANAGER_H
99