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 
21 #define DEBUG_DECLARE_ONLY
22 
23 #include "test_settings.h"
24 
25 namespace genesys {
26 
27 namespace {
28 
29 bool s_testing_mode = false;
30 std::uint16_t s_vendor_id = 0;
31 std::uint16_t s_product_id = 0;
32 std::uint16_t s_bcd_device = 0;
33 TestCheckpointCallback s_checkpoint_callback;
34 
35 } // namespace
36 
is_testing_mode()37 bool is_testing_mode()
38 {
39     return s_testing_mode;
40 }
41 
disable_testing_mode()42 void disable_testing_mode()
43 {
44     s_testing_mode = false;
45     s_vendor_id = 0;
46     s_product_id = 0;
47     s_bcd_device = 0;
48 }
49 
enable_testing_mode(std::uint16_t vendor_id, std::uint16_t product_id, std::uint16_t bcd_device, TestCheckpointCallback checkpoint_callback)50 void enable_testing_mode(std::uint16_t vendor_id, std::uint16_t product_id,
51                          std::uint16_t bcd_device,
52                          TestCheckpointCallback checkpoint_callback)
53 {
54     s_testing_mode = true;
55     s_vendor_id = vendor_id;
56     s_product_id = product_id;
57     s_bcd_device = bcd_device;
58     s_checkpoint_callback = checkpoint_callback;
59 }
60 
get_testing_vendor_id()61 std::uint16_t get_testing_vendor_id()
62 {
63     return s_vendor_id;
64 }
65 
get_testing_product_id()66 std::uint16_t get_testing_product_id()
67 {
68     return s_product_id;
69 }
70 
get_testing_bcd_device()71 std::uint16_t get_testing_bcd_device()
72 {
73     return s_bcd_device;
74 }
75 
get_testing_device_name()76 std::string get_testing_device_name()
77 {
78     std::string name;
79     unsigned max_size = 50;
80     name.resize(max_size);
81     name.resize(std::snprintf(&name.front(), max_size, "test device:0x%04x:0x%04x",
82                               s_vendor_id, s_product_id));
83     return name;
84 }
85 
get_testing_checkpoint_callback()86 TestCheckpointCallback get_testing_checkpoint_callback()
87 {
88     return s_checkpoint_callback;
89 }
90 
91 } // namespace genesys
92