Commit 0629a028 authored by Sebastian Dröge's avatar Sebastian Dröge 🍵

Use SendValue instead of Value for all our GValue usage

We require types that can be sent between threads.
parent 9734ec29
......@@ -16,7 +16,7 @@ use CapsIntersectMode;
use glib;
use ffi;
use glib::translate::{from_glib, from_glib_full, ToGlib, ToGlibPtr};
use glib::value::ToValue;
use glib::value::ToSendValue;
#[repr(C)]
pub struct CapsRef(ffi::GstCaps);
......@@ -43,7 +43,7 @@ impl GstRc<CapsRef> {
unsafe { from_glib_full(ffi::gst_caps_new_any()) }
}
pub fn new_simple(name: &str, values: &[(&str, &ToValue)]) -> Self {
pub fn new_simple(name: &str, values: &[(&str, &ToSendValue)]) -> Self {
assert_initialized_main_thread!();
let mut caps = Caps::new_empty();
......@@ -117,7 +117,7 @@ impl str::FromStr for Caps {
}
impl CapsRef {
pub fn set_simple(&mut self, values: &[(&str, &ToValue)]) {
pub fn set_simple(&mut self, values: &[(&str, &ToSendValue)]) {
for &(name, value) in values {
let value = value.to_value();
......@@ -382,7 +382,7 @@ impl Builder {
}
}
pub fn field<V: ToValue>(mut self, name: &str, value: V) -> Self {
pub fn field<V: ToSendValue>(mut self, name: &str, value: V) -> Self {
self.s.set(name, value);
self
}
......
This diff is collapsed.
This diff is collapsed.
......@@ -20,12 +20,13 @@ use Fraction;
use glib;
use glib::translate::{from_glib, from_glib_full, from_glib_none, FromGlibPtrFull, FromGlibPtrNone,
GlibPtrDefault, Stash, StashMut, ToGlib, ToGlibPtr, ToGlibPtrMut};
use glib::value::{FromValueOptional, ToValue, Value};
use glib::value::{FromValueOptional, ToSendValue, SendValue};
use ffi;
use glib_ffi::gpointer;
use gobject_ffi;
pub struct Structure(*mut StructureRef, PhantomData<StructureRef>);
unsafe impl Send for Structure { }
impl Structure {
pub fn builder(name: &str) -> Builder {
......@@ -41,12 +42,12 @@ impl Structure {
)
}
pub fn new(name: &str, values: &[(&str, &ToValue)]) -> Structure {
pub fn new(name: &str, values: &[(&str, &ToSendValue)]) -> Structure {
assert_initialized_main_thread!();
let mut structure = Structure::new_empty(name);
for &(f, v) in values {
structure.set_value(f, v.to_value());
structure.set_value(f, v.to_send_value());
}
structure
......@@ -288,11 +289,11 @@ impl StructureRef {
unsafe { from_glib_full(ffi::gst_structure_to_string(&self.0)) }
}
pub fn get<'a, T: FromValueOptional<'a>>(&'a self, name: &str) -> Option<T> {
pub fn get<'a, T: FromValueOptional<'a> + Send>(&'a self, name: &str) -> Option<T> {
self.get_value(name).and_then(|v| v.get())
}
pub fn get_value<'a>(&'a self, name: &str) -> Option<&Value> {
pub fn get_value<'a>(&'a self, name: &str) -> Option<&SendValue> {
unsafe {
let value = ffi::gst_structure_get_value(&self.0, name.to_glib_none().0);
......@@ -300,16 +301,16 @@ impl StructureRef {
return None;
}
Some(&*(value as *const Value))
Some(&*(value as *const SendValue))
}
}
pub fn set<T: ToValue>(&mut self, name: &str, value: T) {
let value = value.to_value();
pub fn set<T: ToSendValue>(&mut self, name: &str, value: T) {
let value = value.to_send_value();
self.set_value(name, value);
}
pub fn set_value(&mut self, name: &str, mut value: Value) {
pub fn set_value(&mut self, name: &str, mut value: SendValue) {
unsafe {
ffi::gst_structure_take_value(
&mut self.0,
......@@ -567,9 +568,9 @@ impl<'a> Iter<'a> {
}
impl<'a> Iterator for Iter<'a> {
type Item = (&'a str, &'a Value);
type Item = (&'a str, &'a SendValue);
fn next(&mut self) -> Option<(&'a str, &'a Value)> {
fn next(&mut self) -> Option<(&'a str, &'a SendValue)> {
if let Some(f) = self.iter.next() {
let v = self.iter.structure.get_value(f);
Some((f, v.unwrap()))
......@@ -607,7 +608,7 @@ impl Builder {
}
}
pub fn field<V: ToValue>(mut self, name: &str, value: V) -> Self {
pub fn field<V: ToSendValue>(mut self, name: &str, value: V) -> Self {
self.s.set(name, value);
self
}
......
......@@ -11,22 +11,22 @@ use TagSetter;
use TagMergeMode;
use glib::object::IsA;
use glib::translate::*;
use glib::value::ToValue;
use glib::value::ToSendValue;
use tags::*;
pub trait TagSetterExtManual {
fn add<'a, T: Tag<'a>>(&mut self, value: T::TagType, mode: TagMergeMode)
where
T::TagType: ToValue;
T::TagType: ToSendValue;
}
impl<O: IsA<TagSetter>> TagSetterExtManual for O {
fn add<'a, T: Tag<'a>>(&mut self, value: T::TagType, mode: TagMergeMode)
where
T::TagType: ToValue,
T::TagType: ToSendValue,
{
unsafe {
let v = value.to_value();
let v = value.to_send_value();
ffi::gst_tag_setter_add_tag_value(
self.to_glib_none().0,
......
......@@ -14,7 +14,7 @@ use std::ffi::CStr;
use ffi;
use glib;
use glib::StaticType;
use glib::value::{FromValueOptional, SetValue, ToValue, TypedValue, Value};
use glib::value::{FromValueOptional, SetValue, ToSendValue, TypedValue, Value};
use glib::translate::{from_glib, from_glib_full, ToGlib, ToGlibPtr, ToGlibPtrMut};
use miniobject::*;
......@@ -23,7 +23,7 @@ use TagMergeMode;
use Sample;
pub trait Tag<'a> {
type TagType: FromValueOptional<'a> + SetValue;
type TagType: FromValueOptional<'a> + SetValue + Send;
fn tag_name<'b>() -> &'b str;
}
......@@ -257,10 +257,10 @@ impl Default for GstRc<TagListRef> {
impl TagListRef {
pub fn add<'a, T: Tag<'a>>(&mut self, value: T::TagType, mode: TagMergeMode)
where
T::TagType: ToValue,
T::TagType: ToSendValue,
{
unsafe {
let v = value.to_value();
let v = value.to_send_value();
ffi::gst_tag_list_add_value(
self.as_mut_ptr(),
......
......@@ -524,6 +524,8 @@ impl SetValue for Bitmask {
#[derive(Clone, Debug)]
pub struct Array<'a>(Cow<'a, [glib::Value]>);
unsafe impl<'a> Send for Array<'a> {}
impl<'a> Array<'a> {
pub fn new(values: &[&ToValue]) -> Self {
assert_initialized_main_thread!();
......@@ -593,6 +595,8 @@ impl<'a> glib::types::StaticType for Array<'a> {
#[derive(Clone, Debug)]
pub struct List<'a>(Cow<'a, [glib::Value]>);
unsafe impl<'a> Send for List<'a> {}
impl<'a> List<'a> {
pub fn new(values: &[&ToValue]) -> Self {
assert_initialized_main_thread!();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment