tbx  0.7.5
loader.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_LOADER_H_
26 #define TBX_LOADER_H_
27 
28 #include "object.h"
29 #include "gadget.h"
30 #include "point.h"
31 
32 namespace tbx {
33 
41 class LoadEvent
42 {
43 private:
44  Object _object;
45  Gadget _gadget;
46  Point _point;
47  int _est_size;
48  int _file_type;
49  std::string _file_name;
50  bool _from_filer;
51 
52 public:
53  LoadEvent(Object obj, Gadget gadget, int x, int y,
54  int est, int type, const char *file_name, bool from_filer);
55 
59  Object destination_object() {return _object;}
60 
64  Gadget destination_gadget() {return _gadget;}
65 
69  const Point &destination_point() const {return _point;}
70 
74  int estimated_size() const {return _est_size;}
75 
79  int file_type() const {return _file_type;}
80 
88  const std::string &file_name() const {return _file_name;}
89 
93  bool from_filer() const {return _from_filer;}
94 
99  bool opener() const {return _object.null();}
100 
106  void update_file_details(const char *file_name, int size) {_file_name = file_name; _est_size = size;}
107 };
108 
113 {
114 private:
115  LoadEvent *_load_event;
116  void *_buffer;
117  int _buffer_size;
118  int _received;
119  bool _more;
120 
121 public:
125  DataReceivedEvent(LoadEvent *event, void *buffer, int buffer_size, int received) :
126  _load_event(event),
127  _buffer(buffer),
128  _buffer_size(buffer_size),
129  _received(received)
130  {
131  _more = (_buffer_size == _received);
132  }
133 
137  const LoadEvent &load_event() const {return *_load_event;}
138 
142  void *buffer() const {return _buffer;}
143 
147  void buffer(void *buf) {_buffer = buf;}
148 
152  int buffer_size() const {return _buffer_size;}
153 
158  void buffer_size(int size) {_buffer_size = size;}
159 
163  int received() const {return _received;}
164 
168  bool more() const {return _more;}
169 };
170 
179 class Loader {
180 public:
181  virtual ~Loader() {};
182 
190  virtual bool load_file(LoadEvent &event) = 0;
191 
199  virtual bool accept_file(LoadEvent &event) {return true;}
200 
214  virtual void *data_buffer(const LoadEvent &event, int &buffer_size) {return 0;}
215 
236  virtual bool data_received(DataReceivedEvent &event) {return false;}
237 
244  virtual void data_error(const LoadEvent &event) {}
245 };
246 
247 }
248 
249 #endif /* LOADER_H_ */
virtual void data_error(const LoadEvent &event)
Informs loader that an error occurred during application to application data transfer.
Definition: loader.h:244
A library for creating RISC OS toolbox applications.
Definition: abouttobeshownlistener.cc:34
This is the base class for all Gadgets.
Definition: gadget.h:48
int file_type() const
File type of file.
Definition: loader.h:79
Object destination_object()
Object the load is going to occur on.
Definition: loader.h:59
const LoadEvent & load_event() const
Return o LoadEvent that started the transfer.
Definition: loader.h:137
const Point & destination_point() const
Location for load (screen coordinates)
Definition: loader.h:69
bool from_filer() const
Check if the load is from the filer.
Definition: loader.h:93
virtual bool accept_file(LoadEvent &event)
Override to see if the loader can accept a file.
Definition: loader.h:199
virtual void * data_buffer(const LoadEvent &event, int &buffer_size)
Set up buffer for application to application data transfer.
Definition: loader.h:214
Class with details of buffer transferred from another application.
Definition: loader.h:112
LoadEvent(Object obj, Gadget gadget, int x, int y, int est, int type, const char *file_name, bool from_filer)
Constructor.
Definition: loader.cc:32
DataReceivedEvent(LoadEvent *event, void *buffer, int buffer_size, int received)
Construct with details of received buffer.
Definition: loader.h:125
Class to represent a position in two dimensional space.
Definition: point.h:36
void * buffer() const
Return the buffer the transmitted data has been copied too.
Definition: loader.h:142
Class to handle file/data loading from the filer or an external application.
Definition: loader.h:179
void buffer(void *buf)
Set the buffer address for the next bytes received.
Definition: loader.h:147
const std::string & file_name() const
File name of file.
Definition: loader.h:88
int estimated_size() const
Estimated size of file.
Definition: loader.h:74
Gadget destination_gadget()
Gadget for load (can be a null gadget if no gadget is involved).
Definition: loader.h:64
int received() const
Number of bytes received.
Definition: loader.h:163
bool opener() const
Returns true if this event is from an opener added to the main application.
Definition: loader.h:99
virtual bool data_received(DataReceivedEvent &event)
Override to receive the file by in memory transfer from another application.
Definition: loader.h:236
Class with details of a file load operation.
Definition: loader.h:41
bool more() const
Return true if more data is to come.
Definition: loader.h:168
bool null() const
Check if object has been initialised.
Definition: object.h:87
void update_file_details(const char *file_name, int size)
Update file details for load.
Definition: loader.h:106
void buffer_size(int size)
Set the buffer size for the next transmission from the other application.
Definition: loader.h:158
Class to manipulate a toolbox object.
Definition: object.h:50
int buffer_size() const
Return the buffer size of the current buffer.
Definition: loader.h:152