sync API
authorVolker Birk <vb@pep-project.org>
Tue, 03 May 2016 15:50:40 +0200
changeset 5723077e2489dfe
parent 571 2b1666bc1b45
child 573 28b0d3154f0f
sync API
src/sync.c
src/sync.h
src/sync_internal.h
sync/Makefile
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/sync.c	Tue May 03 15:50:40 2016 +0200
     1.3 @@ -0,0 +1,29 @@
     1.4 +#include "pEp_internal.h"
     1.5 +#include "sync_internal.h"
     1.6 +
     1.7 +#include <memory.h>
     1.8 +#include <assert.h>
     1.9 +
    1.10 +
    1.11 +PEP_sync_callbacks_t PEP_sync_callbacks = { NULL, NULL, NULL };
    1.12 +
    1.13 +DYNAMIC_API PEP_STATUS register_sync_callbacks(
    1.14 +        PEP_SESSION session,
    1.15 +        sendBeacon_t sendBeacon,
    1.16 +        sendHandshakeRequest_t sendHandshakeRequest,
    1.17 +        showHandshake_t showHandshake
    1.18 +    )
    1.19 +{
    1.20 +    PEP_sync_callbacks.sendBeacon = sendBeacon;
    1.21 +    PEP_sync_callbacks.sendHandshakeRequest = sendHandshakeRequest;
    1.22 +    PEP_sync_callbacks.showHandshake = showHandshake;
    1.23 +
    1.24 +    return PEP_STATUS_OK;
    1.25 +}
    1.26 +
    1.27 +DYNAMIC_API void unregister_sync_callbacks(PEP_SESSION session) {
    1.28 +    PEP_sync_callbacks.sendBeacon = NULL;
    1.29 +    PEP_sync_callbacks.sendHandshakeRequest = NULL;
    1.30 +    PEP_sync_callbacks.showHandshake = NULL;
    1.31 +}
    1.32 +
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/src/sync.h	Tue May 03 15:50:40 2016 +0200
     2.3 @@ -0,0 +1,87 @@
     2.4 +#pragma once
     2.5 +
     2.6 +#include "message.h"
     2.7 +
     2.8 +
     2.9 +// this module is for being used WITHOUT the Transport API in transport.h
    2.10 +// DO NOT USE IT WHEN USING Transport API!
    2.11 +
    2.12 +
    2.13 +#ifdef __cplusplus
    2.14 +extern "C" {
    2.15 +#endif
    2.16 +
    2.17 +// sendBeacon() - send a beacon message
    2.18 +//
    2.19 +//  parameters:
    2.20 +//      beacon (in)     message struct with beacon message to send
    2.21 +//
    2.22 +//  return value:
    2.23 +//      must return PEP_STATUS_OK or any other value on error
    2.24 +
    2.25 +typedef PEP_STATUS (*sendBeacon_t)(message beacon);
    2.26 +
    2.27 +
    2.28 +// sendHandshakeRequest() - send a handshake request message
    2.29 +//
    2.30 +//  parameters:
    2.31 +//      request (in)    message struct with beacon message to send
    2.32 +//
    2.33 +//  return value:
    2.34 +//      must return PEP_STATUS_OK or any other value on error
    2.35 +
    2.36 +typedef PEP_STATUS (*sendHandshakeRequest_t)(message request);
    2.37 +
    2.38 +
    2.39 +typedef enum _sync_handshake_result {
    2.40 +    SYNC_HANDSHAKE_CANCEL = -1,
    2.41 +    SYNC_HANDSHAKE_ACCEPTED = 0,
    2.42 +    SYNC_HANDSHAKE_REJECTED = 1
    2.43 +} sync_handshake_result;
    2.44 +
    2.45 +// showHandshake() - do a handshake and deliver the result
    2.46 +//
    2.47 +//  parameters:
    2.48 +//      self (in)       own identity
    2.49 +//      partner (in)    identity of partner
    2.50 +//
    2.51 +//  return value:
    2.52 +//      result of handshake
    2.53 +
    2.54 +typedef sync_handshake_result (*showHandshake_t)(
    2.55 +        pEp_identity self,
    2.56 +        pEp_identity partner
    2.57 +    );
    2.58 +
    2.59 +
    2.60 +// register_sync_callbacks() - register adapter's callbacks
    2.61 +//
    2.62 +//  parameters:
    2.63 +//      session (in)                session handle
    2.64 +//      sendBeacon (in)             callback for sending beacon
    2.65 +//      sendHandshakeRequest (in)   callback for sending handshake request
    2.66 +//      showHandshake (in)          callback for doing the handshake
    2.67 +//
    2.68 +//  return value:
    2.69 +//      PEP_STATUS_OK or any other value on errror
    2.70 +
    2.71 +DYNAMIC_API PEP_STATUS register_sync_callbacks(
    2.72 +        PEP_SESSION session,
    2.73 +        sendBeacon_t sendBeacon,
    2.74 +        sendHandshakeRequest_t sendHandshakeRequest,
    2.75 +        showHandshake_t showHandshake
    2.76 +    );
    2.77 +
    2.78 +
    2.79 +// unregister_sync_callbacks() - unregister adapter's callbacks
    2.80 +//
    2.81 +//  parameters:
    2.82 +//      session (in)                session handle
    2.83 +
    2.84 +DYNAMIC_API void unregister_sync_callbacks(PEP_SESSION session);
    2.85 +
    2.86 +
    2.87 +#ifdef __cplusplus
    2.88 +}
    2.89 +#endif
    2.90 +
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/src/sync_internal.h	Tue May 03 15:50:40 2016 +0200
     3.3 @@ -0,0 +1,10 @@
     3.4 +#include "sync.h"
     3.5 +
     3.6 +typedef struct _PEP_sync_callbacks_t {
     3.7 +    sendBeacon_t sendBeacon;
     3.8 +    sendHandshakeRequest_t sendHandshakeRequest;
     3.9 +    showHandshake_t showHandshake;
    3.10 +} PEP_sync_callbacks_t;
    3.11 +
    3.12 +extern PEP_sync_callbacks_t PEP_sync_callbacks;
    3.13 +
     4.1 --- a/sync/Makefile	Tue May 03 08:49:27 2016 +0200
     4.2 +++ b/sync/Makefile	Tue May 03 15:50:40 2016 +0200
     4.3 @@ -1,2 +1,2 @@
     4.4 -sync.xml: sync.fsm
     4.5 +sync.xml: sync.fsm fsm.yml2
     4.6  	yml2proc -P sync.fsm -o sync.xml