xref: /haiku/src/tests/kits/app/bmessenger/ForwardMessageTest.cpp (revision bb2242b4225f5ed14b2ad25748762092a8d0d827)
1 #include <stdio.h>
2 #include <Application.h>
3 #include <Looper.h>
4 
5 class MyLooper :  public BLooper
6 {
7 public:
MyLooper(BLooper * looper)8 	MyLooper(BLooper *looper) : BLooper("test") {
9 		printf("Looper created\n");
10 		fLooper = looper;
11 	};
12 
MessageReceived(BMessage * msg)13 	virtual void MessageReceived(BMessage *msg) {
14 	printf("MessageReceived : %.4s\n", (char*)&msg->what);
15 	switch (msg->what) {
16 	case 'toto':
17 		if (fLooper) {
18 			BMessenger(fLooper).SendMessage(msg);
19 			break;
20 		}
21 		msg->SendReply('couc');
22 		break;
23 	default:
24 		BLooper::MessageReceived(msg);
25 	}
26 	};
27 
28 	BLooper *fLooper;
29 };
30 
31 class App : public BApplication
32 {
33 public:
App()34 	App() : BApplication("application/test") {
35 
36 	};
ReadyToRun()37 	virtual void ReadyToRun() {
38 		MyLooper looper2(NULL);
39 		looper2.Run();
40 		MyLooper looper1(&looper2);
41 		looper1.Run();
42 		printf("loopers run\n");
43 		BMessage reply;
44 		BMessenger(&looper1).SendMessage('toto', &reply);
45 		printf("message sent and replied\ncheck there is only a 'couc' what in  the reply\n");
46 		reply.PrintToStream();
47 		exit(0);
48 	};
49 
50 };
51 
main()52 int main()
53 {
54 	App().Run();
55 }
56