Skip to content

Commit

Permalink
Merge pull request #137 from AlwinEsch/interface-change
Browse files Browse the repository at this point in the history
[Matrix] change to new C++ PVR interface way
  • Loading branch information
AlwinEsch authored Jun 13, 2020
2 parents 8daa62f + f08a9cc commit f81c460
Show file tree
Hide file tree
Showing 30 changed files with 2,727 additions and 2,681 deletions.
88 changes: 88 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
---
# BasedOnStyle: LLVM
AccessModifierOffset: -2
AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
AlignEscapedNewlines: DontAlign
AlignOperands: true
AlignTrailingComments: false
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: InlineOnly
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: true
BinPackArguments: true
BinPackParameters: false
BreakBeforeBinaryOperators: None
BreakBeforeBraces: Allman
BreakBeforeTernaryOperators: true
BreakConstructorInitializersBeforeComma: false
BreakConstructorInitializers: BeforeColon
BreakAfterJavaFieldAnnotations: false
BreakStringLiterals: true
ColumnLimit: 100
CommentPragmas: '^ IWYU pragma:'
ConstructorInitializerAllOnOneLineOrOnePerLine: true
ConstructorInitializerIndentWidth: 2
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
DerivePointerAlignment: false
DisableFormat: false
ExperimentalAutoDetectBinPacking: false
ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH ]
IncludeBlocks: Regroup
IncludeCategories:
- Regex: '^<[a-z0-9_]+>$'
Priority: 3
- Regex: '^<(assert|complex|ctype|errno|fenv|float|inttypes|iso646|limits|locale|math|setjmp|signal|stdalign|stdarg|stdatomic|stdbool|stddef|stdint|stdio|stdlib|stdnoreturn|string|tgmath|threads|time|uchar|wchar|wctype)\.h>$'
Priority: 3
- Regex: '^<'
Priority: 3
- Regex: '^["<](kodi|p8-platform)\/.*\.h[">]$'
Priority: 2
- Regex: '.*'
Priority: 1
IncludeIsMainRegex: '$'
IndentCaseLabels: true
IndentWidth: 2
IndentWrappedFunctionNames: false
JavaScriptQuotes: Leave
JavaScriptWrapImports: true
KeepEmptyLinesAtTheStartOfBlocks: true
MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 2
NamespaceIndentation: None
ObjCBlockIndentWidth: 2
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: true
PenaltyBreakBeforeFirstCallParameter: 19
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakString: 1000
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 60000
PointerAlignment: Left
ReflowComments: false
SortIncludes: true
SpaceAfterCStyleCast: false
SpaceAfterTemplateKeyword: false
SpaceBeforeAssignmentOperators: true
SpaceBeforeParens: ControlStatements
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: false
SpacesInContainerLiterals: true
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: Cpp11
TabWidth: 8
UseTab: Never
...
2 changes: 0 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ set(BASE_SOURCES
src/base/Cache.cpp)

set(SOURCES
src/client.cpp
src/ChannelManager.cpp
src/CWatchdog.cpp
src/GuideManager.cpp
Expand All @@ -48,7 +47,6 @@ set(STALKER_SOURCES

set(STALKER_HEADERS
src/ChannelManager.h
src/client.h
src/CWatchdog.h
src/Error.h
src/GuideManager.h
Expand Down
4 changes: 2 additions & 2 deletions pvr.stalker/addon.xml.in
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<addon
id="pvr.stalker"
version="5.0.0"
version="6.0.0"
name="Stalker Client"
provider-name="Jamal Edey">
<requires>@ADDON_DEPENDS@</requires>
<extension
point="xbmc.pvrclient"
point="kodi.pvrclient"
library_@PLATFORM@="@LIBRARY_FILENAME@"/>
<extension point="xbmc.addon.metadata">
<summary lang="af_ZA">PVR Kliënt om Kodi aan Stalker Middleware te konnekteer</summary>
Expand Down
5 changes: 5 additions & 0 deletions pvr.stalker/changelog.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
v6.0.0
- PVR API 7.0.0
- Rework addon to support new API interface
- Code cleanup

v5.0.0:
- Update PVR API 6.5.1
- Update Global API 1.2.0
Expand Down
108 changes: 54 additions & 54 deletions src/CWatchdog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,74 +8,74 @@

#include "CWatchdog.h"

#include "client.h"
#include <chrono>
#include <kodi/General.h>
#include <thread>

#if defined(_WIN32) || defined(_WIN64)
#include <windows.h>
#define usleep(usec) Sleep((DWORD)(usec)/1000)
#else
#include <unistd.h>
#endif

using namespace ADDON;
using namespace SC;

CWatchdog::CWatchdog(uint32_t interval, SAPI *api, std::function<void(SError)> errorCallback)
: m_interval(interval), m_api(api), m_errorCallback(errorCallback), m_threadActive(false) {
CWatchdog::CWatchdog(uint32_t interval, SAPI* api, std::function<void(SError)> errorCallback)
: m_interval(interval), m_api(api), m_errorCallback(errorCallback)
{
}

CWatchdog::~CWatchdog() {
Stop();
CWatchdog::~CWatchdog()
{
Stop();
}

void CWatchdog::Start() {
m_threadActive = true;
m_thread = std::thread([this] {
Process();
});
void CWatchdog::Start()
{
m_threadActive = true;
m_thread = std::thread([this] { Process(); });
}

void CWatchdog::Stop() {
m_threadActive = false;
if (m_thread.joinable())
m_thread.join();
void CWatchdog::Stop()
{
m_threadActive = false;
if (m_thread.joinable())
m_thread.join();
}

void CWatchdog::Process() {
XBMC->Log(LOG_DEBUG, "%s: start", __FUNCTION__);

int curPlayType;
int eventActiveId;
Json::Value parsed;
SError ret;
unsigned int target(m_interval * 1000);
unsigned int count;

while (m_threadActive) {
// hardcode values for now
curPlayType = 1; // tv
eventActiveId = 0;

ret = m_api->WatchdogGetEvents(curPlayType, eventActiveId, parsed);
if (ret != SERROR_OK) {
XBMC->Log(LOG_ERROR, "%s: WatchdogGetEvents failed", __FUNCTION__);

if (m_errorCallback != nullptr)
m_errorCallback(ret);
}
void CWatchdog::Process()
{
kodi::Log(ADDON_LOG_DEBUG, "%s: start", __func__);

int curPlayType;
int eventActiveId;
Json::Value parsed;
SError ret;
unsigned int target(m_interval * 1000);
unsigned int count;

while (m_threadActive)
{
// hardcode values for now
curPlayType = 1; // tv
eventActiveId = 0;

ret = m_api->WatchdogGetEvents(curPlayType, eventActiveId, parsed);
if (ret != SERROR_OK)
{
kodi::Log(ADDON_LOG_ERROR, "%s: WatchdogGetEvents failed", __func__);

if (m_errorCallback != nullptr)
m_errorCallback(ret);
}

// ignore the result. don't confirm events (yet)
// ignore the result. don't confirm events (yet)

parsed.clear();
parsed.clear();

count = 0;
while (count < target) {
usleep(100000);
if (!m_threadActive)
break;
count += 100;
}
count = 0;
while (count < target)
{
std::this_thread::sleep_for(std::chrono::milliseconds(100));
if (!m_threadActive)
break;
count += 100;
}
}

XBMC->Log(LOG_DEBUG, "%s: stop", __FUNCTION__);
kodi::Log(ADDON_LOG_DEBUG, "%s: stop", __func__);
}
39 changes: 20 additions & 19 deletions src/CWatchdog.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,31 @@

#pragma once

#include <thread>
#include <functional>

#include "SAPI.h"

namespace SC {
class CWatchdog {
public:
CWatchdog(unsigned int interval, SAPI *api, std::function<void(SError)> errorCallback);
#include <functional>
#include <thread>

virtual ~CWatchdog();
namespace SC
{
class CWatchdog
{
public:
CWatchdog(unsigned int interval, SAPI* api, std::function<void(SError)> errorCallback);

virtual void Start();
virtual ~CWatchdog();

virtual void Stop();
virtual void Start();

private:
void Process();
virtual void Stop();

unsigned int m_interval;
SAPI *m_api;
std::function<void(SError)> m_errorCallback;
bool m_threadActive;
std::thread m_thread;
};
}
private:
void Process();

unsigned int m_interval;
SAPI* m_api;
std::function<void(SError)> m_errorCallback;
bool m_threadActive = false;
std::thread m_thread;
};
} // namespace SC
Loading

0 comments on commit f81c460

Please sign in to comment.