From 77d6501f22f00c977356763bce2e728ca6324529 Mon Sep 17 00:00:00 2001 From: Ingo Weinhold Date: Mon, 10 Feb 2003 00:24:51 +0000 Subject: [PATCH] Added notification tests. git-svn-id: file:///srv/svn/repos/haiku/trunk/current@2681 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- .../storage/disk_device/DiskDeviceTest.cpp | 123 +++++++++++++++++- 1 file changed, 119 insertions(+), 4 deletions(-) diff --git a/src/tests/kits/storage/disk_device/DiskDeviceTest.cpp b/src/tests/kits/storage/disk_device/DiskDeviceTest.cpp index b9ca1aa90f..0d45eb687e 100644 --- a/src/tests/kits/storage/disk_device/DiskDeviceTest.cpp +++ b/src/tests/kits/storage/disk_device/DiskDeviceTest.cpp @@ -3,16 +3,23 @@ // by the OpenBeOS license. //--------------------------------------------------------------------- +#include +#include + +#include #include #include +#include +#include #include +#include #include #include -#include // needed only until we can link against -#include // libopenbeos -#include // -#include // +// needed only until we can link against libopenbeos +#include +#include +#include // Hack to make BDiskDeviceRoster communicate with our registrar. @@ -63,7 +70,9 @@ init_roster() } } +//---------------------------------------------------------------------------- +// DumpVisitor class DumpVisitor : public BDiskDeviceVisitor { public: virtual bool Visit(BDiskDevice *device) @@ -108,13 +117,119 @@ public: } }; +// TestApp +class TestApp : public BApplication { +public: + TestApp(const char *signature) + : BApplication(signature) + { + } + + virtual void MessageReceived(BMessage *message) + { +printf("TestApp::MessageReceived(%.4s)\n", (char*)&message->what); + switch (message->what) { + case B_DEVICE_UPDATE: + { + uint32 event; + if (message->FindInt32("event", (int32*)&event) == B_OK) { + switch (event) { + case B_DEVICE_MOUNT_POINT_MOVED: + MountPointMoved(message); + break; + case B_DEVICE_PARTITION_MOUNTED: + PartitionMounted(message); + break; + case B_DEVICE_PARTITION_UNMOUNTED: + PartitionUnmounted(message); + break; + case B_DEVICE_PARTITION_CHANGED: + case B_DEVICE_PARTITION_ADDED: + case B_DEVICE_PARTITION_REMOVED: + case B_DEVICE_MEDIA_CHANGED: + case B_DEVICE_ADDED: + case B_DEVICE_REMOVED: + printf("unhandled event\n"); + message->PrintToStream(); + break; + } + } + break; + } + default: + BApplication::MessageReceived(message); + break; + } + } + + + void MountPointMoved(BMessage *message) + { + printf("TestApp::MountPointMoved()\n"); + PrintPartitionInfo(message); + entry_ref oldRoot, newRoot; + BPath oldPath, newPath; + if (message->FindRef("old_directory", &oldRoot) == B_OK + && message->FindRef("new_directory", &newRoot) == B_OK + && oldPath.SetTo(&oldRoot) == B_OK + && newPath.SetTo(&newRoot) == B_OK) { + printf("old mount point: `%s'\n", oldPath.Path()); + printf("new mount point: `%s'\n", newPath.Path()); + } + + } + + void PartitionMounted(BMessage *message) + { + printf("TestApp::PartitionMounted()\n"); + PrintPartitionInfo(message); + } + + void PartitionUnmounted(BMessage *message) + { + printf("TestApp::PartitionUnmounted()\n"); + PrintPartitionInfo(message); + } + + void PrintPartitionInfo(BMessage *message) + { + int32 deviceID; + int32 sessionID; + int32 partitionID; + if (message->FindInt32("device_id", &deviceID) == B_OK + && message->FindInt32("session_id", &sessionID) == B_OK + && message->FindInt32("partition_id", &partitionID) == B_OK) { + BDiskDeviceRoster roster; + BDiskDevice device; + BPartition *partition; + if (roster.GetPartitionWithID(partitionID, &device, &partition) + == B_OK) { + DumpVisitor().Visit(partition); + } + } + } + +}; + // main int main() { init_roster(); + // ----------- + TestApp app("application/x-vnd.obos-disk-device-test"); BDiskDeviceRoster roster; DumpVisitor visitor; roster.Traverse(&visitor); + status_t error = B_OK; + error = roster.StartWatching(BMessenger(&app)); + if (error != B_OK) + printf("start watching failed: %s\n", strerror(error)); + if (error == B_OK) + app.Run(); + error = roster.StopWatching(BMessenger(&app)); + if (error != B_OK) + printf("stop watching failed: %s\n", strerror(error)); + return 0; }