| // Copyright 2023 The Fuchsia Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| |
| #include "pcf8563-server.h" |
| |
| #include <fidl/fuchsia.hardware.rtc/cpp/fidl.h> |
| #include <lib/driver/logging/cpp/logger.h> |
| #include <lib/fdf/cpp/dispatcher.h> |
| #include <lib/fit/result.h> |
| |
| #include <functional> |
| #include <memory> |
| #include <utility> |
| |
| namespace pcf8563 { |
| |
| namespace frtc = fuchsia_hardware_rtc; |
| |
| frtc::Service::InstanceHandler RtcServer::GetInstanceHandler() { |
| auto dispatcher = fdf::Dispatcher::GetCurrent(); |
| return frtc::Service::InstanceHandler({ |
| .device = bindings_.CreateHandler(this, dispatcher->async_dispatcher(), |
| fidl::kIgnoreBindingClosure), |
| }); |
| } |
| |
| void RtcServer::Get(GetCompleter::Sync& completer) { |
| if (auto result{device_->Read()}; result.is_error()) { |
| completer.Reply(fit::error(result.status_value())); |
| } else { |
| completer.Reply(fit::ok(result.value())); |
| } |
| } |
| |
| void RtcServer::Set(SetRequest& req, SetCompleter::Sync& completer) { |
| auto result{device_->Write(req.rtc())}; |
| completer.Reply(result.status_value()); |
| } |
| |
| void RtcServer::OnUnbound(fidl::UnbindInfo info, fidl::ServerEnd<frtc::Device> server_end) { |
| if (info.is_peer_closed()) { |
| FDF_LOG(DEBUG, "client disconnected"); |
| } else if (!info.is_user_initiated()) { |
| FDF_LOG(ERROR, "client unbound: %s", info.status_string()); |
| } |
| } |
| |
| } // namespace pcf8563 |