1 /* 2 * Copyright 2001-2011, 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 <Locker.h> 17 #include <SupportDefs.h> 18 19 20 // token types as specified in targets 21 #define B_PREFERRED_TOKEN -2 /* A little bird told me about this one */ 22 #define B_NULL_TOKEN -1 23 #define B_ANY_TOKEN 0 24 25 // token types in the token list 26 #define B_HANDLER_TOKEN 1 27 #define B_SERVER_TOKEN 2 28 29 30 namespace BPrivate { 31 32 33 class BDirectMessageTarget; 34 35 36 class BTokenSpace : public BLocker { 37 public: 38 BTokenSpace(); 39 ~BTokenSpace(); 40 41 int32 NewToken(int16 type, void* object); 42 bool SetToken(int32 token, int16 type, void* object); 43 44 bool RemoveToken(int32 token); 45 bool CheckToken(int32 token, int16 type) const; 46 status_t GetToken(int32 token, int16 type, 47 void** _object) const; 48 49 status_t SetHandlerTarget(int32 token, 50 BDirectMessageTarget* target); 51 status_t AcquireHandlerTarget(int32 token, 52 BDirectMessageTarget** _target); 53 54 void InitAfterFork(); 55 56 private: 57 struct token_info { 58 int16 type; 59 void* object; 60 BDirectMessageTarget* target; 61 }; 62 typedef std::map<int32, token_info> TokenMap; 63 64 TokenMap fTokenMap; 65 int32 fTokenCount; 66 }; 67 68 69 extern BTokenSpace gDefaultTokens; 70 71 72 } // namespace BPrivate 73 74 75 #endif // _TOKEN_SPACE_H 76