summaryrefslogtreecommitdiff
path: root/SmartDeviceLink/SDLRPCMessage.m
blob: be5f95334c0cbe4e3a16d3ade7c4964318b87767 (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
81
//  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 = NAMES_request;
        [store setObject:function forKey:messageType];
        [function setObject:parameters forKey:NAMES_parameters];
        [function setObject:name forKey:NAMES_operation_name];
    }
    return self;
}

- (instancetype)initWithDictionary:(NSMutableDictionary *)dict {
    if (self = [super initWithDictionary:dict]) {
        NSEnumerator *enumerator = [store keyEnumerator];
        while (messageType = [enumerator nextObject]) {
            if ([messageType isEqualToString:@"bulkData"] == FALSE) {
                break;
            }
        }

        function = [store objectForKey:messageType];
        parameters = [function objectForKey:NAMES_parameters];
        self.bulkData = [dict objectForKey:@"bulkData"];
    }
    return self;
}

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

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

- (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:NAMES_operation_name];
}

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

    return description;
}

@end