libdebugger: Add initial version of network interface.
[haiku.git] / src / kits / storage / VolumeRoster.cpp
blob3149ab523f13862f183c3742f12283fc2bba676d
1 // ----------------------------------------------------------------------
2 // This software is part of the OpenBeOS distribution and is covered
3 // by the OpenBeOS license.
4 //
5 // File Name: VolumeRoster.cpp
6 //
7 // Description: BVolumeRoster class
8 // ----------------------------------------------------------------------
11 #include <errno.h>
12 #include <new>
14 #include <Bitmap.h>
15 #include <Directory.h>
16 #include <fs_info.h>
17 #include <Node.h>
18 #include <NodeMonitor.h>
19 #include <VolumeRoster.h>
22 static const char kBootVolumePath[] = "/boot";
24 using namespace std;
27 #ifdef USE_OPENBEOS_NAMESPACE
28 namespace OpenBeOS {
29 #endif
32 BVolumeRoster::BVolumeRoster()
33 : fCookie(0),
34 fTarget(NULL)
39 // Deletes the volume roster and frees all associated resources.
40 BVolumeRoster::~BVolumeRoster()
42 StopWatching();
46 // Fills out the passed in BVolume object with the next available volume.
47 status_t
48 BVolumeRoster::GetNextVolume(BVolume *volume)
50 // check parameter
51 status_t error = (volume ? B_OK : B_BAD_VALUE);
52 // get next device
53 dev_t device;
54 if (error == B_OK) {
55 device = next_dev(&fCookie);
56 if (device < 0)
57 error = device;
59 // init volume
60 if (error == B_OK)
61 error = volume->SetTo(device);
62 return error;
66 // Rewinds the list of available volumes back to the first item.
67 void
68 BVolumeRoster::Rewind()
70 fCookie = 0;
74 // Fills out the passed in BVolume object with the boot volume.
75 status_t
76 BVolumeRoster::GetBootVolume(BVolume *volume)
78 // check parameter
79 status_t error = (volume ? B_OK : B_BAD_VALUE);
80 // get device
81 dev_t device;
82 if (error == B_OK) {
83 device = dev_for_path(kBootVolumePath);
84 if (device < 0)
85 error = device;
87 // init volume
88 if (error == B_OK)
89 error = volume->SetTo(device);
90 return error;
94 // Starts watching the available volumes for changes.
95 status_t
96 BVolumeRoster::StartWatching(BMessenger messenger)
98 StopWatching();
99 status_t error = (messenger.IsValid() ? B_OK : B_ERROR);
100 // clone messenger
101 if (error == B_OK) {
102 fTarget = new(nothrow) BMessenger(messenger);
103 if (!fTarget)
104 error = B_NO_MEMORY;
106 // start watching
107 if (error == B_OK)
108 error = watch_node(NULL, B_WATCH_MOUNT, messenger);
109 // cleanup on failure
110 if (error != B_OK && fTarget) {
111 delete fTarget;
112 fTarget = NULL;
114 return error;
118 // Stops watching volumes initiated by StartWatching().
119 void
120 BVolumeRoster::StopWatching()
122 if (fTarget) {
123 stop_watching(*fTarget);
124 delete fTarget;
125 fTarget = NULL;
130 // Returns the messenger currently watching the volume list.
131 BMessenger
132 BVolumeRoster::Messenger() const
134 return (fTarget ? *fTarget : BMessenger());
138 // FBC
139 void BVolumeRoster::_SeveredVRoster1() {}
140 void BVolumeRoster::_SeveredVRoster2() {}
143 #ifdef USE_OPENBEOS_NAMESPACE
145 #endif