event by name sync
authorVolker Birk <vb@pep.foundation>
Thu, 23 Aug 2018 10:33:59 +0200
branchsync
changeset 288126b451252f73
parent 2880 fa5b054aa4b6
child 2882 76f789a19606
event by name
sync/gen_statemachine.ysl2
test/src/engine_tests/SyncTests.cc
     1.1 --- a/sync/gen_statemachine.ysl2	Thu Aug 23 10:24:49 2018 +0200
     1.2 +++ b/sync/gen_statemachine.ysl2	Thu Aug 23 10:33:59 2018 +0200
     1.3 @@ -585,6 +585,7 @@
     1.4          // state machine
     1.5  
     1.6          const char *«@name»_state_name(int state);
     1.7 +        const char *«@name»_event_name(int event);
     1.8  
     1.9          // the state machine function is returning the next state in case of a
    1.10          // transition or None for staying
    1.11 @@ -630,6 +631,25 @@
    1.12              }
    1.13          }
    1.14  
    1.15 +        const char *«@name»_event_name(int event)
    1.16 +        {
    1.17 +            switch (event) {
    1.18 +                case None:
    1.19 +                    return "None";
    1.20 +                case Init:
    1.21 +                    return "Init";
    1.22 +        ||
    1.23 +        for "func:distinctName(state/event[not(@name='Init')])" {
    1.24 +            |>> case «@name»:
    1.25 +            |>>> return "«@name»";
    1.26 +        }
    1.27 +        ||
    1.28 +                default:
    1.29 +                    return "unknown event";
    1.30 +            }
    1.31 +        }
    1.32 +
    1.33 +
    1.34          static char *_str(int n, bool hex)
    1.35          {
    1.36              char *buf = calloc(1, 24);
     2.1 --- a/test/src/engine_tests/SyncTests.cc	Thu Aug 23 10:24:49 2018 +0200
     2.2 +++ b/test/src/engine_tests/SyncTests.cc	Thu Aug 23 10:33:59 2018 +0200
     2.3 @@ -36,7 +36,7 @@
     2.4      static int inject_sync_event(SYNC_EVENT ev, void *management)
     2.5      {
     2.6          Sync_event_t *_ev = ev;
     2.7 -        cout << "injecting event " << _ev->event << "\n";
     2.8 +        cout << "injecting event " << KeySync_event_name(_ev->event) << "\n";
     2.9          auto adapter = static_cast< Sync_Adapter *>(management);
    2.10          adapter->q.push_front(ev);
    2.11          return 0;