From b8c20c07ce2a18f4c03431d16c64f8cc60d62a55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Sun, 7 Mar 2021 13:08:06 +0200 Subject: [PATCH] Update for new #[glib::object_subclass] attribute macro --- examples/src/bin/rtsp-server-subclass.rs | 64 +++--------------------- examples/src/bin/subclass.rs | 19 +------ gstreamer/src/subclass/element.rs | 6 +-- gstreamer/src/subclass/pad.rs | 15 +----- 4 files changed, 13 insertions(+), 91 deletions(-) diff --git a/examples/src/bin/rtsp-server-subclass.rs b/examples/src/bin/rtsp-server-subclass.rs index 499e12fa6..d3df47572 100644 --- a/examples/src/bin/rtsp-server-subclass.rs +++ b/examples/src/bin/rtsp-server-subclass.rs @@ -78,9 +78,7 @@ fn main_loop() -> Result<(), Error> { mod media_factory { use super::*; - use glib::subclass; use glib::subclass::prelude::*; - use gst_rtsp_server::subclass::prelude::*; // In the imp submodule we include the actual implementation @@ -88,27 +86,17 @@ mod media_factory { use super::*; // This is the private data of our factory + #[derive(Default)] pub struct Factory {} // This trait registers our type with the GObject object system and // provides the entry points for creating a new instance and setting // up the class data + #[glib::object_subclass] impl ObjectSubclass for Factory { const NAME: &'static str = "RsRTSPMediaFactory"; type Type = super::Factory; type ParentType = gst_rtsp_server::RTSPMediaFactory; - type Interfaces = (); - type Instance = gst::subclass::ElementInstanceStruct; - type Class = subclass::simple::ClassStruct; - - // This macro provides some boilerplate - glib::object_subclass!(); - - // Called when a new instance is to be created. We need to return an instance - // of our struct here. - fn new() -> Self { - Self {} - } } // Implementation of glib::Object virtual methods @@ -172,9 +160,7 @@ mod media_factory { // Our custom media subclass that adds a custom attribute to the SDP returned by DESCRIBE mod media { - use glib::subclass; use glib::subclass::prelude::*; - use gst_rtsp_server::subclass::prelude::*; // In the imp submodule we include the actual implementation @@ -182,27 +168,17 @@ mod media { use super::*; // This is the private data of our media + #[derive(Default)] pub struct Media {} // This trait registers our type with the GObject object system and // provides the entry points for creating a new instance and setting // up the class data + #[glib::object_subclass] impl ObjectSubclass for Media { const NAME: &'static str = "RsRTSPMedia"; type Type = super::Media; type ParentType = gst_rtsp_server::RTSPMedia; - type Interfaces = (); - type Instance = gst::subclass::ElementInstanceStruct; - type Class = subclass::simple::ClassStruct; - - // This macro provides some boilerplate - glib::object_subclass!(); - - // Called when a new instance is to be created. We need to return an instance - // of our struct here. - fn new() -> Self { - Self {} - } } // Implementation of glib::Object virtual methods @@ -241,9 +217,7 @@ mod media { mod server { use super::*; - use glib::subclass; use glib::subclass::prelude::*; - use gst_rtsp_server::subclass::prelude::*; // In the imp submodule we include the actual implementation @@ -251,27 +225,17 @@ mod server { use super::*; // This is the private data of our server + #[derive(Default)] pub struct Server {} // This trait registers our type with the GObject object system and // provides the entry points for creating a new instance and setting // up the class data + #[glib::object_subclass] impl ObjectSubclass for Server { const NAME: &'static str = "RsRTSPServer"; type Type = super::Server; type ParentType = gst_rtsp_server::RTSPServer; - type Interfaces = (); - type Instance = gst::subclass::ElementInstanceStruct; - type Class = subclass::simple::ClassStruct; - - // This macro provides some boilerplate - glib::object_subclass!(); - - // Called when a new instance is to be created. We need to return an instance - // of our struct here. - fn new() -> Self { - Self {} - } } // Implementation of glib::Object virtual methods @@ -318,9 +282,7 @@ mod server { // Our custom RTSP client subclass. mod client { - use glib::subclass; use glib::subclass::prelude::*; - use gst_rtsp_server::subclass::prelude::*; // In the imp submodule we include the actual implementation @@ -328,27 +290,17 @@ mod client { use super::*; // This is the private data of our server + #[derive(Default)] pub struct Client {} // This trait registers our type with the GObject object system and // provides the entry points for creating a new instance and setting // up the class data + #[glib::object_subclass] impl ObjectSubclass for Client { const NAME: &'static str = "RsRTSPClient"; type Type = super::Client; type ParentType = gst_rtsp_server::RTSPClient; - type Interfaces = (); - type Instance = gst::subclass::ElementInstanceStruct; - type Class = subclass::simple::ClassStruct; - - // This macro provides some boilerplate - glib::object_subclass!(); - - // Called when a new instance is to be created. We need to return an instance - // of our struct here. - fn new() -> Self { - Self {} - } } // Implementation of glib::Object virtual methods diff --git a/examples/src/bin/subclass.rs b/examples/src/bin/subclass.rs index 54fc7472b..9a4567362 100644 --- a/examples/src/bin/subclass.rs +++ b/examples/src/bin/subclass.rs @@ -19,11 +19,8 @@ mod examples_common; mod fir_filter { use super::*; - use glib::subclass; use glib::subclass::prelude::*; - use gst::subclass::prelude::*; - use gst_base::subclass::prelude::*; use byte_slice_cast::*; @@ -47,6 +44,7 @@ mod fir_filter { use std::sync::Mutex; // This is the private data of our filter + #[derive(Default)] pub struct FirFilter { pub(super) coeffs: Mutex>, history: Mutex>, @@ -55,25 +53,12 @@ mod fir_filter { // This trait registers our type with the GObject object system and // provides the entry points for creating a new instance and setting // up the class data + #[glib::object_subclass] impl ObjectSubclass for FirFilter { const NAME: &'static str = "RsFirFilter"; type Type = super::FirFilter; type ParentType = gst_base::BaseTransform; - type Interfaces = (); type Instance = gst::subclass::ElementInstanceStruct; - type Class = subclass::simple::ClassStruct; - - // This macro provides some boilerplate - glib::object_subclass!(); - - // Called when a new instance is to be created. We need to return an instance - // of our struct here. - fn new() -> Self { - Self { - coeffs: Mutex::new(Vec::new()), - history: Mutex::new(VecDeque::new()), - } - } } // Implementation of glib::Object virtual methods diff --git a/gstreamer/src/subclass/element.rs b/gstreamer/src/subclass/element.rs index 578b8f4f9..81994c6c5 100644 --- a/gstreamer/src/subclass/element.rs +++ b/gstreamer/src/subclass/element.rs @@ -589,7 +589,6 @@ where #[cfg(test)] mod tests { use super::*; - use glib::subclass; use std::sync::atomic; use crate::ElementFactory; @@ -652,15 +651,12 @@ mod tests { } } + #[glib::object_subclass] impl ObjectSubclass for TestElement { const NAME: &'static str = "TestElement"; type Type = super::TestElement; type ParentType = Element; - type Interfaces = (); type Instance = crate::subclass::ElementInstanceStruct; - type Class = subclass::simple::ClassStruct; - - glib::object_subclass!(); fn with_class(klass: &Self::Class) -> Self { let templ = klass.get_pad_template("sink").unwrap(); diff --git a/gstreamer/src/subclass/pad.rs b/gstreamer/src/subclass/pad.rs index 7da9b09d8..495c08d5b 100644 --- a/gstreamer/src/subclass/pad.rs +++ b/gstreamer/src/subclass/pad.rs @@ -87,7 +87,6 @@ unsafe extern "C" fn pad_unlinked(ptr: *mut ffi::GstPad, peer: *mut mod tests { use super::*; use crate::prelude::*; - use glib::subclass; use std::sync::atomic; use crate::PadDirection; @@ -95,27 +94,17 @@ mod tests { pub mod imp { use super::*; + #[derive(Default)] pub struct TestPad { pub(super) linked: atomic::AtomicBool, pub(super) unlinked: atomic::AtomicBool, } + #[glib::object_subclass] impl ObjectSubclass for TestPad { const NAME: &'static str = "TestPad"; type Type = super::TestPad; type ParentType = Pad; - type Interfaces = (); - type Instance = subclass::simple::InstanceStruct; - type Class = subclass::simple::ClassStruct; - - glib::object_subclass!(); - - fn new() -> Self { - Self { - linked: atomic::AtomicBool::new(false), - unlinked: atomic::AtomicBool::new(false), - } - } } impl ObjectImpl for TestPad {}