Update for new #[glib::object_subclass] attribute macro

This commit is contained in:
Sebastian Dröge 2021-03-07 13:08:06 +02:00
parent c58f2b09d2
commit b8c20c07ce
4 changed files with 13 additions and 91 deletions

View file

@ -78,9 +78,7 @@ fn main_loop() -> Result<(), Error> {
mod media_factory { mod media_factory {
use super::*; use super::*;
use glib::subclass;
use glib::subclass::prelude::*; use glib::subclass::prelude::*;
use gst_rtsp_server::subclass::prelude::*; use gst_rtsp_server::subclass::prelude::*;
// In the imp submodule we include the actual implementation // In the imp submodule we include the actual implementation
@ -88,27 +86,17 @@ mod media_factory {
use super::*; use super::*;
// This is the private data of our factory // This is the private data of our factory
#[derive(Default)]
pub struct Factory {} pub struct Factory {}
// This trait registers our type with the GObject object system and // This trait registers our type with the GObject object system and
// provides the entry points for creating a new instance and setting // provides the entry points for creating a new instance and setting
// up the class data // up the class data
#[glib::object_subclass]
impl ObjectSubclass for Factory { impl ObjectSubclass for Factory {
const NAME: &'static str = "RsRTSPMediaFactory"; const NAME: &'static str = "RsRTSPMediaFactory";
type Type = super::Factory; type Type = super::Factory;
type ParentType = gst_rtsp_server::RTSPMediaFactory; type ParentType = gst_rtsp_server::RTSPMediaFactory;
type Interfaces = ();
type Instance = gst::subclass::ElementInstanceStruct<Self>;
type Class = subclass::simple::ClassStruct<Self>;
// 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 // 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 // Our custom media subclass that adds a custom attribute to the SDP returned by DESCRIBE
mod media { mod media {
use glib::subclass;
use glib::subclass::prelude::*; use glib::subclass::prelude::*;
use gst_rtsp_server::subclass::prelude::*; use gst_rtsp_server::subclass::prelude::*;
// In the imp submodule we include the actual implementation // In the imp submodule we include the actual implementation
@ -182,27 +168,17 @@ mod media {
use super::*; use super::*;
// This is the private data of our media // This is the private data of our media
#[derive(Default)]
pub struct Media {} pub struct Media {}
// This trait registers our type with the GObject object system and // This trait registers our type with the GObject object system and
// provides the entry points for creating a new instance and setting // provides the entry points for creating a new instance and setting
// up the class data // up the class data
#[glib::object_subclass]
impl ObjectSubclass for Media { impl ObjectSubclass for Media {
const NAME: &'static str = "RsRTSPMedia"; const NAME: &'static str = "RsRTSPMedia";
type Type = super::Media; type Type = super::Media;
type ParentType = gst_rtsp_server::RTSPMedia; type ParentType = gst_rtsp_server::RTSPMedia;
type Interfaces = ();
type Instance = gst::subclass::ElementInstanceStruct<Self>;
type Class = subclass::simple::ClassStruct<Self>;
// 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 // Implementation of glib::Object virtual methods
@ -241,9 +217,7 @@ mod media {
mod server { mod server {
use super::*; use super::*;
use glib::subclass;
use glib::subclass::prelude::*; use glib::subclass::prelude::*;
use gst_rtsp_server::subclass::prelude::*; use gst_rtsp_server::subclass::prelude::*;
// In the imp submodule we include the actual implementation // In the imp submodule we include the actual implementation
@ -251,27 +225,17 @@ mod server {
use super::*; use super::*;
// This is the private data of our server // This is the private data of our server
#[derive(Default)]
pub struct Server {} pub struct Server {}
// This trait registers our type with the GObject object system and // This trait registers our type with the GObject object system and
// provides the entry points for creating a new instance and setting // provides the entry points for creating a new instance and setting
// up the class data // up the class data
#[glib::object_subclass]
impl ObjectSubclass for Server { impl ObjectSubclass for Server {
const NAME: &'static str = "RsRTSPServer"; const NAME: &'static str = "RsRTSPServer";
type Type = super::Server; type Type = super::Server;
type ParentType = gst_rtsp_server::RTSPServer; type ParentType = gst_rtsp_server::RTSPServer;
type Interfaces = ();
type Instance = gst::subclass::ElementInstanceStruct<Self>;
type Class = subclass::simple::ClassStruct<Self>;
// 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 // Implementation of glib::Object virtual methods
@ -318,9 +282,7 @@ mod server {
// Our custom RTSP client subclass. // Our custom RTSP client subclass.
mod client { mod client {
use glib::subclass;
use glib::subclass::prelude::*; use glib::subclass::prelude::*;
use gst_rtsp_server::subclass::prelude::*; use gst_rtsp_server::subclass::prelude::*;
// In the imp submodule we include the actual implementation // In the imp submodule we include the actual implementation
@ -328,27 +290,17 @@ mod client {
use super::*; use super::*;
// This is the private data of our server // This is the private data of our server
#[derive(Default)]
pub struct Client {} pub struct Client {}
// This trait registers our type with the GObject object system and // This trait registers our type with the GObject object system and
// provides the entry points for creating a new instance and setting // provides the entry points for creating a new instance and setting
// up the class data // up the class data
#[glib::object_subclass]
impl ObjectSubclass for Client { impl ObjectSubclass for Client {
const NAME: &'static str = "RsRTSPClient"; const NAME: &'static str = "RsRTSPClient";
type Type = super::Client; type Type = super::Client;
type ParentType = gst_rtsp_server::RTSPClient; type ParentType = gst_rtsp_server::RTSPClient;
type Interfaces = ();
type Instance = gst::subclass::ElementInstanceStruct<Self>;
type Class = subclass::simple::ClassStruct<Self>;
// 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 // Implementation of glib::Object virtual methods

View file

@ -19,11 +19,8 @@ mod examples_common;
mod fir_filter { mod fir_filter {
use super::*; use super::*;
use glib::subclass;
use glib::subclass::prelude::*; use glib::subclass::prelude::*;
use gst::subclass::prelude::*; use gst::subclass::prelude::*;
use gst_base::subclass::prelude::*; use gst_base::subclass::prelude::*;
use byte_slice_cast::*; use byte_slice_cast::*;
@ -47,6 +44,7 @@ mod fir_filter {
use std::sync::Mutex; use std::sync::Mutex;
// This is the private data of our filter // This is the private data of our filter
#[derive(Default)]
pub struct FirFilter { pub struct FirFilter {
pub(super) coeffs: Mutex<Vec<f32>>, pub(super) coeffs: Mutex<Vec<f32>>,
history: Mutex<VecDeque<f32>>, history: Mutex<VecDeque<f32>>,
@ -55,25 +53,12 @@ mod fir_filter {
// This trait registers our type with the GObject object system and // This trait registers our type with the GObject object system and
// provides the entry points for creating a new instance and setting // provides the entry points for creating a new instance and setting
// up the class data // up the class data
#[glib::object_subclass]
impl ObjectSubclass for FirFilter { impl ObjectSubclass for FirFilter {
const NAME: &'static str = "RsFirFilter"; const NAME: &'static str = "RsFirFilter";
type Type = super::FirFilter; type Type = super::FirFilter;
type ParentType = gst_base::BaseTransform; type ParentType = gst_base::BaseTransform;
type Interfaces = ();
type Instance = gst::subclass::ElementInstanceStruct<Self>; type Instance = gst::subclass::ElementInstanceStruct<Self>;
type Class = subclass::simple::ClassStruct<Self>;
// 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 // Implementation of glib::Object virtual methods

View file

@ -589,7 +589,6 @@ where
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;
use glib::subclass;
use std::sync::atomic; use std::sync::atomic;
use crate::ElementFactory; use crate::ElementFactory;
@ -652,15 +651,12 @@ mod tests {
} }
} }
#[glib::object_subclass]
impl ObjectSubclass for TestElement { impl ObjectSubclass for TestElement {
const NAME: &'static str = "TestElement"; const NAME: &'static str = "TestElement";
type Type = super::TestElement; type Type = super::TestElement;
type ParentType = Element; type ParentType = Element;
type Interfaces = ();
type Instance = crate::subclass::ElementInstanceStruct<Self>; type Instance = crate::subclass::ElementInstanceStruct<Self>;
type Class = subclass::simple::ClassStruct<Self>;
glib::object_subclass!();
fn with_class(klass: &Self::Class) -> Self { fn with_class(klass: &Self::Class) -> Self {
let templ = klass.get_pad_template("sink").unwrap(); let templ = klass.get_pad_template("sink").unwrap();

View file

@ -87,7 +87,6 @@ unsafe extern "C" fn pad_unlinked<T: PadImpl>(ptr: *mut ffi::GstPad, peer: *mut
mod tests { mod tests {
use super::*; use super::*;
use crate::prelude::*; use crate::prelude::*;
use glib::subclass;
use std::sync::atomic; use std::sync::atomic;
use crate::PadDirection; use crate::PadDirection;
@ -95,27 +94,17 @@ mod tests {
pub mod imp { pub mod imp {
use super::*; use super::*;
#[derive(Default)]
pub struct TestPad { pub struct TestPad {
pub(super) linked: atomic::AtomicBool, pub(super) linked: atomic::AtomicBool,
pub(super) unlinked: atomic::AtomicBool, pub(super) unlinked: atomic::AtomicBool,
} }
#[glib::object_subclass]
impl ObjectSubclass for TestPad { impl ObjectSubclass for TestPad {
const NAME: &'static str = "TestPad"; const NAME: &'static str = "TestPad";
type Type = super::TestPad; type Type = super::TestPad;
type ParentType = Pad; type ParentType = Pad;
type Interfaces = ();
type Instance = subclass::simple::InstanceStruct<Self>;
type Class = subclass::simple::ClassStruct<Self>;
glib::object_subclass!();
fn new() -> Self {
Self {
linked: atomic::AtomicBool::new(false),
unlinked: atomic::AtomicBool::new(false),
}
}
} }
impl ObjectImpl for TestPad {} impl ObjectImpl for TestPad {}