This repository has been archived by the owner on Jun 7, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathhandle.hpp
163 lines (128 loc) · 5.05 KB
/
handle.hpp
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
// handle.hpp -- for a SANE scanner object
// Copyright (C) 2012-2015 SEIKO EPSON CORPORATION
//
// License: GPL-3.0+
// Author : EPSON AVASYS CORPORATION
//
// This file is part of the 'Utsushi' package.
// This package is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License or, at
// your option, any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You ought to have received a copy of the GNU General Public License
// along with this package. If not, see <http://www.gnu.org/licenses/>.
#ifndef sane_handle_hpp_
#define sane_handle_hpp_
extern "C" { // needed until sane-backends-1.0.14
#include <sane/sane.h>
}
#include <csignal>
#include <string>
#include <vector>
#include <boost/operators.hpp>
#include <utsushi/pump.hpp>
#include <utsushi/scanner.hpp>
#include <utsushi/stream.hpp>
namespace sane {
//! Implements a SANE scanner object
/*! \remark The implementation assumes that the SANE API entries
* handle argument screening and \e never pass invalid
* arguments to the public handle API.
*/
class handle
{
public:
handle (const utsushi::scanner::info& info);
std::string name () const;
//! Returns the number of options
SANE_Int size () const;
//! Grabs a hold of the SANE option descriptor at \a index
const SANE_Option_Descriptor * descriptor (SANE_Int index) const;
bool is_active (SANE_Int index) const;
bool is_button (SANE_Int index) const;
bool is_group (SANE_Int index) const;
bool is_settable (SANE_Int index) const;
bool is_automatic (SANE_Int index) const;
bool is_scanning () const;
//! Handles \c SANE_ACTION_GET_VALUE option control requests
SANE_Status get (SANE_Int index, void *value) const;
//! Handles \c SANE_ACTION_SET_VALUE option control requests
SANE_Status set (SANE_Int index, void *value, SANE_Word *info);
//! Handles \c SANE_ACTION_SET_AUTO option control requests
SANE_Status set (SANE_Int index, SANE_Word *info);
utsushi::context get_context () const;
utsushi::streamsize start ();
utsushi::streamsize read (utsushi::octet *buffer,
utsushi::streamsize length);
void cancel ();
protected:
void end_scan_sequence ();
//! Decorates utsushi::input::marker()
/*! The main reason for this wrapper it to make the stream survive
* across repeated invocations of sane_start() for the duration of
* a whole scan sequence. Filters that are part of the stream may
* in theory depend on their state carrying over between images to
* achieve the desired effect.
*
* A pleasant side effect of keeping the stream around until the
* end of a scan sequence is of course more efficient use of our
* resources and less time wasted setting a stream up.
*/
utsushi::streamsize marker ();
std::string name_;
utsushi::scanner::ptr idev_;
utsushi::idevice::ptr cache_;
utsushi::pump::ptr pump_;
//! Manage cache_ resource safely in the face of concurrency
utsushi::weak_ptr< utsushi::idevice > iptr_;
utsushi::streamsize last_marker_;
sig_atomic_t work_in_progress_; // ORDER DEPENDENCY
sig_atomic_t cancel_requested_;
private:
void add_option (utsushi::option& visitor);
//! Update SANE options to reflect latest state
/*! Whereas the Utsushi API allows for options to appear and disappear
* at will, the SANE API dictates a fixed number of option descriptor
* objects. Here we cater to the possibility of disappearing and/or
* reappearing Utsushi options as well as any state changes they may
* have undergone.
*
* The \a info argument is not modified unless an option has changed
* in one way or another.
*/
void update_options (SANE_Word *info);
void update_capabilities (SANE_Word *info);
utsushi::option::map opt_;
//! Add a key dictionary to SANE_Option_Descriptor objects
struct option_descriptor
: SANE_Option_Descriptor
, private boost::equality_comparable< option_descriptor >
{
utsushi::key orig_key;
std::string sane_key;
utsushi::string name_;
utsushi::string desc_;
std::vector< utsushi::string > strings_;
option_descriptor ();
option_descriptor (const option_descriptor& od);
option_descriptor (const utsushi::option& visitor);
~option_descriptor ();
option_descriptor& operator= (const option_descriptor& rhs);
bool operator== (const option_descriptor& rhs) const;
};
void add_group (const utsushi::key& key,
const utsushi::string& name,
const utsushi::string& text = utsushi::string ());
std::vector< option_descriptor > sod_;
bool emulating_automatic_scan_area_;
bool do_automatic_scan_area_;
friend struct match_key;
};
} // namespace sane
#endif /* sane_handle_hpp_ */