diff options
author | Daniel Schadt <kingdread@gmx.de> | 2020-10-01 16:44:59 +0200 |
---|---|---|
committer | Daniel Schadt <kingdread@gmx.de> | 2020-10-01 16:44:59 +0200 |
commit | 62249e950c0c5dee0b09b962842543fd60c9ccb4 (patch) | |
tree | 337312ec128010d6ea6a04df51f7a0f10acd6061 /src/processing.rs | |
parent | fa3f8e5ce231a5844e59f0d5e1081b5c6f8274c8 (diff) | |
download | evtclib-62249e950c0c5dee0b09b962842543fd60c9ccb4.tar.gz evtclib-62249e950c0c5dee0b09b962842543fd60c9ccb4.tar.bz2 evtclib-62249e950c0c5dee0b09b962842543fd60c9ccb4.zip |
move Agent definition to a separate file
Just like with Event, we now have Agent defined in its own submodule.
The amount of code that it entailed was a lot, so it made sense to split
it off, especially with the deserialization being another big chunk of
Agent related code in lib.rs
The main issue was that the processing submodule accessed private fields
of the Agent struct, which is now no longer possible (since processing
is no longer a submodule of the module in which Agent is defined).
Therefore, some simple crate-public setters for those fields have been
added. Those setters are not public because we do not want outside
crates to mess with the innards of Agent (yet).
Although with (de)serialization being a thing, we need to ensure that we
can handle nonsensical values anyway, since we can no longer guarantee
that we have full control over all of the values, even without setters.
Diffstat (limited to 'src/processing.rs')
-rw-r--r-- | src/processing.rs | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/src/processing.rs b/src/processing.rs index 722440b..11bdda7 100644 --- a/src/processing.rs +++ b/src/processing.rs @@ -110,7 +110,7 @@ fn setup_agents(data: &raw::Evtc) -> Result<Vec<Agent>, EvtcError> { fn get_agent_by_addr(agents: &mut [Agent], addr: u64) -> Option<&mut Agent> { for agent in agents { - if agent.addr == addr { + if agent.addr() == addr { return Some(agent); } } @@ -121,11 +121,11 @@ fn set_agent_awares(data: &raw::Evtc, agents: &mut [Agent]) -> Result<(), EvtcEr for event in &data.events { if event.is_statechange == raw::CbtStateChange::None { if let Some(current_agent) = get_agent_by_addr(agents, event.src_agent) { - current_agent.instance_id = event.src_instid; - if current_agent.first_aware == 0 { - current_agent.first_aware = event.time; + current_agent.set_instance_id(event.src_instid); + if current_agent.first_aware() == 0 { + current_agent.set_first_aware(event.time); } - current_agent.last_aware = event.time; + current_agent.set_last_aware(event.time); } } } @@ -137,17 +137,17 @@ fn set_agent_masters(data: &raw::Evtc, agents: &mut [Agent]) -> Result<(), EvtcE if event.src_master_instid != 0 { let mut master_addr = None; for agent in &*agents { - if agent.instance_id == event.src_master_instid - && agent.first_aware < event.time - && event.time < agent.last_aware + if agent.instance_id() == event.src_master_instid + && agent.first_aware() < event.time + && event.time < agent.last_aware() { - master_addr = Some(agent.addr); + master_addr = Some(agent.addr()); break; } } if let Some(master_addr) = master_addr { if let Some(current_slave) = get_agent_by_addr(agents, event.src_agent) { - current_slave.master_agent = Some(master_addr); + current_slave.set_master_agent(Some(master_addr)); } } } |