Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
ldltools committed Mar 28, 2019
2 parents ddd5e84 + 3f82f52 commit e20dca0
Show file tree
Hide file tree
Showing 99 changed files with 3,231 additions and 616 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ _build/
tmp/
trash/
obsolete/
CHANGES.html
README.html
.DS_Store
*~
Expand Down
16 changes: 12 additions & 4 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
# v0.12.0rc

- **new** [scxmlrun-all](tools/runall):
run several SCXML processes (along with generic MQTT processes) in parallel.

- add `*_mqtt.conf` for testing composite SCXML processes connected via MQTT.
- update/adjust examples

# v0.11.0 (2018-12-27)

- [new] introduce _"event repeater"_ (invoked with "-r") which transparently transmits incoming events without any interpretation.
- **new** introduce _"event repeater"_ (activated by: `scxmlrun -r`) which relays incoming events to elsewhere.

- add/update examples
- add `*.conf` files for testing with [shelltest](https://github.com/simonmichael/shelltestrunner)
- add man page (`man scxmlrun`)
- add `*.conf` files for unit-testing using [shelltest](https://github.com/simonmichael/shelltestrunner)
- add man page (for `man scxmlrun`)

# v0.10.0 (2018-11-08)

- [new] introduce JS functions: `SCXML.raise` and `SCXML.send`
- **new** introduce JS functions: `SCXML.raise` and `SCXML.send`

- add examples: microwave, calc (with web ui), traffic-control, and blackjack
- add examples: voting and vulnerable
Expand Down
51 changes: 46 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ RUN echo "dash dash/sh boolean false" | debconf-set-selections;\
dpkg-reconfigure -f noninteractive dash;\
echo "/usr/local/lib" > /etc/ld.so.conf.d/usr-local-lib.conf
RUN apt-get update;\
apt-get install -y build-essential g++ flex bison gawk;\
apt-get install -y build-essential g++ flex bison gawk jq;\
apt-get install -y file rsync wget net-tools nmap

# Qt5
Expand All @@ -33,17 +33,17 @@ RUN version=5.9.5;\
# JSON
RUN apt-get install -y nlohmann-json-dev

# MQTT
RUN apt-get install -y mosquitto mosquitto-clients libmosquitto-dev
RUN dir=/etc/mosquitto/conf.d; conf=${dir}/websockets.conf;\
# MQTT w. the WebSocket-bridge functionality activated
RUN apt-get install -y mosquitto mosquitto-clients libmosquitto-dev;\
dir=/etc/mosquitto/conf.d; conf=${dir}/websockets.conf;\
test -d $dir -a ! -f $conf &&\
echo -e "listener 1883\nlistener 9001\nprotocol websockets" > $conf &&\
service mosquitto restart

# SCXMLRUN
ADD . /root/scxmlrun
WORKDIR /root/scxmlrun
RUN make && make install
RUN make && PREFIX=/usr/local make install

#
WORKDIR /root
Expand All @@ -52,3 +52,44 @@ CMD ["/bin/bash"]
# MQTT/Websocket ports
EXPOSE 1883
EXPOSE 9001

# ====================
# final image
# ====================
FROM ubuntu:18.04

RUN echo "dash dash/sh boolean false" | debconf-set-selections;\
dpkg-reconfigure -f noninteractive dash;\
echo "/usr/local/lib" > /etc/ld.so.conf.d/usr-local-lib.conf;\
apt-get update

# Qt5
RUN apt-get install -y libqt5core5a libqt5network5 libqt5qml5

# QtSCXML
WORKDIR /usr/lib/x86_64-linux-gnu/
COPY --from=builder /usr/lib/x86_64-linux-gnu/libQt5Scxml.so.5.9.5 .
RUN ln -s libQt5Scxml.so.5.9.5 libQt5Scxml.so.5.9;\
ln -s libQt5Scxml.so.5.9.5 libQt5Scxml.so.5;\
ln -s libQt5Scxml.so.5.9.5 libQt5Scxml.so

# MQTT
RUN apt-get install -y mosquitto mosquitto-clients;\
dir=/etc/mosquitto/conf.d; conf=${dir}/websockets.conf;\
test -d $dir -a ! -f $conf &&\
echo -e "listener 1883\nlistener 9001\nprotocol websockets" > $conf

# SCXMLRUN
COPY --from=builder /usr/local /usr/local
RUN ldconfig

# examples & tests
ADD examples /root/examples
ADD tests /root/tests
RUN apt-get install -y make gawk jq shelltestrunner

WORKDIR /root
CMD ["/bin/bash"]

# MQTT/Websocket ports
EXPOSE 1883 9001
68 changes: 46 additions & 22 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# $Id: $
# $Id: Makefile,v 1.1 2019/03/27 02:33:58 sato Exp sato $

PREFIX ?= /usr/local

SUBDIRS = src examples tests docs
SUBDIRS = src examples tests docs

all::
for d in $(SUBDIRS); do $(MAKE) -C $$d $@; done
Expand All @@ -18,27 +18,51 @@ clean::
veryclean:: clean
rm -rf _build/*

# docker
DOCKER_REPO = ldltools/scxmlrun
SHELL := /bin/bash
VERSION = $(shell echo -e '\#include "src/version.hpp"\nSCXMLRUN_VERSION' | cpp -P | sed 's/\"//g')

.PHONY: $(DOCKER_REPO)-dev $(DOCKER_REPO)

$(DOCKER_REPO)-dev:
docker build --target builder -t $(DOCKER_REPO)-dev .
$(DOCKER_REPO):
docker build -t $(DOCKER_REPO) .

docker-build: docker-build-$(DOCKER_REPO)
docker-run: check-latest-$(DOCKER_REPO)
# docker run -it --rm $(DOCKER_REPO)
docker run -d --rm $(DOCKER_REPO) /usr/sbin/mosquitto -c /etc/mosquitto/mosquitto.conf
container=$$(docker ps -l --format '{{.ID}}');\
docker exec -it $$container /bin/bash;\
docker exec $$container pkill mosquitto

#
define GENRULES
docker-build-all:: docker-build-$(1)
docker-build-$(1): $(1)

docker-tag:: docker-tag-$(1)
docker-tag-$(1): check-latest-$(1) docker-untag-$(1)
docker tag $(1):latest $(1):$$(VERSION)
docker rmi $(1):latest

docker-untag:: docker-untag-$(1)
docker-untag-$(1): check-latest-$(1)
@docker images --format "{{.Repository}}:{{.Tag}}" | grep -q "$(1):$$(VERSION)" && docker rmi $(1):$$(VERSION) || true

check-latest-$(1):
@docker images --format "{{.Repository}}:{{.Tag}}" | grep -q "$(1):latest" || { echo "** image \"$(1):latest\" not found"; exit 1; }
endef
$(foreach repo,$(DOCKER_REPO)-dev $(DOCKER_REPO),$(eval $(call GENRULES,$(repo))))

#
GITHOME ?= $(HOME)/git/github.com/ldltools/scxmlrun
rsync:: clean
test -d $(GITHOME) || exit 1
rsync -avzop --exclude=_build --exclude=.git --exclude=out --exclude=obsolete --exclude=node_modules ./ $(GITHOME)
tar: veryclean
(dir=`basename $$PWD`; cd ..; tar cvJf scxmlrun`date +%y%m%d`.tar.xz --exclude=.git --exclude=_build --exclude=RCS --exclude=obsolete $$dir)

# docker
DOCKER_IMAGE = ldltools/scxmlrun
.PHONY: $(DOCKER_IMAGE)-dev $(DOCKER_IMAGE)
$(DOCKER_IMAGE)-dev:
docker images | grep -q '^ldltools/ldlsat-dev' || exit 1
docker images | grep -q "^$@ " && { echo "** $@ exists"; exit 0; } ||\
docker build --target builder -t $@ .
$(DOCKER_IMAGE):
docker images | grep -q '^ldltools/ldlsat-dev' || exit 1
docker images | grep -q "^$@ " && { echo "** $@ exists"; exit 0; } ||\
docker build -t $@ .

docker-build-all: $(DOCKER_IMAGE)-dev
docker-build: $(DOCKER_IMAGE)-dev
docker-run: $(DOCKER_IMAGE)-dev
docker run -it --rm $<
#
GITHOME ?= $(HOME)/git/github.com/ldltools/scxmlrun
rsync: clean
test -d $(GITHOME) || exit 1
rsync -avzop --exclude=_build --exclude=.git --exclude=out --exclude=obsolete --exclude=node_modules ./ $(GITHOME)
23 changes: 16 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,24 @@ hello
## Reading event(s) via MQTT

```
$ scxmlrun echo.scxml --sub echo
$ scxmlrun echo.scxml --sub echo &
$ mosquitto_pub -t echo -m '{"event":{"name":"echo","data":"world"}}'
world
```

Check out [more examples](examples/README.md) if you are interested.
For the usage of _scxmlrun_, see [the man page](docs/man/scxmlrun.man)
To see how SCXML processes interact with each other via MQTT,
take a look at the [ping\_pong](examples/ping_pong/README.md) example.

To browse examples,
check out [this list](examples/README.md).
For the usage of _scxmlrun_, see [the man page](docs/man/scxmlrun.html)
which will be accessible through `man scxmlrun` after installation.

# Installation on Docker

- run `make docker-build` to build a new docker image for scxmlrun
- run `make docker-run` to enter into the image
- run `make docker-run` to spawn a container and enter into it
- (in the container, try `make -C /root/tests test`)

# Installation on Debian/Ubuntu

Expand Down Expand Up @@ -72,13 +77,17 @@ which will be accessible through `man scxmlrun` after installation.
run: `apt-get install nlohmann-json-dev`

## Build
- run: `make && make install` in this directory.
- run: `make && make install` in the top directory.

## Testing

- run: `make -C ./tests test` once installation is done.
Once installation is done, try the following.

- run: `make -C ./tests test`

- run: `make -C ./tests test-mqtt`

(You may need to install [shelltest](https://github.com/simonmichael/shelltestrunner).)
Note: you may need to install [shelltest](https://github.com/simonmichael/shelltestrunner) (by running `apt-get install shelltestrunner`).

# Installation on macOS/Darwin

Expand Down
34 changes: 26 additions & 8 deletions docs/ethereum.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,42 @@
This memo explains how to compile, deploy, and run smart contracts on a local ethereum network.
It also discusses event transmission from Ethereum to SCXML statecharts running with `scxmlrun`.
It also discusses event transmission from Ethereum to SCXML processes (run by `scxmlrun`).

## [Ganache](https://truffleframework.com/ganache): local ethereum network for testing
## Prerequisites

### [Truffle](https://truffleframework.com/) (Framework for Solidity)

```
$ npm install -g ganache-cli
$ ganache-cli &
$ npm install -g truffle
```

This launches a new local ethereum network (at port 7545 by default).
### [Ganache](https://truffleframework.com/ganache): local ethereum network for testing

```
$ npm install -g ganache-cli
```

## Contract compilation and deployment
## Compilation & Deployment

### [Truffle](https://truffleframework.com/) (Solidity)
Compose a contract in Solidity, and compile & deploy it in the following manner.

```
$ truffle compile && truffle deploy
```

### [web3](https://github.com/ethereum/web3.js/)
## Testing

Compose test scripts using [web3](https://github.com/ethereum/web3.js/).
Then, launch a new local ethereum network (at port 7545 by default).

```
$ ganache-cli &
```

Then, run the test scripts.

```
$ truffle test
```

## Connection between Ethereum and MQTT

Expand Down
8 changes: 7 additions & 1 deletion docs/man/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,15 @@ SUBDIRS =

%.man: %.tex
latex2man $< $@
%.html: %.tex
latex2man -H: $< $@

COMMANDS = scxmlrun
MANPAGES = $(COMMANDS:%=%.man)
HTMLPAGES = $(COMMANDS:%=%.html)

MANPAGES = scxmlrun.man
man: $(MANPAGES)
html: $(HTMLPAGES)

install:: all
@dir=$(PREFIX)/share/man/man1; mkdir -p $$dir && test -w $$dir || exit 1
Expand Down
Loading

0 comments on commit e20dca0

Please sign in to comment.