2007-01-26 15:11:33 +03:00
|
|
|
/*
|
|
|
|
* Copyright 2001-2007, Haiku.
|
|
|
|
* Distributed under the terms of the MIT License.
|
|
|
|
*
|
|
|
|
* Authors:
|
|
|
|
* Erik Jaesler (erik@cgsoftware.com)
|
|
|
|
*/
|
2002-07-15 20:04:06 +04:00
|
|
|
#ifndef LOOPERLIST_H
|
|
|
|
#define LOOPERLIST_H
|
|
|
|
|
|
|
|
|
|
|
|
#include <Locker.h>
|
|
|
|
#include <OS.h>
|
|
|
|
#include <SupportDefs.h>
|
|
|
|
|
2007-01-26 15:11:33 +03:00
|
|
|
#include <vector>
|
2002-07-15 20:04:06 +04:00
|
|
|
|
2007-10-16 00:13:55 +04:00
|
|
|
class BList;
|
2002-07-15 20:04:06 +04:00
|
|
|
class BLooper;
|
|
|
|
|
2007-01-26 15:11:33 +03:00
|
|
|
|
2002-07-15 20:04:06 +04:00
|
|
|
namespace BPrivate {
|
|
|
|
|
2007-01-26 15:11:33 +03:00
|
|
|
class BLooperList {
|
2002-07-15 20:04:06 +04:00
|
|
|
public:
|
|
|
|
BLooperList();
|
|
|
|
|
|
|
|
bool Lock();
|
|
|
|
void Unlock();
|
|
|
|
bool IsLocked();
|
|
|
|
|
|
|
|
void AddLooper(BLooper* l);
|
|
|
|
bool IsLooperValid(const BLooper* l);
|
|
|
|
bool RemoveLooper(BLooper* l);
|
|
|
|
void GetLooperList(BList* list);
|
2002-08-04 03:18:14 +04:00
|
|
|
int32 CountLoopers();
|
|
|
|
BLooper* LooperAt(int32 index);
|
2002-07-15 20:04:06 +04:00
|
|
|
BLooper* LooperForThread(thread_id tid);
|
|
|
|
BLooper* LooperForName(const char* name);
|
|
|
|
BLooper* LooperForPort(port_id port);
|
|
|
|
|
2007-01-26 15:11:33 +03:00
|
|
|
private:
|
|
|
|
struct LooperData {
|
2002-07-15 20:04:06 +04:00
|
|
|
LooperData();
|
2007-01-26 15:11:33 +03:00
|
|
|
LooperData(BLooper* looper);
|
2002-07-15 20:04:06 +04:00
|
|
|
LooperData(const LooperData& rhs);
|
|
|
|
LooperData& operator=(const LooperData& rhs);
|
|
|
|
|
|
|
|
BLooper* looper;
|
|
|
|
};
|
|
|
|
|
2007-01-26 15:11:33 +03:00
|
|
|
static bool EmptySlotPred(LooperData& Data);
|
|
|
|
struct FindLooperPred {
|
2002-07-15 20:04:06 +04:00
|
|
|
FindLooperPred(const BLooper* loop) : looper(loop) {;}
|
|
|
|
bool operator()(LooperData& Data);
|
|
|
|
const BLooper* looper;
|
|
|
|
};
|
2007-01-26 15:11:33 +03:00
|
|
|
struct FindThreadPred {
|
2002-07-15 20:04:06 +04:00
|
|
|
FindThreadPred(thread_id tid) : thread(tid) {;}
|
|
|
|
bool operator()(LooperData& Data);
|
|
|
|
thread_id thread;
|
|
|
|
};
|
2007-01-26 15:11:33 +03:00
|
|
|
struct FindNamePred {
|
2002-07-15 20:04:06 +04:00
|
|
|
FindNamePred(const char* n) : name(n) {;}
|
|
|
|
bool operator()(LooperData& Data);
|
|
|
|
const char* name;
|
|
|
|
};
|
2007-01-26 15:11:33 +03:00
|
|
|
struct FindPortPred {
|
2002-07-15 20:04:06 +04:00
|
|
|
FindPortPred(port_id pid) : port(pid) {;}
|
|
|
|
bool operator()(LooperData& Data);
|
|
|
|
port_id port;
|
|
|
|
};
|
|
|
|
|
|
|
|
void AssertLocked();
|
|
|
|
|
|
|
|
BLocker fLock;
|
|
|
|
std::vector<LooperData> fData;
|
|
|
|
};
|
|
|
|
|
2007-01-26 15:11:33 +03:00
|
|
|
extern BLooperList gLooperList;
|
2002-07-15 20:04:06 +04:00
|
|
|
|
2007-01-26 15:11:33 +03:00
|
|
|
} // namespace BPrivate
|
2002-07-15 20:04:06 +04:00
|
|
|
|
2007-01-26 15:11:33 +03:00
|
|
|
#endif // LOOPERLIST_H
|