-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsane_device_fake.h
96 lines (83 loc) · 3.21 KB
/
sane_device_fake.h
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
// Copyright 2023 The ChromiumOS Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef LORGNETTE_SANE_DEVICE_FAKE_H_
#define LORGNETTE_SANE_DEVICE_FAKE_H_
#include <cstdint>
#include <memory>
#include <optional>
#include <string>
#include <unordered_map>
#include <vector>
#include <sane/sane.h>
#include "lorgnette/sane_device.h"
namespace lorgnette {
class SaneDeviceFake : public SaneDevice {
public:
SaneDeviceFake();
~SaneDeviceFake();
std::optional<ValidOptionValues> GetValidOptionValues(
brillo::ErrorPtr* error) override;
std::optional<int> GetScanResolution(brillo::ErrorPtr* error) override {
return resolution_;
}
bool SetScanResolution(brillo::ErrorPtr* error, int resolution) override;
std::optional<std::string> GetDocumentSource(
brillo::ErrorPtr* error) override {
return source_name_;
}
bool SetDocumentSource(brillo::ErrorPtr* error,
const std::string& source_name) override;
std::optional<ColorMode> GetColorMode(brillo::ErrorPtr* error) override {
return color_mode_;
}
bool SetColorMode(brillo::ErrorPtr* error, ColorMode color_mode) override;
bool SetScanRegion(brillo::ErrorPtr* error,
const ScanRegion& region) override;
SANE_Status StartScan(brillo::ErrorPtr* error) override;
SANE_Status GetScanParameters(brillo::ErrorPtr* error,
ScanParameters* params) override;
SANE_Status ReadScanData(brillo::ErrorPtr* error,
uint8_t* buf,
size_t count,
size_t* read_out) override;
bool CancelScan(brillo::ErrorPtr* error) override;
SANE_Status SetOption(brillo::ErrorPtr* error,
const ScannerOption& option) override;
std::optional<ScannerConfig> GetCurrentConfig(
brillo::ErrorPtr* error) override;
void SetScannerConfig(const std::optional<ScannerConfig>& config);
void SetValidOptionValues(const std::optional<ValidOptionValues>& values);
void SetStartScanResult(SANE_Status status);
void SetScanParameters(const std::optional<ScanParameters>& params);
void SetReadScanDataResult(SANE_Status result);
void SetScanData(const std::vector<std::vector<uint8_t>>& scan_data);
void SetMaxReadSize(size_t read_size);
void SetInitialEmptyReads(size_t num_empty);
void SetCancelScanResult(bool result);
void ClearScanJob();
void SetCallStartJob(bool call);
void SetOptionStatus(const std::string& option, SANE_Status status);
private:
int resolution_;
std::string source_name_;
ColorMode color_mode_;
std::optional<ScannerConfig> config_;
std::optional<ValidOptionValues> values_;
std::unordered_map<std::string, SANE_Status> set_option_status_;
SANE_Status start_scan_result_;
bool call_start_job_;
SANE_Status read_scan_data_result_;
bool cancel_scan_result_;
bool scan_running_;
bool cancelled_;
std::optional<ScanParameters> params_;
std::vector<std::vector<uint8_t>> scan_data_;
size_t max_read_size_;
size_t initial_empty_reads_;
size_t num_empty_reads_;
size_t current_page_;
size_t scan_data_offset_;
};
} // namespace lorgnette
#endif // LORGNETTE_SANE_DEVICE_FAKE_H_