-
Notifications
You must be signed in to change notification settings - Fork 168
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
RCORE-2201 Add an implementation for the realm_app_config_get_sync_client_config() function in the Core CAPI #7891
Changes from all commits
193f2f3
7233c68
88d1012
0d641fc
3916d42
449179f
bc7ff1b
b68b707
170b31c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3023,8 +3023,6 @@ RLM_API void realm_app_config_set_metadata_mode(realm_app_config_t*, | |
RLM_API void realm_app_config_set_metadata_encryption_key(realm_app_config_t*, const uint8_t[64]) RLM_API_NOEXCEPT; | ||
RLM_API void realm_app_config_set_security_access_group(realm_app_config_t*, const char*) RLM_API_NOEXCEPT; | ||
|
||
RLM_API realm_sync_client_config_t* realm_app_config_get_sync_client_config(realm_app_config_t*) RLM_API_NOEXCEPT; | ||
|
||
/** | ||
* Get an existing @a realm_app_credentials_t and return it's json representation | ||
* Note: the caller must delete the pointer to the string via realm_release | ||
|
@@ -3746,8 +3744,21 @@ typedef void (*realm_async_open_task_completion_func_t)(realm_userdata_t userdat | |
// callback runs. | ||
typedef void (*realm_async_open_task_init_subscription_func_t)(realm_thread_safe_reference_t* realm, | ||
realm_userdata_t userdata); | ||
|
||
#if REALM_APP_SERVICES | ||
// If using App Services, the realm_sync_client_config_t instance is part of the | ||
// realm_app_config_t structure and this function returns a pointer to that | ||
// member property. The realm_sync_client_config_t reference returned by this | ||
// function should not be freed using realm_release. | ||
RLM_API realm_sync_client_config_t* realm_app_config_get_sync_client_config(realm_app_config_t*) RLM_API_NOEXCEPT; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should add a comment here that the returned pointer is owned by core and that it shouldn't be released and maybe some other remarks on lifecycle. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry, I forgot to complete my comment.... |
||
#else | ||
// If not using App Services, the realm_app_config_t structure is not defined, and | ||
// the real_sync_client_config_t structure returned by this function is meant to be | ||
// used with realm_sync_manager_create() to create a separate Sync Manager instance. | ||
// The realm_sync_client_config_t instance returned by this function will need to be | ||
// manually freed using realm_release. | ||
RLM_API realm_sync_client_config_t* realm_sync_client_config_new(void) RLM_API_NOEXCEPT; | ||
#endif // REALM_APP_SERVICES | ||
|
||
RLM_API void realm_sync_client_config_set_reconnect_mode(realm_sync_client_config_t*, | ||
realm_sync_client_reconnect_mode_e) RLM_API_NOEXCEPT; | ||
RLM_API void realm_sync_client_config_set_multiplex_sessions(realm_sync_client_config_t*, bool) RLM_API_NOEXCEPT; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't fully understand why this getter couldn't just be implemented. The issue I see is that with only a setter available, it becomes impossible to just set one property of the sync_client_config because
realm_app_config_set_sync_client_config
will overwrite everything. This means that this API will only allow a use like this:realm_app_config_set_sync_client_config
to apply the changesWhereas if we support a getter that returns a pointer to the already existing instance
AppConfig::sync_client_config
then users of this API can just get that pointer and modify it directly with the various setters, and never need to allocate memory on their side of things.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The problem is that in the non-appservices scenario users allocate and free realm_sync_client_config_t, which requires that it inherit from WrapC. Owning and non-owning pointers need to be different types with how we've structured the C API. We could add a second type, but a simpler variation on that would be to add getters and setters for the SyncConfig fields that just take an AppConfig.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have been trying to add a second type that also uses the existing functions, but I don't think I've been able to get it just right without having to add separate functions for the second type. I tried creating a
realm_sync_client_config
that inherits from realm::SyncClientConfig and used by all the functions; and arealm_sync_client_config_wrapc
that inherits fromWrapC
andrealm_sync_client_config
, which is returned by the sync_client_config_new() function....I would be happy to just add setters for the SyncConfig fields (we usually don't have getters on most of the struct fields).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see, that is an unfortunate conflict that muddies the API. Whatever seems easiest is fine.
If the SDKs use the
realm_app_config_set_sync_client_config
function as it is now, then I suppose they have created a new config instance that they manage the lifetime of anyways, which means that if they want to update a single property, they could set it on their instance, and then update the entire thing again using the setter. So not the end of the world.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I left the
realm_app_config_set_sync_client_config()
function in the code and also added individual C_API setter functions for the SyncClientConfig parameters in the app config to give the SDK a choice as to what they want to use. I could also easily add arealm_app_config_get_sync_client_config()
function that returns a copy of the sync_client_config, but I thought that might be confusing/misleading...There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ironage - since the
realm_sync_client_config_new()
is not needed if REALM_APP_SERVICES is enabled, I just updated therealm_sync_client_config_t
to be one of the two different types depending on the REALM_APP_SERVICES value:realm_app_config_get_sync_client_config()
is now available to get the sync client config from app config.realm_sync_client_config_new()
is available to create the sync client config to use with therealm_sync_manager_create()
, which is also only available if REALM_APP_SERVICES is not set.