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