1 // Copyright 2020 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chromeos/dbus/ip_peripheral/fake_ip_peripheral_service_client.h"
6
7 #include <utility>
8
9 #include "base/bind.h"
10 #include "base/threading/thread_task_runner_handle.h"
11
12 namespace chromeos {
13 namespace {
14
15 FakeIpPeripheralServiceClient* g_instance = nullptr;
16
17 constexpr int32_t kMinPan = -400;
18 constexpr int32_t kMaxPan = 400;
19 constexpr int32_t kMinTilt = -300;
20 constexpr int32_t kMaxTilt = 300;
21 constexpr int32_t kMinZoom = 100;
22 constexpr int32_t kMaxZoom = 500;
23
24 } // namespace
25
26 // static
Get()27 FakeIpPeripheralServiceClient* FakeIpPeripheralServiceClient::Get() {
28 CHECK(g_instance);
29 return g_instance;
30 }
31
FakeIpPeripheralServiceClient()32 FakeIpPeripheralServiceClient::FakeIpPeripheralServiceClient() {
33 CHECK(!g_instance);
34 g_instance = this;
35 }
36
~FakeIpPeripheralServiceClient()37 FakeIpPeripheralServiceClient::~FakeIpPeripheralServiceClient() {
38 CHECK_EQ(g_instance, this);
39 g_instance = nullptr;
40 }
41
GetPan(const std::string & ip,GetCallback callback)42 void FakeIpPeripheralServiceClient::GetPan(const std::string& ip,
43 GetCallback callback) {
44 get_pan_call_count_++;
45 base::ThreadTaskRunnerHandle::Get()->PostTask(
46 FROM_HERE,
47 base::BindOnce(std::move(callback), true, pan_, kMinPan, kMaxPan));
48 }
49
GetTilt(const std::string & ip,GetCallback callback)50 void FakeIpPeripheralServiceClient::GetTilt(const std::string& ip,
51 GetCallback callback) {
52 get_tilt_call_count_++;
53 base::ThreadTaskRunnerHandle::Get()->PostTask(
54 FROM_HERE,
55 base::BindOnce(std::move(callback), true, tilt_, kMinTilt, kMaxTilt));
56 }
57
GetZoom(const std::string & ip,GetCallback callback)58 void FakeIpPeripheralServiceClient::GetZoom(const std::string& ip,
59 GetCallback callback) {
60 get_zoom_call_count_++;
61 base::ThreadTaskRunnerHandle::Get()->PostTask(
62 FROM_HERE,
63 base::BindOnce(std::move(callback), true, zoom_, kMinZoom, kMaxZoom));
64 }
65
SetPan(const std::string & ip,int32_t pan,SetCallback callback)66 void FakeIpPeripheralServiceClient::SetPan(const std::string& ip,
67 int32_t pan,
68 SetCallback callback) {
69 set_pan_call_count_++;
70 pan_ = pan;
71 base::ThreadTaskRunnerHandle::Get()->PostTask(
72 FROM_HERE, base::BindOnce(std::move(callback), true));
73 }
74
SetTilt(const std::string & ip,int32_t tilt,SetCallback callback)75 void FakeIpPeripheralServiceClient::SetTilt(const std::string& ip,
76 int32_t tilt,
77 SetCallback callback) {
78 set_tilt_call_count_++;
79 tilt_ = tilt;
80 base::ThreadTaskRunnerHandle::Get()->PostTask(
81 FROM_HERE, base::BindOnce(std::move(callback), true));
82 }
83
SetZoom(const std::string & ip,int32_t zoom,SetCallback callback)84 void FakeIpPeripheralServiceClient::SetZoom(const std::string& ip,
85 int32_t zoom,
86 SetCallback callback) {
87 set_zoom_call_count_++;
88 zoom_ = zoom;
89 base::ThreadTaskRunnerHandle::Get()->PostTask(
90 FROM_HERE, base::BindOnce(std::move(callback), true));
91 }
92
93 } // namespace chromeos
94