jkrumow / tbstatemachine Goto Github PK
View Code? Open in Web Editor NEWA lightweight hierarchical state machine framework in Objective-C.
License: MIT License
A lightweight hierarchical state machine framework in Objective-C.
License: MIT License
Hello,
I am playing with the state machine and I have the following example
TBSMStateMachine *sm = [TBSMStateMachine stateMachineWithName:@"SM"];
TBSMStateMachine *smA = [TBSMStateMachine stateMachineWithName:@"SMA"];
TBSMSubState *a = [TBSMSubState subStateWithName:@"A"];
TBSMState *a1 = [TBSMState stateWithName:@"A1"];
TBSMState *a2 = [TBSMState stateWithName:@"A2"];
smA.states = @[a1,a2];
a.stateMachine = smA;
sm.states = @[a];
sm.initialState = a;
[sm setUp:nil];
I've noticed that A1 is the default state of SMA by default and it's enterBlock
is called at setup.
It is not possible to be in state A and not be in the same time in state A1?
Please help me understand what I am missing,
Thank you
-switchState:data:action:
to -switchPath:data:action:
-enter:(id<TBStateMachineNode>)state data:(NSDictionary *)data
to -enter:(NSArray *)state data:(NSDictionary *)data
-exit:(id<TBStateMachineNode>)state data:(NSDictionary *)data
to -exit:(NSArray *)state data:(NSDictionary *)data
When scheduleEvent:data: is called from different concurrent threads:
Hi,
How can I create a parent state which listen to event, transition its substates and still listen to the same event.
Generally speaking:
I have 3 states: stateA, stateB, stateC
and one event eventA with attached data dataA
Statemachine is in stateA and receives eventA.
if dataA is valid statemachine should switch to stateB if not it should switch to stateC.
What is best practice for doing it with your library.
Here is my current implementation, but I am not sure that it is a good practice.
[waitingForFirstVideoFrame addHandlerForEvent:ZZMRecordingSessionVideoFrameEvent
target:recording
kind:TBSMTransitionExternal
action:nil
guard:^BOOL(TBSMState * _Nullable sourceState, TBSMState * _Nullable targetState, ZZMFrame *videoFrame) {
BOOL setup = [self startRecordingWithFrame:videoFrame];
if (!setup) {
[_stateMachine switchState:sourceState targetState:die action:nil data:nil];
}
return setup;
}];
Thank you in advance.
Add a property parallelQueue
. Perform dispatch_apply
when a queue is set, use a simple for loop otherwise.
Do you have any links or papers that describe hierarchical state machine well? Maybe adding them to the README will be nice.
target
- action
- guard
action
block - use target
Since it is supported by cocoapods 0.38.
Minimal implementation can be as following.
[stateMachine umpleRepresentation];
#=>
class CourseSection
{
status
{
Planned {
openRegistration -> NotEnoughStudents;
}
Open {
cancel -> Cancelled;
NotEnoughStudents {
closeRegistration -> Cancelled;
register [getClassSize() > getMinimumClassSize()] -> EnoughStudents;
}
EnoughStudents {
closeRegistration -> Closed;
register [getClassSize() > getMaximumClassSize()] -> Closed;
}
}
Cancelled {}
Closed {}
}
}
Graphical representation:
http://cruise.eecs.uottawa.ca/umpleonline/umple.php?model=160218638587&diagramtype=state
A state should be able to define a given event as deferred.
The state machine should be able to queue these events until a state has been entered which can handle the deferred event.
Substates should take precedence over super states. In orthogonal regions the consuming state takes precedence over the deferring state.
The state machine should only execute guard and action blocks when parameter target
in method -registerEvent:target:action:guard:
in class TBSMState
is set to nil
. The exit block should not be executed.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.