xref: /haiku/src/servers/package/Root.h (revision 04a0e9c7b68cbe3a43d38e2bca8e860fd80936fb)
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 VolumeJob;
59 			struct RequestJob;
60 
61 			friend struct RequestJob;
62 
63 private:
64 			Volume**			_GetVolume(PackageFSMountType mountType);
65 			Volume*				_NextVolumeFor(Volume* volume);
66 
67 			void				_InitPackages(Volume* volume);
68 			void				_DeleteVolume(Volume* volume);
69 			void				_ProcessNodeMonitorEvents(Volume* volume);
70 			void				_HandleRequest(BMessage* message);
71 
72 			status_t			_QueueJob(Job* job);
73 
74 	static	status_t			_JobRunnerEntry(void* data);
75 			status_t			_JobRunner();
76 
77 	static	void				_ShowError(const char* errorMessage);
78 
79 private:
80 	mutable	BLocker				fLock;
81 			node_ref			fNodeRef;
82 			bool				fIsSystemRoot;
83 			BString				fPath;
84 			Volume*				fSystemVolume;
85 			Volume*				fHomeVolume;
86 			JobQueue			fJobQueue;
87 			thread_id			fJobRunner;
88 };
89 
90 
91 #endif	// ROOT_H
92