xref: /haiku/src/kits/translation/TranslatorRosterPrivate.h (revision e81a954787e50e56a7f06f72705b7859b6ab06d1)
1 /*
2  * Copyright 2006-2015, Haiku, Inc. All Rights Reserved.
3  * Distributed under the terms of the MIT License.
4  *
5  * Author:
6  *		Axel Dörfler, axeld@pinc-software.de
7  */
8 #ifndef TRANSLATOR_ROSTER_PRIVATE_H
9 #define TRANSLATOR_ROSTER_PRIVATE_H
10 
11 #include <map>
12 #include <set>
13 #include <vector>
14 
15 #include <Entry.h>
16 #include <Handler.h>
17 #include <Locker.h>
18 #include <Messenger.h>
19 #include <TranslatorRoster.h>
20 
21 
22 struct translator_data;
23 
24 
25 struct translator_item {
26 	BTranslator*	translator;
27 	entry_ref		ref;
28 	ino_t			node;
29 	image_id		image;
30 };
31 
32 typedef std::map<translator_id, translator_item> TranslatorMap;
33 typedef std::vector<BMessenger> MessengerList;
34 typedef std::vector<node_ref> NodeRefList;
35 typedef std::set<entry_ref> EntryRefSet;
36 typedef std::map<image_id, int32> ImageMap;
37 typedef std::map<BTranslator*, image_id> TranslatorImageMap;
38 
39 
40 class BTranslatorRoster::Private : public BHandler, public BLocker {
41 public:
42 								Private();
43 	virtual						~Private();
44 
45 	virtual	void				MessageReceived(BMessage* message);
46 
47 			void				AddDefaultPaths();
48 			status_t			AddPaths(const char* paths);
49 			status_t			AddPath(const char* path, int32* _added = NULL);
50 			status_t			AddTranslator(BTranslator* translator,
51 									image_id image = -1,
52 									const entry_ref* ref = NULL,
53 									ino_t node = 0);
54 
55 			void				RemoveTranslators(entry_ref& ref);
56 
57 			BTranslator*		FindTranslator(translator_id id);
58 
59 			status_t			StoreTranslators(BMessage& archive);
60 			status_t			Identify(BPositionIO* source,
61 									BMessage* ioExtension, uint32 hintType,
62 									const char* hintMIME, uint32 wantType,
63 									translator_info* _info);
64 
65 			status_t			GetTranslators(BPositionIO* source,
66 									BMessage* ioExtension, uint32 hintType,
67 									const char* hintMIME, uint32 wantType,
68 									translator_info** _info, int32* _numInfo);
69 			status_t			GetAllTranslators(translator_id** _ids,
70 									int32* _count);
71 			status_t			GetRefFor(translator_id id, entry_ref& ref);
72 
73 			bool				IsActive() const { return Looper(); }
74 
75 			status_t			CreateTranslators(const entry_ref& ref,
76 									int32& count, BMessage* update = NULL);
77 			status_t			GetTranslatorData(image_id image,
78 									translator_data& data);
79 
80 			status_t			StartWatching(BMessenger target);
81 			status_t			StopWatching(BMessenger target);
82 
83 private:
84 	static	int					_CompareSupport(const void* _a, const void* _b);
85 
86 			void				_RescanChanged();
87 
88 			const translation_format* _CheckHints(
89 									const translation_format* formats,
90 									int32 formatsCount, uint32 hintType,
91 									const char* hintMIME);
92 
93 			const translator_item* _FindTranslator(translator_id id) const;
94 			const translator_item* _FindTranslator(const char* name) const;
95 			const translator_item* _FindTranslator(entry_ref& ref) const;
96 			translator_item*	_FindTranslator(node_ref& nodeRef);
97 
98 			int32				_CompareTranslatorDirectoryPriority(
99 									const entry_ref& a,
100 									const entry_ref& b) const;
101 			bool				_IsKnownDirectory(const node_ref& nodeRef)
102 									const;
103 
104 			void				_RemoveTranslators(const node_ref* nodeRef,
105 									const entry_ref* ref = NULL);
106 			void				_EntryAdded(const node_ref& nodeRef,
107 									const char* name);
108 			void				_EntryAdded(const entry_ref& ref);
109 			void				_NotifyListeners(BMessage& update) const;
110 			void				_TranslatorDeleted(translator_id id,
111 									BTranslator *self);
112 
113 			NodeRefList			fDirectories;
114 			TranslatorMap		fTranslators;
115 			MessengerList		fMessengers;
116 			EntryRefSet			fRescanEntries;
117 			ImageMap			fKnownImages;
118 			TranslatorImageMap	fImageOrigins;
119 			const char*			fABISubDirectory;
120 			int32				fNextID;
121 			bool				fLazyScanning;
122 			bool				fSafeMode;
123 };
124 
125 
126 #endif	// TRANSLATOR_ROSTER_PRIVATE_H
127