xref: /haiku/headers/private/app/TokenSpace.h (revision 4f00613311d0bd6b70fa82ce19931c41f071ea4e)
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 		void		SetToken(int32 token, int16 type, void* object);
45 
46 		bool		RemoveToken(int32 token, remove_token_callback callback = NULL);
47 		bool		CheckToken(int32 token, int16 type) const;
48 		status_t	GetToken(int32 token, int16 type, void** object,
49 						get_token_callback callback = NULL) const;
50 
51 	private:
52 		struct token_info {
53 			int16	type;
54 			void*	object;
55 		};
56 		typedef std::map<int32, token_info> TokenMap;
57 
58 		TokenMap	fTokenMap;
59 		int32		fTokenCount;
60 };
61 
62 extern _IMPEXP_BE BTokenSpace gDefaultTokens;
63 
64 }	// namespace BPrivate
65 
66 #endif	// _TOKEN_SPACE_H
67