-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsane_client_fake.cc
78 lines (64 loc) · 2.11 KB
/
sane_client_fake.cc
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
74
75
76
77
78
// Copyright 2020 The ChromiumOS Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "lorgnette/sane_client_fake.h"
#include <algorithm>
#include <map>
#include <optional>
#include <utility>
#include <chromeos/dbus/service_constants.h>
#include "lorgnette/constants.h"
#include "lorgnette/dbus_adaptors/org.chromium.lorgnette.Manager.h"
namespace lorgnette {
std::unique_ptr<SaneDevice> SaneClientFake::ConnectToDeviceInternal(
brillo::ErrorPtr* error,
SANE_Status* sane_status,
const std::string& device_name) {
if (devices_.count(device_name) > 0) {
auto ptr = std::move(devices_[device_name]);
devices_.erase(device_name);
return ptr;
}
brillo::Error::AddTo(error, FROM_HERE, kDbusDomain, kManagerServiceError,
"No device");
if (sane_status) {
*sane_status = SANE_STATUS_INVAL;
}
return nullptr;
}
void SaneClientFake::SetListDevicesResult(bool value) {
list_devices_result_ = value;
}
void SaneClientFake::AddDevice(const std::string& name,
const std::string& manufacturer,
const std::string& model,
const std::string& type) {
ScannerInfo info;
info.set_name(name);
info.set_manufacturer(manufacturer);
info.set_model(model);
info.set_type(type);
scanners_.push_back(info);
}
void SaneClientFake::RemoveDevice(const std::string& name) {
auto it = scanners_.begin();
while (it != scanners_.end()) {
if (it->name() == name) {
it = scanners_.erase(it);
} else {
++it;
}
}
}
void SaneClientFake::SetDeviceForName(const std::string& device_name,
std::unique_ptr<SaneDeviceFake> device) {
devices_.emplace(device_name, std::move(device));
}
void SaneClientFake::SetIppUsbSocketDir(base::FilePath path) {
ippusb_socket_dir_ = std::move(path);
}
base::FilePath SaneClientFake::IppUsbSocketDir() const {
return ippusb_socket_dir_ ? *ippusb_socket_dir_
: SaneClient::IppUsbSocketDir();
}
} // namespace lorgnette