Permalink
Browse files

Isolate brlapi.h

  • Loading branch information...
mlang committed Jul 22, 2017
1 parent 343f86c commit ee25ae2f7b13c29cfaa06fb19a06880d83ced90c
Showing with 63 additions and 37 deletions.
  1. +2 −0 CMakeLists.txt
  2. +11 −0 brltest.cpp
  3. +36 −0 lib/brlapi.cpp
  4. +13 −33 lib/brlapi.hpp
  5. +1 −4 stats.cpp
View
@@ -10,3 +10,5 @@ add_subdirectory(lib)
add_executable(stats stats.cpp)
target_link_libraries(stats IO Boost::boost)
add_executable(brltest brltest.cpp)
target_link_libraries(brltest IO)
View
@@ -0,0 +1,11 @@
#include <iostream>
#include <brlapi.hpp>
using std::cout;
using std::endl;
int main() {
BrlAPI::Connection Braille;
cout << Braille.driverName() << " (" << Braille.displaySize() << ")" << endl;
}
View
@@ -1,2 +1,38 @@
#include "brlapi.hpp"
#include <brlapi.h>
struct BrlAPI::Connection::Implementation {
std::unique_ptr<gsl::byte[]> HandleStorage;
brlapi_handle_t *handle() const {
return static_cast<brlapi_handle_t *>(static_cast<void *>(HandleStorage.get()));
}
Implementation() : HandleStorage(new gsl::byte[brlapi_getHandleSize()]) {}
};
BrlAPI::Connection::Connection()
: BrlAPI(std::make_unique<Implementation>())
{
brlapi_connectionSettings_t Settings = BRLAPI_SETTINGS_INITIALIZER;
auto FileDescriptor = brlapi__openConnection(BrlAPI->handle(), &Settings, &Settings);
if (FileDescriptor == -1) {
throw std::system_error(errno, std::generic_category());
}
}
BrlAPI::Connection::~Connection() {
brlapi__closeConnection(BrlAPI->handle());
}
std::string BrlAPI::Connection::driverName() const {
char Name[32];
brlapi__getDriverName(BrlAPI->handle(), Name, 32);
return { Name, strlen(Name) };
}
BrlAPI::DisplaySize BrlAPI::Connection::displaySize() const {
DisplaySize Size;
brlapi__getDisplaySize(BrlAPI->handle(), &Size.X, &Size.Y);
return Size;
}
View
@@ -1,7 +1,6 @@
#include <ostream>
#include <system_error>
#include <gsl/gsl>
#include <brlapi.h>
namespace BrlAPI {
@@ -10,62 +9,43 @@ struct DisplaySize {
unsigned int Y;
};
bool operator==(DisplaySize const &Lhs, DisplaySize const &Rhs) {
inline bool operator==(DisplaySize const &Lhs, DisplaySize const &Rhs) {
return Lhs.X == Rhs.X && Lhs.Y == Rhs.Y;
}
bool operator!=(DisplaySize const &Lhs, DisplaySize const &Rhs) {
inline bool operator!=(DisplaySize const &Lhs, DisplaySize const &Rhs) {
return Lhs.X != Rhs.X || Lhs.Y != Rhs.Y;
}
bool operator>(DisplaySize const &Lhs, DisplaySize const &Rhs) {
inline bool operator>(DisplaySize const &Lhs, DisplaySize const &Rhs) {
return Lhs.X * Lhs.Y > Rhs.X * Rhs.Y;
}
bool operator>=(DisplaySize const &Lhs, DisplaySize const &Rhs) {
inline bool operator>=(DisplaySize const &Lhs, DisplaySize const &Rhs) {
return Lhs.X * Lhs.Y >= Rhs.X * Rhs.Y;
}
bool operator<=(DisplaySize const &Lhs, DisplaySize const &Rhs) {
inline bool operator<=(DisplaySize const &Lhs, DisplaySize const &Rhs) {
return Lhs.X * Lhs.Y <= Rhs.X * Rhs.Y;
}
bool operator<(DisplaySize const &Lhs, DisplaySize const &Rhs) {
inline bool operator<(DisplaySize const &Lhs, DisplaySize const &Rhs) {
return Lhs.X * Lhs.Y < Rhs.X * Rhs.Y;
}
std::ostream &operator<<(std::ostream &Out, DisplaySize const &Size) {
inline std::ostream &operator<<(std::ostream &Out, DisplaySize const &Size) {
Out << Size.X << 'x' << Size.Y;
return Out;
}
class Connection {
std::unique_ptr<gsl::byte[]> HandleStorage;
brlapi_handle_t *handle() const {
return static_cast<brlapi_handle_t *>(static_cast<void *>(HandleStorage.get()));
}
class Implementation;
std::unique_ptr<Implementation> BrlAPI;
public:
Connection() : HandleStorage(new gsl::byte[brlapi_getHandleSize()])
{
brlapi_connectionSettings_t Settings = BRLAPI_SETTINGS_INITIALIZER;
auto FileDescriptor = brlapi__openConnection(handle(), &Settings, &Settings);
if (FileDescriptor == -1) {
throw std::system_error(errno, std::generic_category());
}
}
~Connection() {
brlapi__closeConnection(handle());
}
std::string driverName() const {
char Name[32];
brlapi__getDriverName(handle(), Name, 32);
return { Name, strlen(Name) };
}
DisplaySize displaySize() const {
DisplaySize Size;
brlapi__getDisplaySize(handle(), &Size.X, &Size.Y);
return Size;
}
Connection();
~Connection();
std::string driverName() const;
DisplaySize displaySize() const;
};
}
View
@@ -1,5 +1,4 @@
#include "jack.hpp"
#include "brlapi.hpp"
#include <jack.hpp>
#include <boost/accumulators/accumulators.hpp>
#include <boost/accumulators/statistics.hpp>
@@ -42,8 +41,6 @@ using std::this_thread::sleep_for;
using namespace std::literals::chrono_literals;
int main() {
BrlAPI::Connection Braille;
cout << Braille.driverName() << " (" << Braille.displaySize() << ")" << endl;
Statistics Client;
cout << "Rate: " << Client.sampleRate() << endl;

0 comments on commit ee25ae2

Please sign in to comment.