diff options
Diffstat (limited to 'src/networkfilemanager.cpp')
| -rw-r--r-- | src/networkfilemanager.cpp | 185 |
1 files changed, 93 insertions, 92 deletions
diff --git a/src/networkfilemanager.cpp b/src/networkfilemanager.cpp index 102d3d15..b68a60a3 100644 --- a/src/networkfilemanager.cpp +++ b/src/networkfilemanager.cpp @@ -53,7 +53,7 @@ class MyMutex { // cppcheck-suppress functionStatic void unlock() { pj_release_lock(); } }; -} +} // namespace #else #include <mutex> #define MyMutex std::mutex @@ -839,50 +839,51 @@ void NetworkChunkCache::insert(PJ_CONTEXT *ctx, const std::string &url, // Lambda to recycle an existing entry that was either invalidated, or // least recently used. - const auto reuseExistingEntry = [ctx, &blob, &diskCache, hDB, &url, - chunkIdx, &dataPtr]( - std::unique_ptr<SQLiteStatement> &stmtIn) { - const auto chunk_id = stmtIn->getInt64(); - const auto data_id = stmtIn->getInt64(); - if (data_id <= 0) { - pj_log(ctx, PJ_LOG_ERROR, "data_id <= 0"); - return; - } + const auto reuseExistingEntry = + [ctx, &blob, &diskCache, hDB, &url, chunkIdx, + &dataPtr](std::unique_ptr<SQLiteStatement> &stmtIn) { + const auto chunk_id = stmtIn->getInt64(); + const auto data_id = stmtIn->getInt64(); + if (data_id <= 0) { + pj_log(ctx, PJ_LOG_ERROR, "data_id <= 0"); + return; + } - auto l_stmt = - diskCache->prepare("UPDATE chunk_data SET data = ? WHERE id = ?"); - if (!l_stmt) - return; - l_stmt->bindBlob(blob.data(), blob.size()); - l_stmt->bindInt64(data_id); - { - const auto ret2 = l_stmt->execute(); - if (ret2 != SQLITE_DONE) { - pj_log(ctx, PJ_LOG_ERROR, "%s", sqlite3_errmsg(hDB)); + auto l_stmt = diskCache->prepare( + "UPDATE chunk_data SET data = ? WHERE id = ?"); + if (!l_stmt) return; + l_stmt->bindBlob(blob.data(), blob.size()); + l_stmt->bindInt64(data_id); + { + const auto ret2 = l_stmt->execute(); + if (ret2 != SQLITE_DONE) { + pj_log(ctx, PJ_LOG_ERROR, "%s", sqlite3_errmsg(hDB)); + return; + } } - } - l_stmt = diskCache->prepare("UPDATE chunks SET url = ?, " - "offset = ?, data_size = ?, data_id = ? " - "WHERE id = ?"); - if (!l_stmt) - return; - l_stmt->bindText(url.c_str()); - l_stmt->bindInt64(chunkIdx * DOWNLOAD_CHUNK_SIZE); - l_stmt->bindInt64(dataPtr->size()); - l_stmt->bindInt64(data_id); - l_stmt->bindInt64(chunk_id); - { - const auto ret2 = l_stmt->execute(); - if (ret2 != SQLITE_DONE) { - pj_log(ctx, PJ_LOG_ERROR, "%s", sqlite3_errmsg(hDB)); + l_stmt = + diskCache->prepare("UPDATE chunks SET url = ?, " + "offset = ?, data_size = ?, data_id = ? " + "WHERE id = ?"); + if (!l_stmt) return; + l_stmt->bindText(url.c_str()); + l_stmt->bindInt64(chunkIdx * DOWNLOAD_CHUNK_SIZE); + l_stmt->bindInt64(dataPtr->size()); + l_stmt->bindInt64(data_id); + l_stmt->bindInt64(chunk_id); + { + const auto ret2 = l_stmt->execute(); + if (ret2 != SQLITE_DONE) { + pj_log(ctx, PJ_LOG_ERROR, "%s", sqlite3_errmsg(hDB)); + return; + } } - } - diskCache->move_to_head(chunk_id); - }; + diskCache->move_to_head(chunk_id); + }; // Find if there is an invalidated chunk we can reuse stmt = diskCache->prepare( @@ -2017,16 +2018,16 @@ int proj_context_set_network_callbacks( // --------------------------------------------------------------------------- /** Enable or disable network access. -* -* This overrides the default endpoint in the PROJ configuration file or with -* the PROJ_NETWORK environment variable. -* -* @param ctx PROJ context, or NULL -* @param enable TRUE if network access is allowed. -* @return TRUE if network access is possible. That is either libcurl is -* available, or an alternate interface has been set. -* @since 7.0 -*/ + * + * This overrides the default endpoint in the PROJ configuration file or with + * the PROJ_NETWORK environment variable. + * + * @param ctx PROJ context, or NULL + * @param enable TRUE if network access is allowed. + * @return TRUE if network access is possible. That is either libcurl is + * available, or an alternate interface has been set. + * @since 7.0 + */ int proj_context_set_enable_network(PJ_CONTEXT *ctx, int enable) { if (ctx == nullptr) { ctx = pj_get_default_ctx(); @@ -2046,11 +2047,11 @@ int proj_context_set_enable_network(PJ_CONTEXT *ctx, int enable) { // --------------------------------------------------------------------------- /** Return if network access is enabled. -* -* @param ctx PROJ context, or NULL -* @return TRUE if network access has been enabled -* @since 7.0 -*/ + * + * @param ctx PROJ context, or NULL + * @return TRUE if network access has been enabled + * @since 7.0 + */ int proj_context_is_network_enabled(PJ_CONTEXT *ctx) { if (ctx == nullptr) { ctx = pj_get_default_ctx(); @@ -2074,14 +2075,14 @@ int proj_context_is_network_enabled(PJ_CONTEXT *ctx) { // --------------------------------------------------------------------------- /** Define the URL endpoint to query for remote grids. -* -* This overrides the default endpoint in the PROJ configuration file or with -* the PROJ_NETWORK_ENDPOINT environment variable. -* -* @param ctx PROJ context, or NULL -* @param url Endpoint URL. Must NOT be NULL. -* @since 7.0 -*/ + * + * This overrides the default endpoint in the PROJ configuration file or with + * the PROJ_NETWORK_ENDPOINT environment variable. + * + * @param ctx PROJ context, or NULL + * @param url Endpoint URL. Must NOT be NULL. + * @since 7.0 + */ void proj_context_set_url_endpoint(PJ_CONTEXT *ctx, const char *url) { if (ctx == nullptr) { ctx = pj_get_default_ctx(); @@ -2094,13 +2095,13 @@ void proj_context_set_url_endpoint(PJ_CONTEXT *ctx, const char *url) { // --------------------------------------------------------------------------- /** Enable or disable the local cache of grid chunks -* -* This overrides the setting in the PROJ configuration file. -* -* @param ctx PROJ context, or NULL -* @param enabled TRUE if the cache is enabled. -* @since 7.0 -*/ + * + * This overrides the setting in the PROJ configuration file. + * + * @param ctx PROJ context, or NULL + * @param enabled TRUE if the cache is enabled. + * @since 7.0 + */ void proj_grid_cache_set_enable(PJ_CONTEXT *ctx, int enabled) { if (ctx == nullptr) { ctx = pj_get_default_ctx(); @@ -2113,13 +2114,13 @@ void proj_grid_cache_set_enable(PJ_CONTEXT *ctx, int enabled) { // --------------------------------------------------------------------------- /** Override, for the considered context, the path and file of the local -* cache of grid chunks. -* -* @param ctx PROJ context, or NULL -* @param fullname Full name to the cache (encoded in UTF-8). If set to NULL, -* caching will be disabled. -* @since 7.0 -*/ + * cache of grid chunks. + * + * @param ctx PROJ context, or NULL + * @param fullname Full name to the cache (encoded in UTF-8). If set to NULL, + * caching will be disabled. + * @since 7.0 + */ void proj_grid_cache_set_filename(PJ_CONTEXT *ctx, const char *fullname) { if (ctx == nullptr) { ctx = pj_get_default_ctx(); @@ -2132,13 +2133,13 @@ void proj_grid_cache_set_filename(PJ_CONTEXT *ctx, const char *fullname) { // --------------------------------------------------------------------------- /** Override, for the considered context, the maximum size of the local -* cache of grid chunks. -* -* @param ctx PROJ context, or NULL -* @param max_size_MB Maximum size, in mega-bytes (1024*1024 bytes), or -* negative value to set unlimited size. -* @since 7.0 -*/ + * cache of grid chunks. + * + * @param ctx PROJ context, or NULL + * @param max_size_MB Maximum size, in mega-bytes (1024*1024 bytes), or + * negative value to set unlimited size. + * @since 7.0 + */ void proj_grid_cache_set_max_size(PJ_CONTEXT *ctx, int max_size_MB) { if (ctx == nullptr) { ctx = pj_get_default_ctx(); @@ -2160,12 +2161,12 @@ void proj_grid_cache_set_max_size(PJ_CONTEXT *ctx, int max_size_MB) { // --------------------------------------------------------------------------- /** Override, for the considered context, the time-to-live delay for -* re-checking if the cached properties of files are still up-to-date. -* -* @param ctx PROJ context, or NULL -* @param ttl_seconds Delay in seconds. Use negative value for no expiration. -* @since 7.0 -*/ + * re-checking if the cached properties of files are still up-to-date. + * + * @param ctx PROJ context, or NULL + * @param ttl_seconds Delay in seconds. Use negative value for no expiration. + * @since 7.0 + */ void proj_grid_cache_set_ttl(PJ_CONTEXT *ctx, int ttl_seconds) { if (ctx == nullptr) { ctx = pj_get_default_ctx(); @@ -2178,10 +2179,10 @@ void proj_grid_cache_set_ttl(PJ_CONTEXT *ctx, int ttl_seconds) { // --------------------------------------------------------------------------- /** Clear the local cache of grid chunks. -* -* @param ctx PROJ context, or NULL -* @since 7.0 -*/ + * + * @param ctx PROJ context, or NULL + * @since 7.0 + */ void proj_grid_cache_clear(PJ_CONTEXT *ctx) { if (ctx == nullptr) { ctx = pj_get_default_ctx(); |
