xref: /haiku/src/servers/package/Root.h (revision 8e8f7748d39f8407894a5ab79f7b4f93bc4f4652)
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 			status_t			RegisterVolume(Volume* volume);
41 			void				UnregisterVolume(Volume* volume);
42 									// deletes the volume (eventually)
43 
44 			Volume*				FindVolume(dev_t deviceID) const;
45 			Volume*				GetVolume(
46 									BPackageInstallationLocation location);
47 
48 			void				HandleRequest(BMessage* message);
49 
50 private:
51 	// Volume::Listener
52 	virtual	void				VolumeNodeMonitorEventOccurred(Volume* volume);
53 
54 protected:
55 	virtual	void				LastReferenceReleased();
56 
57 private:
58 			struct AbstractVolumeJob;
59 			struct VolumeJob;
60 			struct ProcessNodeMonitorEventsJob;
61 			struct CommitTransactionJob;
62 			struct VolumeJobFilter;
63 
64 			friend struct CommitTransactionJob;
65 
66 private:
67 			Volume**			_GetVolume(PackageFSMountType mountType);
68 			Volume*				_NextVolumeFor(Volume* volume);
69 
70 			void				_InitPackages(Volume* volume);
71 			void				_DeleteVolume(Volume* volume);
72 			void				_ProcessNodeMonitorEvents(Volume* volume);
73 			void				_CommitTransaction(Volume* volume,
74 									BMessage* message);
75 
76 			status_t			_QueueJob(Job* job);
77 
78 	static	status_t			_JobRunnerEntry(void* data);
79 			status_t			_JobRunner();
80 
81 	static	void				_ShowError(const char* errorMessage);
82 
83 private:
84 	mutable	BLocker				fLock;
85 			node_ref			fNodeRef;
86 			bool				fIsSystemRoot;
87 			BString				fPath;
88 			Volume*				fSystemVolume;
89 			Volume*				fHomeVolume;
90 			JobQueue			fJobQueue;
91 			thread_id			fJobRunner;
92 };
93 
94 
95 #endif	// ROOT_H
96