xref: /haiku/src/system/boot/loader/package_support.h (revision c237c4ce593ee823d9867fd997e51e4c447f5623)
1 /*
2  * Copyright 2014, Ingo Weinhold, ingo_weinhold@gmx.de.
3  * Distributed under the terms of the MIT License.
4  */
5 #ifndef PACKAGE_SUPPORT_H
6 #define PACKAGE_SUPPORT_H
7 
8 
9 #include <dirent.h>
10 
11 #include <Referenceable.h>
12 #include <util/DoublyLinkedList.h>
13 
14 
15 class Directory;
16 
17 
18 class PackageVolumeState : public DoublyLinkedListLinkImpl<PackageVolumeState> {
19 public:
20 								PackageVolumeState();
21 								~PackageVolumeState();
22 
23 			status_t			SetTo(const char* stateName);
24 			void				Unset();
25 
26 			const char*			Name() const
27 									{ return fName; }
28 			const char*			DisplayName() const;
29 
30 			const char*			SystemPackage() const
31 									{ return fSystemPackage; }
32 			status_t			SetSystemPackage(const char* package);
33 
34 			void				GetPackagePath(const char* name, char* path,
35 									size_t pathSize);
36 
37 	static	bool				IsNewer(const PackageVolumeState* a,
38 									const PackageVolumeState* b);
39 
40 private:
41 			char*				fName;
42 			char*				fDisplayName;
43 			char*				fSystemPackage;
44 };
45 
46 typedef DoublyLinkedList<PackageVolumeState> PackageVolumeStateList;
47 
48 
49 class PackageVolumeInfo : public BReferenceable {
50 public:
51 			typedef PackageVolumeStateList StateList;
52 
53 public:
54 								PackageVolumeInfo();
55 								~PackageVolumeInfo();
56 
57 			status_t			SetTo(Directory* baseDirectory,
58 									const char* packagesPath);
59 
60 			status_t			LoadOldStates();
61 
62 			const StateList&	States() const
63 									{ return fStates; }
64 
65 private:
66 			PackageVolumeState*	_AddState(const char* stateName);
67 			status_t			_InitState(Directory* packagesDirectory,
68 									DIR* dir, PackageVolumeState* state);
69 			status_t			_ParseActivatedPackagesFile(
70 									Directory* packagesDirectory,
71 									PackageVolumeState* state,
72 									char* packageName, size_t packageNameSize);
73 
74 private:
75 			StateList			fStates;
76 			DIR*				fPackagesDir;
77 };
78 
79 
80 #endif	// PACKAGE_SUPPORT_H
81