Skip to content

Commit

Permalink
Expose get_cached_app in C API (#7182)
Browse files Browse the repository at this point in the history
* Expose get_cached_app in C API

* Add wrap_err around app_get_cached

* Don't use set_out_param to avoid leaking the app when out_app is nullptr

* fix pointer assignment
  • Loading branch information
nirinchev authored Dec 7, 2023
1 parent c41cfd0 commit 27d40dc
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* <New feature description> (PR [#????](https://github.com/realm/realm-core/pull/????))
* Automatic client reset recovery now preserves the original division of changesets, rather than combining all unsynchronized changes into a single changeset ([PR #7161](https://github.com/realm/realm-core/pull/7161)).
* Automatic client reset recovery now does a better job of recovering changes when changesets were downloaded from the server after the unuploaded local changes were committed. If the local Realm happened to be fully up to date with the server prior to the client reset, automatic recovery should now always produce exactly the same state as if no client reset was involved ([PR #7161](https://github.com/realm/realm-core/pull/7161)).
* [C API] Exposed `realm_app_create_cached` and `realm_app_get_cached` in the C API. (Issue [#7181](https://github.com/realm/realm-core/issues/7181))

### Fixed
* <How do the end-user experience this issue? what was the impact?> ([#????](https://github.com/realm/realm-core/issues/????), since v?.?.?)
Expand Down
15 changes: 15 additions & 0 deletions src/realm.h
Original file line number Diff line number Diff line change
Expand Up @@ -2913,6 +2913,21 @@ RLM_API const char* realm_app_credentials_serialize_as_json(realm_app_credential
*/
RLM_API realm_app_t* realm_app_create(const realm_app_config_t*, const realm_sync_client_config_t*);

/**
* Create cached realm_app_t* instance given a valid realm configuration and sync client configuration.
*
* @return A non-null pointer if no error occurred.
*/
RLM_API realm_app_t* realm_app_create_cached(const realm_app_config_t*, const realm_sync_client_config_t*);

/**
* Get a cached realm_app_t* instance given an app id. out_app may be null if the app with this id hasn't been
* previously cached by calling realm_app_create_cached.
*
* @return true if no error occurred.
*/
RLM_API bool realm_app_get_cached(const char* app_id, const char* base_url, realm_app_t** out_app);

/**
* Clear all the cached @a realm_app_t* instances in the process.
*
Expand Down
21 changes: 21 additions & 0 deletions src/realm/object-store/c_api/app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,27 @@ RLM_API realm_app_t* realm_app_create(const realm_app_config_t* app_config,
});
}

RLM_API realm_app_t* realm_app_create_cached(const realm_app_config_t* app_config,
const realm_sync_client_config_t* sync_client_config)
{
return wrap_err([&] {
return new realm_app_t(App::get_shared_app(*app_config, *sync_client_config));
});
}

RLM_API bool realm_app_get_cached(const char* app_id, const char* base_url, realm_app_t** out_app)
{
return wrap_err([&] {
auto app =
App::get_cached_app(std::string(app_id), base_url ? util::some<std::string>(base_url) : util::none);
if (out_app) {
*out_app = app ? new realm_app_t(app) : nullptr;
}

return true;
});
}

RLM_API void realm_clear_cached_apps(void) noexcept
{
App::clear_cached_apps();
Expand Down

0 comments on commit 27d40dc

Please sign in to comment.