Skip to content

Commit

Permalink
Add fbinfo, libblight_client, and fix building for device
Browse files Browse the repository at this point in the history
  • Loading branch information
Eeems committed Jan 18, 2024
1 parent b60b370 commit 849c88f
Show file tree
Hide file tree
Showing 24 changed files with 992 additions and 76 deletions.
5 changes: 3 additions & 2 deletions applications/applications.pro
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ SUBDIRS = \
xdg-icon-resource \
xdg-open \
xdg-settings \
display-server
display-server \
fbinfo

launcher.depends = system-service update-desktop-database
lockscreen.depends = system-service
Expand All @@ -43,5 +44,5 @@ desktop-file-edit.depends =
desktop-file-install.depends =
inject_evdev.depends =
display-server.depends = system-service

fbinfo.depends =
INSTALLS += $$SUBDIRS
6 changes: 4 additions & 2 deletions applications/display-server/connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,11 @@ void Connection::readSocket(){
O_WARNING("Unexpected message type" << message.header.type);
}
auto ack = Blight::message_t::create_ack(message);
auto res = socket->write(
auto res = ::send(
socket->socketDescriptor(),
reinterpret_cast<char*>(ack),
sizeof(Blight::header_t)
sizeof(Blight::header_t),
MSG_EOR
);
delete ack;
if(res < 0){
Expand Down
5 changes: 1 addition & 4 deletions applications/display-server/display-server.pro
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@ CONFIG += c++17
CONFIG -= app_bundle
CONFIG += qml_debug
CONFIG += qtquickcompiler
CONFIG += qmltypes

DEFINES += QT_DEPRECATED_WARNINGS
DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
CONFIG += qmltypes # disables all the APIs deprecated before Qt 6.0.0

QML_IMPORT_NAME = codes.eeems.blight
QML_IMPORT_PATH += .
Expand Down
19 changes: 19 additions & 0 deletions applications/fbinfo/fbinfo.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
QT -= gui

CONFIG += c++11
CONFIG += console
CONFIG -= app_bundle

SOURCES += \
main.cpp

HEADERS +=

TARGET = fbinfo
include(../../qmake/common.pri)
target.path = /opt/bin
INSTALLS += target

INCLUDEPATH += ../../shared/mxcfb

include(../../qmake/liboxide.pri)
98 changes: 98 additions & 0 deletions applications/fbinfo/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
#include <QCommandLineParser>
#include <QTextStream>
#include <QDebug>

#include <liboxide/meta.h>
#include <liboxide/sentry.h>
#include <liboxide/devicesettings.h>
#include <epframebuffer.h>
#include <QFile>
#include <mxcfb.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#include <unistd.h>

using namespace Oxide::Sentry;

QDebug operator<<(QDebug debug, const fb_bitfield& bitfield){
QDebugStateSaver saver(debug);
Q_UNUSED(saver);
return debug.nospace()
<< "offset=" << bitfield.offset
<< " length=" << bitfield.length
<< " msb_right=" << bitfield.msb_right;
}

QDebug operator<<(QDebug debug, const fb_var_screeninfo& vinfo){
QDebugStateSaver saver(debug);
Q_UNUSED(saver);
return debug.nospace()
<< "xres: " << vinfo.xres << Qt::endl
<< "yres: " << vinfo.yres << Qt::endl
<< "xres_virtual: " << vinfo.xres_virtual << Qt::endl
<< "yres_virtual: " << vinfo.yres_virtual << Qt::endl
<< "xoffset: " << vinfo.xoffset << Qt::endl
<< "yoffset: " << vinfo.yoffset << Qt::endl
<< "bits_per_pixel: " << vinfo.bits_per_pixel << Qt::endl
<< "grayscale: " << vinfo.grayscale << Qt::endl
<< "red: " << vinfo.red << Qt::endl
<< "green: " << vinfo.green << Qt::endl
<< "blue: " << vinfo.blue << Qt::endl
<< "transp: " << vinfo.transp << Qt::endl
<< "nonstd: " << vinfo.nonstd << Qt::endl
<< "activate: " << vinfo.activate << Qt::endl
<< "width: " << vinfo.width << Qt::endl
<< "height: " << vinfo.height << Qt::endl
<< "accel_flags: " << vinfo.accel_flags << Qt::endl
<< "pixclock: " << vinfo.pixclock << Qt::endl
<< "left_margin: " << vinfo.left_margin << Qt::endl
<< "right_margin: " << vinfo.right_margin << Qt::endl
<< "upper_margin: " << vinfo.upper_margin << Qt::endl
<< "lower_margin: " << vinfo.lower_margin << Qt::endl
<< "hsync_len: " << vinfo.hsync_len << Qt::endl
<< "vsync_len: " << vinfo.vsync_len << Qt::endl
<< "sync: " << vinfo.sync << Qt::endl
<< "vmode: " << vinfo.vmode << Qt::endl
<< "rotate: " << vinfo.rotate << Qt::endl
<< "colorspace: " << vinfo.colorspace << Qt::endl
<< "reserved 0: " << vinfo.reserved[0] << Qt::endl
<< "reserved 1: " << vinfo.reserved[1] << Qt::endl
<< "reserved 2: " << vinfo.reserved[2] << Qt::endl
<< "reserved 3: " << vinfo.reserved[3] << Qt::endl;
}

int main(int argc, char *argv[]){
QCoreApplication app(argc, argv);
sentry_init("fbinfo", argv);
app.setOrganizationName("Eeems");
app.setOrganizationDomain(OXIDE_SERVICE);
app.setApplicationName("notify-send");
app.setApplicationVersion(APP_VERSION);
QCommandLineParser parser;
parser.setApplicationDescription("a tool to get framebuffer information");
parser.addVersionOption();
auto path = "/dev/fb0";
if(QString::fromLatin1(path).isEmpty()){
qDebug() << "Unable to find framebuffer";
return EXIT_FAILURE;
}
auto fd = open(path, O_RDONLY);
if(fd == -1){
qDebug() << "Failed to open framebuffer:" << strerror(errno);
return errno;
}
fb_var_screeninfo vinfo;
auto res = ioctl(fd, FBIOGET_VSCREENINFO, &vinfo);
auto err = errno;
close(fd);
if(res == -1){
qDebug() << "Failed to get screen info:" << strerror(err);
return err;
}
QFile file;
file.open(stdout, QIODevice::WriteOnly);
QDebug(&file)
<< "path:" << path << Qt::endl
<< vinfo;
return EXIT_SUCCESS;
}
2 changes: 1 addition & 1 deletion applications/system-service/wpa_supplicant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* This file was generated by qdbusxml2cpp version 0.8
* Command line was: qdbusxml2cpp -N -p wpa_supplicant.h:wpa_supplicant.cpp fi.w1.wpa_supplicant1.xml
*
* qdbusxml2cpp is Copyright (C) 2022 The Qt Company Ltd.
* qdbusxml2cpp is Copyright (C) 2020 The Qt Company Ltd.
*
* This is an auto-generated file.
* This file may have been hand-edited. Look for HAND-EDIT comments
Expand Down
2 changes: 1 addition & 1 deletion applications/system-service/wpa_supplicant.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* This file was generated by qdbusxml2cpp version 0.8
* Command line was: qdbusxml2cpp -N -p wpa_supplicant.h:wpa_supplicant.cpp fi.w1.wpa_supplicant1.xml
*
* qdbusxml2cpp is Copyright (C) 2022 The Qt Company Ltd.
* qdbusxml2cpp is Copyright (C) 2020 The Qt Company Ltd.
*
* This is an auto-generated file.
* Do not edit! All changes made to it will be lost.
Expand Down
11 changes: 6 additions & 5 deletions applications/test/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,14 @@ int main(int argc, char *argv[]){
blankImage.bytesPerLine(),
Blight::Format::Format_ARGB32_Premultiplied
);
if(buffer.fd == -1 || buffer.data == nullptr){
if(buffer->fd == -1 || buffer->data == nullptr){
O_WARNING("Failed to create buffer:" << strerror(errno));
qApp->exit(EXIT_FAILURE);
return;
}
memcpy(buffer.data, blankImage.constBits(), size);
memcpy(buffer->data, blankImage.constBits(), size);
auto image = new QImage(
buffer.data,
buffer->data,
blankImage.width(),
blankImage.height(),
blankImage.bytesPerLine(),
Expand All @@ -89,7 +90,7 @@ int main(int argc, char *argv[]){
O_WARNING("Invalid size" << image->size());
}
std::string id = Blight::addSurface(
buffer.fd,
buffer->fd,
geometry.x(),
geometry.y(),
image->width(),
Expand Down Expand Up @@ -119,7 +120,7 @@ int main(int argc, char *argv[]){
geometry.height()
);
O_DEBUG("Done!");
buffer.close();
delete buffer;
delete connection;
QTimer::singleShot(1000, []{ qApp->exit(); });
});
Expand Down
3 changes: 0 additions & 3 deletions applications/test/test.pro
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ CONFIG += c++11
CONFIG += qml_debug
CONFIG += qtquickcompiler

DEFINES += QT_DEPRECATED_WARNINGS
DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0

SOURCES += \
main.cpp

Expand Down
12 changes: 6 additions & 6 deletions qmake/common.pri
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ VERSION = 2.8
!contains(DEFINES, QT_DEPRECATED_WARNINGS){
DEFINES += QT_DEPRECATED_WARNINGS
}
!contains(DEFINES, QT_DISABLE_DEPRECATED_BEFORE){
isEmpty(QT_DISABLE_DEPRECATED_BEFORE){
DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000
}else{
DEFINES += QT_DISABLE_DEPRECATED_BEFORE=$${QT_DISABLE_DEPRECATED_BEFORE}
}
isEmpty(QT_DISABLE_DEPRECATED_BEFORE){
QT_DISABLE_DEPRECATED_BEFORE = 0x060000
}else{
message("Using override deprecation value")
}
DEFINES ~= s/QT_DISABLE_DEPRECATED_BEFORE=.+/
DEFINES += QT_DISABLE_DEPRECATED_BEFORE=$${QT_DISABLE_DEPRECATED_BEFORE}
CONFIG(debug, debug|release){
LIBS += -lunwind
contains(DEFINES, SANITIZER){
Expand Down
73 changes: 56 additions & 17 deletions shared/libblight/connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,15 @@ static std::atomic<unsigned int> ackid;
namespace Blight{
Connection::Connection(int fd)
: m_fd(fcntl(fd, F_DUPFD_CLOEXEC, 3)),
thread(run, std::ref(*this))
thread(run, std::ref(*this)),
stop_requested(false)
{
int flags = fcntl(fd, F_GETFD, NULL);
fcntl(fd, F_SETFD, flags | O_NONBLOCK);
}

Connection::~Connection(){
stop_source.request_stop();
stop_requested = true;
if(thread.joinable()){
thread.join();
}
Expand All @@ -33,25 +36,51 @@ namespace Blight{

const message_t* Connection::read(){
auto message = new message_t;
if(::read(m_fd, &message->header, sizeof(header_t)) < 0){
auto res = ::recv(m_fd, &message->header, sizeof(header_t), MSG_WAITALL);
if(res < 0){
delete message;
return nullptr;
}
if(::read(m_fd, message->data, message->header.size) < 0){
// In theory this could happen with a EAGAIN result,
// but the server sends it all at once, so something
// probably went wrong if this happens
if(res != sizeof(header_t)){
std::cerr
<< "Failed to read connection message body: "
<< std::strerror(errno)
<< "Failed to read connection message header: Size mismatch!"
<< std::endl;
delete message;
errno = EMSGSIZE;
return nullptr;
}
if(!message->header.size){
return message;
}
res = -1;
// Handle the
while(res < 0){
auto res = ::recv(m_fd, message->data, message->header.size, MSG_WAITALL);
if((size_t)res == message->header.size){
break;
}
if(res > 0){
errno = EMSGSIZE;
}
if(errno != EAGAIN){
std::cerr
<< "Failed to read connection message body: "
<< std::strerror(errno)
<< std::endl;
delete message;
return nullptr;
}
timespec remaining;
timespec requested{
.tv_sec = 0,
.tv_nsec = 5000
};
nanosleep(&requested, &remaining);
}
return message;
}
int Connection::write(const message_t& message){
auto res = ::write(m_fd, &message.header, sizeof(header_t));
auto res = ::send(m_fd, &message.header, sizeof(header_t), MSG_EOR);
if(res < 0){
std::cerr
<< "Failed to write connection message header: "
Expand All @@ -65,7 +94,7 @@ namespace Blight{
<< std::endl;
return -EMSGSIZE;
}
res = ::write(m_fd, message.data, message.header.size);
res = ::send(m_fd, message.data, message.header.size, MSG_EOR);
if(res < 0){
std::cerr
<< "Failed to write connection message data: "
Expand Down Expand Up @@ -142,13 +171,9 @@ namespace Blight{
<< "[BlightWorker] Starting"
<< std::endl;
prctl(PR_SET_NAME,"BlightWorker\0", 0, 0, 0);
auto stop_token = connection.stop_source.get_token();
std::vector<unsigned int> pending;
int error = 0;
pollfd pfd;
pfd.fd = connection.m_fd;
pfd.events = POLLIN;
while(!stop_token.stop_requested()){
while(!connection.stop_requested){
// Handle any pending items that are now being waited on
connection.mutex.lock();
auto iter = pending.begin();
Expand All @@ -169,8 +194,23 @@ namespace Blight{
connection.mutex.unlock();
// Commented out, as this for some reason will result in no
// data ever being read.
// TODO - see if epoll would work?
// // Wait for data on the socket, or for a 500ms timeout
// pollfd pfd;
// pfd.fd = connection.m_fd;
// pfd.events = POLLIN;
// auto res = poll(&pfd, 1, 500);
// if(res < 0){
// if(errno == EAGAIN || errno == EINTR){
// continue;
// }
// std::cerr
// << "[BlightWorker] Failed to poll connection socket:"
// << std::strerror(errno)
// << std::endl;
// error = errno;
// break;
// }
// if(res == 0){
// continue;
// }
Expand All @@ -188,7 +228,6 @@ namespace Blight{
// << std::endl;
// continue;
// }
// TODO - see if epoll would work?
auto message = connection.read();
if(message == nullptr){
if(errno == EAGAIN){
Expand Down
4 changes: 3 additions & 1 deletion shared/libblight/connection.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#include <thread>
#include <map>
#include <condition_variable>
#include <functional>
#include <atomic>

namespace Blight {
class LIBBLIGHT_EXPORT Connection {
Expand All @@ -23,7 +25,7 @@ namespace Blight {
private:
int m_fd;
std::thread thread;
std::stop_source stop_source;
std::atomic<bool> stop_requested;
std::mutex mutex;
std::map<int, std::condition_variable*> acks;
std::vector<std::function<void(int)>> disconnectCallbacks;
Expand Down
Loading

0 comments on commit 849c88f

Please sign in to comment.