diff options
author | Konstantin Käfer <mail@kkaefer.com> | 2015-01-22 17:40:12 +0100 |
---|---|---|
committer | Konstantin Käfer <mail@kkaefer.com> | 2015-02-04 10:49:06 +0100 |
commit | 9a549094e02b046eb67a3c3a1ed8df96791825ca (patch) | |
tree | e6b867eac917fb852354e9171a2fefacbb474aa2 | |
parent | 78376acea78056d9c20cc39bf98323adeedd22aa (diff) | |
download | qtlocation-mapboxgl-9a549094e02b046eb67a3c3a1ed8df96791825ca.tar.gz |
make ios compile
-rw-r--r-- | gyp/mbgl-ios.gypi | 5 | ||||
-rw-r--r-- | gyp/mbgl-linux.gypi | 1 | ||||
-rw-r--r-- | gyp/mbgl-osx.gypi | 1 | ||||
-rw-r--r-- | include/mbgl/platform/platform.hpp | 6 | ||||
-rw-r--r-- | macosx/main.mm | 36 | ||||
-rw-r--r-- | platform/darwin/application_root.mm | 4 | ||||
-rw-r--r-- | platform/default/application_root.cpp | 5 | ||||
-rw-r--r-- | platform/default/asset_request_libuv.cpp | 14 | ||||
-rw-r--r-- | platform/ios/cache_database_library.mm | 21 | ||||
-rw-r--r-- | src/mbgl/storage/sqlite_cache.cpp | 38 |
10 files changed, 67 insertions, 64 deletions
diff --git a/gyp/mbgl-ios.gypi b/gyp/mbgl-ios.gypi index 2bc9ec718d..41b04e97c1 100644 --- a/gyp/mbgl-ios.gypi +++ b/gyp/mbgl-ios.gypi @@ -10,7 +10,7 @@ 'IPHONEOS_DEPLOYMENT_TARGET':'7.0', 'TARGETED_DEVICE_FAMILY': '1,2', 'GCC_VERSION': 'com.apple.compilers.llvm.clang.1_0', - 'CLANG_ENABLE_OBJC_ARC': 'YES', + 'CLANG_ENABLE_OBJC_ARC': 'NO', 'CODE_SIGN_IDENTITY': 'iPhone Developer', 'SKIP_INSTALL': 'YES' }, @@ -34,10 +34,9 @@ 'version', ], 'sources': [ - '../platform/ios/cache_database_library.mm', '../platform/darwin/log_nslog.mm', '../platform/darwin/string_nsstring.mm', - '../platform/darwin/http_request_baton_cocoa.mm', + '../platform/darwin/http_request_cocoa.mm', '../platform/darwin/application_root.mm', '../platform/darwin/image.mm', '../platform/default/asset_request_libuv.cpp', diff --git a/gyp/mbgl-linux.gypi b/gyp/mbgl-linux.gypi index 98449d744f..ae873c5a9e 100644 --- a/gyp/mbgl-linux.gypi +++ b/gyp/mbgl-linux.gypi @@ -30,7 +30,6 @@ ], }, 'sources': [ - '../platform/default/shader_cache_tmp.cpp', '../platform/default/log_stderr.cpp', '../platform/default/string_stdlib.cpp', '../platform/default/http_request_curl.cpp', diff --git a/gyp/mbgl-osx.gypi b/gyp/mbgl-osx.gypi index 8de90a8a22..352a132a06 100644 --- a/gyp/mbgl-osx.gypi +++ b/gyp/mbgl-osx.gypi @@ -9,7 +9,6 @@ 'version', ], 'sources': [ - '../platform/osx/shader_cache_application_support.mm', '../platform/darwin/log_nslog.mm', '../platform/darwin/string_nsstring.mm', '../platform/darwin/http_request_cocoa.mm', diff --git a/include/mbgl/platform/platform.hpp b/include/mbgl/platform/platform.hpp index 024771cc7c..7a6762cbcf 100644 --- a/include/mbgl/platform/platform.hpp +++ b/include/mbgl/platform/platform.hpp @@ -17,10 +17,8 @@ std::string uppercase(const std::string &string); // Lowercase a string, potentially using platform-specific routines. std::string lowercase(const std::string &string); -// Returns the path to the default shader cache on this system. -std::string defaultShaderCache(); - -std::string applicationRoot(); +// Returns the path to the root folder of the application. +const std::string &applicationRoot(); // Shows an alpha image with the specified dimensions in a named window. void show_debug_image(std::string name, const char *data, size_t width, size_t height); diff --git a/macosx/main.mm b/macosx/main.mm index a81d5e2c16..5c6e67d1bd 100644 --- a/macosx/main.mm +++ b/macosx/main.mm @@ -73,28 +73,30 @@ @end // Returns the path to the default cache database on this system. -std::string defaultCacheDatabase() { - NSArray *paths = - NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES); - if ([paths count] == 0) { - // Disable the cache if we don't have a location to write. - return ""; - } +const std::string &defaultCacheDatabase() { + static const std::string path = []() -> std::string { + NSArray *paths = NSSearchPathForDirectoriesInDomains( + NSApplicationSupportDirectory, NSUserDomainMask, YES); + if ([paths count] == 0) { + // Disable the cache if we don't have a location to write. + return ""; + } - NSString *path = [[paths objectAtIndex:0] stringByAppendingPathComponent:@"Mapbox GL"]; + NSString *p = [[paths objectAtIndex:0] stringByAppendingPathComponent:@"Mapbox GL"]; - if (![[NSFileManager defaultManager] createDirectoryAtPath:path - withIntermediateDirectories:YES - attributes:nil - error:nil]) { - // Disable the cache if we couldn't create the directory. - return ""; - } + if (![[NSFileManager defaultManager] createDirectoryAtPath:p + withIntermediateDirectories:YES + attributes:nil + error:nil]) { + // Disable the cache if we couldn't create the directory. + return ""; + } - return [[path stringByAppendingPathComponent:@"cache.db"] UTF8String]; + return [[p stringByAppendingPathComponent:@"cache.db"] UTF8String]; + }(); + return path; } - int main() { mbgl::Log::Set<mbgl::NSLogBackend>(); diff --git a/platform/darwin/application_root.mm b/platform/darwin/application_root.mm index 19b872c54d..d4702c7ec5 100644 --- a/platform/darwin/application_root.mm +++ b/platform/darwin/application_root.mm @@ -5,8 +5,8 @@ namespace mbgl { namespace platform { -// Returns the path to the default shader cache on this system. -std::string applicationRoot() { +// Returns the path to the root folder of the application. +const std::string &applicationRoot() { static const std::string root = []() -> std::string { NSString *path = [[[NSBundle mainBundle] resourceURL] path]; return {[path cStringUsingEncoding : NSUTF8StringEncoding], diff --git a/platform/default/application_root.cpp b/platform/default/application_root.cpp index f25a44d46b..654d105c70 100644 --- a/platform/default/application_root.cpp +++ b/platform/default/application_root.cpp @@ -5,11 +5,10 @@ namespace mbgl { namespace platform { -// Returns the path the application root. -std::string applicationRoot() { +// Returns the path to the root folder of the application. +const std::string &applicationRoot() { static const std::string root = uv::cwd(); return root; } - } } diff --git a/platform/default/asset_request_libuv.cpp b/platform/default/asset_request_libuv.cpp index 006e573631..4a6fc88eb6 100644 --- a/platform/default/asset_request_libuv.cpp +++ b/platform/default/asset_request_libuv.cpp @@ -3,6 +3,7 @@ #include <mbgl/util/std.hpp> #include <mbgl/util/util.hpp> #include <mbgl/util/uv.hpp> +#include <mbgl/platform/platform.hpp> #include <uv.h> #include <boost/algorithm/string.hpp> @@ -47,7 +48,18 @@ AssetRequestImpl::~AssetRequestImpl() { AssetRequestImpl::AssetRequestImpl(AssetRequest *request_, uv_loop_t *loop) : request(request_) { req.data = this; - uv_fs_open(loop, &req, (request->resource.url.substr(8)).c_str(), O_RDONLY, S_IRUSR, fileOpened); + + const auto &url = request->resource.url; + std::string path; + if (url.size() <= 8 || url[8] == '/') { + // This is an empty or absolute path. + path = url.substr(8); + } else { + // This is a relative path. Prefix with the application root. + path = platform::applicationRoot() + "/" + url.substr(8); + } + + uv_fs_open(loop, &req, path.c_str(), O_RDONLY, S_IRUSR, fileOpened); } void AssetRequestImpl::fileOpened(uv_fs_t *req) { diff --git a/platform/ios/cache_database_library.mm b/platform/ios/cache_database_library.mm deleted file mode 100644 index 7989e73a4e..0000000000 --- a/platform/ios/cache_database_library.mm +++ /dev/null @@ -1,21 +0,0 @@ -#import <Foundation/Foundation.h> - -#include <mbgl/platform/platform.hpp> - -namespace mbgl { -namespace platform { - -// Returns the path to the default cache database on this system. -std::string defaultCacheDatabase() { - NSArray *paths = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES); - if ([paths count] == 0) { - // Disable the cache if we don't have a location to write. - return ""; - } - - NSString *libraryDirectory = [paths objectAtIndex:0]; - return [[libraryDirectory stringByAppendingPathComponent:@"cache.db"] UTF8String]; -} - -} -} diff --git a/src/mbgl/storage/sqlite_cache.cpp b/src/mbgl/storage/sqlite_cache.cpp index 7a0fd21ce6..14fbb0ca18 100644 --- a/src/mbgl/storage/sqlite_cache.cpp +++ b/src/mbgl/storage/sqlite_cache.cpp @@ -5,6 +5,7 @@ #include <mbgl/util/util.hpp> #include <mbgl/util/async_queue.hpp> #include <mbgl/util/variant.hpp> +#include <mbgl/platform/log.hpp> #include "../util/sqlite3.hpp" #include "../util/compression.hpp" @@ -139,17 +140,32 @@ void SQLiteCache::put(const Resource &resource, std::shared_ptr<const Response> void SQLiteCache::createDatabase() { db = util::make_unique<Database>(path.c_str(), ReadWrite | Create); - db->exec("CREATE TABLE IF NOT EXISTS `http_cache` (" - " `url` TEXT PRIMARY KEY NOT NULL," - " `status` INTEGER NOT NULL," // The response status (Successful or Error). - " `kind` INTEGER NOT NULL," // The kind of file. - " `modified` INTEGER," // Timestamp when the file was last modified. - " `etag` TEXT," - " `expires` INTEGER," // Timestamp when the server says the file expires. - " `data` BLOB," - " `compressed` INTEGER NOT NULL DEFAULT 0" // Whether the data is compressed. - ");" - "CREATE INDEX IF NOT EXISTS `http_cache_kind_idx` ON `http_cache` (`kind`);"); + constexpr const char *const sql = "" + "CREATE TABLE IF NOT EXISTS `http_cache` (" + " `url` TEXT PRIMARY KEY NOT NULL," + " `status` INTEGER NOT NULL," // The response status (Successful or Error). + " `kind` INTEGER NOT NULL," // The kind of file. + " `modified` INTEGER," // Timestamp when the file was last modified. + " `etag` TEXT," + " `expires` INTEGER," // Timestamp when the server says the file expires. + " `data` BLOB," + " `compressed` INTEGER NOT NULL DEFAULT 0" // Whether the data is compressed. + ");" + "CREATE INDEX IF NOT EXISTS `http_cache_kind_idx` ON `http_cache` (`kind`);"; + + try { + db->exec(sql); + } catch(mapbox::sqlite::Exception &) { + // Creating the database table + index failed. That means there may already be one, likely + // with different columsn. Drop it and try to create a new one. + try { + db->exec("DROP TABLE IF EXISTS `http_cache`"); + db->exec(sql); + } catch (mapbox::sqlite::Exception &ex) { + Log::Error(Event::Database, "Failed to create database: %s", ex.what()); + db.release(); + } + } } void SQLiteCache::process(GetAction &action) { |