Skip to content

alexzhornyak/UscxmlCLib

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

90 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GitHub Source SCXML Wiki SCXML Editor Examples Forum

intro

State Machines in C++ Builder, Delphi

The main objective of the project is to execute dynamic SCXML state charts in C++ Builder by using such a great library as USCXML. But the problem is that USCXML source code can not be compiled by Borland C++ Compiler (not full C11 support, compiler bugs etc). We have an option to use uscxml-transformer application for transpiling SCXML source code to ANSI-C. But in this case you have to compile application every time once you've made corrections to state chart. The solution seems to have a common library wrapper with only C-functions, which could be executed on all versions of C++ Builder.

UscxmlCLib consists of only 1 lib and 1 header which should be added to C++ Builder to start executing state charts.

Supported Operating System

Windows 7, Windows 8, Windows 10

Supported Compilers for building UscxmlCLib from source code

MSVC 2015 SP3

Supported Compilers for using UscxmlCLib.dll

UscxmlCLib\Lib\UscxmlCLib_borland.lib - for Borland C++ Compiler (tests were performed on C++ Builder 2010, C++ Builder XE7)

UscxmlCLib\Lib\UscxmlCLib.lib - for MSVC 2015 SP3

Installation

  1. Install Visual C++ Redistributable for Visual Studio 2015 SP3

  2. Put UscxmlCLib\Bin binaries to Windows search path or add dir with binaries to PATH environment settings

Build from source code

There will be special article

Getting Started

Let's start 'Hello, world' example in C++ Builder

hello_world

  1. Add library to project
#include "UscxmlCLib.h"

#pragma comment(lib,"UscxmlCLib_borland.lib")
  1. Set callbacks from interpreter and notifiers for main thread
class TLogNotify : public TIdNotify {
	const UnicodeString FMessage;

protected:
	virtual void __fastcall DoNotify(void) {
		FormHelloWorld->Memo1->Lines->Add(FMessage);
	}

public:
	__fastcall TLogNotify(const UnicodeString &sMsg) : FMessage(sMsg) {
	}
};

void __stdcall OnInterpreterLogCallback(const UsclibInterpreter *AInterpreter, const int nSeverity, const char *chMessage, void *AUser) {
	(new TLogNotify(chMessage))->Notify();
}
  1. Work with interprter
if (USCLIB_SUCCESS != usclib_OpenInterpreter(&g_Interpreter, 0, 0, 0))
	throw Exception(usclib_GetLastError());

usclib_RegisterLogCallback(g_Interpreter, OnInterpreterLogCallback, NULL);

if (USCLIB_SUCCESS != usclib_StartInterpreter(g_Interpreter, g_chScxml, USCLIB_SCXML_AS_TEXT))
	throw Exception(usclib_GetLastError());

if (USCLIB_SUCCESS != usclib_CloseInterpreter(g_Interpreter))
	throw Exception(usclib_GetLastError());

Output

image

Library Usage Chart

LibChart

Licensing

UscxmlCLib itself is distributed under under the terms of the BSD 3-Clause License but it include external components with their own licensies

Project License Comment
uSCXML Simplified BSD license This wrapper mostly based on uSCXML original SDK
libcurl MIT/X derivate Used in uSCXML to fetch remote content
Xerces-C++ Apache v2 XML parser and DOM implementation
libevent 3-clause BSD Delayed event queues
uriparser New BSD Referring and resolving URIs
Lua Under the terms of the MIT license Lua Data Model
JavaScriptCore Under the LGPL and BSD licenses EcmaScript Data Model

SCXML Standard Compliance

Almost the same as uSCXML original with some restrictions. Run W3C testing application to get more info TesterW3C

DataModels supported

  1. NULL
  2. Lua
  3. Luavia (Lua datamodel with some non-standard extensions to increase state chart performance)
  4. EcmaScript Based on JavaScriptCore binaries

Examples

After installation you are able to start ready-to-use examples.

Take special look at KT76C Transponder Example!

It has ZERO lines of device logic in C++! Just connected GUI controls!

KT76C_orig

KT76C_Logic

KT76C_example

TOP GitHub Source SCXML Wiki SCXML Editor Examples Forum