1 /* 2 * Copyright 2010, Axel Dörfler, axeld@pinc-software.de. 3 * Distributed under the terms of the MIT License. 4 */ 5 6 7 #include <stdio.h> 8 9 #include <Application.h> 10 #include <Entry.h> 11 #include <NodeMonitor.h> 12 13 14 class Application : public BApplication { 15 public: 16 Application(); 17 virtual ~Application(); 18 19 protected: 20 virtual void ArgvReceived(int32 argCount, char** args); 21 virtual void ReadyToRun(); 22 virtual void MessageReceived(BMessage* message); 23 24 private: 25 bool fWatchingNode; 26 }; 27 28 29 Application::Application() 30 : 31 BApplication("application/x-vnd.test-node-monitor-test"), 32 fWatchingNode(false) 33 { 34 } 35 36 37 Application::~Application() 38 { 39 } 40 41 42 void 43 Application::ArgvReceived(int32 argCount, char** args) 44 { 45 uint32 flags = B_WATCH_STAT; 46 47 for (int32 i = 0; i < argCount; i++) { 48 BEntry entry(args[i]); 49 if (!entry.Exists()) { 50 fprintf(stderr, "Entry does not exist: %s\n", args[i]); 51 continue; 52 } 53 54 node_ref nodeRef; 55 entry.GetNodeRef(&nodeRef); 56 if (watch_node(&nodeRef, flags, this) == B_OK) 57 fWatchingNode = true; 58 } 59 } 60 61 62 void 63 Application::ReadyToRun() 64 { 65 if (!fWatchingNode) 66 Quit(); 67 } 68 69 70 void 71 Application::MessageReceived(BMessage* message) 72 { 73 switch (message->what) { 74 case B_NODE_MONITOR: 75 message->PrintToStream(); 76 break; 77 78 default: 79 BApplication::MessageReceived(message); 80 } 81 } 82 83 84 // #pragma mark - 85 86 87 int 88 main(int argc, char** argv) 89 { 90 Application app; 91 app.Run(); 92 93 return 0; 94 } 95