From cd53daa525b9664c84f7e58c72a10c06339ac202 Mon Sep 17 00:00:00 2001 From: "hongwei.li" Date: Thu, 7 Jul 2022 18:22:52 +0800 Subject: [PATCH 1/6] =?UTF-8?q?=E5=86=85=E5=AD=98=E5=88=86=E9=85=8D?= =?UTF-8?q?=E4=BB=A3=E7=A0=81=E5=AE=9E=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tools/src/lib.rs | 2 + tools/src/memory_poll.rs | 112 ++++++++++++++++++++++++++++++++++ tools/src/memory_poll/test.rs | 30 +++++++++ 3 files changed, 144 insertions(+) create mode 100644 tools/src/memory_poll.rs create mode 100644 tools/src/memory_poll/test.rs diff --git a/tools/src/lib.rs b/tools/src/lib.rs index 809d067..6e3fac6 100644 --- a/tools/src/lib.rs +++ b/tools/src/lib.rs @@ -1,2 +1,4 @@ #![cfg_attr(feature = "alloc", no_std)] +#![feature(const_maybe_uninit_zeroed)] extern crate alloc; +pub mod memory_poll; diff --git a/tools/src/memory_poll.rs b/tools/src/memory_poll.rs new file mode 100644 index 0000000..7b4a570 --- /dev/null +++ b/tools/src/memory_poll.rs @@ -0,0 +1,112 @@ +mod test; +use core::mem::size_of; +use core::mem::MaybeUninit; +use core::sync::atomic::{AtomicUsize, Ordering}; +use stdlib::io::Result; +const CHUNKE_SIZE: usize = 1024 * 10; +const CHUNKE_NUMBER: usize = 8; +const LAST_CHUNK: usize = CHUNKE_NUMBER - 1; +static mut POOL: [Chunk; CHUNKE_NUMBER] = unsafe { MaybeUninit::zeroed().assume_init() }; +static _MEMORY_HEADER: AtomicUsize = AtomicUsize::new(usize::max_value()); +static _HOLD_HEADER: AtomicUsize = AtomicUsize::new(0); +#[repr(C, align(8))] +struct Chunk { + next: *mut Chunk, + body: [u8; CHUNKE_SIZE - size_of::<*mut Chunk>()], +} + +pub struct MemoryPoll; + +impl MemoryPoll { + unsafe fn init() -> usize { + for i in &mut POOL[..CHUNKE_NUMBER - 1] { + i.next = (i as *mut Chunk).offset(1); + } + POOL[LAST_CHUNK].next = core::ptr::null_mut(); + &POOL[0] as *const _ as usize + } + + // 分配内存 + pub fn memroy_allocat() -> Result<*const u8> { + // 当前可使用的内存块指针 + let mut current = _MEMORY_HEADER.load(Ordering::SeqCst); + let mut spin = 0; + + loop { + match current { + 1 => { + current = _MEMORY_HEADER.load(Ordering::Acquire); + spin = spin + 1; + if spin < 100 { + core::hint::spin_loop(); + continue; + } + continue; + } + 0 => { + // 已经没有内存块可用 + return Err(stdlib::io::Error::new( + "there is no more memory to allocate", + )); + } + usize::MAX => { + match _MEMORY_HEADER.compare_exchange_weak( + current, + 1, + Ordering::AcqRel, + Ordering::Acquire, + ) { + Ok(_) => { + let rtn = unsafe { Self::init() }; + let current = unsafe { (*(rtn as *const Chunk)).next } as usize; + _MEMORY_HEADER.store(current, Ordering::Release); + return Ok(rtn as *const u8); + } + Err(s) => current = s, + } + } + _ => { + // 将 current 赋值给 _HOLD_HEADER + _HOLD_HEADER.store(current, Ordering::SeqCst); + let next = unsafe { (*(current as *const Chunk)).next } as usize; + match _MEMORY_HEADER.compare_exchange_weak( + current, + next, + Ordering::AcqRel, + Ordering::Acquire, + ) { + Ok(_) => { + return Ok(current as *const u8); + } + Err(s) => { + current = s; + continue; + } + } + } + } + } + } + + // 回收内存 + pub fn memory_free(memory_chunk: *const u8) { + loop { + let now_header = _MEMORY_HEADER.load(Ordering::SeqCst); + let return_header = unsafe { *(memory_chunk as *mut usize) }; + if return_header == _HOLD_HEADER.load(Ordering::SeqCst) { + continue; + } + unsafe { *(memory_chunk as *mut usize) = now_header }; + let result = _MEMORY_HEADER.compare_exchange( + now_header, + memory_chunk as usize, + Ordering::SeqCst, + Ordering::SeqCst, + ); + match result { + Ok(_) => break, + Err(_) => continue, + } + } + } +} diff --git a/tools/src/memory_poll/test.rs b/tools/src/memory_poll/test.rs new file mode 100644 index 0000000..06c59fb --- /dev/null +++ b/tools/src/memory_poll/test.rs @@ -0,0 +1,30 @@ +use std::println; + +use crate::memory_poll::*; +use alloc::string::ToString; + +extern crate std; +#[test] +fn memory_poll_test() { + for _ in 0..4 { + stdlib::thread::spawn(|| { + for _ in 0..10000000 { + let memory_chunk = MemoryPoll::memroy_allocat(); + match memory_chunk { + Ok(pointer) => { + unsafe { + *(pointer as *mut [usize; 1280]) = + [usize::max_value(); (10 * 1024) / core::mem::size_of::()] + }; + MemoryPoll::memory_free(pointer); + // std::println!("{}", "分配成功,写入成功,内存回收成功"); + } + Err(e) => { + std::println!("{}", e.to_string()); + } + } + } + }) + .join(); + } +} -- Gitee From abf5da258983afe5e5fae663fb048405999fdf70 Mon Sep 17 00:00:00 2001 From: "hongwei.li" Date: Thu, 7 Jul 2022 18:24:06 +0800 Subject: [PATCH 2/6] =?UTF-8?q?=E6=B5=8B=E8=AF=95=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tools/src/memory_poll/test.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/src/memory_poll/test.rs b/tools/src/memory_poll/test.rs index 06c59fb..cf564b7 100644 --- a/tools/src/memory_poll/test.rs +++ b/tools/src/memory_poll/test.rs @@ -1,6 +1,6 @@ use std::println; -use crate::memory_poll::*; +use crate::memory_poll::MemoryPoll; use alloc::string::ToString; extern crate std; -- Gitee From 3d8d3636c2de8e2ef520abb754e85e80f846b229 Mon Sep 17 00:00:00 2001 From: "hongwei.li" Date: Fri, 22 Jul 2022 16:29:04 +0800 Subject: [PATCH 3/6] =?UTF-8?q?=E5=86=85=E5=AD=98=E5=88=86=E9=85=8D?= =?UTF-8?q?=EF=BC=8C=E8=AF=BB=E5=86=99=E5=8C=85=E8=A3=85=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/Cargo.toml | 12 +- cypto/Cargo.toml | 11 +- server/Cargo.toml | 10 +- tools/Cargo.toml | 10 +- tools/src/io.rs | 237 ++++++++++++++++++++++++++++++++++ tools/src/io/test.rs | 138 ++++++++++++++++++++ tools/src/lib.rs | 6 +- tools/src/memory_poll.rs | 2 +- tools/src/memory_poll/test.rs | 10 +- types/Cargo.toml | 8 +- 10 files changed, 409 insertions(+), 35 deletions(-) create mode 100644 tools/src/io.rs create mode 100644 tools/src/io/test.rs diff --git a/core/Cargo.toml b/core/Cargo.toml index bdbc2e6..faa290e 100644 --- a/core/Cargo.toml +++ b/core/Cargo.toml @@ -5,11 +5,9 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [features] -default=["alloc"] -alloc=["stdlib/alloc"] -std=["stdlib/std"] +default = ["alloc"] +alloc = ["stdlib/alloc"] +std = ["stdlib/std"] [dependencies] -types={path="../types"} -stdlib = { git = "https://gitee.com/iot-ua/stdlib.git", default-features = false,branch="develop"} - - +types = { path = "../types" } +stdlib = { git = "https://gitee.com/iot-ua/stdlib.git", default-features = false, branch = "master" } diff --git a/cypto/Cargo.toml b/cypto/Cargo.toml index 06add12..05af5b5 100644 --- a/cypto/Cargo.toml +++ b/cypto/Cargo.toml @@ -6,10 +6,9 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [features] -default=["alloc"] -alloc=["stdlib/alloc"] -std=["stdlib/std"] +default = ["alloc"] +alloc = ["stdlib/alloc"] +std = ["stdlib/std"] [dependencies] -stdlib = { git = "https://gitee.com/iot-ua/stdlib.git", default-features = false,branch="develop"} -types={path="../types"} - +stdlib = { git = "https://gitee.com/iot-ua/stdlib.git", default-features = false, branch = "master" } +types = { path = "../types" } diff --git a/server/Cargo.toml b/server/Cargo.toml index dda00af..8ce0232 100644 --- a/server/Cargo.toml +++ b/server/Cargo.toml @@ -6,9 +6,9 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [features] -default=["alloc"] -alloc=["stdlib/alloc"] -std=["stdlib/std"] +default = ["alloc"] +alloc = ["stdlib/alloc"] +std = ["stdlib/std"] [dependencies] -stdlib = { git = "https://gitee.com/iot-ua/stdlib.git", default-features = false,branch="develop"} -types={path="../types"} +stdlib = { git = "https://gitee.com/iot-ua/stdlib.git", default-features = false, branch = "master" } +types = { path = "../types" } diff --git a/tools/Cargo.toml b/tools/Cargo.toml index 51ba7e8..8cb9855 100644 --- a/tools/Cargo.toml +++ b/tools/Cargo.toml @@ -6,9 +6,9 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [features] -default=["alloc"] -alloc=["stdlib/alloc"] -std=["stdlib/std"] +default = ["alloc"] +alloc = ["stdlib/alloc"] +std = ["stdlib/std"] [dependencies] -stdlib = { git = "https://gitee.com/iot-ua/stdlib.git", default-features = false,branch="develop"} -types={path="../types"} +stdlib = { git = "https://gitee.com/iot-ua/stdlib.git", default-features = false, branch = "master" } +types = { path = "../types" } diff --git a/tools/src/io.rs b/tools/src/io.rs new file mode 100644 index 0000000..93b3705 --- /dev/null +++ b/tools/src/io.rs @@ -0,0 +1,237 @@ +mod test; +use core::sync::atomic::{AtomicU64, Ordering}; + +use alloc::vec::Vec; + +use crate::memory_poll::{MemoryPoll, CHUNKE_SIZE}; +#[derive(Debug)] +pub struct ChunkBuf { + inner: Vec, + pos: AtomicU64, +} + +unsafe impl Send for ChunkBuf {} +unsafe impl Sync for ChunkBuf {} + +impl ChunkBuf { + pub fn new() -> ChunkBuf { + let mut inner = Vec::::with_capacity(10); + inner.push(Self::alloc_memory_chunk()); + ChunkBuf { + inner, + pos: AtomicU64::new(0), + } + } + + fn alloc_memory_chunk() -> usize { + MemoryPoll::memroy_allocat().unwrap() as usize + } + + /// 返回光标当前的位置 + pub fn position(&self) -> u64 { + self.pos.load(Ordering::Relaxed) + } + + /// 返回剩余容量 + pub fn get_margin(&self) -> u64 { + let total_capacity = self.inner.len() * CHUNKE_SIZE; + total_capacity as u64 - self.position() + } + + // /// 返回剩余的片 + // pub fn remaining_slice(&self) -> &[u8] { + // let len = self.position().min(CHUNKE_SIZE as u64); + // unsafe { &(*(self.inner as *const [u8; CHUNKE_SIZE]))[(len as usize)..] } + // } + + /// slice 为空返回 true + pub fn is_empty(&self) -> bool { + self.position() >= self.get_margin() + } + + pub fn write(&mut self, buf: &[u8]) -> stdlib::io::Result { + let pos = self.pos.load(Ordering::Relaxed); + loop { + // 剩余容量 + let margin = self.get_margin(); + if pos == u64::MAX { + continue; + } + match self + .pos + .compare_exchange_weak(pos, u64::MAX, Ordering::SeqCst, Ordering::Relaxed) + { + Ok(_) => { + // 开始写入的索引位置 + let start_index = pos; + // 结束写入的索引位置 + let end_index = pos + buf.len() as u64; + // 当前应该写入的块索引 + let mut current_vec_index = pos / CHUNKE_SIZE as u64; + // pos 指向 chunk 中真实的索引 + let mut chunk_index = pos % CHUNKE_SIZE as u64; + // 若剩余容量与开始索引的和小于结束索引,则先分配内存再进行写入 + if margin + start_index < end_index { + // 内存不够,继续分配内存 + self.inner.push(Self::alloc_memory_chunk()); + // 将数据分段写入chunk + if chunk_index == 0 && margin == 0 { + // 满足上述条件则说明刚好写满一块内存,数据没有跨段存储 + current_vec_index -= 1; + chunk_index = CHUNKE_SIZE as u64; + } + // 首段数据 + let first_memeory_chunk_slice = unsafe { + &mut (*(self.inner[current_vec_index as usize] + as *mut [u8; CHUNKE_SIZE]))[(chunk_index as usize)..] + }; + // 尾段数据 + let last_memeory_chunk_slice = unsafe { + &mut (*(self.inner[(current_vec_index + 1) as usize] + as *mut [u8; CHUNKE_SIZE])) + [0..(buf.len() - margin as usize)] + }; + // 将 buf 按照 margin 进行拆分 + let (left, right) = unsafe { buf.split_at_unchecked(margin as usize) }; + // 首段写入left + first_memeory_chunk_slice.copy_from_slice(left); + // 尾段写入right + last_memeory_chunk_slice.copy_from_slice(right); + // 修改原子变量 pos + self.pos.store(pos + (buf.len()) as u64, Ordering::SeqCst); + return Ok(buf.len()); + } else { + let memeory_chunk_slice = unsafe { + &mut (*(self.inner[current_vec_index as usize] + as *mut [u8; CHUNKE_SIZE]))[(chunk_index + as usize) + ..(chunk_index as usize + buf.len() as usize)] + }; + memeory_chunk_slice.copy_from_slice(buf); + self.pos.store(pos + (buf.len()) as u64, Ordering::SeqCst); + return Ok(buf.len()); + } + } + Err(_) => { + continue; + } + } + } + } + + /// 从 point 处读取指定长度字节 + pub fn read(&mut self, buf: &mut [u8]) -> stdlib::io::Result { + // 准备读取字节数 + let len = buf.len() as u64; + // 当前光标位置 + let mut pos = self.position(); + // 实际读取长度 + let mut read_len; + loop { + if len > pos { + buf.get_mut(0..(pos as usize)) + .unwrap() + .copy_from_slice(self.read_all()); + read_len = pos; + } else { + // chunk 块内真实数据指针位 + let chunk_index = pos % CHUNKE_SIZE as u64; + // 当前pos指向的chunk块在vec中的索引位置 + let current_vec_index = pos / CHUNKE_SIZE as u64; + // 若len大于chunk_index则说明,buf被分段存储 + if len > chunk_index { + // 尾段长度 + let last_len = chunk_index; + // 首段长度 + let first_len = len - last_len; + // 尾段数据 + let last_chunk_res = unsafe { + &(*(self.inner[current_vec_index as usize] as *const [u8; CHUNKE_SIZE])) + [0..(chunk_index as usize)] + }; + // 首段数据 + let first_chunk_res = unsafe { + &(*(self.inner[(current_vec_index - 1) as usize] + as *const [u8; CHUNKE_SIZE])) + [(CHUNKE_SIZE - first_len as usize)..] + }; + // 首段写入buf + let _ = + &(*buf)[..(len - chunk_index) as usize].copy_from_slice(first_chunk_res); + // 尾段写入buf + let _ = &(*buf)[(len - chunk_index) as usize..].copy_from_slice(last_chunk_res); + } else { + let res = unsafe { + &(*(self.inner[current_vec_index as usize] as *const [u8; CHUNKE_SIZE])) + [((chunk_index - len) as usize)..(chunk_index as usize)] + }; + buf.copy_from_slice(res); + } + read_len = len; + } + match self.pos.compare_exchange_weak( + pos, + pos - read_len, + Ordering::SeqCst, + Ordering::Relaxed, + ) { + Ok(_) => return Ok(read_len as usize), + Err(v) => { + pos = v; + continue; + } + } + } + } + + pub fn read_exact(&mut self, mut buf: &mut [u8]) -> stdlib::io::Result { + while !buf.is_empty() { + match self.read(buf) { + Ok(0) => break, + Ok(n) => { + let tmp = buf; + buf = &mut tmp[n..]; + } + Err(e) => return Err(e), + } + } + if !buf.is_empty() { + Err(stdlib::io::Error::new( + "there is no more memory to allocate", + )) + } else { + Ok(buf.len()) + } + } + + /// 从 point 出读取全部字节 + fn read_all(&mut self) -> &[u8] { + let mut pos = self.position(); + + let mut res; + if pos == 0 { + return &[]; + } + loop { + res = unsafe { &(*(self.inner[0] as *const [u8; CHUNKE_SIZE]))[..(pos as usize)] }; + match self + .pos + .compare_exchange_weak(pos, 0, Ordering::SeqCst, Ordering::Relaxed) + { + Ok(_) => return res, + Err(v) => { + pos = v; + continue; + } + } + } + } +} + +impl Drop for ChunkBuf { + fn drop(&mut self) { + for item in &self.inner { + MemoryPoll::memory_free(*(item) as *const u8) + } + } +} diff --git a/tools/src/io/test.rs b/tools/src/io/test.rs new file mode 100644 index 0000000..2b38993 --- /dev/null +++ b/tools/src/io/test.rs @@ -0,0 +1,138 @@ +#[test] +fn test_write_read() { + use super::ChunkBuf; + use std::println; + extern crate std; + let mut chunk_buf = ChunkBuf::new(); + // 剩余容量 + println!("剩余容量 len:{}", chunk_buf.get_margin()); + // 0xFFu8 1 + let _ = chunk_buf.write(&0xFFu8.to_le_bytes()[..]); + // 0xFEu8 2 + let _ = chunk_buf.write(&0xFEu8.to_le_bytes()[..]); + // 0xFDu8 3 + let _ = chunk_buf.write(&0xFDu8.to_le_bytes()[..]); + // 0xFCu8 4 + let _ = chunk_buf.write(&0xFCu8.to_le_bytes()[..]); + // 0xFBu8 5 + let _ = chunk_buf.write(&0xFBu8.to_le_bytes()[..]); + // 0xFAu8 6 + let _ = chunk_buf.write(&0xFAu8.to_le_bytes()[..]); + // 0xF9u8 7 + let _ = chunk_buf.write(&0xF9u8.to_le_bytes()[..]); + // 0xF8u8 8 + let _ = chunk_buf.write(&0xF8u8.to_le_bytes()[..]); + // 0xF7u8 9 + let _ = chunk_buf.write(&0xF7u8.to_le_bytes()[..]); + // 0xFFF6u16 10,11 + let _ = chunk_buf.write(&0xFFF6u16.to_le_bytes()[..]); + // 0xF5u8 12 + let _ = chunk_buf.write(&0xF5u8.to_le_bytes()[..]); + // 0xF4u8 13 + let _ = chunk_buf.write(&0xF4u8.to_le_bytes()[..]); + // 0xF3u8 14 + let _ = chunk_buf.write(&0xF3u8.to_le_bytes()[..]); + // 0xF2u8 15 + let _ = chunk_buf.write(&0xF2u8.to_le_bytes()[..]); + // 0xF1u8 16 + let _ = chunk_buf.write(&0xF1u8.to_le_bytes()[..]); + // 0xF0u8 17 + let _ = chunk_buf.write(&0xF0u8.to_le_bytes()[..]); + // 0xEFu8 18 + let _ = chunk_buf.write(&0xEFu8.to_le_bytes()[..]); + // 0xEEu8 19 + let _ = chunk_buf.write(&0xEEu8.to_le_bytes()[..]); + // 0xEDu8 20 + let _ = chunk_buf.write(&0xEDu8.to_le_bytes()[..]); + // 0xECu8 21 + let _ = chunk_buf.write(&0xECu8.to_le_bytes()[..]); + // 剩余容量 + println!(" 剩余容量 len:{}", chunk_buf.get_margin()); + + let mut read_buf = [0u8; 1]; + // 0xECu8 21 + let _ = chunk_buf.read(&mut read_buf); + assert_eq!(read_buf[0], 0xECu8); + // 0xEDu8 20 + let _ = chunk_buf.read(&mut read_buf); + assert_eq!(read_buf[0], 0xEDu8); + // 0xEEu8 19 + let _ = chunk_buf.read(&mut read_buf); + assert_eq!(read_buf[0], 0xEEu8); + // 0xEFu8 18 + let _ = chunk_buf.read(&mut read_buf); + assert_eq!(read_buf[0], 0xEFu8); + // 0xF0u8 17 + let _ = chunk_buf.read(&mut read_buf); + assert_eq!(read_buf[0], 0xF0u8); + // 0xF1u8 16 + let _ = chunk_buf.read(&mut read_buf); + assert_eq!(read_buf[0], 0xF1u8); + // 0xF2u8 15 + let _ = chunk_buf.read(&mut read_buf); + assert_eq!(read_buf[0], 0xF2u8); + // 0xF3u8 14 + let _ = chunk_buf.read(&mut read_buf); + assert_eq!(read_buf[0], 0xF3u8); + // 0xF4u8 13 + let _ = chunk_buf.read(&mut read_buf); + assert_eq!(read_buf[0], 0xF4u8); + // 0xF5u8 12 + let _ = chunk_buf.read(&mut read_buf); + assert_eq!(read_buf[0], 0xF5u8); + // 0xFFF6u16 10,11 + let mut read_buf2 = [0u8; 2]; + let _ = chunk_buf.read(&mut read_buf2); + assert_eq!(u16::from_le_bytes(read_buf2), 0xFFF6u16); + // 0xF7u8 9 + let _ = chunk_buf.read(&mut read_buf); + assert_eq!(read_buf[0], 0xF7u8); + // 0xF8u8 8 + let _ = chunk_buf.read(&mut read_buf); + assert_eq!(read_buf[0], 0xF8u8); + // 0xF9u8 7 + let _ = chunk_buf.read(&mut read_buf); + assert_eq!(read_buf[0], 0xF9u8); + // 0xFAu8 6 + let _ = chunk_buf.read(&mut read_buf); + assert_eq!(read_buf[0], 0xFAu8); + // 0xFBu8 5 + let _ = chunk_buf.read(&mut read_buf); + assert_eq!(read_buf[0], 0xFBu8); + // 0xFCu8 4 + let _ = chunk_buf.read(&mut read_buf); + assert_eq!(read_buf[0], 0xFCu8); + // 0xFDu8 3 + let _ = chunk_buf.read(&mut read_buf); + assert_eq!(read_buf[0], 0xFDu8); + // 0xFEu8 2 + let _ = chunk_buf.read(&mut read_buf); + assert_eq!(read_buf[0], 0xFEu8); + // 0xFFu8 1 + let _ = chunk_buf.read(&mut read_buf); + assert_eq!(read_buf[0], 0xFFu8); +} + +#[test] +fn test_thread() { + use super::ChunkBuf; + use std::println; + extern crate std; + let mut chunk_buf = ChunkBuf::new(); + for i in 0..10 { + let chunk_buf_ref = &chunk_buf; + let mut_ref = unsafe { &mut *(chunk_buf_ref as *const _ as *mut ChunkBuf) }; + stdlib::thread::spawn(move || { + let _ = mut_ref.write(&(0xFFu8 - i).to_le_bytes()[..]); + println!("len:{}", mut_ref.get_margin()); + }) + .join(); + } + println!("len:{}", chunk_buf.get_margin()); + let mut buf = [0u8; 10]; + let _ = chunk_buf.read(&mut buf); + for item in buf.iter() { + println!("{}", item) + } + assert_eq!(chunk_buf.get_margin(), 10240); +} diff --git a/tools/src/lib.rs b/tools/src/lib.rs index 6e3fac6..223528f 100644 --- a/tools/src/lib.rs +++ b/tools/src/lib.rs @@ -1,4 +1,8 @@ #![cfg_attr(feature = "alloc", no_std)] #![feature(const_maybe_uninit_zeroed)] +#![feature(slice_split_at_unchecked)] extern crate alloc; -pub mod memory_poll; +mod io; +mod memory_poll; +pub use io::*; +pub use memory_poll::*; diff --git a/tools/src/memory_poll.rs b/tools/src/memory_poll.rs index 7b4a570..1152d9b 100644 --- a/tools/src/memory_poll.rs +++ b/tools/src/memory_poll.rs @@ -3,7 +3,7 @@ use core::mem::size_of; use core::mem::MaybeUninit; use core::sync::atomic::{AtomicUsize, Ordering}; use stdlib::io::Result; -const CHUNKE_SIZE: usize = 1024 * 10; +pub const CHUNKE_SIZE: usize = 1024 * 10; const CHUNKE_NUMBER: usize = 8; const LAST_CHUNK: usize = CHUNKE_NUMBER - 1; static mut POOL: [Chunk; CHUNKE_NUMBER] = unsafe { MaybeUninit::zeroed().assume_init() }; diff --git a/tools/src/memory_poll/test.rs b/tools/src/memory_poll/test.rs index cf564b7..2c67b07 100644 --- a/tools/src/memory_poll/test.rs +++ b/tools/src/memory_poll/test.rs @@ -1,11 +1,9 @@ -use std::println; - -use crate::memory_poll::MemoryPoll; -use alloc::string::ToString; - -extern crate std; #[test] fn memory_poll_test() { + use crate::memory_poll::MemoryPoll; + use alloc::string::ToString; + + extern crate std; for _ in 0..4 { stdlib::thread::spawn(|| { for _ in 0..10000000 { diff --git a/types/Cargo.toml b/types/Cargo.toml index 29b349a..68c2d2a 100644 --- a/types/Cargo.toml +++ b/types/Cargo.toml @@ -6,8 +6,8 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [features] -default=["alloc"] -alloc=["stdlib/alloc"] -std=["stdlib/std"] +default = ["alloc"] +alloc = ["stdlib/alloc"] +std = ["stdlib/std"] [dependencies] -stdlib = { git = "https://gitee.com/iot-ua/stdlib.git", default-features = false,branch="develop"} +stdlib = { git = "https://gitee.com/iot-ua/stdlib.git", default-features = false, branch = "master" } -- Gitee From eda2c35cdcec57ab4902a671e13248e1f964be46 Mon Sep 17 00:00:00 2001 From: "hongwei.li" Date: Fri, 22 Jul 2022 16:58:21 +0800 Subject: [PATCH 4/6] =?UTF-8?q?=E6=96=B9=E4=BE=BF=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=EF=BC=8C=E4=BF=AE=E6=94=B9=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tools/src/memory_poll.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tools/src/memory_poll.rs b/tools/src/memory_poll.rs index 1152d9b..b3dcde5 100644 --- a/tools/src/memory_poll.rs +++ b/tools/src/memory_poll.rs @@ -3,7 +3,8 @@ use core::mem::size_of; use core::mem::MaybeUninit; use core::sync::atomic::{AtomicUsize, Ordering}; use stdlib::io::Result; -pub const CHUNKE_SIZE: usize = 1024 * 10; +// pub const CHUNKE_SIZE: usize = 1024 * 10; +pub const CHUNKE_SIZE: usize = 10; const CHUNKE_NUMBER: usize = 8; const LAST_CHUNK: usize = CHUNKE_NUMBER - 1; static mut POOL: [Chunk; CHUNKE_NUMBER] = unsafe { MaybeUninit::zeroed().assume_init() }; -- Gitee From ef8d9c88f3419d745e20422a9d3e2ce4a6b6e9b4 Mon Sep 17 00:00:00 2001 From: "hongwei.li" Date: Mon, 25 Jul 2022 17:21:33 +0800 Subject: [PATCH 5/6] =?UTF-8?q?=E4=BD=BF=E7=94=A8=E8=87=AA=E5=AE=9A?= =?UTF-8?q?=E4=B9=89=E5=86=85=E5=AD=98=E6=B1=A0=E5=AE=9E=E7=8E=B0=E5=9F=BA?= =?UTF-8?q?=E6=9C=AC=E7=B1=BB=E5=9E=8B=E7=9A=84encoding?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/Cargo.toml | 1 + core/src/lib.rs | 3 +- core/src/serialization/encoding.rs | 156 ++++++++++++++++++++++++ core/src/serialization/encoding/test.rs | 58 +++++++++ core/src/serialization/mod.rs | 2 + core/src/traits/block_process_trait.rs | 16 --- core/src/traits/mod.rs | 1 - core/src/types/mod.rs | 1 + core/src/types/tcp_types.rs | 1 + 9 files changed, 221 insertions(+), 18 deletions(-) create mode 100644 core/src/serialization/encoding.rs create mode 100644 core/src/serialization/encoding/test.rs create mode 100644 core/src/serialization/mod.rs delete mode 100644 core/src/traits/block_process_trait.rs delete mode 100644 core/src/traits/mod.rs create mode 100644 core/src/types/mod.rs create mode 100644 core/src/types/tcp_types.rs diff --git a/core/Cargo.toml b/core/Cargo.toml index faa290e..b0752da 100644 --- a/core/Cargo.toml +++ b/core/Cargo.toml @@ -10,4 +10,5 @@ alloc = ["stdlib/alloc"] std = ["stdlib/std"] [dependencies] types = { path = "../types" } +tools = { path = "../tools" } stdlib = { git = "https://gitee.com/iot-ua/stdlib.git", default-features = false, branch = "master" } diff --git a/core/src/lib.rs b/core/src/lib.rs index f949ac2..18fde4c 100644 --- a/core/src/lib.rs +++ b/core/src/lib.rs @@ -1,4 +1,5 @@ #![cfg_attr(feature = "alloc", no_std)] extern crate alloc; -pub mod traits; +mod serialization; +mod types; diff --git a/core/src/serialization/encoding.rs b/core/src/serialization/encoding.rs new file mode 100644 index 0000000..115f6ef --- /dev/null +++ b/core/src/serialization/encoding.rs @@ -0,0 +1,156 @@ +mod test; +use tools::ChunkBuf; +pub trait BinaryEncoder { + /// 返回结构体所占字节长度 + fn byte_len(&self) -> usize; + /// 将 实例 写入 stream + fn encode(&self, stream: &mut ChunkBuf) -> stdlib::io::Result; + /// 将实例读出一个实例 + fn decode(stream: &mut ChunkBuf) -> stdlib::io::Result; +} + +pub fn write_u8(stream: &mut ChunkBuf, value: T) -> stdlib::io::Result +where + T: Into, +{ + let buf: [u8; 1] = [value.into()]; + stream.write(&buf) +} + +pub fn write_i16(stream: &mut ChunkBuf, value: T) -> stdlib::io::Result +where + T: Into, +{ + let value: i16 = value.into(); + let buf: [u8; 2] = value.to_le_bytes(); + stream.write(&buf) +} + +pub fn write_u16(stream: &mut ChunkBuf, value: T) -> stdlib::io::Result +where + T: Into, +{ + let value: u16 = value.into(); + let buf: [u8; 2] = value.to_le_bytes(); + stream.write(&buf) +} + +pub fn write_i32(stream: &mut ChunkBuf, value: T) -> stdlib::io::Result +where + T: Into, +{ + let value: i32 = value.into(); + let buf: [u8; 4] = value.to_le_bytes(); + stream.write(&buf) +} + +pub fn write_u32(stream: &mut ChunkBuf, value: T) -> stdlib::io::Result +where + T: Into, +{ + let value: u32 = value.into(); + let buf: [u8; 4] = value.to_le_bytes(); + stream.write(&buf) +} + +pub fn write_i64(stream: &mut ChunkBuf, value: T) -> stdlib::io::Result +where + T: Into, +{ + let value: i64 = value.into(); + let buf: [u8; 8] = value.to_le_bytes(); + stream.write(&buf) +} + +pub fn write_u64(stream: &mut ChunkBuf, value: T) -> stdlib::io::Result +where + T: Into, +{ + let value: u64 = value.into(); + let buf: [u8; 8] = value.to_le_bytes(); + stream.write(&buf) +} + +pub fn write_f32(stream: &mut ChunkBuf, value: T) -> stdlib::io::Result +where + T: Into, +{ + let value: f32 = value.into(); + let buf: [u8; 4] = value.to_le_bytes(); + stream.write(&buf) +} + +pub fn write_f64(stream: &mut ChunkBuf, value: T) -> stdlib::io::Result +where + T: Into, +{ + let value: f64 = value.into(); + let buf: [u8; 8] = value.to_le_bytes(); + stream.write(&buf) +} + +pub fn read_bytes(stream: &mut ChunkBuf, buf: &mut [u8]) -> stdlib::io::Result { + stream.read_exact(buf) +} + +pub fn read_u8(stream: &mut ChunkBuf) -> stdlib::io::Result { + let mut buf = [0u8]; + let _ = stream.read_exact(&mut buf)?; + Ok(buf[0]) +} + +pub fn read_i16(stream: &mut ChunkBuf) -> stdlib::io::Result { + let mut buf = [0u8; 2]; + let _ = stream.read_exact(&mut buf)?; + let value = i16::from_le_bytes(buf); + Ok(value) +} + +pub fn read_u16(stream: &mut ChunkBuf) -> stdlib::io::Result { + let mut buf = [0u8; 2]; + let _ = stream.read_exact(&mut buf)?; + let value = u16::from_le_bytes(buf); + Ok(value) +} + +pub fn read_i32(stream: &mut ChunkBuf) -> stdlib::io::Result { + let mut buf = [0u8; 4]; + let _ = stream.read_exact(&mut buf)?; + let value = i32::from_le_bytes(buf); + Ok(value) +} + +pub fn read_u32(stream: &mut ChunkBuf) -> stdlib::io::Result { + let mut buf = [0u8; 4]; + let _ = stream.read_exact(&mut buf)?; + let value = u32::from_le_bytes(buf); + Ok(value) +} + +pub fn read_i64(stream: &mut ChunkBuf) -> stdlib::io::Result { + let mut buf = [0u8; 8]; + let _ = stream.read_exact(&mut buf)?; + let value = i64::from_le_bytes(buf); + Ok(value) +} + +pub fn read_u64(stream: &mut ChunkBuf) -> stdlib::io::Result { + let mut buf = [0u8; 8]; + let _ = stream.read_exact(&mut buf)?; + let value = u64::from_le_bytes(buf); + Ok(value) +} + +pub fn read_f32(stream: &mut ChunkBuf) -> stdlib::io::Result { + let mut buf = [0u8; 4]; + let _ = stream.read_exact(&mut buf)?; + let value = f32::from_le_bytes(buf); + Ok(value) +} + +pub fn read_f64(stream: &mut ChunkBuf) -> stdlib::io::Result { + let mut buf = [0u8; 8]; + let _ = stream.read_exact(&mut buf)?; + let value = f64::from_le_bytes(buf); + Ok(value) +} diff --git a/core/src/serialization/encoding/test.rs b/core/src/serialization/encoding/test.rs new file mode 100644 index 0000000..f0f241e --- /dev/null +++ b/core/src/serialization/encoding/test.rs @@ -0,0 +1,58 @@ +#[test] +fn test_read_write_basic_type() { + use super::*; + use tools::ChunkBuf; + struct A { + a: u8, + b: i16, + c: u16, + d: i32, + e: u32, + f: i64, + g: u64, + h: f32, + i: f64, + } + let a_struct = A { + a: 1, + b: -2, + c: 3, + d: -4, + e: 5, + f: -6, + g: 7, + h: 8.8, + i: 9.9, + }; + let mut chunk_buf = ChunkBuf::new(); + + let _ = write_u8(&mut chunk_buf, a_struct.a); + let _ = write_i16(&mut chunk_buf, a_struct.b); + let _ = write_u16(&mut chunk_buf, a_struct.c); + let _ = write_i32(&mut chunk_buf, a_struct.d); + let _ = write_u32(&mut chunk_buf, a_struct.e); + let _ = write_i64(&mut chunk_buf, a_struct.f); + let _ = write_u64(&mut chunk_buf, a_struct.g); + let _ = write_f32(&mut chunk_buf, a_struct.h); + let _ = write_f64(&mut chunk_buf, a_struct.i); + + let i = read_f64(&mut chunk_buf).unwrap(); + let h = read_f32(&mut chunk_buf).unwrap(); + let g = read_u64(&mut chunk_buf).unwrap(); + let f = read_i64(&mut chunk_buf).unwrap(); + let e = read_u32(&mut chunk_buf).unwrap(); + let d = read_i32(&mut chunk_buf).unwrap(); + let c = read_u16(&mut chunk_buf).unwrap(); + let b = read_i16(&mut chunk_buf).unwrap(); + let a = read_u8(&mut chunk_buf).unwrap(); + + assert_eq!(a, a_struct.a); + assert_eq!(b, a_struct.b); + assert_eq!(c, a_struct.c); + assert_eq!(d, a_struct.d); + assert_eq!(e, a_struct.e); + assert_eq!(f, a_struct.f); + assert_eq!(g, a_struct.g); + assert_eq!(h, a_struct.h); + assert_eq!(i, a_struct.i); +} diff --git a/core/src/serialization/mod.rs b/core/src/serialization/mod.rs new file mode 100644 index 0000000..e7df06f --- /dev/null +++ b/core/src/serialization/mod.rs @@ -0,0 +1,2 @@ +mod encoding; +pub use encoding::BinaryEncoder; diff --git a/core/src/traits/block_process_trait.rs b/core/src/traits/block_process_trait.rs deleted file mode 100644 index bd2c573..0000000 --- a/core/src/traits/block_process_trait.rs +++ /dev/null @@ -1,16 +0,0 @@ -use types::build_in::Result; -pub trait BolckProcessTrait { - fn check_blocks() -> Result; - - fn encode() -> Result; - - fn decode() -> Result; -} - -pub trait BlockInfoTrait { - fn new() -> Result; - - fn write_ack(&mut self) -> Result; - - fn write(&mut self) -> Result; -} diff --git a/core/src/traits/mod.rs b/core/src/traits/mod.rs deleted file mode 100644 index fb6efcf..0000000 --- a/core/src/traits/mod.rs +++ /dev/null @@ -1 +0,0 @@ -pub mod block_process_trait; diff --git a/core/src/types/mod.rs b/core/src/types/mod.rs new file mode 100644 index 0000000..4b4c173 --- /dev/null +++ b/core/src/types/mod.rs @@ -0,0 +1 @@ +mod tcp_types; diff --git a/core/src/types/tcp_types.rs b/core/src/types/tcp_types.rs new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/core/src/types/tcp_types.rs @@ -0,0 +1 @@ + -- Gitee From 3b2880b65b45490312d843fc0086227ff9ab2011 Mon Sep 17 00:00:00 2001 From: "hongwei.li" Date: Wed, 10 Aug 2022 14:01:56 +0800 Subject: [PATCH 6/6] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E7=89=88=E6=9D=83?= =?UTF-8?q?=E5=A3=B0=E6=98=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/src/lib.rs | 3 +++ core/src/serialization/encoding.rs | 3 +++ core/src/serialization/encoding/test.rs | 3 +++ core/src/serialization/mod.rs | 3 +++ core/src/types/mod.rs | 3 +++ core/src/types/tcp_types.rs | 3 +++ cypto/src/lib.rs | 3 +++ server/src/address_space/mod.rs | 3 +++ server/src/address_space/traits/address_space_trait.rs | 3 +++ server/src/address_space/traits/mod.rs | 3 +++ server/src/communication_services/mod.rs | 3 +++ server/src/communication_services/traits/mod.rs | 3 +++ .../traits/secure_channel_service_trait.rs | 3 +++ server/src/communication_services/traits/transport_tarit.rs | 3 +++ server/src/discovery/mod.rs | 3 +++ server/src/discovery/traits/discovery_trait.rs | 3 +++ server/src/discovery/traits/mod.rs | 3 +++ server/src/history/mod.rs | 3 +++ server/src/history/traits/mod.rs | 3 +++ server/src/lib.rs | 3 +++ server/src/server_security/mod.rs | 3 +++ server/src/server_security/traits/mod.rs | 3 +++ server/src/services/mod.rs | 3 +++ server/src/services/traits/attribute_trait.rs | 3 +++ server/src/services/traits/discovery_trait.rs | 3 +++ server/src/services/traits/method_trait.rs | 3 +++ server/src/services/traits/mod.rs | 3 +++ server/src/services/traits/monitored_item_trait.rs | 3 +++ server/src/services/traits/node_management_trait.rs | 3 +++ server/src/services/traits/query_trait.rs | 3 +++ server/src/services/traits/session_trait.rs | 3 +++ server/src/services/traits/subscription_trait.rs | 3 +++ server/src/services/traits/view_trait.rs | 3 +++ tools/src/io.rs | 3 +++ tools/src/io/test.rs | 3 +++ tools/src/lib.rs | 3 +++ tools/src/memory_poll.rs | 3 +++ tools/src/memory_poll/test.rs | 3 +++ types/src/build_in.rs | 3 +++ types/src/lib.rs | 3 +++ 40 files changed, 120 insertions(+) diff --git a/core/src/lib.rs b/core/src/lib.rs index 18fde4c..021123c 100644 --- a/core/src/lib.rs +++ b/core/src/lib.rs @@ -1,5 +1,8 @@ +// Copyright (C) 2022-2022 Agilor Co.,Ltd. All rights reserved. +// SPDX-License-Identifier: Apache-2.0 #![cfg_attr(feature = "alloc", no_std)] extern crate alloc; mod serialization; mod types; + diff --git a/core/src/serialization/encoding.rs b/core/src/serialization/encoding.rs index 115f6ef..6ba5e5c 100644 --- a/core/src/serialization/encoding.rs +++ b/core/src/serialization/encoding.rs @@ -1,3 +1,5 @@ +// Copyright (C) 2022-2022 Agilor Co.,Ltd. All rights reserved. +// SPDX-License-Identifier: Apache-2.0 mod test; use tools::ChunkBuf; pub trait BinaryEncoder { @@ -154,3 +156,4 @@ pub fn read_f64(stream: &mut ChunkBuf) -> stdlib::io::Result { let value = f64::from_le_bytes(buf); Ok(value) } + diff --git a/core/src/serialization/encoding/test.rs b/core/src/serialization/encoding/test.rs index f0f241e..f744f4e 100644 --- a/core/src/serialization/encoding/test.rs +++ b/core/src/serialization/encoding/test.rs @@ -1,3 +1,5 @@ +// Copyright (C) 2022-2022 Agilor Co.,Ltd. All rights reserved. +// SPDX-License-Identifier: Apache-2.0 #[test] fn test_read_write_basic_type() { use super::*; @@ -56,3 +58,4 @@ fn test_read_write_basic_type() { assert_eq!(h, a_struct.h); assert_eq!(i, a_struct.i); } + diff --git a/core/src/serialization/mod.rs b/core/src/serialization/mod.rs index e7df06f..8d34c2b 100644 --- a/core/src/serialization/mod.rs +++ b/core/src/serialization/mod.rs @@ -1,2 +1,5 @@ +// Copyright (C) 2022-2022 Agilor Co.,Ltd. All rights reserved. +// SPDX-License-Identifier: Apache-2.0 mod encoding; pub use encoding::BinaryEncoder; + diff --git a/core/src/types/mod.rs b/core/src/types/mod.rs index 4b4c173..9941d6a 100644 --- a/core/src/types/mod.rs +++ b/core/src/types/mod.rs @@ -1 +1,4 @@ +// Copyright (C) 2022-2022 Agilor Co.,Ltd. All rights reserved. +// SPDX-License-Identifier: Apache-2.0 mod tcp_types; + diff --git a/core/src/types/tcp_types.rs b/core/src/types/tcp_types.rs index 8b13789..290b56e 100644 --- a/core/src/types/tcp_types.rs +++ b/core/src/types/tcp_types.rs @@ -1 +1,4 @@ +// Copyright (C) 2022-2022 Agilor Co.,Ltd. All rights reserved. +// SPDX-License-Identifier: Apache-2.0 + diff --git a/cypto/src/lib.rs b/cypto/src/lib.rs index 809d067..896c38e 100644 --- a/cypto/src/lib.rs +++ b/cypto/src/lib.rs @@ -1,2 +1,5 @@ +// Copyright (C) 2022-2022 Agilor Co.,Ltd. All rights reserved. +// SPDX-License-Identifier: Apache-2.0 #![cfg_attr(feature = "alloc", no_std)] extern crate alloc; + diff --git a/server/src/address_space/mod.rs b/server/src/address_space/mod.rs index f6ac8fc..e1131db 100644 --- a/server/src/address_space/mod.rs +++ b/server/src/address_space/mod.rs @@ -1 +1,4 @@ +// Copyright (C) 2022-2022 Agilor Co.,Ltd. All rights reserved. +// SPDX-License-Identifier: Apache-2.0 pub mod traits; + diff --git a/server/src/address_space/traits/address_space_trait.rs b/server/src/address_space/traits/address_space_trait.rs index 1947b0a..8245dd8 100644 --- a/server/src/address_space/traits/address_space_trait.rs +++ b/server/src/address_space/traits/address_space_trait.rs @@ -1,3 +1,5 @@ +// Copyright (C) 2022-2022 Agilor Co.,Ltd. All rights reserved. +// SPDX-License-Identifier: Apache-2.0 use types::build_in::Result; pub trait AddressSpaceTrait { /// Constructs a default address space @@ -46,3 +48,4 @@ pub trait AddressSpaceTrait { /// Returns the references fn references(&self) -> Result; } + diff --git a/server/src/address_space/traits/mod.rs b/server/src/address_space/traits/mod.rs index 5bed418..bb0b16c 100644 --- a/server/src/address_space/traits/mod.rs +++ b/server/src/address_space/traits/mod.rs @@ -1 +1,4 @@ +// Copyright (C) 2022-2022 Agilor Co.,Ltd. All rights reserved. +// SPDX-License-Identifier: Apache-2.0 pub mod address_space_trait; + diff --git a/server/src/communication_services/mod.rs b/server/src/communication_services/mod.rs index f6ac8fc..e1131db 100644 --- a/server/src/communication_services/mod.rs +++ b/server/src/communication_services/mod.rs @@ -1 +1,4 @@ +// Copyright (C) 2022-2022 Agilor Co.,Ltd. All rights reserved. +// SPDX-License-Identifier: Apache-2.0 pub mod traits; + diff --git a/server/src/communication_services/traits/mod.rs b/server/src/communication_services/traits/mod.rs index af4705a..a0d62f2 100644 --- a/server/src/communication_services/traits/mod.rs +++ b/server/src/communication_services/traits/mod.rs @@ -1,2 +1,5 @@ +// Copyright (C) 2022-2022 Agilor Co.,Ltd. All rights reserved. +// SPDX-License-Identifier: Apache-2.0 pub mod secure_channel_service_trait; pub mod transport_tarit; + diff --git a/server/src/communication_services/traits/secure_channel_service_trait.rs b/server/src/communication_services/traits/secure_channel_service_trait.rs index e82b58e..181cb18 100644 --- a/server/src/communication_services/traits/secure_channel_service_trait.rs +++ b/server/src/communication_services/traits/secure_channel_service_trait.rs @@ -1,3 +1,5 @@ +// Copyright (C) 2022-2022 Agilor Co.,Ltd. All rights reserved. +// SPDX-License-Identifier: Apache-2.0 use types::build_in::Result; pub trait SecureChannelServiceTrait { fn new() -> Result; @@ -6,3 +8,4 @@ pub trait SecureChannelServiceTrait { fn close_secure_channel() -> Result; } + diff --git a/server/src/communication_services/traits/transport_tarit.rs b/server/src/communication_services/traits/transport_tarit.rs index 1ddab0e..33bc626 100644 --- a/server/src/communication_services/traits/transport_tarit.rs +++ b/server/src/communication_services/traits/transport_tarit.rs @@ -1,3 +1,5 @@ +// Copyright (C) 2022-2022 Agilor Co.,Ltd. All rights reserved. +// SPDX-License-Identifier: Apache-2.0 use alloc::string::String; use types::build_in::Result; pub trait Transport { @@ -19,3 +21,4 @@ pub trait Transport { /// Test if the session is terminated fn is_session_terminated(&self) -> bool; } + diff --git a/server/src/discovery/mod.rs b/server/src/discovery/mod.rs index f6ac8fc..e1131db 100644 --- a/server/src/discovery/mod.rs +++ b/server/src/discovery/mod.rs @@ -1 +1,4 @@ +// Copyright (C) 2022-2022 Agilor Co.,Ltd. All rights reserved. +// SPDX-License-Identifier: Apache-2.0 pub mod traits; + diff --git a/server/src/discovery/traits/discovery_trait.rs b/server/src/discovery/traits/discovery_trait.rs index d446b5a..d74e4a6 100644 --- a/server/src/discovery/traits/discovery_trait.rs +++ b/server/src/discovery/traits/discovery_trait.rs @@ -1,4 +1,7 @@ +// Copyright (C) 2022-2022 Agilor Co.,Ltd. All rights reserved. +// SPDX-License-Identifier: Apache-2.0 pub trait DiscoveryTrait { /// Registers the specified endpoints with the specified discovery server fn register_with_discovery_server(discovery_server_url: &str); } + diff --git a/server/src/discovery/traits/mod.rs b/server/src/discovery/traits/mod.rs index 24c8a1c..03041bc 100644 --- a/server/src/discovery/traits/mod.rs +++ b/server/src/discovery/traits/mod.rs @@ -1 +1,4 @@ +// Copyright (C) 2022-2022 Agilor Co.,Ltd. All rights reserved. +// SPDX-License-Identifier: Apache-2.0 pub mod discovery_trait; + diff --git a/server/src/history/mod.rs b/server/src/history/mod.rs index f6ac8fc..e1131db 100644 --- a/server/src/history/mod.rs +++ b/server/src/history/mod.rs @@ -1 +1,4 @@ +// Copyright (C) 2022-2022 Agilor Co.,Ltd. All rights reserved. +// SPDX-License-Identifier: Apache-2.0 pub mod traits; + diff --git a/server/src/history/traits/mod.rs b/server/src/history/traits/mod.rs index e69de29..8b2c719 100644 --- a/server/src/history/traits/mod.rs +++ b/server/src/history/traits/mod.rs @@ -0,0 +1,3 @@ +// Copyright (C) 2022-2022 Agilor Co.,Ltd. All rights reserved. +// SPDX-License-Identifier: Apache-2.0 + diff --git a/server/src/lib.rs b/server/src/lib.rs index 746c75c..0982cdb 100644 --- a/server/src/lib.rs +++ b/server/src/lib.rs @@ -1,3 +1,5 @@ +// Copyright (C) 2022-2022 Agilor Co.,Ltd. All rights reserved. +// SPDX-License-Identifier: Apache-2.0 #![cfg_attr(feature = "alloc", no_std)] extern crate alloc; @@ -7,3 +9,4 @@ pub mod discovery; pub mod history; pub mod server_security; pub mod services; + diff --git a/server/src/server_security/mod.rs b/server/src/server_security/mod.rs index f6ac8fc..e1131db 100644 --- a/server/src/server_security/mod.rs +++ b/server/src/server_security/mod.rs @@ -1 +1,4 @@ +// Copyright (C) 2022-2022 Agilor Co.,Ltd. All rights reserved. +// SPDX-License-Identifier: Apache-2.0 pub mod traits; + diff --git a/server/src/server_security/traits/mod.rs b/server/src/server_security/traits/mod.rs index e69de29..8b2c719 100644 --- a/server/src/server_security/traits/mod.rs +++ b/server/src/server_security/traits/mod.rs @@ -0,0 +1,3 @@ +// Copyright (C) 2022-2022 Agilor Co.,Ltd. All rights reserved. +// SPDX-License-Identifier: Apache-2.0 + diff --git a/server/src/services/mod.rs b/server/src/services/mod.rs index f6ac8fc..e1131db 100644 --- a/server/src/services/mod.rs +++ b/server/src/services/mod.rs @@ -1 +1,4 @@ +// Copyright (C) 2022-2022 Agilor Co.,Ltd. All rights reserved. +// SPDX-License-Identifier: Apache-2.0 pub mod traits; + diff --git a/server/src/services/traits/attribute_trait.rs b/server/src/services/traits/attribute_trait.rs index 01ac98e..b761deb 100644 --- a/server/src/services/traits/attribute_trait.rs +++ b/server/src/services/traits/attribute_trait.rs @@ -1,3 +1,5 @@ +// Copyright (C) 2022-2022 Agilor Co.,Ltd. All rights reserved. +// SPDX-License-Identifier: Apache-2.0 use types::build_in::Result; pub trait AttributeTrait { fn new() -> Result; @@ -14,3 +16,4 @@ pub trait AttributeTrait { /// Used to update or update historical values fn history_update(&self /* TODO */) -> Result; } + diff --git a/server/src/services/traits/discovery_trait.rs b/server/src/services/traits/discovery_trait.rs index 7aceb07..2c98051 100644 --- a/server/src/services/traits/discovery_trait.rs +++ b/server/src/services/traits/discovery_trait.rs @@ -1,3 +1,5 @@ +// Copyright (C) 2022-2022 Agilor Co.,Ltd. All rights reserved. +// SPDX-License-Identifier: Apache-2.0 use types::build_in::Result; pub trait DiscoverTrait { fn new() -> Result; @@ -8,3 +10,4 @@ pub trait DiscoverTrait { fn find_servers(&self /* TODO */) -> Result; } + diff --git a/server/src/services/traits/method_trait.rs b/server/src/services/traits/method_trait.rs index 310d07f..9d1eb36 100644 --- a/server/src/services/traits/method_trait.rs +++ b/server/src/services/traits/method_trait.rs @@ -1,6 +1,9 @@ +// Copyright (C) 2022-2022 Agilor Co.,Ltd. All rights reserved. +// SPDX-License-Identifier: Apache-2.0 use types::build_in::Result; pub trait MethodTrait { fn new() -> Result; fn call(&self /* TODO */) -> Result; } + diff --git a/server/src/services/traits/mod.rs b/server/src/services/traits/mod.rs index e23ab1e..51f8f03 100644 --- a/server/src/services/traits/mod.rs +++ b/server/src/services/traits/mod.rs @@ -1,3 +1,5 @@ +// Copyright (C) 2022-2022 Agilor Co.,Ltd. All rights reserved. +// SPDX-License-Identifier: Apache-2.0 pub mod attribute_trait; pub mod discovery_trait; pub mod method_trait; @@ -7,3 +9,4 @@ pub mod query_trait; pub mod session_trait; pub mod subscription_trait; pub mod view_trait; + diff --git a/server/src/services/traits/monitored_item_trait.rs b/server/src/services/traits/monitored_item_trait.rs index 9a52360..cade736 100644 --- a/server/src/services/traits/monitored_item_trait.rs +++ b/server/src/services/traits/monitored_item_trait.rs @@ -1,3 +1,5 @@ +// Copyright (C) 2022-2022 Agilor Co.,Ltd. All rights reserved. +// SPDX-License-Identifier: Apache-2.0 use types::build_in::Result; pub trait MonitoredItemTrait { fn new() -> Result; @@ -12,3 +14,4 @@ pub trait MonitoredItemTrait { fn delete_monitored_items(&self /* TODO */) -> Result; } + diff --git a/server/src/services/traits/node_management_trait.rs b/server/src/services/traits/node_management_trait.rs index 6a3ce54..58bad6d 100644 --- a/server/src/services/traits/node_management_trait.rs +++ b/server/src/services/traits/node_management_trait.rs @@ -1,3 +1,5 @@ +// Copyright (C) 2022-2022 Agilor Co.,Ltd. All rights reserved. +// SPDX-License-Identifier: Apache-2.0 use types::build_in::Result; pub trait NodeManagementTrait { fn new() -> Result; @@ -10,3 +12,4 @@ pub trait NodeManagementTrait { fn delete_references(&self /* TODO */) -> Result; } + diff --git a/server/src/services/traits/query_trait.rs b/server/src/services/traits/query_trait.rs index 781a90e..bf4bcc1 100644 --- a/server/src/services/traits/query_trait.rs +++ b/server/src/services/traits/query_trait.rs @@ -1,3 +1,5 @@ +// Copyright (C) 2022-2022 Agilor Co.,Ltd. All rights reserved. +// SPDX-License-Identifier: Apache-2.0 use types::build_in::Result; pub trait QuertTrait { fn new() -> Result; @@ -6,3 +8,4 @@ pub trait QuertTrait { fn query_next(&self /* TODO */) -> Result; } + diff --git a/server/src/services/traits/session_trait.rs b/server/src/services/traits/session_trait.rs index 181a089..7985832 100644 --- a/server/src/services/traits/session_trait.rs +++ b/server/src/services/traits/session_trait.rs @@ -1,3 +1,5 @@ +// Copyright (C) 2022-2022 Agilor Co.,Ltd. All rights reserved. +// SPDX-License-Identifier: Apache-2.0 use types::build_in::Result; pub trait SessionTrait { fn new() -> Result; @@ -10,3 +12,4 @@ pub trait SessionTrait { fn cancel(&self /* TODO */) -> Result; } + diff --git a/server/src/services/traits/subscription_trait.rs b/server/src/services/traits/subscription_trait.rs index 6c91a5c..e3f760d 100644 --- a/server/src/services/traits/subscription_trait.rs +++ b/server/src/services/traits/subscription_trait.rs @@ -1,3 +1,5 @@ +// Copyright (C) 2022-2022 Agilor Co.,Ltd. All rights reserved. +// SPDX-License-Identifier: Apache-2.0 use types::build_in::Result; pub trait SubscriptionTrait { fn new() -> Result; @@ -16,3 +18,4 @@ pub trait SubscriptionTrait { fn republish(&self /* TODO */) -> Result; } + diff --git a/server/src/services/traits/view_trait.rs b/server/src/services/traits/view_trait.rs index 520bfda..40d870f 100644 --- a/server/src/services/traits/view_trait.rs +++ b/server/src/services/traits/view_trait.rs @@ -1,3 +1,5 @@ +// Copyright (C) 2022-2022 Agilor Co.,Ltd. All rights reserved. +// SPDX-License-Identifier: Apache-2.0 use types::build_in::Result; pub trait ViewTrait { fn new() -> Result; @@ -10,3 +12,4 @@ pub trait ViewTrait { fn unregister_nodes(&self /* TODO */) -> Result; } + diff --git a/tools/src/io.rs b/tools/src/io.rs index 93b3705..1369473 100644 --- a/tools/src/io.rs +++ b/tools/src/io.rs @@ -1,3 +1,5 @@ +// Copyright (C) 2022-2022 Agilor Co.,Ltd. All rights reserved. +// SPDX-License-Identifier: Apache-2.0 mod test; use core::sync::atomic::{AtomicU64, Ordering}; @@ -235,3 +237,4 @@ impl Drop for ChunkBuf { } } } + diff --git a/tools/src/io/test.rs b/tools/src/io/test.rs index 2b38993..628464c 100644 --- a/tools/src/io/test.rs +++ b/tools/src/io/test.rs @@ -1,3 +1,5 @@ +// Copyright (C) 2022-2022 Agilor Co.,Ltd. All rights reserved. +// SPDX-License-Identifier: Apache-2.0 #[test] fn test_write_read() { use super::ChunkBuf; @@ -136,3 +138,4 @@ fn test_thread() { } assert_eq!(chunk_buf.get_margin(), 10240); } + diff --git a/tools/src/lib.rs b/tools/src/lib.rs index 223528f..fa04428 100644 --- a/tools/src/lib.rs +++ b/tools/src/lib.rs @@ -1,3 +1,5 @@ +// Copyright (C) 2022-2022 Agilor Co.,Ltd. All rights reserved. +// SPDX-License-Identifier: Apache-2.0 #![cfg_attr(feature = "alloc", no_std)] #![feature(const_maybe_uninit_zeroed)] #![feature(slice_split_at_unchecked)] @@ -6,3 +8,4 @@ mod io; mod memory_poll; pub use io::*; pub use memory_poll::*; + diff --git a/tools/src/memory_poll.rs b/tools/src/memory_poll.rs index b3dcde5..c9bea47 100644 --- a/tools/src/memory_poll.rs +++ b/tools/src/memory_poll.rs @@ -1,3 +1,5 @@ +// Copyright (C) 2022-2022 Agilor Co.,Ltd. All rights reserved. +// SPDX-License-Identifier: Apache-2.0 mod test; use core::mem::size_of; use core::mem::MaybeUninit; @@ -111,3 +113,4 @@ impl MemoryPoll { } } } + diff --git a/tools/src/memory_poll/test.rs b/tools/src/memory_poll/test.rs index 2c67b07..c92bed7 100644 --- a/tools/src/memory_poll/test.rs +++ b/tools/src/memory_poll/test.rs @@ -1,3 +1,5 @@ +// Copyright (C) 2022-2022 Agilor Co.,Ltd. All rights reserved. +// SPDX-License-Identifier: Apache-2.0 #[test] fn memory_poll_test() { use crate::memory_poll::MemoryPoll; @@ -26,3 +28,4 @@ fn memory_poll_test() { .join(); } } + diff --git a/types/src/build_in.rs b/types/src/build_in.rs index 9e6060f..53113fe 100644 --- a/types/src/build_in.rs +++ b/types/src/build_in.rs @@ -1 +1,4 @@ +// Copyright (C) 2022-2022 Agilor Co.,Ltd. All rights reserved. +// SPDX-License-Identifier: Apache-2.0 pub struct Result; + diff --git a/types/src/lib.rs b/types/src/lib.rs index 2e62dbd..6741699 100644 --- a/types/src/lib.rs +++ b/types/src/lib.rs @@ -1,4 +1,7 @@ +// Copyright (C) 2022-2022 Agilor Co.,Ltd. All rights reserved. +// SPDX-License-Identifier: Apache-2.0 #![cfg_attr(feature = "alloc", no_std)] extern crate alloc; pub mod build_in; + -- Gitee