Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
R
RoboPLC
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
黄新宇
RoboPLC
Commits
c3640f8d
提交
c3640f8d
authored
3月 12, 2024
作者:
Serhij S
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
docs & fixes
上级
982405a3
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
81 行增加
和
2 行删除
+81
-2
Cargo.toml
roboplc-derive/Cargo.toml
+4
-1
lib.rs
roboplc-derive/src/lib.rs
+77
-1
没有找到文件。
roboplc-derive/Cargo.toml
浏览文件 @
c3640f8d
[package]
[package]
name
=
"roboplc-derive"
name
=
"roboplc-derive"
version
=
"0.1.
1
"
version
=
"0.1.
2
"
edition
=
"2021"
edition
=
"2021"
authors
=
[
"Serhij S. <div@altertech.com>"
]
authors
=
[
"Serhij S. <div@altertech.com>"
]
license
=
"Apache-2.0"
license
=
"Apache-2.0"
...
@@ -17,3 +17,6 @@ syn = { version = "1.0", features = ["full"] }
...
@@ -17,3 +17,6 @@ syn = { version = "1.0", features = ["full"] }
quote
=
"1.0"
quote
=
"1.0"
proc-macro2
=
"1.0"
proc-macro2
=
"1.0"
darling
=
"0.13.0"
darling
=
"0.13.0"
[dev-dependencies]
roboplc
=
"0.1"
roboplc-derive/src/lib.rs
浏览文件 @
c3640f8d
...
@@ -3,6 +3,41 @@ use proc_macro::TokenStream;
...
@@ -3,6 +3,41 @@ use proc_macro::TokenStream;
use
quote
::
quote
;
use
quote
::
quote
;
use
syn
::{
parse_macro_input
,
Data
,
DeriveInput
,
Fields
,
Lit
,
Meta
,
MetaNameValue
,
NestedMeta
};
use
syn
::{
parse_macro_input
,
Data
,
DeriveInput
,
Fields
,
Lit
,
Meta
,
MetaNameValue
,
NestedMeta
};
/// Automatically implements the `DataDeliveryPolicy` trait for an enum
///
/// Atrributes (should be spcified for each enum variant):
///
/// * `data_delivery` - Specifies the delivery policy for a variant. The value can be one of the
/// following: `single`, `single_optional`, `optional`, `always`. If not specified, the default is
/// *always*.
///
/// * `data_priority` - Specifies the priority for a variant, lower is better. The value must be an
/// integer. If not specified, the default is *100*.
///
/// * `data_expires` - Specifies if the data expires. The value must be a function that returns
/// boolean. If not specified, the default is *false* (i.e. data does not expire). For named
/// associated data, the source MUST be stored in `value` field.
///
/// Example:
///
/// ```rust
/// use roboplc::DataPolicy;
/// use roboplc::ttlcell::TtlCell;
///
/// #[derive(DataPolicy)]
/// enum MyEnum {
/// #[data_delivery(single)]
/// #[data_priority(10)]
/// #[data_expires(TtlCell::is_expired)]
/// SensorData(TtlCell<f32>),
/// #[data_delivery(optional)]
/// DatabaseTelemetry(f32),
/// // the default one, can be omitted
/// #[data_delivery(always)]
/// Shutdown,
/// }
/// ```
///
/// # Panics
/// # Panics
///
///
/// Will panic on parse errors
/// Will panic on parse errors
...
@@ -175,6 +210,47 @@ fn parse_delivery_policy(s: Option<&str>) -> proc_macro2::TokenStream {
...
@@ -175,6 +210,47 @@ fn parse_delivery_policy(s: Option<&str>) -> proc_macro2::TokenStream {
}
}
}
}
/// Automatically implements the `WorkerOptions` trait for a worker struct
///
/// Provides an attribute #[worker_opts] to specify the worker options. The attribute can be
/// specifieid multiple times.
///
/// Atrribute arguments:
///
/// * `name` - Specifies the name of the worker. The value is mandatory and must be a quoted
/// string. The name must be unique and must be 15 characters or less.
///
/// * `stack_size` - Specifies the stack size for the worker
///
/// * `scheduling` - Specifies the scheduling policy for the worker. The value can be one of the:
/// `roundrobin`, `fifo`, `idle`, `batch`, `deadline`, `normal`. If not specified, the default is
/// `normal`.
///
/// * `priority` - Specifies the real-time priority for the worker, higher is better. If specified,
/// the scheduling policy must be `fifo`, `roundrobin` or `deadline`.
///
/// * `cpu` - Specifies the CPU affinity for the worker. The value can be a single CPU number or a
/// range of CPUs separated by a dash. The value can be a quoted string or an integer.
///
/// Example:
///
/// ```rust
/// use roboplc::controller::prelude::*;
///
/// #[derive(WorkerOpts)]
/// #[worker_opts(name = "my_worker", stack_size = 8192, scheduling = "fifo", priority = 80, cpu = "0-3")]
/// struct MyWorker {
/// // some fields
/// }
///
/// #[derive(WorkerOpts)]
/// #[worker_opts(name = "my_worker2", scheduling = "fifo", priority = 80, cpu = 1)]
/// struct MyWorker2 {
/// // some fields
/// }
/// ```
///
///
/// # Panics
/// # Panics
///
///
/// Will panic if the worker name is not specified or is invalid
/// Will panic if the worker name is not specified or is invalid
...
@@ -298,7 +374,7 @@ pub fn worker_opts_derive(input: TokenStream) -> TokenStream {
...
@@ -298,7 +374,7 @@ pub fn worker_opts_derive(input: TokenStream) -> TokenStream {
quote!
{}
quote!
{}
};
};
let
expanded
=
quote!
{
let
expanded
=
quote!
{
impl
WorkerOptions
for
#
name
{
impl
::
roboplc
::
controller
::
WorkerOptions
for
#
name
{
fn
worker_name
(
&
self
)
->
&
str
{
fn
worker_name
(
&
self
)
->
&
str
{
#
worker_name
#
worker_name
}
}
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论