Skip to content

Commit d9e01ac

Browse files
amabluea-maurice
amablue
authored andcommitted
Hooked up special .info values. Special values .info/serverTimeOffset,
.info/authenticated, and .info/connected can now be queried and will return the appropriate results. PiperOrigin-RevId: 256015690
1 parent 55bf8ec commit d9e01ac

13 files changed

+279
-48
lines changed

database/CMakeLists.txt

+2
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,10 @@ set(desktop_SRCS
8282
src/desktop/connection/web_socket_client_impl.cc
8383
src/desktop/core/child_event_registration.cc
8484
src/desktop/core/compound_write.cc
85+
src/desktop/core/constants.cc
8586
src/desktop/core/event_registration.cc
8687
src/desktop/core/indexed_variant.cc
88+
src/desktop/core/info_listen_provider.cc
8789
src/desktop/core/keep_synced_event_registration.cc
8890
src/desktop/core/listen_provider.cc
8991
src/desktop/core/operation.cc

database/src/desktop/connection/persistent_connection.cc

+5-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "app/src/path.h"
2626
#include "app/src/time.h"
2727
#include "app/src/variant_util.h"
28+
#include "database/src/desktop/core/constants.h"
2829
#include "database/src/desktop/util_desktop.h"
2930
#include "database/src/include/firebase/database/common.h"
3031

@@ -172,7 +173,10 @@ void PersistentConnection::OnReady(int64_t timestamp,
172173
// Trigger OnServerInfoUpdate based on timestamp delta
173174
LogDebug("%s Handle timestamp: %lld in ms", log_id_.c_str(), timestamp);
174175
int64_t time_delta = timestamp - ::firebase::internal::GetTimestampEpoch();
175-
event_handler_->OnServerInfoUpdate(time_delta);
176+
std::map<Variant, Variant> updates{
177+
std::make_pair(kDotInfoServerTimeOffset, time_delta),
178+
};
179+
event_handler_->OnServerInfoUpdate(updates);
176180

177181
// Send client SDK status
178182
if (is_first_connection_) {

database/src/desktop/connection/persistent_connection.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,8 @@ class PersistentConnectionEventHandler {
543543

544544
virtual void OnAuthStatus(bool auth_ok) = 0;
545545

546-
virtual void OnServerInfoUpdate(int64_t timestamp_delta) = 0;
546+
virtual void OnServerInfoUpdate(
547+
const std::map<Variant, Variant>& updates) = 0;
547548

548549
virtual void OnDataUpdate(const Path& path, const Variant& payload_data,
549550
bool is_merge,
+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Copyright 2019 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#include "database/src/desktop/core/constants.h"
16+
17+
namespace firebase {
18+
namespace database {
19+
namespace internal {
20+
21+
const char kDotInfo[] = ".info";
22+
const char kDotInfoServerTimeOffset[] = "serverTimeOffset";
23+
const char kDotInfoAuthenticated[] = "authenticated";
24+
const char kDotInfoConnected[] = "connected";
25+
26+
} // namespace internal
27+
} // namespace database
28+
} // namespace firebase

database/src/desktop/core/constants.h

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Copyright 2019 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#ifndef FIREBASE_DATABASE_CLIENT_CPP_SRC_DESKTOP_CORE_CONSTANTS_H_
16+
#define FIREBASE_DATABASE_CLIENT_CPP_SRC_DESKTOP_CORE_CONSTANTS_H_
17+
18+
namespace firebase {
19+
namespace database {
20+
namespace internal {
21+
22+
extern const char kDotInfo[];
23+
extern const char kDotInfoServerTimeOffset[];
24+
extern const char kDotInfoAuthenticated[];
25+
extern const char kDotInfoConnected[];
26+
27+
} // namespace internal
28+
} // namespace database
29+
} // namespace firebase
30+
31+
#endif // FIREBASE_DATABASE_CLIENT_CPP_SRC_DESKTOP_CORE_CONSTANTS_H_
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// Copyright 2019 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#include "database/src/desktop/core/info_listen_provider.h"
16+
17+
#include "database/src/common/query_spec.h"
18+
#include "database/src/desktop/connection/persistent_connection.h"
19+
#include "database/src/desktop/core/listen_provider.h"
20+
#include "database/src/desktop/util_desktop.h"
21+
#include "database/src/desktop/view/view.h"
22+
23+
namespace firebase {
24+
namespace database {
25+
namespace internal {
26+
27+
void InfoListenProvider::StartListening(const QuerySpec& query_spec,
28+
const View* view) {
29+
repo_->scheduler().Schedule([this, query_spec]() {
30+
const Variant& value = VariantGetChild(info_data_, query_spec.path);
31+
if (!VariantIsEmpty(value)) {
32+
repo_->PostEvents(
33+
sync_tree_->ApplyServerOverwrite(query_spec.path, value));
34+
}
35+
});
36+
}
37+
38+
void InfoListenProvider::StopListening(const QuerySpec& query_spec) {}
39+
40+
} // namespace internal
41+
} // namespace database
42+
} // namespace firebase
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// Copyright 2019 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#ifndef FIREBASE_DATABASE_CLIENT_CPP_SRC_DESKTOP_CORE_INFO_LISTEN_PROVIDER_H_
16+
#define FIREBASE_DATABASE_CLIENT_CPP_SRC_DESKTOP_CORE_INFO_LISTEN_PROVIDER_H_
17+
18+
#include "database/src/common/query_spec.h"
19+
#include "database/src/desktop/connection/persistent_connection.h"
20+
#include "database/src/desktop/core/listen_provider.h"
21+
#include "database/src/desktop/core/repo.h"
22+
23+
namespace firebase {
24+
namespace database {
25+
namespace internal {
26+
27+
class InfoListenProvider : public ListenProvider {
28+
public:
29+
InfoListenProvider(Repo* repo, Variant* info_data)
30+
: repo_(repo), info_data_(info_data), sync_tree_(nullptr) {}
31+
32+
~InfoListenProvider() override {}
33+
34+
void set_sync_tree(SyncTree* sync_tree) { sync_tree_ = sync_tree; }
35+
36+
void StartListening(const QuerySpec& query_spec, const View* view) override;
37+
38+
void StopListening(const QuerySpec& query_spec) override;
39+
40+
private:
41+
Repo* repo_;
42+
Variant* info_data_;
43+
SyncTree* sync_tree_;
44+
};
45+
46+
} // namespace internal
47+
} // namespace database
48+
} // namespace firebase
49+
50+
#endif // FIREBASE_DATABASE_CLIENT_CPP_SRC_DESKTOP_CORE_INFO_LISTEN_PROVIDER_H_

0 commit comments

Comments
 (0)