Permalink
Browse files

BrlAPI::TTY

  • Loading branch information...
mlang committed Jul 22, 2017
1 parent 0352bad commit 46e91461fd9c3ea50602b9366da4a85a4e06dcc6
Showing with 55 additions and 2 deletions.
  1. +10 −0 brltest.cpp
  2. +16 −1 lib/brlapi.cpp
  3. +29 −1 lib/brlapi.hpp
View
@@ -1,11 +1,21 @@
#include <chrono>
#include <iostream>
#include <thread>
#include <brlapi.hpp>
using std::cout;
using std::endl;
using namespace std::literals::chrono_literals;
int main() {
BrlAPI::Connection Braille;
cout << Braille.driverName() << " (" << Braille.displaySize() << ")" << endl;
{
auto TTY = Braille.tty(1, true);
std::stringstream Text;
Text << "You are on tty" << TTY.number();
TTY.writeText(Text);
std::this_thread::sleep_for(5s);
}
}
View
@@ -11,11 +11,20 @@ class BrlAPI::Connection::Implementation {
}
};
BrlAPI::TTY::~TTY() {
brlapi__leaveTtyMode(Conn->BrlAPI->handle());
}
void BrlAPI::TTY::writeText(std::string Text) {
if (brlapi__writeText(Conn->BrlAPI->handle(), -1, Text.c_str()) == -1)
throw std::system_error(brlapi_errno, std::generic_category());
}
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());
throw std::system_error(brlapi_errno, std::generic_category());
}
}
@@ -35,3 +44,9 @@ BrlAPI::DisplaySize BrlAPI::Connection::displaySize() const {
return Size;
}
BrlAPI::TTY BrlAPI::Connection::tty(int TTY, bool Raw) {
auto Number = brlapi__enterTtyMode(BrlAPI->handle(), TTY, "");
if (Number == -1) throw std::system_error(brlapi_errno, std::generic_category());
return { this, Number };
}
View
@@ -1,5 +1,5 @@
#include <ostream>
#include <system_error>
#include <sstream>
#include <gsl/gsl>
namespace BrlAPI {
@@ -38,15 +38,43 @@ inline std::ostream &operator<<(std::ostream &Out, DisplaySize const &Size) {
return Out;
}
class Connection;
class TTY {
Connection *Conn;
int Number;
friend class Connection;
TTY(Connection *Conn, int Number) : Conn(Conn), Number(Number) {}
public:
~TTY();
TTY(TTY const &) = delete;
TTY(TTY &&) = default;
TTY &operator=(TTY const &) = delete;
TTY &operator=(TTY &&) = default;
int number() const { return Number; }
void writeText(std::string);
void writeText(std::stringstream const &Stream) { writeText(Stream.str()); }
};
class Connection {
class Implementation;
std::unique_ptr<Implementation> BrlAPI;
friend class TTY;
public:
Connection();
~Connection();
std::string driverName() const;
DisplaySize displaySize() const;
TTY tty(int, bool);
};
}

0 comments on commit 46e9146

Please sign in to comment.