Browse Source

sync: obey new app notification enum names, this time with corresponding actions generated

doc_update_sequoia
Edouard Tisserant 5 years ago
parent
commit
a85281fd45
9 changed files with 274 additions and 225 deletions
  1. +3
    -6
      src/sync.h
  2. +1
    -128
      src/sync_actions.c
  3. +14
    -10
      sync/devicegroup.fsm
  4. +64
    -0
      sync/gen_actions.ysl2
  5. +6
    -0
      sync/gen_statemachine.ysl2
  6. +23
    -16
      sync/generated/sync_fsm.c
  7. +5
    -6
      sync/generated/sync_fsm.h
  8. +136
    -0
      sync/generated/sync_send_actions.c
  9. +22
    -59
      sync/skeletons/sync_actions.c

+ 3
- 6
src/sync.h View File

@ -79,6 +79,7 @@ extern "C" {
typedef PEP_STATUS (*messageToSend_t)(void *obj, message *msg);
// TODO add this to generated code.
typedef enum _sync_handshake_signal {
SYNC_NOTIFY_UNDEFINED = 0,
@ -87,17 +88,13 @@ typedef enum _sync_handshake_signal {
SYNC_NOTIFY_INIT_ADD_OTHER_DEVICE,
SYNC_NOTIFY_INIT_FORM_GROUP,
// handshake process is done or was cancelled
SYNC_NOTIFY_DISMISSED,
SYNC_NOTIFY_CANCELED,
// handshake process timed out
SYNC_NOTIFY_TIMEOUT,
// handshake accepted by user
SYNC_NOTIFY_ACCEPTED_DEVICE_ADDED,
SYNC_NOTIFY_ACCEPTED_GROUP_CREATED,
SYNC_NOTIFY_ACCEPTED_GROUP_CREATED
// handshake was rejected by user
SYNC_NOTIFY_REJECTED
} sync_handshake_signal;
// notifyHandshake() - notify UI about sync handshaking process


+ 1
- 128
src/sync_actions.c View File

@ -97,7 +97,7 @@ the_end:
return result;
}
static PEP_STATUS _notifyHandshake(
PEP_STATUS _notifyHandshake(
PEP_SESSION session,
Identity partner,
sync_handshake_signal signal
@ -139,133 +139,6 @@ error:
return status;
}
// showHandshake() - trigger the handshake dialog of the application
//
// params:
// session (in) session handle
// state (in) state the state machine is in
// partner (in) partner to communicate with
//
// returns:
// PEP_STATUS_OK or any other value on error
PEP_STATUS showHandshake(
PEP_SESSION session,
DeviceState_state state,
Identity partner,
void *extra
)
{
assert(extra == NULL);
return _notifyHandshake(session, partner, SYNC_NOTIFY_INIT_ADD_OUR_DEVICE);
}
// dismissHandshake() - kill the handshake dialog of the application
//
// params:
// session (in) session handle
// state (in) state the state machine is in
// partner (in) partner to communicate with
//
// returns:
// PEP_STATUS_OK or any other value on error
PEP_STATUS dismissHandshake(
PEP_SESSION session,
DeviceState_state state,
Identity partner,
void *extra
)
{
assert(extra == NULL);
return _notifyHandshake(session, partner, SYNC_NOTIFY_DISMISSED);
}
// handshakeSuccess() - notify the application that handshake succeeded
//
// params:
// session (in) session handle
// state (in) state the state machine is in
// partner (in) partner to communicate with
//
// returns:
// PEP_STATUS_OK or any other value on error
PEP_STATUS handshakeSuccess(
PEP_SESSION session,
DeviceState_state state,
Identity partner,
void *extra
)
{
assert(extra == NULL);
return _notifyHandshake(session, partner, SYNC_NOTIFY_ACCEPTED_DEVICE_ADDED);
}
// handshakeGroupCreated() - notify the application that initial group was created
// and partner's device was included in group
//
// params:
// session (in) session handle
// state (in) state the state machine is in
// partner (in) partner to communicate with
//
// returns:
// PEP_STATUS_OK or any other value on error
PEP_STATUS handshakeGroupCreated(
PEP_SESSION session,
DeviceState_state state,
Identity partner,
void *extra
)
{
assert(extra == NULL);
return _notifyHandshake(session, partner, SYNC_NOTIFY_ACCEPTED_GROUP_CREATED);
}
// handshakeDeviceAdded() - notify the application that partner's device was added to group
//
// params:
// session (in) session handle
// state (in) state the state machine is in
// partner (in) partner to communicate with
//
// returns:
// PEP_STATUS_OK or any other value on error
PEP_STATUS handshakeDeviceAdded(
PEP_SESSION session,
DeviceState_state state,
Identity partner,
void *extra
)
{
assert(extra == NULL);
return _notifyHandshake(session, partner, SYNC_NOTIFY_ACCEPTED_DEVICE_ADDED);
}
// handshakeFailure() - notify the application that handshake failed
//
// params:
// session (in) session handle
// state (in) state the state machine is in
// partner (in) partner to communicate with
//
// returns:
// PEP_STATUS_OK or any other value on error
PEP_STATUS handshakeFailure(
PEP_SESSION session,
DeviceState_state state,
Identity partner,
void *extra
)
{
assert(extra == NULL);
return _notifyHandshake(session, partner, SYNC_NOTIFY_TIMEOUT);
}
// acceptHandshake() - stores acception of partner
//
// params:


+ 14
- 10
sync/devicegroup.fsm View File

@ -41,8 +41,14 @@ protocol DeviceGroup {
}
state HandshakingSole timeout=600 (Identity expected) {
on Init
do showHandshake(partner);
on Init{
if keyElectionWon(partner) { // an already existing group
do notifyInitFormGroup(partner);
} else {
do notifyInitAddOurDevice(partner);
}
}
on HandshakeRejected(Identity partner) {
do rejectHandshake(partner); // stores rejection of partner
go Sole;
@ -52,14 +58,14 @@ protocol DeviceGroup {
if keyElectionWon(partner) { // an already existing group
// always wins
do sendGroupKeys(partner);
do handshakeGroupCreated(partner);
do notifyAcceptedGroupCreated(partner);
go Grouped;
}
go WaitForGroupKeysSole(partner);
}
on Cancel go Sole;
on Timeout {
do dismissHandshake(expected);
do notifyTimeout(expected);
go Sole;
}
}
@ -68,11 +74,11 @@ protocol DeviceGroup {
on GroupKeys(Identity partner, Stringlist keys) {
// TODO ensure partner == expected
do storeGroupKeys(partner, keys);
do handshakeSuccess(partner);
do notifyAcceptedDeviceAdded(partner);
go Grouped;
}
on Timeout {
do handshakeFailure(expected);
do notifyTimeout(expected);
go Sole;
}
}
@ -98,7 +104,7 @@ protocol DeviceGroup {
state HandshakingGrouped timeout=600 (Identity expected) {
on Init
do showHandshake(partner);
do notifyInitAddOurDevice(partner);
on HandshakeRejected(Identity partner) {
do rejectHandshake(partner); // stores rejection of partner
go Grouped;
@ -109,12 +115,10 @@ protocol DeviceGroup {
// an already existing group always wins
do sendGroupKeys(partner);
do handshakeDeviceAdded(partner);
go Grouped;
}
on Timeout {
do handshakeFailure(expected);
do notifyTimeout(expected);
go Grouped;
}
}


+ 64
- 0
sync/gen_actions.ysl2 View File

@ -41,6 +41,22 @@ tstylesheet {
with "action", ".",
with "fsm", "$name",
with "filename", "$filename";
||
PEP_STATUS _notifyHandshake(
PEP_SESSION session,
Identity partner,
sync_handshake_signal signal
);
||
for "func:distinctName(//action)"
if "substring(@name, 1, 6) = 'notify'"
call "notify_action"
with "action", ".",
with "fsm", "$name",
with "filename", "$filename";
}
template "fsm", mode=other document "skeletons/{@filename}_actions.c", "text" {
@ -217,5 +233,53 @@ tstylesheet {
||
}
function "UnCamelUp" {
param "text";
const "tokens", "str:tokenize($text, '')";
for "$tokens" {
choose {
when "contains('ABCDEFGHIJKLMNOPQRSTUVWXYZ',.)" > _«.»
otherwise value "yml:ucase(.)";
}
}
}
function "notify_action" {
param "action";
param "fsm";
param "filename", "'###'";
const "name", "substring($action/@name, 7, 255)";
const "uname" call "UnCamelUp" with "text", "$name";
||
// «$action/@name»() - notify «$name» to app
//
// params:
// session (in) session handle
// state (in) state the state machine is in
// partner (in) partner to communicate with
//
// returns:
// PEP_STATUS_OK or any other value on error
PEP_STATUS «$action/@name»(
PEP_SESSION session,
«$fsm»_state state,
Identity partner,
void *extra
)
{
assert(session && state);
assert(extra == NULL);
if (!(session && state && extra == NULL))
return PEP_ILLEGAL_VALUE;
return _notifyHandshake(session, partner, SYNC_NOTIFY«$uname»);
}
||
}
}

+ 6
- 0
sync/gen_statemachine.ysl2 View File

@ -266,6 +266,12 @@ tstylesheet {
| if (cond_result) {
apply "action|transition|condition";
| }
const "else", "./following-sibling::*[position()=1][name(.)='else']";
if "$else" {
| else {
apply "$else/action|transition|condition";
| }
}
}
template "parm" choose {


+ 23
- 16
sync/generated/sync_fsm.c View File

@ -89,11 +89,23 @@ DeviceState_state fsm_DeviceState(
switch (event) {
case Init:
{
status = showHandshake(session, state, partner, NULL);
if (status == PEP_OUT_OF_MEMORY)
return (int) invalid_out_of_memory;
if (status != PEP_STATUS_OK)
return (int) invalid_action;
cond_result = keyElectionWon(session, partner);
if (cond_result < 0)
return cond_result;
if (cond_result) {
status = notifyInitFormGroup(session, state, partner, NULL);
if (status == PEP_OUT_OF_MEMORY)
return (int) invalid_out_of_memory;
if (status != PEP_STATUS_OK)
return (int) invalid_action;
}
else {
status = notifyInitAddOurDevice(session, state, partner, NULL);
if (status == PEP_OUT_OF_MEMORY)
return (int) invalid_out_of_memory;
if (status != PEP_STATUS_OK)
return (int) invalid_action;
}
break;
}
case HandshakeRejected:
@ -125,7 +137,7 @@ DeviceState_state fsm_DeviceState(
return (int) invalid_out_of_memory;
if (status != PEP_STATUS_OK)
return (int) invalid_action;
status = handshakeGroupCreated(session, state, partner, NULL);
status = notifyAcceptedGroupCreated(session, state, partner, NULL);
if (status == PEP_OUT_OF_MEMORY)
return (int) invalid_out_of_memory;
if (status != PEP_STATUS_OK)
@ -153,7 +165,7 @@ DeviceState_state fsm_DeviceState(
}
case Timeout:
{
status = dismissHandshake(session, state, expected, NULL);
status = notifyTimeout(session, state, expected, NULL);
if (status == PEP_OUT_OF_MEMORY)
return (int) invalid_out_of_memory;
if (status != PEP_STATUS_OK)
@ -182,7 +194,7 @@ DeviceState_state fsm_DeviceState(
return (int) invalid_out_of_memory;
if (status != PEP_STATUS_OK)
return (int) invalid_action;
status = handshakeSuccess(session, state, partner, NULL);
status = notifyAcceptedDeviceAdded(session, state, partner, NULL);
if (status == PEP_OUT_OF_MEMORY)
return (int) invalid_out_of_memory;
if (status != PEP_STATUS_OK)
@ -195,7 +207,7 @@ DeviceState_state fsm_DeviceState(
}
case Timeout:
{
status = handshakeFailure(session, state, expected, NULL);
status = notifyTimeout(session, state, expected, NULL);
if (status == PEP_OUT_OF_MEMORY)
return (int) invalid_out_of_memory;
if (status != PEP_STATUS_OK)
@ -291,7 +303,7 @@ DeviceState_state fsm_DeviceState(
switch (event) {
case Init:
{
status = showHandshake(session, state, partner, NULL);
status = notifyInitAddOurDevice(session, state, partner, NULL);
if (status == PEP_OUT_OF_MEMORY)
return (int) invalid_out_of_memory;
if (status != PEP_STATUS_OK)
@ -319,11 +331,6 @@ DeviceState_state fsm_DeviceState(
if (status != PEP_STATUS_OK)
return (int) invalid_action;
status = sendGroupKeys(session, state, partner, NULL);
if (status == PEP_OUT_OF_MEMORY)
return (int) invalid_out_of_memory;
if (status != PEP_STATUS_OK)
return (int) invalid_action;
status = handshakeDeviceAdded(session, state, partner, NULL);
if (status == PEP_OUT_OF_MEMORY)
return (int) invalid_out_of_memory;
if (status != PEP_STATUS_OK)
@ -336,7 +343,7 @@ DeviceState_state fsm_DeviceState(
}
case Timeout:
{
status = handshakeFailure(session, state, expected, NULL);
status = notifyTimeout(session, state, expected, NULL);
if (status == PEP_OUT_OF_MEMORY)
return (int) invalid_out_of_memory;
if (status != PEP_STATUS_OK)


+ 5
- 6
sync/generated/sync_fsm.h View File

@ -74,19 +74,18 @@ typedef enum _DeviceState_event {
PEP_STATUS sendBeacon(PEP_SESSION session, DeviceState_state state, Identity partner, void *extra);
PEP_STATUS sendHandshakeRequest(PEP_SESSION session, DeviceState_state state, Identity partner, void *extra);
PEP_STATUS showHandshake(PEP_SESSION session, DeviceState_state state, Identity partner, void *extra);
PEP_STATUS notifyInitFormGroup(PEP_SESSION session, DeviceState_state state, Identity partner, void *extra);
PEP_STATUS notifyInitAddOurDevice(PEP_SESSION session, DeviceState_state state, Identity partner, void *extra);
PEP_STATUS rejectHandshake(PEP_SESSION session, DeviceState_state state, Identity partner, void *extra);
PEP_STATUS acceptHandshake(PEP_SESSION session, DeviceState_state state, Identity partner, void *extra);
PEP_STATUS sendGroupKeys(PEP_SESSION session, DeviceState_state state, Identity partner, void *extra);
PEP_STATUS handshakeGroupCreated(PEP_SESSION session, DeviceState_state state, Identity partner, void *extra);
PEP_STATUS dismissHandshake(PEP_SESSION session, DeviceState_state state, Identity partner, void *extra);
PEP_STATUS notifyAcceptedGroupCreated(PEP_SESSION session, DeviceState_state state, Identity partner, void *extra);
PEP_STATUS notifyTimeout(PEP_SESSION session, DeviceState_state state, Identity partner, void *extra);
PEP_STATUS storeGroupKeys(PEP_SESSION session, DeviceState_state state, Identity partner, void *extra);
PEP_STATUS handshakeSuccess(PEP_SESSION session, DeviceState_state state, Identity partner, void *extra);
PEP_STATUS handshakeFailure(PEP_SESSION session, DeviceState_state state, Identity partner, void *extra);
PEP_STATUS notifyAcceptedDeviceAdded(PEP_SESSION session, DeviceState_state state, Identity partner, void *extra);
PEP_STATUS enterGroup(PEP_SESSION session, DeviceState_state state, Identity partner, void *extra);
PEP_STATUS sendGroupUpdate(PEP_SESSION session, DeviceState_state state, Identity partner, void *extra);
PEP_STATUS sendUpdateRequest(PEP_SESSION session, DeviceState_state state, Identity partner, void *extra);
PEP_STATUS handshakeDeviceAdded(PEP_SESSION session, DeviceState_state state, Identity partner, void *extra);
// event injector


+ 136
- 0
sync/generated/sync_send_actions.c View File

@ -255,3 +255,139 @@ error:
return status;
}
PEP_STATUS _notifyHandshake(
PEP_SESSION session,
Identity partner,
sync_handshake_signal signal
);
// notifyInitFormGroup() - notify InitFormGroup to app
//
// params:
// session (in) session handle
// state (in) state the state machine is in
// partner (in) partner to communicate with
//
// returns:
// PEP_STATUS_OK or any other value on error
PEP_STATUS notifyInitFormGroup(
PEP_SESSION session,
DeviceState_state state,
Identity partner,
void *extra
)
{
assert(session && state);
assert(extra == NULL);
if (!(session && state && extra == NULL))
return PEP_ILLEGAL_VALUE;
return _notifyHandshake(session, partner, SYNC_NOTIFY_INIT_FORM_GROUP);
}
// notifyInitAddOurDevice() - notify InitAddOurDevice to app
//
// params:
// session (in) session handle
// state (in) state the state machine is in
// partner (in) partner to communicate with
//
// returns:
// PEP_STATUS_OK or any other value on error
PEP_STATUS notifyInitAddOurDevice(
PEP_SESSION session,
DeviceState_state state,
Identity partner,
void *extra
)
{
assert(session && state);
assert(extra == NULL);
if (!(session && state && extra == NULL))
return PEP_ILLEGAL_VALUE;
return _notifyHandshake(session, partner, SYNC_NOTIFY_INIT_ADD_OUR_DEVICE);
}
// notifyAcceptedGroupCreated() - notify AcceptedGroupCreated to app
//
// params:
// session (in) session handle
// state (in) state the state machine is in
// partner (in) partner to communicate with
//
// returns:
// PEP_STATUS_OK or any other value on error
PEP_STATUS notifyAcceptedGroupCreated(
PEP_SESSION session,
DeviceState_state state,
Identity partner,
void *extra
)
{
assert(session && state);
assert(extra == NULL);
if (!(session && state && extra == NULL))
return PEP_ILLEGAL_VALUE;
return _notifyHandshake(session, partner, SYNC_NOTIFY_ACCEPTED_GROUP_CREATED);
}
// notifyTimeout() - notify Timeout to app
//
// params:
// session (in) session handle
// state (in) state the state machine is in
// partner (in) partner to communicate with
//
// returns:
// PEP_STATUS_OK or any other value on error
PEP_STATUS notifyTimeout(
PEP_SESSION session,
DeviceState_state state,
Identity partner,
void *extra
)
{
assert(session && state);
assert(extra == NULL);
if (!(session && state && extra == NULL))
return PEP_ILLEGAL_VALUE;
return _notifyHandshake(session, partner, SYNC_NOTIFY_TIMEOUT);
}
// notifyAcceptedDeviceAdded() - notify AcceptedDeviceAdded to app
//
// params:
// session (in) session handle
// state (in) state the state machine is in
// partner (in) partner to communicate with
//
// returns:
// PEP_STATUS_OK or any other value on error
PEP_STATUS notifyAcceptedDeviceAdded(
PEP_SESSION session,
DeviceState_state state,
Identity partner,
void *extra
)
{
assert(session && state);
assert(extra == NULL);
if (!(session && state && extra == NULL))
return PEP_ILLEGAL_VALUE;
return _notifyHandshake(session, partner, SYNC_NOTIFY_ACCEPTED_DEVICE_ADDED);
}

+ 22
- 59
sync/skeletons/sync_actions.c View File

@ -8,7 +8,7 @@
#include "../asn.1/DeviceGroup-Protocol.h"
// showHandshake() -
// notifyInitFormGroup() -
//
// params:
// session (in) session handle
@ -18,7 +18,7 @@
// returns:
// PEP_STATUS_OK or any other value on error
PEP_STATUS showHandshake(
PEP_STATUS notifyInitFormGroup(
PEP_SESSION session,
DeviceState_state state,
Identity partner,
@ -45,7 +45,7 @@ error:
}
// rejectHandshake() -
// notifyInitAddOurDevice() -
//
// params:
// session (in) session handle
@ -55,7 +55,7 @@ error:
// returns:
// PEP_STATUS_OK or any other value on error
PEP_STATUS rejectHandshake(
PEP_STATUS notifyInitAddOurDevice(
PEP_SESSION session,
DeviceState_state state,
Identity partner,
@ -82,7 +82,7 @@ error:
}
// acceptHandshake() -
// rejectHandshake() -
//
// params:
// session (in) session handle
@ -92,7 +92,7 @@ error:
// returns:
// PEP_STATUS_OK or any other value on error
PEP_STATUS acceptHandshake(
PEP_STATUS rejectHandshake(
PEP_SESSION session,
DeviceState_state state,
Identity partner,
@ -119,7 +119,7 @@ error:
}
// handshakeGroupCreated() -
// acceptHandshake() -
//
// params:
// session (in) session handle
@ -129,7 +129,7 @@ error:
// returns:
// PEP_STATUS_OK or any other value on error
PEP_STATUS handshakeGroupCreated(
PEP_STATUS acceptHandshake(
PEP_SESSION session,
DeviceState_state state,
Identity partner,
@ -156,7 +156,7 @@ error:
}
// dismissHandshake() -
// notifyAcceptedGroupCreated() -
//
// params:
// session (in) session handle
@ -166,7 +166,7 @@ error:
// returns:
// PEP_STATUS_OK or any other value on error
PEP_STATUS dismissHandshake(
PEP_STATUS notifyAcceptedGroupCreated(
PEP_SESSION session,
DeviceState_state state,
Identity partner,
@ -176,8 +176,8 @@ PEP_STATUS dismissHandshake(
PEP_STATUS status = PEP_STATUS_OK;
assert(session);
assert(!partner);
if (!(session && !partner))
assert(partner);
if (!(session && partner))
return PEP_ILLEGAL_VALUE;
// working code
@ -193,7 +193,7 @@ error:
}
// storeGroupKeys() -
// notifyTimeout() -
//
// params:
// session (in) session handle
@ -203,7 +203,7 @@ error:
// returns:
// PEP_STATUS_OK or any other value on error
PEP_STATUS storeGroupKeys(
PEP_STATUS notifyTimeout(
PEP_SESSION session,
DeviceState_state state,
Identity partner,
@ -213,8 +213,8 @@ PEP_STATUS storeGroupKeys(
PEP_STATUS status = PEP_STATUS_OK;
assert(session);
assert(partner);
if (!(session && partner))
assert(!partner);
if (!(session && !partner))
return PEP_ILLEGAL_VALUE;
// working code
@ -230,7 +230,7 @@ error:
}
// handshakeSuccess() -
// storeGroupKeys() -
//
// params:
// session (in) session handle
@ -240,7 +240,7 @@ error:
// returns:
// PEP_STATUS_OK or any other value on error
PEP_STATUS handshakeSuccess(
PEP_STATUS storeGroupKeys(
PEP_SESSION session,
DeviceState_state state,
Identity partner,
@ -267,7 +267,7 @@ error:
}
// handshakeFailure() -
// notifyAcceptedDeviceAdded() -
//
// params:
// session (in) session handle
@ -277,7 +277,7 @@ error:
// returns:
// PEP_STATUS_OK or any other value on error
PEP_STATUS handshakeFailure(
PEP_STATUS notifyAcceptedDeviceAdded(
PEP_SESSION session,
DeviceState_state state,
Identity partner,
@ -287,8 +287,8 @@ PEP_STATUS handshakeFailure(
PEP_STATUS status = PEP_STATUS_OK;
assert(session);
assert(!partner);
if (!(session && !partner))
assert(partner);
if (!(session && partner))
return PEP_ILLEGAL_VALUE;
// working code
@ -340,40 +340,3 @@ error:
return status;
}
// handshakeDeviceAdded() -
//
// params:
// session (in) session handle
// state (in) state the state machine is in
// partner (in) partner to communicate with
//
// returns:
// PEP_STATUS_OK or any other value on error
PEP_STATUS handshakeDeviceAdded(
PEP_SESSION session,
DeviceState_state state,
Identity partner,
void *extra
)
{
PEP_STATUS status = PEP_STATUS_OK;
assert(session);
assert(partner);
if (!(session && partner))
return PEP_ILLEGAL_VALUE;
// working code
// free extra
return status;
enomem:
status = PEP_OUT_OF_MEMORY;
error:
// free extra
return status;
}

Loading…
Cancel
Save