[sanexx-commit] SF.net SVN: sanexx: [10]
Status: Pre-Alpha
Brought to you by:
paddy_hack
|
From: <pad...@us...> - 2006-03-06 11:29:24
|
Revision: 10 Author: paddy_hack Date: 2006-03-06 03:29:10 -0800 (Mon, 06 Mar 2006) ViewCVS: http://svn.sourceforge.net/sanexx/?rev=10&view=rev Log Message: ----------- r21@qed: olaf | 2006-03-04 13:46:48 +0900 Implemented a minimal set of SANE API functions to pass the new test, which requires a list of devices. The implementation does not do the error handling it should yet. Modified Paths: -------------- trunk/include/sane++ trunk/lib/sane++.cc trunk/src/scanimage.cc Property Changed: ---------------- / Property changes on: ___________________________________________________________________ Name: svk:merge - 52428bda-890d-0410-88ad-be188b7e1831:/local:20 + 52428bda-890d-0410-88ad-be188b7e1831:/local:21 Modified: trunk/include/sane++ =================================================================== --- trunk/include/sane++ 2006-03-06 11:28:50 UTC (rev 9) +++ trunk/include/sane++ 2006-03-06 11:29:10 UTC (rev 10) @@ -25,4 +25,44 @@ #include <sane/sane.h> +#include <list> +#include <ostream> +#include <string> + +namespace sane +{ +using std::list; +using std::ostream; +using std::string; + +class device +{ +public: + class info + { + public: + info (const SANE_Device *dev_info); + + const string& name () const; + const string& vendor () const; + const string& model () const; + const string& type () const; + + private: + string _name; + string _vendor; + string _model; + string _type; + }; +}; + +void init (void); +void exit (void); + +list<device::info> get_devices (void); + +ostream& operator<< (ostream& os, const device::info& i); + +} // namespace sane + #endif /* !included_sanexx */ Modified: trunk/lib/sane++.cc =================================================================== --- trunk/lib/sane++.cc 2006-03-06 11:28:50 UTC (rev 9) +++ trunk/lib/sane++.cc 2006-03-06 11:29:10 UTC (rev 10) @@ -21,3 +21,85 @@ #include <sane++> + +#include <cstdlib> + +namespace sane +{ + +void +init (void) +{ + sane_init (NULL, NULL); +} + +void +exit (void) +{ + return sane_exit (); +} + +list<device::info> +get_devices (void) +{ + list<device::info> result; + + const SANE_Device **device_list = NULL; + SANE_Status s = sane_get_devices (&device_list, true); + + if (SANE_STATUS_GOOD != s) + return result; // or throw something appropriate + + const SANE_Device **device = device_list; + while (device && *device) + { + result.push_back (device::info (*device)); + ++device; + } + + return result; +} + + + device::info::info (const SANE_Device *dev_info) + : _name (dev_info->name), + _vendor (dev_info->vendor), + _model (dev_info->model), + _type (dev_info->type) +{ +} + +const string& +device::info::name () const +{ + return _name; +} + +const string& +device::info::vendor () const +{ + return _vendor; +} + +const string& +device::info::model () const +{ + return _model; +} + +const string& +device::info::type () const +{ + return _type; +} + +ostream& +operator<< (ostream& os, const device::info& i) +{ + return os << i.name () + << i.vendor () + << i.model () + << i.type (); +} + +} // namespace sane Modified: trunk/src/scanimage.cc =================================================================== --- trunk/src/scanimage.cc 2006-03-06 11:28:50 UTC (rev 9) +++ trunk/src/scanimage.cc 2006-03-06 11:29:10 UTC (rev 10) @@ -38,11 +38,12 @@ namespace po = boost::program_options; +int display_version (const char *program_name); int display_help (const char *program_name, const po::options_description& desc); -int display_version (const char *program_name); +int list_devices (const char *program_name, + const po::options_description& desc); - int main (int argc, char *argv[]) { @@ -50,22 +51,28 @@ po::options_description common ("Common options"); common.add_options () + ("version", + "display version information and exit") ("help,h", "display this help message and exit") - ("version", - "display version information and exit") + ("list-devices", + "display a list of available devices") ; po::variables_map vm; po::store (po::parse_command_line (argc, argv, common), vm); po::notify (vm); + if (vm.count ("version")) { + return display_version (program_name); + } + if (vm.count ("help")) { return display_help (program_name, common); } - if (vm.count ("version")) { - return display_version (program_name); + if (vm.count ("list-devices")) { + return list_devices (program_name, common); } return EXIT_SUCCESS; @@ -73,14 +80,6 @@ int -display_help (const char *program_name, - const po::options_description& desc) -{ - cout << desc << endl; - return EXIT_SUCCESS; -} - -int display_version (const char *program_name) { cout << program_name @@ -94,3 +93,31 @@ return EXIT_SUCCESS; } + +int +display_help (const char *program_name, + const po::options_description& desc) +{ + cout << desc << endl; + return EXIT_SUCCESS; +} + +int +list_devices (const char *program_name, + const po::options_description& desc) +{ + using namespace sane; + + init (); + + list<device::info> dev_info_list = get_devices (); + list<device::info>::const_iterator dev_info = dev_info_list.begin (); + + for (; dev_info != dev_info_list.end (); ++dev_info) { + cout << *dev_info << endl; + } + + exit (); + + return EXIT_SUCCESS; +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |