summaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
authorStefan Radomski <github@mintwerk.de>2017-07-13 20:29:09 (GMT)
committerStefan Radomski <github@mintwerk.de>2017-07-13 20:29:09 (GMT)
commit04b04aa6624caf73ffe4fc33f918e7f48b27da37 (patch)
tree40a8f92a0abd081f59a8aacc4b726dabf3c8f2f5 /apps
parente0d6ac8097bfd148a9956128a48b7d1addf81e68 (diff)
downloaduscxml-04b04aa6624caf73ffe4fc33f918e7f48b27da37.zip
uscxml-04b04aa6624caf73ffe4fc33f918e7f48b27da37.tar.gz
uscxml-04b04aa6624caf73ffe4fc33f918e7f48b27da37.tar.bz2
LambdaMonitors and prepared use-case examples
Diffstat (limited to 'apps')
-rw-r--r--apps/arduino/WaterPump.cxx170
-rw-r--r--apps/arduino/WaterPump.scxml70
-rw-r--r--apps/arduino/stateMachine.c1291
-rw-r--r--apps/uscxml-browser.cpp132
-rw-r--r--apps/uscxml-browser.vbs177
-rw-r--r--apps/uscxml-debugger.html2839
-rw-r--r--apps/uscxml-transform.cpp385
7 files changed, 0 insertions, 5064 deletions
diff --git a/apps/arduino/WaterPump.cxx b/apps/arduino/WaterPump.cxx
deleted file mode 100644
index 01f4cfa..0000000
--- a/apps/arduino/WaterPump.cxx
+++ /dev/null
@@ -1,170 +0,0 @@
-// Resources:
-// https://www.avrprogrammers.com/howto/atmega328-power
-// https://github.com/PaulStoffregen/CapacitiveSensor
-// https://de.wikipedia.org/wiki/Faustformelverfahren_%28Automatisierungstechnik%29
-// http://brettbeauregard.com/blog/2011/04/improving-the-beginners-pid-introduction/
-// google://SCC3 for conformal coating
-
-#include <LowPower.h>
-#include <CapacitiveSensor.h>
-
-
-#define USCXML_NO_HISTORY
-
-#define LED 13 // LED pin on the Arduino Nano
-#define LIGHT A7 // 1:10 voltage divider soldered into the solar panel
-#define LIGHT_THRES 300 // do not actuate beneath this brightness
-#define MEASURE_INTERVAL SLEEP_1S // time between cycles
-#define DARK_SLEEP_CYCLES 1
-
-#define PUMP_ON LOW // Setting an output to LOW will trigger the relais
-#define PUMP_OFF HIGH
-
-#define ROLLOFF 0.8 // exponential smoothing for sensor readings
-
-float soil[4] = { 0, 0, 0, 0 }; // smoothed sensor readings from the capacitive sensors
-int pump[4] = { A0, A1, A2, A3 }; // we abuse analog pins as digital output
-int activePump = -1;
-
-int thrs[4] = { 1400, 1400, 1400, 1400 }; // start pumping below these values
-
-CapacitiveSensor bed[4] = { // Pins where the capacitive sensors are connected
- CapacitiveSensor(3, 2),
- CapacitiveSensor(5, 4),
- CapacitiveSensor(7, 6),
- CapacitiveSensor(9, 8)
-};
-char readCapSense = 0; // Whether the capsense invoker is active
-
-struct data_t {
- int light;
-};
-struct event_t {
- const char* name;
- struct data_t data;
-};
-
-// the various events
-long pumpRemain = 0;
-struct event_t _eventIdle = {
- name: "idle"
-};
-struct event_t _eventLight = {
- name: "light"
-};
-struct event_t _eventPump = {
- name: "pump"
-};
-struct event_t* _event;
-
-#include "stateMachine.c"
-
-uscxml_ctx ctx;
-
-/* state chart is invoking something */
-static int invoke(const uscxml_ctx* ctx,
- const uscxml_state* s,
- const uscxml_elem_invoke* invocation,
- unsigned char uninvoke) {
- if (strcmp(invocation->type, "pump") == 0) {
- int pumpId = atoi(invocation->id);
- digitalWrite(pump[pumpId], uninvoke == 0 ? PUMP_ON : PUMP_OFF);
- } else if (strcmp(invocation->type, "capsense") == 0) {
- readCapSense = uninvoke;
- }
-}
-
-/* is the event matching */
-static int matched(const uscxml_ctx* ctx,
- const uscxml_transition* transition,
- const void* event) {
- // we ignore most event name matching rules here
- return strcmp(transition->event, ((const struct event_t*)event)->name) == 0;
-}
-
-static int send(const uscxml_ctx* ctx, const uscxml_elem_send* send) {
- if (send->delay > 0)
- pumpRemain = send->delay;
- return USCXML_ERR_OK;
-}
-
-static void* dequeueExternal(const uscxml_ctx* ctx) {
- // we will only call step when we have an event
- void* tmp = _event;
- _event = NULL;
- return tmp;
-}
-
-static bool isInState(const char* stateId) {
- for (size_t i = 0; i < ctx.machine->nr_states; i++) {
- if (ctx.machine->states[i].name &&
- strcmp(ctx.machine->states[i].name, stateId) == 0 &&
- BIT_HAS(i, ctx.config)) {
- return true;
- }
- }
-
- return false;
-}
-
-void setup() {
- // initilize the state chart
- memset(&ctx, 0, sizeof(uscxml_ctx));
- ctx.machine = &USCXML_MACHINE;
- ctx.invoke = invoke;
- ctx.is_matched = matched;
- ctx.dequeue_external = dequeueExternal;
- ctx.exec_content_send = send;
-
- int err = USCXML_ERR_OK;
-
- // run until first stable config
- while((err = uscxml_step(&ctx)) != USCXML_ERR_IDLE) {}
-}
-
-
-void loop() {
- digitalWrite(LED, HIGH);
-
- int err = USCXML_ERR_OK;
-
- if (readCapSense) {
- // capsense invoker is active
- for (int i = 0; i < 4; ++i) {
- int cap = bed[i].capacitiveSensor(50);
- if (cap > 0) {
- soil[i] = ROLLOFF * soil[i] + (1 - ROLLOFF) * (cap - thrs[i]);
- }
- }
- }
-
- _eventLight.data.light = analogRead(LIGHT);
- _event = &_eventLight;
- while((err = uscxml_step(&ctx)) != USCXML_ERR_IDLE) {}
-
- if (isInState("dark")) {
- LowPower.powerDown(MEASURE_INTERVAL, ADC_OFF, BOD_OFF);
- return;
- }
-
- if (isInState("light")) {
- if (false) {
- } else if (isInState("pumping")) {
- // is time elapsed already?
- if (pumpRemain == 0) {
- _event = &_eventIdle;
- while((err = uscxml_step(&ctx)) != USCXML_ERR_IDLE) {}
- }
- } else if (isInState("idle")) {
- // check is we need to pump
- _event = &_eventPump;
- while((err = uscxml_step(&ctx)) != USCXML_ERR_IDLE) {}
- }
- }
-
- pumpRemain = (pumpRemain >= 8000) ? pumpRemain - 8000 : 0;
-
- digitalWrite(LED, LOW);
- LowPower.powerDown(MEASURE_INTERVAL, ADC_OFF, BOD_OFF);
-
-}
diff --git a/apps/arduino/WaterPump.scxml b/apps/arduino/WaterPump.scxml
deleted file mode 100644
index a7d8bad..0000000
--- a/apps/arduino/WaterPump.scxml
+++ /dev/null
@@ -1,70 +0,0 @@
-<scxml datamodel="native" initial="dark" version="1.0">
- <!-- we provide the datamodel inline in the scaffolding -->
- <script><![CDATA[
- pinMode(LED, OUTPUT);
- for (char i = 0; i < 4; ++i) {
- pinMode(pump[i], OUTPUT);
- digitalWrite(pump[i], PUMP_OFF);
- bed[i].set_CS_AutocaL_Millis(0xFFFFFFFF);
- }
- ]]></script>
-
- <!-- it is too dark to water flowers -->
- <state id="dark">
- <transition event="light" cond="_event->data.light > LIGHT_THRES" target="light" />
- <onentry>
- <script><![CDATA[
- for (char i = 0; i < 4; ++i) {
- digitalWrite(pump[i], PUMP_OFF);
- }
- ]]></script>
- </onentry>
- </state>
-
- <!-- start to take measurements and activate single pumps if too dry -->
- <state id="light">
- <transition event="light" cond="_event->data.light &lt; LIGHT_THRES" target="dark" />
-
- <!-- delivers events for all the capsense measurements -->
- <invoke type="capsense" id="cap" />
-
- <state id="idle">
- <transition event="pump" cond="soil[0] &lt; 0 &amp;&amp;
- soil[0] &lt;= soil[1] &amp;&amp;
- soil[0] &lt;= soil[2] &amp;&amp;
- soil[0] &lt;= soil[3]" target="pump1" />
- <transition event="pump" cond="soil[1] &lt; 0 &amp;&amp;
- soil[1] &lt;= soil[0] &amp;&amp;
- soil[1] &lt;= soil[2] &amp;&amp;
- soil[1] &lt;= soil[3]" target="pump2" />
- <transition event="pump" cond="soil[2] &lt; 0 &amp;&amp;
- soil[2] &lt;= soil[0] &amp;&amp;
- soil[2] &lt;= soil[1] &amp;&amp;
- soil[2] &lt;= soil[3]" target="pump3" />
- <transition event="pump" cond="soil[3] &lt; 0 &amp;&amp;
- soil[3] &lt;= soil[0] &amp;&amp;
- soil[3] &lt;= soil[1] &amp;&amp;
- soil[3] &lt;= soil[2]" target="pump4" />
- </state>
-
- <state id="pumping">
- <transition event="idle" target="idle" />
- <onentry>
- <send delay="8000ms" event="idle" />
- </onentry>
-
- <state id="pump1">
- <invoke type="pump" id="1" />
- </state>
- <state id="pump2">
- <invoke type="pump" id="2" />
- </state>
- <state id="pump3">
- <invoke type="pump" id="3" />
- </state>
- <state id="pump4">
- <invoke type="pump" id="4" />
- </state>
- </state>
- </state>
-</scxml>
diff --git a/apps/arduino/stateMachine.c b/apps/arduino/stateMachine.c
deleted file mode 100644
index a74535b..0000000
--- a/apps/arduino/stateMachine.c
+++ /dev/null
@@ -1,1291 +0,0 @@
-/**
- Generated from source:
- file:///Users/sradomski/Documents/Electronics/WaterPump/WaterPump.scxml
-*/
-
-#ifndef USCXML_NO_STDTYPES_H
-# include <stdint.h> /* explicit types */
-#endif
-#include <stddef.h> /* NULL */
-
-#ifndef USCXML_NO_GEN_C_MACROS
-
-/**
- * All macros used for the scxml types and functions
- *
- * ** IMPORTANT: Make sure to set the following macros prior to including. **
- * They are used to represent the machine in the types to follow
- * and to allocate stack memory during a micro-step function.
- * When in doubt, overprovide.
- *
- * USCXML_NR_STATES_TYPE
- * as the smallest type for positive integers that can contain the
- * largest number of states from an individual state machine. E.g.:
- * < 2^8 states => uint8_t
- * < 2^16 states => uint16_t
- * < 2^32 states => uint32_t
- */
-
-#ifndef USCXML_NR_STATES_TYPE
-# define USCXML_NR_STATES_TYPE uint8_t
-#endif
-
-/**
- * USCXML_NR_TRANS_TYPE
- * the same as above but for the number of transitions.
- */
-
-#ifndef USCXML_NR_TRANS_TYPE
-# define USCXML_NR_TRANS_TYPE uint8_t
-#endif
-
-/**
- * USCXML_MAX_NR_STATES_BYTES
- * the smallest multiple of 8 that, if multiplied by 8,
- * is larger than USCXML_NR_STATES_TYPE, e.g:
- * 1-8 states => 1
- * 9-16 states => 2
- * 17-24 states => 3
- * 25-32 states => 4
- * ...
- */
-
-#ifndef USCXML_MAX_NR_STATES_BYTES
-# define USCXML_MAX_NR_STATES_BYTES 2
-#endif
-
-/**
- * USCXML_MAX_NR_TRANS_BYTES
- * same as above but for transitions.
- */
-
-#ifndef USCXML_MAX_NR_TRANS_BYTES
-# define USCXML_MAX_NR_TRANS_BYTES 1
-#endif
-
-/**
- * USCXML_NUMBER_STATES / USCXML_NUMBER_TRANS
- * Per default the number of states / transitions is retrieved from the machine
- * info in the uscxml_ctx struct, but you can also hard-code it per macro.
- */
-
-#ifndef USCXML_NUMBER_STATES
-# define USCXML_NUMBER_STATES (ctx->machine->nr_states)
-#endif
-
-#ifndef USCXML_NUMBER_TRANS
-# define USCXML_NUMBER_TRANS (ctx->machine->nr_transitions)
-#endif
-
-/**
- * USCXML_GET_STATE / USCXML_GET_TRANS
- * Per default an individual state or transitions is retrieved from the machine
- * info in the uscxml_ctx struct, but you can also hard-code it per macro.
- */
-
-#ifndef USCXML_GET_STATE
-# define USCXML_GET_STATE(i) (ctx->machine->states[i])
-#endif
-
-#ifndef USCXML_GET_TRANS
-# define USCXML_GET_TRANS(i) (ctx->machine->transitions[i])
-#endif
-
-
-/* Common macros below */
-
-#define BIT_HAS(idx, bitset) ((bitset[idx >> 3] & (1 << (idx & 7))) != 0)
-#define BIT_SET_AT(idx, bitset) bitset[idx >> 3] |= (1 << (idx & 7));
-#define BIT_CLEAR(idx, bitset) bitset[idx >> 3] &= (1 << (idx & 7)) ^ 0xFF;
-
-#ifdef __GNUC__
-# define likely(x) (__builtin_expect(!!(x), 1))
-# define unlikely(x) (__builtin_expect(!!(x), 0))
-#else
-# define likely(x) (x)
-# define unlikely(x) (x)
-#endif
-
-/* error return codes */
-#define USCXML_ERR_OK 0
-#define USCXML_ERR_IDLE 1
-#define USCXML_ERR_DONE 2
-#define USCXML_ERR_MISSING_CALLBACK 3
-#define USCXML_ERR_FOREACH_DONE 4
-#define USCXML_ERR_EXEC_CONTENT 5
-#define USCXML_ERR_INVALID_TARGET 6
-#define USCXML_ERR_INVALID_TYPE 7
-#define USCXML_ERR_UNSUPPORTED 8
-
-#define USCXML_TRANS_SPONTANEOUS 0x01
-#define USCXML_TRANS_TARGETLESS 0x02
-#define USCXML_TRANS_INTERNAL 0x04
-#define USCXML_TRANS_HISTORY 0x08
-#define USCXML_TRANS_INITIAL 0x10
-
-#define USCXML_STATE_ATOMIC 0x01
-#define USCXML_STATE_PARALLEL 0x02
-#define USCXML_STATE_COMPOUND 0x03
-#define USCXML_STATE_FINAL 0x04
-#define USCXML_STATE_HISTORY_DEEP 0x05
-#define USCXML_STATE_HISTORY_SHALLOW 0x06
-#define USCXML_STATE_INITIAL 0x07
-#define USCXML_STATE_HAS_HISTORY 0x80 /* highest bit */
-#define USCXML_STATE_MASK(t) (t & 0x7F) /* mask highest bit */
-
-#define USCXML_CTX_PRISTINE 0x00
-#define USCXML_CTX_SPONTANEOUS 0x01
-#define USCXML_CTX_INITIALIZED 0x02
-#define USCXML_CTX_TOP_LEVEL_FINAL 0x04
-#define USCXML_CTX_TRANSITION_FOUND 0x08
-#define USCXML_CTX_FINISHED 0x10
-
-#define USCXML_ELEM_DATA_IS_SET(data) (data->id != NULL)
-#define USCXML_ELEM_DONEDATA_IS_SET(donedata) (donedata->content != NULL || donedata->contentexpr != NULL || donedata->params != NULL)
-#define USCXML_ELEM_PARAM_IS_SET(param) (param->name != NULL)
-#define USCXML_MACHINE_IS_SET(machine) (machine->nr_states > 0)
-
-#define USCXML_NO_GEN_C_MACROS
-#endif
-
-
-#ifndef USCXML_NO_GEN_C_TYPES
-
-/**
- * All types required to represent an SCXML state chart.
- * Just predefine the USCXML_NO_GEN_C_TYPES macro if you do not need them.
- */
-
-typedef struct uscxml_machine uscxml_machine;
-typedef struct uscxml_transition uscxml_transition;
-typedef struct uscxml_state uscxml_state;
-typedef struct uscxml_ctx uscxml_ctx;
-typedef struct uscxml_elem_invoke uscxml_elem_invoke;
-
-typedef struct uscxml_elem_send uscxml_elem_send;
-typedef struct uscxml_elem_param uscxml_elem_param;
-typedef struct uscxml_elem_data uscxml_elem_data;
-typedef struct uscxml_elem_assign uscxml_elem_assign;
-typedef struct uscxml_elem_donedata uscxml_elem_donedata;
-typedef struct uscxml_elem_foreach uscxml_elem_foreach;
-
-typedef void* (*dequeue_internal_t)(const uscxml_ctx* ctx);
-typedef void* (*dequeue_external_t)(const uscxml_ctx* ctx);
-typedef int (*is_enabled_t)(const uscxml_ctx* ctx, const uscxml_transition* transition);
-typedef int (*is_matched_t)(const uscxml_ctx* ctx, const uscxml_transition* transition, const void* event);
-typedef int (*is_true_t)(const uscxml_ctx* ctx, const char* expr);
-typedef int (*exec_content_t)(const uscxml_ctx* ctx, const uscxml_state* state, const void* event);
-typedef int (*raise_done_event_t)(const uscxml_ctx* ctx, const uscxml_state* state, const uscxml_elem_donedata* donedata);
-typedef int (*invoke_t)(const uscxml_ctx* ctx, const uscxml_state* s, const uscxml_elem_invoke* invocation, unsigned char uninvoke);
-
-typedef int (*exec_content_log_t)(const uscxml_ctx* ctx, const char* label, const char* expr);
-typedef int (*exec_content_raise_t)(const uscxml_ctx* ctx, const char* event);
-typedef int (*exec_content_send_t)(const uscxml_ctx* ctx, const uscxml_elem_send* send);
-typedef int (*exec_content_foreach_init_t)(const uscxml_ctx* ctx, const uscxml_elem_foreach* foreach);
-typedef int (*exec_content_foreach_next_t)(const uscxml_ctx* ctx, const uscxml_elem_foreach* foreach);
-typedef int (*exec_content_foreach_done_t)(const uscxml_ctx* ctx, const uscxml_elem_foreach* foreach);
-typedef int (*exec_content_assign_t)(const uscxml_ctx* ctx, const uscxml_elem_assign* assign);
-typedef int (*exec_content_init_t)(const uscxml_ctx* ctx, const uscxml_elem_data* data);
-typedef int (*exec_content_cancel_t)(const uscxml_ctx* ctx, const char* sendid, const char* sendidexpr);
-typedef int (*exec_content_finalize_t)(const uscxml_ctx* ctx, const uscxml_elem_invoke* invoker, const void* event);
-typedef int (*exec_content_script_t)(const uscxml_ctx* ctx, const char* src, const char* content);
-
-/**
- * A single SCXML state-machine.
- */
-struct uscxml_machine {
- unsigned char flags; /* Unused */
- USCXML_NR_STATES_TYPE nr_states; /* Make sure to set type per macro! */
- USCXML_NR_TRANS_TYPE nr_transitions; /* Make sure to set type per macro! */
- const char* name;
- const char* datamodel;
- const char* uuid; /* currently MD5 sum */
- const uscxml_state* states;
- const uscxml_transition* transitions;
- const uscxml_machine* parent;
- const uscxml_elem_donedata* donedata;
- const exec_content_t script; /* Global script elements */
-};
-
-/**
- * All information pertaining to a <data> element
- * With late data binding, blocks of data elements are separated by NULL
- * use USCXML_ELEM_DATA_IS_SET to test for end of a block.
- */
-struct uscxml_elem_data {
- const char* id;
- const char* src;
- const char* expr;
- const char* content;
-};
-
-/**
- * All information pertaining to an <assign> element
- */
-struct uscxml_elem_assign {
- const char* location;
- const char* expr;
- const char* content;
-};
-
-/**
- * All information pertaining to any state element
- */
-struct uscxml_state {
- const char* name; /* eventual name */
- const USCXML_NR_STATES_TYPE parent; /* parent */
- const exec_content_t on_entry; /* on entry handlers */
- const exec_content_t on_exit; /* on exit handlers */
- const invoke_t invoke; /* invocations */
- const unsigned char children[USCXML_MAX_NR_STATES_BYTES]; /* all children */
- const unsigned char completion[USCXML_MAX_NR_STATES_BYTES]; /* default completion */
- const unsigned char ancestors[USCXML_MAX_NR_STATES_BYTES]; /* all ancestors */
- const uscxml_elem_data* data; /* data with late binding */
- const unsigned char type; /* One of USCXML_STATE_* */
-};
-
-/**
- * All information pertaining to a <transition> element
- */
-struct uscxml_transition {
- const USCXML_NR_STATES_TYPE source;
- const unsigned char target[USCXML_MAX_NR_STATES_BYTES];
- const char* event;
- const char* condition;
- const is_enabled_t is_enabled;
- const exec_content_t on_transition;
- const unsigned char type;
- const unsigned char conflicts[USCXML_MAX_NR_TRANS_BYTES];
- const unsigned char exit_set[USCXML_MAX_NR_STATES_BYTES];
-};
-
-/**
- * All information pertaining to a <foreach> element
- */
-struct uscxml_elem_foreach {
- const char* array;
- const char* item;
- const char* index;
-};
-
-/**
- * All information pertaining to a <param> element
- * Blocks of params are separated by NULL params, use
- * USCXML_ELEM_PARAM_IS_SET to test for end of a block.
- */
-struct uscxml_elem_param {
- const char* name;
- const char* expr;
- const char* location;
-};
-
-/**
- * All information pertaining to a <donedata> element
- */
-struct uscxml_elem_donedata {
- const USCXML_NR_STATES_TYPE source;
- const char* content;
- const char* contentexpr;
- const uscxml_elem_param* params;
-};
-
-/**
- * All information pertaining to an <invoke> element
- */
-struct uscxml_elem_invoke {
- const uscxml_machine* machine;
- const char* type;
- const char* typeexpr;
- const char* src;
- const char* srcexpr;
- const char* id;
- const char* idlocation;
- const char* sourcename;
- const char* namelist;
- const unsigned char autoforward;
- const uscxml_elem_param* params;
- exec_content_finalize_t finalize;
- const char* content;
- const char* contentexpr;
-};
-
-/**
- * All information pertaining to a <send> element
- */
-struct uscxml_elem_send {
- const char* event;
- const char* eventexpr;
- const char* target;
- const char* targetexpr;
- const char* type;
- const char* typeexpr;
- const char* id;
- const char* idlocation;
- unsigned long delay;
- const char* delayexpr;
- const char* namelist; /* not space-separated, still as in attribute value */
- const char* content;
- const char* contentexpr;
- const uscxml_elem_param* params;
-};
-
-/**
- * Represents an instance of a state-chart at runtime/
- */
-struct uscxml_ctx {
- unsigned char flags;
- const uscxml_machine* machine;
-
- unsigned char config[USCXML_MAX_NR_STATES_BYTES]; /* Make sure these macros specify a sufficient size */
- unsigned char history[USCXML_MAX_NR_STATES_BYTES];
- unsigned char invocations[USCXML_MAX_NR_STATES_BYTES];
- unsigned char initialized_data[USCXML_MAX_NR_STATES_BYTES];
-
- void* user_data;
- void* event;
-
- dequeue_internal_t dequeue_internal;
- dequeue_external_t dequeue_external;
- is_matched_t is_matched;
- is_true_t is_true;
- raise_done_event_t raise_done_event;
-
- exec_content_log_t exec_content_log;
- exec_content_raise_t exec_content_raise;
- exec_content_send_t exec_content_send;
- exec_content_foreach_init_t exec_content_foreach_init;
- exec_content_foreach_next_t exec_content_foreach_next;
- exec_content_foreach_done_t exec_content_foreach_done;
- exec_content_assign_t exec_content_assign;
- exec_content_init_t exec_content_init;
- exec_content_cancel_t exec_content_cancel;
- exec_content_script_t exec_content_script;
-
- invoke_t invoke;
-};
-
-#define USCXML_NO_GEN_C_TYPES
-#endif
-
-/* forward declare machines to allow references */
-extern const uscxml_machine _uscxml_4FC60039__machine;
-
-#ifndef USCXML_NO_ELEM_INFO
-
-static const uscxml_elem_send _uscxml_4FC60039__elem_sends[1] = {
- {
- /* event */ "idle",
- /* eventexpr */ NULL,
- /* target */ NULL,
- /* targetexpr */ NULL,
- /* type */ NULL,
- /* typeexpr */ NULL,
- /* id */ NULL,
- /* idlocation */ NULL,
- /* delay */ 8000,
- /* delayexpr */ NULL,
- /* namelist */ NULL,
- /* content */ NULL,
- /* contentexpr */ NULL,
- /* params */ NULL
- }
-};
-
-static const uscxml_elem_donedata _uscxml_4FC60039__elem_donedatas[1] = {
- /* source, content, contentexpr, params */
- { 0, NULL, NULL, NULL }
-};
-
-#endif
-
-#ifndef USCXML_NO_ELEM_INFO
-
-static const uscxml_elem_invoke _uscxml_4FC60039__elem_invokes[5] = {
- {
- /* machine */ NULL,
- /* type */ "capsense",
- /* typeexpr */ NULL,
- /* src */ NULL,
- /* srcexpr */ NULL,
- /* id */ "cap",
- /* idlocation */ NULL,
- /* sourcename */ "light",
- /* namelist */ NULL,
- /* autoforward */ 0,
- /* params */ NULL,
- /* finalize */ NULL,
- /* content */ NULL,
- /* contentexpr */ NULL,
- },
- {
- /* machine */ NULL,
- /* type */ "pump",
- /* typeexpr */ NULL,
- /* src */ NULL,
- /* srcexpr */ NULL,
- /* id */ "1",
- /* idlocation */ NULL,
- /* sourcename */ "pump1",
- /* namelist */ NULL,
- /* autoforward */ 0,
- /* params */ NULL,
- /* finalize */ NULL,
- /* content */ NULL,
- /* contentexpr */ NULL,
- },
- {
- /* machine */ NULL,
- /* type */ "pump",
- /* typeexpr */ NULL,
- /* src */ NULL,
- /* srcexpr */ NULL,
- /* id */ "2",
- /* idlocation */ NULL,
- /* sourcename */ "pump2",
- /* namelist */ NULL,
- /* autoforward */ 0,
- /* params */ NULL,
- /* finalize */ NULL,
- /* content */ NULL,
- /* contentexpr */ NULL,
- },
- {
- /* machine */ NULL,
- /* type */ "pump",
- /* typeexpr */ NULL,
- /* src */ NULL,
- /* srcexpr */ NULL,
- /* id */ "3",
- /* idlocation */ NULL,
- /* sourcename */ "pump3",
- /* namelist */ NULL,
- /* autoforward */ 0,
- /* params */ NULL,
- /* finalize */ NULL,
- /* content */ NULL,
- /* contentexpr */ NULL,
- },
- {
- /* machine */ NULL,
- /* type */ "pump",
- /* typeexpr */ NULL,
- /* src */ NULL,
- /* srcexpr */ NULL,
- /* id */ "4",
- /* idlocation */ NULL,
- /* sourcename */ "pump4",
- /* namelist */ NULL,
- /* autoforward */ 0,
- /* params */ NULL,
- /* finalize */ NULL,
- /* content */ NULL,
- /* contentexpr */ NULL,
- }
-};
-
-#endif
-
-#ifndef USCXML_NO_EXEC_CONTENT
-
-static int _uscxml_4FC60039__global_script_0(const uscxml_ctx* ctx, const uscxml_state* state, const void* event) {
- int err = USCXML_ERR_OK;
-
- pinMode(LED, OUTPUT);
- for (char i = 0; i < 4; ++i) {
- pinMode(pump[i], OUTPUT);
- digitalWrite(pump[i], PUMP_OFF);
- bed[i].set_CS_AutocaL_Millis(0xFFFFFFFF);
- }
- return USCXML_ERR_OK;
-}
-static int _uscxml_4FC60039__global_script(const uscxml_ctx* ctx, const uscxml_state* state, const void* event) {
- _uscxml_4FC60039__global_script_0(ctx, state, event);
- return USCXML_ERR_OK;
-}
-
-static int _uscxml_4FC60039__dark_on_entry_0(const uscxml_ctx* ctx, const uscxml_state* state, const void* event) {
- int err = USCXML_ERR_OK;
-
- for (char i = 0; i < 4; ++i) {
- digitalWrite(pump[i], PUMP_OFF);
- }
- return USCXML_ERR_OK;
-}
-
-static int _uscxml_4FC60039__dark_on_entry(const uscxml_ctx* ctx, const uscxml_state* state, const void* event) {
- _uscxml_4FC60039__dark_on_entry_0(ctx, state, event);
- return USCXML_ERR_OK;
-}
-
-static int _uscxml_4FC60039__light_invoke(const uscxml_ctx* ctx, const uscxml_state* s, const uscxml_elem_invoke* invocation, unsigned char uninvoke) {
- ctx->invoke(ctx, s, &_uscxml_4FC60039__elem_invokes[0], uninvoke);
-
- return USCXML_ERR_OK;
-}
-static int _uscxml_4FC60039__pumping_on_entry_0(const uscxml_ctx* ctx, const uscxml_state* state, const void* event) {
- int err = USCXML_ERR_OK;
- if likely(ctx->exec_content_send != NULL) {
- if ((ctx->exec_content_send(ctx, &_uscxml_4FC60039__elem_sends[0])) != USCXML_ERR_OK) return err;
- } else {
- return USCXML_ERR_MISSING_CALLBACK;
- }
- return USCXML_ERR_OK;
-}
-
-static int _uscxml_4FC60039__pumping_on_entry(const uscxml_ctx* ctx, const uscxml_state* state, const void* event) {
- _uscxml_4FC60039__pumping_on_entry_0(ctx, state, event);
- return USCXML_ERR_OK;
-}
-
-static int _uscxml_4FC60039__pump1_invoke(const uscxml_ctx* ctx, const uscxml_state* s, const uscxml_elem_invoke* invocation, unsigned char uninvoke) {
- ctx->invoke(ctx, s, &_uscxml_4FC60039__elem_invokes[1], uninvoke);
-
- return USCXML_ERR_OK;
-}
-static int _uscxml_4FC60039__pump2_invoke(const uscxml_ctx* ctx, const uscxml_state* s, const uscxml_elem_invoke* invocation, unsigned char uninvoke) {
- ctx->invoke(ctx, s, &_uscxml_4FC60039__elem_invokes[2], uninvoke);
-
- return USCXML_ERR_OK;
-}
-static int _uscxml_4FC60039__pump3_invoke(const uscxml_ctx* ctx, const uscxml_state* s, const uscxml_elem_invoke* invocation, unsigned char uninvoke) {
- ctx->invoke(ctx, s, &_uscxml_4FC60039__elem_invokes[3], uninvoke);
-
- return USCXML_ERR_OK;
-}
-static int _uscxml_4FC60039__pump4_invoke(const uscxml_ctx* ctx, const uscxml_state* s, const uscxml_elem_invoke* invocation, unsigned char uninvoke) {
- ctx->invoke(ctx, s, &_uscxml_4FC60039__elem_invokes[4], uninvoke);
-
- return USCXML_ERR_OK;
-}
-static int _uscxml_4FC60039__dark_transition0_is_enabled(const uscxml_ctx* ctx, const uscxml_transition* transition) {
- return (_event->data.light > LIGHT_THRES);
-}
-static int _uscxml_4FC60039__idle_transition0_is_enabled(const uscxml_ctx* ctx, const uscxml_transition* transition) {
- return (soil[0] < 0 && soil[0] <= soil[1]);
-}
-static int _uscxml_4FC60039__idle_transition1_is_enabled(const uscxml_ctx* ctx, const uscxml_transition* transition) {
- return (soil[1] < 0 && soil[1] <= soil[0]);
-}
-static int _uscxml_4FC60039__light_transition0_is_enabled(const uscxml_ctx* ctx, const uscxml_transition* transition) {
- return (_event->data.light < LIGHT_THRES);
-}
-#endif
-
-#ifndef USCXML_NO_ELEM_INFO
-
-static const uscxml_state _uscxml_4FC60039__states[9] = {
- { /* state number 0 */
- /* name */ NULL,
- /* parent */ 0,
- /* onentry */ NULL,
- /* onexit */ NULL,
- /* invoke */ NULL,
- /* children */ { 0x06, 0x00 /* 011000000 */ },
- /* completion */ { 0x02, 0x00 /* 010000000 */ },
- /* ancestors */ { 0x00, 0x00 /* 000000000 */ },
- /* data */ NULL,
- /* type */ USCXML_STATE_COMPOUND,
- },
- { /* state number 1 */
- /* name */ "dark",
- /* parent */ 0,
- /* onentry */ _uscxml_4FC60039__dark_on_entry,
- /* onexit */ NULL,
- /* invoke */ NULL,
- /* children */ { 0x00, 0x00 /* 000000000 */ },
- /* completion */ { 0x00, 0x00 /* 000000000 */ },
- /* ancestors */ { 0x01, 0x00 /* 100000000 */ },
- /* data */ NULL,
- /* type */ USCXML_STATE_ATOMIC,
- },
- { /* state number 2 */
- /* name */ "light",
- /* parent */ 0,
- /* onentry */ NULL,
- /* onexit */ NULL,
- /* invoke */ _uscxml_4FC60039__light_invoke,
- /* children */ { 0x18, 0x00 /* 000110000 */ },
- /* completion */ { 0x08, 0x00 /* 000100000 */ },
- /* ancestors */ { 0x01, 0x00 /* 100000000 */ },
- /* data */ NULL,
- /* type */ USCXML_STATE_COMPOUND,
- },
- { /* state number 3 */
- /* name */ "idle",
- /* parent */ 2,
- /* onentry */ NULL,
- /* onexit */ NULL,
- /* invoke */ NULL,
- /* children */ { 0x00, 0x00 /* 000000000 */ },
- /* completion */ { 0x00, 0x00 /* 000000000 */ },
- /* ancestors */ { 0x05, 0x00 /* 101000000 */ },
- /* data */ NULL,
- /* type */ USCXML_STATE_ATOMIC,
- },
- { /* state number 4 */
- /* name */ "pumping",
- /* parent */ 2,
- /* onentry */ _uscxml_4FC60039__pumping_on_entry,
- /* onexit */ NULL,
- /* invoke */ NULL,
- /* children */ { 0xe0, 0x01 /* 000001111 */ },
- /* completion */ { 0x20, 0x00 /* 000001000 */ },
- /* ancestors */ { 0x05, 0x00 /* 101000000 */ },
- /* data */ NULL,
- /* type */ USCXML_STATE_COMPOUND,
- },
- { /* state number 5 */
- /* name */ "pump1",
- /* parent */ 4,
- /* onentry */ NULL,
- /* onexit */ NULL,
- /* invoke */ _uscxml_4FC60039__pump1_invoke,
- /* children */ { 0x00, 0x00 /* 000000000 */ },
- /* completion */ { 0x00, 0x00 /* 000000000 */ },
- /* ancestors */ { 0x15, 0x00 /* 101010000 */ },
- /* data */ NULL,
- /* type */ USCXML_STATE_ATOMIC,
- },
- { /* state number 6 */
- /* name */ "pump2",
- /* parent */ 4,
- /* onentry */ NULL,
- /* onexit */ NULL,
- /* invoke */ _uscxml_4FC60039__pump2_invoke,
- /* children */ { 0x00, 0x00 /* 000000000 */ },
- /* completion */ { 0x00, 0x00 /* 000000000 */ },
- /* ancestors */ { 0x15, 0x00 /* 101010000 */ },
- /* data */ NULL,
- /* type */ USCXML_STATE_ATOMIC,
- },
- { /* state number 7 */
- /* name */ "pump3",
- /* parent */ 4,
- /* onentry */ NULL,
- /* onexit */ NULL,
- /* invoke */ _uscxml_4FC60039__pump3_invoke,
- /* children */ { 0x00, 0x00 /* 000000000 */ },
- /* completion */ { 0x00, 0x00 /* 000000000 */ },
- /* ancestors */ { 0x15, 0x00 /* 101010000 */ },
- /* data */ NULL,
- /* type */ USCXML_STATE_ATOMIC,
- },
- { /* state number 8 */
- /* name */ "pump4",
- /* parent */ 4,
- /* onentry */ NULL,
- /* onexit */ NULL,
- /* invoke */ _uscxml_4FC60039__pump4_invoke,
- /* children */ { 0x00, 0x00 /* 000000000 */ },
- /* completion */ { 0x00, 0x00 /* 000000000 */ },
- /* ancestors */ { 0x15, 0x00 /* 101010000 */ },
- /* data */ NULL,
- /* type */ USCXML_STATE_ATOMIC,
- }
-};
-
-#endif
-
-#ifndef USCXML_NO_ELEM_INFO
-
-static const uscxml_transition _uscxml_4FC60039__transitions[5] = {
- { /* transition number 0 with priority 0
- target: light
- */
- /* source */ 1,
- /* target */ { 0x04, 0x00 /* 001000000 */ },
- /* event */ "light",
- /* condition */ NULL,
- /* is_enabled */ _uscxml_4FC60039__dark_transition0_is_enabled,
- /* ontrans */ NULL,
- /* type */ 0,
- /* conflicts */ { 0x1f /* 11111 */ },
- /* exit set */ { 0xfe, 0x01 /* 011111111 */ }
- },
- { /* transition number 2 with priority 1
- target: pump1
- */
- /* source */ 3,
- /* target */ { 0x20, 0x00 /* 000001000 */ },
- /* event */ "pump",
- /* condition */ NULL,
- /* is_enabled */ _uscxml_4FC60039__idle_transition0_is_enabled,
- /* ontrans */ NULL,
- /* type */ 0,
- /* conflicts */ { 0x1f /* 11111 */ },
- /* exit set */ { 0xf8, 0x01 /* 000111111 */ }
- },
- { /* transition number 3 with priority 2
- target: pump2
- */
- /* source */ 3,
- /* target */ { 0x40, 0x00 /* 000000100 */ },
- /* event */ "pump",
- /* condition */ NULL,
- /* is_enabled */ _uscxml_4FC60039__idle_transition1_is_enabled,
- /* ontrans */ NULL,
- /* type */ 0,
- /* conflicts */ { 0x1f /* 11111 */ },
- /* exit set */ { 0xf8, 0x01 /* 000111111 */ }
- },
- { /* transition number 4 with priority 3
- target: idle
- */
- /* source */ 4,
- /* target */ { 0x08, 0x00 /* 000100000 */ },
- /* event */ "idle",
- /* condition */ NULL,
- /* is_enabled */ NULL,
- /* ontrans */ NULL,
- /* type */ 0,
- /* conflicts */ { 0x1f /* 11111 */ },
- /* exit set */ { 0xf8, 0x01 /* 000111111 */ }
- },
- { /* transition number 1 with priority 4
- target: dark
- */
- /* source */ 2,
- /* target */ { 0x02, 0x00 /* 010000000 */ },
- /* event */ "light",
- /* condition */ NULL,
- /* is_enabled */ _uscxml_4FC60039__light_transition0_is_enabled,
- /* ontrans */ NULL,
- /* type */ 0,
- /* conflicts */ { 0x1f /* 11111 */ },
- /* exit set */ { 0xfe, 0x01 /* 011111111 */ }
- }
-};
-
-#endif
-
-#ifndef USCXML_NO_ELEM_INFO
-
-#ifndef USCXML_MACHINE
-# define USCXML_MACHINE _uscxml_4FC60039__machine
-#endif
-#define USCXML_MACHINE_0 _uscxml_4FC60039__machine
-#define USCXML_MACHINE_WATERPUMP_SCXML _uscxml_4FC60039__machine
-
-const uscxml_machine _uscxml_4FC60039__machine = {
- /* flags */ 0,
- /* nr_states */ 9,
- /* nr_transitions */ 5,
- /* name */ "WaterPump.scxml",
- /* datamodel */ "native",
- /* uuid */ "4FC600390B3422E11879652D26725E30",
- /* states */ &_uscxml_4FC60039__states[0],
- /* transitions */ &_uscxml_4FC60039__transitions[0],
- /* parent */ NULL,
- /* donedata */ &_uscxml_4FC60039__elem_donedatas[0],
- /* script */ _uscxml_4FC60039__global_script
-
-};
-
-#endif
-
-#ifdef USCXML_VERBOSE
-/**
- * Print name of states contained in a (debugging).
- */
-static void printStateNames(const uscxml_ctx* ctx, const unsigned char* a, size_t length) {
- size_t i;
- const char* seperator = "";
- for (i = 0; i < length; i++) {
- if (BIT_HAS(i, a)) {
- printf("%s%s", seperator, (USCXML_GET_STATE(i).name != NULL ? USCXML_GET_STATE(i).name : "UNK"));
- seperator = ", ";
- }
- }
- printf("\n");
-}
-
-/**
- * Print bits set in a in a binary representation (debugging).
- */
-static void printBitsetIndices(const unsigned char* a, size_t length) {
- size_t i;
- const char* seperator = "";
- for (i = 0; i < length; i++) {
- if (BIT_HAS(i, a)) {
- printf("%s%zu", seperator, i);
- seperator = ", ";
- }
- }
- printf("\n");
-}
-#endif
-
-#ifndef USCXML_NO_BIT_OPERATIONS
-/**
- * Return true if there is a common bit in a and b.
- */
-static int bit_has_and(const unsigned char* a, const unsigned char* b, size_t i) {
- while(i--) {
- if (a[i] & b[i])
- return 1;
- }
- return 0;
-}
-
-/**
- * Set all bits to 0, this corresponds to memset(a, 0, i),
- * but does not require string.h or cstring.
- */
-static void bit_clear_all(unsigned char* a, size_t i) {
- while(i--) {
- a[i] = 0;
- }
-}
-
-/**
- * Return true if there is any bit set in a.
- */
-static int bit_has_any(unsigned const char* a, size_t i) {
- while(i--) {
- if (a[i] > 0)
- return 1;
- }
- return 0;
-}
-
-/**
- * Set all bits from given mask in dest, this is |= for bit arrays.
- */
-static void bit_or(unsigned char* dest, const unsigned char* mask, size_t i) {
- while(i--) {
- dest[i] |= mask[i];
- }
-}
-
-/**
- * Copy all bits from source to dest, this corresponds to memcpy(a, b, i),
- * but does not require string.h or cstring.
- */
-static void bit_copy(unsigned char* dest, const unsigned char* source, size_t i) {
- while(i--) {
- dest[i] = source[i];
- }
-}
-
-/**
- * Unset bits from mask in dest.
- */
-static void bit_and_not(unsigned char* dest, const unsigned char* mask, size_t i) {
- while(i--) {
- dest[i] &= ~mask[i];
- }
-}
-
-/**
- * Set bits from mask in dest.
- */
-static void bit_and(unsigned char* dest, const unsigned char* mask, size_t i) {
- while(i--) {
- dest[i] &= mask[i];
- };
-}
-
-#define USCXML_NO_BIT_OPERATIONS
-#endif
-
-#ifndef USCXML_NO_STEP_FUNCTION
-int uscxml_step(uscxml_ctx* ctx) {
-
- USCXML_NR_STATES_TYPE i, j, k;
- USCXML_NR_STATES_TYPE nr_states_bytes = ((USCXML_NUMBER_STATES + 7) & ~7) >> 3;
- USCXML_NR_TRANS_TYPE nr_trans_bytes = ((USCXML_NUMBER_TRANS + 7) & ~7) >> 3;
- int err = USCXML_ERR_OK;
- unsigned char conflicts [USCXML_MAX_NR_TRANS_BYTES];
- unsigned char trans_set [USCXML_MAX_NR_TRANS_BYTES];
- unsigned char target_set [USCXML_MAX_NR_STATES_BYTES];
- unsigned char exit_set [USCXML_MAX_NR_STATES_BYTES];
- unsigned char entry_set [USCXML_MAX_NR_STATES_BYTES];
- unsigned char tmp_states [USCXML_MAX_NR_STATES_BYTES];
-
-#ifdef USCXML_VERBOSE
- printf("Config: ");
- printStateNames(ctx, ctx->config, USCXML_NUMBER_STATES);
-#endif
-
- if (ctx->flags & USCXML_CTX_FINISHED)
- return USCXML_ERR_DONE;
-
- if (ctx->flags & USCXML_CTX_TOP_LEVEL_FINAL) {
- /* exit all remaining states */
- i = USCXML_NUMBER_STATES;
- while(i-- > 0) {
- if (BIT_HAS(i, ctx->config)) {
- /* call all on exit handlers */
- if (USCXML_GET_STATE(i).on_exit != NULL) {
- if unlikely((err = USCXML_GET_STATE(i).on_exit(ctx, &USCXML_GET_STATE(i), ctx->event)) != USCXML_ERR_OK)
- return err;
- }
- }
- if (BIT_HAS(i, ctx->invocations)) {
- if (USCXML_GET_STATE(i).invoke != NULL)
- USCXML_GET_STATE(i).invoke(ctx, &USCXML_GET_STATE(i), NULL, 1);
- BIT_CLEAR(i, ctx->invocations);
- }
- }
- ctx->flags |= USCXML_CTX_FINISHED;
- return USCXML_ERR_DONE;
- }
-
- bit_clear_all(target_set, nr_states_bytes);
- bit_clear_all(trans_set, nr_trans_bytes);
- if unlikely(ctx->flags == USCXML_CTX_PRISTINE) {
- if (ctx->machine->script != NULL)
- ctx->machine->script(ctx, &ctx->machine->states[0], NULL);
- bit_or(target_set, ctx->machine->states[0].completion, nr_states_bytes);
- ctx->flags |= USCXML_CTX_SPONTANEOUS | USCXML_CTX_INITIALIZED;
- goto ESTABLISH_ENTRY_SET;
- }
-
-DEQUEUE_EVENT:
- if (ctx->flags & USCXML_CTX_SPONTANEOUS) {
- ctx->event = NULL;
- goto SELECT_TRANSITIONS;
- }
- if (ctx->dequeue_internal != NULL && (ctx->event = ctx->dequeue_internal(ctx)) != NULL) {
- goto SELECT_TRANSITIONS;
- }
-
- /* manage invocations */
- for (i = 0; i < USCXML_NUMBER_STATES; i++) {
- /* uninvoke */
- if (!BIT_HAS(i, ctx->config) && BIT_HAS(i, ctx->invocations)) {
- if (USCXML_GET_STATE(i).invoke != NULL)
- USCXML_GET_STATE(i).invoke(ctx, &USCXML_GET_STATE(i), NULL, 1);
- BIT_CLEAR(i, ctx->invocations)
- }
- /* invoke */
- if (BIT_HAS(i, ctx->config) && !BIT_HAS(i, ctx->invocations)) {
- if (USCXML_GET_STATE(i).invoke != NULL)
- USCXML_GET_STATE(i).invoke(ctx, &USCXML_GET_STATE(i), NULL, 0);
- BIT_SET_AT(i, ctx->invocations)
- }
- }
-
- if (ctx->dequeue_external != NULL && (ctx->event = ctx->dequeue_external(ctx)) != NULL) {
- goto SELECT_TRANSITIONS;
- }
-
- if (ctx->dequeue_external == NULL) {
- return USCXML_ERR_DONE;
- }
- return USCXML_ERR_IDLE;
-
-SELECT_TRANSITIONS:
- bit_clear_all(conflicts, nr_trans_bytes);
- bit_clear_all(exit_set, nr_states_bytes);
- for (i = 0; i < USCXML_NUMBER_TRANS; i++) {
- /* never select history or initial transitions automatically */
- if unlikely(USCXML_GET_TRANS(i).type & (USCXML_TRANS_HISTORY | USCXML_TRANS_INITIAL))
- continue;
-
- /* is the transition active? */
- if (BIT_HAS(USCXML_GET_TRANS(i).source, ctx->config)) {
- /* is it non-conflicting? */
- if (!BIT_HAS(i, conflicts)) {
- /* is it spontaneous with an event or vice versa? */
- if ((USCXML_GET_TRANS(i).event == NULL && ctx->event == NULL) ||
- (USCXML_GET_TRANS(i).event != NULL && ctx->event != NULL)) {
- /* is it enabled? */
- if ((ctx->event == NULL || ctx->is_matched(ctx, &USCXML_GET_TRANS(i), ctx->event) > 0) &&
- (USCXML_GET_TRANS(i).condition == NULL ||
- USCXML_GET_TRANS(i).is_enabled(ctx, &USCXML_GET_TRANS(i)) > 0)) {
- /* remember that we found a transition */
- ctx->flags |= USCXML_CTX_TRANSITION_FOUND;
-
- /* transitions that are pre-empted */
- bit_or(conflicts, USCXML_GET_TRANS(i).conflicts, nr_trans_bytes);
-
- /* states that are directly targeted (resolve as entry-set later) */
- bit_or(target_set, USCXML_GET_TRANS(i).target, nr_states_bytes);
-
- /* states that will be left */
- bit_or(exit_set, USCXML_GET_TRANS(i).exit_set, nr_states_bytes);
-
- BIT_SET_AT(i, trans_set);
- }
- }
- }
- }
- }
- bit_and(exit_set, ctx->config, nr_states_bytes);
-
- if (ctx->flags & USCXML_CTX_TRANSITION_FOUND) {
- ctx->flags |= USCXML_CTX_SPONTANEOUS;
- ctx->flags &= ~USCXML_CTX_TRANSITION_FOUND;
- } else {
- ctx->flags &= ~USCXML_CTX_SPONTANEOUS;
- goto DEQUEUE_EVENT;
- }
-
-#ifdef USCXML_VERBOSE
- printf("Targets: ");
- printStateNames(ctx, target_set, USCXML_NUMBER_STATES);
-#endif
-
-#ifdef USCXML_VERBOSE
- printf("Exiting: ");
- printStateNames(ctx, exit_set, USCXML_NUMBER_STATES);
-#endif
-
-#ifdef USCXML_VERBOSE
- printf("History: ");
- printStateNames(ctx, ctx->history, USCXML_NUMBER_STATES);
-#endif
-
-/* REMEMBER_HISTORY: */
- for (i = 0; i < USCXML_NUMBER_STATES; i++) {
- if unlikely(USCXML_STATE_MASK(USCXML_GET_STATE(i).type) == USCXML_STATE_HISTORY_SHALLOW ||
- USCXML_STATE_MASK(USCXML_GET_STATE(i).type) == USCXML_STATE_HISTORY_DEEP) {
- /* a history state whose parent is about to be exited */
- if unlikely(BIT_HAS(USCXML_GET_STATE(i).parent, exit_set)) {
- bit_copy(tmp_states, USCXML_GET_STATE(i).completion, nr_states_bytes);
-
- /* set those states who were enabled */
- bit_and(tmp_states, ctx->config, nr_states_bytes);
-
- /* clear current history with completion mask */
- bit_and_not(ctx->history, USCXML_GET_STATE(i).completion, nr_states_bytes);
-
- /* set history */
- bit_or(ctx->history, tmp_states, nr_states_bytes);
- }
- }
- }
-
-ESTABLISH_ENTRY_SET:
- /* calculate new entry set */
- bit_copy(entry_set, target_set, nr_states_bytes);
-
- /* iterate for ancestors */
- for (i = 0; i < USCXML_NUMBER_STATES; i++) {
- if (BIT_HAS(i, entry_set)) {
- bit_or(entry_set, USCXML_GET_STATE(i).ancestors, nr_states_bytes);
- }
- }
-
- /* iterate for descendants */
- for (i = 0; i < USCXML_NUMBER_STATES; i++) {
- if (BIT_HAS(i, entry_set)) {
- switch (USCXML_STATE_MASK(USCXML_GET_STATE(i).type)) {
- case USCXML_STATE_PARALLEL: {
- bit_or(entry_set, USCXML_GET_STATE(i).completion, nr_states_bytes);
- break;
- }
-#ifndef USCXML_NO_HISTORY
- case USCXML_STATE_HISTORY_SHALLOW:
- case USCXML_STATE_HISTORY_DEEP: {
- if (!bit_has_and(USCXML_GET_STATE(i).completion, ctx->history, nr_states_bytes) &&
- !BIT_HAS(USCXML_GET_STATE(i).parent, ctx->config)) {
- /* nothing set for history, look for a default transition */
- for (j = 0; j < USCXML_NUMBER_TRANS; j++) {
- if unlikely(ctx->machine->transitions[j].source == i) {
- bit_or(entry_set, ctx->machine->transitions[j].target, nr_states_bytes);
- if(USCXML_STATE_MASK(USCXML_GET_STATE(i).type) == USCXML_STATE_HISTORY_DEEP &&
- !bit_has_and(ctx->machine->transitions[j].target, USCXML_GET_STATE(i).children, nr_states_bytes)) {
- for (k = i + 1; k < USCXML_NUMBER_STATES; k++) {
- if (BIT_HAS(k, ctx->machine->transitions[j].target)) {
- bit_or(entry_set, ctx->machine->states[k].ancestors, nr_states_bytes);
- break;
- }
- }
- }
- BIT_SET_AT(j, trans_set);
- break;
- }
- /* Note: SCXML mandates every history to have a transition! */
- }
- } else {
- bit_copy(tmp_states, USCXML_GET_STATE(i).completion, nr_states_bytes);
- bit_and(tmp_states, ctx->history, nr_states_bytes);
- bit_or(entry_set, tmp_states, nr_states_bytes);
- if (USCXML_GET_STATE(i).type == (USCXML_STATE_HAS_HISTORY | USCXML_STATE_HISTORY_DEEP)) {
- /* a deep history state with nested histories -> more completion */
- for (j = i + 1; j < USCXML_NUMBER_STATES; j++) {
- if (BIT_HAS(j, USCXML_GET_STATE(i).completion) &&
- BIT_HAS(j, entry_set) &&
- (ctx->machine->states[j].type & USCXML_STATE_HAS_HISTORY)) {
- for (k = j + 1; k < USCXML_NUMBER_STATES; k++) {
- /* add nested history to entry_set */
- if ((USCXML_STATE_MASK(ctx->machine->states[k].type) == USCXML_STATE_HISTORY_DEEP ||
- USCXML_STATE_MASK(ctx->machine->states[k].type) == USCXML_STATE_HISTORY_SHALLOW) &&
- BIT_HAS(k, ctx->machine->states[j].children)) {
- /* a nested history state */
- BIT_SET_AT(k, entry_set);
- }
- }
- }
- }
- }
- }
- break;
- }
-#endif
- case USCXML_STATE_INITIAL: {
- for (j = 0; j < USCXML_NUMBER_TRANS; j++) {
- if (ctx->machine->transitions[j].source == i) {
- BIT_SET_AT(j, trans_set);
- BIT_CLEAR(i, entry_set);
- bit_or(entry_set, ctx->machine->transitions[j].target, nr_states_bytes);
- for (k = i + 1; k < USCXML_NUMBER_STATES; k++) {
- if (BIT_HAS(k, ctx->machine->transitions[j].target)) {
- bit_or(entry_set, ctx->machine->states[k].ancestors, nr_states_bytes);
- }
- }
- }
- }
- break;
- }
- case USCXML_STATE_COMPOUND: { /* we need to check whether one child is already in entry_set */
- if (!bit_has_and(entry_set, USCXML_GET_STATE(i).children, nr_states_bytes) &&
- (!bit_has_and(ctx->config, USCXML_GET_STATE(i).children, nr_states_bytes) ||
- bit_has_and(exit_set, USCXML_GET_STATE(i).children, nr_states_bytes)))
- {
- bit_or(entry_set, USCXML_GET_STATE(i).completion, nr_states_bytes);
- if (!bit_has_and(USCXML_GET_STATE(i).completion, USCXML_GET_STATE(i).children, nr_states_bytes)) {
- /* deep completion */
- for (j = i + 1; j < USCXML_NUMBER_STATES; j++) {
- if (BIT_HAS(j, USCXML_GET_STATE(i).completion)) {
- bit_or(entry_set, ctx->machine->states[j].ancestors, nr_states_bytes);
- break; /* completion of compound is single state */
- }
- }
- }
- }
- break;
- }
- }
- }
- }
-
-#ifdef USCXML_VERBOSE
- printf("Transitions: ");
- printBitsetIndices(trans_set, sizeof(char) * 8 * nr_trans_bytes);
-#endif
-
-/* EXIT_STATES: */
- i = USCXML_NUMBER_STATES;
- while(i-- > 0) {
- if (BIT_HAS(i, exit_set) && BIT_HAS(i, ctx->config)) {
- /* call all on exit handlers */
- if (USCXML_GET_STATE(i).on_exit != NULL) {
- if unlikely((err = USCXML_GET_STATE(i).on_exit(ctx, &USCXML_GET_STATE(i), ctx->event)) != USCXML_ERR_OK)
- return err;
- }
- BIT_CLEAR(i, ctx->config);
- }
- }
-
-/* TAKE_TRANSITIONS: */
- for (i = 0; i < USCXML_NUMBER_TRANS; i++) {
- if (BIT_HAS(i, trans_set) && (USCXML_GET_TRANS(i).type & (USCXML_TRANS_HISTORY | USCXML_TRANS_INITIAL)) == 0) {
- /* call executable content in transition */
- if (USCXML_GET_TRANS(i).on_transition != NULL) {
- if unlikely((err = USCXML_GET_TRANS(i).on_transition(ctx,
- &ctx->machine->states[USCXML_GET_TRANS(i).source],
- ctx->event)) != USCXML_ERR_OK)
- return err;
- }
- }
- }
-
-#ifdef USCXML_VERBOSE
- printf("Entering: ");
- printStateNames(ctx, entry_set, USCXML_NUMBER_STATES);
-#endif
-
-/* ENTER_STATES: */
- for (i = 0; i < USCXML_NUMBER_STATES; i++) {
- if (BIT_HAS(i, entry_set) && !BIT_HAS(i, ctx->config)) {
- /* these are no proper states */
- if unlikely(USCXML_STATE_MASK(USCXML_GET_STATE(i).type) == USCXML_STATE_HISTORY_DEEP ||
- USCXML_STATE_MASK(USCXML_GET_STATE(i).type) == USCXML_STATE_HISTORY_SHALLOW ||
- USCXML_STATE_MASK(USCXML_GET_STATE(i).type) == USCXML_STATE_INITIAL)
- continue;
-
- BIT_SET_AT(i, ctx->config);
-
- /* initialize data */
- if (!BIT_HAS(i, ctx->initialized_data)) {
- if unlikely(USCXML_GET_STATE(i).data != NULL && ctx->exec_content_init != NULL) {
- ctx->exec_content_init(ctx, USCXML_GET_STATE(i).data);
- }
- BIT_SET_AT(i, ctx->initialized_data);
- }
-
- if (USCXML_GET_STATE(i).on_entry != NULL) {
- if unlikely((err = USCXML_GET_STATE(i).on_entry(ctx, &USCXML_GET_STATE(i), ctx->event)) != USCXML_ERR_OK)
- return err;
- }
-
- /* take history and initial transitions */
- for (j = 0; j < USCXML_NUMBER_TRANS; j++) {
- if unlikely(BIT_HAS(j, trans_set) &&
- (ctx->machine->transitions[j].type & (USCXML_TRANS_HISTORY | USCXML_TRANS_INITIAL)) &&
- ctx->machine->states[ctx->machine->transitions[j].source].parent == i) {
- /* call executable content in transition */
- if (ctx->machine->transitions[j].on_transition != NULL) {
- if unlikely((err = ctx->machine->transitions[j].on_transition(ctx,
- &USCXML_GET_STATE(i),
- ctx->event)) != USCXML_ERR_OK)
- return err;
- }
- }
- }
-
- /* handle final states */
- if unlikely(USCXML_STATE_MASK(USCXML_GET_STATE(i).type) == USCXML_STATE_FINAL) {
- if unlikely(USCXML_GET_STATE(i).ancestors[0] == 0x01) {
- ctx->flags |= USCXML_CTX_TOP_LEVEL_FINAL;
- } else {
- /* raise done event */
- const uscxml_elem_donedata* donedata = &ctx->machine->donedata[0];
- while(USCXML_ELEM_DONEDATA_IS_SET(donedata)) {
- if unlikely(donedata->source == i)
- break;
- donedata++;
- }
- ctx->raise_done_event(ctx, &ctx->machine->states[USCXML_GET_STATE(i).parent], (USCXML_ELEM_DONEDATA_IS_SET(donedata) ? donedata : NULL));
- }
-
- /**
- * are we the last final state to leave a parallel state?:
- * 1. Gather all parallel states in our ancestor chain
- * 2. Find all states for which these parallels are ancestors
- * 3. Iterate all active final states and remove their ancestors
- * 4. If a state remains, not all children of a parallel are final
- */
- for (j = 0; j < USCXML_NUMBER_STATES; j++) {
- if unlikely(USCXML_STATE_MASK(ctx->machine->states[j].type) == USCXML_STATE_PARALLEL &&
- BIT_HAS(j, USCXML_GET_STATE(i).ancestors)) {
- bit_clear_all(tmp_states, nr_states_bytes);
- for (k = 0; k < USCXML_NUMBER_STATES; k++) {
- if unlikely(BIT_HAS(j, ctx->machine->states[k].ancestors) && BIT_HAS(k, ctx->config)) {
- if (USCXML_STATE_MASK(ctx->machine->states[k].type) == USCXML_STATE_FINAL) {
- bit_and_not(tmp_states, ctx->machine->states[k].ancestors, nr_states_bytes);
- } else {
- BIT_SET_AT(k, tmp_states);
- }
- }
- }
- if unlikely(!bit_has_any(tmp_states, nr_states_bytes)) {
- ctx->raise_done_event(ctx, &ctx->machine->states[j], NULL);
- }
- }
- }
-
- }
-
- }
- }
-
- return USCXML_ERR_OK;
-}
-
-#define USCXML_NO_STEP_FUNCTION
-#endif
-
diff --git a/apps/uscxml-browser.cpp b/apps/uscxml-browser.cpp
deleted file mode 100644
index dd0633b..0000000
--- a/apps/uscxml-browser.cpp
+++ /dev/null
@@ -1,132 +0,0 @@
-#include "uscxml/config.h"
-#include "uscxml/Interpreter.h"
-#include "uscxml/InterpreterOptions.h"
-#include "uscxml/debug/InterpreterIssue.h"
-#include "uscxml/debug/DebuggerServlet.h"
-#include "uscxml/interpreter/InterpreterMonitor.h"
-#include "uscxml/util/DOM.h"
-
-#include "uscxml/interpreter/Logging.h"
-
-#include "uscxml/plugins/Factory.h"
-#include "uscxml/server/HTTPServer.h"
-
-
-int main(int argc, char** argv) {
- using namespace uscxml;
-
-#if defined(HAS_SIGNAL_H) && !defined(WIN32)
- signal(SIGPIPE, SIG_IGN);
-#endif
-
- InterpreterOptions options = InterpreterOptions::fromCmdLine(argc, argv);
-
- if (!options) {
- InterpreterOptions::printUsageAndExit(argv[0]);
- }
-
- if (!options.validate) {
- // setup HTTP server
- HTTPServer::SSLConfig* sslConf = NULL;
- if (options.certificate.length() > 0) {
- sslConf = new HTTPServer::SSLConfig();
- sslConf->privateKey = options.certificate;
- sslConf->publicKey = options.certificate;
- sslConf->port = options.httpsPort;
-
- } else if (options.privateKey.length() > 0 && options.publicKey.length() > 0) {
- sslConf = new HTTPServer::SSLConfig();
- sslConf->privateKey = options.privateKey;
- sslConf->publicKey = options.publicKey;
- sslConf->port = options.httpsPort;
-
- }
- HTTPServer::getInstance(options.httpPort, options.wsPort, sslConf);
- }
-
- if (options.pluginPath.length() > 0) {
- Factory::setDefaultPluginPath(options.pluginPath);
- }
-
- if (options.verbose) {
- Factory::getInstance()->listComponents();
- }
-
- // instantiate and configure interpreters
- std::list<Interpreter> interpreters;
- for(size_t i = 0; i < options.interpreters.size(); i++) {
-
-// InterpreterOptions* currOptions = options.interpreters[0].second;
- std::string documentURL = options.interpreters[i].first;
-
- LOGD(USCXML_INFO) << "Processing " << documentURL << std::endl;
-
- try {
- Interpreter interpreter = Interpreter::fromURL(documentURL);
- if (interpreter) {
-
- if (options.validate) {
- std::list<InterpreterIssue> issues = interpreter.validate();
- for (std::list<InterpreterIssue>::iterator issueIter = issues.begin(); issueIter != issues.end(); issueIter++) {
- LOGD(USCXML_DEBUG) << "" << *issueIter << std::endl;
- }
- if (issues.size() == 0) {
- LOGD(USCXML_DEBUG) << "No issues found" << std::endl;
- }
-
- }
-
- if (options.verbose) {
- StateTransitionMonitor* vm = new StateTransitionMonitor();
- vm->copyToInvokers(true);
- interpreter.addMonitor(vm);
- }
-
- interpreters.push_back(interpreter);
-
- } else {
- LOGD(USCXML_ERROR) << "Cannot create interpreter from " << documentURL << std::endl;
- }
- } catch (Event e) {
- LOGD(USCXML_ERROR) << e << std::endl;
- }
- }
-
- if (options.validate) {
- return EXIT_SUCCESS;
- }
-
- if (options.withDebugger) {
- DebuggerServlet* debugger;
- debugger = new DebuggerServlet();
- debugger->copyToInvokers(true);
- HTTPServer::getInstance()->registerServlet("/debug", debugger);
- for (auto interpreter : interpreters) {
- interpreter.addMonitor(debugger);
- }
- }
-
- // run interpreters
- if (interpreters.size() > 0) {
- try {
- std::list<Interpreter>::iterator interpreterIter = interpreters.begin();
- while (interpreters.size() > 0) {
- while(interpreterIter != interpreters.end()) {
- InterpreterState state = interpreterIter->step();
- if (state == USCXML_FINISHED) {
- interpreterIter = interpreters.erase(interpreterIter);
- } else {
- interpreterIter++;
- }
- }
- interpreterIter = interpreters.begin();
- }
- } catch (Event e) {
- LOGD(USCXML_ERROR) << e << std::endl;
- }
- } else if (options.withDebugger) {
- while(true)
- std::this_thread::sleep_for(std::chrono::seconds(1));
- }
- return EXIT_SUCCESS;
-}
diff --git a/apps/uscxml-browser.vbs b/apps/uscxml-browser.vbs
deleted file mode 100644
index fc8ea9a..0000000
--- a/apps/uscxml-browser.vbs
+++ /dev/null
@@ -1,177 +0,0 @@
-'
-' Description: VBScript/VBS open file dialog
-' Compatible with most Windows platforms
-' Author: wangye <pcn88 at hotmail dot com>
-' Website: http://wangye.org
-'
-' dir is the initial directory; if no directory is
-' specified "Desktop" is used.
-' filter is the file type filter; format "File type description|*.ext"
-'
-Public Function GetOpenFileName(dir, filter)
- Const msoFileDialogFilePicker = 3
-
- If VarType(dir) <> vbString Or dir="" Then
- dir = CreateObject( "WScript.Shell" ).SpecialFolders( "Desktop" )
- End If
-
- If VarType(filter) <> vbString Or filter="" Then
- filter = "All files|*.*"
- End If
-
- Dim i,j, objDialog, TryObjectNames
- TryObjectNames = Array( _
- "UserAccounts.CommonDialog", _
- "MSComDlg.CommonDialog", _
- "MSComDlg.CommonDialog.1", _
- "Word.Application", _
- "SAFRCFileDlg.FileOpen", _
- "InternetExplorer.Application" _
- )
-
- On Error Resume Next
- Err.Clear
-
- For i=0 To UBound(TryObjectNames)
- Set objDialog = WSH.CreateObject(TryObjectNames(i))
- If Err.Number<>0 Then
- Err.Clear
- Else
- Exit For
- End If
- Next
-
- Select Case i
- Case 0,1,2
- ' 0. UserAccounts.CommonDialog XP Only.
- ' 1.2. MSComDlg.CommonDialog MSCOMDLG32.OCX must registered.
- If i=0 Then
- objDialog.InitialDir = dir
- Else
- objDialog.InitDir = dir
- End If
- objDialog.Filter = filter
- If objDialog.ShowOpen Then
- GetOpenFileName = objDialog.FileName
- End If
- Case 3
- ' 3. Word.Application Microsoft Office must installed.
- objDialog.Visible = False
- Dim objOpenDialog, filtersInArray
- filtersInArray = Split(filter, "|")
- Set objOpenDialog = _
- objDialog.Application.FileDialog( _
- msoFileDialogFilePicker)
- With objOpenDialog
- .Title = "Open File(s):"
- .AllowMultiSelect = False
- .InitialFileName = dir
- .Filters.Clear
- For j=0 To UBound(filtersInArray) Step 2
- .Filters.Add filtersInArray(j), _
- filtersInArray(j+1), 1
- Next
- If .Show And .SelectedItems.Count>0 Then
- GetOpenFileName = .SelectedItems(1)
- End If
- End With
- objDialog.Visible = True
- objDialog.Quit
- Set objOpenDialog = Nothing
- Case 4
- ' 4. SAFRCFileDlg.FileOpen xp 2003 only
- ' See http://www.robvanderwoude.com/vbstech_ui_fileopen.php
- If objDialog.OpenFileOpenDlg Then
- GetOpenFileName = objDialog.FileName
- End If
- Case 5
-
- Dim IEVersion,IEMajorVersion, hasCompleted
- hasCompleted = False
- Dim shell
- Set shell = CreateObject("WScript.Shell")
- ' 下面获取IE版本
- IEVersion = shell.RegRead( _
- "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\Version")
- If InStr(IEVersion,".")>0 Then
- ' 获取主版本号
- IEMajorVersion = CInt(Left(IEVersion, InStr(IEVersion,".")-1))
- If IEMajorVersion>7 Then
- ' 如果版本号大于7,也就是大于IE7,则采取MSHTA方案
- ' Bypasses c:\fakepath\file.txt problem
- ' http://pastebin.com/txVgnLBV
- Dim fso
- Set fso = CreateObject("Scripting.FileSystemObject")
-
- Dim tempFolder : Set tempFolder = fso.GetSpecialFolder(2)
- Dim tempName : tempName = fso.GetTempName()
- Dim tempFile : Set tempFile = tempFolder.CreateTextFile(tempName & ".hta")
- Dim tempBaseName
- tempBaseName = tempFolder & "\" & tempName
- tempFile.Write _
- "<html>" & _
- " <head>" & _
- " <title>Browse</title>" & _
- " </head>" & _
- " <body>" & _
- " <input type='file' id='f'>" & _
- " <script type='text/javascript'>" & _
- " var f = document.getElementById('f');" & _
- " f.click();" & _
- " var fso = new ActiveXObject('Scripting.FileSystemObject');" & _
- " var file = fso.OpenTextFile('" & _
- Replace(tempBaseName,"\", "\\") & ".txt" & "', 2, true);" & _
- " file.Write(f.value);" & _
- " file.Close();" & _
- " window.close();" & _
- " </script>" & _
- " </body>" & _
- "</html>"
- tempFile.Close
- Set tempFile = Nothing
- Set tempFolder = Nothing
- shell.Run tempBaseName & ".hta", 1, True
- Set tempFile = fso.OpenTextFile(tempBaseName & ".txt", 1)
- GetOpenFileName = tempFile.ReadLine
- tempFile.Close
- fso.DeleteFile tempBaseName & ".hta"
- fso.DeleteFile tempBaseName & ".txt"
- Set tempFile = Nothing
- Set fso = Nothing
- hasCompleted = True ' 标记为已完成
- End If
- End If
- If Not hasCompleted Then
- ' 5. InternetExplorer.Application IE must installed
- objDialog.Navigate "about:blank"
- Dim objBody, objFileDialog
- Set objBody = _
- objDialog.document.getElementsByTagName("body")(0)
- objBody.innerHTML = "<input type='file' id='fileDialog'>"
- while objDialog.Busy Or objDialog.ReadyState <> 4
- WScript.sleep 10
- Wend
- Set objFileDialog = objDialog.document.all.fileDialog
- objFileDialog.click
- GetOpenFileName = objFileDialog.value
- End If
- objDialog.Quit
- Set objFileDialog = Nothing
- Set objBody = Nothing
- Set shell = Nothing
- Case Else
- ' Sorry I cannot do that!
- End Select
-
- Set objDialog = Nothing
-End Function
-
-scxmlFile = GetOpenFileName(CreateObject("WScript.Shell").SpecialFolders("MyDocuments"), "All Files|*.*|SCXML Files|*.scxml")
-
-if scxmlFile <> "" then
- set wshShell = WScript.CreateObject("WScript.Shell")
- set objFs = WScript.CreateObject("Scripting.FileSystemObject")
- wshShell.CurrentDirectory = objFs.GetParentFolderName(Wscript.ScriptFullName)
-' WScript.Echo scxmlFile
- wshShell.Run("mmi-browser.exe """ & scxmlFile & """")
-end if \ No newline at end of file
diff --git a/apps/uscxml-debugger.html b/apps/uscxml-debugger.html
deleted file mode 100644
index fa49554..0000000
--- a/apps/uscxml-debugger.html
+++ /dev/null
@@ -1,2839 +0,0 @@
-<!doctype html>
-<html>
-<head>
- <!-- <link href="http://localhost/~sradomski/jsPlumb/font-awesome.css" rel="stylesheet"> -->
- <!-- <link rel="stylesheet" href="http://localhost/~sradomski/jsPlumb/demo-all.css"> -->
- <!-- <link rel="stylesheet" href="http://localhost/~sradomski/jsPlumb/demo.css"> -->
-
- <!-- script src="https://google-code-prettify.googlecode.com/svn/loader/prettify.js?autoload=false"></script -->
- <!--script src="https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js?autoload=false&amp;lang=xml" defer="defer"></script-->
-
- <script src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
- <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.4/jquery-ui.min.js"></script>
- <script src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.11.1/jquery.validate.min.js"></script>
- <script src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.11.1/additional-methods.min.js"></script>
- <script src="http://netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script>
-
- <script src="http://cdn.jsdelivr.net/ace/1.1.01/min/ace.js" charset="utf-8"></script>
- <script src="http://vkbeautify.googlecode.com/files/vkbeautify.0.99.00.beta.js" charset="utf-8"></script>
- <script src="http://cdnjs.cloudflare.com/ajax/libs/typeahead.js/0.9.3/typeahead.min.js" charset="utf-8"></script>
- <script src="http://dean.edwards.name/base/Base.js" charset="utf-8"></script>
- <!-- alternatively http://maxailloud.github.io/confirm-bootstrap/#liveDemo -->
-
- <script src="https://rawgithub.com/jibe914/Bootstrap-Confirmation/master/bootstrap3-confirmation.js" charset="utf-8"></script>
- <!--script src="https://raw.githubusercontent.com/jibe914/Bootstrap-Confirmation/master/bootstrap3-confirmation.js" charset="utf-8"></script-->
- <!-- script src="https://raw.github.com/Tavicu/bootstrap-confirmation/master/bootstrap-confirmation.js" charset="utf-8"></script -->
-
-
- <script src="https://rawgithub.com/msurguy/ladda-bootstrap/master/dist/spin.js" charset="utf-8"></script>
- <script src="https://rawgithub.com/msurguy/ladda-bootstrap/master/dist/ladda.js" charset="utf-8"></script>
- <script src="https://rawgithub.com/prettycode/Object.identical.js/master/Object.identical.js" charset="utf-8"></script>
-
-
- <!-- <link rel="stylesheet" href="jQuery-File-Upload/css/style.css">
- <link rel="stylesheet" href="jQuery-File-Upload/css/jquery.fileupload.css"> -->
-
-
-
- <link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.4/themes/smoothness/jquery-ui.css" />
- <link rel="stylesheet" href="http://netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css">
- <!-- <link rel="stylesheet" href="http://netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap-theme.min.css"> -->
- <!-- <link rel="stylesheet" href="http://twitter.github.io/typeahead.js/css/main.css" /> -->
- <link rel="stylesheet" href="https://raw.githubusercontent.com/hyspace/typeahead.js-bootstrap3.less/master/typeahead.css" />
- <link rel="stylesheet" href="https://rawgithub.com/msurguy/ladda-bootstrap/master/dist/ladda-themeless.min.css" />
-
- <!-- script src="jquery-ui-1.10.4.uscxml/js/jquery-1.10.2.js"></script>
- <script src="http://cdnjs.cloudflare.com/ajax/libs/select2/3.4.5/select2.min.js" charset="utf-8"></script>
- <link rel="stylesheet" href="http://twitter.github.io/typeahead.js/css/main.css" />
- <script src="Base.js"></script>
- <script src="jquery-ui-1.10.4.uscxml/js/jquery-ui-1.10.4.custom.js"></script>
- <script src="http://localhost/~sradomski/ace/ace.js" charset="utf-8"></script>
- <script src="http://localhost/~sradomski/vkbeautify.0.99.00.beta.js" charset="utf-8"></script>
- <link rel="stylesheet" href="http://cdnjs.cloudflare.com/ajax/libs/select2/3.4.5/select2.min.css">
-
- <script src='http://localhost/~sradomski/jsPlumb/jquery.min.js'></script>
- <script src='http://localhost/~sradomski/jsPlumb/jquery-ui.min.js'></script>
- <script src='http://localhost/~sradomski/jsPlumb/jquery.ui.touch-punch.min.js'></script>
- <script src="//cdnjs.cloudflare.com/ajax/libs/ace/1.1.01/ace.js"></script>
- <script src='http://localhost/~sradomski/jsPlumb/jquery.jsPlumb-1.5.5.js'></script>
- <script src="http://localhost/~sradomski/ace/ace.js" charset="utf-8"></script>
- <script src="http://localhost/~sradomski/jquery.dropdown.min.js" charset="utf-8"></script>
- <script src="http://localhost/~sradomski/bootstrap/js/bootstrap.min.js"></script -->
-
- <!-- link href="jquery.dropdown.css" rel="stylesheet" / -->
- <!-- <link rel="stylesheet" href="//code.jquery.com/ui/1.10.4/themes/dark-hive/jquery-ui.css"> -->
- <!-- link rel="stylesheet" href="//code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css" -->
-
- <style type="text/css">
-
- body {
-/* font-family: "Trebuchet MS", "Helvetica", "Arial", "Verdana", "sans-serif";*/
- }
-
- .windowlet {
- position: absolute;
- top: 3em;
- left: 5em;
- box-shadow: 5px 2px 19px #aaa;
- -o-box-shadow: 5px 2px 19px #aaa;
- -webkit-box-shadow: 5px 2px 19px #aaa;
- -moz-box-shadow: 5px 2px 19px #aaa;
- }
-
- .windowlet .panel-body {
- padding: 8px;
- }
-
- .windowlet textarea {
- resize:vertical;
- }
-
- .debug {
- position:fixed !important;
- width: 320px;
- min-width: 250px;
- }
-
- .debug > .panel > .panel-group {
-/* overflow: hidden;*/
- margin-bottom: 0px;
- }
-
- .debug > .panel {
- margin-bottom: 0;
- }
-
- .debug > .panel > .panel-footer {
- padding: 5px 5px;
- font-family:Consolas,Monaco,Lucida Console,Liberation Mono,DejaVu Sans Mono,Bitstream Vera Sans Mono,Courier New, monospace;
- font-size: 10px;
- }
-
- .panel-group .panel {
-/* border: 1px solid transparent;*/
- overflow: visible;
- }
-
- .debug-header {
- cursor: move;
-/* padding: 10px 15px 5px 15px;
-*/ }
-
- .subtitle {
- font-size: 0.7em;
- font-weight: normal;
- }
-
- /* nested panels */
- .panel .panel .panel-heading {
- padding: 8px 15px;
- }
-
- .panel .panel-group .panel {
- border-radius: 0px;
- }
-
- .panel .panel .panel-title {
- font-size: 100%; /* Override explicit font-size from bootstrap */
- }
-
- .panel .panel {
- font-size: 90%;
- }
-
- .panel-group .panel+.panel {
- margin-top: 0px;
- }
-
- .panel-heading {
- position: relative;
- }
- .heading-decoration {
- position: absolute;
- right: 40px;
- top: 4px;
- }
-
- .heading-decoration .badge {
- float: left;
- margin-top: 2px;
- margin-right: 5px;
- }
-
- .panel-heading .panel-toggle:after {
- /* symbol for "opening" panels */
- font-family: 'Glyphicons Halflings'; /* essential for enabling glyphicon */
- content: "\e114"; /* adjust as needed, taken from bootstrap.css */
- float: right; /* adjust as needed */
- color: grey; /* adjust as needed */
- }
- .panel-heading.collapsed .panel-toggle:after {
- /* symbol for "collapsed" panels */
- content: "\e080"; /* adjust as needed, taken from bootstrap.css */
- }
-
- /* see http://stackoverflow.com/questions/18059161/css-issue-on-twitter-typeahead-with-bootstrap-3 */
- .twitter-typeahead .tt-hint {
- display: block;
- height: 34px;
- padding: 6px 12px;
- font-size: 14px;
- line-height: 1.428571429;
- border: 1px solid transparent;
- }
-
- .form-group .twitter-typeahead {
- width: 100%;
- }
-
- .messages-content textarea.messages {
- font-size: 10px;
- cursor: auto;
- white-space: pre;
- overflow: auto;
- font-family:Consolas,Monaco,Lucida Console,Liberation Mono,DejaVu Sans Mono,Bitstream Vera Sans Mono,Courier New, monospace;
- height: 16em;
- }
-
- ul.dropdown-menu li.server-session {
- padding-left: 0.7em;
- }
-
- ul.recent-documents span.recent-document-features {
- padding-left: 0.7em;
- }
-
- .tooltip-inner {
- background-color: #333;
- }
- .tooltip.bottom .tooltip-arrow {
- border-bottom-color: #333;
- background-color: #FFF transparent;
- }
-
- .dom {
- font-size: 10px;
- font-family:Consolas,Monaco,Lucida Console,Liberation Mono,DejaVu Sans Mono,Bitstream Vera Sans Mono,Courier New, monospace;
- color: #666;
- }
-
- .dom .active-state {
- color: #000;
- }
-
- .dom .xpath-selected {
- color: #A00;
- font-weight: bold;
- }
-
- </style>
-
- <script type="text/javascript">
-
- var SCXMLEditor = Base.extend({
- constructor: function(params) {
- $.extend(this, params);
-
- this.debugger = new SCXMLEditor.Debugger.USCXML({
- debuggerURL: "http://localhost:8088",
- scxmlEditor: this,
- });
-
- this.xmlView = new SCXMLEditor.XMLView({
- destNode: $("body").find(".dom")[0],
- });
-
- $(this.debugger.getNode()).appendTo($("body"));
- },
-
- scxmlDOM: undefined,
- scxmlURL: undefined,
- scxmlRoot: undefined,
- scxmlStates: {},
-
- setDocumentNameFromURL: function(url) {
- var tmp = $('<a>', { href:url } )[0];
- $(this.debugger.debugDocumentNameNode).html(tmp.pathname.split('/').pop());
- $(this.debugger.saveBreakpointsNode).closest("li").removeClass("disabled");
- },
-
- loadURL: function(scxmlURL) {
- this.scxmlURL = scxmlURL;
- this.setDocumentNameFromURL(scxmlURL);
-
- if (scxmlURL in this.debugger.recentDocuments) {
- // load breakpoints
- if ('breakpoints' in this.debugger.recentDocuments[scxmlURL]) {
- for (var index in this.debugger.recentDocuments[scxmlURL].breakpoints) {
- var breakpointData = this.debugger.recentDocuments[scxmlURL].breakpoints[index];
- var breakpoint = new SCXMLEditor.Debugger.Breakpoint({
- data: breakpointData
- });
-
- var serializedBreakpoint = JSON.stringify(breakpoint.toWireFormat());
- var alreadyExists = false;
-
- // check if such a breakpoint already exists
- for (var index in this.debugger.breakpoints) {
- var otherBreakpoint = this.debugger.breakpoints[index];
- if (serializedBreakpoint === JSON.stringify(otherBreakpoint.toWireFormat())) {
- alreadyExists = true;
- break;
- }
- }
-
- if (!alreadyExists)
- this.debugger.addBreakpoint(breakpoint);
- }
- }
- }
-
- // get instance into scope chain
- var scxmlEdit = this;
- $.ajax({
- type: "GET",
- dataType: "text xml",
- url: scxmlURL,
- success: function (dom) {
- scxmlEdit.loadDOM(dom);
- },
- error: function(data) {
- console.log(data);
- }
- });
- },
-
- loadDOM: function(scxmlDOM) {
- this.scxmlDOM = scxmlDOM;
- this.scxmlRoot = $(scxmlDOM).find("scxml")[0];
-
- // notify the debugger
- this.debugger.loadDOM(scxmlDOM);
-
- // var domText = SCXMLEditor.xmlToString(this.scxmlDOM);
- // $("body").find("pre.dom").text(domText);
- if (this.xmlView) {
- this.xmlView.setXML(this.scxmlDOM);
- this.xmlView.prettyPrint();
- }
-
- // add 'nested' class to states of nested scxml documents
- $(this.scxmlRoot).find("scxml").find("state, final, parallel, history").addClass("nested");
- $(this.getNode()).appendTo(this.containerNode);
- },
-
- getNode: function() {
- this.node = document.createElement('div');
- this.node.className = "scxml-editor";
- this.node.innerHTML = '\
- <div class="state-tree"></div>\
- <div class="tools"></div>\
- ';
-
- this.stateTreeNode = $(this.node).children("div.state-tree");
- this.toolsNode = $(this.node).children("div.tools");
-
- // var rootState = new SCXMLEditor.PortletStateView({
- // scxmlState: this.scxmlRoot,
- // scxmlEditor: this
- // });
- // this.rootNode = rootState.getNode();
- // $(this.rootNode).appendTo(this.stateTreeNode);
- // $(this.rootNode).draggable();
-
- return this.node;
- },
-
- getAllChildStates: function() {
- return $(this.scxmlRoot).find("state, parallel, final, history").not(".nested");
- },
-
- getAllStateIds: function() {
- var stateIds = [];
- var self = this;
- $.each(this.getAllChildStates(), function(index, state) {
- stateIds.push(SCXMLEditor.getStateId(state));
- });
- return stateIds;
- }
-
- });
-
- SCXMLEditor.getStateId = function(state) {
- return $(state).attr("id") || $(state).attr("name") || "scxml";
- }
-
- SCXMLEditor.getStateType = function(state) {
- return state.nodeName.toLowerCase();
- }
-
- SCXMLEditor.xmlToString = function (xmlNode) {
- var text = xmlNode.xml || (new XMLSerializer()).serializeToString(xmlNode);
- return vkbeautify.xml(text);
- }
-
- SCXMLEditor.XMLView = Base.extend({
- constructor: function(params) {
- $.extend(this, params);
- },
-
- prettyPrint: function(destNode) {
- var self = this;
-
- function escapeText(text) {
- return $('<div/>').text(text).html();
- }
- function prettyIndent(xmlNode, indentation) {
- var outputText = '';
- var indenter = '';
-
- for (var i = 0; i < indentation; i++) {
- indenter += "&nbsp;&nbsp;&nbsp;&nbsp;";
- }
- var isActive = false;
- var isXPathSelected = false;
-
- switch(xmlNode.nodeType) {
- case Node.ELEMENT_NODE:
- if (xmlNode.nodeName.toLowerCase() === "state") {
- var stateId = xmlNode.getAttribute("id");
- if ($.inArray(stateId, self.activeStates) >= 0) {
- outputText += '<span class="active-state">';
- isActive = true;
- }
- }
-
- if (xpathNodeSet && xpathNodeSet.snapshotLength > 0) {
- for (var i = 0; i < xpathNodeSet.snapshotLength; i++) {
- var currNode = xpathNodeSet.snapshotItem(i);
- // console.log("Comparing:");
- // console.log(currNode);
- // console.log(xmlNode);
- if (currNode === xmlNode) {
- // console.log("currNode:");
- // console.log(currNode);
- outputText += '<span class="xpath-selected">';
- isXPathSelected = true;
- break;
- }
- }
- }
-
- outputText += indenter;
- outputText += '&lt;' + xmlNode.nodeName;
- for (var j = 0; j < xmlNode.attributes.length; j++) {
- var attribute = xmlNode.attributes.item(j);
- outputText += " " + attribute.nodeName + "=\"" + attribute.nodeValue + "\"";
- }
- if (!xmlNode.hasChildNodes()) {
- outputText += ' /&gt;';
- outputText += '<br />';
- } else {
- outputText += '&gt;';
- outputText += '<br />';
- }
- break;
- case Node.COMMENT_NODE:
- outputText += indenter;
- outputText += '&lt;!-- ' + escapeText(xmlNode.nodeValue.trim()) + ' -->';
- outputText += '<br />';
- break;
- case Node.TEXT_NODE:
- var text = xmlNode.nodeValue.trim();
- if (text.length > 0) {
- outputText += indenter;
- outputText += escapeText(text);
- outputText += '<br />';
- }
- break;
- case Node.ATTRIBUTE_NODE:
- case Node.CDATA_SECTION_NODE:
- case Node.ENTITY_REFERENCE_NODE:
- case Node.ENTITY_NODE:
- case Node.PROCESSING_INSTRUCTION_NODE:
- case Node.DOCUMENT_NODE:
- case Node.DOCUMENT_TYPE_NODE:
- case Node.DOCUMENT_FRAGMENT_NODE:
- case Node.NOTATION_NODE:
- default:
- }
-
- var child = xmlNode.firstChild;
- while(child) {
- outputText += prettyIndent(child, indentation + 1);
- child = child.nextSibling;
- }
-
- switch(xmlNode.nodeType) {
- case Node.ELEMENT_NODE:
- if (xmlNode.hasChildNodes()) {
- outputText += indenter;
- outputText += '&lt;/' + xmlNode.nodeName;
- outputText += '&gt;';
- outputText += '<br />';
- }
- break;
- default:
- }
-
- if (isActive) {
- outputText += '</span>';
- }
- if (isXPathSelected) {
- outputText += '</span>';
- }
-
- return outputText;
- }
-
- if (typeof this.xmlNode == "string") {
- this.xmlNode = $.parseXML(this.xmlNode);
- }
-
- // this.xpath = "//*[local-name() = \"state\"][@id=\"s0\"]/*[local-name() = \"onentry\"][1]/*[local-name() = \"foreach\"][1]";
- // this.xpath = "//*[local-name() = \"state\"][@id=\"s0\"]/*[local-name() = \"onentry\"][1]/*[local-name() = \"foreach\"][1]";
- var xpathNodeSet = undefined;
-
- // console.log("xpath:");
- // console.log(this.xpath);
-
- if (this.xpath) {
- try {
- xpathNodeSet = this.xmlNode.evaluate(
- this.xpath,
- this.xmlNode,
- function (prefix) {
- switch (prefix) {
- case 'scxml':
- default:
- return 'http://www.w3.org/2005/07/scxml';
- }
- return null;
- },
- XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,
- null);
- for (var i = 0; i < xpathNodeSet.snapshotLength; i++) {
- var currNode = xpathNodeSet.snapshotItem(i);
- // console.log("Got node:");
- // console.log(currNode);
- }
-
- } catch(e) {
- console.log(e);
- }
- }
-
-
- var xmlMarkup = '<font color=#888>' + prettyIndent(this.xmlNode, 0) + '</font>';
-
-
- if (destNode) {
- $(destNode).html(xmlMarkup);
- } else {
- $(this.destNode).html(xmlMarkup);
- }
- },
-
- setDestinationNode: function(destNode) {
- this.destNode = destNode;
- },
-
- setXML: function(xmlNode) {
- this.xmlNode = xmlNode;
- },
-
- setElementXPath: function(xpath) {
- this.xpath = xpath;
- },
-
- setActiveStates: function(states) {
- this.activeStates = states;
- },
- });
-
- // base class of all views onto a state
- SCXMLEditor.StateView = Base.extend({
- constructor: function(params) {
- $.extend(this, params);
- this.scxmlStateType = SCXMLEditor.getStateType(this.scxmlState);
- this.scxmlStateId = SCXMLEditor.getStateId(this.scxmlState);
-
- $(this.scxmlState).bind("DOMSubtreeModified", this.scxmlStateSubtreeModified)
- },
-
- node: undefined,
- scxmlStateType: undefined,
- scxmlStateId: undefined,
- scxmlState: undefined,
-
- getNode: function() {
- console.log("SCXMLEditor.StateView.getNode()");
- },
-
- scxmlStateSubtreeModified: function() {
- console.log("SCXMLEditor.StateView.scxmlStateSubtreeModified()");
- },
-
- isRoot: function() {
- return $(this.scxmlState).prop("tagName").toLowerCase() === "scxml";
- },
-
- getDirectChildStates: function() {
- return $(this.scxmlState).children("state, parallel, final, history").not(".nested");
- },
-
- getAllChildStates: function() {
- return $(this.scxmlState).find("state, parallel, final, history").not(".nested");
- },
-
- createTransitions: function() {
-
- }
- });
-
- // view a state in a small windowlet
- SCXMLEditor.ToolsStateView = SCXMLEditor.StateView.extend({
- constructor: function(params) {
- this.base(params);
- },
-
- getNode: function() {
-
- var tools = this;
-
- this.node = document.createElement('div');
- this.node.className = 'windowlet tools ui-widget-content';
- this.node.innerHTML = '\
- <div class="ui-widget-header">' + this.getStateId() + '<span class="ui-icon ui-icon-close"></span></div>\
- ';
-
- $(this.node).children( ".ui-widget-header" ).children( ".ui-icon-close" ).click(function() {
- $(tools.node).remove();
- });
-
- $(this.node).resizable();
- $(this.node).draggable();
- $(this.node).css("position", "absolute");
- $(this.node).appendTo(this.containerNode);
-
- return this.node;
- },
-
- scxmlStateSubtreeModified: function() {
- console.log("SCXMLEditor.StateView.scxmlStateSubtreeModified()");
- },
-
- });
-
- SCXMLEditor.PortletStateView = SCXMLEditor.StateView.extend({
- constructor: function(params) {
- this.base(params);
- },
-
- getNode: function() {
-
- this.node = document.createElement('div');
- this.node.className = 'portlet';
-
- this.node.innerHTML = '\
- <div class="portlet-header"><span class="stateId">' + this.scxmlStateId + '</span></div>\
- <div class="portlet-content"></div>\
- ';
-
- this.portletHeader = $(this.node).children("div.portlet-header")[0];
- this.portletContent = $(this.node).children("div.portlet-content")[0];
-
- var scxmlState = this.scxmlState;
-
- var settingsButton = document.createElement('button');
- settingsButton.innerHTML = 'Settings';
- $(settingsButton).button({
- icons: {
- primary: "ui-icon-gear",
- secondary: "ui-icon-triangle-1-s"
- },
- text: false
- });
-
- var settingsMenu = document.createElement('ul');
- settingsMenu.innerHTML = '\
- <li><a href="#"><span class="ui-icon ui-icon-plus"></span>Add nested State</a></li>\
- <li><a href="#"><span class="ui-icon ui-icon-arrow-4-diag"></span>Move this State</a></li>\
- <li><a href="#"><span class="ui-icon ui-icon-trash"></span>Remove this State</a></li>\
- <li>-</li>\
- <li><a href="#"><span class="ui-icon ui-icon-transfer-e-w"></span>Transitions</a></li>\
- <li><a href="#"><span class="ui-icon ui-icon-gear"></span>Executable Content</a></li>\
- <li><a href="#"><span class="ui-icon ui-icon-tag"></span>Datamodel</a></li>\
- <li><a href="#"><span class="ui-icon ui-icon-document"></span>Invokers</a></li>\
- <li><a href="#"><span class="ui-icon ui-icon-zoomin"></span>States</a></li>\
- ';
-
- $(settingsMenu).menu().hide();
-
- $(settingsButton).click(function() {
- $(settingsMenu).show().position({
- my: "left top",
- at: "left top",
- of: this
- });
- $(settingsMenu).find("a").click(function event() {
- $(settingsMenu).hide();
- });
- $(settingsMenu).mouseleave(function(event) {
- $(settingsMenu).hide();
- });
- return false;
- })
-
- $(settingsMenu).prependTo(this.portletHeader);
- $(settingsButton).prependTo(this.portletHeader);
-
- var childs = this.getDirectChildStates();
- var nrChilds = childs.length + 1;
-
- var nrCols = Math.ceil(Math.sqrt(nrChilds));
- var nrRows = Math.ceil(nrChilds / nrCols);
-
- // console.log(nrCols + ' / ' + nrRows);
- for (var col = 0; col < nrCols; col++) {
- var colNode = document.createElement('div');
- colNode.className = "column";
-
- for (var row = 0; row < nrRows; row++) {
- if (childs.length > col * nrRows + row) {
- var child = childs[col * nrRows + row];
- var childPortlet = new SCXMLEditor.PortletStateView({
- scxmlState: child,
- scxmlEditor: this.scxmlEditor
- });
- $(childPortlet.getNode()).appendTo(colNode);
- }
- }
- $(colNode).appendTo(this.portletContent);
-
- $(colNode).sortable({
- connectWith: ".column",
- handle: ".portlet-header",
- cancel: ".portlet-toggle",
- placeholder: "portlet-placeholder ui-corner-all"
- });
- }
-
- // see https://api.jqueryui.com/theming/icons/
- $(this.node)
- .addClass( "ui-widget ui-widget-content ui-helper-clearfix ui-corner-all" )
- .children( ".portlet-header" )
- .addClass( "ui-widget-header ui-corner-all" )
- .prepend( "<span class='ui-icon ui-icon-minusthick portlet-toggle'></span>")
- .prepend( "<span class='ui-icon ui-icon-newwin portlet-detach'></span>")
- .append( "&nbsp;&nbsp;&nbsp;");
-
- $(this.node).children( ".portlet-header" ).children( ".portlet-toggle" ).click(function() {
- var icon = $(this);
- icon.toggleClass( "ui-icon-minusthick ui-icon-plusthick" );
- icon.closest( ".portlet" ).children( ".portlet-content" ).toggle();
- });
-
- $(this.node).children( ".portlet-header" ).children( ".portlet-detach" ).click(function() {
- var detach = $(this);
- detach.toggleClass( "ui-icon-arrowthickstop-1-s ui-icon-newwin" );
- this.tools = new SCXMLEditor.ToolsStateView({
- scxmlState: scxmlState,
- scxmlEditor: this.scxmlEditor
- });
- $(this.tools.getNode()).appendTo($("body")); // TODO ought to be relative?
- });
- return this.node;
-
- },
- })
-
- SCXMLEditor.Debugger = Base.extend({
- constructor: function(params) {
- this.breakpointsEnabled = true;
- $.extend(this, params);
- },
-
- breakpoints: [],
- currEvent: {},
-
- loadDOM: function(scxmlDOM) {
- // called by the editor, inherit to e.g. activate buttons
- },
-
- getNode: function() {
-
- var debug = this;
- this.node = document.createElement('div');
- this.node.className = 'windowlet debug';
- $(this.node).css("position", "absolute");
-
- // data-parent="#accordion" missing from <a> to show multiple panels
- this.node.innerHTML = '\
- <div class="panel panel-default">\
- <div class="panel-heading debug-header">\
- <h4 class="panel-title">Debugger<span class="toolbar pull-right"></span></h4>\
- <!--span class="subtitle document-name">No Document loaded</span -->\
- </div>\
- <div class="panel-group">\
-<!-- Breakpoints -->\
- <div class="breakpoints panel panel-default">\
- <div class="panel-heading" data-toggle="collapse" data-target="#collapseBreakpoints">\
- <span class="panel-toggle"></span>\
- <h4 class="panel-title">Breakpoints<br/><span class="subtitle current-breakpoint"></span>\
- <i class="heading-decoration pull-right">\
- <div class="btn-group">\
- <button title="Deactivate all Breakpoints" class="deactivate btn btn-default btn-xs btn-primary"><span class="glyphicon glyphicon-off"></span></button>\
- </div>\
- <div class="btn-group">\
- <button title="Add a new Breakpoint" class="new btn btn-default btn-xs"><span class="glyphicon glyphicon-plus"></span></button>\
- <button \
- title="Remove all Breakpoints" class="delete-all btn btn-default btn-xs"><span class="glyphicon glyphicon-remove"></span></button>\
- </div>\
- </i>\
- </h4>\
- </div>\
- <div id="collapseBreakpoints" class="breakpoints-content panel-collapse collapse">\
- </div>\
- </div>\
-<!-- Current Event -->\
- <!--div class="event panel panel-default">\
- <div class="panel-heading" data-toggle="collapse" data-target="#collapseEvent">\
- <h4 class="panel-title">Current Event\
- <i class="heading-decoration pull-right">\
- <div class="btn-group">\
- <button title="Insert a new Event" class="new btn btn-default btn-xs"><span class="glyphicon glyphicon-plus"></span></button>\
- <button title="Edit current Event" class="edit btn btn-default btn-xs"><span class="glyphicon glyphicon-pencil"></span></button>\
- <button title="View Event in Window" class="view btn btn-default btn-xs"><span class="glyphicon glyphicon-search"></span></button>\
- </div>\
- </i>\
- <span class="panel-toggle"></span></h4>\
- </div>\
- <div id="collapseEvent" class="panel-collapse collapse">\
- <div class="panel-body event-content"></div>\
- </div>\
- </div-->\
-<!-- Active States -->\
- <!-- div class="states panel panel-default">\
- <div class="panel-heading" data-toggle="collapse" data-target="#collapseStates">\
- <h4 class="panel-title">Active States<span class="panel-toggle"></span></h4>\
- </div>\
- <div id="collapseStates" class="panel-collapse collapse">\
- <div class="panel-body states-content">\
- Anim pariatur cliche reprehenderit, enim eiusmod high life\
- </div>\
- </div>\
- </div -->\
-<!-- Datamodel -->\
- <div class="datamodel panel panel-default">\
- <div class="panel-heading" data-toggle="collapse" data-target="#collapseDatamodel">\
- <h4 class="panel-title">Datamodel\
- <!--i class="heading-decoration pull-right">\
- <div class="btn-group">\
- <button title="Clear Log" class="clear btn btn-default btn-xs"><span class="glyphicon glyphicon-trash"></span></button>\
- <button title="View Log in Window" class="view btn btn-default btn-xs"><span class="glyphicon glyphicon-search"></span></button>\
- </div>\
- </i-->\
- <span class="panel-toggle"></span></h4>\
- </div>\
- <div id="collapseDatamodel" class="panel-collapse collapse">\
- <div class="panel-body datamodel-content"></div>\
- </div>\
- </div>\
-<!-- Assets -->\
- <!--div class="assets panel panel-default">\
- <div class="panel-heading" data-toggle="collapse" data-target="#collapseAssets">\
- <h4 class="panel-title">Assets\
- <i class="heading-decoration pull-right">\
- <div class="btn-group">\
- <button title="New Asset" class="view btn btn-default btn-xs"><span class="glyphicon glyphicon-plus"></span></button>\
- </div>\
- </i>\
- <span class="panel-toggle"></span></h4>\
- </div>\
- <div id="collapseAssets" class="panel-collapse collapse">\
- <div class="panel-body assets-content"></div>\
- </div>\
- </div-->\
-<!-- Message -->\
- <div class="messages panel panel-default">\
- <div class="panel-heading" data-toggle="collapse" data-target="#collapseMessages">\
- <h4 class="panel-title">Messages\
- <i class="heading-decoration pull-right">\
- <span class="badge"></span>\
- <div class="btn-group">\
- <button title="Clear Log" class="clear btn btn-default btn-xs"><span class="glyphicon glyphicon-trash"></span></button>\
- <button title="Text Wrap" class="textwrap btn btn-default btn-xs"><span class="glyphicon glyphicon-align-left"></span></button>\
- </div>\
- </i>\
- <span class="panel-toggle"></span></h4>\
- </div>\
- <div id="collapseMessages" class="panel-collapse collapse in">\
- <div class="panel-body messages-content">\
- <textarea class="form-control messages" wrap="off" readonly></textarea>\
- </div>\
- </div>\
- </div>\
- </div>\
- <div class="panel-footer">\
- <span class="status-indicators"></span>\
- <span class="pull-right document-name"></span>\
- </div>\
- </div>\
- ';
-
- $(this.node).find("div.panel-collapse").not(".in").prev().addClass("collapsed");
-
-
- // get some nodes
- this.debugFooterNode = $(this.node).find(".panel-footer")[0];
- this.statusIndicatorNode = $(this.node).find(".status-indicators")[0];
- this.debugDocumentNameNode = $(this.node).find(".document-name")[0];
- this.currentBreakpointNode = $(this.node).find(".current-breakpoint")[0];
- this.toolbarNode = $(this.node).find(".toolbar")[0];
-
- this.messagesNode = $(this.node).find("div.messages-content")[0];
- this.messagesBadgeNode = $(this.node).find("div.messages").find("span.badge")[0];
- this.clearMessagesButton = $(this.node).find("div.messages").find("button.clear")[0];
- this.textwrapMessagesButton = $(this.node).find("div.messages").find("button.textwrap")[0];
- this.messagesTextarea = $(this.node).find("div.messages-content").find("textarea")[0];
-
- this.breakpointNode = $(this.node).find("div.breakpoints-content")[0];
- this.deleteAllBreakpointsButton = $(this.node).find("div.breakpoints").find("button.delete-all")[0];
- this.disableBreakpointsButton = $(this.node).find("div.breakpoints").find("button.deactivate")[0];
- this.addNewBreakpointsButton = $(this.node).find("div.breakpoints").find("button.new")[0];
-
- this.currEventNode = $(this.node).find("div.event-content")[0];
- this.insertEventButton = $(this.node).find("div.event").find("button.new")[0];
- this.editEventButton = $(this.node).find("div.event").find("button.edit")[0];
- this.viewEventButton = $(this.node).find("div.event").find("button.view")[0];
-
- this.dataModelNode = $(this.node).find("div.datamodel-content")[0];
- this.clearDataModelLogButton = $(this.node).find("div.datamodel").find("button.clear")[0];
- this.viewDataModelLogButton = $(this.node).find("div.datamodel").find("button.view")[0];
-
- this.initBreakpoints();
- this.initToolBar();
-// this.initCurrEvent();
- this.initDataModel();
- this.initMessages();
-
- // enable tooltips
- $(this.node).find("button").tooltip({
- placement: 'bottom',
- container: 'body',
- delay: { show: 300, hide: 100 }
- });
-
- $(this.node).resizable({grid: [1, 100000]});
- $(this.node).draggable({
- handle: $(this.node).find("div.debug-header")
- });
-
- return this.node;
- },
-
- initMessages: function() {
- var debug = this;
-
- $(this.clearMessagesButton).prop('disabled', true);
-
- $(this.node).find('#collapseMessages')
- .unbind('show.bs.collapse')
- .unbind('shown.bs.collapse')
- .on('show.bs.collapse', function () {
- $(debug.messagesBadgeNode).html(""); // remove number from badge
- }).on('shown.bs.collapse', function () {
- debug.messagesTextarea.scrollTop = debug.messagesTextarea.scrollHeight; // scroll to bottom (won't work when hidden)
- });
-
- $(this.messagesTextarea)
- .unbind('mouseenter')
- .unbind('mouseleave')
- .mouseenter(function () {
- $(this).addClass("dont-scroll");
- })
- .mouseleave(function () {
- $(this).removeClass("dont-scroll");
- });
-
- $(this.clearMessagesButton)
- .unbind('mouseenter')
- .unbind('mouseleave')
- .unbind('click')
- .mouseenter(function() {
- $(this).addClass("btn-warning");
- }).mouseleave(function() {
- $(this).removeClass("btn-warning");
- }).click(function() {
- debug.messagesTextarea.value = "";
- $(debug.messagesBadgeNode).html("");
- $(this).prop('disabled', true);
- $(this).removeClass("btn-warning");
- $(this).tooltip("hide");
- return false;
- });
-
- $(this.textwrapMessagesButton).unbind('click')
- .click(function() {
- if ($(debug.messagesTextarea).attr("wrap") == "on") {
- $(this).removeClass("active");
- $(debug.messagesTextarea).attr("wrap", "off");
- } else {
- $(this).addClass("active");
- $(debug.messagesTextarea).attr("wrap", "on");
- }
- return false;
- });
-
-
- },
-
- initToolBar: function() {
- var debug = this;
-
- this.toolbarNode.innerHTML = '\
- <div class="btn-group">\
- <button class="control btn btn-default btn-xs dropdown-toggle" data-toggle="dropdown">\
- <span class="glyphicon glyphicon-cog"></span>\
- <span class="caret"></span>\
- </button>\
- <ul class="dropdown-menu">\
- <li><a class="load-from-url" href="#"><i class="glyphicon glyphicon-import"></i> Load Document</a></li>\
- <li><a class="save-breakpoints" href="#"><i class="glyphicon glyphicon-floppy-save"></i> Save Breakpoints</a></li>\
- </ul>\
- </div>\
- <div class="btn-group">\
- <button title="Start Execution" class="start btn btn-default btn-xs"><span class="glyphicon glyphicon-play"></span></button>\
- <div class="btn-group" data-toggle="buttons-checkbox">\
- <button title="Pause Execution" class="pause btn btn-default btn-xs"><span class="glyphicon glyphicon-pause"></span></button>\
- </div>\
- <button title="Step Execution" class="step btn btn-default btn-xs"><span class="glyphicon glyphicon-step-forward"></span></button>\
- </div>\
- '
- this.controlButtonNode = $(this.toolbarNode).children("div.btn-group").children("button.control")[0];
- this.controlDropdownNode = $(this.toolbarNode).children("div.btn-group").children("ul.dropdown-menu")[0];
- this.loadFromURLNode = $(this.toolbarNode).find("a.load-from-url")[0];
- this.saveBreakpointsNode = $(this.toolbarNode).find("a.save-breakpoints")[0];
- this.startButtonNode = $(this.toolbarNode).children("div.btn-group").children("button.start")[0];
- this.pauseButtonNode = $(this.toolbarNode).children("div.btn-group").find("button.pause")[0];
- this.stepButtonNode = $(this.toolbarNode).children("div.btn-group").children("button.step")[0];
- this.globalDropDownNode = $(this.toolbarNode).find(".dropdown-menu")[0];
-
- $(this.loadFromURLNode).unbind('click').click(function() {
- debug.showLoadDialog();
- return false;
- });
-
- $(this.saveBreakpointsNode)
- .unbind('click').click(function() {
- debug.recentDocuments[debug.scxmlEditor.scxmlURL].breakpoints = [];
- for (var key in debug.breakpoints) {
- debug.recentDocuments[debug.scxmlEditor.scxmlURL].breakpoints.push(debug.breakpoints[key].toWireFormat());
- }
- localStorage.recentDocuments = JSON.stringify(debug.recentDocuments);
- $(debug.controlButtonNode).effect('highlight', {color: '#3AA453'}, 600);
- return false;
- })
- .closest("li").addClass("disabled");
-
-
- $(this.startButtonNode).prop('disabled', true);
- $(this.pauseButtonNode).prop('disabled', true);
- $(this.stepButtonNode).prop('disabled', true);
-
- },
-
- showLoadDialog: function() {
- var debug = this;
-
- // do we already have a modal div?
- $("body").children("div#loadFromURLModal").remove();
-
- // load from URL form - modal window
- this.loadFromURLModalNode = $('\
- <div class="modal fade" id="loadFromURLModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">\
- <div class="modal-dialog">\
- <form action="" id="loadFromURLModalForm">\
- <div class="modal-content">\
- <div class="modal-header">\
- <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>\
- <h4 class="modal-title" id="myModalLabel">Load SCXML from URL</h4>\
- </div>\
- <div class="modal-body">\
- <div class="form-group">\
- <div class="input-group">\
- <span class="input-group-btn">\
- <button title="Recent Documents" type="button" class="btn dropdown-toggle" data-toggle="dropdown">\
- <span class="glyphicon glyphicon-list-alt"></span>\
- </button>\
- <ul class="recent-documents dropdown-menu" role="menu" />\
- </span>\
- <input id="loadFromURLModalInput" name="scxmlUrl" class="form-control" placeholder="URL of SCXML document">\
- </div>\
- </div>\
- </div>\
- <div class="modal-footer">\
- <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>\
- <button type="submit" class="btn btn-primary">Load</button>\
- </div>\
- </div>\
- </form>\
- </div>\
- </div>\
- ');
-
- this.recentDocumentsNode = $(this.loadFromURLModalNode).find("ul.recent-documents")[0];
- $(this.recentDocumentsNode).prev().attr('disabled', true);
-
- this.recentDocuments = {};
- if (localStorage.recentDocuments) {
- this.recentDocuments = JSON.parse(localStorage.recentDocuments);
- for (var key in this.recentDocuments) {
- if ((key.substring(0, 4) != "http") && (key.substring(0, 4) != "file")) {
- // no idea, but it's not a document
- delete this.recentDocuments[key];
- continue;
- }
- var recentURL = key; // not sure, but key is not available in callback
- // we found a document, enable "recent" button
- $(this.recentDocumentsNode).prev().attr('disabled', false);
-
- console.log(recentURL);
-
- var recentDocumentItem = $('\
- <li><a href="#"><!-- i class="glyphicon glyphicon-floppy-open" style="margin-right: 0.7em" / -->' + key + '<span class="recent-document-features"></span></a></li>\
- ');
- var recentDocumentFeatures = $(recentDocumentItem).find("span.recent-document-features");
- $(recentDocumentItem).children("a").unbind('click').click(function() {
- console.log("recentURL: " + recentURL);
- $(debug.loadFromURLModalNode).find("input#loadFromURLModalInput").val(recentURL);
- $(debug.recentDocumentsNode).dropdown("toggle");
- return false;
- });
- if ('breakpoints' in this.recentDocuments[key] && this.recentDocuments[key].breakpoints.length > 0) {
- $(recentDocumentFeatures).append('<i title="Has Breakpoints" class="glyphicon glyphicon-th-list">');
- }
-
- $(this.recentDocumentsNode).append(recentDocumentItem);
- }
- }
-
- $("body").append(this.loadFromURLModalNode);
-
- var fromURLValidator = $(this.loadFromURLModalNode).find("form#loadFromURLModalForm").validate({ // initialize the plugin
- rules: { scxmlUrl: { required: true, url2: true }},
- highlight: function(element) {
- $(element).closest('.form-group').removeClass('has-success').addClass('has-error');
- },
- success: function(element) {
- element.text('OK!').addClass('valid').closest('.input-group').removeClass('has-error').addClass('has-success');
- },
- submitHandler: function (form) {
- $(debug.loadFromURLModalNode).modal("hide");
- return true;
- }
- });
-
- $(this.loadFromURLModalNode).on('hide.bs.modal', function(e) {
- if (!fromURLValidator.valid()) {
- $(debug.loadFromURLModalNode).find(".form-group").removeClass('has-success').removeClass('has-error');
- $(debug.loadFromURLModalNode).find("input#loadFromURLModalInput").val("");
- } else {
- var scxmlURL = $(debug.loadFromURLModalNode).find("input#loadFromURLModalInput").val();
- if (!(scxmlURL in debug.recentDocuments)) {
- debug.recentDocuments[scxmlURL] = {};
- }
- localStorage.recentDocuments = JSON.stringify(debug.recentDocuments);
- debug.scxmlEditor.loadURL(scxmlURL);
- }
- fromURLValidator.resetForm();
- });
-
- $(this.loadFromURLModalNode).modal();
-
- },
-
- initDataModel: function() {
- var debug = this;
-
- $(this.clearDataModelLogButton).prop('disabled', true);
- $(this.viewDataModelLogButton).prop('disabled', true);
-
- // add functionality to buttons
- $(this.clearDataModelLogButton).mouseenter(function() {
- $(this).addClass("btn-warning");
- }).mouseleave(function() {
- $(this).removeClass("btn-warning");
- }).click(function() {
-
- return false;
- });
-
- this.dataModelListingNode = document.createElement('div');
-
- this.dataModelEditor = ace.edit(this.dataModelListingNode, {});
- this.dataModelEditor.getSession().setUseWorker(false);
- this.dataModelListingNode.style.fontSize='10px';
- this.dataModelEditor.setTheme("ace/theme/tomorrow");
- this.dataModelEditor.getSession().setMode("ace/mode/javascript");
- this.dataModelEditor.setReadOnly(true);
- // this.dataModelEditor.getSession().setUseWrapMode(true);
- this.dataModelEditor.setShowPrintMargin(false);
- this.dataModelEditor.renderer.setShowGutter(false);
- // this.dataModelEditor.getSession().setValue(vkbeautify.json(initialContent));
- $(this.dataModelListingNode).css("height", ((this.dataModelEditor.session.getLength() + 10) * 1.5) + "em");
-
- $(this.dataModelNode).append(this.dataModelListingNode);
- $(this.dataModelNode).append('\
- <div class="input-group input-group-sm">\
- <span class="input-group-btn">\
- <button title="Quick Command" type="button" class="datamodel-suggest btn dropdown-toggle" data-toggle="dropdown">\
- <span class="glyphicon glyphicon-list-alt"></span>\
- </button>\
- <ul class="suggested-commands dropdown-menu" role="menu">\
- <li><a href="#">_event</a></li>\
- <li><a href="#">_name</a></li>\
- <li><a href="#">_sessionid</a></li>\
- <li><a href="#">_invokers</a></li>\
- <li><a href="#">_ioprocessors</a></li>\
- <li><a href="#">_x</a></li>\
- </ul>\
- </span>\
- <input type="text" class="datamodel-eval form-control">\
- <div class="input-group-btn">\
- <button title="Evaluate as String" type="button" class="datamodel-eval btn btn-default"><span class="glyphicon glyphicon-play"></span></button>\
- </div>\
- </div>\
- ');
-
- this.dataModelInputNode = $(this.dataModelNode).find("input.datamodel-eval")[0];
- this.dataModelInputButton = $(this.dataModelNode).find("button.datamodel-eval")[0];
- this.dataModelSuggestButton = $(this.dataModelNode).find("button.datamodel-suggest")[0];
-
- $(this.dataModelSuggestButton).prop('disabled', true);
-
- $(this.dataModelNode).find("ul.suggested-commands").find("li")
- .unbind('click').click(function() {
- var expression = $(this).children("a").text();
- $(debug.dataModelInputNode).val(expression);
- debug.evalOnDataModel(expression);
- $(this).closest("ul").dropdown('toggle');
- return false;
- });
-
- $(this.dataModelInputNode)
- .prop('disabled', true)
- .unbind('keypress').keypress(function(e) {
- if (e.which == 13)
- debug.evalOnDataModel($(this).val());
- });
-
- $(this.dataModelInputButton)
- .prop('disabled', true)
- .unbind('click').click(function() {
- debug.evalOnDataModel($(debug.dataModelInputNode).val());
- return false;
- });
-
- // $(this.dataModelListingNode).resizable({handles: "n, s"});
- // $(this.dataModelListingNode).resizable({grid: [100000, 1], alsoResize: $(this.node)});
- // $(this.dataModelListingNode).unbind('resize').on('resize', function() {
- // debug.dataModelEditor.resize();
- // });
- },
-
- initBreakpoints: function() {
- var debug = this;
-
- $(this.deleteAllBreakpointsButton)
- .unbind('mouseenter')
- .unbind('mouseleave')
- .unbind('click');
- $(this.deleteAllBreakpointsButton).mouseenter(function() {
- $(this).addClass("btn-danger");
- }).mouseleave(function() {
- $(this).removeClass("btn-danger");
- }).click(function() {
- return false;
- });
-
- $(this.deleteAllBreakpointsButton).confirmation({
- singleton: true,
- container: "body",
- btnOkClass: "btn btn-danger",
- btnOkLabel: "Delete All",
- btnOkIcon: "glyphicon glyphicon-trash",
- onConfirm: function() {
- while (debug.breakpoints.length > 0) {
- debug.removeBreakpoint(debug.breakpoints[0]);
- }
- }
- });
-
- $(this.disableBreakpointsButton).unbind('click');
- $(this.disableBreakpointsButton).click(function() {
- $(this).toggleClass("btn-primary");
- if ($(this).hasClass("btn-primary")) {
- debug.enableAllBreakpoints();
- } else {
- debug.disableAllBreakpoints();
- }
- return false;
- });
-
- $(this.addNewBreakpointsButton).unbind('click');
- $(this.addNewBreakpointsButton).click(function() {
- debug.addBreakpoint();
- return false;
- });
-
- this.breakpointNode.innerHTML = '\
- <table class="table table-hover">\
- </table>\
- ';
-
- for (var index in this.breakpoints) {
- $(this.breakpointNode).children("table").append(this.breakpoints[index].getNode());
- }
- },
-
- initCurrEvent: function() {
- var debug = this;
-
- $(this.insertEventButton).prop('disabled', true);
- $(this.editEventButton).prop('disabled', true);
- $(this.viewEventButton).prop('disabled', true);
-
- var initialContent = '';
-
- var editor = ace.edit(this.currEventNode, {});
- editor.getSession().setUseWorker(false);
- this.currEventNode.style.fontSize='10px';
- editor.setTheme("ace/theme/tomorrow");
- editor.getSession().setMode("ace/mode/javascript");
- editor.setReadOnly(true);
- editor.setShowPrintMargin(false);
- editor.renderer.setShowGutter(false);
- try {
- editor.getSession().setValue(vkbeautify.json(initialContent));
- } catch(e) {
- editor.getSession().setValue(initialContent);
- }
- $(this.currEventNode).css("height", (editor.session.getLength() * 1.5) + "em");
-
- this.eventViewModal = $('\
- <div class="modal fade bs-example-modal-lg" id="eventViewModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">\
- <div class="modal-dialog modal-lg">\
- <form action="" id="eventViewModalForm">\
- <div class="modal-content">\
- <div class="modal-header">\
- <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>\
- <h4 class="modal-title" id="myModalLabel">View / Edit Event</h4>\
- </div>\
- <div class="modal-body">\
- <div class="editor"></div>\
- </div>\
- <div class="modal-footer">\
- <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>\
- <button type="submit" class="btn btn-primary">Apply</button>\
- </div>\
- </div>\
- </form>\
- </div>\
- </div>\
- ');
-
-
- $(this.eventViewModal).modal({
- show: false
- });
-
- // $(this.eventViewModal).find("div.modal-dialog").resizable();
- // $(this.eventViewModal).find("div.modal-dialog").draggable();
-
- $("body").append(this.eventViewModal);
-
- // add functionality to buttons
- $(this.viewEventButton).click(function() {
- $(debug.eventViewModal).find(".editor");
-
- var modalEditorNode = $(debug.eventViewModal).find(".editor")[0];
-
- var modalEditor = ace.edit(modalEditorNode, {});
- modalEditorNode.style.fontSize='10px';
- // safari has the cursor somewhat off
-// modalEditorNode.style.font='inherit!important';
- modalEditor.setTheme("ace/theme/tomorrow");
- modalEditor.getSession().setMode("ace/mode/javascript");
- modalEditor.setReadOnly(false);
- modalEditor.setShowPrintMargin(false);
- modalEditor.renderer.setShowGutter(true);
- modalEditor.getSession().setValue(vkbeautify.json(initialContent));
-
- $(modalEditorNode).css("min-height", (editor.session.getLength() * 1.5) + "em");
- //$(modalEditorNode).css("height", "80%");
-
- $(debug.eventViewModal).modal("show");
- return false;
- });
-
- },
-
- log: function(messages) {
- var self = this;
-
- $(this.clearMessagesButton).prop('disabled', false);
-
- if (!self.messagesTextarea) {
- console.log(messages);
- return;
- }
-
- function logSingleMsg(msg) {
- // only show badge when when collapsed
- if (!$(self.messagesNode).parent().hasClass("in")) {
- var bagdeContent = parseInt($(self.messagesBadgeNode).html()) || 0;
- $(self.messagesBadgeNode).html(bagdeContent + 1);
- }
-
- if (typeof(msg) === 'string') {
- self.messagesTextarea.value += msg.trim() + "\n";
- } else if (typeof(msg) === 'object') {
- if ('formatted' in msg) {
- self.messagesTextarea.value += msg.formatted.trim() + "\n";
- } else if('message' in msg) {
- self.messagesTextarea.value += msg.message.trim() + "\n";
- } else {
- try {
- self.messagesTextarea.value += vkbeautify.json(msg) + "\n";
- } catch(e) {
- self.messagesTextarea.value += JSON.stringify(msg).trim() + "\n";
- }
- }
- } else {
- //not sure what to do here
- self.messagesTextarea.value += msg;
- }
- }
-
- if (messages instanceof Array) {
- for (var key in messages) {
- logSingleMsg(messages[key]);
- }
- } else {
- logSingleMsg(messages);
- }
-
- // scroll to bottom
- if (!$(self.messagesTextarea).hasClass("dont-scroll"))
- self.messagesTextarea.scrollTop = self.messagesTextarea.scrollHeight;
- },
-
- // find a breakpoint by value and return its index
- findBreakpoint: function(breakpoint) {
- for (var index in this.breakpoints) {
- var currBreakpoint = this.breakpoints[index];
-
- // $("body").append("<pre>" + JSON.stringify(breakpoint.toWireFormat()) + "</pre><br />");
- // $("body").append("<pre>" + JSON.stringify(currBreakpoint.toWireFormat()) + "</pre><br />");
- if (Object.identical(breakpoint.toWireFormat(), currBreakpoint.toWireFormat())) {
- return index;
- }
- }
- return -1;
- },
-
- editBreakpoint: function(breakpoint) {
- breakpoint.showEditDialog()
- },
-
- editedBreakpoint: function(breakpoint, oldData) {
- // override to update your debugger
- },
-
- skipToBreakpoint: function(breakpoint) {
- },
-
- addBreakpoint: function(breakpoint) {
- var debug = this;
- if (breakpoint) {
- breakpoint.scxmlEditor = this.scxmlEditor;
- breakpoint.scxmlDebugger = this;
-
- if (this.findBreakpoint(breakpoint) < 0) {
- // add as new breakpoint
- this.breakpoints.push(breakpoint);
- var breakpointNode = breakpoint.getNode();
- if (!debug.breakpointsEnabled) {
- $(breakpointNode).find("button.enable").prop('disabled', true);
- $(breakpointNode).find("button.skipto").prop('disabled', true);
- }
- $(this.breakpointNode).children("table").append(breakpointNode);
- }
- } else {
- // show dialog to add a breakpoint
- var newBreakpoint = new SCXMLEditor.Debugger.Breakpoint({
- scxmlEditor: this.scxmlEditor,
- scxmlDebugger: this
- });
- debug.editBreakpoint(newBreakpoint);
- }
- },
-
- removeBreakpoint: function(breakpoint) {
- var debug = this;
- var breakPointIndex = this.findBreakpoint(breakpoint);
- if (breakPointIndex >= 0) {
- this.breakpoints.splice(breakPointIndex, 1);
- $(this.breakpointNode).children("table").find("tr").slice(breakPointIndex, breakPointIndex + 1).detach();
- }
- },
-
- highlightBreakpoint: function(breakpoint) {
- var breakPointIndex = this.findBreakpoint(breakpoint);
- if (breakPointIndex < 0)
- return;
-
- // open breakpoint collapsible
- $(this.node).find("div.breakpoints").find("div.panel-collapse").addClass("in");
-
- // highlight breakpoint
- $(this.breakpointNode)
- .children("table")
- .find("tr").slice(breakPointIndex, breakPointIndex + 1)
- .addClass("info");
-
- },
-
- unhighlightAllBreakpoints: function() {
- $(this.breakpointNode)
- .children("table")
- .find("tr").removeClass("info");
- },
-
- enableBreakpoint: function(breakpoint) {
- var breakPointIndex = this.findBreakpoint(breakpoint);
- if (breakPointIndex < 0)
- return;
-
- $(this.breakpointNode)
- .children("table")
- .find("tr").slice(breakPointIndex, breakPointIndex + 1)
- .find("button.enable").addClass('btn-primary');
-
- $(this.breakpointNode)
- .children("table")
- .find("tr").slice(breakPointIndex, breakPointIndex + 1)
- .find("button.skipto")
- .prop('disabled', false);
-
- },
-
- disableBreakpoint: function(breakpoint) {
- var breakPointIndex = this.findBreakpoint(breakpoint);
- if (breakPointIndex < 0)
- return;
-
- $(this.breakpointNode)
- .children("table")
- .find("tr").slice(breakPointIndex, breakPointIndex + 1)
- .find("button.enable").removeClass('btn-primary');
-
- $(this.breakpointNode)
- .children("table")
- .find("tr").slice(breakPointIndex, breakPointIndex + 1)
- .find("button.skipto")
- .prop('disabled', true);
- },
-
- disableAllBreakpoints: function() {
- this.breakpointsEnabled = false;
- $(this.breakpointNode).find("button.enable").prop('disabled', true);
- $(this.breakpointNode).find("button.skipto").prop('disabled', true);
- },
-
- enableAllBreakpoints: function() {
- this.breakpointsEnabled = true;
-
- $(this.breakpointNode).find("button.enable").each(function() {
- $(this).prop('disabled', false);
- if ($(this).hasClass("btn-primary")) {
- $(this).parent().children("button.skipto").prop('disabled', false);
- }
- });
- },
-
- evalOnDataModel: function() {
- },
-
- attachDebug: function(sessionId) {
- },
-
- prepareDebug: function() {
- this.scxmlText = SCXMLEditor.xmlToString(this.scxmlEditor.scxmlDOM);
- },
-
- startDebug: function() {
- this.unhighlightAllBreakpoints();
- },
-
- stopDebug: function() {
- this.unhighlightAllBreakpoints();
- },
-
- stepDebug: function() {
- this.unhighlightAllBreakpoints();
- },
-
- });
-
-
- SCXMLEditor.Debugger.Breakpoint = Base.extend({
- constructor: function(params) {
- $.extend(this, params);
- this.seqNr = SCXMLEditor.Debugger.Breakpoint.seqNr++;
- },
-
- data: {}, // all data describing this breakpoint
- editNodes: {}, // html nodes of form-groups during editing - needed to retain input - TODO
-
- breakpointTypes: {
- "categories": [
- { id: "state", label: "States" },
- { id: "event", label: "Events" },
- { id: "transition", label: "Transitions" },
- { id: "executable", label: "Executable Content" },
- { id: "invoke", label: "Invokers" },
- { id: "configuration", label: "Configuration" },
- ],
- "types": [
- { id: "state-before-enter",
- label: "Before Entering State", category: "state",
- hint: "Stop execution <b>before</b> a given state is <b>entered</b>."
- },
- { id: "state-after-enter",
- label: "After Entering State", category: "state",
- hint: "Stops execution <b>after</b> a given state is <b>entered</b>."
- },
- { id: "state-before-exit",
- label: "Before Exiting State", category: "state",
- hint: "Stops execution <b>before</b> a given state was <b>exited</b>."
- },
- { id: "state-after-exit",
- label: "After Exiting State", category: "state",
- hint: "Stops execution <b>after</b> a given state was <b>exited</b>."
- },
- { id: "event-before",
- label: "Before Processing Event", category: "event",
- hint: "Stops execution <b>before</b> a given event is processed."
- },
- { id: "transition-before",
- label: "Before Taking Transition", category: "transition",
- hint: "Stops execution <b>before</b> a given transition is taken."
- },
- { id: "transition-after",
- label: "After Taking Transition", category: "transition",
- hint: "Stops execution <b>after</b> a given transition was taken."
- },
- { id: "invoker-before-invoke",
- label: "Before Starting Invoker", category: "invoke",
- hint: "Stop execution <b>before</b> an invoker is <b>started</b>."
- },
- { id: "invoker-after-invoke",
- label: "After Starting Invoker", category: "invoke",
- hint: "Stops execution <b>after</b> an invoker is <b>started</b>."
- },
- { id: "invoker-before-cancel",
- label: "Before Cancelling Invoker", category: "invoke",
- hint: "Stop execution <b>before</b> an invoker is <b>cancelled</b>."
- },
- { id: "invoker-after-cancel",
- label: "After Cancelling Invoker", category: "invoke",
- hint: "Stops execution <b>after</b> an invoker is <b>cancelled</b>."
- },
- { id: "executable-before",
- label: "Before Executing Content", category: "executable",
- hint: "Stops <b>before</b> executing content."
- },
- { id: "executable-after",
- label: "After Executing Content", category: "executable",
- hint: "Stops <b>after</b> executing content."
- },
- { id: "microstep-before",
- label: "Before Microstep", category: "configuration",
- hint: "Stops execution <b>before</b> processing a microstep."
- },
- { id: "microstep-after",
- label: "After Microstep", category: "configuration",
- hint: "Stops execution <b>after</b> after a microstep was processed."
- },
- { id: "stable-on",
- label: "On Stable Configuration", category: "configuration",
- hint: "Stops execution when the interpreter reached a stable configuration and waits for events."
- }
- ]
- },
-
- isEnabled: function() {
- return true;
- },
-
- toWireFormat: function() {
- var jsonData = jQuery.extend(true, {}, this.data);
-
- if ('breakpointType' in this.data) {
- var typeComponents = this.data.breakpointType.split("-");
- jsonData.subject = typeComponents[0];
- jsonData.when = typeComponents[1];
- if (typeComponents.length > 2) {
- jsonData.action = typeComponents[2];
- } else {
- delete jsonData.action;
- }
- }
- delete jsonData.breakpointType;
-
- return jsonData;
- },
-
- showEditDialog: function() {
- var breakpoint = this;
-
- // do we already have a modal div?
- $("body").children("div#editBreakpointModal").remove();
-
- this.editModalNode = $('\
- <div class="modal fade" id="editBreakpointModal" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">\
- <div class="modal-dialog">\
- <form action="" class="form-horizontal" role="form">\
- <div class="modal-content">\
- <div class="modal-header">\
- <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>\
- <h4 class="modal-title" id="myModalLabel"></h4>\
- </div>\
- <div class="modal-body">\
- <div class="form-group">\
- <label for="breakpointType" class="col-sm-2 control-label">Type</label>\
- <div class="col-sm-10 type-select"></div>\
- </div>\
- <div class="col-sm-2"></div><div class="col-sm-10 alert alert-info"></div>\
- </div>\
- <div class="modal-footer">\
- <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>\
- <button type="submit" class="btn btn-primary">Apply</button>\
- </div>\
- </div>\
- </form>\
- </div>\
- </div>\
- ');
-
- $(this.editModalNode).find("div.modal-body").find("div.type-select").append(this._typeSelectNode());
- $("body").append(this.editModalNode);
-
- this.editTypeInfoNode = $(this.editModalNode).find("div.alert-info")[0];
- this.editTypeNode = $(this.editModalNode).find("div.modal-body")[0];
-
- var stateNames = this.scxmlEditor.getAllStateIds();
-
- var editTypeSelectNode = $(this.editTypeNode).find("div.type-select").children("select");
- if ('breakpointType' in this.data) {
- $(editTypeSelectNode).val(this.data.breakpointType);
- $(this.editModalNode).find("h4.modal-title").text("Edit Breakpoint");
- } else {
- $(this.editModalNode).find("h4.modal-title").text("Add Breakpoint");
- }
-
- $(this.editModalNode).find("form").removeData(); // important as closures persist with dom
- $(this.editModalNode).find("form").validate({
- debug: true,
- highlight: function(element) {
- $(element).closest('.form-group').removeClass('has-success has-warning').addClass('has-error');
- },
- success: function(element) {
- var state = element.closest('.form-group').find("input[name=stateId], input[name=toStateId], input[name=fromStateId]").val();
- if (state && $.inArray(state, stateNames) < 0) {
- element.text('Warning: No such state!').addClass('valid').closest('.form-group').removeClass('has-success has-error').addClass('has-warning');
- return;
- }
- element.text('OK!').addClass('valid').closest('.form-group').removeClass('has-error has-warning').addClass('has-success');
- },
- submitHandler: function (form) {
- $(breakpoint.editModalNode).modal("hide");
-
- // reset
- var oldData = jQuery.extend(true, {}, breakpoint.data);
- breakpoint.data = {};
-
- // copy over form fields
- $(breakpoint.editTypeNode).find("textarea[name], input[name], select[name]").each(function() {
- var name = $(this).attr("name");
- var value = $(this).val();
- if (name.length > 0 && value.length > 0) {
- breakpoint.data[name] = value;
- }
- })
- console.log(breakpoint.data);
- if (breakpoint.node) {
- breakpoint._updateLabelNode();
- breakpoint._updateConditionNode();
- }
- if (oldData.length > 0) {
- breakpoint.scxmlDebugger.editedBreakpoint(breakpoint, oldData);
- } else {
- breakpoint.scxmlDebugger.addBreakpoint(breakpoint);
- }
- return true;
- }
- });
-
- $(breakpoint.editTypeNode).children(".form-group").not(':first').remove();
- $(breakpoint.editTypeNode).children("input[type=hidden]").remove(); // hidden fields
-
-
- $(editTypeSelectNode).change(function () {
- $(breakpoint.editTypeNode).children(".form-group").not(':first').remove();
- $(breakpoint.editTypeNode).children("input[type=hidden]").remove(); // hidden fields
- breakpoint._updateEditTypeDOM($(editTypeSelectNode).val());
- });
- this._updateEditTypeDOM($(editTypeSelectNode).val());
-
- $(this.editModalNode).modal();
- },
-
- _updateEditTypeDOM: function(typeId) {
- var breakpoint = this;
- var breakpointType = $.grep(this.breakpointTypes["types"], function(e){ return e.id == typeId; })[0];
- this.editTypeInfoNode.innerHTML = breakpointType.hint;
-
- // $(this.editTypeNode).append('\
- // <input type="hidden" name="label" value="' + breakpointType.label + '" />\
- // ');
-
- var stateNames = this.scxmlEditor.getAllStateIds();
-
- switch(true) {
- case /state-.*/.test(typeId):
- var editTypeStateFormGroupNode = $('\
- <div class="form-group">\
- <label for="stateId" class="col-sm-2 control-label">State</label>\
- <div class="col-sm-10">\
- <input class="form-control" type="text" name="stateId" placeholder="The id of the state"/>\
- </div>\
- </div>\
- ');
- $(this.editTypeNode).append(editTypeStateFormGroupNode);
- $(editTypeStateFormGroupNode).find("input[name=stateId]")
- .val('stateId' in breakpoint.data ? breakpoint.data.stateId : "")
- .typeahead({local: stateNames})
- .rules('add', 'required');
-
- break;
- case /event-.*/.test(typeId):
- var editTypeEventFormGroupNode = $('\
- <div class="form-group">\
- <label for="eventName" class="col-sm-2 control-label">Event</label>\
- <div class="col-sm-10">\
- <input class="form-control" type="text" name="eventName" placeholder="The name or prefix of the event"/>\
- </div>\
- </div>\
- ');
- $(this.editTypeNode).append(editTypeEventFormGroupNode);
- $(editTypeEventFormGroupNode).find("input[name=eventName]")
- .val('eventName' in breakpoint.data ? breakpoint.data.eventName : "")
- .rules('add', 'required');
- break;
- case /transition-.*/.test(typeId):
- var editTypeTransitionFormGroupNode = $('\
- <div class="form-group">\
- <label for="transSourceId" class="col-sm-2 control-label">From State</label>\
- <div class="col-sm-10">\
- <input class="form-control" type="text" name="transSourceId" placeholder="The id of the source state"/>\
- </div>\
- </div>\
- <div class="form-group">\
- <label for="transTargetId" class="col-sm-2 control-label">To State</label>\
- <div class="col-sm-10">\
- <input class="form-control" type="text" name="transTargetId" placeholder="The id of the destination state"/>\
- </div>\
- </div>\
- ');
- $(this.editTypeNode).append(editTypeTransitionFormGroupNode);
- $(editTypeTransitionFormGroupNode).find("input[name=transSourceId]")
- .val('transSourceId' in breakpoint.data ? breakpoint.data.transSourceId : "")
- .typeahead({local: stateNames});
- $(editTypeTransitionFormGroupNode).find("input[name=transTargetId]")
- .val('transTargetId' in breakpoint.data ? breakpoint.data.transTargetId : "")
- .typeahead({local: stateNames});
- break
- case /invoker-.*/.test(typeId):
- var editTypeInvokerFormGroupNode = $('\
- <div class="form-group">\
- <label for="invokeId" class="col-sm-2 control-label">Invoke ID</label>\
- <div class="col-sm-10">\
- <input class="form-control" type="text" name="invokeId" placeholder="The id of the invoker"/>\
- </div>\
- </div>\
- <div class="form-group">\
- <label for="invokeType" class="col-sm-2 control-label">Invoke Type</label>\
- <div class="col-sm-10">\
- <input class="form-control" type="text" name="invokeType" placeholder="The type of the invoker"/>\
- </div>\
- </div>\
- ');
- $(this.editTypeNode).append(editTypeInvokerFormGroupNode);
- $(editTypeInvokerFormGroupNode).find("input[name=invokeId]")
- .val('invokeId' in breakpoint.data ? breakpoint.data.invokeId : "");
- $(editTypeInvokerFormGroupNode).find("input[name=invokeType]")
- .val('invokeType' in breakpoint.data ? breakpoint.data.invokeType : "");
- break
-
- case /executable-.*/.test(typeId):
- var editTypeExecutableFormGroupNode = $('\
- <div class="form-group">\
- <label for="executableName" class="col-sm-2 control-label">Element Name</label>\
- <div class="col-sm-10">\
- <input class="form-control" type="text" name="executableName" placeholder="The executable\'s element name"/>\
- </div>\
- </div>\
- <div class="form-group">\
- <label for="executableXPath" class="col-sm-2 control-label">Element XPath</label>\
- <div class="col-sm-10">\
- <input class="form-control" type="text" name="executableXPath" placeholder="The executable\'s XPath expression"/>\
- </div>\
- </div>\
- ');
- $(this.editTypeNode).append(editTypeExecutableFormGroupNode);
- $(editTypeExecutableFormGroupNode).find("input[name=executableName]")
- .val('executableName' in breakpoint.data ? breakpoint.data.executableName : "");
- $(editTypeExecutableFormGroupNode).find("input[name=executableXPath]")
- .val('executableXPath' in breakpoint.data ? breakpoint.data.executableXPath : "");
- break;
- default:
- break;
- }
-
- var editTypeConditionFormGroupNode = $('\
- <div class="form-group">\
- <label for="condition" class="col-sm-2 control-label">Condition</label>\
- <div class="col-sm-10">\
- <textarea class="form-control" rows="4" style="resize:vertical;" name="condition" placeholder="An optional boolean expression evaluated on the datamodel. Breakpoint is only triggered if true." />\
- </div>\
- </div>\
- ');
- $(editTypeConditionFormGroupNode).find("textarea[name=condition]")
- .val('condition' in breakpoint.data ? breakpoint.data.condition : "")
-
- $(this.editTypeNode).append(editTypeConditionFormGroupNode);
- },
-
- getNode: function() {
- var self = this;
- this.node = $('\
- <tr>\
- <td>\
- <button title="Enable this Breakpoint" class="enable btn btn-default btn-xs btn-primary"><span class="glyphicon glyphicon-ok"></span></button><br />\
- <button title="Skip to this Breakpoint" class="skipto btn btn-default btn-xs"><span class="glyphicon glyphicon-fast-forward"></span></button>\
- </td>\
- <td width="100%">\
- <span class="breakpoint-label"></span>\
- <span class="breakpoint-condition"></span>\
- </td>\
- <td>\
- <button title="Edit this Breakpoint" class="edit btn btn-default btn-xs"><span class="glyphicon glyphicon-wrench"></span></button><br />\
- <button title="Remove this Breakpoint" class="delete btn btn-default btn-xs"><span class="glyphicon glyphicon-trash"></span></button>\
- </td>\
- </tr>\
- ');
-
- this.labelNode = $(this.node).find("span.breakpoint-label")[0];
- this.conditionNode = $(this.node).find("span.breakpoint-condition")[0];
- this.enableButtonNode = $(this.node).find("button.enable")[0];
- this.skipToButtonNode = $(this.node).find("button.skipto")[0];
- this.deleteButtonNode = $(this.node).find("button.delete")[0];
- this.editButtonNode = $(this.node).find("button.edit")[0];
-
- $(this.enableButtonNode)
- .unbind('click')
- .click(function() {
- if ($(this).hasClass("btn-primary")) {
- self.scxmlDebugger.disableBreakpoint(self);
- } else {
- self.scxmlDebugger.enableBreakpoint(self);
- }
- return false;
- });
-
- $(this.deleteButtonNode)
- .unbind('mouseenter')
- .unbind('mouseleave')
- .unbind('click')
- .mouseenter(function() {
- $(this).addClass("btn-danger");
- })
- .mouseleave(function() {
- $(this).removeClass("btn-danger");
- })
- .click(function() {
- self.scxmlDebugger.removeBreakpoint(self);
- return false;
- });
-
- $(this.editButtonNode)
- .unbind('click').click(function() {
- self.showEditDialog()
- return false;
- });
-
- $(this.skipToButtonNode)
- .unbind('click').click(function() {
- self.scxmlDebugger.skipToBreakpoint(self);
- return false;
- });
-
- this._updateLabelNode();
- this._updateConditionNode();
-
- return this.node;
- },
-
- toDescription: function() {
- var wireFormat = this.toWireFormat();
-
- var breakpointString = '';
- breakpointString += ('when' in wireFormat ? wireFormat.when + ' ' : '');
- breakpointString += ('action' in wireFormat ? wireFormat.action + ' ' : '');
- breakpointString += ('subject' in wireFormat ? wireFormat.subject + ' ' : '');
-
- breakpointString += (wireFormat.subject === 'state' ? wireFormat.stateId + ' ' : '');
- breakpointString += (wireFormat.subject === 'event' ? wireFormat.eventName + ' ' : '');
- if (wireFormat.subject === 'transition') {
- breakpointString += ('transSourceId' in wireFormat ? wireFormat.transSourceId + ' ' : '* ');
- breakpointString += '&rArr; ';
- breakpointString += ('transTargetId' in wireFormat ? wireFormat.transTargetId + ' ' : '* ');
- }
-
- return breakpointString;
- },
-
- _updateLabelNode: function() {
- this.labelNode.innerHTML = 'Halt ' + this.toDescription();
- },
-
- _updateConditionNode: function() {
- if (this.data.condition) {
- this.conditionNode.innerHTML = "<br/>But only when <code>" + this.data.condition + "</code>";
- } else {
- this.conditionNode.innerHTML = '';
- }
- },
-
- _typeSelectNode: function() {
- // establish optgroups for selecting the breakpoint type
- var optGroups = {};
- for (var index in this.breakpointTypes.types) {
- var bp = this.breakpointTypes.types[index];
- var optGroup = bp.category;
- if (!(optGroup in optGroups)) optGroups[optGroup] = [];
- optGroups[optGroup].push(bp);
- }
-
- var breakpointTypeSelectNode = document.createElement('select');
- breakpointTypeSelectNode.className = 'form-control';
- $(breakpointTypeSelectNode).attr("name", "breakpointType");
-
- for (var optGroup in this.breakpointTypes.categories) {
- var cat = this.breakpointTypes.categories[optGroup];
- var optGroupNode = document.createElement('optgroup');
- $(optGroupNode).attr('label', cat.label);
-
- for(var type in optGroups[cat.id]) {
- var breakpointType = optGroups[cat.id][type];
- var optionNode = document.createElement('option');
- $(optionNode).attr('value', breakpointType.id);
- optionNode.innerHTML = breakpointType.label;
- $(optionNode).appendTo(optGroupNode);
- }
- $(optGroupNode).appendTo(breakpointTypeSelectNode);
- }
-
- return breakpointTypeSelectNode;
- },
-
- });
- SCXMLEditor.Debugger.Breakpoint.seqNr = 0;
-
- SCXMLEditor.Debugger.USCXML = SCXMLEditor.Debugger.extend({
- constructor: function(params) {
- this.base(params);
-
- this.isConnected = false; // we have a connection to the uscxml server
- this.isPrepared = false; // we uploaded a document
- this.isRunning = false; // the interpreter on the server is running
- this.isPaused = false; // the interpreter is running but paused
- this.hasDOMLoaded = false; // the client has a DOM loaded
- this.isAttached = false; // we are attached to a server session
- this.isPolling = false; // we have a unreplied poll request standing
- this.sessionId = "";
- },
-
- _updateDebugControls: function() {
- // all buttons are disabled per base class
- $(this.startButtonNode).prop('disabled', true)
- $(this.pauseButtonNode).prop('disabled', true);
- $(this.stepButtonNode).prop('disabled', true);
-
- var status = "";
- status += (this.isConnected ? "CON " : "con ");
- status += (this.isPolling ? "POL " : "pol ");
- status += (this.isPrepared ? "PRP " : "prp ");
- status += (this.isRunning ? "RUN " : "run ");
- status += (this.isPaused ? "PAU " : "pau ");
- status += (this.hasDOMLoaded ? "DOM " : "dom ");
- status += (this.isAttached ? "ATC " : "atc ");
-
- $(this.statusIndicatorNode).html(status);
-
- // some sanity
- if (!this.isConnected) {
- $("body").find(".dom").text("");
- $(this.currentBreakpointNode).html("");
- this.isPaused = false;
- this.isRunning = false;
- this.isAttached = false;
- this.isPrepared = false;
- }
-
- if (!this.isRunning) {
- this.isPaused = false;
- $(this.currentBreakpointNode).html("");
- }
-
- // toggle button icons
- if (this.isRunning) { // switch play and stop
- $(this.startButtonNode).children("span.glyphicon").removeClass("glyphicon-play").addClass("glyphicon-stop");
- $(this.startButtonNode).prop('title', 'Stop Execution');
- } else {
- $(this.startButtonNode).children("span.glyphicon").removeClass("glyphicon-stop").addClass("glyphicon-play");
- $(this.startButtonNode).prop('title', 'Start Execution');
- }
-
- if (!this.isPaused) { // switch pause and resume
- $(this.pauseButtonNode).removeClass("active");
- $(this.pauseButtonNode).prop('title', 'Pause Execution');
- this.unhighlightAllBreakpoints();
- $(this.currentBreakpointNode).html("");
- } else {
- $(this.pauseButtonNode).addClass("active");
- $(this.pauseButtonNode).prop('title', 'Resume Execution');
- }
-
- if (this.isConnected && (this.hasDOMLoaded || this.isAttached)) {
- // are we connected, not running and have a DOM or are attached?
- if (!this.isAttached) {
- $(this.startButtonNode).prop('disabled', false);
- }
- if (this.isRunning) {
- $(this.pauseButtonNode).prop('disabled', false);
- $(this.stepButtonNode).prop('disabled', false);
- } else {
- $(this.startButtonNode).prop('disabled', false)
- $(this.pauseButtonNode).prop('disabled', true);
- $(this.stepButtonNode).prop('disabled', false);
- }
- return;
- } else {
- $("body").find(".dom").text("");
- }
- },
-
- loadDOM: function(scxmlDOM) {
- this.hasDOMLoaded = true;
- this._updateDebugControls();
- },
-
- getNode: function() {
- this.base();
- var debug = this;
-
- // a new menu item
- $(this.controlDropdownNode).append('\
- <li role="presentation" class="divider"></li>\
- <li class="disabled"><a href="#"><i class="glyphicon glyphicon-resize-small"></i> Attach to Instance</a></li>\
- ');
-
- // the connect bar
- $(this.node).find(".debug-header").after('\
- <div class="panel-body input-group input-group-sm">\
- <input type="text" class="form-control connect" placeholder="uSCMXL Interpreter URL">\
- <span class="input-group-btn">\
- <button title="Connect" class="btn btn-default ladda-button connect" data-spinner-color="#000" data-style="zoom-in">\
- <span class="ladda-label"><span class="ui-icon ui-icon-unlocked"></span></span></button>\
- </span>\
- </div>\
- ');
-
- this.connectInputNode = $(this.node).find("input.connect");
- this.connectButtonNode = $(this.connectInputNode).next().children("button.connect")[0];
-
- if (this.debuggerURL) {
- $(this.connectInputNode).val(this.debuggerURL);
- } else {
- $(this.connectInputNode).attr("placeholder", "URL of uscxml-debug");
- }
-
- $(this.connectInputNode).focus(function () {
- $(debug.connectButtonNode)
- .removeClass("btn-warning")
- .find("span.ui-icon")
- .removeClass("ui-icon-alert ui-icon-locked")
- .addClass("ui-icon-unlocked");
- });
-
- $(this.connectInputNode).unbind('keypress').keypress(function(e) {
- if (e.which == 13)
- $(debug.connectButtonNode).trigger('click');
- });
-
-
- $(this.connectButtonNode).unbind("click");
- $(this.connectButtonNode).click(function() {
- debug.connectSpinner = Ladda.create(this);
- debug.connectSpinner.start();
- if (debug.isConnected) {
- debug.disconnect();
- } else {
- debug.connect($(debug.connectInputNode).val());
- }
- });
-
- // debug controls
- $(this.startButtonNode)
- .unbind('click').click(function () {
- $(this).tooltip("hide");
- if ($(this).children(".glyphicon").hasClass("glyphicon-play")) {
- debug.startDebug();
- } else {
- debug.stopDebug();
- }
- });
-
- $(this.pauseButtonNode)
- .unbind('click').click(function() {
- $(this).tooltip("hide");
- if (debug.isPaused) {
- debug.resumeDebug();
- } else {
- debug.pauseDebug();
- }
- });
-
- $(this.stepButtonNode)
- .unbind('click').click(function() {
- $(this).tooltip("hide");
- debug.stepDebug();
- });
-
- this._updateDebugControls();
-
- return this.node;
- },
-
- _indicateLockedConnection: function() {
- $(this.connectButtonNode)
- .removeClass("btn-warning")
- .find("span.ui-icon")
- .removeClass("ui-icon-alert ui-icon-unlocked")
- .addClass("ui-icon-locked");
- $(this.connectInputNode).attr('disabled', true);
- $(this.dataModelInputNode).prop('disabled', false);
- $(this.dataModelInputButton).prop('disabled', false);
- $(this.dataModelSuggestButton).prop('disabled', false);
- },
-
- _indicateFailedConnection: function() {
- $(this.connectButtonNode)
- .addClass("btn-warning")
- .find("span.ui-icon")
- .removeClass("ui-icon-locked ui-icon-unlocked")
- .addClass("ui-icon-alert");
- },
-
- _indicateUnlockedConnection: function() {
- $(this.connectButtonNode)
- .removeClass("btn-warning")
- .find("span.ui-icon")
- .removeClass("ui-icon-locked ui-icon-alert")
- .addClass("ui-icon-unlocked");
- $(this.connectInputNode).attr('disabled', false);
- $(this.dataModelInputNode).prop('disabled', true);
- $(this.dataModelInputButton).prop('disabled', true);
- $(this.dataModelSuggestButton).prop('disabled', true);
- },
-
- connect: function(debuggerURL) {
- if (!debuggerURL || debuggerURL.length == 0)
- return;
-
- this.debuggerURL = debuggerURL;
-
- var self = this;
-
- this.requestWithJSON('/debug/connect', {
- onFailure: function(dataObj, statusString, xhrObj) {
- self.isConnected = false;
- self._indicateFailedConnection();
- },
- onSuccess: function(dataObj, statusString, xhrObj) {
- self.isConnected = true;
- self._indicateLockedConnection();
-
- self.log("Client successfully connected to " + self.debuggerURL);
- self.sessionId = dataObj.session;
- // send all breakpoints when connected
- if (self.breakpoints.length > 0) {
- for (var index in self.breakpoints) {
- self.addBreakpoint(self.breakpoints[index]);
- }
- }
- // register disconnect handler
- $(window).unload(function() {
- self.disconnect();
- });
- // update list of sessions from server
- self.updateServerSessions();
- // and start long-poller
- self.pollServer();
- },
- onComplete: function(dataObj, statusString) {
- self.connectSpinner.stop();
- }
- });
- },
-
- disconnect: function() {
- if (!this.isConnected)
- return;
- var self = this;
-
- this.requestWithJSON('/debug/disconnect', {
- async: false,
- onComplete: function(dataObj, statusString) {
- self.isConnected = false;
- self.isPrepared = false;
- self._indicateUnlockedConnection();
- self.connectSpinner.stop();
-
- // remove all previous sessions
- $(self.controlDropdownNode).children("li.server-session").remove();
- self.debuggerURL = '';
- }
- });
- },
-
- updateServerSessions: function() {
- this.base();
- if (!this.isConnected)
- return;
-
- var self = this;
-
- this.requestWithJSON('/debug/sessions', {
- onSuccess: function(dataObj, statusString, xhrObj) {
- $(self.controlButtonNode).effect('highlight', {color: '#4489CA'}, 600);
-
- // remove all previous sessions
- $(self.controlDropdownNode).children("li.server-session").remove();
- for (var key in dataObj.sessions) {
- $(self.controlDropdownNode).append('\
- <li class="server-session" \
- session-url="' + dataObj.sessions[key].source + '"\
- session-name="' + dataObj.sessions[key].name + '"\
- session-id="' + dataObj.sessions[key].id + '"\
- ><a href="#"><i class="glyphicon glyphicon-link"></i> ' + dataObj.sessions[key].source + '</a></li>\
- ');
- }
- $(self.controlDropdownNode).find("li").unbind('click').click(function() {
- var session = {
- sessionId: $(this).attr("session-id"),
- sessionName: $(this).attr("session-name"),
- sessionURL: $(this).attr("session-url"),
- };
- self.attachDebug(session);
-
- $(self.controlDropdownNode).dropdown('toggle');
- return false;
- });
- }
- });
- },
-
-
- addBreakpoint: function(breakpoint) {
- this.base(breakpoint);
- if (!this.isConnected)
- return;
-
- if (!breakpoint) // it's perfectly fine to call this without a breakpoint - will add a new one
- return;
-
- this.requestWithJSON('/debug/breakpoint/add', {
- data: breakpoint.toWireFormat()
- });
- },
-
- removeBreakpoint: function(breakpoint) {
- this.base(breakpoint);
- if (!this.isConnected)
- return;
- this.requestWithJSON('/debug/breakpoint/remove', {
- data: breakpoint.toWireFormat()
- });
- },
-
- editedBreakpoint: function(breakpoint, oldData) {
- this.base(breakpoint, oldData);
- if (!this.isConnected)
- return;
-
- var oldBreakpoint = new SCXMLEditor.Debugger.Breakpoint({ data : oldData });
- this.requestWithJSON('/debug/breakpoint/remove', {
- data: oldBreakpoint.toWireFormat()
- });
- this.requestWithJSONBlocking('/debug/breakpoint/add', {
- data: breakpoint.toWireFormat()
- });
- },
-
- skipToBreakpoint: function(breakpoint) {
- this.base(breakpoint);
- if (!this.isConnected)
- return;
-
- this.requestWithJSON('/debug/breakpoint/skipto', {
- data: breakpoint.toWireFormat()
- });
-
- },
-
- enableBreakpoint: function(breakpoint) {
- this.base(breakpoint);
- if (!this.isConnected)
- return;
-
- this.requestWithJSON('/debug/breakpoint/enable', {
- data: breakpoint.toWireFormat()
- });
- },
-
- disableBreakpoint: function(breakpoint) {
- this.base(breakpoint);
- if (!this.isConnected)
- return;
-
- this.requestWithJSON('/debug/breakpoint/disable', {
- data: breakpoint.toWireFormat()
- });
- },
-
- enableAllBreakpoints: function() {
- this.base();
- if (!this.isConnected)
- return;
-
- this.requestWithJSON('/debug/breakpoint/enable/all');
- },
-
- disableAllBreakpoints: function() {
- this.base();
- if (!this.isConnected)
- return;
-
- this.requestWithJSON('/debug/breakpoint/disable/all');
-
- },
-
-
- attachDebug: function(session) {
- this.base();
- if (!this.isConnected)
- return;
-
- var self = this;
-
- var data = {
- attach: session.sessionId,
- };
-
- this.requestWithJSON('/debug/attach', {
- data: data,
- onSuccess: function(dataObj, statusString, xhrObj) {
- self.isPrepared = true;
- self.isRunning = true;
- self.isAttached = true;
-
- if (self.scxmlEditor.xmlView) {
- self.scxmlEditor.xmlView.setXML(dataObj.xml)
- self.scxmlEditor.xmlView.prettyPrint();
- }
-
- // var domText = vkbeautify.xml(dataObj.xml);
- // $("body").find("pre.dom").text(domText);
- self.scxmlEditor.setDocumentNameFromURL(session.sessionURL);
- self._updateDebugControls();
- }
- });
-
- },
-
- prepareDebug: function() {
- this.base();
- if (!this.isConnected)
- return;
-
- if (this.isAttached)
- return;
-
- var self = this;
-
- var data = {
- url: this.scxmlEditor.scxmlURL,
- xml: this.scxmlText
- };
-
- this.requestWithJSON('/debug/prepare', {
- data: data,
- onSuccess: function(dataObj, statusString, xhrObj) {
- self.isPrepared = true;
- }
- });
- },
-
- startDebug: function() {
- this.base();
- if (!this.isConnected)
- return;
-
- if (!this.isPrepared)
- this.prepareDebug();
-
- var self = this;
-
- this.requestWithJSON('/debug/start', {
- onSuccess: function(dataObj, statusString, xhrObj) {
- self.isRunning = true;
- }
- });
- },
-
- stopDebug: function() {
- this.base();
- if (!this.isConnected)
- return;
-
- var self = this;
-
- this.requestWithJSON('/debug/stop', {
- onSuccess: function(dataObj, statusString, xhrObj) {
- self.isRunning = false;
- self.isPrepared = false;
- }
- });
- },
-
- pauseDebug: function() {
- this.base();
- if (!this.isConnected)
- return;
-
- var self = this;
-
- this.requestWithJSON('/debug/pause', {
- onSuccess: function(dataObj, statusString, xhrObj) {
- self.isPaused = true;
- self._updateDebugControls();
- }
- });
- },
-
- resumeDebug: function() {
- this.base();
- if (!this.isConnected)
- return;
-
- var self = this;
-
- this.requestWithJSON('/debug/resume', {
- onSuccess: function(dataObj, statusString, xhrObj) {
- self.isPaused = false;
- self._updateDebugControls();
- }
- });
- },
-
- stepDebug: function() {
- this.base();
- if (!this.isConnected)
- return;
-
- if (!this.isPrepared)
- this.prepareDebug();
-
- var self = this;
-
- this.requestWithJSON('/debug/step', {
- onSuccess: function(dataObj, statusString, xhrObj) {
- self.isRunning = true;
- self.isPaused = true;
- self._updateDebugControls();
- }
- });
- },
-
- evalOnDataModel: function(expression) {
- this.base();
- if (!this.isConnected)
- return;
-
- var self = this;
-
- var data = {};
- data.expression = expression;
-
- this.requestWithJSON('/debug/eval', {
- data: data,
- onSuccess: function(dataObj, statusString, xhrObj) {
- var content = JSON.stringify(dataObj.eval);
- self.dataModelEditor.getSession().setValue(vkbeautify.json(content));
-
- },
- });
-
- },
-
- // server will return 'status' with JSON response, dispatch accordingly
- requestWithJSON: function(url, params) {
- var self = this;
- if (!params)
- params = {};
-
- params.method = ('method' in params ? params.method : "POST");
- params.async = ('async' in params ? params.async : true);
- params.onSuccess = ('onSuccess' in params ? params.onSuccess : function() {});
- params.onFailure = ('onFailure' in params ? params.onFailure : function(dataObj) { self.log(dataObj); });
- params.onComplete = ('onComplete' in params ? params.onComplete : function() {});
- params.onError = ('onError' in params ? params.onError : function() {});
- params.returnType = ('returnType' in params ? params.returnType : "json");
- params.sendType = ('sendType' in params ? params.sendType : "application/json; charset=utf-8");
- params.data = ('data' in params ? params.data : {});
-
- if (params.sendType.match("^application/json")) {
- if (this.sessionId.length > 0) // automatically add session
- params.data.session = this.sessionId;
- params.data = JSON.stringify(params.data);
- }
-
- $.ajax({
- type: params.method,
- dataType: params.returnType,
- async: params.async,
- data: params.data,
- contentType: params.sendType,
- url: this.debuggerURL + url,
- success: function (dataObj, statusString, xhrObj) {
- self.log("Received from " + url);
- self.log(dataObj);
-
- if ("status" in dataObj && dataObj.status === 'success') {
- params.onSuccess(dataObj, statusString, xhrObj);
- } else {
- params.onFailure(dataObj, statusString, xhrObj);
- }
- },
- error: function(xhrObj, statusString, errorString) {
- self.log("Error from " + self.debuggerURL + url);
- self.log(statusString + "\n\t" + errorString);
- self.log(xhrObj);
-
- self.isConnected = false;
- self._indicateFailedConnection();
- params.onError(errorString, statusString, xhrObj);
- },
- complete: function(xhrObj, statusString) {
- params.onComplete(xhrObj, statusString);
- self._updateDebugControls();
- }
- });
- },
-
- handleBreakpointReturn: function(serverReturn) {
- var updateViewer = false;
- if ('qualified' in serverReturn) {
- var qualifiedBreakpoint = new SCXMLEditor.Debugger.Breakpoint({ data : serverReturn.qualified });
- var breakpointString = 'Halted ' + qualifiedBreakpoint.toDescription();
- $(this.currentBreakpointNode).html(breakpointString);
-
- if ('xpath' in serverReturn.qualified) {
- if (this.scxmlEditor.xmlView) {
- this.scxmlEditor.xmlView.setElementXPath(serverReturn.qualified.xpath);
- }
- } else {
- this.scxmlEditor.xmlView.setElementXPath("");
- }
- }
-
- if ('basicStates' in serverReturn) {
- if (this.scxmlEditor.xmlView) {
- this.scxmlEditor.xmlView.setActiveStates(serverReturn['basicStates']);
- }
- }
-
- if (this.scxmlEditor.xmlView) {
- this.scxmlEditor.xmlView.prettyPrint();
- }
-
- if ('breakpoint' in serverReturn) {
- var breakpoint = new SCXMLEditor.Debugger.Breakpoint({ data : serverReturn.breakpoint });
- this.highlightBreakpoint(breakpoint);
- }
-
- },
-
- pollServer: function() {
- this.isPolling = false;
- this._updateDebugControls();
-
- if (!this.isConnected)
- return;
-
- if (this.sessionId.length == 0)
- return;
-
- var self = this;
- this.isPolling = true;
- self._updateDebugControls();
-
- $.ajax({
- type: "POST",
- dataType: "json",
- async: true,
- timeout: 100000000,
- data: JSON.stringify({session: this.sessionId}),
- contentType: "application/json",
- url: this.debuggerURL + '/debug/poll',
- success: function (dataObj, statusString, xhrObj) {
- try {
- if ('status' in dataObj) {
- if (dataObj.status !== 'success') {
- self.log("Error from " + self.debuggerURL + "/debug/poll");
- self.log(dataObj);
- return;
- }
- }
- if ('replyType' in dataObj) {
- //self.log("Received " + dataObj.replyType);
- if (dataObj.replyType === "log") {
- self.log(dataObj);
- } else if (dataObj.replyType === "finished") {
- self.isRunning = false;
- self.isPrepared = false;
- } else if (dataObj.replyType === "breakpoint") {
- self.isPaused = true;
- self.log(dataObj);
- self.handleBreakpointReturn(dataObj);
- } else {
- self.log("Unhandled reply from /pollServer");
- self.log(dataObj);
- }
- } else {
- self.log("Untyped reply from /pollServer");
- self.log(dataObj);
- }
- } catch(e) {
- self.log("Exception when dispatching server push:");
- self.log(e);
- }
- // dispatch server push here
- self.pollServer();
- },
- error: function(xhrObj, statusString, errorString) {
- if (xhrObj.statusText === "timeout") {
- self.pollServer(); // just repoll
- return;
- }
-
- self.log("Error from /pollServer");
- self.log(statusString + "\n\t" + errorString);
- self.log(xhrObj);
-
- self.isConnected = false;
- self._indicateFailedConnection();
- },
- complete: function(xhrObj, statusString) {
- self._updateDebugControls();
- }
- });
-
- },
-
- });
-
- // see http://nealvs.wordpress.com/2010/07/12/how-to-compare-two-javascript-objects-for-equality/
- function deepEquals(x, y) {
- for (var p in y) {
- if (typeof(y[p]) !== typeof(x[p])) return false;
- if ((y[p] === null) !== (x[p] === null)) return false;
- switch (typeof(y[p])) {
- case 'undefined':
- if (typeof(x[p]) != 'undefined') return false;
- break;
- case 'object':
- if (y[p] !== null && x[p] !== null && (y[p].constructor.toString() !== x[p].constructor.toString() || !y[p].equals(x[p]))) return false;
- break;
- case 'function':
- if (p != 'equals' && y[p].toString() != x[p].toString()) return false;
- break;
- default:
- if (y[p] !== x[p]) return false;
- }
- }
- return true;
- }
-
- $(document).ready(function() {
-
-
- // see http://stackoverflow.com/questions/18754020/bootstrap-3-with-jquery-validation-plugin
- $.validator.setDefaults({
- highlight: function(element) {
- $(element).closest('.form-group').addClass('has-error');
- },
- unhighlight: function(element) {
- $(element).closest('.form-group').removeClass('has-error');
- },
- errorElement: 'span',
- errorClass: 'help-block',
- errorPlacement: function(error, element) {
- if(element.parent('.input-group').length) {
- error.insertAfter(element.parent());
- } else {
- error.insertAfter(element);
- }
- }
- });
-
- var scxmlEdit = new SCXMLEditor({
- containerNode: $("#scxml-editor")[0]
- });
-
- });
-
- </script>
-</head>
-<body>
- <div id="scxml-editor"></div>
- <div class="messages"></div>
- <div class="dom"></pre>
-</body>
-</html>
diff --git a/apps/uscxml-transform.cpp b/apps/uscxml-transform.cpp
deleted file mode 100644
index e99ed68..0000000
--- a/apps/uscxml-transform.cpp
+++ /dev/null
@@ -1,385 +0,0 @@
-#include "uscxml/config.h"
-#include "uscxml/Interpreter.h"
-#include "uscxml/util/String.h"
-#include "uscxml/transform/ChartToC.h"
-#include "uscxml/transform/ChartToJava.h"
-#include "uscxml/transform/ChartToVHDL.h"
-#include "uscxml/transform/ChartToPromela.h"
-
-#include <boost/algorithm/string.hpp>
-
-#include <fstream>
-#include <iostream>
-#include <map>
-
-#include "uscxml/plugins/Factory.h"
-#include "uscxml/server/HTTPServer.h"
-#include "getopt.h"
-
-#include "uscxml/interpreter/Logging.h"
-
-#define ANNOTATE(envKey, annotationParam) \
-envVarIsTrue(envKey) || std::find(options.begin(), options.end(), annotationParam) != options.end()
-
-void printUsageAndExit(const char* progName) {
- // remove path from program name
- std::string progStr(progName);
- if (progStr.find_last_of(PATH_SEPERATOR) != std::string::npos) {
- progStr = progStr.substr(progStr.find_last_of(PATH_SEPERATOR) + 1, progStr.length() - (progStr.find_last_of(PATH_SEPERATOR) + 1));
- }
-
- printf("%s version " USCXML_VERSION " (" CMAKE_BUILD_TYPE " build - " CMAKE_COMPILER_STRING ")\n", progStr.c_str());
- printf("Usage\n");
- printf("\t%s", progStr.c_str());
- printf(" [-t c|pml|flat|min] [-a {OPTIONS}] [-v] [-lN]");
-#ifdef BUILD_AS_PLUGINS
- printf(" [-p pluginPath]");
-#endif
- printf(" [-i URL] [-o FILE]");
- printf("\n");
- printf("Options\n");
- printf("\t-t c : convert to C program\n");
- printf("\t-t pml : convert to spin/promela program\n");
- printf("\t-t vhdl : convert to VHDL hardware description\n");
- printf("\t-t java : convert to Java classes\n");
- printf("\t-t flat : flatten to SCXML state-machine\n");
- printf("\t-a FILE : write annotated SCXML document for transformation\n");
- printf("\t-X {PARAMETER} : pass additional parameters to the transformation\n");
- printf("\t prefix=ID - prefix all symbols and identifiers with ID (-tc)\n");
- printf("\t-v : be verbose\n");
- printf("\t-lN : Set loglevel to N\n");
- printf("\t-i URL : Input file (defaults to STDIN)\n");
- printf("\t-o FILE : Output file (defaults to STDOUT)\n");
- printf("\n");
- exit(1);
-}
-
-int main(int argc, char** argv) {
- using namespace uscxml;
-
- bool verbose = false;
- std::string outType;
- std::string pluginPath;
- std::string inputFile;
- std::string annotatedFile;
- std::string outputFile;
- std::list<std::string> options;
- std::multimap<std::string, std::string> extensions;
-
-#if defined(HAS_SIGNAL_H) && !defined(WIN32)
- signal(SIGPIPE, SIG_IGN);
-#endif
-
- optind = 0;
- opterr = 0;
-
- struct option longOptions[] = {
- {"verbose", no_argument, 0, 'v'},
- {"type", required_argument, 0, 't'},
- {"annotate", required_argument, 0, 'a'},
- {"param", required_argument, 0, 'X'},
- {"plugin-path", required_argument, 0, 'p'},
- {"input-file", required_argument, 0, 'i'},
- {"output-file", required_argument, 0, 'o'},
- {"loglevel", required_argument, 0, 'l'},
- {0, 0, 0, 0}
- };
-
- // parse global options
- int optionInd = 0;
- int option;
- for (;;) {
- option = getopt_long_only(argc, argv, "+vp:X:t:i:o:l:a:", longOptions, &optionInd);
- if (option == -1) {
- break;
- }
- switch(option) {
- // cases without short option
- case 0: {
- break;
- }
- // cases with short-hand options
- case 'v':
- verbose = true;
- break;
- case 't':
- outType = optarg;
- break;
- case 'p':
- pluginPath = optarg;
- break;
- case 'i':
- inputFile = optarg;
- break;
- case 'a':
- annotatedFile = optarg;
- break;
- case 'X': {
- std::list<std::string> extension = tokenize(optarg, '=');
- if (extension.size() != 2)
- printUsageAndExit(argv[0]);
- std::string key = boost::trim_copy(*(extension.begin()));
- std::string value = boost::trim_copy(*(++extension.begin()));
- extensions.insert(std::pair<std::string, std::string>(key, value));
- }
- break;
- case 'o':
- outputFile = optarg;
- extensions.insert(std::pair<std::string, std::string>("outputFile", outputFile));
- break;
- case 'l':
- break;
- case '?': {
- break;
- }
- default:
- break;
- }
- }
-
- // make sure given annotation options are available in the environment
- if(ANNOTATE("USCXML_ANNOTATE_GLOBAL_STATE_STEP", "step"))
- setenv("USCXML_ANNOTATE_GLOBAL_STATE_STEP", "YES", 1);
-
- if (ANNOTATE("USCXML_ANNOTATE_GLOBAL_TRANS_PRIO", "priority"))
- setenv("USCXML_ANNOTATE_GLOBAL_TRANS_PRIO", "YES", 1);
-
- if (ANNOTATE("USCXML_ANNOTATE_VERBOSE_COMMENTS", "verbose"))
- setenv("USCXML_ANNOTATE_VERBOSE_COMMENTS", "YES", 1);
-
- if (ANNOTATE("USCXML_ANNOTATE_TRANS_EXITSET", "exitset"))
- setenv("USCXML_ANNOTATE_TRANS_EXITSET", "YES", 1);
-
- if (ANNOTATE("USCXML_ANNOTATE_TRANS_DOMAIN", "domain"))
- setenv("USCXML_ANNOTATE_TRANS_DOMAIN", "YES", 1);
-
- if (ANNOTATE("USCXML_ANNOTATE_TRANS_CONFLICTS", "conflicts"))
- setenv("USCXML_ANNOTATE_TRANS_CONFLICTS", "YES", 1);
-
- if (ANNOTATE("USCXML_ANNOTATE_TRANS_ENTRYSET", "entryset"))
- setenv("USCXML_ANNOTATE_TRANS_ENTRYSET", "YES", 1);
-
- if(ANNOTATE("USCXML_ANNOTATE_GLOBAL_TRANS_MEMBERS", "members"))
- setenv("USCXML_ANNOTATE_GLOBAL_TRANS_MEMBERS", "YES", 1);
-
- if(ANNOTATE("USCXML_ANNOTATE_GLOBAL_TRANS_SENDS", "sends"))
- setenv("USCXML_ANNOTATE_GLOBAL_TRANS_SENDS", "YES", 1);
-
- if(ANNOTATE("USCXML_ANNOTATE_GLOBAL_TRANS_RAISES", "raises"))
- setenv("USCXML_ANNOTATE_GLOBAL_TRANS_RAISES", "YES", 1);
-
- if(ANNOTATE("USCXML_ANNOTATE_PROGRESS", "progress"))
- setenv("USCXML_ANNOTATE_PROGRESS", "YES", 1);
-
- if(ANNOTATE("USCXML_ANNOTATE_NOCOMMENT", "nocomment"))
- setenv("USCXML_ANNOTATE_NOCOMMENT", "YES", 1);
-
-
-// if (outType.length() == 0 && outputFile.length() > 0) {
-// // try to get type from outfile extension
-// size_t dotPos = outputFile.find_last_of(".");
-// if (dotPos != std::string::npos) {
-// outType= outputFile.substr(dotPos + 1);
-// }
-// }
-
-// if (outType.length() == 0)
-// printUsageAndExit(argv[0]);
-
- if (outType != "flat" &&
- outType != "scxml" &&
- outType != "pml" &&
- outType != "c" &&
- outType != "vhdl" &&
- outType != "java" &&
- outType != "min" &&
- std::find(options.begin(), options.end(), "priority") == options.end() &&
- std::find(options.begin(), options.end(), "domain") == options.end() &&
- std::find(options.begin(), options.end(), "conflicts") == options.end() &&
- std::find(options.begin(), options.end(), "exitset") == options.end() &&
- std::find(options.begin(), options.end(), "entryset") == options.end())
- printUsageAndExit(argv[0]);
-
- // register plugins
- if (pluginPath.length() > 0) {
- Factory::setDefaultPluginPath(pluginPath);
- }
-
- // start HTTP server
- HTTPServer::getInstance(30444, 30445, NULL);
-
- Interpreter interpreter;
- try {
- if (inputFile.size() == 0 || inputFile == "-") {
- LOGD(USCXML_INFO) << "Reading SCXML from STDIN" << std::endl;
- std::stringstream ss;
- std::string line;
- while (std::getline(std::cin, line)) {
- ss << line;
- }
- URL tmp("anonymous.scxml");
- tmp = URL::resolveWithCWD(tmp);
- interpreter = Interpreter::fromXML(ss.str(), tmp);
- } else {
- interpreter = Interpreter::fromURL(inputFile);
- }
- } catch (Event e) {
- // we will reattempt below, not yet a fatal error
- } catch (const std::exception &e) {
- std::cout << e.what() << std::endl;
- }
-
- if (!interpreter) {
- URL tmp(inputFile);
- tmp = URL::resolveWithCWD(tmp);
- std::string content = tmp.getInContent();
-
- std::string inlineBeginMarker = "INLINE SCXML BEGIN\n";
- std::string inlineEndMarker = "\nINLINE SCXML END";
-
- size_t inlineSCXMLBegin = content.find(inlineBeginMarker);
- if (inlineSCXMLBegin != std::string::npos) {
- inlineSCXMLBegin += inlineBeginMarker.size();
- size_t inlineSCXMLEnd = content.find(inlineEndMarker);
- std::string inlineSCXMLContent = content.substr(inlineSCXMLBegin, inlineSCXMLEnd - inlineSCXMLBegin);
- try {
- interpreter = Interpreter::fromXML(inlineSCXMLContent, tmp);
- } catch (Event e) {
- std::cout << e << std::endl;
- } catch (const std::exception &e) {
- std::cout << e.what() << std::endl;
- }
- }
-
- }
-
- if (!interpreter) {
- LOGD(USCXML_ERROR) << "Cannot create interpreter from " << inputFile << std::endl;
- exit(EXIT_FAILURE);
-
- }
-
- try {
- if (verbose) {
- std::list<InterpreterIssue> issues = interpreter.validate();
- for (std::list<InterpreterIssue>::iterator issueIter = issues.begin(); issueIter != issues.end(); issueIter++) {
- std::cerr << *issueIter << std::endl;
- }
- }
-
- Transformer transformer;
- if (outType == "c") {
- transformer = ChartToC::transform(interpreter);
- transformer.setExtensions(extensions);
- transformer.setOptions(options);
-
- if (outputFile.size() == 0 || outputFile == "-") {
- transformer.writeTo(std::cout);
- } else {
- std::ofstream outStream;
- outStream.open(outputFile.c_str());
- transformer.writeTo(outStream);
- outStream.close();
- }
- }
-
- if (outType == "java") {
- transformer = ChartToJava::transform(interpreter);
- transformer.setExtensions(extensions);
- transformer.setOptions(options);
-
- if (outputFile.size() == 0 || outputFile == "-") {
- transformer.writeTo(std::cout);
- } else {
- std::ofstream outStream;
- outStream.open(outputFile.c_str());
- transformer.writeTo(outStream);
- outStream.close();
- }
- }
-
- if (outType == "vhdl") {
- transformer = ChartToVHDL::transform(interpreter);
- transformer.setExtensions(extensions);
- transformer.setOptions(options);
-
- if (outputFile.size() == 0 || outputFile == "-") {
- transformer.writeTo(std::cout);
- } else {
- std::ofstream outStream;
- outStream.open(outputFile.c_str());
- transformer.writeTo(outStream);
- outStream.close();
- }
- }
-
- if (outType == "pml") {
- transformer = ChartToPromela::transform(interpreter);
- transformer.setExtensions(extensions);
- transformer.setOptions(options);
-
- if (outputFile.size() == 0 || outputFile == "-") {
- transformer.writeTo(std::cout);
- } else {
- std::ofstream outStream;
- outStream.open(outputFile.c_str());
- transformer.writeTo(outStream);
- outStream.close();
- }
- }
-
-// if (outType == "tex") {
-// if (outputFile.size() == 0 || outputFile == "-") {
-// ChartToTex::transform(interpreter).writeTo(std::cout);
-// } else {
-// std::ofstream outStream;
-// outStream.open(outputFile.c_str());
-// ChartToTex::transform(interpreter).writeTo(outStream);
-// outStream.close();
-// }
-// exit(EXIT_SUCCESS);
-// }
-
-// if (outType == "flat") {
-// if (outputFile.size() == 0 || outputFile == "-") {
-// ChartToFlatSCXML::transform(interpreter).writeTo(std::cout);
-// } else {
-// std::ofstream outStream;
-// outStream.open(outputFile.c_str());
-// ChartToFlatSCXML::transform(interpreter).writeTo(outStream);
-// outStream.close();
-// }
-// exit(EXIT_SUCCESS);
-// }
-
-// if (outType == "min") {
-// if (outputFile.size() == 0 || outputFile == "-") {
-// ChartToMinimalSCXML::transform(interpreter).writeTo(std::cout);
-// } else {
-// std::ofstream outStream;
-// outStream.open(outputFile.c_str());
-// ChartToMinimalSCXML::transform(interpreter).writeTo(outStream);
-// outStream.close();
-// }
-// exit(EXIT_SUCCESS);
-// }
-
- if (annotatedFile.size() > 0) {
- std::ofstream outStream;
- outStream.open(annotatedFile.c_str());
- outStream << (*transformer.getImpl()->getDocument());
- outStream.close();
-
- }
-
-
- } catch (Event e) {
- std::cout << e << std::endl;
- return EXIT_FAILURE;
- } catch (const std::exception &e) {
- std::cout << e.what() << std::endl;
- return EXIT_FAILURE;
- }
-
- return EXIT_SUCCESS;
-}