1 /* sane - Scanner Access Now Easy.
2
3 Copyright (C) 2019 Povilas Kanapickas <povilas@radix.lt>
4
5 This file is part of the SANE package.
6
7 This program is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License as
9 published by the Free Software Foundation; either version 2 of the
10 License, or (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <https://www.gnu.org/licenses/>.
19
20 As a special exception, the authors of SANE give permission for
21 additional uses of the libraries contained in this release of SANE.
22
23 The exception is that, if you link a SANE library with other files
24 to produce an executable, this does not by itself cause the
25 resulting executable to be covered by the GNU General Public
26 License. Your use of that executable is in no way restricted on
27 account of linking the SANE library code into it.
28
29 This exception does not, however, invalidate any other reasons why
30 the executable file might be covered by the GNU General Public
31 License.
32
33 If you submit changes to SANE to the maintainers to be included in
34 a subsequent release, you agree by submitting the changes that
35 those changes may be distributed with this exception intact.
36
37 If you write modifications of your own for SANE, it is your choice
38 whether to permit this exception to apply to your modifications.
39 If you do not wish that, delete this exception notice.
40 */
41
42 #define DEBUG_DECLARE_ONLY
43
44 #include "test_settings.h"
45
46 namespace genesys {
47
48 namespace {
49
50 bool s_testing_mode = false;
51 std::uint16_t s_vendor_id = 0;
52 std::uint16_t s_product_id = 0;
53 std::uint16_t s_bcd_device = 0;
54 TestCheckpointCallback s_checkpoint_callback;
55
56 } // namespace
57
is_testing_mode()58 bool is_testing_mode()
59 {
60 return s_testing_mode;
61 }
62
disable_testing_mode()63 void disable_testing_mode()
64 {
65 s_testing_mode = false;
66 s_vendor_id = 0;
67 s_product_id = 0;
68 s_bcd_device = 0;
69 }
70
enable_testing_mode(std::uint16_t vendor_id,std::uint16_t product_id,std::uint16_t bcd_device,TestCheckpointCallback checkpoint_callback)71 void enable_testing_mode(std::uint16_t vendor_id, std::uint16_t product_id,
72 std::uint16_t bcd_device,
73 TestCheckpointCallback checkpoint_callback)
74 {
75 s_testing_mode = true;
76 s_vendor_id = vendor_id;
77 s_product_id = product_id;
78 s_bcd_device = bcd_device;
79 s_checkpoint_callback = checkpoint_callback;
80 }
81
get_testing_vendor_id()82 std::uint16_t get_testing_vendor_id()
83 {
84 return s_vendor_id;
85 }
86
get_testing_product_id()87 std::uint16_t get_testing_product_id()
88 {
89 return s_product_id;
90 }
91
get_testing_bcd_device()92 std::uint16_t get_testing_bcd_device()
93 {
94 return s_bcd_device;
95 }
96
get_testing_device_name()97 std::string get_testing_device_name()
98 {
99 std::string name;
100 unsigned max_size = 50;
101 name.resize(max_size);
102 name.resize(std::snprintf(&name.front(), max_size, "test device:0x%04x:0x%04x",
103 s_vendor_id, s_product_id));
104 return name;
105 }
106
get_testing_checkpoint_callback()107 TestCheckpointCallback get_testing_checkpoint_callback()
108 {
109 return s_checkpoint_callback;
110 }
111
112 } // namespace genesys
113