状态机中的动态目标

发布于 2024-10-19 08:01:41 字数 717 浏览 2 评论 0原文

在使用 SCXML 制作的状态机中,有没有办法为转换设置动态目标值?

我的意思是,假设我有一个名为“obj”的对象,它已被设置为 scxml 的数据模型。因此可以在其上设置条件(如果对象中有一个名为 checkCondition 的属性),例如:

cond="obj.checkCondition"

<state id="state1">
    <transition cond="obj.checkCondition" target="state2"/>
</state>
<state id="state2">
    ...
</state>

我在 obj 中有另一个名为 nextTarget 的属性。我想在此转换中设置目标,从对象中读取其值(就像在条件中完成的那样)。

<state id="state1">
    <transition cond="obj.checkCondition" target="eval(obj.nextTarget)"/>
</state>
<!-- Where in obj.nextTarget there it has been set as value "state1", "state2" or any state name -->

有什么语法可以做到这一点吗?

谢谢。

In a state machine made with SCXML, is there any way to set a dynamic target value for a transition?

I mean, suppose I have an object called "obj" which has been set as the datamodel for a scxml. So there can be set conditions (if there were a property called checkCondition in the object) on it like:

cond="obj.checkCondition"

<state id="state1">
    <transition cond="obj.checkCondition" target="state2"/>
</state>
<state id="state2">
    ...
</state>

I have another property in obj called nextTarget. I want to set the target in this transition reading its value from the object (as it is done in the conditions).

<state id="state1">
    <transition cond="obj.checkCondition" target="eval(obj.nextTarget)"/>
</state>
<!-- Where in obj.nextTarget there it has been set as value "state1", "state2" or any state name -->

Is there any syntax to do this?

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

偷得浮生 2024-10-26 08:01:41

您可以在过渡元素中指定 cond 属性

<transition cond="data.value > 10" target="state2"/>

You can specify the cond attribute in a transition element

<transition cond="data.value > 10" target="state2"/>
东京女 2024-10-26 08:01:41

您正在尝试构建非常面向应用程序的复杂状态机框架。这有点像为每个电子表格应用程序构建自己的电子表格框架而不是使用 EXCEL。更好的方法可能是使用现有框架并在 SCXML 中定义事件和操作。您可以在 www.StateSoft.org -> 中查看 SM API 框架的示例。状态机画廊。

-贾努斯

You are trying to build very application oriented, complicated State Machine framework. This is a bit like building own spreadsheet framework for every spreadsheet application instead of using EXCEL. A better approach may be to use existing framework and define your events and actions in SCXML. You can see examples of SM API framework in www.StateSoft.org -> State Machine Gallery.

-Janusz

遥远的她 2024-10-26 08:01:41

SCXML 是对状态以及这些状态之间可能的转换的相当简单的描述。不存在条件转换之类的东西。

但是,每个状态可以有多个转换。从某个状态转换的次数没有限制。

所以你的问题的答案是你有尽可能多的转换来描述你想要去的条件方向,并且你评估其他地方的条件(即在Java中)。

示例来源是 SCXML 维基百科条目

<state id="ready">
    <transition event="watch.start" target="running"/>
</state>
<state id="running">
    <transition event="watch.split" target="paused"/>
    <transition event="watch.stop" target="stopped"/>
</state>
<state id="paused">
    <transition event="watch.unsplit" target="running"/>
    <transition event="watch.stop" target="stopped"/>
</state>
<state id="stopped">
    <transition event="watch.reset" target="ready"/>
</state>

在此处输入图像描述

SCXML is a fairly simple description of states and the possible transitions between those states. There's no such thing as conditional transitions.

However, you can have more than one transition from each state. There's no limit on the number of transitions you have from a state.

So the answer to your question is you have as many transitions as are required to describe the conditional directions you wish to go, and you evaluate the conditions elsewhere (i.e. in Java).

Example source is the SCXML Wikipedia entry.

<state id="ready">
    <transition event="watch.start" target="running"/>
</state>
<state id="running">
    <transition event="watch.split" target="paused"/>
    <transition event="watch.stop" target="stopped"/>
</state>
<state id="paused">
    <transition event="watch.unsplit" target="running"/>
    <transition event="watch.stop" target="stopped"/>
</state>
<state id="stopped">
    <transition event="watch.reset" target="ready"/>
</state>

enter image description here

漆黑的白昼 2024-10-26 08:01:41

虽然@Charles Goodwin 的答案非常准确......我可以添加我的话。简化一下:

  • 您的设计内容:您有一个过渡
    my_transition
  • 你想要什么:这个转变可能会导致
    几个 state_targets

您完全隐藏了问题的逻辑。

您应该拥有:多个转换

  • my_transition_A 目标 state_A_target
  • my_transition_B 目标 state_B_target
  • my_transition_C 目标 state_C_target
  • my_transition_D 目标 state_D_target...

以及在设计中动态设置目标的进程将动态处理 my_transition_A 的事件或 my_transition_C...就像它会在您的设计中选择 target_state 一样)。

Although the answer of @Charles Goodwin is pretty acurate... I may add my words. To simplify:

  • What you have in your design: you have one transition
    my_transition
  • What you woud like: that this transition may lead to
    several state_targets

You are sheerly hiding the logic of the problem.

What you should have: several transitions

  • my_transition_A targetting state_A_target
  • my_transition_B targetting state_B_target
  • my_transition_C targetting state_C_target
  • my_transition_D targetting state_D_target...

and the process which would have dynamically set the target in your design, will dynamically process the event for my_transition_A or my_transition_C... just like it would have chosen the target_state in your design).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文