|
OpenSRX 0.1.0
C++ library for interfacing with Keyence SR series barcode readers
|
Embedded FTP server for receiving images from the scanner. More...
#include <ImageServer.hpp>
Public Member Functions | |
| ImageServer (uint16_t port=0, const std::string &username="opensrx", const std::string &password="opensrx") | |
| Construct (but do not start) the image server. | |
| ~ImageServer () | |
| ImageServer (const ImageServer &)=delete | |
| ImageServer & | operator= (const ImageServer &)=delete |
| void | start () |
| void | stop () |
| bool | isRunning () const |
| uint16_t | getPort () const |
| std::string | getUsername () const |
| std::string | getPassword () const |
| std::string | getRootPath () const |
| Image | waitForImage () |
| Block until an image is available, then return it. | |
| bool | tryGetImage (Image &image) |
| Return the next image if one is available, without blocking. | |
| std::deque< Image > | getImages () |
| Return all images currently queued. | |
| void | setImageCallback (std::function< void(const Image &)> cb) |
| Set a callback invoked each time a new image is decoded. | |
Private Member Functions | |
| void | watchDirectory () |
Private Attributes | |
| uint16_t | port |
| std::string | username |
| std::string | password |
| std::string | rootPath |
| std::unique_ptr< fineftp::FtpServer > | ftpServer |
| std::atomic< bool > | running {false} |
| std::thread | watcherThread |
| std::mutex | queueMutex |
| std::condition_variable | queueCV |
| std::deque< Image > | imageQueue |
| std::function< void(const Image &)> | imageCallback |
Embedded FTP server for receiving images from the scanner.
Creates a temporary directory (under /tmp) and starts a fineftp FTP server. A background thread polls the directory for new BMP files, decodes them, and stores them in a queue that can be consumed by the caller.
| OpenSRX::ImageServer::ImageServer | ( | uint16_t | port = 0, |
| const std::string & | username = "opensrx", | ||
| const std::string & | password = "opensrx" ) |
Construct (but do not start) the image server.
| port | FTP port to listen on (0 = OS picks a free port). |
| username | FTP username the scanner will log in with. |
| password | FTP password the scanner will log in with. |
| OpenSRX::ImageServer::~ImageServer | ( | ) |
|
delete |
| std::deque< Image > OpenSRX::ImageServer::getImages | ( | ) |
Return all images currently queued.
|
inline |
| uint16_t OpenSRX::ImageServer::getPort | ( | ) | const |
|
inline |
|
inline |
|
inline |
|
delete |
| void OpenSRX::ImageServer::setImageCallback | ( | std::function< void(const Image &)> | cb | ) |
Set a callback invoked each time a new image is decoded.
The callback runs on the watcher thread; keep it fast.
| void OpenSRX::ImageServer::start | ( | ) |
Start the FTP server and the background watcher thread.
| void OpenSRX::ImageServer::stop | ( | ) |
Stop the FTP server and watcher thread.
| bool OpenSRX::ImageServer::tryGetImage | ( | Image & | image | ) |
Return the next image if one is available, without blocking.
| [out] | image | Filled with the image data on success. |
| Image OpenSRX::ImageServer::waitForImage | ( | ) |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |