xref: /haiku/src/apps/cortex/RouteApp/RouteAppNodeManager.h (revision c90684742e7361651849be4116d0e5de3a817194)
1 // RouteAppNodeManager.h
2 // * PURPOSE
3 //   Extends NodeManager to provide services to a graphical
4 //   routing interface:
5 //   - automatic group management (groups are formed/merged
6 //     as nodes are connected, and split when nodes are
7 //     disconnected)
8 //   - error logging via BMessage +++++ nyi
9 //   - icon management: generation and caching of MediaIcons
10 //
11 //   - persistence support: drives export and import of user-created
12 //     nodes, groups, and connections to & from XML streams.
13 //
14 //   EXPORT PROCESS
15 //
16 //     1) Assign each node to be saved an ID string.  Reject nodes
17 //        that the user didn't create.
18 //     2) Export each node.
19 //     3) Export each connection.
20 //     4) Export each group.
21 //     5) Export UI state data via export-context hook
22 //
23 //   IMPORT PROCESS
24 //
25 //     1) Import each node's description and [try to] instantiate the
26 //        node.  Build a map of ID -> media_node_id.
27 //        (?) how much failure tolerance is too much?
28 //     2) Import and attempt to recreate each connection.  Note: once
29 //        notification of the connection comes, the default behavior
30 //        will be to automatically group the node; this needs to be
31 //        bypassed!
32 //     3) Import each group.
33 //     4) Import UI state data via import-context hook
34 //
35 // * HISTORY
36 //	 c.lenz		28may00		Begun notification/error logging support
37 //   e.moon		7dec99		Persistence support
38 //   e.moon		7nov99		Begun
39 
40 #ifndef __RouteAppNodeManager_H__
41 #define __RouteAppNodeManager_H__
42 
43 #include <Mime.h> // defines icon_size -- weird.
44 
45 #include <map>
46 #include <set>
47 
48 #include "NodeManager.h"
49 #include "XML.h"
50 #include "ImportContext.h"
51 #include "ExportContext.h"
52 
53 #include "NodeKey.h"
54 
55 #include "cortex_defs.h"
56 __BEGIN_CORTEX_NAMESPACE
57 
58 class MediaIcon;
59 
60 class RouteAppNodeManager :
61 	public	NodeManager,
62 	public	IPersistent {
63 
64 public:														// *** constants
65 	enum message_t {
66 		// outbound: sent to the designated log-message target
67 		// 'text' (string) +++++ not yet implemented
68 		M_LOG													= RouteAppNodeManager_message_base,
69 
70 		// outbound: sent to observers when a time source is added/removed
71 		// 'nodeID' (int32)
72 		M_TIME_SOURCE_CREATED,
73 		M_TIME_SOURCE_DELETED
74 	};
75 
76 //	static const char* const				s_rootElement;
77 //	static const char* const				s_uiStateElement;
78 
79 public:														// *** ctor/dtor
80 	virtual ~RouteAppNodeManager();
81 	RouteAppNodeManager(
82 		bool													useAddOnHost=false);
83 
84 public:														// *** group management
85 
86 public:														// *** icon management
87 
88 	// fetch cached icon for the given live node; the MediaIcon
89 	// instance is guaranteed to last as long as this object.
90 	// Returns 0 if the node doesn't exist.
91 
92 	const MediaIcon* mediaIconFor(
93 		media_node_id									nodeID,
94 		icon_size											iconSize);
95 
96 	const MediaIcon* mediaIconFor(
97 		live_node_info								nodeInfo,
98 		icon_size											iconSize);
99 
100 public:														// *** notification & error handling
101 
102 	status_t setNotifyTarget(
103 		const BMessenger&							target);
104 
105 	status_t setLogTarget(
106 		const BMessenger&							target);
107 
108 public:														// NodeManager hook implementations
109 
110 	virtual void nodeCreated(
111 		NodeRef*									ref);
112 
113 	virtual void nodeDeleted(
114 		const NodeRef*								ref);
115 
116 	virtual void connectionMade(
117 		Connection*									connection);
118 
119 	virtual void connectionBroken(
120 		const Connection*							connection);
121 
122 	virtual void connectionFailed(
123 		const media_output &						output,
124 		const media_input &							input,
125 		const media_format &						format,
126 		status_t									error);
127 
128 public:														// *** IPersistent
129 
130 	// EXPORT
131 
132 	virtual void xmlExportBegin(
133 		ExportContext&								context) const;
134 
135 	virtual void xmlExportAttributes(
136 		ExportContext&								context) const;
137 
138 	virtual void xmlExportContent(
139 		ExportContext&								context) const; //nyi
140 
141 	virtual void xmlExportEnd(
142 		ExportContext&								context) const;
143 
144 	// IMPORT
145 
146 	virtual void xmlImportBegin(
147 		ImportContext&								context); //nyi
148 
149 	virtual void xmlImportAttribute(
150 		const char*										key,
151 		const char*										value,
152 		ImportContext&								context); //nyi
153 
154 	virtual void xmlImportContent(
155 		const char*										data,
156 		uint32												length,
157 		ImportContext&								context); //nyi
158 
159 	virtual void xmlImportChild(
160 		IPersistent*									child,
161 		ImportContext&								context); //nyi
162 
163 	virtual void xmlImportComplete(
164 		ImportContext&								context); //nyi
165 
166 public:												// *** static setup method
167 
168 	// call this method to install element hooks in the
169 	// given document type
170 	static void AddTo(
171 		XML::DocumentType*				docType);
172 
173 private:													// implementation
174 
175 	// current new-group-name index
176 	uint32													m_nextGroupNumber;
177 
178 	// app message handler: group selection, etc
179 	BMessenger											m_notifyTarget;
180 
181 	// log-message handler
182 	BMessenger											m_logTarget;
183 
184 	// cached MediaIcon instances
185 	// KEY:
186 	// high 32 bits: media_node_id
187 	// low 32 bits: icon_size
188 	typedef std::map<uint64, MediaIcon*> icon_map;
189 	icon_map												m_iconMap;
190 
191 //	class import_state*								m_importState;
192 
193 private:
194 
195 	uint64 _makeIconKey(media_node_id, icon_size);
196 	void _readIconKey(uint64, media_node_id&, icon_size&);
197 	void _freeIcons();
198 
199 	bool _canGroup(NodeRef* ref) const;
200 
201 //	void _exportNode(NodeRef* ref, const char* key, ExportContext& context) const;
202 //	void _exportConnection(Connection* connection, ExportContext& context) const; //nyi
203 //	void _exportGroup(NodeGroup* group, ExportContext& context) const; //nyi
204 //
205 //	void _importDormantNode(
206 //		class _dormant_node_import_state* state,
207 //		ImportContext& context); //nyi
208 };
209 
210 __END_CORTEX_NAMESPACE
211 #endif /*__RouteAppNodeManager_H__*/
212