Skip to content

Commit

Permalink
Adopting to changes in Realm Core
Browse files Browse the repository at this point in the history
  • Loading branch information
kraenhansen authored and kneth committed Oct 26, 2021
1 parent 14adbee commit d861347
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 31 deletions.
4 changes: 1 addition & 3 deletions src/js_app.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,7 @@ void AppClass<T>::constructor(ContextType ctx, ObjectType this_object, Arguments
throw std::runtime_error("Expected either a configuration object or an app id string.");
}

config.transport_generator = [ctx = Protected(Context::get_global_context(ctx)), eld=NetworkTransport::make_dispatcher()] {
return AppClass<T>::transport_generator(ctx, eld);
};
config.transport = AppClass<T>::transport_generator(Protected(Context::get_global_context(ctx)), NetworkTransport::make_dispatcher());

config.platform = platform_os;
config.platform_version = platform_version;
Expand Down
16 changes: 8 additions & 8 deletions src/js_sync.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -412,14 +412,14 @@ void SessionClass<T>::add_progress_notification(ContextType ctx, ObjectType this

if (auto session = get_internal<T, SessionClass<T>>(ctx, this_object)->lock()) {

std::string direction = Value::validated_to_string(ctx, args[0], "direction");
std::string direction_str = Value::validated_to_string(ctx, args[0], "direction");
std::string mode = Value::validated_to_string(ctx, args[1], "mode");
SyncSession::NotifierType notifierType;
if (direction == "download") {
notifierType = SyncSession::NotifierType::download;
SyncSession::ProgressDirection direction;
if (direction_str == "download") {
direction = SyncSession::ProgressDirection::download;
}
else if (direction == "upload") {
notifierType = SyncSession::NotifierType::upload;
else if (direction_str == "upload") {
direction = SyncSession::ProgressDirection::upload;
}
else {
throw std::invalid_argument("Invalid argument 'direction'. Only 'download' and 'upload' progress notification directions are supported");
Expand Down Expand Up @@ -455,7 +455,7 @@ void SessionClass<T>::add_progress_notification(ContextType ctx, ObjectType this

progressFunc = std::move(progress_handler);

auto registrationToken = session->register_progress_notifier(std::move(progressFunc), notifierType, is_streaming);
auto registrationToken = session->register_progress_notifier(std::move(progressFunc), direction, is_streaming);
auto syncSession = create_object<T, SessionClass<T>>(ctx, new WeakSession(session));
PropertyAttributes attributes = ReadOnly | DontEnum | DontDelete;
Object::set_property(ctx, callback_function, "_syncSession", syncSession, attributes);
Expand Down Expand Up @@ -755,7 +755,7 @@ void SyncClass<T>::set_sync_logger(ContextType ctx, ObjectType this_object, Argu
};

auto sync_logger = common::logger::Logger::build_sync_logger(show_logs);
app->sync_manager()->set_logger_factory( *sync_logger );
app->sync_manager()->set_logger_factory(sync_logger);
}

template<typename T>
Expand Down
27 changes: 7 additions & 20 deletions src/logger.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,24 +112,6 @@ class SyncLoggerDelegator : public util::RootLogger {
Delegated loggerDelegate;
};

class SyncLoggerDelegatorFactory : public realm::SyncLoggerFactory {
public:
SyncLoggerDelegatorFactory(Delegated logs_fn) : logs_fn{logs_fn} {}

std::unique_ptr<realm::util::Logger> make_logger(
realm::util::Logger::Level level) {
auto logger = std::make_unique<SyncLoggerDelegator>();

logger->set_level_threshold(level);
logger->delegate(logs_fn);

return logger;
}

private:
Delegated logs_fn;
};

class Logger {
private:
// Warning: If this grows to big (for example: another method) we should
Expand Down Expand Up @@ -157,8 +139,13 @@ class Logger {
throw std::runtime_error("Bad log level");
}

static SyncLoggerDelegatorFactory* build_sync_logger(Delegated& log_fn) {
return new SyncLoggerDelegatorFactory(log_fn);
static SyncClientConfig::LoggerFactory build_sync_logger(Delegated& log_fn) {
return [&log_fn] (realm::util::Logger::Level level) {
auto logger = std::make_unique<SyncLoggerDelegator>();
logger->set_level_threshold(level);
logger->delegate(log_fn);
return logger;
};
}
};

Expand Down

0 comments on commit d861347

Please sign in to comment.