Skip to content

Commit 589dbbe

Browse files
authored
RCORE-1940 conditionally compile out the app services code (#7589)
* conditionally compile out the app services code * exclude more code * review touchups * make the conditional define part of compile definitions rather than an include
1 parent e079db6 commit 589dbbe

File tree

22 files changed

+278
-178
lines changed

22 files changed

+278
-178
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
* App metadata storage has been entirely rewritten in preparation for supporting sharing metadata realms between processes. ([PR #7300](https://github.com/realm/realm-core/pull/7300).
4848
* The metadata disabled mode has been replaced with an in-memory metadata mode which performs similarly and doesn't work weirdly differently from the normal mode. The new mode is intended for testing purposes, but should be suitable for production usage if there is a scenario where metadata persistence is not needed. ([PR #7300](https://github.com/realm/realm-core/pull/7300).
4949
* The ownership relationship between App and User has changed. User now strongly retains App and App has a weak cache of Users. This means that creating a SyncConfig or opening a Realm will keep the parent App alive, rather than things being in a broken state if the App is deallocated. ([PR #7300](https://github.com/realm/realm-core/pull/7300).
50+
* A new CMake define `REALM_APP_SERVICES` can be used to compile out core's default implmentation of the application services. ([#7268](https://github.com/realm/realm-core/issues/7268))
5051

5152
----------------------------------------------
5253

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,7 @@ option(REALM_VALGRIND "Tell the test suite we are running with valgrind" OFF)
266266
option(REALM_SYNC_MULTIPLEXING "Enables/disables sync session multiplexing by default" ON)
267267
set(REALM_MAX_BPNODE_SIZE "1000" CACHE STRING "Max B+ tree node size.")
268268
option(REALM_ENABLE_GEOSPATIAL "Enable geospatial types and queries." ON)
269+
option(REALM_APP_SERVICES "Enable the default app services implementation." ON)
269270

270271
# Find dependencies
271272
set(THREADS_PREFER_PTHREAD_FLAG ON)

Package.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ var cxxSettings: [CXXSetting] = [
1717
.define("REALM_ENABLE_ENCRYPTION", to: "1"),
1818
.define("REALM_ENABLE_SYNC", to: "1"),
1919
.define("REALM_ENABLE_GEOSPATIAL", to: "1"),
20+
.define("REALM_APP_SERVICES", to: "1"),
2021

2122
.define("REALM_VERSION_MAJOR", to: String(versionCompontents[0])),
2223
.define("REALM_VERSION_MINOR", to: String(versionCompontents[1])),
@@ -493,7 +494,8 @@ let package = Package(
493494
.target(
494495
name: "RealmFFI",
495496
dependencies: ["Capi"],
496-
path: "src/swift"),
497+
path: "src/swift",
498+
cxxSettings: (cxxSettings) as [CXXSetting]),
497499
.target(
498500
name: "Catch2Generated",
499501
path: "external/generated",

evergreen/config.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1874,3 +1874,17 @@ buildvariants:
18741874
tasks:
18751875
- name: compile_local_tests
18761876

1877+
- name: ubuntu-no-app-services
1878+
display_name: "Ubuntu (AppServices Disabled)"
1879+
run_on: ubuntu2204-arm64-large
1880+
expansions:
1881+
cmake_url: "https://s3.amazonaws.com/static.realm.io/evergreen-assets/cmake-3.26.3-linux-aarch64.tar.gz"
1882+
cmake_bindir: "./cmake_binaries/bin"
1883+
fetch_missing_dependencies: On
1884+
c_compiler: "/opt/clang+llvm/bin/clang"
1885+
cxx_compiler: "/opt/clang+llvm/bin/clang++"
1886+
extra_flags: "-DREALM_APP_SERVICES=OFF"
1887+
disable_tests_against_baas: On
1888+
tasks:
1889+
- name: compile_local_tests
1890+

src/realm.h

Lines changed: 95 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,20 @@
1-
/*
2-
FIXME: License, since this header may be distributed independently from
3-
other headers.
4-
*/
1+
/*************************************************************************
2+
*
3+
* Copyright 2024 Realm Inc.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*
17+
**************************************************************************/
518

619
#ifndef REALM_H
720
#define REALM_H
@@ -2861,16 +2874,39 @@ RLM_API realm_http_transport_t* realm_http_transport_new(realm_http_request_func
28612874
RLM_API void realm_http_transport_complete_request(void* request_context, const realm_http_response_t* response);
28622875

28632876
/* App */
2864-
typedef struct realm_app realm_app_t;
2865-
typedef struct realm_app_credentials realm_app_credentials_t;
28662877
typedef struct realm_user realm_user_t;
2867-
28682878
typedef enum realm_user_state {
28692879
RLM_USER_STATE_LOGGED_OUT,
28702880
RLM_USER_STATE_LOGGED_IN,
28712881
RLM_USER_STATE_REMOVED
28722882
} realm_user_state_e;
28732883

2884+
// This type should never be returned from a function.
2885+
// It's only meant as an asynchronous callback argument.
2886+
// Pointers to this struct and its pointer members are only valid inside the scope
2887+
// of the callback they were passed to.
2888+
typedef struct realm_app_error {
2889+
realm_errno_e error;
2890+
realm_error_categories categories;
2891+
const char* message;
2892+
2893+
/**
2894+
* The underlying HTTP status code returned by the server,
2895+
* otherwise zero.
2896+
*/
2897+
int http_status_code;
2898+
2899+
/**
2900+
* A link to MongoDB Realm server logs related to the error,
2901+
* or NULL if error response didn't contain log information.
2902+
*/
2903+
const char* link_to_server_logs;
2904+
} realm_app_error_t;
2905+
2906+
#if REALM_APP_SERVICES
2907+
typedef struct realm_app realm_app_t;
2908+
typedef struct realm_app_credentials realm_app_credentials_t;
2909+
28742910
typedef enum realm_auth_provider {
28752911
RLM_AUTH_PROVIDER_ANONYMOUS,
28762912
RLM_AUTH_PROVIDER_ANONYMOUS_NO_REUSE,
@@ -2896,28 +2932,6 @@ typedef struct realm_app_user_apikey {
28962932
bool disabled;
28972933
} realm_app_user_apikey_t;
28982934

2899-
// This type should never be returned from a function.
2900-
// It's only meant as an asynchronous callback argument.
2901-
// Pointers to this struct and its pointer members are only valid inside the scope
2902-
// of the callback they were passed to.
2903-
typedef struct realm_app_error {
2904-
realm_errno_e error;
2905-
realm_error_categories categories;
2906-
const char* message;
2907-
2908-
/**
2909-
* The underlying HTTP status code returned by the server,
2910-
* otherwise zero.
2911-
*/
2912-
int http_status_code;
2913-
2914-
/**
2915-
* A link to MongoDB Realm server logs related to the error,
2916-
* or NULL if error response didn't contain log information.
2917-
*/
2918-
const char* link_to_server_logs;
2919-
} realm_app_error_t;
2920-
29212935
typedef struct realm_user_identity {
29222936
/**
29232937
* Ptr to null terminated string representing user identity (memory has to be freed by SDK)
@@ -3391,19 +3405,6 @@ RLM_API void realm_app_sync_client_wait_for_sessions_to_terminate(realm_app_t*)
33913405
*/
33923406
RLM_API char* realm_app_sync_client_get_default_file_path_for_realm(const realm_sync_config_t*,
33933407
const char* custom_filename);
3394-
/**
3395-
* Return the identiy for the user passed as argument
3396-
* @param user ptr to the user for which the identiy has to be retrieved
3397-
* @return a ptr to the identity string. This must be manually released with realm_free().
3398-
*/
3399-
RLM_API char* realm_user_get_identity(const realm_user_t* user) RLM_API_NOEXCEPT;
3400-
3401-
/**
3402-
* Retrieve the state for the user passed as argument
3403-
* @param user ptr to the user for which the state has to be retrieved
3404-
* @return realm_user_state_e value
3405-
*/
3406-
RLM_API realm_user_state_e realm_user_get_state(const realm_user_t* user) RLM_API_NOEXCEPT;
34073408

34083409
/**
34093410
* Get the list of identities of this @a user.
@@ -3430,8 +3431,6 @@ RLM_API char* realm_user_get_device_id(const realm_user_t*) RLM_API_NOEXCEPT;
34303431
*/
34313432
RLM_API bool realm_user_log_out(realm_user_t*);
34323433

3433-
RLM_API bool realm_user_is_logged_in(const realm_user_t*) RLM_API_NOEXCEPT;
3434-
34353434
/**
34363435
* Get the custom user data from the user's access token.
34373436
*
@@ -3452,24 +3451,65 @@ RLM_API char* realm_user_get_custom_data(const realm_user_t*) RLM_API_NOEXCEPT;
34523451
*/
34533452
RLM_API char* realm_user_get_profile_data(const realm_user_t*);
34543453

3454+
typedef struct realm_app_user_subscription_token realm_app_user_subscription_token_t;
3455+
typedef void (*realm_sync_on_user_state_changed_t)(realm_userdata_t userdata, realm_user_state_e s);
34553456
/**
3456-
* Return the access token associated with the user.
3457-
* @return a string that rapresents the access token
3457+
* @return a notification token object. Dispose it to stop receiving notifications.
34583458
*/
3459-
RLM_API char* realm_user_get_access_token(const realm_user_t*);
3459+
RLM_API realm_app_user_subscription_token_t*
3460+
realm_sync_user_on_state_change_register_callback(realm_user_t*, realm_sync_on_user_state_changed_t,
3461+
realm_userdata_t userdata,
3462+
realm_free_userdata_func_t userdata_free);
34603463

34613464
/**
3462-
* Return the refresh token associated with the user.
3463-
* @return a string that represents the refresh token
3465+
* In case manual reset is needed, run this function in order to reset sync client files.
3466+
* The sync_path is going to passed into realm_sync_error_handler_func_t, if manual reset is needed.
3467+
* This function is supposed to be called inside realm_sync_error_handler_func_t callback, if sync client reset is
3468+
* needed
3469+
* @param realm_app ptr to realm app.
3470+
* @param sync_path path where the sync files are.
3471+
* @param did_run ptr to bool, which will be set to true if operation was successful
3472+
* @return true if operation was successful
34643473
*/
3465-
RLM_API char* realm_user_get_refresh_token(const realm_user_t*);
3474+
RLM_API bool realm_sync_immediately_run_file_actions(realm_app_t* realm_app, const char* sync_path,
3475+
bool* did_run) RLM_API_NOEXCEPT;
34663476

34673477
/**
34683478
* Return the realm app for the user passed as parameter.
34693479
* @return a ptr to the app for the user.
34703480
*/
34713481
RLM_API realm_app_t* realm_user_get_app(const realm_user_t*) RLM_API_NOEXCEPT;
34723482

3483+
#endif // REALM_APP_SERVICES
3484+
3485+
/**
3486+
* Return the identiy for the user passed as argument
3487+
* @param user ptr to the user for which the identiy has to be retrieved
3488+
* @return a ptr to the identity string. This must be manually released with realm_free().
3489+
*/
3490+
RLM_API char* realm_user_get_identity(const realm_user_t* user) RLM_API_NOEXCEPT;
3491+
3492+
/**
3493+
* Retrieve the state for the user passed as argument
3494+
* @param user ptr to the user for which the state has to be retrieved
3495+
* @return realm_user_state_e value
3496+
*/
3497+
RLM_API realm_user_state_e realm_user_get_state(const realm_user_t* user) RLM_API_NOEXCEPT;
3498+
3499+
RLM_API bool realm_user_is_logged_in(const realm_user_t*) RLM_API_NOEXCEPT;
3500+
3501+
/**
3502+
* Return the access token associated with the user.
3503+
* @return a string that rapresents the access token
3504+
*/
3505+
RLM_API char* realm_user_get_access_token(const realm_user_t*);
3506+
3507+
/**
3508+
* Return the refresh token associated with the user.
3509+
* @return a string that represents the refresh token
3510+
*/
3511+
RLM_API char* realm_user_get_refresh_token(const realm_user_t*);
3512+
34733513

34743514
/* Sync */
34753515
typedef enum realm_sync_client_reconnect_mode {
@@ -3601,13 +3641,10 @@ typedef enum realm_flx_sync_subscription_set_state {
36013641
typedef void (*realm_sync_on_subscription_state_changed_t)(realm_userdata_t userdata,
36023642
realm_flx_sync_subscription_set_state_e state);
36033643

3604-
typedef void (*realm_sync_on_user_state_changed_t)(realm_userdata_t userdata, realm_user_state_e s);
3605-
36063644

36073645
typedef struct realm_async_open_task_progress_notification_token realm_async_open_task_progress_notification_token_t;
36083646
typedef struct realm_sync_session_connection_state_notification_token
36093647
realm_sync_session_connection_state_notification_token_t;
3610-
typedef struct realm_app_user_subscription_token realm_app_user_subscription_token_t;
36113648

36123649
/**
36133650
* Callback function invoked by the async open task once the realm is open and fully synchronized.
@@ -3976,18 +4013,6 @@ RLM_API void realm_sync_session_resume(realm_sync_session_t*) RLM_API_NOEXCEPT;
39764013
RLM_API void realm_sync_session_get_file_ident(realm_sync_session_t*,
39774014
realm_salted_file_ident_t* out) RLM_API_NOEXCEPT;
39784015

3979-
/**
3980-
* In case manual reset is needed, run this function in order to reset sync client files.
3981-
* The sync_path is going to passed into realm_sync_error_handler_func_t, if manual reset is needed.
3982-
* This function is supposed to be called inside realm_sync_error_handler_func_t callback, if sync client reset is
3983-
* needed
3984-
* @param realm_app ptr to realm app.
3985-
* @param sync_path path where the sync files are.
3986-
* @param did_run ptr to bool, which will be set to true if operation was successful
3987-
* @return true if operation was successful
3988-
*/
3989-
RLM_API bool realm_sync_immediately_run_file_actions(realm_app_t* realm_app, const char* sync_path,
3990-
bool* did_run) RLM_API_NOEXCEPT;
39914016

39924017
/**
39934018
* Register a callback that will be invoked every time the session's connection state changes.
@@ -4014,14 +4039,6 @@ RLM_API realm_sync_session_connection_state_notification_token_t* realm_sync_ses
40144039
realm_userdata_t userdata, realm_free_userdata_func_t userdata_free) RLM_API_NOEXCEPT;
40154040

40164041

4017-
/**
4018-
* @return a notification token object. Dispose it to stop receiving notifications.
4019-
*/
4020-
RLM_API realm_app_user_subscription_token_t*
4021-
realm_sync_user_on_state_change_register_callback(realm_user_t*, realm_sync_on_user_state_changed_t,
4022-
realm_userdata_t userdata,
4023-
realm_free_userdata_func_t userdata_free);
4024-
40254042
/**
40264043
* Register a callback that will be invoked when all pending downloads have completed.
40274044
*/
@@ -4057,6 +4074,9 @@ RLM_API void realm_sync_session_handle_error_for_testing(const realm_sync_sessio
40574074
*/
40584075
RLM_API void realm_register_user_code_callback_error(realm_userdata_t usercode_error) RLM_API_NOEXCEPT;
40594076

4077+
4078+
#if REALM_APP_SERVICES
4079+
40604080
typedef struct realm_mongodb_collection realm_mongodb_collection_t;
40614081

40624082
typedef struct realm_mongodb_find_options {
@@ -4275,6 +4295,8 @@ RLM_API bool realm_mongo_collection_find_one_and_delete(realm_mongodb_collection
42754295
realm_userdata_t data, realm_free_userdata_func_t delete_data,
42764296
realm_mongodb_callback_t callback);
42774297

4298+
#endif // REALM_APP_SERVICES
4299+
42784300
/**
42794301
* Creates a new sync socket instance for the Sync Client that handles the operations for a custom
42804302
* websocket and event loop implementation.

0 commit comments

Comments
 (0)