basic structure and skeleton
authorVolker Birk <vb@pep-project.org>
Sun, 15 May 2016 15:18:53 +0200
changeset 623533a7fcc423b
parent 622 ed6f7d40e6a7
child 624 4892dffa9e70
basic structure and skeleton
Makefile.conf
src/fsm_driver.c
src/sync_actions.c
src/sync_codec.c
src/sync_fsm.h
sync/Makefile
sync/functions.ysl2
sync/gen_actions_skeleton.ysl2
sync/gen_codec.ysl2
sync/gen_statemachine.ysl2
     1.1 --- a/Makefile.conf	Sat May 14 12:01:50 2016 +0200
     1.2 +++ b/Makefile.conf	Sun May 15 15:18:53 2016 +0200
     1.3 @@ -8,6 +8,8 @@
     1.4  # the next two lines are ignored on Windoze
     1.5  SYSTEM_DB=/usr/local/share/pEp/system.db
     1.6  PREFIX=$(HOME)
     1.7 +YML2PROC=$(HOME)/yml2/yml2proc
     1.8 +YML_HOME=$(HOME)
     1.9  
    1.10  # C makros (not environment variables) to overwrite:
    1.11  #
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/src/fsm_driver.c	Sun May 15 15:18:53 2016 +0200
     2.3 @@ -0,0 +1,12 @@
     2.4 +// Driver for DeviceState state machine
     2.5 +
     2.6 +#include <assert.h>
     2.7 +#include "sync_fsm.h"
     2.8 +
     2.9 +
    2.10 +PEP_STATUS fsm_DeviceState_inject(PEP_SESSION session, DeviceState_event event)
    2.11 +{
    2.12 +    PEP_STATUS status = PEP_STATUS_OK;
    2.13 +
    2.14 +    return status;
    2.15 +}
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/src/sync_actions.c	Sun May 15 15:18:53 2016 +0200
     3.3 @@ -0,0 +1,160 @@
     3.4 +// Actions for DeviceState state machine
     3.5 +
     3.6 +#include <assert.h>
     3.7 +#include "sync_fsm.h"
     3.8 +
     3.9 +
    3.10 +// sendBeacon() - 
    3.11 +//
    3.12 +//  params:
    3.13 +//      partner (in)        (must be NULL)
    3.14 +//
    3.15 +//  returns:
    3.16 +//      PEP_STATUS_OK or any other value on error
    3.17 +
    3.18 +PEP_STATUS sendBeacon(const Identity partner)
    3.19 +{
    3.20 +    PEP_STATUS status = PEP_STATUS_OK;
    3.21 +
    3.22 +    assert(partner == NULL);
    3.23 +    if (partner)
    3.24 +        return PEP_ILLEGAL_VALUE;
    3.25 +
    3.26 +    // working code
    3.27 +
    3.28 +
    3.29 +    return status;
    3.30 +}
    3.31 +
    3.32 +// sendHandshakeRequest() - 
    3.33 +//
    3.34 +//  params:
    3.35 +//      partner (in)        partner in sync
    3.36 +//
    3.37 +//  returns:
    3.38 +//      PEP_STATUS_OK or any other value on error
    3.39 +
    3.40 +PEP_STATUS sendHandshakeRequest(const Identity partner)
    3.41 +{
    3.42 +    PEP_STATUS status = PEP_STATUS_OK;
    3.43 +
    3.44 +    assert(partner);
    3.45 +    if (!partner)
    3.46 +        return PEP_ILLEGAL_VALUE;
    3.47 +
    3.48 +    // working code
    3.49 +
    3.50 +
    3.51 +    return status;
    3.52 +}
    3.53 +
    3.54 +// showHandshake() - 
    3.55 +//
    3.56 +//  params:
    3.57 +//      partner (in)        partner in sync
    3.58 +//
    3.59 +//  returns:
    3.60 +//      PEP_STATUS_OK or any other value on error
    3.61 +
    3.62 +PEP_STATUS showHandshake(const Identity partner)
    3.63 +{
    3.64 +    PEP_STATUS status = PEP_STATUS_OK;
    3.65 +
    3.66 +    assert(partner);
    3.67 +    if (!partner)
    3.68 +        return PEP_ILLEGAL_VALUE;
    3.69 +
    3.70 +    // working code
    3.71 +
    3.72 +
    3.73 +    return status;
    3.74 +}
    3.75 +
    3.76 +// reject() - 
    3.77 +//
    3.78 +//  params:
    3.79 +//      partner (in)        partner in sync
    3.80 +//
    3.81 +//  returns:
    3.82 +//      PEP_STATUS_OK or any other value on error
    3.83 +
    3.84 +PEP_STATUS reject(const Identity partner)
    3.85 +{
    3.86 +    PEP_STATUS status = PEP_STATUS_OK;
    3.87 +
    3.88 +    assert(partner);
    3.89 +    if (!partner)
    3.90 +        return PEP_ILLEGAL_VALUE;
    3.91 +
    3.92 +    // working code
    3.93 +
    3.94 +
    3.95 +    return status;
    3.96 +}
    3.97 +
    3.98 +// storeGroupKeys() - 
    3.99 +//
   3.100 +//  params:
   3.101 +//      partner (in)        partner in sync
   3.102 +//
   3.103 +//  returns:
   3.104 +//      PEP_STATUS_OK or any other value on error
   3.105 +
   3.106 +PEP_STATUS storeGroupKeys(const Identity partner)
   3.107 +{
   3.108 +    PEP_STATUS status = PEP_STATUS_OK;
   3.109 +
   3.110 +    assert(partner);
   3.111 +    if (!partner)
   3.112 +        return PEP_ILLEGAL_VALUE;
   3.113 +
   3.114 +    // working code
   3.115 +
   3.116 +
   3.117 +    return status;
   3.118 +}
   3.119 +
   3.120 +// sendOwnKeys() - 
   3.121 +//
   3.122 +//  params:
   3.123 +//      partner (in)        (must be NULL)
   3.124 +//
   3.125 +//  returns:
   3.126 +//      PEP_STATUS_OK or any other value on error
   3.127 +
   3.128 +PEP_STATUS sendOwnKeys(const Identity partner)
   3.129 +{
   3.130 +    PEP_STATUS status = PEP_STATUS_OK;
   3.131 +
   3.132 +    assert(partner == NULL);
   3.133 +    if (partner)
   3.134 +        return PEP_ILLEGAL_VALUE;
   3.135 +
   3.136 +    // working code
   3.137 +
   3.138 +
   3.139 +    return status;
   3.140 +}
   3.141 +
   3.142 +// transmitGroupKeys() - 
   3.143 +//
   3.144 +//  params:
   3.145 +//      partner (in)        partner in sync
   3.146 +//
   3.147 +//  returns:
   3.148 +//      PEP_STATUS_OK or any other value on error
   3.149 +
   3.150 +PEP_STATUS transmitGroupKeys(const Identity partner)
   3.151 +{
   3.152 +    PEP_STATUS status = PEP_STATUS_OK;
   3.153 +
   3.154 +    assert(partner);
   3.155 +    if (!partner)
   3.156 +        return PEP_ILLEGAL_VALUE;
   3.157 +
   3.158 +    // working code
   3.159 +
   3.160 +
   3.161 +    return status;
   3.162 +}
   3.163 +
     4.1 --- a/src/sync_codec.c	Sat May 14 12:01:50 2016 +0200
     4.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.3 @@ -1,15 +0,0 @@
     4.4 -// encoders and decoders state for DeviceGroup protocol
     4.5 -
     4.6 -#include "sync_fsm.h"
     4.7 -
     4.8 -// decoders
     4.9 -
    4.10 -void readBeacon(const char *buf, size_t size);
    4.11 -void readHandshakeRequest(const char *buf, size_t size, Identity partner);
    4.12 -void readOwnKeys(const char *buf, size_t size, Stringlist *ownKeys);
    4.13 -
    4.14 -// encoders 
    4.15 -
    4.16 -void createBeacon(const char **bufp, size_t *sizep);
    4.17 -void createHandshakeRequest(const char **bufp, size_t *sizep, Identity partner);
    4.18 -void createOwnKeys(const char **bufp, size_t *sizep, Stringlist *ownKeys);
     5.1 --- a/src/sync_fsm.h	Sat May 14 12:01:50 2016 +0200
     5.2 +++ b/src/sync_fsm.h	Sun May 15 15:18:53 2016 +0200
     5.3 @@ -7,7 +7,6 @@
     5.4  // types
     5.5  
     5.6  typedef pEp_identity * Identity;
     5.7 -typedef stringlist_t * Stringlist;
     5.8  typedef union _param { const Identity partner; const stringlist_t *keylist; } param_t;
     5.9  
    5.10  // error values
    5.11 @@ -43,15 +42,15 @@
    5.12  
    5.13  // actions
    5.14  
    5.15 -void sendBeacon(const Identity partner);
    5.16 -void sendHandshakeRequest(const Identity partner);
    5.17 -void showHandshake(const Identity partner);
    5.18 -void reject(const Identity partner);
    5.19 -void storeGroupKeys(const Identity partner);
    5.20 -void sendOwnKeys(const Identity partner);
    5.21 -void transmitGroupKeys(const Identity partner);
    5.22 +PEP_STATUS sendBeacon(const Identity partner);
    5.23 +PEP_STATUS sendHandshakeRequest(const Identity partner);
    5.24 +PEP_STATUS showHandshake(const Identity partner);
    5.25 +PEP_STATUS reject(const Identity partner);
    5.26 +PEP_STATUS storeGroupKeys(const Identity partner);
    5.27 +PEP_STATUS sendOwnKeys(const Identity partner);
    5.28 +PEP_STATUS transmitGroupKeys(const Identity partner);
    5.29  
    5.30  // driver
    5.31  
    5.32 -void fsm_DeviceState_inject(PEP_SESSION session, DeviceState_event event);
    5.33 +PEP_STATUS fsm_DeviceState_inject(PEP_SESSION session, DeviceState_event event);
    5.34  
     6.1 --- a/sync/Makefile	Sat May 14 12:01:50 2016 +0200
     6.2 +++ b/sync/Makefile	Sun May 15 15:18:53 2016 +0200
     6.3 @@ -1,15 +1,16 @@
     6.4 -all: ../src/sync_fsm.c ../src/sync_codec.c
     6.5 +include ../Makefile.conf
     6.6  
     6.7 -../src/sync_fsm.c: sync.fsm gen_statemachine.ysl2 fsm.yml2
     6.8 -	yml2proc -y gen_statemachine.ysl2 $< -o $@
     6.9 +all: ../src/sync_fsm.c
    6.10  
    6.11 -../src/sync_codec.c: sync.fsm gen_codec.ysl2 fsm.yml2
    6.12 -	yml2proc -y gen_codec.ysl2 $< -o $@
    6.13 +skeleton: ../src/sync_actions.c
    6.14  
    6.15 -sync.xml: sync.fsm fsm.yml2
    6.16 -	yml2proc -P sync.fsm -o sync.xml
    6.17 +../src/sync_actions.c: sync.fsm gen_actions_skeleton.ysl2 fsm.yml2 functions.ysl2
    6.18 +	$(YML2PROC) -y gen_actions_skeleton.ysl2 $< -o $@
    6.19 +
    6.20 +../src/sync_fsm.c: sync.fsm gen_statemachine.ysl2 fsm.yml2 functions.ysl2
    6.21 +	$(YML2PROC) -y gen_statemachine.ysl2 $< -o $@
    6.22  
    6.23  .PHONY: clean
    6.24  
    6.25  clean:
    6.26 -	rm -f *.xml ../src/sync_fsm.c
    6.27 +	rm -f *.xml *.xsl ../src/sync_fsm.*
     7.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.2 +++ b/sync/functions.ysl2	Sun May 15 15:18:53 2016 +0200
     7.3 @@ -0,0 +1,12 @@
     7.4 +// function library
     7.5 +
     7.6 +def "func:distinctName" {
     7.7 +    param "nodes", "/..";
     7.8 +    choose {
     7.9 +        when "not($nodes)"
    7.10 +            result "/..";
    7.11 +        otherwise {
    7.12 +            result "$nodes[1] | func:distinctName($nodes[position() > 1])[@name != $nodes[1]/@name]";
    7.13 +        }
    7.14 +    }
    7.15 +}
     8.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.2 +++ b/sync/gen_actions_skeleton.ysl2	Sun May 15 15:18:53 2016 +0200
     8.3 @@ -0,0 +1,73 @@
     8.4 +// generate actions skeleton
     8.5 +
     8.6 +// Copyleft (c) 2016, p≡p foundation
     8.7 +
     8.8 +// Written by Volker Birk
     8.9 +
    8.10 +include yslt.yml2
    8.11 +
    8.12 +tstylesheet {
    8.13 +    include ./functions.ysl2
    8.14 +
    8.15 +    template "/protocol/fsm" {
    8.16 +    document "../src/fsm_driver.c", "text"
    8.17 +    ||
    8.18 +    // Driver for «@name» state machine
    8.19 +
    8.20 +    #include <assert.h>
    8.21 +    #include "sync_fsm.h"
    8.22 +
    8.23 +
    8.24 +    PEP_STATUS fsm_«@name»_inject(PEP_SESSION session, «@name»_event event)
    8.25 +    {
    8.26 +        PEP_STATUS status = PEP_STATUS_OK;
    8.27 +
    8.28 +        return status;
    8.29 +    }
    8.30 +    ||
    8.31 +    ||
    8.32 +    // Actions for «@name» state machine
    8.33 +
    8.34 +    #include <assert.h>
    8.35 +    #include "sync_fsm.h"
    8.36 +
    8.37 +
    8.38 +    `` for "func:distinctName(//action)" call "action" with "action", ".";
    8.39 +
    8.40 +    ||
    8.41 +    }
    8.42 +
    8.43 +    function "action" {
    8.44 +        param "action";
    8.45 +
    8.46 +        ||
    8.47 +        // «$action/@name»() - 
    8.48 +        //
    8.49 +        //  params:
    8.50 +        `` if "parm"        | //      partner (in)        partner in sync
    8.51 +        `` if "not(parm)"   | //      partner (in)        (must be NULL)
    8.52 +        //
    8.53 +        //  returns:
    8.54 +        //      PEP_STATUS_OK or any other value on error
    8.55 +
    8.56 +        PEP_STATUS «$action/@name»(const Identity partner)
    8.57 +        {
    8.58 +            PEP_STATUS status = PEP_STATUS_OK;
    8.59 +
    8.60 +        `` if "parm"        |> assert(partner);
    8.61 +        `` if "parm"        |> if (!partner)
    8.62 +        `` if "parm"        |>> return PEP_ILLEGAL_VALUE;
    8.63 +        `` if "not(parm)"   |> assert(partner == NULL);
    8.64 +        `` if "not(parm)"   |> if (partner)
    8.65 +        `` if "not(parm)"   |>> return PEP_ILLEGAL_VALUE;
    8.66 +
    8.67 +            // working code
    8.68 +
    8.69 +
    8.70 +            return status;
    8.71 +        }
    8.72 +
    8.73 +        ||
    8.74 +    }
    8.75 +}
    8.76 +
     9.1 --- a/sync/gen_codec.ysl2	Sat May 14 12:01:50 2016 +0200
     9.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     9.3 @@ -1,84 +0,0 @@
     9.4 -// generate encoder and decoders for protocol messages
     9.5 -
     9.6 -// Copyleft (c) 2016, p≡p foundation
     9.7 -
     9.8 -include yslt.yml2
     9.9 -
    9.10 -tstylesheet {
    9.11 -
    9.12 -    key "ActionByNames", "/protocol/fsm/state/event//action", "@name";
    9.13 -    variable "UniqueActions", "/protocol/fsm/state/event//action[generate-id()=generate-id(key('ActionByNames',@name)[1])]";
    9.14 -    variable "UniqueSendActions", "$UniqueActions[starts-with(@name,'send')]";
    9.15 -
    9.16 -    template "/protocol" {
    9.17 -        ||
    9.18 -        // encoders and decoders state for «@name» protocol
    9.19 -
    9.20 -        #include "sync_fsm.h"
    9.21 -
    9.22 -        // decoders
    9.23 -
    9.24 -        ||
    9.25 -        apply "$UniqueSendActions",0 mode="proto" {
    9.26 -            with "pfx", "'read'";
    9.27 -            with "baseParms" > const char *buf, size_t size
    9.28 -        }
    9.29 -        ||
    9.30 -
    9.31 -        // encoders 
    9.32 -
    9.33 -        ||
    9.34 -        apply "$UniqueSendActions",0 mode="proto" {
    9.35 -            with "pfx", "'create'";
    9.36 -            with "baseParms" > const char **bufp, size_t *sizep
    9.37 -        }
    9.38 -        ||
    9.39 -
    9.40 -        ||
    9.41 -    }
    9.42 -
    9.43 -    def "xsl:typeOfActionParam" {
    9.44 -        param "n", "name(.)";
    9.45 -        result "ancestor::event/child::parm[child::*[position()=2 and name(.)=$n]]/child::*[position()=1]";
    9.46 -    }
    9.47 -    
    9.48 -    function "interfaces_params" {
    9.49 -        param "ifaceName";
    9.50 -        // variable "ifaceCommons", "/protocol/interface[@name = 'commons']/*";
    9.51 -        variable "ifaceParams", "$UniqueActions[@name = concat('send',$ifaceName)]/parm/*";
    9.52 -        variable "ifaceAdditions", "/protocol/interface[@name = $ifaceName]/*";
    9.53 -
    9.54 -        // if "count($ifaceCommons) != 0" > , 
    9.55 -        // for "$ifaceCommons" > «name(.)» *«name(./*)»`if "position() != last()" > ,`
    9.56 -
    9.57 -        if "count($ifaceParams) != 0" > , 
    9.58 -        for "set:distinct($ifaceParams)" {
    9.59 -            > «name(xsl:typeOfActionParam())» «name(.)»
    9.60 -            if "position() != last()" > ,
    9.61 -        }
    9.62 -
    9.63 -        if "count($ifaceAdditions) != 0" > , 
    9.64 -        for "$ifaceAdditions" > «name(.)» *«name(./*)»`if "position() != last()" > ,`
    9.65 -    }
    9.66 -
    9.67 -    template "action", mode="func_header" {
    9.68 -        param "pfx";
    9.69 -        param "baseParms";
    9.70 -        variable "ifaceName", "substring-after(@name, 'send')";
    9.71 -
    9.72 -        > void «$pfx»«$ifaceName»(«$baseParms»
    9.73 -        call("interfaces_params") with "ifaceName", "$ifaceName";
    9.74 -        > )
    9.75 -    }
    9.76 -
    9.77 -    template "action", mode="proto" {
    9.78 -        param "pfx";
    9.79 -        param "baseParms";
    9.80 -        apply ".",0 mode="func_header" {
    9.81 -            with "pfx", "$pfx" ;
    9.82 -            with "baseParms", "$baseParms" ;
    9.83 -        }
    9.84 -        | ;
    9.85 -    }
    9.86 -}
    9.87 -
    10.1 --- a/sync/gen_statemachine.ysl2	Sat May 14 12:01:50 2016 +0200
    10.2 +++ b/sync/gen_statemachine.ysl2	Sun May 15 15:18:53 2016 +0200
    10.3 @@ -7,6 +7,7 @@
    10.4  include yslt.yml2
    10.5  
    10.6  tstylesheet {
    10.7 +    include ./functions.ysl2
    10.8  
    10.9      template "/protocol/fsm" {
   10.10          document "../src/sync_fsm.h", "text"
   10.11 @@ -20,7 +21,6 @@
   10.12          // types
   10.13  
   10.14          typedef pEp_identity * Identity;
   10.15 -        typedef stringlist_t * Stringlist;
   10.16          typedef union _param { const Identity partner; const stringlist_t *keylist; } param_t;
   10.17  
   10.18          // error values
   10.19 @@ -33,22 +33,22 @@
   10.20          // states
   10.21  
   10.22          typedef enum _«@name»_state {
   10.23 -        `` for "set:distinct(state/@name)" |> «.»`if "position()!=last()" > , `
   10.24 +        `` for "func:distinctName(state)" |> «@name»`if "position()!=last()" > , `
   10.25          } «@name»_state;
   10.26  
   10.27          // events
   10.28  
   10.29          typedef enum _«@name»_event {
   10.30 -        `` for "set:distinct(state/event/@name)" |> «.»`if "position()!=last()" > , `
   10.31 +        `` for "func:distinctName(state/event)" |> «@name»`if "position()!=last()" > , `
   10.32          } «@name»_event;
   10.33  
   10.34          // actions
   10.35  
   10.36 -        `` for "set:distinct(state/event//action/@name)" | void «.»(const Identity partner);
   10.37 +        `` for "func:distinctName(//action)" | PEP_STATUS «@name»(const Identity partner);
   10.38  
   10.39          // driver
   10.40  
   10.41 -        void fsm_«@name»_inject(PEP_SESSION session, «@name»_event event);
   10.42 +        PEP_STATUS fsm_«@name»_inject(PEP_SESSION session, «@name»_event event);
   10.43  
   10.44          ||
   10.45          ||