Realm C++ SDK Version v2.2.0

sync_session.hpp

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//
18
19#ifndef CPPREALM_BRIDGE_SYNC_SESSION_HPP
20#define CPPREALM_BRIDGE_SYNC_SESSION_HPP
21
22#include <memory>
23#include <functional>
24#include <future>
25#include <system_error>
26
27namespace realm {
28 class SyncSession;
29 namespace internal::bridge {
30 struct status;
31 struct realm;
32
33 struct sync_session {
34
35 enum class state {
36 active,
37 dying,
38 inactive,
39 waiting_for_access_token,
40 paused
41 };
42
43 enum class connection_state {
44 disconnected,
45 connecting,
46 connected
47 };
48
49 // The session's current state.
50 enum state state() const;
51
52 // The session's current connection state.
53 enum connection_state connection_state() const;
54
55 // Register a callback that will be called when all pending uploads have completed.
56 // The callback is run asynchronously, and upon whatever thread the underlying sync client
57 // chooses to run it on.
58 void wait_for_upload_completion(std::function<void(status)>&& callback);
59
60 // Register a callback that will be called when all pending downloads have been completed.
61 // Works the same way as `wait_for_upload_completion()`.
62 void wait_for_download_completion(std::function<void(status)>&& callback);
63
64 // Register a callback that will be called when all pending uploads have completed.
65 // The callback is run asynchronously, and upon whatever thread the underlying sync client
66 // chooses to run it on.
67 std::future<void> wait_for_upload_completion();
68
69 // Register a callback that will be called when all pending downloads have been completed.
70 std::future<void> wait_for_download_completion();
71
78 void pause();
79
86 void resume();
87
103 void reconnect();
104
109 uint64_t observe_connection_change(std::function<void(enum connection_state old_state, enum connection_state new_state)>&& callback);
110
115 void unregister_connection_change_observer(uint64_t token);
116
117 operator std::weak_ptr<SyncSession>();
118 private:
119 std::weak_ptr<SyncSession> m_session;
120 sync_session(const std::shared_ptr<SyncSession> &);
121 friend struct internal::bridge::realm;
122 };
123 }
124}
125
126#endif //CPPREALM_BRIDGE_SYNC_SESSION_HPP
Definition: realm.hpp:67
Definition: status.hpp:63
Definition: sync_session.hpp:33
void resume()
Definition: sync_session.cpp:108
uint64_t observe_connection_change(std::function< void(enum connection_state old_state, enum connection_state new_state)> &&callback)
Definition: sync_session.cpp:124
void unregister_connection_change_observer(uint64_t token)
Definition: sync_session.cpp:134
void pause()
Definition: sync_session.cpp:100
void reconnect()
Definition: sync_session.cpp:116