summaryrefslogtreecommitdiff
path: root/SmartDeviceLink/SDLRPCMessage.m
blob: 140762dc2ae020c823af13c60e0d899ca8afaff6 (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
//  SDLRPCMessage.m
//


#import "SDLRPCMessage.h"

#import "NSMutableDictionary+Store.h"
#import "SDLNames.h"

NS_ASSUME_NONNULL_BEGIN

@implementation SDLRPCMessage

@synthesize messageType;

- (instancetype)initWithName:(NSString *)name {
    if (self = [super init]) {
        function = [[NSMutableDictionary alloc] initWithCapacity:3];
        parameters = [[NSMutableDictionary alloc] init];
        messageType = SDLNameRequest;
        [store setObject:function forKey:messageType];
        [function setObject:parameters forKey:SDLNameParameters];
        [function setObject:name forKey:SDLNameOperationName];
    }
    return self;
}

- (instancetype)initWithDictionary:(NSDictionary *)dict {
    if (self = [super initWithDictionary:dict]) {
        NSEnumerator *enumerator = [store keyEnumerator];
        while (messageType = [enumerator nextObject]) {
            if (![messageType isEqualToString:SDLNameBulkData]) {
                break;
            }
        }
        if (messageType != nil) {
            function = [[store objectForKey:messageType] mutableCopy];
            parameters = [[function objectForKey:SDLNameParameters] mutableCopy];
        }
        self.bulkData = [dict objectForKey:SDLNameBulkData];
    }
    
    return self;
}

- (nullable NSString *)getFunctionName {
    return [function sdl_objectForName:SDLNameOperationName];
}

- (void)setFunctionName:(nullable NSString *)functionName {
    [function sdl_setObject:functionName forName:SDLNameOperationName];
}

- (nullable NSObject *)getParameters:(NSString *)functionName {
    return [parameters sdl_objectForName:functionName];
}

- (void)setParameters:(NSString *)functionName value:(nullable NSObject *)value {
    [parameters sdl_setObject:value forName:functionName];
}

- (NSString *)name {
    return [self getFunctionName];
}

- (NSString *)description {
    NSMutableString *description = [NSMutableString stringWithFormat:@"%@ (%@)\n%@", self.name, self.messageType, self->parameters];

    return description;
}

@end

NS_ASSUME_NONNULL_END