forked from realm/realm-swift
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRLMRealmConfiguration+Sync.mm
73 lines (62 loc) · 2.76 KB
/
RLMRealmConfiguration+Sync.mm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
////////////////////////////////////////////////////////////////////////////
//
// Copyright 2016 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.
//
////////////////////////////////////////////////////////////////////////////
#import "RLMRealmConfiguration+Sync.h"
#import "RLMRealmConfiguration_Private.hpp"
#import "RLMSyncConfiguration_Private.hpp"
#import "RLMSyncUser_Private.hpp"
#import "RLMSyncManager_Private.h"
#import "RLMSyncUtil_Private.hpp"
#import "RLMUtil.hpp"
#import "sync/sync_config.hpp"
#import "sync/sync_manager.hpp"
@implementation RLMRealmConfiguration (Sync)
#pragma mark - API
- (void)setSyncConfiguration:(RLMSyncConfiguration *)syncConfiguration {
if (self.config.should_compact_on_launch_function) {
@throw RLMException(@"Cannot set `syncConfiguration` when `shouldCompactOnLaunch` is set.");
}
RLMSyncUser *user = syncConfiguration.user;
if (user.state == RLMSyncUserStateError) {
@throw RLMException(@"Cannot set a sync configuration which has an errored-out user.");
}
// Ensure sync manager is initialized, if it hasn't already been.
[RLMSyncManager sharedManager];
NSAssert(user.identity, @"Cannot call this method on a user that doesn't have an identity.");
self.config.in_memory = false;
self.config.sync_config = std::make_shared<realm::SyncConfig>([syncConfiguration rawConfiguration]);
self.config.schema_mode = realm::SchemaMode::Additive;
if (syncConfiguration.customFileURL) {
self.config.path = syncConfiguration.customFileURL.path.UTF8String;
} else {
self.config.path = SyncManager::shared().path_for_realm(*[user _syncUser],
self.config.sync_config->realm_url());
}
if (!self.config.encryption_key.empty()) {
auto& sync_encryption_key = self.config.sync_config->realm_encryption_key;
sync_encryption_key = std::array<char, 64>();
std::copy_n(self.config.encryption_key.begin(), 64, sync_encryption_key->begin());
}
}
- (RLMSyncConfiguration *)syncConfiguration {
if (!self.config.sync_config) {
return nil;
}
realm::SyncConfig& sync_config = *self.config.sync_config;
return [[RLMSyncConfiguration alloc] initWithRawConfig:sync_config];
}
@end