BTRFS: Implement BTree::Path and change _Find.
[haiku.git] / src / apps / cortex / RouteApp / RouteAppNodeManager.h
blob956762c3035324f4426eced6c07135ac370c9cfa
1 /*
2 * Copyright (c) 1999-2000, Eric Moon.
3 * All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions, and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions, and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * 3. The name of the author may not be used to endorse or promote products
17 * derived from this software without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR
20 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21 * OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
23 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
26 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
27 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 // RouteAppNodeManager.h
33 // * PURPOSE
34 // Extends NodeManager to provide services to a graphical
35 // routing interface:
36 // - automatic group management (groups are formed/merged
37 // as nodes are connected, and split when nodes are
38 // disconnected)
39 // - error logging via BMessage +++++ nyi
40 // - icon management: generation and caching of MediaIcons
42 // - persistence support: drives export and import of user-created
43 // nodes, groups, and connections to & from XML streams.
45 // EXPORT PROCESS
47 // 1) Assign each node to be saved an ID string. Reject nodes
48 // that the user didn't create.
49 // 2) Export each node.
50 // 3) Export each connection.
51 // 4) Export each group.
52 // 5) Export UI state data via export-context hook
54 // IMPORT PROCESS
56 // 1) Import each node's description and [try to] instantiate the
57 // node. Build a map of ID -> media_node_id.
58 // (?) how much failure tolerance is too much?
59 // 2) Import and attempt to recreate each connection. Note: once
60 // notification of the connection comes, the default behavior
61 // will be to automatically group the node; this needs to be
62 // bypassed!
63 // 3) Import each group.
64 // 4) Import UI state data via import-context hook
66 // * HISTORY
67 // c.lenz 28may00 Begun notification/error logging support
68 // e.moon 7dec99 Persistence support
69 // e.moon 7nov99 Begun
71 #ifndef __RouteAppNodeManager_H__
72 #define __RouteAppNodeManager_H__
74 #include <Mime.h> // defines icon_size -- weird.
76 #include <map>
77 #include <set>
79 #include "NodeManager.h"
80 #include "XML.h"
81 #include "ImportContext.h"
82 #include "ExportContext.h"
84 #include "NodeKey.h"
86 #include "cortex_defs.h"
87 __BEGIN_CORTEX_NAMESPACE
89 class MediaIcon;
91 class RouteAppNodeManager :
92 public NodeManager,
93 public IPersistent {
95 public: // *** constants
96 enum message_t {
97 // outbound: sent to the designated log-message target
98 // 'text' (string) +++++ not yet implemented
99 M_LOG = RouteAppNodeManager_message_base,
101 // outbound: sent to observers when a time source is added/removed
102 // 'nodeID' (int32)
103 M_TIME_SOURCE_CREATED,
104 M_TIME_SOURCE_DELETED
107 // static const char* const s_rootElement;
108 // static const char* const s_uiStateElement;
110 public: // *** ctor/dtor
111 virtual ~RouteAppNodeManager();
112 RouteAppNodeManager(
113 bool useAddOnHost=false);
115 public: // *** group management
117 public: // *** icon management
119 // fetch cached icon for the given live node; the MediaIcon
120 // instance is guaranteed to last as long as this object.
121 // Returns 0 if the node doesn't exist.
123 const MediaIcon* mediaIconFor(
124 media_node_id nodeID,
125 icon_size iconSize);
127 const MediaIcon* mediaIconFor(
128 live_node_info nodeInfo,
129 icon_size iconSize);
131 public: // *** notification & error handling
133 status_t setNotifyTarget(
134 const BMessenger& target);
136 status_t setLogTarget(
137 const BMessenger& target);
139 public: // NodeManager hook implementations
141 virtual void nodeCreated(
142 NodeRef* ref);
144 virtual void nodeDeleted(
145 const NodeRef* ref);
147 virtual void connectionMade(
148 Connection* connection);
150 virtual void connectionBroken(
151 const Connection* connection);
153 virtual void connectionFailed(
154 const media_output & output,
155 const media_input & input,
156 const media_format & format,
157 status_t error);
159 public: // *** IPersistent
161 // EXPORT
163 virtual void xmlExportBegin(
164 ExportContext& context) const;
166 virtual void xmlExportAttributes(
167 ExportContext& context) const;
169 virtual void xmlExportContent(
170 ExportContext& context) const; //nyi
172 virtual void xmlExportEnd(
173 ExportContext& context) const;
175 // IMPORT
177 virtual void xmlImportBegin(
178 ImportContext& context); //nyi
180 virtual void xmlImportAttribute(
181 const char* key,
182 const char* value,
183 ImportContext& context); //nyi
185 virtual void xmlImportContent(
186 const char* data,
187 uint32 length,
188 ImportContext& context); //nyi
190 virtual void xmlImportChild(
191 IPersistent* child,
192 ImportContext& context); //nyi
194 virtual void xmlImportComplete(
195 ImportContext& context); //nyi
197 public: // *** static setup method
199 // call this method to install element hooks in the
200 // given document type
201 static void AddTo(
202 XML::DocumentType* docType);
204 private: // implementation
206 // current new-group-name index
207 uint32 m_nextGroupNumber;
209 // app message handler: group selection, etc
210 BMessenger m_notifyTarget;
212 // log-message handler
213 BMessenger m_logTarget;
215 // cached MediaIcon instances
216 // KEY:
217 // high 32 bits: media_node_id
218 // low 32 bits: icon_size
219 typedef std::map<uint64, MediaIcon*> icon_map;
220 icon_map m_iconMap;
222 // class import_state* m_importState;
224 private:
226 uint64 _makeIconKey(media_node_id, icon_size);
227 void _readIconKey(uint64, media_node_id&, icon_size&);
228 void _freeIcons();
230 bool _canGroup(NodeRef* ref) const;
232 // void _exportNode(NodeRef* ref, const char* key, ExportContext& context) const;
233 // void _exportConnection(Connection* connection, ExportContext& context) const; //nyi
234 // void _exportGroup(NodeGroup* group, ExportContext& context) const; //nyi
236 // void _importDormantNode(
237 // class _dormant_node_import_state* state,
238 // ImportContext& context); //nyi
241 __END_CORTEX_NAMESPACE
242 #endif /*__RouteAppNodeManager_H__*/