Skip to content

Commit

Permalink
Merge f96586a into 4c66ff0
Browse files Browse the repository at this point in the history
  • Loading branch information
nielsenko committed Mar 16, 2022
2 parents 4c66ff0 + f96586a commit 2a9a843
Show file tree
Hide file tree
Showing 14 changed files with 190 additions and 3 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/realm-dart-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ jobs:
with:
submodules: 'recursive'

- name: Install libraries with vcpkg
run: vcpkg --triplet x64-windows zlib # zlib needed when sync is enabled

- name: Build Realm Dart for Windows
run: scripts\build.bat

Expand Down
2 changes: 2 additions & 0 deletions ffigen/linux.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ headers:
- 'realm_dart.h'
- 'realm_dart_scheduler.h'
- 'realm_dart_collections.h'
- 'realm_dart_http_transport.h'
- 'realm_android_platform.h'
include-directives: #generate only for these headers
- 'realm.h'
- 'realm_dart.h'
- 'realm_dart_scheduler.h'
- 'realm_dart_collections.h'
- 'realm_dart_http_transport.h'
- 'realm_android_platform.h'
compiler-opts:
- '-DRLM_NO_ANON_UNIONS'
Expand Down
2 changes: 2 additions & 0 deletions ffigen/macos.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ headers:
- 'realm_dart.h'
- 'realm_dart_scheduler.h'
- 'realm_dart_collections.h'
- 'realm_dart_http_transport.h'
- 'realm_android_platform.h'
include-directives: #generate only for these headers
- 'realm.h'
- 'realm_dart.h'
- 'realm_dart_scheduler.h'
- 'realm_dart_collections.h'
- 'realm_dart_http_transport.h'
- 'realm_android_platform.h'
compiler-opts:
- '-DRLM_NO_ANON_UNIONS'
Expand Down
1 change: 1 addition & 0 deletions ffigen/realm_dart_http_transport.h
2 changes: 2 additions & 0 deletions ffigen/windows.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ headers:
- 'realm_dart.h'
- 'realm_dart_scheduler.h'
- 'realm_dart_collections.h'
- 'realm_dart_http_transport.h'
- 'realm_android_platform.h'
include-directives: #generate only for these headers
- 'realm.h'
- 'realm_dart.h'
- 'realm_dart_scheduler.h'
- 'realm_dart_collections.h'
- 'realm_dart_http_transport.h'
- 'realm_android_platform.h'
compiler-opts:
- '-DRLM_NO_ANON_UNIONS'
Expand Down
2 changes: 2 additions & 0 deletions flutter/realm_flutter/ios/Classes/RealmPlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#import "realm_dart.h"
#import "realm_dart_scheduler.h"
#import "realm_dart_collections.h"
#import "realm_dart_http_transport.h"
#import "platform.h"
@implementation RealmPlugin
+ (void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar>*)registrar {
Expand All @@ -43,6 +44,7 @@ void dummy(void) {
realm_results_get_object(NULL, 0);
realm_list_size(NULL, 0);
realm_dart_results_add_notification_callback(NULL, NULL, NULL, NULL);
realm_dart_http_transport_new(NULL, NULL);
realm_results_snapshot(NULL);
}

Expand Down
1 change: 1 addition & 0 deletions flutter/realm_flutter/ios/realm.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Pod::Spec.new do |s|
'src/realm_dart.cpp'
'src/realm_dart_scheduler.cpp'
'src/realm_dart_collections.cpp'
'src/realm_dart_http_transport.cpp'
s.public_header_files = 'Classes/**/*.h',
s.vendored_frameworks = 'realm_flutter_ios.xcframework'
s.dependency 'Flutter'
Expand Down
39 changes: 38 additions & 1 deletion lib/src/native/realm_bindings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// Generated by `package:ffigen`.
import 'dart:ffi' as ffi;

/// A Windows config for ffigen Usage: dart run ffigen --config windows.yaml
/// A MacOs config for ffigen Usage: dart run ffigen --config macos.yaml
class RealmLibrary {
/// Holds the symbol lookup function.
final ffi.Pointer<T> Function<T extends ffi.NativeType>(String symbolName)
Expand Down Expand Up @@ -7555,6 +7555,29 @@ class RealmLibrary {
realm_dart_on_object_change_func_t,
ffi.Pointer<realm_scheduler_t>)>();

/// Create a new HTTP transport with these callbacks implementing its functionality.
///
/// This is a dart specific wrapper for realm_http_transport_new.
ffi.Pointer<realm_http_transport_t> realm_dart_http_transport_new(
realm_dart_http_request_func_t request_callback,
Object userdata,
) {
return _realm_dart_http_transport_new(
request_callback,
userdata,
);
}

late final _realm_dart_http_transport_newPtr = _lookup<
ffi.NativeFunction<
ffi.Pointer<realm_http_transport_t> Function(
realm_dart_http_request_func_t,
ffi.Handle)>>('realm_dart_http_transport_new');
late final _realm_dart_http_transport_new =
_realm_dart_http_transport_newPtr.asFunction<
ffi.Pointer<realm_http_transport_t> Function(
realm_dart_http_request_func_t, Object)>();

ffi.Pointer<ffi.Int8> realm_dart_get_files_path() {
return _realm_dart_get_files_path();
}
Expand Down Expand Up @@ -8478,3 +8501,17 @@ typedef realm_dart_on_collection_change_func_t = ffi.Pointer<
typedef realm_dart_on_object_change_func_t = ffi.Pointer<
ffi.NativeFunction<
ffi.Void Function(ffi.Handle, ffi.Pointer<realm_object_changes_t>)>>;

/// Callback function used by Core to make a HTTP request.
///
/// Complete the request by calling realm_dart_http_transport_complete_request(),
/// passing in the request_context pointer here and the received response.
/// Network request are expected to be asynchronous and can be completed on any thread.
///
/// @param userdata The userdata pointer passed to realm_dart_http_transport_new().
/// @param request The request to send.
/// @param request_context Internal state pointer of Core, needed by realm_http_transport_complete_request().
typedef realm_dart_http_request_func_t = ffi.Pointer<
ffi.NativeFunction<
ffi.Void Function(
ffi.Handle, realm_http_request_t, ffi.Pointer<ffi.Void>)>>;
1 change: 1 addition & 0 deletions scripts/build-ios.sh
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ cp "$PROJECT_ROOT"/src/realm-core/src/realm.h _include/realm_dart_ios/
cp "$PROJECT_ROOT"/src/realm_dart.h _include/realm_dart_ios/
cp "$PROJECT_ROOT"/src/realm_dart_scheduler.h _include/realm_dart_ios/
cp "$PROJECT_ROOT"/src/realm_dart_collections.h _include/realm_dart_ios/
cp "$PROJECT_ROOT"/src/realm_dart_http_transport.h _include/realm_dart_ios/
cp -r "$PROJECT_ROOT"/src/dart-include _include/realm_dart_ios/


Expand Down
4 changes: 3 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ set(SOURCES
realm_dart.cpp
realm_dart_scheduler.cpp
realm_dart_collections.cpp
realm_dart_http_transport.cpp
dart-include/dart_api_dl.c
)

set(HEADERS
realm_dart.h
realm_dart_scheduler.h
realm_dart_collections.h
realm_dart_http_transport.h
realm-core/src/realm.h
)

Expand Down Expand Up @@ -42,7 +44,7 @@ endif()
option(REALM_BUILD_CORE_FROM_SOURCE "Build Realm Core from source" ON)
if(REALM_BUILD_CORE_FROM_SOURCE)
set(REALM_BUILD_LIB_ONLY ON)
set(REALM_ENABLE_SYNC OFF)
set(REALM_ENABLE_SYNC ON)

if(ANDROID)
message ("Realm Flutter Android build enabled")
Expand Down
2 changes: 1 addition & 1 deletion src/realm-core
Submodule realm-core updated 43 files
+3 −0 .gitmodules
+10 −13 CHANGELOG.md
+57 −44 CMakeLists.txt
+28 −8 Jenkinsfile
+5 −11 Package.swift
+1 −1 dependencies.list
+3 −1 evergreen/config.yml
+10 −0 src/realm.h
+1 −1 src/realm/column_type.hpp
+8 −1 src/realm/exec/CMakeLists.txt
+18 −1 src/realm/exec/realm2json.cpp
+54 −0 src/realm/exec/realm_decrypt.cpp
+2 −1 src/realm/exec/realm_trawler.cpp
+35 −49 src/realm/mixed.cpp
+10 −0 src/realm/object-store/c_api/config.cpp
+4 −1 src/realm/object-store/c_api/error.cpp
+1 −1 src/realm/object-store/impl/realm_coordinator.cpp
+3 −3 src/realm/object-store/shared_realm.cpp
+1 −1 src/realm/object-store/sync/sync_session.cpp
+6 −3 src/realm/object-store/util/event_loop_dispatcher.hpp
+6 −1 src/realm/sync/CMakeLists.txt
+1 −0 src/realm/sync/noinst/client_impl_base.cpp
+84 −48 src/realm/sync/subscriptions.cpp
+19 −7 src/realm/sync/subscriptions.hpp
+3 −2 src/realm/table_view.cpp
+2 −1 src/realm/table_view.hpp
+1 −0 src/realm/util/aes_cryptor.hpp
+34 −1 src/realm/util/encrypted_file_mapping.cpp
+22 −0 test/object-store/c_api/c_api.cpp
+66 −5 test/object-store/realm.cpp
+3 −37 test/object-store/sync/client_reset.cpp
+4 −4 test/object-store/sync/flx_sync.cpp
+0 −90 test/object-store/sync/sync_test_utils.cpp
+1 −3 test/object-store/sync/sync_test_utils.hpp
+25 −0 test/test_array_mixed.cpp
+46 −31 test/test_sync_subscriptions.cpp
+41 −34 tools/cmake/RealmConfig.cmake.in
+1 −0 tools/vcpkg/ports
+6 −0 tools/vcpkg/triplets/arm-uwp-static.cmake
+6 −0 tools/vcpkg/triplets/arm64-uwp-static.cmake
+6 −0 tools/vcpkg/triplets/x64-uwp-static.cmake
+6 −0 tools/vcpkg/triplets/x86-uwp-static.cmake
+20 −0 tools/vcpkg/vcpkg.json
1 change: 1 addition & 0 deletions src/realm_dart.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ void dummy(void) {
realm_list_size(nullptr, 0);
realm_results_add_notification_callback(nullptr, nullptr, nullptr, nullptr, nullptr, nullptr);
realm_results_snapshot(nullptr);
realm_http_transport_new(nullptr, nullptr, nullptr);
#if (ANDROID)
realm_android_dummy();
#endif
Expand Down
87 changes: 87 additions & 0 deletions src/realm_dart_http_transport.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
////////////////////////////////////////////////////////////////////////////////
//
// Copyright 2022 Realm Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
////////////////////////////////////////////////////////////////////////////////

#include "realm_dart_http_transport.h"
#include "dart_api_dl.h"

struct HandleScope {
HandleScope() {
Dart_EnterScope_DL();
}

~HandleScope() {
Dart_ExitScope_DL();
}
};

class RequestCallbackData {
static void finalize_handle(void* isolate_callback_data, void* peer) {
auto request_callback_data = static_cast<RequestCallbackData*>(peer);
request_callback_data->delete_handle();
}

void delete_handle() {
if (m_handle) {
Dart_DeleteWeakPersistentHandle_DL(m_handle);
m_handle = nullptr;
}
}

public:
RequestCallbackData(Dart_Handle handle, realm_dart_http_request_func_t callback)
: m_handle(Dart_NewWeakPersistentHandle_DL(handle, nullptr, 1, finalize_handle)), m_callback(callback)
{}

~RequestCallbackData() {
delete_handle();
}

void callback(const realm_http_request_t request, void* request_context) {
if (m_handle) {
HandleScope scope;
auto handle = Dart_HandleFromWeakPersistent_DL(m_handle);
m_callback(handle, request, request_context);
}
}

private:
Dart_WeakPersistentHandle m_handle;
realm_dart_http_request_func_t m_callback;
};

void free_request_callback_data(void* userdata) {
auto request_callback_data = static_cast<RequestCallbackData*>(userdata);
delete request_callback_data;
}

void on_request_callback(
void* userdata,
const realm_http_request_t request,
void* request_context)
{
auto request_callback_data = static_cast<RequestCallbackData*>(userdata);
request_callback_data->callback(request, request_context);
}

RLM_API realm_http_transport_t* realm_dart_http_transport_new(
realm_dart_http_request_func_t request_callback,
Dart_Handle userdata)
{
auto request_callback_data = new RequestCallbackData(userdata, request_callback);
return realm_http_transport_new(on_request_callback, request_callback_data, free_request_callback_data);
}
46 changes: 46 additions & 0 deletions src/realm_dart_http_transport.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
////////////////////////////////////////////////////////////////////////////////
//
// Copyright 2022 Realm Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
////////////////////////////////////////////////////////////////////////////////

#ifndef REALM_DART_HTTP_TRANSPORT_H
#define REALM_DART_HTTP_TRANSPORT_H

#include "realm.h"
#include "dart_api_dl.h"

/**
* Callback function used by Core to make a HTTP request.
*
* Complete the request by calling realm_dart_http_transport_complete_request(),
* passing in the request_context pointer here and the received response.
* Network request are expected to be asynchronous and can be completed on any thread.
*
* @param userdata The userdata pointer passed to realm_dart_http_transport_new().
* @param request The request to send.
* @param request_context Internal state pointer of Core, needed by realm_http_transport_complete_request().
*/
typedef void (*realm_dart_http_request_func_t)(Dart_Handle userdata, const realm_http_request_t request, void* request_context);

/**
* Create a new HTTP transport with these callbacks implementing its functionality.
*
* This is a dart specific wrapper for realm_http_transport_new.
*/
RLM_API realm_http_transport_t* realm_dart_http_transport_new(realm_dart_http_request_func_t request_callback,
Dart_Handle userdata);

#endif

0 comments on commit 2a9a843

Please sign in to comment.