1 // SMReplyTarget.cpp 2 3 #include <TestUtils.h> 4 #include <cppunit/TestAssert.h> 5 6 #include "SMReplyTarget.h" 7 #include "SMLooper.h" 8 9 // constructor 10 SMReplyTarget::SMReplyTarget(bool preferred) 11 : fHandler(NULL), 12 fLooper(NULL) 13 { 14 // create looper and handler 15 fLooper = new SMLooper; 16 fLooper->Run(); 17 if (!preferred) { 18 fHandler = new SMHandler; 19 CHK(fLooper->Lock()); 20 fLooper->AddHandler(fHandler); 21 fLooper->Unlock(); 22 } 23 } 24 25 // destructor 26 SMReplyTarget::~SMReplyTarget() 27 { 28 if (fLooper) { 29 fLooper->Lock(); 30 if (fHandler) { 31 fLooper->RemoveHandler(fHandler); 32 delete fHandler; 33 } 34 fLooper->Quit(); 35 } 36 } 37 38 // Handler 39 BHandler * 40 SMReplyTarget::Handler() 41 { 42 return fHandler; 43 } 44 45 // Messenger 46 BMessenger 47 SMReplyTarget::Messenger() 48 { 49 return BMessenger(fHandler, fLooper); 50 } 51 52 // ReplySuccess 53 bool 54 SMReplyTarget::ReplySuccess() 55 { 56 return fLooper->ReplySuccess(); 57 } 58 59 60