mirror of
https://github.com/gnif/LookingGlass.git
synced 2026-08-22 15:11:31 +00:00
[idd] transport: isolate interactive services
This commit is contained in:
@@ -21,40 +21,109 @@
|
||||
#pragma once
|
||||
|
||||
#include "CSRWLock.h"
|
||||
#include "transport/IControlSink.h"
|
||||
#include "transport/IControlTransport.h"
|
||||
#include "transport/ITransport.h"
|
||||
|
||||
#include <memory>
|
||||
#include <Windows.h>
|
||||
|
||||
#include <stdint.h>
|
||||
#include <vector>
|
||||
|
||||
class CControlHub final : public IControlTransport
|
||||
class CControlHub final : public IControlTransport, public IControlEvents
|
||||
{
|
||||
private:
|
||||
struct Sink
|
||||
static constexpr unsigned MAX_SINKS = 8;
|
||||
static constexpr DWORD RETRY_MS = 5;
|
||||
|
||||
enum class WorkType
|
||||
{
|
||||
BackendId backend;
|
||||
uint32_t epoch;
|
||||
CSRWLock lock;
|
||||
IControlTransport * control;
|
||||
POSITION,
|
||||
SHAPE,
|
||||
TRANSFORM,
|
||||
COUNT,
|
||||
};
|
||||
|
||||
mutable CSRWLock m_sinkLock;
|
||||
std::vector<std::shared_ptr<Sink>> m_sinks;
|
||||
struct State
|
||||
{
|
||||
std::shared_ptr<const D12ColorTransform> transform;
|
||||
IDARG_OUT_QUERY_HWCURSOR cursor = {};
|
||||
std::shared_ptr<const std::vector<BYTE>> cursorData;
|
||||
UINT sdrWhiteLevel = 0;
|
||||
uint64_t positionRevision = 0;
|
||||
uint64_t shapeRevision = 0;
|
||||
uint64_t transformRevision = 1;
|
||||
};
|
||||
|
||||
struct Work
|
||||
{
|
||||
WorkType type = WorkType::POSITION;
|
||||
IControlSink * target = nullptr;
|
||||
IDARG_OUT_QUERY_HWCURSOR cursor = {};
|
||||
std::shared_ptr<const std::vector<BYTE>> cursorData;
|
||||
std::shared_ptr<const D12ColorTransform> transform;
|
||||
UINT sdrWhiteLevel = 0;
|
||||
uint64_t positionRevision = 0;
|
||||
uint64_t shapeRevision = 0;
|
||||
uint64_t transformRevision = 0;
|
||||
uint64_t bindingSerial = 0;
|
||||
uint64_t replaySerial = 0;
|
||||
};
|
||||
|
||||
struct Sink
|
||||
{
|
||||
CControlHub * owner = nullptr;
|
||||
unsigned index = 0;
|
||||
BackendId backend = 0;
|
||||
uint32_t epoch = 0;
|
||||
CSRWLock lock;
|
||||
IControlSink * target = nullptr;
|
||||
HANDLE wake = nullptr;
|
||||
HANDLE idle = nullptr;
|
||||
HANDLE thread = nullptr;
|
||||
uint64_t deliveredPosition = 0;
|
||||
uint64_t deliveredShape = 0;
|
||||
uint64_t deliveredTransform = 0;
|
||||
uint64_t retryAt[static_cast<unsigned>(WorkType::COUNT)] = {};
|
||||
unsigned nextWork = 0;
|
||||
uint64_t bindingSerial = 0;
|
||||
uint64_t replaySerial = 0;
|
||||
bool active = false;
|
||||
bool failed = false;
|
||||
bool failurePending = false;
|
||||
bool reserved = false;
|
||||
bool calling = false;
|
||||
};
|
||||
|
||||
mutable CSRWLock m_listLock;
|
||||
mutable CSRWLock m_stateLock;
|
||||
std::shared_ptr<const D12ColorTransform> m_colorTransform;
|
||||
IDARG_OUT_QUERY_HWCURSOR m_cursor = {};
|
||||
std::vector<BYTE> m_cursorData;
|
||||
UINT m_sdrWhiteLevel = 0;
|
||||
bool m_cursorValid = false;
|
||||
bool m_shapeValid = false;
|
||||
CSRWLock m_lifecycleLock;
|
||||
State m_state;
|
||||
Sink m_sinks[MAX_SINKS];
|
||||
HANDLE m_stopEvent = nullptr;
|
||||
bool m_valid = false;
|
||||
|
||||
std::vector<std::shared_ptr<Sink>> Snapshot() const;
|
||||
void Replay(const std::shared_ptr<Sink>& sink);
|
||||
static DWORD WINAPI WorkerProc(void * opaque);
|
||||
static uint64_t NextRevision(uint64_t revision);
|
||||
static bool TokenMatches(const Sink& sink, const ControlToken& token);
|
||||
|
||||
bool BeginWork(Sink& sink, Work& work, DWORD& wait);
|
||||
bool CompleteWork(Sink& sink, const Work& work, ControlResult result);
|
||||
void Worker(Sink& sink);
|
||||
void WakeAll(WorkType type);
|
||||
|
||||
public:
|
||||
bool Add(BackendId backend, uint32_t epoch, IControlTransport& control);
|
||||
CControlHub();
|
||||
~CControlHub() override;
|
||||
|
||||
CControlHub(const CControlHub&) = delete;
|
||||
CControlHub& operator=(const CControlHub&) = delete;
|
||||
|
||||
bool Add(BackendId backend, uint32_t epoch, IControlSink& control);
|
||||
void Remove(BackendId backend, uint32_t epoch);
|
||||
bool TakeFailure(ControlToken& token);
|
||||
|
||||
void OnControlReplay(const ControlToken& token) override;
|
||||
|
||||
void SendCursor(const IDARG_OUT_QUERY_HWCURSOR& info,
|
||||
const BYTE * data, UINT sdrWhiteLevel) override;
|
||||
|
||||
Reference in New Issue
Block a user