Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
AlwinEsch committed Feb 11, 2022
1 parent 420029e commit aab24ee
Show file tree
Hide file tree
Showing 78 changed files with 13,187 additions and 135 deletions.
15 changes: 10 additions & 5 deletions xbmc/addons/interface/Controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,22 +237,27 @@ void CController::Process()
const ChildStatus status = it->second->ProcessActive();
if (status != ChildStatus::Running)
{
const auto addon = it->second->GetAddon();
const auto uuid = it->second->GetUUID();
const auto addonId = it->second->GetAddonID();

fprintf(stderr, "--> Process Stopped %s - %i !!!\n", addon->ID().c_str(), status);
CLog::Log(LOGFATAL, "CController::{}: Addon '{}' process was uncontrolled stopped!",
__func__, addon->ID());
__func__, addonId);
it->second->InformStopReport(status);
it->second->Kill();

const auto uuid = it->second->GetUUID();
const auto stacktrace = it->second->GetStackTrace();

m_runningProcesses.erase(it++);

/*
* Check for case user interrupt Kodi with a e.g. Strg+C
* and not start a GUI in this case!
*/
if (!m_onSystemStop)
CGUIDialogCrashReporter::ReportCrash(addon, uuid);
{
// Show Dialog with a non blocking call and to have this thread further available
MESSAGING::HELPERS::ShowReportCrashDialog(std::move(addonId), std::move(uuid), std::move(stacktrace));
}
continue;
}

Expand Down
2 changes: 0 additions & 2 deletions xbmc/addons/interface/InstanceHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ IInstanceHandler::IInstanceHandler(const KODI_ADDON_INSTANCE_BACKEND_HDL hdl,
m_info.type = m_type;
m_info.kodi = hdl;
m_info.parent = m_parentInstance;

// m_info.first_instance = m_addon && !m_addon->Initialized();
}

IInstanceHandler::~IInstanceHandler()
Expand Down
1 change: 1 addition & 0 deletions xbmc/addons/interface/InstanceHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ class IInstanceHandler
const std::shared_ptr<ADDON::IAddon>& Addon() const { return m_addon; }
const std::shared_ptr<ADDON::CAddonInfo>& GetAddonInfo() const { return m_addonInfo; }
const std::shared_ptr<CRunningProcess>& GetProcess() const { return m_process; }
const KODI_ADDON_INSTANCE_INFO* GetCInfo() const { return &m_info; }

virtual void StopReport(ChildStatus status) {}
virtual void OnPreInstall() {}
Expand Down
11 changes: 8 additions & 3 deletions xbmc/addons/interface/RunningProcess.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -385,11 +385,11 @@ void CRunningProcess::AddAddonInstance(IInstanceHandler* handler)
return;
}

if (m_activeAddonHandlers.empty())
m_interface.kodi_addon_base_h->kodi_addon_create_v1(&m_hdl);

std::unique_lock<std::mutex> lock(m_mutex);

if (m_activeAddonHandlers.empty())
m_interface.kodi_addon_base_h->kodi_addon_create_v1(handler->GetCInfo(), &m_hdl);

// add the instance handler to the info to know used amount on addon
m_activeAddonHandlers.insert(handler);
}
Expand Down Expand Up @@ -441,6 +441,11 @@ size_t CRunningProcess::UsedInstanceCount() const
return m_activeAddonHandlers.size();
}

const std::string& CRunningProcess::GetStackTrace() const
{
return m_launcher ? m_launcher->GetStackTrace() : StringUtils::Empty;
}

void CRunningProcess::SetEndtime(unsigned int milliseconds)
{
/*
Expand Down
1 change: 1 addition & 0 deletions xbmc/addons/interface/RunningProcess.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ class CRunningProcess : private CThread
const std::shared_ptr<ADDON::IAddon>& GetAddon() const { return m_addon; }
std::string GetAddonID() const { return m_addon->ID(); }
size_t UsedInstanceCount() const;
const std::string& GetStackTrace() const;

CInterface& GetIfc() { return m_interface; }

Expand Down
10 changes: 5 additions & 5 deletions xbmc/addons/interface/api/addon_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -540,19 +540,19 @@ bool CHdl_kodi_addon_base_h::HandleMessage(int funcGroup,
// Function calls from Kodi to addon

enum ADDON_STATUS CHdl_kodi_addon_base_h::kodi_addon_create_v1(
const KODI_ADDON_INSTANCE_BACKEND_HDL first_instance, KODI_ADDON_HDL* hdl)
const struct KODI_ADDON_INSTANCE_INFO* first_instance, KODI_ADDON_HDL* hdl)
{
// Original API call: typedef enum ADDON_STATUS(ATTR_APIENTRYP PFN_KODI_ADDON_CREATE_V1)(const KODI_ADDON_INSTANCE_BACKEND_HDL first_instance, KODI_ADDON_HDL* hdl);
// Tuple in: typedef std::tuple<PtrValue /* CheckAPIUse(100)::PLACE_12(1) */> msgChild__IN_kodi_addon_create_v1; /* Autogenerated */
// Original API call: typedef enum ADDON_STATUS(ATTR_APIENTRYP PFN_KODI_ADDON_CREATE_V1)(const struct KODI_ADDON_INSTANCE_INFO* first_instance, KODI_ADDON_HDL* hdl);
// Tuple in: typedef std::tuple<IFC_KODI_ADDON_INSTANCE_INFO /* CheckAPIUse(100)::PLACE_18(1) */> msgChild__IN_kodi_addon_create_v1; /* Autogenerated */
// Tuple out: typedef std::tuple<ADDON_STATUS, PtrValue /* CheckAPIUse(100)::PLACE_13(1) */> msgChild_OUT_kodi_addon_create_v1; /* Autogenerated */

#ifndef KODI_INHIBIT_SHARED
if (!m_interface.m_directDll)
{
msgpack::sbuffer in;
msgpack::sbuffer out;
msgpack::pack(in, msgChild__IN_kodi_addon_create_v1(
PtrValue(first_instance) /* CheckAPIUse_WAY_12 (0005) */));
msgpack::pack(
in, msgChild__IN_kodi_addon_create_v1(first_instance /* CheckAPIUse_WAY_16 (0005) */));
if (!m_process->SendMessage(funcGroup_addon_base_h, funcChild_kodi_addon_create_v1, in, out))
return ADDON_STATUS_OK;
msgpack::unpacked ident = msgpack::unpack(out.data(), out.size());
Expand Down
2 changes: 1 addition & 1 deletion xbmc/addons/interface/api/addon_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class CHdl_kodi_addon_base_h : public IMsgHdl

// Function calls from Kodi to addon

enum ADDON_STATUS kodi_addon_create_v1(const KODI_ADDON_INSTANCE_BACKEND_HDL first_instance,
enum ADDON_STATUS kodi_addon_create_v1(const struct KODI_ADDON_INSTANCE_INFO* first_instance,
KODI_ADDON_HDL* hdl); // Added with API 1

void kodi_addon_destroy_v1(KODI_ADDON_HDL hdl); // Added with API 1
Expand Down
30 changes: 22 additions & 8 deletions xbmc/addons/interface/gui/GUIDialogCrashReporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,22 @@ CGUIDialogCrashReporter::RESULT CGUIDialogCrashReporter::GetResult() const
return RESULT::IgnoreCrash;
}

void CGUIDialogCrashReporter::ReportCrash(const std::shared_ptr<ADDON::IAddon>& addon,
const std::string& uuid)
void CGUIDialogCrashReporter::ReportCrash(const KODI::MESSAGING::HELPERS::DialogCrashReportMessage* options)
{
ReportCrash(options->addon, options->uuid, options->stacktrace);
delete options;
}

void CGUIDialogCrashReporter::ReportCrash(const std::string& addon,
const std::string& uuid,
const std::string& stacktrace)
{
using namespace ADDON;

AddonInfoPtr addonInfo = CServiceBroker::GetAddonMgr().GetAddonInfo(addon);
if (!addonInfo)
return;

const auto gui = CServiceBroker::GetGUI();
if (!gui)
return;
Expand All @@ -118,7 +129,7 @@ void CGUIDialogCrashReporter::ReportCrash(const std::shared_ptr<ADDON::IAddon>&
if (!dialog)
return;

const std::string text = StringUtils::Format(g_localizeStrings.Get(2296), addon->Name());
const std::string text = StringUtils::Format(g_localizeStrings.Get(2296), addonInfo->Name());
dialog->SetHeading(2295);
dialog->SetText(text);
dialog->m_canceled = false;
Expand All @@ -135,11 +146,11 @@ void CGUIDialogCrashReporter::ReportCrash(const std::shared_ptr<ADDON::IAddon>&
case RESULT::IgnoreCrash:
break;
case RESULT::DisableAddonAndReport:
SendCrashReport(gui, addon, uuid);
SendCrashReport(gui, addonInfo, uuid, stacktrace);
// fallthru is intended
[[fallthrough]];
case RESULT::DisableAddon:
CServiceBroker::GetAddonMgr().DisableAddon(addon->ID(),
CServiceBroker::GetAddonMgr().DisableAddon(addonInfo->ID(),
AddonDisabledReason::PERMANENT_FAILURE);
break;

Expand All @@ -149,8 +160,9 @@ void CGUIDialogCrashReporter::ReportCrash(const std::shared_ptr<ADDON::IAddon>&
}

void CGUIDialogCrashReporter::SendCrashReport(CGUIComponent* const gui,
const std::shared_ptr<ADDON::IAddon>& addon,
const std::string& uuid)
const ADDON::AddonInfoPtr& addonInfo,
const std::string& uuid,
const std::string& stacktrace)
{
using namespace ADDON;
using namespace XFILE;
Expand All @@ -163,7 +175,7 @@ void CGUIDialogCrashReporter::SendCrashReport(CGUIComponent* const gui,
dialog->SetHeading(g_localizeStrings.Get(2294));
dialog->UseMonoFont(true);

if (addon->Type(addon->Type())->Language() == AddonLanguage::Java)
if (addonInfo->Type(addonInfo->MainType())->Language() == AddonLanguage::Java)
{

const std::string path =
Expand All @@ -179,6 +191,8 @@ void CGUIDialogCrashReporter::SendCrashReport(CGUIComponent* const gui,
}
}
}
else if (!stacktrace.empty())
dialog->SetText(stacktrace);
else
{
dialog->SetText("NEED TODO");
Expand Down
18 changes: 15 additions & 3 deletions xbmc/addons/interface/gui/GUIDialogCrashReporter.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

#include "addons/IAddon.h"
#include "dialogs/GUIDialogBoxBase.h"
#include "messaging/helpers/DialogCrashReporter.h"

namespace KODI
{
Expand All @@ -28,7 +29,17 @@ class CGUIDialogCrashReporter : public CGUIDialogBoxBase
bool OnAction(const CAction& action) override;
bool OnBack(int actionID) override;

static void ReportCrash(const std::shared_ptr<ADDON::IAddon>& addon, const std::string& uuid);
static void ReportCrash(const std::string& addon, const std::string& uuid, const std::string& stacktrace);

/*!
\brief Open a add-on crash report dialog and wait for input
\param[in] options a struct of type DialogCrashReportMessage containing
the options to set for this dialog.
\sa KODI::MESSAGING::HELPERS::DialogCrashReportMessage
*/
void ReportCrash(const KODI::MESSAGING::HELPERS::DialogCrashReportMessage* options);

private:
void OnInitWindow() override;
Expand All @@ -42,8 +53,9 @@ class CGUIDialogCrashReporter : public CGUIDialogBoxBase
};
RESULT GetResult() const;
static void SendCrashReport(CGUIComponent* const gui,
const std::shared_ptr<ADDON::IAddon>& addon,
const std::string& uuid);
const ADDON::AddonInfoPtr& addonInfo,
const std::string& uuid,
const std::string& stacktrace);

bool m_canceled;
bool m_disableAddon;
Expand Down
2 changes: 2 additions & 0 deletions xbmc/addons/interface/launcher/ILauncher.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,15 @@ class ILauncher

int GetExitCode() const { return m_exitCode; }
ChildStatus GetLastChildStatus() const { return m_lastStatus; }
const std::string& GetStackTrace() const { return m_stacktrace; }

protected:
const std::shared_ptr<ADDON::IAddon> m_addonInfo;
const std::string m_uuid;

int m_exitCode = 0;
std::atomic<ChildStatus> m_lastStatus{ChildStatus::NotStarted};
std::string m_stacktrace;
};

} /* namespace INTERFACE */
Expand Down
Loading

0 comments on commit aab24ee

Please sign in to comment.