Sync : use statics to share inject_sync_msg and sync_obj with other sessions. keysync
authorEdouard Tisserant <edouard@pep-project.org>
Tue, 20 Sep 2016 11:46:59 +0200
branchkeysync
changeset 1167781218f0c0d0
parent 1166 f128fb9fe444
child 1169 7d666711da67
child 1170 8949bee99bcd
Sync : use statics to share inject_sync_msg and sync_obj with other sessions.
src/sync.c
src/sync_impl.c
     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  
     2.1 --- a/src/sync_impl.c	Sun Sep 18 22:12:27 2016 +0200
     2.2 +++ b/src/sync_impl.c	Tue Sep 20 11:46:59 2016 +0200
     2.3 @@ -62,6 +62,9 @@
     2.4      return status;
     2.5  }
     2.6  
     2.7 +// from sync.c
     2.8 +int call_inject_sync_msg(PEP_SESSION session, void *msg);
     2.9 +
    2.10  PEP_STATUS receive_DeviceState_msg(
    2.11      PEP_SESSION session, 
    2.12      message *src, 
    2.13 @@ -72,10 +75,6 @@
    2.14      if (!(session && src))
    2.15          return PEP_ILLEGAL_VALUE;
    2.16  
    2.17 -    assert(session->inject_sync_msg);
    2.18 -    if (!session->inject_sync_msg)
    2.19 -        return PEP_SYNC_NO_INJECT_CALLBACK;
    2.20 -
    2.21      bool found = false;
    2.22      
    2.23      bloblist_t *last = NULL;
    2.24 @@ -143,7 +142,7 @@
    2.25  
    2.26                  if (status == PEP_STATUS_OK) {
    2.27                      found = true;
    2.28 -                    status = session->inject_sync_msg(msg, session->sync_obj);
    2.29 +                    status = call_inject_sync_msg(session, msg);
    2.30                      ASN_STRUCT_FREE(asn_DEF_DeviceGroup_Protocol, msg);
    2.31                      if (status != PEP_STATUS_OK){
    2.32                          return status;