pEpObjCAdapter/PEPSync.m
author Dirk Zimmermann <dirk@pep-project.org>
Fri, 05 Oct 2018 12:09:01 +0200
branchIOSAD-103
changeset 695 26359df4bec8
parent 693 5bc227f08143
child 698 aaf199099cf1
permissions -rw-r--r--
IOSAD-103 PEPSync.init with PEPNotifyHandshakeDelegate
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
+ (void)setPEPSyncSendMessageDelegate:
dirk@691
    20
(PEPSyncSendMessageDelegate * _Nullable)syncSendMessageDelegate;
dirk@691
    21
dirk@691
    22
+ (PEPSyncSendMessageDelegate * _Nullable)syncSendMessageDelegate;
dirk@691
    23
dirk@692
    24
@property (nonatomic, nullable, weak) PEPSyncSendMessageDelegate *syncSendMessageDelegate;
dirk@692
    25
dirk@691
    26
@end
dirk@691
    27
dirk@693
    28
// MARK: - Globals called by the engine, used in session init
dirk@693
    29
dirk@682
    30
PEP_STATUS messageToSendObjc(struct _message *msg)
dirk@682
    31
{
dirk@688
    32
    PEPSyncSendMessageDelegate *delegate = [PEPSync syncSendMessageDelegate];
dirk@688
    33
    if (delegate) {
dirk@688
    34
        PEPMessage *theMessage = pEpMessageFromStruct(msg);
dirk@688
    35
        return [delegate sendMessage:theMessage];
dirk@689
    36
    } else {
dirk@689
    37
        return PEP_SYNC_NO_MESSAGE_SEND_CALLBACK;
dirk@688
    38
    }
dirk@682
    39
}
dirk@682
    40
dirk@682
    41
int inject_sync_eventObjc(SYNC_EVENT ev, void *management)
dirk@682
    42
{
dirk@682
    43
    return 0;
dirk@682
    44
}
dirk@682
    45
dirk@693
    46
// MARK: - Internal globals
dirk@693
    47
dirk@686
    48
static __weak PEPSyncSendMessageDelegate *s_PEPSyncSendMessageDelegate;
dirk@686
    49
dirk@693
    50
// MARK: - PEPSync class
dirk@693
    51
dirk@681
    52
@implementation PEPSync
dirk@681
    53
dirk@686
    54
+ (void)setPEPSyncSendMessageDelegate:
dirk@686
    55
(PEPSyncSendMessageDelegate * _Nullable)syncSendMessageDelegate
dirk@686
    56
{
dirk@686
    57
    s_PEPSyncSendMessageDelegate = syncSendMessageDelegate;
dirk@686
    58
}
dirk@686
    59
dirk@686
    60
+ (PEPSyncSendMessageDelegate * _Nullable)syncSendMessageDelegate
dirk@686
    61
{
dirk@686
    62
    return s_PEPSyncSendMessageDelegate;
dirk@686
    63
}
dirk@686
    64
dirk@695
    65
- (instancetype)initWithSyncSendMessageDelegate:(PEPSyncSendMessageDelegate *
dirk@695
    66
                                                 _Nonnull)syncSendMessageDelegate
dirk@695
    67
                        notifyHandshakeDelegate:(PEPNotifyHandshakeDelegate *
dirk@695
    68
                                                 _Nonnull)notifyHandshakeDelegate
dirk@695
    69
{
dirk@695
    70
    if (self = [super init]) {
dirk@695
    71
        
dirk@695
    72
    }
dirk@695
    73
    return self;
dirk@695
    74
}
dirk@695
    75
dirk@686
    76
- (void)setSyncSendMessageDelegate:(PEPSyncSendMessageDelegate *)syncSendMessageDelegate
dirk@686
    77
{
dirk@686
    78
    [PEPSync setPEPSyncSendMessageDelegate:syncSendMessageDelegate];
dirk@686
    79
}
dirk@686
    80
dirk@686
    81
- (PEPSyncSendMessageDelegate *)syncSendMessageDelegate
dirk@686
    82
{
dirk@686
    83
    return [PEPSync syncSendMessageDelegate];
dirk@686
    84
}
dirk@686
    85
dirk@681
    86
@end