1 2 #include <stdio.h> 3 4 #include <Message.h> 5 #include <MessageQueue.h> 6 #include <String.h> 7 8 #include "WindowLayer.h" 9 10 #include "ClientLooper.h" 11 12 #define SLOW_DRAWING 0 13 14 // constructor 15 ClientLooper::ClientLooper(const char* name, WindowLayer* serverWindow) 16 : BLooper(""), 17 fServerWindow(serverWindow), 18 fViewCount(0) 19 { 20 BString clientName(name); 21 clientName << " client"; 22 SetName(clientName.String()); 23 } 24 25 // destructor 26 ClientLooper::~ClientLooper() 27 { 28 } 29 30 // MessageReceived 31 void 32 ClientLooper::MessageReceived(BMessage* message) 33 { 34 switch (message->what) { 35 case MSG_UPDATE: 36 37 fServerWindow->PostMessage(MSG_BEGIN_UPDATE); 38 39 for (int32 i = 0; i < fViewCount; i++) { 40 // the client is slow 41 snooze(20000L); 42 // send the command to redraw a view 43 BMessage command(MSG_DRAWING_COMMAND); 44 command.AddInt32("token", i); 45 fServerWindow->PostMessage(&command); 46 } 47 48 fServerWindow->PostMessage(MSG_END_UPDATE); 49 50 break; 51 case MSG_VIEWS_ADDED: { 52 int32 count; 53 if (message->FindInt32("count", &count) >= B_OK) { 54 fViewCount += count; 55 } 56 break; 57 } 58 case MSG_VIEWS_REMOVED: { 59 int32 count; 60 if (message->FindInt32("count", &count) >= B_OK) 61 fViewCount -= count; 62 break; 63 } 64 default: 65 BLooper::MessageReceived(message); 66 break; 67 } 68 } 69