Skip to content

Commit

Permalink
Merge pull request xbmc#24687 from notspiff/appinbound_sep
Browse files Browse the repository at this point in the history
changed: make AppInboundProtocol more self-contained
  • Loading branch information
fuzzard authored Mar 15, 2024
2 parents 4eff484 + 5f6bd43 commit 33a42c6
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 89 deletions.
89 changes: 87 additions & 2 deletions xbmc/application/AppInboundProtocol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,35 @@
#include "application/Application.h"
#include "application/ApplicationComponents.h"
#include "application/ApplicationPowerHandling.h"
#include "guilib/GUIComponent.h"
#include "guilib/GUIWindowManager.h"
#include "input/InputManager.h"
#include "input/actions/Action.h"
#include "input/actions/ActionIDs.h"
#include "messaging/ApplicationMessenger.h"
#include "settings/AdvancedSettings.h"
#include "settings/DisplaySettings.h"
#include "settings/Settings.h"
#include "settings/SettingsComponent.h"
#include "threads/SingleLock.h"

CAppInboundProtocol::CAppInboundProtocol(CApplication &app) : m_pApp(app)
{
}

bool CAppInboundProtocol::OnEvent(const XBMC_Event& newEvent)
{
std::unique_lock<CCriticalSection> lock(m_portSection);
if (m_closed)
return false;
m_portEvents.push_back(newEvent);
return true;
}

bool CAppInboundProtocol::OnEvent(XBMC_Event &event)
void CAppInboundProtocol::Close()
{
return m_pApp.OnEvent(event);
std::unique_lock<CCriticalSection> lock(m_portSection);
m_closed = true;
}

void CAppInboundProtocol::SetRenderGUI(bool renderGUI)
Expand All @@ -29,3 +49,68 @@ void CAppInboundProtocol::SetRenderGUI(bool renderGUI)
const auto appPower = components.GetComponent<CApplicationPowerHandling>();
appPower->SetRenderGUI(renderGUI);
}

void CAppInboundProtocol::HandleEvents()
{
std::unique_lock<CCriticalSection> lock(m_portSection);
while (!m_portEvents.empty())
{
auto newEvent = m_portEvents.front();
m_portEvents.pop_front();
CSingleExit lock(m_portSection);
switch (newEvent.type)
{
case XBMC_QUIT:
if (!m_pApp.m_bStop)
CServiceBroker::GetAppMessenger()->PostMsg(TMSG_QUIT);
break;
case XBMC_VIDEORESIZE:
if (CServiceBroker::GetGUI()->GetWindowManager().Initialized())
{
if (!CServiceBroker::GetSettingsComponent()->GetAdvancedSettings()->m_fullScreen)
{
CServiceBroker::GetWinSystem()->GetGfxContext().ApplyWindowResize(newEvent.resize.w,
newEvent.resize.h);

const auto settings = CServiceBroker::GetSettingsComponent()->GetSettings();
settings->SetInt(CSettings::SETTING_WINDOW_WIDTH, newEvent.resize.w);
settings->SetInt(CSettings::SETTING_WINDOW_HEIGHT, newEvent.resize.h);
settings->Save();
}
else
{
const auto& res_info = CDisplaySettings::GetInstance().GetResolutionInfo(RES_DESKTOP);
CServiceBroker::GetWinSystem()->ForceFullScreen(res_info);
}
}
break;
case XBMC_VIDEOMOVE:
{
CServiceBroker::GetWinSystem()->OnMove(newEvent.move.x, newEvent.move.y);
}
break;
case XBMC_MODECHANGE:
CServiceBroker::GetWinSystem()->GetGfxContext().ApplyModeChange(newEvent.mode.res);
break;
case XBMC_SCREENCHANGE:
CServiceBroker::GetWinSystem()->OnChangeScreen(newEvent.screen.screenIdx);
break;
case XBMC_USEREVENT:
CServiceBroker::GetAppMessenger()->PostMsg(static_cast<uint32_t>(newEvent.user.code));
break;
case XBMC_SETFOCUS:
{
// Reset the screensaver
const auto appPower = m_pApp.GetComponent<CApplicationPowerHandling>();
appPower->ResetScreenSaver();
appPower->WakeUpScreenSaverAndDPMS();
// Send a mouse motion event with no dx,dy for getting the current guiitem selected
m_pApp.OnAction(CAction(ACTION_MOUSE_MOVE, 0, static_cast<float>(newEvent.focus.x),
static_cast<float>(newEvent.focus.y), 0, 0));
break;
}
default:
CServiceBroker::GetInputManager().OnEvent(newEvent);
}
}
}
15 changes: 13 additions & 2 deletions xbmc/application/AppInboundProtocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,28 @@

#pragma once

#include "threads/CriticalSection.h"
#include "windowing/XBMC_events.h"

#include <deque>

class CApplication;

class CAppInboundProtocol
{
friend class CApplication;

public:
CAppInboundProtocol(CApplication &app);
bool OnEvent(XBMC_Event &event);
CAppInboundProtocol(CApplication& app);
bool OnEvent(const XBMC_Event& newEvent);
void SetRenderGUI(bool renderGUI);
void Close();

protected:
void HandleEvents();

bool m_closed = false;
CApplication &m_pApp;
std::deque<XBMC_Event> m_portEvents;
CCriticalSection m_portSection;
};
78 changes: 4 additions & 74 deletions xbmc/application/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,76 +244,6 @@ CApplication::~CApplication(void)
DeregisterComponent(typeid(CApplicationActionListeners));
}

bool CApplication::OnEvent(XBMC_Event& newEvent)
{
std::unique_lock<CCriticalSection> lock(m_portSection);
m_portEvents.push_back(newEvent);
return true;
}

void CApplication::HandlePortEvents()
{
std::unique_lock<CCriticalSection> lock(m_portSection);
while (!m_portEvents.empty())
{
auto newEvent = m_portEvents.front();
m_portEvents.pop_front();
CSingleExit lock(m_portSection);
switch(newEvent.type)
{
case XBMC_QUIT:
if (!m_bStop)
CServiceBroker::GetAppMessenger()->PostMsg(TMSG_QUIT);
break;
case XBMC_VIDEORESIZE:
if (CServiceBroker::GetGUI()->GetWindowManager().Initialized())
{
if (!CServiceBroker::GetSettingsComponent()->GetAdvancedSettings()->m_fullScreen)
{
CServiceBroker::GetWinSystem()->GetGfxContext().ApplyWindowResize(newEvent.resize.w, newEvent.resize.h);

const std::shared_ptr<CSettings> settings = CServiceBroker::GetSettingsComponent()->GetSettings();
settings->SetInt(CSettings::SETTING_WINDOW_WIDTH, newEvent.resize.w);
settings->SetInt(CSettings::SETTING_WINDOW_HEIGHT, newEvent.resize.h);
settings->Save();
}
else
{
const auto& res_info = CDisplaySettings::GetInstance().GetResolutionInfo(RES_DESKTOP);
CServiceBroker::GetWinSystem()->ForceFullScreen(res_info);
}
}
break;
case XBMC_VIDEOMOVE:
{
CServiceBroker::GetWinSystem()->OnMove(newEvent.move.x, newEvent.move.y);
}
break;
case XBMC_MODECHANGE:
CServiceBroker::GetWinSystem()->GetGfxContext().ApplyModeChange(newEvent.mode.res);
break;
case XBMC_SCREENCHANGE:
CServiceBroker::GetWinSystem()->OnChangeScreen(newEvent.screen.screenIdx);
break;
case XBMC_USEREVENT:
CServiceBroker::GetAppMessenger()->PostMsg(static_cast<uint32_t>(newEvent.user.code));
break;
case XBMC_SETFOCUS:
{
// Reset the screensaver
const auto appPower = GetComponent<CApplicationPowerHandling>();
appPower->ResetScreenSaver();
appPower->WakeUpScreenSaverAndDPMS();
// Send a mouse motion event with no dx,dy for getting the current guiitem selected
OnAction(CAction(ACTION_MOUSE_MOVE, 0, static_cast<float>(newEvent.focus.x), static_cast<float>(newEvent.focus.y), 0, 0));
break;
}
default:
CServiceBroker::GetInputManager().OnEvent(newEvent);
}
}
}

extern "C" void __stdcall init_emu_environ();
extern "C" void __stdcall update_emu_environ();
extern "C" void __stdcall cleanup_emu_environ();
Expand Down Expand Up @@ -1586,7 +1516,7 @@ void CApplication::OnApplicationMessage(ThreadMessage* pMsg)
newEvent.type = XBMC_VIDEORESIZE;
newEvent.resize.w = pMsg->param1;
newEvent.resize.h = pMsg->param2;
OnEvent(newEvent);
m_pAppPort->OnEvent(newEvent);
CServiceBroker::GetGUI()->GetWindowManager().MarkDirty();
}
break;
Expand Down Expand Up @@ -1745,7 +1675,7 @@ void CApplication::OnApplicationMessage(ThreadMessage* pMsg)
if (pMsg->lpVoid)
{
XBMC_Event* event = static_cast<XBMC_Event*>(pMsg->lpVoid);
OnEvent(*event);
m_pAppPort->OnEvent(*event);
delete event;
}
}
Expand Down Expand Up @@ -1823,7 +1753,7 @@ void CApplication::FrameMove(bool processEvents, bool processGUI)
}
}

HandlePortEvents();
m_pAppPort->HandleEvents();
CServiceBroker::GetInputManager().Process(CServiceBroker::GetGUI()->GetWindowManager().GetActiveWindowOrDialog(), frameTime);

if (processGUI && renderGUI)
Expand Down Expand Up @@ -2093,7 +2023,7 @@ bool CApplication::Stop(int exitCode)
break;
}
}
m_pAppPort.reset();
m_pAppPort->Close();
}

try
Expand Down
11 changes: 0 additions & 11 deletions xbmc/application/Application.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,9 @@
#include "utils/GlobalsHandling.h"
#include "utils/Stopwatch.h"
#include "windowing/Resolution.h"
#include "windowing/XBMC_events.h"

#include <atomic>
#include <chrono>
#include <deque>
#include <memory>
#include <string>
#include <vector>
Expand Down Expand Up @@ -88,8 +86,6 @@ class CApplication : public IWindowManagerCallback,
public CApplicationPlayerCallback,
public CApplicationSettingsHandling
{
friend class CAppInboundProtocol;

public:

// If playback time of current item is greater than this value, ACTION_PREV_ITEM will seek to start
Expand Down Expand Up @@ -200,16 +196,11 @@ friend class CAppInboundProtocol;
bool OnSettingsSaving() const override;
void PlaybackCleanup();

// inbound protocol
bool OnEvent(XBMC_Event& newEvent);

std::shared_ptr<ANNOUNCEMENT::CAnnouncementManager> m_pAnnouncementManager;
std::unique_ptr<CGUIComponent> m_pGUI;
std::unique_ptr<CWinSystemBase> m_pWinSystem;
std::unique_ptr<ActiveAE::CActiveAE> m_pActiveAE;
std::shared_ptr<CAppInboundProtocol> m_pAppPort;
std::deque<XBMC_Event> m_portEvents;
CCriticalSection m_portSection;

// timer information
CStopWatch m_restartPlayerTimer;
Expand All @@ -229,8 +220,6 @@ friend class CAppInboundProtocol;

bool PlayStack(CFileItem& item, bool bRestart);

void HandlePortEvents();

std::unique_ptr<CInertialScrollingHandler> m_pInertialScrollingHandler;

std::vector<std::shared_ptr<ADDON::CAddonInfo>>
Expand Down

0 comments on commit 33a42c6

Please sign in to comment.