Skip to content

Commit

Permalink
Work in progress
Browse files Browse the repository at this point in the history
  • Loading branch information
amousset committed Jul 27, 2020
1 parent 1f09871 commit 4743e4f
Showing 1 changed file with 39 additions and 1 deletion.
40 changes: 39 additions & 1 deletion rudder-lang/src/generators/cfengine/syntax.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,22 @@ impl Promise {
}
}

/// Helper for reporting boilerplate (reporting context + na report)
pub struct MethodCall {
resource: String,
sate: String,
parameters: Vec<String>,
report_component: String,
report_parameter: String,
condition: Option<String>,
}

impl MethodCall {
pub fn new(resource: String, state: String) -> MethodCall {
Self { resource, state }
}
}

#[derive(Clone, Copy, PartialEq, Eq, Hash)]
pub enum BundleType {
Agent,
Expand All @@ -239,7 +255,8 @@ pub struct Bundle {
parameters: Vec<String>,
// Promises of a given promise type need to be ordered specifically,
// hence the `Vec`.
promises: HashMap<PromiseType, Vec<Promise>>,
// Group promises for better readability (e.g. a generic method call)
promises: HashMap<PromiseType, Vec<Vec<Promise>>>,
}

impl Bundle {
Expand All @@ -261,6 +278,13 @@ impl Bundle {
self
}

// FIXME ajout d'un raccourcis pour un appel de GM (une promesse + infos report)

pub fn promise_group(mut self, promise: Vec<Promise>) -> Self {
self.add_promise_group(promise);
self
}

pub fn add_promise(&mut self, promise: Promise) {
match self.promises.get_mut(&promise.promise_type) {
Some(promises) => promises.push(promise),
Expand All @@ -269,6 +293,20 @@ impl Bundle {
}
}
}

pub fn add_promise_group(&mut self, promise_group: Vec<Promise>) {
if promise_group.is_empty() {
return;
}
let promise_type = promise_group[0].promise_type;
assert!(promise_group.iter().all(|p| p.promise_type == promise_type));
match self.promises.get_mut(&promise_type) {
Some(promises) => promises.push(promise_group),
None => {
self.promises.insert(promise_type, vec![promise_group]);
}
}
}
}

impl fmt::Display for Bundle {
Expand Down

0 comments on commit 4743e4f

Please sign in to comment.