summaryrefslogtreecommitdiff
path: root/swift/src/IceObjc/PropertiesAdmin.mm
blob: f6c73ce1420aa59376ef5cd39b585d601d075351 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
//
// Copyright (c) ZeroC, Inc. All rights reserved.
//

#import "PropertiesAdmin.h"
#import "Convert.h"

@implementation ICEPropertiesAdmin

-(std::shared_ptr<Ice::PropertiesAdmin>) propertiesAdmin
{
    return std::static_pointer_cast<Ice::PropertiesAdmin>(self.cppObject);
}

-(nullable NSString*) getProperty:(NSString*)key error:(NSError**)error
{
    try
    {
        // This function does not use current so we do not pass it from Swift
        return toNSString(self.propertiesAdmin->getProperty(fromNSString(key), Ice::Current{}));
    }
    catch(const std::exception& ex)
    {
        *error = convertException(ex);
        return nil;
    }
}

-(nullable NSDictionary<NSString*, NSString*>*) getPropertiesForPrefix:(NSString*)prefix error:(NSError**)error
{
    try
    {
        // This function does not use current so we do not pass it from Swift
        return toNSDictionary(self.propertiesAdmin->getPropertiesForPrefix(fromNSString(prefix), Ice::Current{}));
    }
    catch(const std::exception& ex)
    {
        *error = convertException(ex);
        return nil;
    }
}

-(BOOL) setProperties:(NSDictionary<NSString*, NSString*>*)newProperties error:(NSError**)error
{
    try
    {
        // This function does not use current so we do not pass it from Swift
        Ice::PropertyDict props;
        fromNSDictionary(newProperties, props);
        self.propertiesAdmin->setProperties(props, Ice::Current{});
        return YES;
    }
    catch(const std::exception& ex)
    {
        *error = convertException(ex);
        return NO;
    }
}

-(void (^)(void)) addUpdateCallback:(void (^)(NSDictionary<NSString*, NSString*>*))cb
{
    auto facet = std::dynamic_pointer_cast<Ice::NativePropertiesAdmin>(self.propertiesAdmin);
    assert(facet);

    auto removeCb = facet->addUpdateCallback([cb] (const Ice::PropertyDict& props)
                                             {
                                                 cb(toNSDictionary(props));
                                             });

    return ^
    {
        removeCb();
    };

}

@end