Latest 1.4.4
Homepage https://github.com/charleslyh/SDDKit
License MIT
Platforms ios 8.0, requires ARC
Authors

Build Status
CocoaPods Version

SDDKit – State Driven Development Kit

Easiest way for implementing Hierarchical State Machine (HSM) based programs in Objective-C.

Installation

Clone or download source codes directly, or by using CocoaPods.

pod 'SDDKit'

High Level Aspects

Classes listed below gives the major functionalities of SDDKit.

  • SDDState
  • SDDStateMachine
  • SDDEventsPool
  • SDDBuilder

SDDKitSDDBuilder *builder = [SDDBuilder alloc] initWithLogger:nil epool:[SDDEventsPool sharedPool]; [builder addStateMachineWithContext:nil dsl:SDDOCLanguage( // Every statemachine can and must have one topstate [TopState // Two substates [A] [B] ] // Since TopState has two descendants, a $Default transition have to be provided to avoid ambiguity. // Another choice is using $Initial transition from outter state [.] such as: // [.] -> [A]: $Initial [TopState] -> [A]: $Default // If [A] is the current state and signal 'E1' occurs, it will transit to state [B] [A]->[B]: E1 )]; [[SDDEventsPool sharedPool] scheduleEvent:SDDLiteral(E1)]; // Now we are in state [B]

Activation and Deactivation

A statemachine with nil context helps nothing. Something has to be done that we could distinguish between one state and another. That’s the reason why we are using statemachine, aren’t we?

@interface Charles
@end

@implementation Charles
- (void)wakeup {
    NSLog(@"Good morning.")
}

- (void)sayGoodbye {
    NSLog(@"Bye, see ya.");
}

- (void)goToBed {
    NSLog(@"Good night.")
}

@end

int main() {
    Charles *charles = [[Charles alloc] init];

    SDDBuilder *builder = [SDDBuilder alloc] initWithLogger:nil epool:[SDDEventsPool sharedPool];

    [builder addStateMachineWithContext:charles dsl:SDDOCLanguage(
        [Me
            [Awake  
                e: wakeup     // 'e' is short for entering
                x: sayGoodbye // 'x' is short for exiting
            ]
            [Asleep e: goToBed]
        ]

        [.]      -> [Awake]  : $Initial
        [Awake]  -> [Asleep] : Sunset
        [Asleep] -> [Awake]  : Sunrise
    )];
    // Outputs 'Good morning.' for entering initial state [Awake]

    [[SDDEventsPool sharedPool] scheduleEvent:SDDLiteral(Sunset)];
    // Outputs 'Bye, see ya.' for exiting state [Awake]
    // Outputs 'Good night' for entering state [Asleep]

    [[SDDEventsPool sharedPool] scheduleEvent:SDDLiteral(Sunrise)];
    // Outputs 'Good morning.' for entering state [Awake]

    return 0;
)

Latest podspec

{
    "name": "SDDKit",
    "version": "1.4.4",
    "license": "MIT",
    "summary": "Easiest way for implementing hierarchical state machine(HSM) based programs in Objective-C.",
    "homepage": "https://github.com/charleslyh/SDDKit",
    "authors": {
        "Charles Lee": "[email protected]"
    },
    "platforms": {
        "ios": "8.0"
    },
    "source": {
        "git": "https://github.com/charleslyh/SDDKit.git",
        "tag": "1.4.4"
    },
    "requires_arc": true,
    "source_files": [
        "SDDKit",
        "SDDKit/**/*.{m,c,h}"
    ],
    "public_header_files": [
        "SDDKit/SDDKit.h",
        "SDDKit/SDD{EventsPool,StateMachine,Builder,Logger}.h"
    ]
}

Pin It on Pinterest

Share This