Skip to content
This repository has been archived by the owner on May 12, 2020. It is now read-only.

Commit

Permalink
format code
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcAntoine-Arnaud committed Dec 27, 2019
1 parent 8327574 commit 77ef71f
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 20 deletions.
1 change: 0 additions & 1 deletion src/constants.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

pub static GET_NAME_FUNCTION: &str = "get_name";
pub static GET_SHORT_DESCRIPTION_FUNCTION: &str = "get_short_description";
pub static GET_DESCRIPTION_FUNCTION: &str = "get_description";
Expand Down
8 changes: 5 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ extern crate libloading;
extern crate log;

mod constants;
mod worker;
mod process_return;
mod worker;

use amqp_worker::job::*;
use amqp_worker::start_worker;
Expand Down Expand Up @@ -121,7 +121,10 @@ pub fn test_process() {
let job_result = result.unwrap();
assert_eq!(job_result.get_job_id(), 123);
assert_eq!(job_result.get_status(), &JobStatus::Completed);
assert_eq!(job_result.get_destination_paths(), &vec!["/path/out.mxf".to_string()]);
assert_eq!(
job_result.get_destination_paths(),
&vec!["/path/out.mxf".to_string()]
);
}

#[test]
Expand All @@ -140,5 +143,4 @@ pub fn test_failing_process() {
let result = C_WORKER_EVENT.process(message);
assert!(result.is_err());
let _message_error = result.unwrap_err();

}
4 changes: 1 addition & 3 deletions src/process_return.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

use amqp_worker::job::*;
use amqp_worker::MessageError;

Expand Down Expand Up @@ -47,8 +46,7 @@ impl ProcessReturn {
if self.code == 0 {
let mut output_paths = self.output_paths.clone();

let job_result =
JobResult::new(job_id, JobStatus::Completed)
let job_result = JobResult::new(job_id, JobStatus::Completed)
.with_destination_paths(&mut output_paths)
.with_message(&self.message);

Expand Down
36 changes: 23 additions & 13 deletions src/worker.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@

use std::collections::HashMap;
use std::ffi::{CStr, CString};
use std::os::raw::{c_char, c_int, c_uint, c_void};

use crate::constants;
use crate::process_return::ProcessReturn;
use amqp_worker::job::Job;
use amqp_worker::worker::{Parameter, ParameterType};
use amqp_worker::ParametersContainer;
use libloading::Library;
use crate::constants;
use crate::process_return::ProcessReturn;

macro_rules! get_c_string {
($name:expr) => {
Expand Down Expand Up @@ -45,7 +44,7 @@ type ProcessFunc = unsafe fn(
callback: GetParameterValueCallback,
logger: LoggerCallback,
output_message: &*const c_char,
output_paths: &*mut *const c_char
output_paths: &*mut *const c_char,
) -> c_int;

#[allow(unused_assignments)]
Expand Down Expand Up @@ -76,10 +75,18 @@ extern "C" fn logger(level: *const c_char, raw_value: *const c_char) {
let value = get_c_string!(raw_value);

match level.as_str() {
"trace" => {trace!("[Worker] {}", value);},
"debug" => {debug!("[Worker] {}", value);},
"info" => {info!("[Worker] {}", value);},
"error" => {error!("[Worker] {}", value);},
"trace" => {
trace!("[Worker] {}", value);
}
"debug" => {
debug!("[Worker] {}", value);
}
"info" => {
info!("[Worker] {}", value);
}
"error" => {
error!("[Worker] {}", value);
}
_ => {}
}
}
Expand Down Expand Up @@ -228,7 +235,7 @@ pub fn call_worker_process(job: Job) -> ProcessReturn {
get_parameter_value,
logger,
&message_ptr,
&ptr
&ptr,
);

let mut output_paths = vec![];
Expand Down Expand Up @@ -259,12 +266,12 @@ pub fn call_worker_process(job: Job) -> ProcessReturn {
libc::free(message_ptr as *mut libc::c_void);
}

ProcessReturn::new(return_code, &message)
.with_output_paths(output_paths)
ProcessReturn::new(return_code, &message).with_output_paths(output_paths)
}
Err(error) => ProcessReturn::new_error(&format!(
"Could not access {:?} function from worker library: {:?}",
constants::PROCESS_FUNCTION, error
constants::PROCESS_FUNCTION,
error
)),
}
},
Expand Down Expand Up @@ -292,7 +299,10 @@ pub fn test_c_binding_process() {
let returned_code = call_worker_process(job);
assert_eq!(returned_code.get_code(), 0);
assert_eq!(returned_code.get_message(), "Everything worked well!");
assert_eq!(returned_code.get_output_paths(), &vec!["/path/out.mxf".to_string()]);
assert_eq!(
returned_code.get_output_paths(),
&vec!["/path/out.mxf".to_string()]
);
}

#[test]
Expand Down

0 comments on commit 77ef71f

Please sign in to comment.