src/sync.c
branchkeysync
changeset 1167 781218f0c0d0
parent 1160 a176739cd3c3
child 1172 15a75c0cc78f
     1.1 --- a/src/sync.c	Sun Sep 18 22:12:27 2016 +0200
     1.2 +++ b/src/sync.c	Tue Sep 20 11:46:59 2016 +0200
     1.3 @@ -6,6 +6,9 @@
     1.4  #include "asn1_helper.h"
     1.5  #include "../asn.1/DeviceGroup-Protocol.h"
     1.6  
     1.7 +static void *static_sync_obj = NULL;
     1.8 +static inject_sync_msg_t static_inject_sync_msg = NULL;
     1.9 +
    1.10  // receive_sync_msg is defined in the sync_actions
    1.11  
    1.12  PEP_STATUS receive_sync_msg(
    1.13 @@ -32,6 +35,9 @@
    1.14      session->inject_sync_msg = inject_sync_msg;
    1.15      session->retrieve_next_sync_msg = retrieve_next_sync_msg;
    1.16  
    1.17 +    static_sync_obj = obj;
    1.18 +    static_inject_sync_msg = inject_sync_msg;
    1.19 +
    1.20      // start state machine
    1.21      session->sync_state = InitState;
    1.22      PEP_STATUS status = fsm_DeviceState_inject(session, Init, NULL, NULL);
    1.23 @@ -41,14 +47,29 @@
    1.24      return status;
    1.25  }
    1.26  
    1.27 +int call_inject_sync_msg(PEP_SESSION session, void *msg)
    1.28 +{
    1.29 +    if(session->inject_sync_msg && session->sync_obj)
    1.30 +        return session->inject_sync_msg(msg, session->sync_obj);
    1.31 +    else if(static_inject_sync_msg && static_sync_obj)
    1.32 +        return static_inject_sync_msg(msg, static_sync_obj);
    1.33 +    else
    1.34 +       return PEP_SYNC_NO_INJECT_CALLBACK;
    1.35 +}
    1.36 +
    1.37 +
    1.38  DYNAMIC_API void unregister_sync_callbacks(PEP_SESSION session) {
    1.39      // stop state machine
    1.40      session->sync_state = DeviceState_state_NONE;
    1.41  
    1.42 +    static_sync_obj = NULL;
    1.43 +    static_inject_sync_msg = NULL;
    1.44 +
    1.45      // unregister
    1.46      session->sync_obj = NULL;
    1.47      session->messageToSend = NULL;
    1.48      session->showHandshake = NULL;
    1.49 +    session->inject_sync_msg = NULL;
    1.50      session->retrieve_next_sync_msg = NULL;
    1.51  }
    1.52