-
Notifications
You must be signed in to change notification settings - Fork 173
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
168 additions
and
16 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# | ||
# Copyright (c) 2023 ZettaScale Technology | ||
# | ||
# This program and the accompanying materials are made available under the | ||
# terms of the Eclipse Public License 2.0 which is available at | ||
# http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 | ||
# which is available at https://www.apache.org/licenses/LICENSE-2.0. | ||
# | ||
# SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 | ||
# | ||
# Contributors: | ||
# ZettaScale Zenoh Team, <[email protected]> | ||
# | ||
[package] | ||
rust-version = { workspace = true } | ||
name = "zenoh-plugin-storage-example" | ||
version = { workspace = true } | ||
authors = { workspace = true } | ||
edition = { workspace = true } | ||
|
||
[lib] | ||
name = "zenoh_backend_example" | ||
# This crate type will make `cargo` output a dynamic library instead of a rust static library | ||
crate-type = ["cdylib"] | ||
|
||
[dependencies] | ||
async-std = { workspace = true, features = ["default"] } | ||
clap = { workspace = true } | ||
env_logger = { workspace = true } | ||
futures = { workspace = true } | ||
log = { workspace = true } | ||
serde_json = { workspace = true } | ||
zenoh = { workspace = true } | ||
zenoh-core = { workspace = true } | ||
zenoh-plugin-trait = { workspace = true } | ||
zenoh-result = { workspace = true } | ||
zenoh-util = { workspace = true } | ||
async-trait = { workspace = true } | ||
zenoh_backend_traits = { workspace = true } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
use std::sync::Arc; | ||
|
||
// | ||
// Copyright (c) 2023 ZettaScale Technology | ||
// | ||
// This program and the accompanying materials are made available under the | ||
// terms of the Eclipse Public License 2.0 which is available at | ||
// http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 | ||
// which is available at https://www.apache.org/licenses/LICENSE-2.0. | ||
// | ||
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 | ||
// | ||
// Contributors: | ||
// ZettaScale Zenoh Team, <[email protected]> | ||
// | ||
use async_trait::async_trait; | ||
use zenoh::{prelude::OwnedKeyExpr, sample::Sample, time::Timestamp, value::Value}; | ||
use zenoh_backend_traits::{ | ||
config::{StorageConfig, VolumeConfig}, | ||
Capability, History, Persistence, Storage, StorageInsertionResult, StoredData, Volume, | ||
}; | ||
use zenoh_result::ZResult; | ||
|
||
#[no_mangle] | ||
pub fn create_volume(_config: VolumeConfig) -> ZResult<Box<dyn Volume>> { | ||
let volume = ExampleBackendStorage {}; | ||
Ok(Box::new(volume)) | ||
} | ||
|
||
pub struct ExampleBackendStorage {} | ||
|
||
pub struct ExampleStorage {} | ||
|
||
#[async_trait] | ||
impl Volume for ExampleBackendStorage { | ||
fn get_admin_status(&self) -> serde_json::Value { | ||
serde_json::Value::Null | ||
} | ||
fn get_capability(&self) -> Capability { | ||
Capability { | ||
persistence: Persistence::Volatile, | ||
history: History::Latest, | ||
read_cost: 0, | ||
} | ||
} | ||
async fn create_storage(&mut self, _props: StorageConfig) -> ZResult<Box<dyn Storage>> { | ||
Ok(Box::new(ExampleStorage {})) | ||
} | ||
fn incoming_data_interceptor(&self) -> Option<Arc<dyn Fn(Sample) -> Sample + Send + Sync>> { | ||
None | ||
} | ||
fn outgoing_data_interceptor(&self) -> Option<Arc<dyn Fn(Sample) -> Sample + Send + Sync>> { | ||
None | ||
} | ||
} | ||
|
||
#[async_trait] | ||
impl Storage for ExampleStorage { | ||
fn get_admin_status(&self) -> serde_json::Value { | ||
serde_json::Value::Null | ||
} | ||
async fn put( | ||
&mut self, | ||
_key: Option<OwnedKeyExpr>, | ||
_value: Value, | ||
_timestamp: Timestamp, | ||
) -> ZResult<StorageInsertionResult> { | ||
Ok(StorageInsertionResult::Inserted) | ||
} | ||
|
||
async fn delete( | ||
&mut self, | ||
_key: Option<OwnedKeyExpr>, | ||
_timestamp: Timestamp, | ||
) -> ZResult<StorageInsertionResult> { | ||
Ok(StorageInsertionResult::Deleted) | ||
} | ||
|
||
async fn get( | ||
&mut self, | ||
_key: Option<OwnedKeyExpr>, | ||
_parameters: &str, | ||
) -> ZResult<Vec<StoredData>> { | ||
Ok(Vec::new()) | ||
} | ||
|
||
async fn get_all_entries(&self) -> ZResult<Vec<(Option<OwnedKeyExpr>, Timestamp)>> { | ||
Ok(Vec::new()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,16 @@ | ||
{ | ||
"volumes": { | ||
"influxdb_local": { | ||
"__path__": "../zenoh-backend-influxdb/target/debug/libzenoh_backend_influxdb.dylib", | ||
"__config__": "config_influxdb_local.json5" | ||
}, | ||
"influxdb_remote": { | ||
"__path__": "../zenoh-backend-influxdb/target/debug/libzenoh_backend_influxdb.dylib", | ||
"__config__": "config_influxdb_remote.json5" | ||
"example" : { | ||
"__path__": "./plugins/example-storage-plugin/target/debug/libexample_storage_plugin.dylib", | ||
} | ||
//"influxdb_local": { | ||
// "__path__": "../zenoh-backend-influxdb/target/debug/libzenoh_backend_influxdb.dylib", | ||
// "__config__": "config_influxdb_local.json5" | ||
//}, | ||
//"influxdb_remote": { | ||
// "__path__": "../zenoh-backend-influxdb/target/debug/libzenoh_backend_influxdb.dylib", | ||
// "__config__": "config_influxdb_remote.json5" | ||
//} | ||
}, | ||
"storages": {} | ||
} |