Fix crash on startup if an LV2 plugin has a bad .ttl file.
[ardour.git] / libs / glibmm2 / gio / src / fileenumerator.hg
1 // -*- Mode: C++; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2
3 /* Copyright (C) 2007 The glibmm Development Team
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Library General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Library General Public License for more details.
14  *
15  * You should have received a copy of the GNU Library General Public
16  * License along with this library; if not, write to the Free
17  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  */
19
20 #include <glibmm/object.h>
21 #include <glibmm/arrayhandle.h>
22 #include <glibmm/listhandle.h>
23 #include <giomm/asyncresult.h>
24 #include <giomm/cancellable.h>
25 #include <giomm/fileinfo.h>
26 //#include <giomm/file.h>
27
28 _DEFS(giomm,gio)
29 _PINCLUDE(glibmm/private/object_p.h)
30
31 namespace Gio
32 {
33
34 class File;
35
36 //TODO: Consider wrapping this like a std::iterator (or at least renaming it), though the asyncness probably makes that unsuitable.
37
38 /** Enumerated Files Routines.
39  * FileEnumerator allows you to operate on a set of Gio::Files, returning a Gio::FileInfo instance for each file enumerated 
40  * (e.g. Gio::File::enumerate_children() will return a FileEnumerator for each of the children within a directory).
41  *
42  * To get the next file's information from a Gio::FileEnumerator, use next_file() or its asynchronous version, next_file_async(). 
43  * Note that the asynchronous version will return a list of Gio::FileInfos, whereas the synchronous version will only return the next 
44  * file in the enumerator.
45  *
46  * To close a Gio::FileEnumerator, use FileEnumerator::close(), or its asynchronous version, close_async(). Once a FileEnumerator is closed, 
47  * no further actions may be performed on it.
48  *
49  * @newin2p16
50  */
51 class FileEnumerator : public Glib::Object
52 {
53   _CLASS_GOBJECT(FileEnumerator, GFileEnumerator, G_FILE_ENUMERATOR, Glib::Object, GObject)
54
55 public:
56   _WRAP_METHOD(Glib::RefPtr<FileInfo> next_file(const Glib::RefPtr<Cancellable>& cancellable),
57                g_file_enumerator_next_file,
58                errthrow)
59
60   /** 
61    * @return A FileInfo or an empty RefPtr on error or end of enumerator.
62    */
63   #ifdef GLIBMM_EXCEPTIONS_ENABLED
64   Glib::RefPtr<FileInfo> next_file();
65   #else
66   Glib::RefPtr<FileInfo> next_file(std::auto_ptr<Glib::Error>& error);
67   #endif //GLIBMM_EXCEPTIONS_ENABLED
68
69   _WRAP_METHOD(bool close(const Glib::RefPtr<Cancellable>& cancellable),
70                g_file_enumerator_close,
71                errthrow)
72
73   /** Releases all resources used by this enumerator, making the
74    * enumerator throw a Gio::Error with CLOSED on all calls.
75    * 
76    * This will be automatically called when the last reference
77    * is dropped, but you might want to call this method to make sure resources
78    * are released as early as possible.
79    * @return #<tt>true</tt> on success or an empty RefPtr on error.
80    */
81   #ifdef GLIBMM_EXCEPTIONS_ENABLED
82   bool close();
83   #else
84   bool close(std::auto_ptr<Glib::Error>& error);
85   #endif //GLIBMM_EXCEPTIONS_ENABLED
86
87
88   /** Request information for a number of files from the enumerator asynchronously. 
89    * When all I/O for the operation is finished the callback slot will be called with the requested information.
90    *
91    * The callback could be called with less than num_files files in case of error or at the end of the enumerator. 
92    * In case of a partial error the callback will be called with any succeeding items and no error, and on the next request the error will be reported. 
93    * If a request is cancelled the callback will be called with ERROR_CANCELLED.
94    *
95    * During an async request no other sync and async calls are allowed, and will result in ERROR_PENDING errors.
96    *
97    * Any outstanding I/O request with higher priority (lower numerical value) will be executed before an outstanding request with lower priority. 
98    * The default priority is PRIORITY_DEFAULT.
99    * @param slot A callback to call when the request is satisfied.
100    * @param cancellable An cancellable object which can be used to cancel the request.
101    * @param num_files The number of file info objects to request.
102    * @param io_priority The I/O priority of the request.
103    */
104   void next_files_async(const SlotAsyncReady& slot, const Glib::RefPtr<Cancellable>& cancellable, int num_files = 1, int io_priority = Glib::PRIORITY_DEFAULT);
105
106   /** Request information for a number of files from the enumerator asynchronously. 
107    * When all I/O for the operation is finished the callback slot will be called with the requested information.
108    *
109    * The callback could be called with less than num_files files in case of error or at the end of the enumerator. 
110    * In case of a partial error the callback will be called with any succeeding items and no error, and on the next request the error will be reported. 
111    * If a request is cancelled the callback will be called with ERROR_CANCELLED.
112    *
113    * During an async request no other sync and async calls are allowed, and will result in ERROR_PENDING errors.
114    *
115    * Any outstanding I/O request with higher priority (lower numerical value) will be executed before an outstanding request with lower priority. 
116    * The default priority is PRIORITY_DEFAULT.
117    * @param slot A callback to call when the request is satisfied.
118    * @param num_files The number of file info objects to request.
119    * @param io_priority The I/O priority of the request.
120    */
121   void next_files_async(const SlotAsyncReady& slot, int num_files = 1, int io_priority = Glib::PRIORITY_DEFAULT);
122   _IGNORE(g_file_enumerator_next_files_async)
123
124 #m4 _CONVERSION(`GList*',`Glib::ListHandle< Glib::RefPtr<FileInfo> >', `$2(($3), Glib::OWNERSHIP_DEEP)')
125   _WRAP_METHOD(Glib::ListHandle< Glib::RefPtr<FileInfo> > next_files_finish(const Glib::RefPtr<AsyncResult>& result),
126                g_file_enumerator_next_files_finish,
127                errthrow)
128
129
130
131   /** Asynchronously closes the file enumerator.
132    *
133    * See close(), which is the synchronous version of this function.
134    *
135    * The operation can be cancelled by triggering the cancellable object from another thread. 
136    * If the operation was cancelled, a Gio::Error with CANCELLED will be thrown by close_finish().
137    *
138    * @param io_priority The I/O priority of the request.
139    * @param cancellable A Cancellable object which can be used to cancel the operation.
140    * @param slot A callback to call when the request is satisfied.
141    */
142   void close_async(int io_priority, const Glib::RefPtr<Cancellable>& cancellable, const SlotAsyncReady& slot);
143
144   /** Asynchronously closes the file enumerator.
145    *
146    * See close(), which is the synchronous version of this function.
147    *
148    * @param io_priority The I/O priority of the request.
149    * @param slot  A callback to call when the request is satisfied.
150    */
151   void close_async(int io_priority, const SlotAsyncReady& slot);
152   _IGNORE(g_file_enumerator_close_async)
153
154   _WRAP_METHOD(bool close_finish(const Glib::RefPtr<AsyncResult>& result),
155                g_file_enumerator_close_finish,
156                errthrow)
157
158   _WRAP_METHOD(bool is_closed() const, g_file_enumerator_is_closed)
159   _WRAP_METHOD(bool has_pending() const, g_file_enumerator_has_pending)
160   _WRAP_METHOD(void set_pending(bool pending = true), g_file_enumerator_set_pending)
161
162   _WRAP_METHOD(Glib::RefPtr<File> get_container(), g_file_enumerator_get_container, refreturn)
163   _WRAP_METHOD(Glib::RefPtr<const File> get_container() const, g_file_enumerator_get_container, refreturn)
164 };
165
166 } // namespace Gio
167