pEpObjCAdapter/PEPSync.m
author Dirk Zimmermann <dirk@pep-project.org>
Fri, 05 Oct 2018 14:42:21 +0200
branchIOSAD-103
changeset 698 aaf199099cf1
parent 695 26359df4bec8
child 699 924aed6a15e6
permissions -rw-r--r--
IOSAD-103 wire notifyHandshakeDelegate
dirk@681
     1
//
dirk@681
     2
//  PEPSync.m
dirk@681
     3
//  pEpObjCAdapter
dirk@681
     4
//
dirk@681
     5
//  Created by Dirk Zimmermann on 04.10.18.
dirk@681
     6
//  Copyright © 2018 p≡p. All rights reserved.
dirk@681
     7
//
dirk@681
     8
dirk@681
     9
#import "PEPSync.h"
dirk@681
    10
dirk@686
    11
#import "PEPSyncSendMessageDelegate.h"
dirk@688
    12
#import "PEPMessageUtil.h"
dirk@688
    13
#import "PEPMessage.h"
dirk@686
    14
dirk@693
    15
// MARK: - Declare internals
dirk@693
    16
dirk@691
    17
@interface PEPSync ()
dirk@691
    18
dirk@691
    19
+ (PEPSyncSendMessageDelegate * _Nullable)syncSendMessageDelegate;
dirk@698
    20
+ (PEPNotifyHandshakeDelegate * _Nullable)notifyHandshakeDelegate;
dirk@691
    21
dirk@692
    22
@property (nonatomic, nullable, weak) PEPSyncSendMessageDelegate *syncSendMessageDelegate;
dirk@698
    23
@property (nonatomic, nullable, weak) PEPNotifyHandshakeDelegate *notifyHandshakeDelegate;
dirk@692
    24
dirk@691
    25
@end
dirk@691
    26
dirk@693
    27
// MARK: - Globals called by the engine, used in session init
dirk@693
    28
dirk@682
    29
PEP_STATUS messageToSendObjc(struct _message *msg)
dirk@682
    30
{
dirk@688
    31
    PEPSyncSendMessageDelegate *delegate = [PEPSync syncSendMessageDelegate];
dirk@688
    32
    if (delegate) {
dirk@688
    33
        PEPMessage *theMessage = pEpMessageFromStruct(msg);
dirk@688
    34
        return [delegate sendMessage:theMessage];
dirk@689
    35
    } else {
dirk@689
    36
        return PEP_SYNC_NO_MESSAGE_SEND_CALLBACK;
dirk@688
    37
    }
dirk@682
    38
}
dirk@682
    39
dirk@682
    40
int inject_sync_eventObjc(SYNC_EVENT ev, void *management)
dirk@682
    41
{
dirk@698
    42
    PEPNotifyHandshakeDelegate *delegate = [PEPSync notifyHandshakeDelegate];
dirk@698
    43
    if (delegate) {
dirk@698
    44
        return 0;
dirk@698
    45
    }
dirk@698
    46
    return 1;
dirk@682
    47
}
dirk@682
    48
dirk@693
    49
// MARK: - Internal globals
dirk@693
    50
dirk@698
    51
static __weak PEPSyncSendMessageDelegate *s_syncSendMessageDelegate;
dirk@698
    52
static __weak PEPNotifyHandshakeDelegate *s_notifyHandshakeDelegate;
dirk@686
    53
dirk@693
    54
// MARK: - PEPSync class
dirk@693
    55
dirk@681
    56
@implementation PEPSync
dirk@681
    57
dirk@686
    58
+ (void)setPEPSyncSendMessageDelegate:
dirk@686
    59
(PEPSyncSendMessageDelegate * _Nullable)syncSendMessageDelegate
dirk@686
    60
{
dirk@698
    61
    s_syncSendMessageDelegate = syncSendMessageDelegate;
dirk@686
    62
}
dirk@686
    63
dirk@686
    64
+ (PEPSyncSendMessageDelegate * _Nullable)syncSendMessageDelegate
dirk@686
    65
{
dirk@698
    66
    return s_syncSendMessageDelegate;
dirk@698
    67
}
dirk@698
    68
dirk@698
    69
+ (PEPNotifyHandshakeDelegate * _Nullable)notifyHandshakeDelegate
dirk@698
    70
{
dirk@698
    71
    return s_notifyHandshakeDelegate;
dirk@686
    72
}
dirk@686
    73
dirk@695
    74
- (instancetype)initWithSyncSendMessageDelegate:(PEPSyncSendMessageDelegate *
dirk@695
    75
                                                 _Nonnull)syncSendMessageDelegate
dirk@695
    76
                        notifyHandshakeDelegate:(PEPNotifyHandshakeDelegate *
dirk@695
    77
                                                 _Nonnull)notifyHandshakeDelegate
dirk@695
    78
{
dirk@695
    79
    if (self = [super init]) {
dirk@698
    80
        self.syncSendMessageDelegate = syncSendMessageDelegate;
dirk@698
    81
        self.notifyHandshakeDelegate = notifyHandshakeDelegate;
dirk@695
    82
    }
dirk@695
    83
    return self;
dirk@695
    84
}
dirk@695
    85
dirk@686
    86
- (void)setSyncSendMessageDelegate:(PEPSyncSendMessageDelegate *)syncSendMessageDelegate
dirk@686
    87
{
dirk@686
    88
    [PEPSync setPEPSyncSendMessageDelegate:syncSendMessageDelegate];
dirk@686
    89
}
dirk@686
    90
dirk@686
    91
- (PEPSyncSendMessageDelegate *)syncSendMessageDelegate
dirk@686
    92
{
dirk@686
    93
    return [PEPSync syncSendMessageDelegate];
dirk@686
    94
}
dirk@686
    95
dirk@681
    96
@end