Skip to content

Commit

Permalink
Allow conditional compilation of agent protocols
Browse files Browse the repository at this point in the history
  • Loading branch information
jiayihu committed Jan 12, 2021
1 parent c7d832a commit 76451d1
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 13 deletions.
3 changes: 0 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 14 additions & 10 deletions agent/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,10 @@ hyper = "0.11"
kube = { version = "0.23.0", features = ["openapi"] }
k8s-openapi = { version = "0.6.0", features = ["v1_16"] }
log = "0.4"
mime = "0.3"
mockall = "0.6.0"
opcua-client = "0.7.0"
pest = "2.0"
pest_derive = "2.0"
opcua-client = { version = "0.7.0", optional = true }
pest = { version = "2.0", optional = true }
pest_derive = { version = "2.0", optional = true }
prost = "0.6"
rand = "0.7"
regex = "1"
Expand All @@ -35,19 +34,24 @@ serde_json = "1.0.45"
serde_yaml = "0.8.11"
serde_derive = "1.0.104"
akri-shared = { path = "../shared" }
sxd-document = "0.3.0"
sxd-xpath = "0.4.0"
tempfile = "3.1.0"
tokio = { version = "0.2", features = ["full"] }
tokio-core = "0.1"
tonic = "0.1"
tower = "0.3"
udev = "0.4"
udev = { version = "0.4", optional = true }
url = "2.1.0"
uuid = { version = "0.8.1", features = ["v4"] }
xml-rs = "0.8.0"
yaserde = "0.3.13"
yaserde_derive = "0.3.13"
xml-rs = { version = "0.8.0", optional = true }
yaserde = { version = "0.3.13", optional = true }
yaserde_derive = { version = "0.3.13", optional = true }

[build-dependencies]
tonic-build = "0.1.1"

[features]
default = ["onvif", "opcua", "udevfeat"]

onvif = ["xml-rs", "yaserde", "yaserde_derive"]
opcua = ["opcua-client"]
udevfeat = ["pest", "pest_derive", "udev"]
5 changes: 5 additions & 0 deletions agent/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
#[macro_use]
extern crate log;

#[cfg(feature = "onvif")]
#[macro_use]
extern crate yaserde_derive;

#[macro_use]
extern crate serde_derive;

#[cfg(feature = "udevfeat")]
extern crate pest;
#[cfg(feature = "udevfeat")]
#[macro_use]
extern crate pest_derive;

Expand Down
9 changes: 9 additions & 0 deletions agent/src/protocols/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,11 @@ pub trait DiscoveryHandler {
}

pub mod debug_echo;
#[cfg(feature = "onvif")]
mod onvif;
#[cfg(feature = "opcua")]
mod opcua;
#[cfg(feature = "udev")]
mod udev;

pub fn get_discovery_handler(
Expand All @@ -80,13 +83,19 @@ fn inner_get_discovery_handler(
query: &impl EnvVarQuery,
) -> Result<Box<dyn DiscoveryHandler + Sync + Send>, Error> {
match discovery_handler_config {
#[cfg(feature = "onvif")]
ProtocolHandler::onvif(onvif) => Ok(Box::new(onvif::OnvifDiscoveryHandler::new(&onvif))),
#[cfg(feature = "udevfeat")]
ProtocolHandler::udev(udev) => Ok(Box::new(udev::UdevDiscoveryHandler::new(&udev))),
#[cfg(feature = "opcua")]
ProtocolHandler::opcua(opcua) => Ok(Box::new(opcua::OpcuaDiscoveryHandler::new(&opcua))),
ProtocolHandler::debugEcho(dbg) => match query.get_env_var("ENABLE_DEBUG_ECHO") {
Ok(_) => Ok(Box::new(debug_echo::DebugEchoDiscoveryHandler::new(dbg))),
_ => Err(failure::format_err!("No protocol configured")),
},
config => {
panic!("No handler found for configuration {:?}", config);
}
}
}

Expand Down

0 comments on commit 76451d1

Please sign in to comment.