1 #include "NodeMonitorHandler.h"
4 * static util functions for the super lazy
9 NodeMonitorHandler::make_entry_ref(dev_t device
, ino_t directory
,
14 ref
->directory
= directory
;
15 return ref
->set_name(name
);
20 NodeMonitorHandler::make_node_ref(dev_t device
, ino_t node
, node_ref
* ref
)
28 * public functions: constructor, destructor, MessageReceived
31 NodeMonitorHandler::NodeMonitorHandler(const char * name
)
38 NodeMonitorHandler::~NodeMonitorHandler()
45 NodeMonitorHandler::MessageReceived(BMessage
* msg
)
47 status_t status
= B_MESSAGE_NOT_UNDERSTOOD
;
48 if (msg
->what
== B_NODE_MONITOR
) {
50 if (msg
->FindInt32("opcode", &opcode
) == B_OK
) {
53 status
= HandleEntryCreated(msg
);
56 status
= HandleEntryRemoved(msg
);
59 status
= HandleEntryMoved(msg
);
62 status
= HandleStatChanged(msg
);
65 status
= HandleAttrChanged(msg
);
67 case B_DEVICE_MOUNTED
:
68 status
= HandleDeviceMounted(msg
);
70 case B_DEVICE_UNMOUNTED
:
71 status
= HandleDeviceUnmounted(msg
);
78 if (status
== B_MESSAGE_NOT_UNDERSTOOD
) {
79 inherited::MessageReceived(msg
);
84 * default virtual functions do nothing
88 NodeMonitorHandler::EntryCreated(const char *name
, ino_t directory
,
89 dev_t device
, ino_t node
)
96 NodeMonitorHandler::EntryRemoved(const char *name
, ino_t directory
,
97 dev_t device
, ino_t node
)
104 NodeMonitorHandler::EntryMoved(const char *name
, const char *fromName
,
105 ino_t fromDirectory
, ino_t toDirectory
, dev_t device
,ino_t node
,
113 NodeMonitorHandler::StatChanged(ino_t node
, dev_t device
, int32 statFields
)
120 NodeMonitorHandler::AttrChanged(ino_t node
, dev_t device
)
127 NodeMonitorHandler::DeviceMounted(dev_t new_device
, dev_t device
,
135 NodeMonitorHandler::DeviceUnmounted(dev_t new_device
)
142 * private functions to rip apart the corresponding BMessage
146 NodeMonitorHandler::HandleEntryCreated(BMessage
* msg
)
152 if ((msg
->FindString("name", &name
) != B_OK
) ||
153 (msg
->FindInt64("directory", &directory
) != B_OK
) ||
154 (msg
->FindInt32("device", &device
) != B_OK
) ||
155 (msg
->FindInt64("node", &node
) != B_OK
)) {
156 return B_MESSAGE_NOT_UNDERSTOOD
;
158 EntryCreated(name
, directory
, device
, node
);
164 NodeMonitorHandler::HandleEntryRemoved(BMessage
* msg
)
170 if ((msg
->FindString("name", &name
) != B_OK
) ||
171 (msg
->FindInt64("directory", &directory
) != B_OK
) ||
172 (msg
->FindInt32("device", &device
) != B_OK
) ||
173 (msg
->FindInt64("node", &node
) != B_OK
)) {
174 return B_MESSAGE_NOT_UNDERSTOOD
;
176 EntryRemoved(name
, directory
, device
, node
);
182 NodeMonitorHandler::HandleEntryMoved(BMessage
* msg
)
185 const char *fromName
;
191 if ((msg
->FindString("name", &name
) != B_OK
) ||
192 (msg
->FindString("from name", &fromName
) != B_OK
) ||
193 (msg
->FindInt64("from directory", &fromDirectory
) != B_OK
) ||
194 (msg
->FindInt64("to directory", &toDirectory
) != B_OK
) ||
195 (msg
->FindInt32("device", &device
) != B_OK
) ||
196 (msg
->FindInt32("node device", &deviceNode
) != B_OK
) ||
197 (msg
->FindInt64("node", &node
) != B_OK
)) {
198 return B_MESSAGE_NOT_UNDERSTOOD
;
200 EntryMoved(name
, fromName
, fromDirectory
, toDirectory
, device
, node
,
207 NodeMonitorHandler::HandleStatChanged(BMessage
* msg
)
212 if ((msg
->FindInt64("node", &node
) != B_OK
) ||
213 (msg
->FindInt32("device", &device
) != B_OK
) ||
214 (msg
->FindInt32("fields", &statFields
) != B_OK
)) {
215 return B_MESSAGE_NOT_UNDERSTOOD
;
217 StatChanged(node
, device
, statFields
);
223 NodeMonitorHandler::HandleAttrChanged(BMessage
* msg
)
227 if ((msg
->FindInt64("node", &node
) != B_OK
) ||
228 (msg
->FindInt32("device", &device
) != B_OK
)) {
229 return B_MESSAGE_NOT_UNDERSTOOD
;
231 AttrChanged(node
, device
);
237 NodeMonitorHandler::HandleDeviceMounted(BMessage
* msg
)
242 if ((msg
->FindInt32("new device", &new_device
) != B_OK
) ||
243 (msg
->FindInt32("device", &device
) != B_OK
) ||
244 (msg
->FindInt64("directory", &directory
) != B_OK
)) {
245 return B_MESSAGE_NOT_UNDERSTOOD
;
247 DeviceMounted(new_device
, device
, directory
);
253 NodeMonitorHandler::HandleDeviceUnmounted(BMessage
* msg
)
256 if (msg
->FindInt32("new device", &new_device
) != B_OK
) {
257 return B_MESSAGE_NOT_UNDERSTOOD
;
259 DeviceUnmounted(new_device
);