1 /* 2 * Copyright (c) 1999-2000, Eric Moon. 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions, and the following disclaimer. 11 * 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. 15 * 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. 18 * 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. 29 */ 30 31 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 41 // 42 // - persistence support: drives export and import of user-created 43 // nodes, groups, and connections to & from XML streams. 44 // 45 // EXPORT PROCESS 46 // 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 53 // 54 // IMPORT PROCESS 55 // 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 65 // 66 // * HISTORY 67 // c.lenz 28may00 Begun notification/error logging support 68 // e.moon 7dec99 Persistence support 69 // e.moon 7nov99 Begun 70 71 #ifndef __RouteAppNodeManager_H__ 72 #define __RouteAppNodeManager_H__ 73 74 #include <Mime.h> // defines icon_size -- weird. 75 76 #include <map> 77 #include <set> 78 79 #include "NodeManager.h" 80 #include "XML.h" 81 #include "ImportContext.h" 82 #include "ExportContext.h" 83 84 #include "NodeKey.h" 85 86 #include "cortex_defs.h" 87 __BEGIN_CORTEX_NAMESPACE 88 89 class MediaIcon; 90 91 class RouteAppNodeManager : 92 public NodeManager, 93 public IPersistent { 94 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, 100 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 105 }; 106 107 // static const char* const s_rootElement; 108 // static const char* const s_uiStateElement; 109 110 public: // *** ctor/dtor 111 virtual ~RouteAppNodeManager(); 112 RouteAppNodeManager( 113 bool useAddOnHost=false); 114 115 public: // *** group management 116 117 public: // *** icon management 118 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. 122 123 const MediaIcon* mediaIconFor( 124 media_node_id nodeID, 125 icon_size iconSize); 126 127 const MediaIcon* mediaIconFor( 128 live_node_info nodeInfo, 129 icon_size iconSize); 130 131 public: // *** notification & error handling 132 133 status_t setNotifyTarget( 134 const BMessenger& target); 135 136 status_t setLogTarget( 137 const BMessenger& target); 138 139 public: // NodeManager hook implementations 140 141 virtual void nodeCreated( 142 NodeRef* ref); 143 144 virtual void nodeDeleted( 145 const NodeRef* ref); 146 147 virtual void connectionMade( 148 Connection* connection); 149 150 virtual void connectionBroken( 151 const Connection* connection); 152 153 virtual void connectionFailed( 154 const media_output & output, 155 const media_input & input, 156 const media_format & format, 157 status_t error); 158 159 public: // *** IPersistent 160 161 // EXPORT 162 163 virtual void xmlExportBegin( 164 ExportContext& context) const; 165 166 virtual void xmlExportAttributes( 167 ExportContext& context) const; 168 169 virtual void xmlExportContent( 170 ExportContext& context) const; //nyi 171 172 virtual void xmlExportEnd( 173 ExportContext& context) const; 174 175 // IMPORT 176 177 virtual void xmlImportBegin( 178 ImportContext& context); //nyi 179 180 virtual void xmlImportAttribute( 181 const char* key, 182 const char* value, 183 ImportContext& context); //nyi 184 185 virtual void xmlImportContent( 186 const char* data, 187 uint32 length, 188 ImportContext& context); //nyi 189 190 virtual void xmlImportChild( 191 IPersistent* child, 192 ImportContext& context); //nyi 193 194 virtual void xmlImportComplete( 195 ImportContext& context); //nyi 196 197 public: // *** static setup method 198 199 // call this method to install element hooks in the 200 // given document type 201 static void AddTo( 202 XML::DocumentType* docType); 203 204 private: // implementation 205 206 // current new-group-name index 207 uint32 m_nextGroupNumber; 208 209 // app message handler: group selection, etc 210 BMessenger m_notifyTarget; 211 212 // log-message handler 213 BMessenger m_logTarget; 214 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; 221 222 // class import_state* m_importState; 223 224 private: 225 226 uint64 _makeIconKey(media_node_id, icon_size); 227 void _readIconKey(uint64, media_node_id&, icon_size&); 228 void _freeIcons(); 229 230 bool _canGroup(NodeRef* ref) const; 231 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 235 // 236 // void _importDormantNode( 237 // class _dormant_node_import_state* state, 238 // ImportContext& context); //nyi 239 }; 240 241 __END_CORTEX_NAMESPACE 242 #endif /*__RouteAppNodeManager_H__*/ 243