Add time to the sensor list widget, also broadcast and recive the time of a sensor
This commit is contained in:
74
src/sensors/pipewiresensor.cpp
Normal file
74
src/sensors/pipewiresensor.cpp
Normal file
@ -0,0 +1,74 @@
|
||||
#include "pipewiresensor.h"
|
||||
#include <QDebug>
|
||||
|
||||
static const struct pw_node_events node_events = {
|
||||
.version = PW_VERSION_NODE_EVENTS,
|
||||
.info = &PipeWireSensorSource::nodeEventHandler,
|
||||
.param = nullptr
|
||||
};
|
||||
|
||||
PipeWireSensorSource::PipeWireSensorSource(PipeWireHandler* handler, const std::string& nodeName, uint8_t id, QObject *parent)
|
||||
: QObject{parent}, handler_(handler), nodeName_(nodeName), id_(id)
|
||||
{
|
||||
connect(handler_, &PipeWireHandler::nodeAdded, this, &PipeWireSensorSource::nodeAdded);
|
||||
connect(&timer, &QTimer::timeout, this, &PipeWireSensorSource::offTimeout);
|
||||
timer.setSingleShot(true);
|
||||
}
|
||||
|
||||
void PipeWireSensorSource::offTimeout()
|
||||
{
|
||||
if(state == false)
|
||||
return;
|
||||
state = false;
|
||||
stateChanged(Sensor(Sensor::TYPE_AUDIO_OUTPUT, id_, state));
|
||||
}
|
||||
|
||||
void PipeWireSensorSource::nodeEventHandler(void* data, const struct pw_node_info *info)
|
||||
{
|
||||
PipeWireSensorSource* source = static_cast<PipeWireSensorSource*>(data);
|
||||
|
||||
if(info->state == source->prevState)
|
||||
return;
|
||||
|
||||
source->prevState = info->state;
|
||||
|
||||
switch (info->state)
|
||||
{
|
||||
case PW_NODE_STATE_ERROR:
|
||||
case PW_NODE_STATE_CREATING:
|
||||
source->state = false;
|
||||
source->stateChanged(Sensor(Sensor::TYPE_AUDIO_OUTPUT, source->id_, 0));
|
||||
break;
|
||||
case PW_NODE_STATE_SUSPENDED:
|
||||
case PW_NODE_STATE_IDLE:
|
||||
if(source->state == true)
|
||||
source->timer.start(10000);
|
||||
break;
|
||||
case PW_NODE_STATE_RUNNING:
|
||||
if(source->state == false)
|
||||
{
|
||||
source->state = true;
|
||||
source->stateChanged(Sensor(Sensor::TYPE_AUDIO_OUTPUT, source->id_, source->state));
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void PipeWireSensorSource::nodeAdded(PipeWireHandler::PwNode node)
|
||||
{
|
||||
if(node.name == nodeName_)
|
||||
{
|
||||
|
||||
sinkNode = static_cast<struct pw_node*>(pw_registry_bind(handler_->getRegistry(), node.id, PW_TYPE_INTERFACE_Node, PW_VERSION_CLIENT, 0));
|
||||
if(sinkNode)
|
||||
{
|
||||
qDebug()<<"Failed to register to required pipewire node"<<node.name.c_str()<<"as id"<<node.id;
|
||||
return;
|
||||
}
|
||||
pw_node_add_listener(sinkNode, &sinkListener, &node_events, this);
|
||||
qDebug()<<"Found required pipewire node"<<node.name.c_str()<<"as id"<<node.id;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user