xref: /haiku/src/servers/package/Root.h (revision 220d04022750f40f8bac8f01fa551211e28d04f2)
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 ROOT_H
9 #define ROOT_H
10 
11 
12 #include <Locker.h>
13 #include <Node.h>
14 #include <ObjectList.h>
15 #include <OS.h>
16 #include <package/PackageDefs.h>
17 #include <String.h>
18 
19 #include <Referenceable.h>
20 
21 #include <package/packagefs.h>
22 
23 #include "JobQueue.h"
24 #include "Volume.h"
25 
26 
27 class Root : public BReferenceable, private Volume::Listener {
28 public:
29 								Root();
30 	virtual						~Root();
31 
32 			status_t			Init(const node_ref& nodeRef,
33 									bool isSystemRoot);
34 
35 			const node_ref&		NodeRef() const		{ return fNodeRef; }
36 			dev_t				DeviceID() const	{ return fNodeRef.device; }
37 			ino_t				NodeID() const		{ return fNodeRef.node; }
38 			const BString&		Path() const		{ return fPath; }
39 
40 			bool				IsSystemRoot() const
41 									{ return fIsSystemRoot; }
42 
43 			status_t			RegisterVolume(Volume* volume);
44 			void				UnregisterVolume(Volume* volume);
45 									// deletes the volume (eventually)
46 
47 			Volume*				FindVolume(dev_t deviceID) const;
48 			Volume*				GetVolume(
49 									BPackageInstallationLocation location);
50 
51 			void				HandleRequest(BMessage* message);
52 
53 private:
54 	// Volume::Listener
55 	virtual	void				VolumeNodeMonitorEventOccurred(Volume* volume);
56 
57 protected:
58 	virtual	void				LastReferenceReleased();
59 
60 private:
61 			struct AbstractVolumeJob;
62 			struct VolumeJob;
63 			struct ProcessNodeMonitorEventsJob;
64 			struct CommitTransactionJob;
65 			struct VolumeJobFilter;
66 
67 			friend struct CommitTransactionJob;
68 
69 private:
70 			Volume**			_GetVolume(PackageFSMountType mountType);
71 			Volume*				_NextVolumeFor(Volume* volume);
72 
73 			void				_InitPackages(Volume* volume);
74 			void				_DeleteVolume(Volume* volume);
75 			void				_ProcessNodeMonitorEvents(Volume* volume);
76 			void				_CommitTransaction(Volume* volume,
77 									BMessage* message);
78 
79 			status_t			_QueueJob(Job* job);
80 
81 	static	status_t			_JobRunnerEntry(void* data);
82 			status_t			_JobRunner();
83 
84 	static	void				_ShowError(const char* errorMessage);
85 
86 private:
87 	mutable	BLocker				fLock;
88 			node_ref			fNodeRef;
89 			bool				fIsSystemRoot;
90 			BString				fPath;
91 			Volume*				fSystemVolume;
92 			Volume*				fHomeVolume;
93 			JobQueue			fJobQueue;
94 			thread_id			fJobRunner;
95 };
96 
97 
98 #endif	// ROOT_H
99