Skip to content

Commit

Permalink
Allow getting existing surfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
Eeems committed Jan 20, 2024
1 parent e6eadd2 commit f22fbac
Show file tree
Hide file tree
Showing 18 changed files with 520 additions and 257 deletions.
83 changes: 65 additions & 18 deletions applications/display-server/connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,12 +140,23 @@ Surface* Connection::getSurface(QString identifier){
return nullptr;
}

QStringList Connection::getSurfaces(){
QStringList identifiers;
for(auto surface : qAsConst(surfaces)){
if(surface == nullptr){
continue;
}
identifiers.append(surface->id());
}
return identifiers;
}

void Connection::readSocket(){
m_notifier->setEnabled(false);
O_DEBUG("Data received");
while(true){
auto message = Blight::message_t::from_socket(m_serverFd);
if(message == nullptr){
if(message->header.type == Blight::MessageType::Invalid){
break;
}
O_DEBUG(
Expand All @@ -155,9 +166,11 @@ void Connection::readSocket(){
<< ", size=" << message->header.size
<< ", socket=" << m_serverFd
);
unsigned int ack_size = 0;
Blight::shared_data_t ack_data;
switch(message->header.type){
case Blight::MessageType::Repaint:{
auto repaint = Blight::repaint_t::from_message(message);
auto repaint = Blight::repaint_t::from_message(message.get());
O_DEBUG(
"Repaint requested: "
<< repaint.identifier.c_str()
Expand All @@ -170,16 +183,43 @@ void Connection::readSocket(){
.c_str()
);
auto surface = getSurface(repaint.identifier.c_str());
if(surface != nullptr){
emit surface->update(QRect(
repaint.header.x,
repaint.header.y,
repaint.header.width,
repaint.header.height
));
}else{
O_WARNING("Could not find surface for identifier repaint");
if(surface == nullptr){
O_WARNING("Could not find surface " << repaint.identifier.c_str());
break;
}
emit surface->update(QRect(
repaint.header.x,
repaint.header.y,
repaint.header.width,
repaint.header.height
));
break;
}
case Blight::MessageType::Move:
O_WARNING("Move not implemented yet");
break;
case Blight::MessageType::SurfaceInfo:{
std::string identifier;
identifier.assign(
reinterpret_cast<char*>(message->data.get()),
message->header.size
);
auto surface = getSurface(identifier.c_str());
if(surface == nullptr){
O_WARNING("Could not find surface " << identifier.c_str());
break;
}
auto geometry = surface->geometry();
auto info = new Blight::surface_info_t{
.x = geometry.x(),
.y = geometry.y(),
.width = geometry.width(),
.height = geometry.height(),
.stride = surface->stride(),
.format = (Blight::Format)surface->format(),
};
ack_data = Blight::shared_data_t(reinterpret_cast<Blight::data_t>(info));
ack_size = sizeof(Blight::surface_info_t);
break;
}
case Blight::MessageType::Ack:
Expand All @@ -188,26 +228,33 @@ void Connection::readSocket(){
default:
O_WARNING("Unexpected message type" << message->header.type);
}
auto ack = Blight::message_t::create_ack(message);
if(ack_size && ack_data != nullptr){
O_WARNING("Ack expected data, but none sent");
ack_size = 0;
}
auto ack = Blight::message_t::create_ack(message.get(), ack_size);
auto res = ::send(
m_serverFd,
reinterpret_cast<char*>(ack),
sizeof(Blight::header_t),
MSG_EOR
);
delete ack;
if(res < 0){
O_WARNING("Failed to write to socket:" << strerror(errno));
}else if(res != sizeof(Blight::header_t)){
O_WARNING("Failed to write to socket: Size of written bytes doesn't match!");
}else if(ack_size){
res = ::send(m_serverFd, ack_data.get(), ack_size, MSG_EOR);
if(res < 0){
O_WARNING("Failed to write to socket:" << strerror(errno));
}else if(res != sizeof(Blight::header_t)){
O_WARNING("Failed to write to socket: Size of written bytes doesn't match!");
}else{
O_DEBUG("Acked" << message->header.ackid);
}
}else{
O_DEBUG("Acked" << message->header.ackid);
}
if(message->data != nullptr){
delete message->data;
message->data = nullptr;
}
delete message;
};
m_notifier->setEnabled(true);
}
Expand Down
1 change: 1 addition & 0 deletions applications/display-server/connection.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class Connection : public QObject {
void close();
Surface* addSurface(int fd, QRect geometry, int stride, QImage::Format format);
Surface* getSurface(QString identifier);
QStringList getSurfaces();

signals:
void finished();
Expand Down
33 changes: 31 additions & 2 deletions applications/display-server/dbusinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <QCoreApplication>
#include <QQmlComponent>
#include <unistd.h>
#include <QDBusMetaType>
#include <liboxide/debug.h>

DbusInterface* DbusInterface::singleton = nullptr;
Expand Down Expand Up @@ -184,15 +185,43 @@ QString DbusInterface::addSurface(
return surface->id();
}

void DbusInterface::repaint(QString identifier){
auto surface = getSurface(identifier);
void DbusInterface::repaint(QString identifier, QDBusMessage message){
auto connection = getConnection(message);
if(connection == nullptr){
sendErrorReply(QDBusError::AccessDenied, "You must first open a connection");
return;
}
auto surface = connection->getSurface(identifier);
if(surface == nullptr){
sendErrorReply(QDBusError::BadAddress, "Surface not found");
return;
}
surface->repaint();
}

QStringList DbusInterface::surfaces(QDBusMessage message){
auto connection = getConnection(message);
if(connection == nullptr){
sendErrorReply(QDBusError::AccessDenied, "You must first open a connection");
return QStringList();
}
return connection->getSurfaces();
}

QDBusUnixFileDescriptor DbusInterface::getSurface(QString identifier, QDBusMessage message){
auto connection = getConnection(message);
if(connection == nullptr){
sendErrorReply(QDBusError::AccessDenied, "You must first open a connection");
return QDBusUnixFileDescriptor();
}
auto surface = connection->getSurface(identifier);
if(surface == nullptr){
sendErrorReply(QDBusError::BadAddress, "Surface not found");
return QDBusUnixFileDescriptor();
}
return QDBusUnixFileDescriptor(surface->fd());
}

void DbusInterface::serviceOwnerChanged(const QString& name, const QString& oldOwner, const QString& newOwner){
Q_UNUSED(oldOwner);
if(!newOwner.isEmpty()){
Expand Down
6 changes: 5 additions & 1 deletion applications/display-server/dbusinterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
#include <QObject>
#include <QDBusContext>
#include <QDBusConnection>
#pragma once
#include <QDBusConnectionInterface>
#include <QDBusMessage>
#include <QTimer>
#include <QQmlApplicationEngine>
#include <QDBusUnixFileDescriptor>

#include "connection.h"

Expand Down Expand Up @@ -38,7 +40,9 @@ public slots:
int format,
QDBusMessage message
);
void repaint(QString identifier);
void repaint(QString identifier, QDBusMessage message);
QStringList surfaces(QDBusMessage message);
QDBusUnixFileDescriptor getSurface(QString identifier, QDBusMessage message);

private slots:
void serviceOwnerChanged(const QString& name, const QString& oldOwner, const QString& newOwner);
Expand Down
16 changes: 12 additions & 4 deletions applications/display-server/surface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@

Surface::Surface(QObject* parent, int fd, QRect geometry, int stride, QImage::Format format)
: QObject(parent),
geometry(geometry),
stride(stride),
format(format)
m_geometry(geometry),
m_stride(stride),
m_format(format)
{
auto connection = dynamic_cast<Connection*>(parent);
m_id = QString("%1/surface/%2").arg(connection->id()).arg(fd);
Expand Down Expand Up @@ -65,6 +65,14 @@ bool Surface::isValid(){ return component != nullptr; }

QImage* Surface::image(){ return m_image; }

void Surface::repaint(){ emit update(QRect(QPoint(0, 0), geometry.size())); }
void Surface::repaint(){ emit update(QRect(QPoint(0, 0), m_geometry.size())); }

int Surface::fd(){ return file.handle(); }

const QRect& Surface::geometry(){ return m_geometry; }

int Surface::stride(){ return m_stride; }

QImage::Format Surface::format(){ return m_format; }

#include "moc_surface.cpp"
10 changes: 7 additions & 3 deletions applications/display-server/surface.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,18 @@ class Surface : public QObject {
bool isValid();
QImage* image();
void repaint();
int fd();
const QRect& geometry();
int stride();
QImage::Format format();

signals:
void update(const QRect& geometry);

private:
QRect geometry;
int stride;
QImage::Format format;
QRect m_geometry;
int m_stride;
QImage::Format m_format;
QFile file;
uchar* data;
QImage* m_image;
Expand Down
3 changes: 1 addition & 2 deletions applications/test/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,8 @@ int main(int argc, char *argv[]){
0,
geometry.width(),
geometry.height()
);
)->wait();
O_DEBUG("Done!");
delete buffer;
delete connection;
QTimer::singleShot(1000, []{ qApp->exit(); });
});
Expand Down
7 changes: 7 additions & 0 deletions interfaces/blight.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,12 @@
<method name="repaint">
<arg name="identifier" type="s" direction="in"/>
</method>
<method name="surfaces">
<arg type="as" direction="out"/>
</method>
<method name="getSurface">
<arg type="h" direction="out"/>
<arg name="identifier" type="s" direction="in"/>
</method>
</interface>
</node>
24 changes: 0 additions & 24 deletions shared/epaper/epimagenode.h

This file was deleted.

Loading

0 comments on commit f22fbac

Please sign in to comment.