You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
61 lines
1.3 KiB
C++
61 lines
1.3 KiB
C++
#ifndef STMDSPSCANNER_H
|
|
#define STMDSPSCANNER_H
|
|
|
|
#include <fstream>
|
|
#include <set>
|
|
#include <string>
|
|
|
|
namespace stmdsp
|
|
{
|
|
class device
|
|
{
|
|
public:
|
|
device(const std::string& path) :
|
|
m_path(path) {}
|
|
|
|
bool open() {
|
|
m_stream.open(m_path, std::ios_base::in | std::ios_base::out | std::ios_base::binary);
|
|
return m_stream.is_open();
|
|
}
|
|
|
|
std::size_t read(char *buffer, std::size_t count) {
|
|
return m_stream.readsome(buffer, count);
|
|
}
|
|
|
|
std::size_t write(const char *buffer, std::size_t count) {
|
|
m_stream.write(buffer, count);
|
|
return m_stream.good() ? count : 0;
|
|
}
|
|
|
|
const std::string& path() const {
|
|
return m_path;
|
|
}
|
|
|
|
auto operator<=>(const device& other) const {
|
|
return m_path <=> other.m_path;
|
|
}
|
|
|
|
private:
|
|
std::string m_path;
|
|
std::fstream m_stream;
|
|
};
|
|
|
|
class scanner
|
|
{
|
|
private:
|
|
constexpr static unsigned int STMDSP_VENDOR_ID = 0x0483;
|
|
constexpr static unsigned int STMDSP_DEVICE_ID = 0x5740;
|
|
|
|
public:
|
|
void scan();
|
|
const auto& devices() const {
|
|
return m_devices;
|
|
}
|
|
|
|
private:
|
|
std::set<device> m_devices;
|
|
};
|
|
}
|
|
|
|
#endif // STMDSPSCANNER_H
|