make ios compile

This commit is contained in:
Konstantin Käfer
2015-01-22 17:40:12 +01:00
parent 78376acea7
commit 9a549094e0
10 changed files with 67 additions and 64 deletions

View File

@@ -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',

View File

@@ -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',

View File

@@ -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',

View File

@@ -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);

View File

@@ -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>();

View File

@@ -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],

View File

@@ -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;
}
}
}

View File

@@ -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) {

View File

@@ -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];
}
}
}

View File

@@ -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) {