tbx  0.7.6
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  // Clipboard support
64  void paste_ref(int ref) {_paste_ref = ref;}
65  void send_local(int file_type, const char *data, int size, Object load_object, Gadget load_gadget, int x, int y);
66  // Allow temporary interception of loader messages.
67  class MessageIntercept
68  {
69  public:
70  virtual ~MessageIntercept() {};
71  virtual bool loader_message_intercept(WimpMessage::SendType type, WimpMessageEvent &event, int reply_to) = 0;
72  };
73  void message_intercept(MessageIntercept *intercept) {_message_intercept = intercept;}
74  MessageIntercept *message_intercept() const {return _message_intercept;}
75 
76 private:
77  void start_loader(WimpMessageEvent &msg_event, int reply_to);
78  void process_dataload(WimpMessageEvent &event);
79  bool load_file(const WimpMessage &msg);
80  void ram_transmit(const WimpMessage &msg);
81  void find_loading(WimpMessageEvent &msg_event, int reply_to);
82 
83 
84  struct LoaderItem
85  {
86  ObjectId handle;
87  ComponentId id;
88  int file_type;
89  Loader *loader;
90  LoaderItem *next;
91  };
92 
93  std::map<ObjectId, LoaderItem *> _loaders;
94 
95  struct LoadingItem
96  {
97  Loader *_loader;
98  WimpMessage *_data_save_reply;
99  int _reply_to;
100  int _my_ref;
101  int _buffer_size;
102  LoadEvent *_load_event;
103 
104  LoadingItem(Loader *loader) : _loader(loader), _data_save_reply(0), _load_event(0) {};
105  ~LoadingItem() {delete _data_save_reply; delete _load_event;}
106  } *_loading;
107 
108  int _paste_ref;
109  MessageIntercept *_message_intercept;
110 };
111 
113 
114 }
115 
116 #endif /* LOADERMANAGER_H_ */
tbx
A library for creating RISC OS toolbox applications.
Definition: abouttobeshownlistener.cc:35
tbx::ComponentId
int ComponentId
Type for underlying toolbox component id.
Definition: handles.h:33
tbx::WimpMessage::SendType
SendType
Enumeration specifying the type of message to send.
Definition: wimpmessagelistener.h:191
tbx::WimpRecordedMessageListener
Listener to handle WimpRecordedMessages (event code 18)
Definition: wimpmessagelistener.h:270
tbx::WimpUserMessageListener
Listener to handle WimpUserMessages (event code 17)
Definition: wimpmessagelistener.h:253
tbx::ObjectId
unsigned int ObjectId
Type for underlying toolbox object id.
Definition: handles.h:31
tbx::WimpAcknowledgeMessageListener
Listener to handle WimpAcnowledgeMessages (event code 19)
Definition: wimpmessagelistener.h:290