caches are configurable by embedding application
Showing
5 changed files
with
175 additions
and
11 deletions
MapView/Map/RMConfiguration.h
0 → 100644
1 | +// | ||
2 | +// RMConfiguration.h | ||
3 | +// MapView | ||
4 | +// | ||
5 | +// Created by Hauke Brandes on 28.10.08. | ||
6 | +// Copyright 2008 __MyCompanyName__. All rights reserved. | ||
7 | +// | ||
8 | + | ||
9 | +#import <UIKit/UIKit.h> | ||
10 | + | ||
11 | + | ||
12 | +@interface RMConfiguration : NSObject { | ||
13 | + | ||
14 | + id propList; | ||
15 | + | ||
16 | +} | ||
17 | + | ||
18 | ++ (RMConfiguration*) configuration; | ||
19 | + | ||
20 | +- (RMConfiguration*) initWithPath: (NSString*) path; | ||
21 | +- (void) dealloc; | ||
22 | + | ||
23 | +- (NSDictionary*) cacheConfiguration; | ||
24 | + | ||
25 | +@end |
MapView/Map/RMConfiguration.m
0 → 100644
1 | +// | ||
2 | +// RMConfiguration.m | ||
3 | +// MapView | ||
4 | +// | ||
5 | +// Created by Hauke Brandes on 28.10.08. | ||
6 | +// Copyright 2008 __MyCompanyName__. All rights reserved. | ||
7 | +// | ||
8 | + | ||
9 | +#import "RMConfiguration.h" | ||
10 | + | ||
11 | +static RMConfiguration* RMConfigurationSharedInstance = nil; | ||
12 | + | ||
13 | +@implementation RMConfiguration | ||
14 | + | ||
15 | ++ (RMConfiguration*) configuration | ||
16 | +{ | ||
17 | + | ||
18 | + @synchronized (RMConfigurationSharedInstance) { | ||
19 | + if (RMConfigurationSharedInstance != nil) return RMConfigurationSharedInstance; | ||
20 | + | ||
21 | + RMConfigurationSharedInstance = [[RMConfiguration alloc] | ||
22 | + initWithPath: [[NSBundle mainBundle] pathForResource:@"routeme" ofType:@"plist"]]; | ||
23 | + | ||
24 | + return RMConfigurationSharedInstance; | ||
25 | + } | ||
26 | + return nil; | ||
27 | +} | ||
28 | + | ||
29 | + | ||
30 | +- (RMConfiguration*) initWithPath: (NSString*) path | ||
31 | +{ | ||
32 | + self = [super init]; | ||
33 | + | ||
34 | + if (self==nil) return nil; | ||
35 | + | ||
36 | + NSData *plistData; | ||
37 | + NSString *error; | ||
38 | + NSPropertyListFormat format; | ||
39 | + | ||
40 | + if (path==nil) | ||
41 | + { | ||
42 | + propList = nil; | ||
43 | + return self; | ||
44 | + } | ||
45 | + | ||
46 | + NSLog(@"reading configuration from %@", path); | ||
47 | + plistData = [NSData dataWithContentsOfFile:path]; | ||
48 | + | ||
49 | + propList = [[NSPropertyListSerialization | ||
50 | + propertyListFromData:plistData | ||
51 | + mutabilityOption:NSPropertyListImmutable | ||
52 | + format:&format | ||
53 | + errorDescription:&error] retain]; | ||
54 | + | ||
55 | + if(!propList) | ||
56 | + { | ||
57 | + NSLog(@"problem reading from %@: %@", path, error); | ||
58 | + [error release]; | ||
59 | + } | ||
60 | + | ||
61 | + return self; | ||
62 | +} | ||
63 | + | ||
64 | + | ||
65 | +- (void) dealloc | ||
66 | +{ | ||
67 | + [propList release]; | ||
68 | + [super dealloc]; | ||
69 | +} | ||
70 | + | ||
71 | + | ||
72 | +- (NSDictionary*) cacheConfiguration | ||
73 | +{ | ||
74 | + if (propList==nil) return nil; | ||
75 | + return [propList objectForKey: @"caches"]; | ||
76 | +} | ||
77 | + | ||
78 | +@end |
@@ -16,6 +16,8 @@ | @@ -16,6 +16,8 @@ | ||
16 | if (![super init]) | 16 | if (![super init]) |
17 | return nil; | 17 | return nil; |
18 | 18 | ||
19 | + NSLog(@"initializing memory cache with capacity %d", _capacity); | ||
20 | + | ||
19 | cache = [[NSMutableDictionary alloc] initWithCapacity:_capacity]; | 21 | cache = [[NSMutableDictionary alloc] initWithCapacity:_capacity]; |
20 | 22 | ||
21 | if (_capacity < 1) | 23 | if (_capacity < 1) |
@@ -12,6 +12,8 @@ | @@ -12,6 +12,8 @@ | ||
12 | #import "RMDiskCache.h" | 12 | #import "RMDiskCache.h" |
13 | #import "RMDatabaseCache.h" | 13 | #import "RMDatabaseCache.h" |
14 | 14 | ||
15 | +#import "RMConfiguration.h" | ||
16 | + | ||
15 | static RMTileCache *cache = nil; | 17 | static RMTileCache *cache = nil; |
16 | 18 | ||
17 | @implementation RMTileCache | 19 | @implementation RMTileCache |
@@ -23,18 +25,59 @@ static RMTileCache *cache = nil; | @@ -23,18 +25,59 @@ static RMTileCache *cache = nil; | ||
23 | 25 | ||
24 | caches = [[NSMutableArray alloc] init]; | 26 | caches = [[NSMutableArray alloc] init]; |
25 | 27 | ||
26 | - RMMemoryCache *memoryCache = [[RMMemoryCache alloc] init]; | ||
27 | - RMDiskCache *diskCache = [[RMDiskCache alloc] init]; | ||
28 | - RMDatabaseCache *dbCache = [[RMDatabaseCache alloc] init]; | ||
29 | - | ||
30 | - [self addCache:memoryCache]; | ||
31 | - [self addCache:diskCache]; | ||
32 | - [self addCache:dbCache]; | ||
33 | - | ||
34 | - [memoryCache release]; | ||
35 | - [diskCache release]; | ||
36 | - [dbCache release]; | 28 | + id cacheCfg = [[RMConfiguration configuration] cacheConfiguration]; |
37 | 29 | ||
30 | + if (cacheCfg==nil) | ||
31 | + { | ||
32 | + cacheCfg = [NSArray arrayWithObjects: | ||
33 | + [NSDictionary dictionaryWithObject: @"memory-cache" forKey: @"type"], | ||
34 | + [NSDictionary dictionaryWithObject: @"disk-cache" forKey: @"type"], | ||
35 | + [NSDictionary dictionaryWithObject: @"db-cache" forKey: @"type"], | ||
36 | + nil | ||
37 | + ]; | ||
38 | + } | ||
39 | + | ||
40 | + for (id cfg in cacheCfg) | ||
41 | + { | ||
42 | + RMTileCache* newCache = nil; | ||
43 | + | ||
44 | + @try { | ||
45 | + NSString* type = [cfg valueForKey:@"type"]; | ||
46 | + | ||
47 | + if ([@"memory-cache" isEqualToString: type]) | ||
48 | + { | ||
49 | + NSNumber* capacity = [cfg objectForKey:@"capacity"]; | ||
50 | + if (capacity == nil) capacity = [NSNumber numberWithInt: 32]; | ||
51 | + newCache = [[RMMemoryCache alloc] initWithCapacity: [capacity intValue]]; | ||
52 | + } | ||
53 | + | ||
54 | + if ([@"disk-cache" isEqualToString: type]) | ||
55 | + { | ||
56 | + NSLog(@"creating disk cache"); | ||
57 | + newCache = [[RMDiskCache alloc] init]; | ||
58 | + } | ||
59 | + | ||
60 | + if ([@"db-cache" isEqualToString: type]) | ||
61 | + { | ||
62 | + newCache = [[RMDatabaseCache alloc] init]; | ||
63 | + } | ||
64 | + | ||
65 | + if (newCache) | ||
66 | + { | ||
67 | + [caches addObject: newCache]; | ||
68 | + [newCache release]; | ||
69 | + } | ||
70 | + else | ||
71 | + { | ||
72 | + NSLog(@"failed to create cache of type %@", type); | ||
73 | + } | ||
74 | + | ||
75 | + } | ||
76 | + @catch (NSException * e) { | ||
77 | + NSLog(@"*** configuration error: %@", [e reason]); | ||
78 | + } | ||
79 | + | ||
80 | + } | ||
38 | return self; | 81 | return self; |
39 | } | 82 | } |
40 | 83 |
@@ -7,6 +7,8 @@ | @@ -7,6 +7,8 @@ | ||
7 | objects = { | 7 | objects = { |
8 | 8 | ||
9 | /* Begin PBXBuildFile section */ | 9 | /* Begin PBXBuildFile section */ |
10 | + 126692A10EB75C0A00E002D5 /* RMConfiguration.m in Sources */ = {isa = PBXBuildFile; fileRef = 126692A00EB75C0A00E002D5 /* RMConfiguration.m */; }; | ||
11 | + 126693040EB76C0B00E002D5 /* RMConfiguration.m in Sources */ = {isa = PBXBuildFile; fileRef = 126692A00EB75C0A00E002D5 /* RMConfiguration.m */; }; | ||
10 | 1D3623260D0F684500981E51 /* MapViewAppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 1D3623250D0F684500981E51 /* MapViewAppDelegate.m */; }; | 12 | 1D3623260D0F684500981E51 /* MapViewAppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 1D3623250D0F684500981E51 /* MapViewAppDelegate.m */; }; |
11 | 1D60589B0D05DD56006BFB54 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 29B97316FDCFA39411CA2CEA /* main.m */; }; | 13 | 1D60589B0D05DD56006BFB54 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 29B97316FDCFA39411CA2CEA /* main.m */; }; |
12 | 1D60589F0D05DD5A006BFB54 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1D30AB110D05D00D00671497 /* Foundation.framework */; }; | 14 | 1D60589F0D05DD5A006BFB54 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1D30AB110D05D00D00671497 /* Foundation.framework */; }; |
@@ -128,6 +130,8 @@ | @@ -128,6 +130,8 @@ | ||
128 | /* End PBXContainerItemProxy section */ | 130 | /* End PBXContainerItemProxy section */ |
129 | 131 | ||
130 | /* Begin PBXFileReference section */ | 132 | /* Begin PBXFileReference section */ |
133 | + 1266929F0EB75C0A00E002D5 /* RMConfiguration.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RMConfiguration.h; sourceTree = "<group>"; }; | ||
134 | + 126692A00EB75C0A00E002D5 /* RMConfiguration.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RMConfiguration.m; sourceTree = "<group>"; }; | ||
131 | 1D30AB110D05D00D00671497 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; }; | 135 | 1D30AB110D05D00D00671497 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; }; |
132 | 1D3623240D0F684500981E51 /* MapViewAppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MapViewAppDelegate.h; sourceTree = "<group>"; }; | 136 | 1D3623240D0F684500981E51 /* MapViewAppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MapViewAppDelegate.h; sourceTree = "<group>"; }; |
133 | 1D3623250D0F684500981E51 /* MapViewAppDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MapViewAppDelegate.m; sourceTree = "<group>"; }; | 137 | 1D3623250D0F684500981E51 /* MapViewAppDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MapViewAppDelegate.m; sourceTree = "<group>"; }; |
@@ -261,6 +265,15 @@ | @@ -261,6 +265,15 @@ | ||
261 | /* End PBXFrameworksBuildPhase section */ | 265 | /* End PBXFrameworksBuildPhase section */ |
262 | 266 | ||
263 | /* Begin PBXGroup section */ | 267 | /* Begin PBXGroup section */ |
268 | + 1266929E0EB75BEA00E002D5 /* Configuration */ = { | ||
269 | + isa = PBXGroup; | ||
270 | + children = ( | ||
271 | + 1266929F0EB75C0A00E002D5 /* RMConfiguration.h */, | ||
272 | + 126692A00EB75C0A00E002D5 /* RMConfiguration.m */, | ||
273 | + ); | ||
274 | + name = Configuration; | ||
275 | + sourceTree = "<group>"; | ||
276 | + }; | ||
264 | 19C28FACFE9D520D11CA2CBB /* Products */ = { | 277 | 19C28FACFE9D520D11CA2CBB /* Products */ = { |
265 | isa = PBXGroup; | 278 | isa = PBXGroup; |
266 | children = ( | 279 | children = ( |
@@ -506,6 +519,7 @@ | @@ -506,6 +519,7 @@ | ||
506 | B83E64CE0E80E73F001663B6 /* Tile Images */, | 519 | B83E64CE0E80E73F001663B6 /* Tile Images */, |
507 | B83E64B80E80E73F001663B6 /* Renderers */, | 520 | B83E64B80E80E73F001663B6 /* Renderers */, |
508 | B86F26A80E8742ED007A3773 /* Layers */, | 521 | B86F26A80E8742ED007A3773 /* Layers */, |
522 | + 1266929E0EB75BEA00E002D5 /* Configuration */, | ||
509 | B8474C610EB53A01006A0BC1 /* Resources */, | 523 | B8474C610EB53A01006A0BC1 /* Resources */, |
510 | ); | 524 | ); |
511 | path = Map; | 525 | path = Map; |
@@ -681,6 +695,7 @@ | @@ -681,6 +695,7 @@ | ||
681 | 1D60589B0D05DD56006BFB54 /* main.m in Sources */, | 695 | 1D60589B0D05DD56006BFB54 /* main.m in Sources */, |
682 | 1D3623260D0F684500981E51 /* MapViewAppDelegate.m in Sources */, | 696 | 1D3623260D0F684500981E51 /* MapViewAppDelegate.m in Sources */, |
683 | 28D7ACF80DDB3853001CB0EB /* MapViewViewController.m in Sources */, | 697 | 28D7ACF80DDB3853001CB0EB /* MapViewViewController.m in Sources */, |
698 | + 126692A10EB75C0A00E002D5 /* RMConfiguration.m in Sources */, | ||
684 | ); | 699 | ); |
685 | runOnlyForDeploymentPostprocessing = 0; | 700 | runOnlyForDeploymentPostprocessing = 0; |
686 | }; | 701 | }; |
@@ -722,6 +737,7 @@ | @@ -722,6 +737,7 @@ | ||
722 | B8474BA00EB40094006A0BC1 /* FMResultSet.m in Sources */, | 737 | B8474BA00EB40094006A0BC1 /* FMResultSet.m in Sources */, |
723 | B8474BA30EB40094006A0BC1 /* RMTileCacheDAO.m in Sources */, | 738 | B8474BA30EB40094006A0BC1 /* RMTileCacheDAO.m in Sources */, |
724 | B8474BA50EB40094006A0BC1 /* RMDatabaseCache.m in Sources */, | 739 | B8474BA50EB40094006A0BC1 /* RMDatabaseCache.m in Sources */, |
740 | + 126693040EB76C0B00E002D5 /* RMConfiguration.m in Sources */, | ||
725 | ); | 741 | ); |
726 | runOnlyForDeploymentPostprocessing = 0; | 742 | runOnlyForDeploymentPostprocessing = 0; |
727 | }; | 743 | }; |
-
Please register or login to post a comment