From e8ed9ace0b7e2aed2bd0c6b99a6787da411ad9cb Mon Sep 17 00:00:00 2001 From: Kjetil Orbekk Date: Tue, 9 Aug 2016 22:25:34 -0400 Subject: Add list_operations(). --- src/gegl.rs | 28 +++++++++++++++++++++++++--- src/gegl_ffi.rs | 8 +++++++- 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/src/gegl.rs b/src/gegl.rs index b03fca1..0ffdf9c 100644 --- a/src/gegl.rs +++ b/src/gegl.rs @@ -3,6 +3,7 @@ extern crate libc; use gegl_ffi as ffi; use std::ptr; use std::ffi::CString; +use std::ffi::CStr; pub struct GeglContext { _private: () @@ -46,15 +47,36 @@ impl Drop for GeglNode { } } +pub fn list_operations() -> Vec { + let mut num_operations: usize = 0; + let mut result = vec!(); + unsafe { + let operations = + ffi::gegl_list_operations(&mut num_operations as *mut _); + for i in 0..(num_operations as isize) { + result.push(CStr::from_ptr(*operations.offset(i)) + .to_string_lossy().to_string()); + } + ffi::g_free(operations as *mut libc::c_void); + } + result +} + #[cfg(test)] mod tests { use super::*; use gegl_ffi as ffi; #[test] - fn can_create_nodes() { + fn implements_all_operations() { let context = GeglContext::new(); - let node = context.new_node(); - let node2 = context.new_node(); + assert_eq!(Vec::::new(), list_operations()); } + + // #[test] + // fn can_create_nodes() { + // let context = GeglContext::new(); + // context.new_node(); + // context.new_node(); + // } } diff --git a/src/gegl_ffi.rs b/src/gegl_ffi.rs index 093fc3b..a477603 100644 --- a/src/gegl_ffi.rs +++ b/src/gegl_ffi.rs @@ -25,10 +25,16 @@ extern { pub fn gegl_node_link(source: *mut CGeglNode, sink: *mut CGeglNode); pub fn gegl_node_process(node: *mut CGeglNode); - pub fn g_object_unref(object: *mut libc::c_void); pub fn gegl_exit(); pub fn gegl_buffer_new(extent: *mut libc::c_void, format: *mut libc::c_void) -> *mut GeglBuffer; pub fn gegl_buffer_get_extent(buffer: *const libc::c_void) -> *const GeglRectangle; + + + pub fn g_object_unref(object: *mut libc::c_void); + pub fn g_free(object: *mut libc::c_void); + + pub fn gegl_list_operations(num_operations: *mut usize) + -> *mut *const libc::c_char; } -- cgit v1.2.3