Added support for multiple BTestHandlers in a BTestApp.

git-svn-id: file:///srv/svn/repos/haiku/trunk/current@2212 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Ingo Weinhold 2002-12-09 12:55:09 +00:00
parent d0d716f9c8
commit b229fec87b

View File

@ -1,5 +1,7 @@
// TestApp.cpp // TestApp.cpp
#include <Autolock.h>
#include <TestApp.h> #include <TestApp.h>
// TestHandler // TestHandler
@ -29,12 +31,20 @@ BTestHandler::Queue()
BTestApp::BTestApp(const char *signature) BTestApp::BTestApp(const char *signature)
: BApplication(signature), : BApplication(signature),
fAppThread(B_ERROR), fAppThread(B_ERROR),
fHandler() fHandlers()
{ {
AddHandler(&fHandler); CreateTestHandler();
Unlock(); Unlock();
} }
// destructor
BTestApp::~BTestApp()
{
int32 count = fHandlers.CountItems();
for (int32 i = count - 1; i >= 0; i--)
DeleteTestHandler(TestHandlerAt(i));
}
// Init // Init
status_t status_t
BTestApp::Init() BTestApp::Init()
@ -69,11 +79,48 @@ BTestApp::ReadyToRun()
{ {
} }
// CreateTestHandler
BTestHandler *
BTestApp::CreateTestHandler()
{
BTestHandler *handler = new BTestHandler;
Lock();
AddHandler(handler);
fHandlers.AddItem(handler);
Unlock();
return handler;
}
// DeleteTestHandler
bool
BTestApp::DeleteTestHandler(BTestHandler *handler)
{
bool result = false;
Lock();
result = fHandlers.RemoveItem(handler);
if (result)
RemoveHandler(handler);
Unlock();
if (result)
delete handler;
return result;
}
// Handler // Handler
BTestHandler & BTestHandler &
BTestApp::Handler() BTestApp::Handler()
{ {
return fHandler; // The returned handler must never passed to DeleteTestHandler() by the
// caller!
return *TestHandlerAt(0);
}
// TestHandlerAt
BTestHandler *
BTestApp::TestHandlerAt(int32 index)
{
BAutolock _lock(this);
return (BTestHandler*)fHandlers.ItemAt(index);
} }
// _AppThreadStart // _AppThreadStart