Fix crash on startup if an LV2 plugin has a bad .ttl file.
[ardour.git] / libs / glibmm2 / gio / src / fileoutputstream.ccg
1 // -*- Mode: C++; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2
3 /* Copyright (C) 2007 The gtkmm 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 <gio/gio.h>
21 #include <glib.h>
22 #include <glibmm/error.h>
23 #include <glibmm/exceptionhandler.h>
24 #include "slot_async.h"
25
26 namespace Gio
27 {
28
29 #ifdef GLIBMM_EXCEPTIONS_ENABLED
30 Glib::RefPtr<FileInfo> FileOutputStream::query_info(const Glib::RefPtr<Cancellable>& cancellable, const std::string& attributes)
31 #else
32 Glib::RefPtr<FileInfo> FileOutputStream::query_info(const Glib::RefPtr<Cancellable>& cancellable, const std::string& attributes, std::auto_ptr<Glib::Error>& error)
33 #endif //GLIBMM_EXCEPTIONS_ENABLED
34 {
35   GError* gerror = 0;
36   Glib::RefPtr<FileInfo> retvalue = Glib::wrap(g_file_output_stream_query_info(gobj(), g_strdup((attributes).c_str()), const_cast<GCancellable*>(Glib::unwrap(cancellable)), &(gerror)));
37 #ifdef GLIBMM_EXCEPTIONS_ENABLED
38   if(gerror)
39     ::Glib::Error::throw_exception(gerror);
40 #else
41   if(gerror)
42     error = ::Glib::Error::throw_exception(gerror);
43 #endif //GLIBMM_EXCEPTIONS_ENABLED
44
45   if(retvalue)
46     retvalue->reference(); //The function does not do a ref for us.
47   return retvalue;
48 }
49
50 #ifdef GLIBMM_EXCEPTIONS_ENABLED
51 Glib::RefPtr<FileInfo> FileOutputStream::query_info(const std::string& attributes)
52 #else
53 Glib::RefPtr<FileInfo> FileOutputStream::query_info(const std::string& attributes, std::auto_ptr<Glib::Error>& error)
54 #endif //GLIBMM_EXCEPTIONS_ENABLED
55 {
56   GError* gerror = 0;
57   Glib::RefPtr<FileInfo> retvalue = Glib::wrap(g_file_output_stream_query_info(gobj(), g_strdup((attributes).c_str()), NULL, &(gerror)));
58 #ifdef GLIBMM_EXCEPTIONS_ENABLED
59   if(gerror)
60     ::Glib::Error::throw_exception(gerror);
61 #else
62   if(gerror)
63     error = ::Glib::Error::throw_exception(gerror);
64 #endif //GLIBMM_EXCEPTIONS_ENABLED
65
66   if(retvalue)
67     retvalue->reference(); //The function does not do a ref for us.
68   return retvalue;
69 }
70
71 void
72 FileOutputStream::query_info_async(const SlotAsyncReady& slot, const Glib::RefPtr<Cancellable>& cancellable, const std::string& attributes, int io_priority)
73 {
74   // Create a copy of the slot.
75   // A pointer to it will be passed through the callback's data parameter
76   // and deleted in the callback.
77   SlotAsyncReady* slot_copy = new SlotAsyncReady(slot);
78
79   g_file_output_stream_query_info_async(gobj(),
80                                         const_cast<char*>(attributes.c_str()),
81                                         io_priority,
82                                         cancellable->gobj(),
83                                         &SignalProxy_async_callback,
84                                         slot_copy);
85 }
86
87 void
88 FileOutputStream::query_info_async(const SlotAsyncReady& slot, const std::string& attributes, int io_priority)
89 {
90   // Create a copy of the slot.
91   // A pointer to it will be passed through the callback's data parameter
92   // and deleted in the callback.
93   SlotAsyncReady* slot_copy = new SlotAsyncReady(slot);
94
95   g_file_output_stream_query_info_async(gobj(),
96                                         const_cast<char*>(attributes.c_str()),
97                                         io_priority,
98                                         NULL,
99                                         &SignalProxy_async_callback,
100                                         slot_copy);
101 }
102
103 } // namespace Gio