1 /* 2 * Copyright 2001-2005, Haiku. 3 * Distributed under the terms of the MIT License. 4 * 5 * Authors: 6 * Erik Jaesler (erik@cgsoftware.com) 7 * Axel Dörfler, axeld@pinc-software.de 8 */ 9 #ifndef _TOKEN_SPACE_H 10 #define _TOKEN_SPACE_H 11 12 13 #include <map> 14 #include <stack> 15 16 #include <BeBuild.h> 17 #include <Locker.h> 18 #include <SupportDefs.h> 19 20 21 // token types as specified in targets 22 #define B_PREFERRED_TOKEN -2 /* A little bird told me about this one */ 23 #define B_NULL_TOKEN -1 24 #define B_ANY_TOKEN 0 25 26 // token types in the token list 27 #define B_HANDLER_TOKEN 1 28 #define B_SERVER_TOKEN 2 29 30 31 namespace BPrivate { 32 33 typedef void (*new_token_callback)(int16, void*); 34 typedef void (*remove_token_callback)(int16, void*); 35 typedef bool (*get_token_callback)(int16, void*); 36 37 class BTokenSpace : public BLocker { 38 public: 39 BTokenSpace(); 40 ~BTokenSpace(); 41 42 int32 NewToken(int16 type, void* object, 43 new_token_callback callback = NULL); 44 bool RemoveToken(int32 token, remove_token_callback callback = NULL); 45 bool CheckToken(int32 token, int16 type) const; 46 status_t GetToken(int32 token, int16 type, void** object, 47 get_token_callback callback = NULL) const; 48 49 status_t GetList(int32*& tokens, int32& count) const; 50 51 // Possible expansion 52 // void Dump(BDataIO&, bool) const; 53 // int32 NewToken(void*, BDirectMessageTarget*, void (*)(short, void*)); 54 // bool SetTokenTarget(uint32, BDirectMessageTarget*); 55 // BDirectMessageTarget* TokenTarget(uint32 token, int16 type); 56 57 private: 58 struct TTokenInfo { 59 int16 type; 60 void* object; 61 }; 62 63 typedef std::map<int32, TTokenInfo> TTokenMap; 64 65 TTokenMap fTokenMap; 66 std::stack<int32> fTokenBin; 67 int32 fTokenCount; 68 }; 69 70 // Possible expansion 71 //_delete_tokens_(); 72 //_init_tokens_(); 73 //get_handler_token(short, void*); 74 //get_token_list(long, long*); 75 //new_handler_token(short, void*); 76 //remove_handler_token(short, void*); 77 78 extern _IMPEXP_BE BTokenSpace gDefaultTokens; 79 80 } // namespace BPrivate 81 82 #endif // _TOKEN_SPACE_H 83