Commit 4eb3d879 authored by Sebastian Dröge's avatar Sebastian Dröge 🍵
Browse files

Move FFI usage out of actual Sink/Source implementations

parent e1d2751f
......@@ -49,8 +49,7 @@ extern "C" {
classification: *const c_char,
author: *const c_char,
rank: i32,
create_instance: extern "C" fn(controller: SourceController)
-> *mut Box<Source>,
create_instance: fn(controller: SourceController) -> Box<Source>,
protocols: *const c_char,
push_only: GBoolean)
-> GBoolean;
......@@ -64,8 +63,7 @@ extern "C" {
classification: *const c_char,
author: *const c_char,
rank: i32,
create_instance: extern "C" fn(controller: SinkController)
-> *mut Box<Sink>,
create_instance: fn(controller: SinkController) -> Box<Sink>,
protocols: *const c_char)
-> GBoolean;
}
......@@ -83,7 +81,7 @@ pub extern "C" fn sources_register(plugin: *const c_void) -> GBoolean {
.unwrap()
.as_ptr(),
256 + 100,
FileSrc::new_ptr,
FileSrc::new_boxed,
CString::new("file").unwrap().as_ptr(),
GBoolean::False);
......@@ -96,7 +94,7 @@ pub extern "C" fn sources_register(plugin: *const c_void) -> GBoolean {
.unwrap()
.as_ptr(),
256 + 100,
HttpSrc::new_ptr,
HttpSrc::new_boxed,
CString::new("http:https").unwrap().as_ptr(),
GBoolean::True);
}
......@@ -117,7 +115,7 @@ pub extern "C" fn sinks_register(plugin: *const c_void) -> GBoolean {
.unwrap()
.as_ptr(),
256 + 100,
FileSink::new_ptr,
FileSink::new_boxed,
CString::new("file").unwrap().as_ptr());
}
return GBoolean::True;
......
......@@ -38,7 +38,7 @@ unsafe impl Sync for FileSink {}
unsafe impl Send for FileSink {}
impl FileSink {
fn new(controller: SinkController) -> FileSink {
pub fn new(controller: SinkController) -> FileSink {
FileSink {
controller: controller,
location: Mutex::new(None),
......@@ -47,9 +47,8 @@ impl FileSink {
}
}
pub extern "C" fn new_ptr(controller: SinkController) -> *mut Box<Sink> {
let instance: Box<Box<Sink>> = Box::new(Box::new(FileSink::new(controller)));
return Box::into_raw(instance);
pub fn new_boxed(controller: SinkController) -> Box<Sink> {
Box::new(FileSink::new(controller))
}
}
......
......@@ -39,7 +39,7 @@ unsafe impl Sync for FileSrc {}
unsafe impl Send for FileSrc {}
impl FileSrc {
fn new(controller: SourceController) -> FileSrc {
pub fn new(controller: SourceController) -> FileSrc {
FileSrc {
controller: controller,
location: Mutex::new(None),
......@@ -48,9 +48,8 @@ impl FileSrc {
}
}
pub extern "C" fn new_ptr(controller: SourceController) -> *mut Box<Source> {
let instance: Box<Box<Source>> = Box::new(Box::new(FileSrc::new(controller)));
return Box::into_raw(instance);
pub fn new_boxed(controller: SourceController) -> Box<Source> {
Box::new(FileSrc::new(controller))
}
}
......
......@@ -47,7 +47,7 @@ unsafe impl Sync for HttpSrc {}
unsafe impl Send for HttpSrc {}
impl HttpSrc {
fn new(controller: SourceController) -> HttpSrc {
pub fn new(controller: SourceController) -> HttpSrc {
HttpSrc {
controller: controller,
url: Mutex::new(None),
......@@ -61,9 +61,8 @@ impl HttpSrc {
}
}
pub extern "C" fn new_ptr(controller: SourceController) -> *mut Box<Source> {
let instance: Box<Box<Source>> = Box::new(Box::new(HttpSrc::new(controller)));
return Box::into_raw(instance);
pub fn new_boxed(controller: SourceController) -> Box<Source> {
Box::new(HttpSrc::new(controller))
}
pub fn do_request(&mut self, start: u64, stop: u64) -> bool {
......
......@@ -51,10 +51,9 @@ pub trait Sink: Sync + Send {
#[no_mangle]
pub extern "C" fn sink_new(sink: *mut c_void,
create_instance: extern "C" fn(controller: SinkController)
-> *mut Box<Sink>)
create_instance: fn(controller: SinkController) -> Box<Sink>)
-> *mut Box<Sink> {
create_instance(SinkController::new(sink))
Box::into_raw(Box::new(create_instance(SinkController::new(sink))))
}
#[no_mangle]
......
......@@ -55,10 +55,9 @@ pub trait Source: Sync + Send {
#[no_mangle]
pub extern "C" fn source_new(source: *mut c_void,
create_instance: extern "C" fn(controller: SourceController)
-> *mut Box<Source>)
create_instance: fn(controller: SourceController) -> Box<Source>)
-> *mut Box<Source> {
create_instance(SourceController::new(source))
Box::into_raw(Box::new(create_instance(SourceController::new(source))))
}
#[no_mangle]
......
Supports Markdown
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