tbx  0.7.5
loadermanager.h
1 /*
2  * tbx RISC OS toolbox library
3  *
4  * Copyright (C) 2010 Alan Buckley All Rights Reserved.
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a
7  * copy of this software and associated documentation files (the "Software"),
8  * to deal in the Software without restriction, including without limitation
9  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  * and/or sell copies of the Software, and to permit persons to whom the
11  * Software is furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included
14  * in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22  * THE SOFTWARE.
23  */
24 
25 #ifndef TBX_LOADERMANAGER_H_
26 #define TBX_LOADERMANAGER_H_
27 
28 #include "wimpmessagelistener.h"
29 #include "loader.h"
30 #include <map>
31 
32 namespace tbx {
33 
35 /*
36  * Internal class to managed file/data loaders
37  */
38 
39 class LoaderManager:
43 {
44 private:
45  static LoaderManager *_instance;
46 
47 public:
48  LoaderManager();
49  virtual ~LoaderManager();
50 
51  static LoaderManager* instance() {return _instance;}
52 
53  virtual void user_message(WimpMessageEvent &event);
54  virtual void recorded_message(WimpMessageEvent &event, int reply_to);
55  virtual void acknowledge_message(WimpMessageEvent &event);
56 
57  void add_loader(ObjectId handle, ComponentId id, int file_type, Loader *loader);
58  void remove_loader(ObjectId handle, ComponentId id, int file_type, Loader *loader);
59 
60  void remove_all_loaders(ObjectId handle);
61  void remove_all_loaders(ObjectId handle, ComponentId id);
62 
63 private:
64  void start_loader(WimpMessageEvent &msg_event, int reply_to);
65  void process_dataload(WimpMessageEvent &event);
66  bool load_file(const WimpMessage &msg);
67  void ram_transmit(const WimpMessage &msg);
68  void find_loading(WimpMessageEvent &msg_event, int reply_to);
69 
70 
71  struct LoaderItem
72  {
73  ObjectId handle;
74  ComponentId id;
75  int file_type;
76  Loader *loader;
77  LoaderItem *next;
78  };
79 
80  std::map<ObjectId, LoaderItem *> _loaders;
81 
82  struct LoadingItem
83  {
84  Loader *_loader;
85  WimpMessage *_data_save_reply;
86  int _reply_to;
87  int _my_ref;
88  int _buffer_size;
89  LoadEvent *_load_event;
90 
91  LoadingItem(Loader *loader) : _loader(loader), _data_save_reply(0), _load_event(0) {};
92  ~LoadingItem() {delete _data_save_reply; delete _load_event;}
93  } *_loading;
94 };
95 
97 
98 }
99 
100 #endif /* LOADERMANAGER_H_ */
A library for creating RISC OS toolbox applications.
Definition: abouttobeshownlistener.cc:34
int ComponentId
Type for underlying toolbox component id.
Definition: handles.h:33
Listener to handle WimpRecordedMessages (event code 18)
Definition: wimpmessagelistener.h:269
Listener to handle WimpAcnowledgeMessages (event code 19)
Definition: wimpmessagelistener.h:289
Listener to handle WimpUserMessages (event code 17)
Definition: wimpmessagelistener.h:252
unsigned int ObjectId
Type for underlying toolbox object id.
Definition: handles.h:31