Skip to content

Commit

Permalink
Start creating tarnish api in liboxide
Browse files Browse the repository at this point in the history
  • Loading branch information
Eeems committed Jul 4, 2023
1 parent 979061c commit f84b224
Show file tree
Hide file tree
Showing 9 changed files with 134 additions and 48 deletions.
25 changes: 8 additions & 17 deletions applications/lockscreen/controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <QObject>
#include <QQuickItem>
#include <liboxide.h>
#include <liboxide/tarnish.h>

using namespace codes::eeems::oxide1;
using namespace Oxide::Sentry;
Expand All @@ -26,19 +27,10 @@ class Controller : public QObject {
Controller(QObject* parent)
: QObject(parent), confirmPin() {
clockTimer = new QTimer(root);
auto bus = QDBusConnection::systemBus();
qDebug() << "Waiting for tarnish to start up...";
while(!bus.interface()->registeredServiceNames().value().contains(OXIDE_SERVICE)){
struct timespec args{
.tv_sec = 1,
.tv_nsec = 0,
}, res;
nanosleep(&args, &res);
}
api = new General(OXIDE_SERVICE, OXIDE_SERVICE_PATH, bus, this);

Oxide::Tarnish::connect();
auto bus = Oxide::Tarnish::getApi()->connection();
qDebug() << "Requesting system API...";
QDBusObjectPath path = api->requestAPI("system");
QDBusObjectPath path = Oxide::Tarnish::requestAPI("system");
if(path.path() == "/"){
qDebug() << "Unable to get system API";
throw "";
Expand All @@ -50,7 +42,7 @@ class Controller : public QObject {
connect(systemApi, &System::deviceSuspending, this, &Controller::deviceSuspending);

qDebug() << "Requesting power API...";
path = api->requestAPI("power");
path = Oxide::Tarnish::requestAPI("power");
if(path.path() == "/"){
qDebug() << "Unable to get power API";
throw "";
Expand All @@ -66,7 +58,7 @@ class Controller : public QObject {
connect(powerApi, &Power::chargerWarning, this, &Controller::chargerWarning);

qDebug() << "Requesting wifi API...";
path = api->requestAPI("wifi");
path = Oxide::Tarnish::requestAPI("wifi");
if(path.path() == "/"){
qDebug() << "Unable to get wifi API";
throw "";
Expand All @@ -79,7 +71,7 @@ class Controller : public QObject {
connect(wifiApi, &Wifi::rssiChanged, this, &Controller::wifiRssiChanged);

qDebug() << "Requesting apps API...";
path = api->requestAPI("apps");
path = Oxide::Tarnish::requestAPI("apps");
if(path.path() == "/"){
qDebug() << "Unable to get apps API";
throw "";
Expand Down Expand Up @@ -488,7 +480,6 @@ private slots:

private:
QString confirmPin;
General* api;
System* systemApi;
codes::eeems::oxide1::Power* powerApi;
Wifi* wifiApi;
Expand All @@ -501,7 +492,7 @@ private slots:
QObject* stateControllerUI = nullptr;
QObject* pinEntryUI = nullptr;

int tarnishPid() { return api->tarnishPid(); }
int tarnishPid() { return Oxide::Tarnish::tarnishPid(); }
QObject* getBatteryUI() {
batteryUI = root->findChild<QObject*>("batteryLevel");
return batteryUI;
Expand Down
2 changes: 2 additions & 0 deletions applications/lockscreen/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <cstdlib>
#include <liboxide/eventfilter.h>
#include <liboxide/dbus.h>
#include <liboxide/tarnish.h>

#include "controller.h"

Expand All @@ -15,6 +16,7 @@ using namespace Oxide::Sentry;

int main(int argc, char *argv[]){
deviceSettings.setupQtEnvironment();
Tarnish::connect();
QGuiApplication app(argc, argv);
sentry_init("decay", argv);
auto filter = new EventFilter(&app);
Expand Down
21 changes: 7 additions & 14 deletions applications/screenshot-tool/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <cstdlib>
#include <signal.h>
#include <liboxide.h>
#include <liboxide/tarnish.h>

using namespace codes::eeems::oxide1;
using namespace Oxide::Sentry;
Expand Down Expand Up @@ -47,38 +48,30 @@ int main(int argc, char *argv[]){
app.setOrganizationDomain(OXIDE_SERVICE);
app.setApplicationName("fret");
app.setApplicationVersion(APP_VERSION);
auto bus = QDBusConnection::systemBus();
qDebug() << "Waiting for tarnish to start up...";
while(!bus.interface()->registeredServiceNames().value().contains(OXIDE_SERVICE)){
struct timespec args{
.tv_sec = 1,
.tv_nsec = 0,
}, res;
nanosleep(&args, &res);
}
General api(OXIDE_SERVICE, OXIDE_SERVICE_PATH, bus, &app);
Oxide::Tarnish::connect();
auto bus = Oxide::Tarnish::getApi()->connection();
qDebug() << "Requesting system API...";
QDBusObjectPath path = api.requestAPI("system");
QDBusObjectPath path = Oxide::Tarnish::requestAPI("system");
if(path.path() == "/"){
qDebug() << "Unable to get system API";
return EXIT_FAILURE;
}
System system(OXIDE_SERVICE, path.path(), bus, &app);
qDebug() << "Requesting screen API...";
path = api.requestAPI("screen");
path = Oxide::Tarnish::requestAPI("screen");
if(path.path() == "/"){
qDebug() << "Unable to get screen API";
return EXIT_FAILURE;
}
Screen screen(OXIDE_SERVICE, path.path(), bus, &app);
qDebug() << "Requesting notification API...";
path = api.requestAPI("notification");
path = Oxide::Tarnish::requestAPI("notification");
if(path.path() == "/"){
qDebug() << "Unable to get notification API";
return EXIT_FAILURE;
}
Notifications notifications(OXIDE_SERVICE, path.path(), bus, &app);
qDebug() << "Connecting signal listener...";
qDebug() << "Connecting signal listener...";
QObject::connect(&system, &System::rightAction, [&screen, &notifications, bus, &app]{
qDebug() << "Taking screenshot";
auto reply = screen.screenshot();
Expand Down
19 changes: 19 additions & 0 deletions applications/system-service/dbusservice.h
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,25 @@ class DBusService : public APIBase {

int tarnishPid(){ return qApp->applicationPid(); }

Q_INVOKABLE void registerChild(qint64 childPid, QString name, QDBusUnixFileDescriptor stdout, QDBusUnixFileDescriptor stderr){
Q_UNUSED(childPid)
if(!QDBusUnixFileDescriptor::isSupported()){
qCritical("QDBusUnixFileDescriptor is not supported");
::kill(childPid, SIGTERM);
}
if(!stdout.isValid()){
O_WARNING("stdout passed in by" << childPid << "is invalid");
::kill(childPid, SIGTERM);
}
if(!stderr.isValid()){
O_WARNING("stderr passed in by" << childPid << "is invalid");
::kill(childPid, SIGTERM);
}
//stdout.fileDescriptor();
//stderr.fileDescriptor();
qDebug() << "registerChild" << childPid << name;
}

public slots:
QDBusObjectPath requestAPI(QString name, QDBusMessage message) {
#ifdef SENTRY
Expand Down
21 changes: 6 additions & 15 deletions applications/task-switcher/controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <epframebuffer.h>
#include <signal.h>
#include <liboxide.h>
#include <liboxide/tarnish.h>

#include "screenprovider.h"
#include "appitem.h"
Expand All @@ -33,31 +34,22 @@ class Controller : public QObject {
: QObject(parent),applications() {
blankImage = new QImage(qApp->primaryScreen()->geometry().size(), QImage::Format_Mono);
this->screenProvider = screenProvider;
auto bus = QDBusConnection::systemBus();
qDebug() << "Waiting for tarnish to start up...";
while(!bus.interface()->registeredServiceNames().value().contains(OXIDE_SERVICE)){
struct timespec args{
.tv_sec = 1,
.tv_nsec = 0,
}, res;
nanosleep(&args, &res);
}
api = new General(OXIDE_SERVICE, OXIDE_SERVICE_PATH, bus, this);

Oxide::Tarnish::connect();
auto bus = Oxide::Tarnish::getApi()->connection();
SignalHandler::setup_unix_signal_handlers();
connect(signalHandler, &SignalHandler::sigUsr1, this, &Controller::sigUsr1);
connect(signalHandler, &SignalHandler::sigUsr2, this, &Controller::sigUsr2);

qDebug() << "Requesting screen API...";
QDBusObjectPath path = api->requestAPI("screen");
QDBusObjectPath path = Oxide::Tarnish::requestAPI("screen");
if(path.path() == "/"){
qDebug() << "Unable to get screen API";
throw "";
}
screenApi = new Screen(OXIDE_SERVICE, path.path(), bus, this);

qDebug() << "Requesting apps API...";
path = api->requestAPI("apps");
path = Oxide::Tarnish::requestAPI("apps");
if(path.path() == "/"){
qDebug() << "Unable to get apps API";
throw "";
Expand Down Expand Up @@ -268,7 +260,6 @@ private slots:
}

private:
General* api;
Screen* screenApi;
Apps* appsApi;
QObject* root = nullptr;
Expand All @@ -277,7 +268,7 @@ private slots:
QList<QObject*> applications;
QImage* blankImage;

int tarnishPid() { return api->tarnishPid(); }
int tarnishPid() { return Oxide::Tarnish::tarnishPid(); }
QObject* getStateControllerUI(){
stateControllerUI = root->findChild<QObject*>("stateController");
return stateControllerUI;
Expand Down
6 changes: 6 additions & 0 deletions interfaces/dbusservice.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,11 @@
</method>
<method name="startup">
</method>
<method name="registerChild">
<arg name="childPid" type="x" direction="in"/>
<arg name="name" type="s" direction="in"/>
<arg name="stdout" type="h" direction="in"/>
<arg name="stderr" type="h" direction="in"/>
</method>
</interface>
</node>
6 changes: 4 additions & 2 deletions shared/liboxide/liboxide.pro
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ SOURCES += \
settingsfile.cpp \
slothandler.cpp \
sysobject.cpp \
signalhandler.cpp
signalhandler.cpp \
tarnish.cpp

HEADERS += \
../epaper/epframebuffer.h \
Expand All @@ -41,7 +42,8 @@ HEADERS += \
settingsfile.h \
slothandler.h \
sysobject.h \
signalhandler.h
signalhandler.h \
tarnish.h

PRECOMPILED_HEADER = \
liboxide_stable.h
Expand Down
48 changes: 48 additions & 0 deletions shared/liboxide/tarnish.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#include "tarnish.h"
#include "meta.h"
#include "debug.h"

#include <QDBusConnection>

General* api = nullptr;

bool verifyConnection(){
if(api == nullptr){
return false;
}
if(!api->isValid()){
delete api;
api = nullptr;
return false;
}
return true;
}

namespace Oxide::Tarnish {
General* getApi(){ return api; }
QDBusObjectPath requestAPI(std::string name){
connect();
return api->requestAPI(QString::fromStdString(name));
}
void connect(){ connect(qApp->applicationName().toStdString()); }
void connect(std::string name){
if(verifyConnection()){
return;
}
auto bus = QDBusConnection::systemBus();
O_DEBUG("Waiting for tarnish to start up...");
while(!bus.interface()->registeredServiceNames().value().contains(OXIDE_SERVICE)){
timespec args{
.tv_sec = 1,
.tv_nsec = 0,
}, res;
nanosleep(&args, &res);
}
api = new General(OXIDE_SERVICE, OXIDE_SERVICE_PATH, bus, qApp);
api->registerChild(getpid(), QString::fromStdString(name), QDBusUnixFileDescriptor(fileno(stdin)), QDBusUnixFileDescriptor(fileno(stdout)));
}
int tarnishPid(){
connect();
return api->tarnishPid();
}
}
34 changes: 34 additions & 0 deletions shared/liboxide/tarnish.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*!
* \addtogroup Oxide::Tarnish
* \brief The Tarnish module
* @{
* \file
*/
#pragma once
#include "liboxide_global.h"
#include "dbus.h"

using namespace codes::eeems::oxide1;

namespace Oxide::Tarnish {
/*!
* \brief Get the current General API instance
* \return The current General API instance
*/
General* getApi();
QDBusObjectPath requestAPI(std::string name);
/*!
* \brief Connect to the current tarnish instance
*/
void connect();
/*!
* \brief Connect to the current tarnish instance
* \param Name of current application
*/
void connect(std::string name);
/*!
* \brief Get the tarnish PID
* \return The tarnish PID
*/
int tarnishPid();
}

0 comments on commit f84b224

Please sign in to comment.