1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from gir-files (https://github.com/gtk-rs/gir-files)
// from gst-gir-files (https://gitlab.freedesktop.org/gstreamer/gir-files-rs.git)
// DO NOT EDIT

use crate::Extractable;
use glib::object::Cast;
use glib::object::IsA;
use glib::signal::connect_raw;
use glib::signal::SignalHandlerId;
use glib::translate::*;
use std::boxed::Box as Box_;
use std::mem::transmute;
use std::pin::Pin;
use std::ptr;

glib::wrapper! {
    /// A [`crate::Asset`] in the GStreamer Editing Services represents a resources
    /// that can be used. In particular, any class that implements the
    /// [`crate::Extractable`] interface may have some associated assets with a
    /// corresponding [`crate::Asset:extractable-type`], from which its objects can be
    /// extracted using [`crate::prelude::AssetExt::extract()`]. Some examples would be
    /// [`crate::Clip`], [`crate::Formatter`] and [`crate::TrackElement`].
    ///
    /// All assets that are created within GES are stored in a cache; one per
    /// each [`crate::Asset:id`] and [`crate::Asset:extractable-type`] pair. These assets can
    /// be fetched, and initialized if they do not yet exist in the cache,
    /// using [`Self::request()`].
    ///
    /// ``` c
    /// GESAsset *effect_asset;
    /// GESEffect *effect;
    ///
    /// // You create an asset for an effect
    /// effect_asset = ges_asset_request (GES_TYPE_EFFECT, "agingtv", NULL);
    ///
    /// // And now you can extract an instance of GESEffect from that asset
    /// effect = GES_EFFECT (ges_asset_extract (effect_asset));
    ///
    /// ```
    ///
    /// The advantage of using assets, rather than simply creating the object
    /// directly, is that the currently loaded resources can be listed with
    /// `ges_list_assets()` and displayed to an end user. For example, to show
    /// which media files have been loaded, and a standard list of effects. In
    /// fact, the GES library already creates assets for [`crate::TransitionClip`] and
    /// [`crate::Formatter`], which you can use to list all the available transition
    /// types and supported formats.
    ///
    /// The other advantage is that [`crate::Asset`] implements [`crate::MetaContainer`], so
    /// metadata can be set on the asset, with some subclasses automatically
    /// creating this metadata on initiation.
    ///
    /// For example, to display information about the supported formats, you
    /// could do the following:
    ///
    /// ```text
    ///    GList *formatter_assets, *tmp;
    ///
    ///    //  List all  the transitions
    ///    formatter_assets = ges_list_assets (GES_TYPE_FORMATTER);
    ///
    ///    // Print some infos about the formatter GESAsset
    ///    for (tmp = formatter_assets; tmp; tmp = tmp->next) {
    ///      g_print ("Name of the formatter: %s, file extension it produces: %s",
    ///        ges_meta_container_get_string (
    ///          GES_META_CONTAINER (tmp->data), GES_META_FORMATTER_NAME),
    ///        ges_meta_container_get_string (
    ///          GES_META_CONTAINER (tmp->data), GES_META_FORMATTER_EXTENSION));
    ///    }
    ///
    ///    g_list_free (transition_assets);
    ///
    /// ```
    ///
    /// ## ID
    ///
    /// Each asset is uniquely defined in the cache by its
    /// [`crate::Asset:extractable-type`] and [`crate::Asset:id`]. Depending on the
    /// [`crate::Asset:extractable-type`], the [`crate::Asset:id`] can be used to parametrise
    /// the creation of the object upon extraction. By default, a class that
    /// implements [`crate::Extractable`] will only have a single associated asset,
    /// with an [`crate::Asset:id`] set to the type name of its objects. However, this
    /// is overwritten by some implementations, which allow a class to have
    /// multiple associated assets. For example, for [`crate::TransitionClip`] the
    /// [`crate::Asset:id`] will be a nickname of the [`crate::TransitionClip:vtype`]. You
    /// should check the documentation for each extractable type to see if they
    /// differ from the default.
    ///
    /// Moreover, each [`crate::Asset:extractable-type`] may also associate itself
    /// with a specific asset subclass. In such cases, when their asset is
    /// requested, an asset of this subclass will be returned instead.
    ///
    /// ## Managing
    ///
    /// You can use a [`crate::Project`] to easily manage the assets of a
    /// [`crate::Timeline`].
    ///
    /// ## Proxies
    ///
    /// Some assets can (temporarily) act as the [`crate::Asset:proxy`] of another
    /// asset. When the original asset is requested from the cache, the proxy
    /// will be returned in its place. This can be useful if, say, you want
    /// to substitute a [`crate::UriClipAsset`] corresponding to a high resolution
    /// media file with the asset of a lower resolution stand in.
    ///
    /// An asset may even have several proxies, the first of which will act as
    /// its default and be returned on requests, but the others will be ordered
    /// to take its place once it is removed. You can add a proxy to an asset,
    /// or set its default, using [`crate::prelude::AssetExt::set_proxy()`], and you can remove
    /// them with [`crate::prelude::AssetExt::unproxy()`].
    ///
    /// # Implements
    ///
    /// [`trait@crate::prelude::AssetExt`], [`trait@glib::object::ObjectExt`]
    pub struct Asset(Object<ffi::GESAsset, ffi::GESAssetClass>);

    match fn {
        type_ => || ffi::ges_asset_get_type(),
    }
}

impl Asset {
    /// Indicate that an existing [`crate::Asset`] in the cache should be reloaded
    /// upon the next request. This can be used when some condition has
    /// changed, which may require that an existing asset should be updated.
    /// For example, if an external resource has changed or now become
    /// available.
    ///
    /// Note, the asset is not immediately changed, but will only actually
    /// reload on the next call to [`Self::request()`] or
    /// [`Self::request_async()`].
    /// ## `extractable_type`
    /// The [`crate::Asset:extractable-type`] of the asset that
    /// needs reloading
    /// ## `id`
    /// The [`crate::Asset:id`] of the asset asset that needs
    /// reloading
    ///
    /// # Returns
    ///
    /// [`true`] if the specified asset exists in the cache and could be
    /// marked for reloading.
    #[doc(alias = "ges_asset_needs_reload")]
    pub fn needs_reload(extractable_type: glib::types::Type, id: Option<&str>) -> bool {
        assert_initialized_main_thread!();
        unsafe {
            from_glib(ffi::ges_asset_needs_reload(
                extractable_type.into_glib(),
                id.to_glib_none().0,
            ))
        }
    }

    /// Returns an asset with the given properties. If such an asset already
    /// exists in the cache (it has been previously created in GES), then a
    /// reference to the existing asset is returned. Otherwise, a newly created
    /// asset is returned, and also added to the cache.
    ///
    /// If the requested asset has been loaded with an error, then `error` is
    /// set, if given, and [`None`] will be returned instead.
    ///
    /// Note that the given `id` may not be exactly the [`crate::Asset:id`] that is
    /// set on the returned asset. For instance, it may be adjusted into a
    /// standard format. Or, if a [`crate::Extractable`] type does not have its
    /// extraction parametrised, as is the case by default, then the given `id`
    /// may be ignored entirely and the [`crate::Asset:id`] set to some standard, in
    /// which case a [`None`] `id` can be given.
    ///
    /// Similarly, the given `extractable_type` may not be exactly the
    /// [`crate::Asset:extractable-type`] that is set on the returned asset. Instead,
    /// the actual extractable type may correspond to a subclass of the given
    /// `extractable_type`, depending on the given `id`.
    ///
    /// Moreover, depending on the given `extractable_type`, the returned asset
    /// may belong to a subclass of [`crate::Asset`].
    ///
    /// Finally, if the requested asset has a [`crate::Asset:proxy`], then the proxy
    /// that is found at the end of the chain of proxies is returned (a proxy's
    /// proxy will take its place, and so on, unless it has no proxy).
    ///
    /// Some asset subclasses only support asynchronous construction of its
    /// assets, such as [`crate::UriClip`]. For such assets this method will fail, and
    /// you should use [`Self::request_async()`] instead. In the case of
    /// [`crate::UriClip`], you can use [`crate::UriClipAsset::request_sync()`] if you only
    /// want to wait for the request to finish.
    /// ## `extractable_type`
    /// The [`crate::Asset:extractable-type`] of the asset
    /// ## `id`
    /// The [`crate::Asset:id`] of the asset
    ///
    /// # Returns
    ///
    /// A reference to the requested
    /// asset, or [`None`] if an error occurred.
    #[doc(alias = "ges_asset_request")]
    pub fn request(
        extractable_type: glib::types::Type,
        id: Option<&str>,
    ) -> Result<Option<Asset>, glib::Error> {
        assert_initialized_main_thread!();
        unsafe {
            let mut error = ptr::null_mut();
            let ret = ffi::ges_asset_request(
                extractable_type.into_glib(),
                id.to_glib_none().0,
                &mut error,
            );
            if error.is_null() {
                Ok(from_glib_full(ret))
            } else {
                Err(from_glib_full(error))
            }
        }
    }

    /// Requests an asset with the given properties asynchronously (see
    /// [`Self::request()`]). When the asset has been initialized or fetched
    /// from the cache, the given callback function will be called. The
    /// asset can then be retrieved in the callback using the
    /// [`Self::request_finish()`] method on the given [`crate::gio::AsyncResult`].
    ///
    /// Note that the source object passed to the callback will be the
    /// [`crate::Asset`] corresponding to the request, but it may not have loaded
    /// correctly and therefore can not be used as is. Instead,
    /// [`Self::request_finish()`] should be used to fetch a usable asset, or
    /// indicate that an error occurred in the asset's creation.
    ///
    /// Note that the callback will be called in the [`crate::glib::MainLoop`] running under
    /// the same [`crate::glib::MainContext`] that `ges_init()` was called in. So, if you wish
    /// the callback to be invoked outside the default [`crate::glib::MainContext`], you can
    /// call [`crate::glib::MainContext::push_thread_default()`] in a new thread before
    /// calling `ges_init()`.
    ///
    /// Example of an asynchronous asset request:
    /// ``` c
    /// // The request callback
    /// static void
    /// asset_loaded_cb (GESAsset * source, GAsyncResult * res, gpointer user_data)
    /// {
    ///   GESAsset *asset;
    ///   GError *error = NULL;
    ///
    ///   asset = ges_asset_request_finish (res, &error);
    ///   if (asset) {
    ///    g_print ("The file: %s is usable as a GESUriClip",
    ///        ges_asset_get_id (asset));
    ///   } else {
    ///    g_print ("The file: %s is *not* usable as a GESUriClip because: %s",
    ///        ges_asset_get_id (source), error->message);
    ///   }
    ///
    ///   gst_object_unref (asset);
    /// }
    ///
    /// // The request:
    /// ges_asset_request_async (GES_TYPE_URI_CLIP, some_uri, NULL,
    ///    (GAsyncReadyCallback) asset_loaded_cb, user_data);
    /// ```
    /// ## `extractable_type`
    /// The [`crate::Asset:extractable-type`] of the asset
    /// ## `id`
    /// The [`crate::Asset:id`] of the asset
    /// ## `cancellable`
    /// An object to allow cancellation of the
    /// asset request, or [`None`] to ignore
    /// ## `callback`
    /// A function to call when the initialization is finished
    /// ## `user_data`
    /// Data to be passed to `callback`
    #[doc(alias = "ges_asset_request_async")]
    pub fn request_async<
        P: IsA<gio::Cancellable>,
        Q: FnOnce(Result<Asset, glib::Error>) + Send + 'static,
    >(
        extractable_type: glib::types::Type,
        id: Option<&str>,
        cancellable: Option<&P>,
        callback: Q,
    ) {
        assert_initialized_main_thread!();
        let user_data: Box_<Q> = Box_::new(callback);
        unsafe extern "C" fn request_async_trampoline<
            Q: FnOnce(Result<Asset, glib::Error>) + Send + 'static,
        >(
            _source_object: *mut glib::gobject_ffi::GObject,
            res: *mut gio::ffi::GAsyncResult,
            user_data: glib::ffi::gpointer,
        ) {
            let mut error = ptr::null_mut();
            let ret = ffi::ges_asset_request_finish(res, &mut error);
            let result = if error.is_null() {
                Ok(from_glib_full(ret))
            } else {
                Err(from_glib_full(error))
            };
            let callback: Box_<Q> = Box_::from_raw(user_data as *mut _);
            callback(result);
        }
        let callback = request_async_trampoline::<Q>;
        unsafe {
            ffi::ges_asset_request_async(
                extractable_type.into_glib(),
                id.to_glib_none().0,
                cancellable.map(|p| p.as_ref()).to_glib_none().0,
                Some(callback),
                Box_::into_raw(user_data) as *mut _,
            );
        }
    }

    pub fn request_async_future(
        extractable_type: glib::types::Type,
        id: Option<&str>,
    ) -> Pin<Box_<dyn std::future::Future<Output = Result<Asset, glib::Error>> + 'static>> {
        skip_assert_initialized!();
        let id = id.map(ToOwned::to_owned);
        Box_::pin(gio::GioFuture::new(&(), move |_obj, send| {
            let cancellable = gio::Cancellable::new();
            Self::request_async(
                extractable_type,
                id.as_ref().map(::std::borrow::Borrow::borrow),
                Some(&cancellable),
                move |res| {
                    send.resolve(res);
                },
            );

            cancellable
        }))
    }
}

pub const NONE_ASSET: Option<&Asset> = None;

/// Trait containing all `Asset` methods.
///
/// # Implementors
///
/// [`struct@crate::Asset`], [`struct@crate::Project`]
pub trait AssetExt: 'static {
    /// Extracts a new [`crate::Asset:extractable-type`] object from the asset. The
    /// [`crate::Asset:id`] of the asset may determine the properties and state of the
    /// newly created object.
    ///
    /// # Returns
    ///
    /// A newly created object, or [`None`] if an
    /// error occurred.
    #[doc(alias = "ges_asset_extract")]
    fn extract(&self) -> Result<Extractable, glib::Error>;

    /// Retrieve the error that was set on the asset when it was loaded.
    ///
    /// # Returns
    ///
    /// The error set on `asset`, or
    /// [`None`] if no error occurred when `asset` was loaded.
    #[doc(alias = "ges_asset_get_error")]
    #[doc(alias = "get_error")]
    fn error(&self) -> Option<glib::Error>;

    /// Gets the [`crate::Asset:extractable-type`] of the asset.
    ///
    /// # Returns
    ///
    /// The extractable type of `self`.
    #[doc(alias = "ges_asset_get_extractable_type")]
    #[doc(alias = "get_extractable_type")]
    fn extractable_type(&self) -> glib::types::Type;

    /// Gets the [`crate::Asset:id`] of the asset.
    ///
    /// # Returns
    ///
    /// The ID of `self`.
    #[doc(alias = "ges_asset_get_id")]
    #[doc(alias = "get_id")]
    fn id(&self) -> Option<glib::GString>;

    /// Gets the default [`crate::Asset:proxy`] of the asset.
    ///
    /// # Returns
    ///
    /// The default proxy of `self`.
    #[doc(alias = "ges_asset_get_proxy")]
    #[doc(alias = "get_proxy")]
    fn proxy(&self) -> Option<Asset>;

    /// Gets the [`crate::Asset:proxy-target`] of the asset.
    ///
    /// Note that the proxy target may have loaded with an error, so you should
    /// call [`Self::get_error()`] on the returned target.
    ///
    /// # Returns
    ///
    /// The asset that `self` is a proxy
    /// of.
    #[doc(alias = "ges_asset_get_proxy_target")]
    #[doc(alias = "get_proxy_target")]
    fn proxy_target(&self) -> Option<Asset>;

    /// Get all the proxies that the asset has. The first item of the list will
    /// be the default [`crate::Asset:proxy`]. The second will be the proxy that is
    /// 'next in line' to be default, and so on.
    ///
    /// # Returns
    ///
    /// The list of proxies
    /// that `self` has.
    #[doc(alias = "ges_asset_list_proxies")]
    fn list_proxies(&self) -> Vec<Asset>;

    /// Sets the [`crate::Asset:proxy`] for the asset.
    ///
    /// If `proxy` is among the existing proxies of the asset (see
    /// [`Self::list_proxies()`]) it will be moved to become the default
    /// proxy. Otherwise, if `proxy` is not [`None`], it will be added to the list
    /// of proxies, as the new default. The previous default proxy will become
    /// 'next in line' for if the new one is removed, and so on. As such, this
    /// will **not** actually remove the previous default proxy (use
    /// [`Self::unproxy()`] for that).
    ///
    /// Note that an asset can only act as a proxy for one other asset.
    ///
    /// As a special case, if `proxy` is [`None`], then this method will actually
    /// remove **all** proxies from the asset.
    /// ## `proxy`
    /// A new default proxy for `self`
    ///
    /// # Returns
    ///
    /// [`true`] if `proxy` was successfully set as the default for
    /// `self`.
    #[doc(alias = "ges_asset_set_proxy")]
    fn set_proxy<P: IsA<Asset>>(&self, proxy: Option<&P>) -> Result<(), glib::error::BoolError>;

    /// Removes the proxy from the available list of proxies for the asset. If
    /// the given proxy is the default proxy of the list, then the next proxy
    /// in the available list (see [`Self::list_proxies()`]) will become the
    /// default. If there are no other proxies, then the asset will no longer
    /// have a default [`crate::Asset:proxy`].
    /// ## `proxy`
    /// An existing proxy of `self`
    ///
    /// # Returns
    ///
    /// [`true`] if `proxy` was successfully removed from `self`'s proxy
    /// list.
    #[doc(alias = "ges_asset_unproxy")]
    fn unproxy<P: IsA<Asset>>(&self, proxy: &P) -> Result<(), glib::error::BoolError>;

    #[doc(alias = "proxy")]
    fn connect_proxy_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;

    #[doc(alias = "proxy-target")]
    fn connect_proxy_target_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
}

impl<O: IsA<Asset>> AssetExt for O {
    fn extract(&self) -> Result<Extractable, glib::Error> {
        unsafe {
            let mut error = ptr::null_mut();
            let ret = ffi::ges_asset_extract(self.as_ref().to_glib_none().0, &mut error);
            if error.is_null() {
                Ok(from_glib_none(ret))
            } else {
                Err(from_glib_full(error))
            }
        }
    }

    fn error(&self) -> Option<glib::Error> {
        unsafe { from_glib_none(ffi::ges_asset_get_error(self.as_ref().to_glib_none().0)) }
    }

    fn extractable_type(&self) -> glib::types::Type {
        unsafe {
            from_glib(ffi::ges_asset_get_extractable_type(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    fn id(&self) -> Option<glib::GString> {
        unsafe { from_glib_none(ffi::ges_asset_get_id(self.as_ref().to_glib_none().0)) }
    }

    fn proxy(&self) -> Option<Asset> {
        unsafe { from_glib_none(ffi::ges_asset_get_proxy(self.as_ref().to_glib_none().0)) }
    }

    fn proxy_target(&self) -> Option<Asset> {
        unsafe {
            from_glib_none(ffi::ges_asset_get_proxy_target(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    fn list_proxies(&self) -> Vec<Asset> {
        unsafe {
            FromGlibPtrContainer::from_glib_none(ffi::ges_asset_list_proxies(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    fn set_proxy<P: IsA<Asset>>(&self, proxy: Option<&P>) -> Result<(), glib::error::BoolError> {
        unsafe {
            glib::result_from_gboolean!(
                ffi::ges_asset_set_proxy(
                    self.as_ref().to_glib_none().0,
                    proxy.map(|p| p.as_ref()).to_glib_none().0
                ),
                "Failed to set proxy"
            )
        }
    }

    fn unproxy<P: IsA<Asset>>(&self, proxy: &P) -> Result<(), glib::error::BoolError> {
        unsafe {
            glib::result_from_gboolean!(
                ffi::ges_asset_unproxy(
                    self.as_ref().to_glib_none().0,
                    proxy.as_ref().to_glib_none().0
                ),
                "Failed to unproxy asset"
            )
        }
    }

    #[doc(alias = "proxy")]
    fn connect_proxy_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_proxy_trampoline<P, F: Fn(&P) + 'static>(
            this: *mut ffi::GESAsset,
            _param_spec: glib::ffi::gpointer,
            f: glib::ffi::gpointer,
        ) where
            P: IsA<Asset>,
        {
            let f: &F = &*(f as *const F);
            f(&Asset::from_glib_borrow(this).unsafe_cast_ref())
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"notify::proxy\0".as_ptr() as *const _,
                Some(transmute::<_, unsafe extern "C" fn()>(
                    notify_proxy_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    #[doc(alias = "proxy-target")]
    fn connect_proxy_target_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_proxy_target_trampoline<P, F: Fn(&P) + 'static>(
            this: *mut ffi::GESAsset,
            _param_spec: glib::ffi::gpointer,
            f: glib::ffi::gpointer,
        ) where
            P: IsA<Asset>,
        {
            let f: &F = &*(f as *const F);
            f(&Asset::from_glib_borrow(this).unsafe_cast_ref())
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"notify::proxy-target\0".as_ptr() as *const _,
                Some(transmute::<_, unsafe extern "C" fn()>(
                    notify_proxy_target_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }
}