OpenSRX 0.1.0
C++ library for interfacing with Keyence SR series barcode readers
Loading...
Searching...
No Matches
ImageServer.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <fineftp/server.h>
4
5#include <atomic>
6#include <condition_variable>
7#include <cstdint>
8#include <deque>
9#include <functional>
10#include <mutex>
11#include <string>
12#include <thread>
13
14#include "OpenSRX/Image.hpp"
15
16namespace OpenSRX {
17
26 public:
34 ImageServer(uint16_t port = 0, const std::string& username = "opensrx",
35 const std::string& password = "opensrx");
36
38
39 // Non-copyable / non-movable
40 ImageServer(const ImageServer&) = delete;
42
44 void start();
45
47 void stop();
48
50 bool isRunning() const { return running.load(); }
51
53 uint16_t getPort() const;
54
56 std::string getUsername() const { return username; }
57
59 std::string getPassword() const { return password; }
60
62 std::string getRootPath() const { return rootPath; }
63
71
78 bool tryGetImage(Image& image);
79
83 std::deque<Image> getImages();
84
90 void setImageCallback(std::function<void(const Image&)> cb);
91
92 private:
94
95 uint16_t port;
96 std::string username;
97 std::string password;
98 std::string rootPath;
99
100 std::unique_ptr<fineftp::FtpServer> ftpServer;
101
102 std::atomic<bool> running{false};
103 std::thread watcherThread;
104
105 std::mutex queueMutex;
106 std::condition_variable queueCV;
107 std::deque<Image> imageQueue;
108
109 std::function<void(const Image&)> imageCallback;
110};
111
112} // namespace OpenSRX
ImageServer(const ImageServer &)=delete
std::unique_ptr< fineftp::FtpServer > ftpServer
Definition ImageServer.hpp:100
bool tryGetImage(Image &image)
Return the next image if one is available, without blocking.
uint16_t port
Definition ImageServer.hpp:95
std::deque< Image > imageQueue
Definition ImageServer.hpp:107
std::string getRootPath() const
Definition ImageServer.hpp:62
std::string rootPath
Definition ImageServer.hpp:98
std::string getUsername() const
Definition ImageServer.hpp:56
std::string username
Definition ImageServer.hpp:96
std::condition_variable queueCV
Definition ImageServer.hpp:106
Image waitForImage()
Block until an image is available, then return it.
bool isRunning() const
Definition ImageServer.hpp:50
ImageServer & operator=(const ImageServer &)=delete
uint16_t getPort() const
ImageServer(uint16_t port=0, const std::string &username="opensrx", const std::string &password="opensrx")
Construct (but do not start) the image server.
std::thread watcherThread
Definition ImageServer.hpp:103
std::atomic< bool > running
Definition ImageServer.hpp:102
std::function< void(const Image &)> imageCallback
Definition ImageServer.hpp:109
std::deque< Image > getImages()
Return all images currently queued.
std::string password
Definition ImageServer.hpp:97
void setImageCallback(std::function< void(const Image &)> cb)
Set a callback invoked each time a new image is decoded.
std::string getPassword() const
Definition ImageServer.hpp:59
std::mutex queueMutex
Definition ImageServer.hpp:105
Definition AsioInterface.hpp:5
Raw decoded image data.
Definition Image.hpp:18