Skip to content

Commit

Permalink
Prototype JSON parsing and execution
Browse files Browse the repository at this point in the history
Print digraph to stdout on error 72

Move serde types into lib.rs; fixes autocomplete

Make simple job work (via JSON API)

Fix things valgrind complained about

Fix failing test

Cleanup test output

Swap out pkg-config instead of openssl. Not that we have any idea if cargo [replace] ever works more than once per day.
  • Loading branch information
lilith committed Sep 15, 2016
1 parent ef745b4 commit 1706f2e
Show file tree
Hide file tree
Showing 23 changed files with 671 additions and 181 deletions.
5 changes: 5 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ insert_final_newline = true
[*.{c,cpp,hpp,h,py,rb,yml}]
trim_trailing_whitespace = true

[*.{toml,rs}]
trim_trailing_whitespace = true
indent_style = space
indent_size = 4

[*.{c,cpp,hpp,h,py,md}]
tab_width = 8
indent_style = space
Expand Down
4 changes: 2 additions & 2 deletions build.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/bin/bash
set -e #Exit on failure.
set -x

# You're going to need:
# Conan
Expand Down Expand Up @@ -34,7 +35,6 @@ export VALGRIND_COMMAND="valgrind -q --error-exitcode=9 --gen-suppressions=all"
export VALGRIND_RUST_COMMAND="$VALGRIND_COMMAND cargo test"
echo VALGRIND_COMMAND=$VALGRIND_COMMAND

set -x

export COVERAGE=${COVERAGE:-False}
export IMAGEFLOW_SERVER=${IMAGEFLOW_SERVER:-True}
Expand Down Expand Up @@ -119,7 +119,7 @@ if [[ "$TEST_RUST" == 'True' ]]; then
cd ..
if [[ "$IMAGEFLOW_SERVER" == 'True' ]]; then
cd imageflow_server
$COPY_VALGRINDRC
eval $COPY_VALGRINDRC
$VALGRIND_CARGO_COMMAND
cd ..
fi
Expand Down
20 changes: 10 additions & 10 deletions imageflow.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,10 @@ typedef enum flow_node_state {
} flow_node_state;

typedef enum flow_edgetype {
flow_edgetype_null,
flow_edgetype_input,
flow_edgetype_canvas,
flow_edgetype_info,
flow_edgetype_null = 0,
flow_edgetype_input = 1,
flow_edgetype_canvas = 2,
flow_edgetype_info = 3,
flow_edgetype_FORCE_ENUM_SIZE_INT32 = 2147483647
} flow_edgetype;

Expand All @@ -132,12 +132,12 @@ typedef enum flow_compositing_mode {
struct flow_job;

typedef enum flow_codec_type {
flow_codec_type_null,
flow_codec_type_decode_png,
flow_codec_type_encode_png,
flow_codec_type_decode_jpeg,
flow_codec_type_encode_jpeg,
flow_codec_type_decode_gif
flow_codec_type_null = 0,
flow_codec_type_decode_png = 1,
flow_codec_type_encode_png = 2,
flow_codec_type_decode_jpeg = 3,
flow_codec_type_encode_jpeg = 4,
flow_codec_type_decode_gif = 5
} flow_codec_type;

typedef enum flow_scanlines_filter_type {
Expand Down
2 changes: 1 addition & 1 deletion imageflow_advanced.h
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ PUB int32_t flow_edge_duplicate(flow_c * c, struct flow_graph ** g, int32_t edge

PUB bool flow_graph_print_to_dot(flow_c * c, struct flow_graph * g, FILE * stream,
const char * image_node_filename_prefix);

PUB bool flow_graph_print_to_stdout(flow_c * c, struct flow_graph * g);
////////////////////////////////////////////
// Deal with bitmaps

Expand Down
1 change: 1 addition & 0 deletions imageflow_cdylib/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

#![crate_type = "cdylib"]
#![crate_name = "imageflowrs"]
#![feature(alloc_system)]
Expand Down
28 changes: 23 additions & 5 deletions imageflow_core/src/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,25 @@ pub enum IoMode {
read_seekable = 5, // 1 | 4,
write_seekable = 6, // 2 | 4,
read_write_seekable = 15, // 1 | 2 | 4 | 8
}
}
#[repr(C)]
#[derive(Copy,Clone)]
pub enum IoDirection {
Out = 8,
In = 4,
}


#[repr(C)]
#[derive(Copy,Clone)]
pub enum IoDirection {
Out = 8,
In = 4,
pub enum EdgeKind {
None = 0,
Input = 1,
Canvas = 2,
Info = 3
}


#[repr(C)]
#[derive(Copy,Clone)]
pub enum PixelFormat {
Expand Down Expand Up @@ -303,6 +314,12 @@ extern {
-> *mut Graph;


pub fn flow_edge_create(c: *mut Context,
g: *mut *mut Graph,
from: i32,
to: i32,
kind: EdgeKind)
-> i32;
pub fn flow_node_create_decoder(c: *mut Context,
g: *mut *mut Graph,
prev_node: i32,
Expand Down Expand Up @@ -357,7 +374,7 @@ extern {
prev_node: i32,
placeholder_id: i32,
desired_encoder_id: i64,
hints: &EncoderHints)
hints: *const EncoderHints)
-> i32;

pub fn flow_node_create_primitive_flip_vertical(c: *mut Context,
Expand Down Expand Up @@ -395,6 +412,7 @@ extern {
pub fn flow_job_execute(c: *mut Context, job: *mut Job, g: *mut *mut Graph) -> bool;


pub fn flow_graph_print_to_stdout(c: *mut Context, g: *const Graph) -> bool;
pub fn flow_context_set_floatspace(c: *mut Context,
space: Floatspace,
a: f32,
Expand Down
70 changes: 68 additions & 2 deletions imageflow_core/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,27 @@
#![feature(alloc)]
#![feature(oom)]
#![feature(alloc_system)]


#![allow(unused_features)]
#![allow(unused_imports)]
#![allow(dead_code)]
#![allow(unused_variables)]

extern crate alloc_system;


pub mod ffi;
pub mod boring;
pub mod parsing;
pub mod abi;

use std::ops::DerefMut;

pub use ::ffi::{IoDirection, IoMode};

use parsing::JsonResponseError;

#[macro_use]
extern crate json;
extern crate libc;
Expand Down Expand Up @@ -110,6 +117,41 @@ impl ContextPtr {

}


unsafe fn assert_ok(&self, g : Option<*const ::ffi::Graph>) {
match self.get_error_copy(){
Some(which_error) => {
match which_error {
FlowError::Err(e) => {

println!("Error {} {}\n", e.code, e.message_and_stack);
match e.code{
72 if g.is_some() => {
let _ = ::ffi::flow_graph_print_to_stdout(self.ptr.unwrap(), g.unwrap());
}
_ => {}
}

panic!();
},
FlowError::Oom => {
panic!("Out of memory.");
},
FlowError::ErrNotImpl => {
panic!("Error not implemented");
},
FlowError::ContextInvalid => {
panic!("Context pointer null");
}


}
},
None => {}
}
}


fn get_error_copy(&self) -> Option<FlowError> {
unsafe {
match self.ptr {
Expand Down Expand Up @@ -147,6 +189,9 @@ impl Context {
}
}
}
pub fn unsafe_borrow_mut_context_pointer(&mut self) -> std::cell::RefMut<ContextPtr>{
self.p.borrow_mut()
}

fn get_error_copy(&self) -> Option<FlowError> {
(*self.p.borrow()).get_error_copy()
Expand Down Expand Up @@ -299,6 +344,14 @@ fn it_works() {
assert_eq!(c.destroy(), Ok(()));

}
//
//#[test]
//fn leak_mem() {
//
// let mut v = Vec::with_capacity(333);
// v.push(0u8);
// std::mem::forget(v)
//}

//pub struct FlowIoRef{
// ptr: *mut ::ffi::JobIO
Expand Down Expand Up @@ -326,6 +379,12 @@ impl ContextPtr{
r#"{"success": "false","code": 418,"message": "I'm a teapot, short and stout"}"#
.as_bytes()
},
"v0.0.1/build" => JsonResponse {
status_code: 418,
response_json:
r#"{"success": "false","code": 418,"message": "I'm a teapot, short and stout"}"#
.as_bytes()
},
_ => JsonResponse {
status_code: 404,
response_json: r#"{
Expand All @@ -337,8 +396,15 @@ impl ContextPtr{
Ok(response)
}

fn build_graph(&mut self, json: &[u8]){

fn build_0_0_1<'a, 'b, 'c>(&'a mut self, json: &'b [u8]) -> Result<JsonResponse<'c>>{
match ::parsing::BuildRequestHandler::new().do_and_respond(self, json) {
Ok(response) => Ok(response),
Err(original_err) => Err(match original_err {
JsonResponseError::Oom(()) => FlowError::Oom,
JsonResponseError::NotImplemented(()) => FlowError::ErrNotImpl,
JsonResponseError::Other(e) => FlowError::ErrNotImpl
})
}
}

}
Expand Down
Loading

0 comments on commit 1706f2e

Please sign in to comment.