summaryrefslogtreecommitdiff
path: root/SmartDeviceLink/SDLRPCMessage.m
blob: 3f943252c09cd41df4e05a87280dc24774c9ca5e (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
78
79
80
//  SDLRPCMessage.m
//


#import "SDLRPCMessage.h"

#import "SDLNames.h"

@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] == FALSE) {
                break;
            }
        }

        function = [store objectForKey:messageType];
        parameters = [function objectForKey:SDLNameParameters];
        self.bulkData = [dict objectForKey:SDLNameBulkData];
    }
    return self;
}

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

- (void)setFunctionName:(NSString *)functionName {
    if (functionName != nil) {
        [function setObject:functionName forKey:SDLNameOperationName];
    } else {
        [function removeObjectForKey:SDLNameOperationName];
    }
}

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

- (void)setParameters:(NSString *)functionName value:(NSObject *)value {
    if (value != nil) {
        [parameters setObject:value forKey:functionName];
    } else {
        [parameters removeObjectForKey:functionName];
    }
}

- (void)dealloc {
    function = nil;
    parameters = nil;
}

- (NSString *)name {
    return [function objectForKey:SDLNameOperationName];
}

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

    return description;
}

@end