Ticket #5103: main.cpp

File main.cpp, 895 bytes (added by matjako, 10 years ago)
Line 
1#include <Application.h>
2#include <stdio.h>
3#include <Entry.h>
4#include <Node.h>
5#include <NodeMonitor.h>
6
7/**
8 Tests Node Monitor and ArgvReceived functionality in Haiku.
9*/
10class TestApp: public BApplication
11{
12 public:
13
14 TestApp():
15 BApplication("application/x-vnd.test-app1")
16 {
17 }
18
19 ~TestApp() {
20 stop_watching(this);
21 }
22
23 virtual void ArgvReceived(int argc, char** argv)
24 {
25 if (argc > 1) {
26 printf("watching '%s'\n", argv[1]);
27 BNode node(argv[1]);
28 node_ref noderef;
29 node.GetNodeRef(&noderef);
30 watch_node(&noderef, B_WATCH_ALL, this);
31 }
32 }
33
34 virtual void MessageReceived(BMessage *message)
35 {
36 switch (message->what) {
37 case B_NODE_MONITOR:
38 message->PrintToStream();
39 break;
40 default:
41 BApplication::MessageReceived(message);
42 }
43 }
44};
45
46int main(int argc, char **argv)
47{
48 TestApp app;
49 // a workaround
50 app.ArgvReceived(argc, argv);
51 app.Run();
52}