xref: /haiku/headers/private/app/TokenSpace.h (revision 893988af824e65e49e55f517b157db8386e8002b)
1 /*
2  * Copyright 2001-2007, 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 <BeBuild.h>
14 #include <Locker.h>
15 #include <SupportDefs.h>
16 
17 #include <map>
18 #include <stack>
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 class BDirectMessageTarget;
34 
35 
36 class BTokenSpace : public BLocker {
37 	public:
38 		BTokenSpace();
39 		~BTokenSpace();
40 
41 		int32		NewToken(int16 type, void* object);
42 		void		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, void** _object) const;
47 
48 		status_t	SetHandlerTarget(int32 token, BDirectMessageTarget* target);
49 		status_t	AcquireHandlerTarget(int32 token, BDirectMessageTarget** _target);
50 
51 	private:
52 		struct token_info {
53 			int16	type;
54 			void*	object;
55 			BDirectMessageTarget* target;
56 		};
57 		typedef std::map<int32, token_info> TokenMap;
58 
59 		TokenMap	fTokenMap;
60 		int32		fTokenCount;
61 };
62 
63 extern BTokenSpace gDefaultTokens;
64 
65 }	// namespace BPrivate
66 
67 #endif	// _TOKEN_SPACE_H
68