Skip to content

Commit

Permalink
Update to latest Core
Browse files Browse the repository at this point in the history
  • Loading branch information
nirinchev committed Apr 25, 2024
1 parent d73f9e5 commit 3edae22
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 41 deletions.
2 changes: 1 addition & 1 deletion wrappers/realm-core
Submodule realm-core updated 190 files
53 changes: 27 additions & 26 deletions wrappers/src/app_cs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,13 @@
#include <realm/sync/config.hpp>
#include <realm/object-store/thread_safe_reference.hpp>
#include <realm/object-store/sync/sync_session.hpp>
#include <realm/object-store/sync/app_user.hpp>

using namespace realm;
using namespace realm::binding;
using namespace app;

using SharedSyncUser = std::shared_ptr<SyncUser>;
using SharedSyncUser = std::shared_ptr<app::User>;

using UserCallbackT = void(void* tcs_ptr, SharedSyncUser* user, MarshaledAppError err);
using VoidCallbackT = void(void* tcs_ptr, MarshaledAppError err);
Expand Down Expand Up @@ -73,7 +74,7 @@ namespace realm {

uint64_t request_timeout_ms;

realm::SyncClientConfig::MetadataMode metadata_mode;
app::AppConfig::MetadataMode metadata_mode;

bool metadata_mode_has_value;

Expand Down Expand Up @@ -128,7 +129,7 @@ extern "C" {
REALM_EXPORT SharedApp* shared_app_create(AppConfiguration app_config, uint8_t* encryption_key, NativeException::Marshallable& ex)
{
return handle_errors(ex, [&]() {
App::Config config;
app::AppConfig config;
config.app_id = Utf16StringAccessor(app_config.app_id, app_config.app_id_len);

config.device_info.framework_name = s_framework;
Expand All @@ -147,38 +148,36 @@ extern "C" {
config.default_request_timeout_ms = app_config.request_timeout_ms;
}

SyncClientConfig sync_client_config;
sync_client_config.base_file_path = Utf16StringAccessor(app_config.base_file_path, app_config.base_file_path_len);
sync_client_config.timeouts.connection_linger_time = app_config.sync_connection_linger_time_ms;
sync_client_config.timeouts.connect_timeout = app_config.sync_connect_timeout_ms;
sync_client_config.timeouts.fast_reconnect_limit = app_config.sync_fast_reconnect_limit;
sync_client_config.timeouts.ping_keepalive_period = app_config.sync_ping_keep_alive_period_ms;
sync_client_config.timeouts.pong_keepalive_timeout = app_config.sync_pong_keep_alive_timeout_ms;
config.base_file_path = Utf16StringAccessor(app_config.base_file_path, app_config.base_file_path_len);
config.sync_client_config.timeouts.connection_linger_time = app_config.sync_connection_linger_time_ms;
config.sync_client_config.timeouts.connect_timeout = app_config.sync_connect_timeout_ms;
config.sync_client_config.timeouts.fast_reconnect_limit = app_config.sync_fast_reconnect_limit;
config.sync_client_config.timeouts.ping_keepalive_period = app_config.sync_ping_keep_alive_period_ms;
config.sync_client_config.timeouts.pong_keepalive_timeout = app_config.sync_pong_keep_alive_timeout_ms;

if (app_config.managed_websocket_provider) {
sync_client_config.socket_provider = make_websocket_provider(app_config.managed_websocket_provider);
config.sync_client_config.socket_provider = make_websocket_provider(app_config.managed_websocket_provider);
}

if (app_config.metadata_mode_has_value) {
sync_client_config.metadata_mode = app_config.metadata_mode;
config.metadata_mode = app_config.metadata_mode;
}
else {
#if REALM_PLATFORM_APPLE && !TARGET_OS_SIMULATOR && !TARGET_OS_MACCATALYST
sync_client_config.metadata_mode = SyncManager::MetadataMode::Encryption;
config.metadata_mode = app::AppConfig::MetadataMode::Encryption;
#else
sync_client_config.metadata_mode = SyncManager::MetadataMode::NoEncryption;
config.metadata_mode = app::AppConfig::MetadataMode::NoEncryption;
#endif
}

if (encryption_key) {
auto& key = *reinterpret_cast<std::array<char, 64>*>(encryption_key);
sync_client_config.custom_encryption_key = std::vector<char>(key.begin(), key.end());
config.custom_encryption_key = std::vector<char>(key.begin(), key.end());
}

SharedApp app = App::get_app(app_config.use_cache ?
realm::app::App::CacheMode::Enabled : realm::app::App::CacheMode::Disabled,
std::move(config),
std::move(sync_client_config));
std::move(config));

return new SharedApp(app);
});
Expand Down Expand Up @@ -242,20 +241,22 @@ extern "C" {
Utf16StringAccessor id(id_buf, id_len);
Utf16StringAccessor refresh_token(refresh_token_buf, refresh_token_len);
Utf16StringAccessor access_token(access_token_buf, access_token_len);
return new SharedSyncUser(
app->sync_manager()->get_user(
id,
refresh_token,
access_token,
"testing"));

auto user = app::User::make(app, id);
user->update_data_for_testing([&](app::UserData& data) {
data.access_token = RealmJWT(access_token.to_string());
data.refresh_token = RealmJWT(refresh_token.to_string());
});

return new SharedSyncUser(user);
});
}

REALM_EXPORT void shared_app_set_fake_sync_route_for_testing(SharedApp& app,
NativeException::Marshallable& ex)
{
return handle_errors(ex, [&]() {
app->sync_manager()->set_sync_route("realm://www.test.com:1000");
app->sync_manager()->set_sync_route("realm://www.test.com:1000", true);
});
}

Expand All @@ -281,7 +282,7 @@ extern "C" {
{
return handle_errors(ex, [&]() {
std::string path(Utf16StringAccessor(pathbuffer, pathbuffer_len));
return app->sync_manager()->immediately_run_file_actions(path);
return app->immediately_run_file_actions(path);
});
}

Expand Down Expand Up @@ -317,7 +318,7 @@ extern "C" {
REALM_EXPORT size_t shared_app_get_base_file_path(SharedApp& app, uint16_t* buffer, size_t buffer_length, NativeException::Marshallable& ex)
{
return handle_errors(ex, [&]() {
std::string base_file_path(app->sync_manager()->config().base_file_path);
std::string base_file_path(app->config().base_file_path);
return stringdata_to_csharpstringbuffer(base_file_path, buffer, buffer_length);
});
}
Expand Down
5 changes: 3 additions & 2 deletions wrappers/src/app_cs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,12 @@
#include <realm/object-store/sync/app.hpp>
#include <realm/object-store/sync/sync_user.hpp>
#include <realm/object-store/sync/sync_manager.hpp>
#include <realm/object-store/sync/app_user.hpp>

using namespace realm;
using namespace realm::app;

using SharedSyncUser = std::shared_ptr<SyncUser>;
using SharedSyncUser = std::shared_ptr<app::User>;

namespace realm {
namespace binding {
Expand Down Expand Up @@ -146,7 +147,7 @@ namespace binding {
}

inline auto get_user_callback_handler(void* tcs_ptr) {
return [tcs_ptr](std::shared_ptr<SyncUser> user, util::Optional<AppError> err) {
return [tcs_ptr](std::shared_ptr<app::User> user, util::Optional<AppError> err) {
if (err) {
auto& err_copy = *err;
MarshaledAppError app_error(err_copy);
Expand Down
5 changes: 5 additions & 0 deletions wrappers/src/marshalling.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,11 @@ static inline realm_string_t to_capi(StringData data)
return realm_string_t{ data.data(), data.size() };
}

static inline realm_string_t to_capi(std::string_view data)
{
return realm_string_t{ data.data(), data.size() };
}

static inline realm_string_t to_capi(const std::string& str)
{
return realm_string_t{ str.data(), str.length() };
Expand Down
3 changes: 2 additions & 1 deletion wrappers/src/shared_realm_cs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@
#include <realm/object-store/sync/sync_manager.hpp>
#include <realm/object-store/sync/sync_session.hpp>
#include <realm/sync/config.hpp>
#include <realm/object-store/sync/app_user.hpp>

namespace realm::binding {
using SharedSyncUser = std::shared_ptr<SyncUser>;
using SharedSyncUser = std::shared_ptr<app::User>;

struct Configuration
{
Expand Down
24 changes: 13 additions & 11 deletions wrappers/src/sync_user_cs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@
#include <realm/object-store/sync/app.hpp>
#include "app_cs.hpp"
#include "marshalling.hpp"
#include <realm/object-store/sync/app_user.hpp>

using namespace realm;
using namespace realm::binding;
using namespace app;

using SharedSyncUser = std::shared_ptr<SyncUser>;
using SharedSyncUser = std::shared_ptr<User>;
using SharedSyncSession = std::shared_ptr<SyncSession>;
using UserChangedCallbackT = void(void* managed_user_handle);

Expand Down Expand Up @@ -79,8 +79,10 @@ inline AuthProvider to_auth_provider(const std::string& provider) {
return (AuthProvider)999;
}
}
}

void to_json(nlohmann::json& j, const SyncUserIdentity& i)
namespace realm::app {
void to_json(nlohmann::json& j, const UserIdentity& i)
{
j = nlohmann::json{
{ "Id", i.id },
Expand All @@ -107,8 +109,8 @@ extern "C" {
REALM_EXPORT size_t realm_syncuser_get_id(SharedSyncUser& user, uint16_t* buffer, size_t buffer_length, NativeException::Marshallable& ex)
{
return handle_errors(ex, [&] {
std::string identity(user->identity());
return stringdata_to_csharpstringbuffer(identity, buffer, buffer_length);
std::string user_id(user->user_id());
return stringdata_to_csharpstringbuffer(user_id, buffer, buffer_length);
});
}

Expand Down Expand Up @@ -164,17 +166,17 @@ extern "C" {
});
}

REALM_EXPORT Subscribable<realm::SyncUser>::Token* realm_syncuser_register_changed_callback(SharedSyncUser& user, void* managed_user_handle, NativeException::Marshallable& ex)
REALM_EXPORT Subscribable<User>::Token* realm_syncuser_register_changed_callback(SharedSyncUser& user, void* managed_user_handle, NativeException::Marshallable& ex)
{
return handle_errors(ex, [&] {
auto token = user->subscribe([managed_user_handle](const SyncUser&) {
s_user_changed_callback(managed_user_handle);
});
return new Subscribable<realm::SyncUser>::Token(std::move(token));
return new Subscribable<User>::Token(std::move(token));
});
}

REALM_EXPORT void realm_syncuser_unregister_property_changed_callback(SharedSyncUser& user, Subscribable<realm::SyncUser>::Token& token, NativeException::Marshallable& ex)
REALM_EXPORT void realm_syncuser_unregister_property_changed_callback(SharedSyncUser& user, Subscribable<User>::Token& token, NativeException::Marshallable& ex)
{
handle_errors(ex, [&] {
user->unsubscribe(token);
Expand Down Expand Up @@ -252,7 +254,7 @@ extern "C" {
// If the user is detached from the sync manager, we'll hit an assert, so this early check avoids that.
if (user->state() != SyncUser::State::Removed)
{
if (auto shared_app = user->sync_manager()->app().lock()) {
if (auto shared_app = user->app()) {
return new SharedApp(shared_app);
}
}
Expand Down Expand Up @@ -353,11 +355,11 @@ extern "C" {
if (partition_buf) {
Utf16StringAccessor partition(partition_buf, partition_len);
auto sync_config = SyncConfig(user, partition);
path = user->sync_manager()->path_for_realm(std::move(sync_config));
path = user->path_for_realm(std::move(sync_config));
}
else {
auto sync_config = SyncConfig(user, realm::SyncConfig::FLXSyncEnabled{});
path = user->sync_manager()->path_for_realm(std::move(sync_config), "default");
path = user->path_for_realm(std::move(sync_config), "default");
}

return stringdata_to_csharpstringbuffer(path, pathbuffer, pathbuffer_len);
Expand Down

0 comments on commit 3edae22

Please sign in to comment.