Cleanup. Added BTokenSpace::GetList(), though it's probably not needed after all
(we can still remove it later if needed). Added B_SERVER_TOKEN type. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@13451 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -1,31 +1,32 @@
|
|||||||
//------------------------------------------------------------------------------
|
/*
|
||||||
// TokenSpace.h
|
* Copyright 2001-2005, Haiku.
|
||||||
//
|
* Distributed under the terms of the MIT License.
|
||||||
//------------------------------------------------------------------------------
|
*
|
||||||
|
* Authors:
|
||||||
|
* Erik Jaesler ([email protected])
|
||||||
|
* Axel Dörfler, [email protected]
|
||||||
|
*/
|
||||||
|
#ifndef _TOKEN_SPACE_H
|
||||||
|
#define _TOKEN_SPACE_H
|
||||||
|
|
||||||
#ifndef TOKENSPACE_H
|
|
||||||
#define TOKENSPACE_H
|
|
||||||
|
|
||||||
// Standard Includes -----------------------------------------------------------
|
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <stack>
|
#include <stack>
|
||||||
|
|
||||||
// System Includes -------------------------------------------------------------
|
|
||||||
#include <BeBuild.h>
|
#include <BeBuild.h>
|
||||||
#include <Locker.h>
|
#include <Locker.h>
|
||||||
#include <SupportDefs.h>
|
#include <SupportDefs.h>
|
||||||
|
|
||||||
// Project Includes ------------------------------------------------------------
|
|
||||||
|
|
||||||
// Local Includes --------------------------------------------------------------
|
// token types as specified in targets
|
||||||
|
|
||||||
// Local Defines ---------------------------------------------------------------
|
|
||||||
#define B_PREFERRED_TOKEN -2 /* A little bird told me about this one */
|
#define B_PREFERRED_TOKEN -2 /* A little bird told me about this one */
|
||||||
#define B_NULL_TOKEN -1
|
#define B_NULL_TOKEN -1
|
||||||
#define B_ANY_TOKEN 0
|
#define B_ANY_TOKEN 0
|
||||||
#define B_HANDLER_TOKEN 1
|
|
||||||
|
|
||||||
// Globals ---------------------------------------------------------------------
|
// token types in the token list
|
||||||
|
#define B_HANDLER_TOKEN 1
|
||||||
|
#define B_SERVER_TOKEN 2
|
||||||
|
|
||||||
|
|
||||||
namespace BPrivate {
|
namespace BPrivate {
|
||||||
|
|
||||||
@@ -33,19 +34,20 @@ typedef void (*new_token_callback)(int16, void*);
|
|||||||
typedef void (*remove_token_callback)(int16, void*);
|
typedef void (*remove_token_callback)(int16, void*);
|
||||||
typedef bool (*get_token_callback)(int16, void*);
|
typedef bool (*get_token_callback)(int16, void*);
|
||||||
|
|
||||||
class BTokenSpace
|
class BTokenSpace : public BLocker {
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
BTokenSpace();
|
BTokenSpace();
|
||||||
~BTokenSpace();
|
~BTokenSpace();
|
||||||
|
|
||||||
int32 NewToken(int16 type, void* object,
|
int32 NewToken(int16 type, void* object,
|
||||||
new_token_callback callback= NULL);
|
new_token_callback callback = NULL);
|
||||||
bool RemoveToken(int32 token, remove_token_callback callback = NULL);
|
bool RemoveToken(int32 token, remove_token_callback callback = NULL);
|
||||||
bool CheckToken(int32, int16) const;
|
bool CheckToken(int32 token, int16 type) const;
|
||||||
status_t GetToken(int32, int16, void**,
|
status_t GetToken(int32 token, int16 type, void** object,
|
||||||
get_token_callback callback = NULL) const;
|
get_token_callback callback = NULL) const;
|
||||||
|
|
||||||
|
status_t GetList(int32*& tokens, int32& count) const;
|
||||||
|
|
||||||
// Possible expansion
|
// Possible expansion
|
||||||
// void Dump(BDataIO&, bool) const;
|
// void Dump(BDataIO&, bool) const;
|
||||||
// int32 NewToken(void*, BDirectMessageTarget*, void (*)(short, void*));
|
// int32 NewToken(void*, BDirectMessageTarget*, void (*)(short, void*));
|
||||||
@@ -53,10 +55,9 @@ class BTokenSpace
|
|||||||
// BDirectMessageTarget* TokenTarget(uint32 token, int16 type);
|
// BDirectMessageTarget* TokenTarget(uint32 token, int16 type);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
struct TTokenInfo
|
struct TTokenInfo {
|
||||||
{
|
int16 type;
|
||||||
int16 type;
|
void* object;
|
||||||
void* object;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef std::map<int32, TTokenInfo> TTokenMap;
|
typedef std::map<int32, TTokenInfo> TTokenMap;
|
||||||
@@ -64,7 +65,6 @@ class BTokenSpace
|
|||||||
TTokenMap fTokenMap;
|
TTokenMap fTokenMap;
|
||||||
std::stack<int32> fTokenBin;
|
std::stack<int32> fTokenBin;
|
||||||
int32 fTokenCount;
|
int32 fTokenCount;
|
||||||
BLocker fLocker;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Possible expansion
|
// Possible expansion
|
||||||
@@ -79,12 +79,4 @@ extern _IMPEXP_BE BTokenSpace gDefaultTokens;
|
|||||||
|
|
||||||
} // namespace BPrivate
|
} // namespace BPrivate
|
||||||
|
|
||||||
#endif //TOKENSPACE_H
|
#endif // _TOKEN_SPACE_H
|
||||||
|
|
||||||
/*
|
|
||||||
* $Log $
|
|
||||||
*
|
|
||||||
* $Id $
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
*
|
*
|
||||||
* Authors:
|
* Authors:
|
||||||
* Erik Jaesler ([email protected])
|
* Erik Jaesler ([email protected])
|
||||||
|
* Axel Dörfler, [email protected]
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
@@ -35,7 +36,7 @@ int32
|
|||||||
BTokenSpace::NewToken(int16 type, void* object,
|
BTokenSpace::NewToken(int16 type, void* object,
|
||||||
new_token_callback callback)
|
new_token_callback callback)
|
||||||
{
|
{
|
||||||
BAutolock Lock(fLocker);
|
BAutolock locker(this);
|
||||||
|
|
||||||
TTokenInfo tokenInfo = { type, object };
|
TTokenInfo tokenInfo = { type, object };
|
||||||
int32 token;
|
int32 token;
|
||||||
@@ -60,7 +61,7 @@ BTokenSpace::NewToken(int16 type, void* object,
|
|||||||
bool
|
bool
|
||||||
BTokenSpace::RemoveToken(int32 token, remove_token_callback callback)
|
BTokenSpace::RemoveToken(int32 token, remove_token_callback callback)
|
||||||
{
|
{
|
||||||
BAutolock Lock(fLocker);
|
BAutolock locker(this);
|
||||||
|
|
||||||
TTokenMap::iterator iter = fTokenMap.find(token);
|
TTokenMap::iterator iter = fTokenMap.find(token);
|
||||||
if (iter == fTokenMap.end())
|
if (iter == fTokenMap.end())
|
||||||
@@ -83,7 +84,7 @@ BTokenSpace::RemoveToken(int32 token, remove_token_callback callback)
|
|||||||
bool
|
bool
|
||||||
BTokenSpace::CheckToken(int32 token, int16 type) const
|
BTokenSpace::CheckToken(int32 token, int16 type) const
|
||||||
{
|
{
|
||||||
BAutolock Locker(const_cast<BLocker&>(fLocker));
|
BAutolock locker(const_cast<BTokenSpace&>(*this));
|
||||||
|
|
||||||
TTokenMap::const_iterator iter = fTokenMap.find(token);
|
TTokenMap::const_iterator iter = fTokenMap.find(token);
|
||||||
if (iter != fTokenMap.end() && iter->second.type == type)
|
if (iter != fTokenMap.end() && iter->second.type == type)
|
||||||
@@ -97,7 +98,7 @@ status_t
|
|||||||
BTokenSpace::GetToken(int32 token, int16 type, void** object,
|
BTokenSpace::GetToken(int32 token, int16 type, void** object,
|
||||||
get_token_callback callback) const
|
get_token_callback callback) const
|
||||||
{
|
{
|
||||||
BAutolock Locker(const_cast<BLocker&>(fLocker));
|
BAutolock locker(const_cast<BTokenSpace&>(*this));
|
||||||
|
|
||||||
TTokenMap::const_iterator iter = fTokenMap.find(token);
|
TTokenMap::const_iterator iter = fTokenMap.find(token);
|
||||||
if (iter == fTokenMap.end() || iter->second.type != type) {
|
if (iter == fTokenMap.end() || iter->second.type != type) {
|
||||||
@@ -115,5 +116,24 @@ BTokenSpace::GetToken(int32 token, int16 type, void** object,
|
|||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace BPrivate
|
|
||||||
|
|
||||||
|
status_t
|
||||||
|
BTokenSpace::GetList(int32*& tokens, int32& count) const
|
||||||
|
{
|
||||||
|
BAutolock locker(const_cast<BTokenSpace&>(*this));
|
||||||
|
|
||||||
|
count = fTokenMap.size();
|
||||||
|
tokens = (int32*)malloc(count * sizeof(int32));
|
||||||
|
if (tokens == NULL)
|
||||||
|
return B_NO_MEMORY;
|
||||||
|
|
||||||
|
TTokenMap::const_iterator iterator = fTokenMap.begin();
|
||||||
|
for (int32 i = 0; iterator != fTokenMap.end(); i++) {
|
||||||
|
tokens[i] = iterator->first;
|
||||||
|
iterator++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return B_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace BPrivate
|
||||||
|
|||||||
Reference in New Issue
Block a user