[SCM] kodi-pvr-vdr-vnsi/master: implement ConnectionLost callback for async startup

tiber-guest at users.alioth.debian.org tiber-guest at users.alioth.debian.org
Fri Nov 4 00:20:21 UTC 2016


The following commit has been merged in the master branch:
commit 7e2ed92cbff217bd8ea459e81bdc5220c6fe522b
Author: Rainer Hochecker <fernetmenta at online.de>
Date:   Sun Mar 27 10:16:46 2016 +0200

    implement ConnectionLost callback for async startup

diff --git a/src/VNSIData.cpp b/src/VNSIData.cpp
index 212f1d8..7e4de7a 100644
--- a/src/VNSIData.cpp
+++ b/src/VNSIData.cpp
@@ -61,14 +61,22 @@ cVNSIData::cVNSIData()
 
 cVNSIData::~cVNSIData()
 {
-  StopThread();
+  m_abort = true;
+  StopThread(0);
   Close();
 }
 
-bool cVNSIData::Open(const std::string& hostname, int port, const char* name, const std::string& mac)
+bool cVNSIData::Start(const std::string& hostname, int port, const char* name, const std::string& mac)
 {
-  /* First wake up the VDR server in case a MAC-Address is specified */
-  if (!mac.empty()) {
+  m_hostname = hostname;
+  m_port = port;
+
+  if (name != nullptr)
+    m_name = name;
+
+  // First wake up the VDR server in case a MAC-Address is specified
+  if (!mac.empty())
+  {
     const char* temp_mac;
     temp_mac = mac.c_str();
 
@@ -78,32 +86,24 @@ bool cVNSIData::Open(const std::string& hostname, int port, const char* name, co
     }
   }
 
-  if(!cVNSISession::Open(hostname, port, name))
-    return false;
-
-  return true;
-}
-
-bool cVNSIData::Login()
-{
-  if(!cVNSISession::Login())
-    return false;
+  PVR->ConnectionStateChange("VNSI stated", PVR_CONNECTION_STATE_CONNECTING, "VNSI started");
 
+  m_abort = false;
   CreateThread();
+
   return true;
 }
 
 void cVNSIData::OnDisconnect()
 {
-  XBMC->QueueNotification(QUEUE_ERROR, XBMC->GetLocalizedString(30044));
-  PVR->TriggerTimerUpdate();
+  PVR->ConnectionStateChange("vnsi connection lost", PVR_CONNECTION_STATE_DISCONNECTED, XBMC->GetLocalizedString(30044));
 }
 
 void cVNSIData::OnReconnect()
 {
-  XBMC->QueueNotification(QUEUE_INFO, XBMC->GetLocalizedString(30045));
+  EnableStatusInterface(g_bHandleMessages, false);
 
-  EnableStatusInterface(g_bHandleMessages);
+  PVR->ConnectionStateChange("vnsi connection established", PVR_CONNECTION_STATE_CONNECTED, XBMC->GetLocalizedString(30045));
 
   PVR->TriggerChannelUpdate();
   PVR->TriggerTimerUpdate();
@@ -187,12 +187,18 @@ bool cVNSIData::SupportRecordingsUndelete()
   return false;
 }
 
-bool cVNSIData::EnableStatusInterface(bool onOff)
+bool cVNSIData::EnableStatusInterface(bool onOff, bool wait)
 {
   cRequestPacket vrp;
   vrp.init(VNSI_ENABLESTATUSINTERFACE);
   vrp.add_U8(onOff);
 
+  if (!wait)
+  {
+    cVNSISession::TransmitMessage(&vrp);
+    return true;
+  }
+
   auto vresp = ReadResult(&vrp);
   if (!vresp)
   {
@@ -1004,12 +1010,13 @@ bool cVNSIData::OnResponsePacket(cResponsePacket* pkt)
 
 void *cVNSIData::Process()
 {
+  m_connectionLost = true;
   std::unique_ptr<cResponsePacket> vresp;
 
   while (!IsStopped())
   {
     // try to reconnect
-    if(ConnectionLost() && !TryReconnect())
+    if (m_connectionLost && !TryReconnect())
     {
       Sleep(1000);
       continue;
diff --git a/src/VNSIData.h b/src/VNSIData.h
index 0bcb006..93ef8e1 100644
--- a/src/VNSIData.h
+++ b/src/VNSIData.h
@@ -36,12 +36,10 @@ public:
   cVNSIData();
   virtual ~cVNSIData();
 
-  bool        Open(const std::string& hostname, int port, const char* name = NULL, const std::string& mac = "");
-  bool        Login() override;
-
+  bool Start(const std::string& hostname, int port, const char* name = NULL, const std::string& mac = "");
   bool        SupportChannelScan();
   bool        SupportRecordingsUndelete();
-  bool        EnableStatusInterface(bool onOff);
+  bool        EnableStatusInterface(bool onOff, bool wait = true);
   bool        GetDriveSpace(long long *total, long long *used);
 
   int         GetChannelsCount();
diff --git a/src/VNSIDemux.cpp b/src/VNSIDemux.cpp
index fc38f0c..bd05c30 100644
--- a/src/VNSIDemux.cpp
+++ b/src/VNSIDemux.cpp
@@ -89,7 +89,7 @@ void cVNSIDemux::Abort()
 
 DemuxPacket* cVNSIDemux::Read()
 {
-  if(ConnectionLost())
+  if (m_connectionLost)
   {
     return NULL;
   }
diff --git a/src/VNSIRecording.cpp b/src/VNSIRecording.cpp
index bdbcd87..d487d95 100644
--- a/src/VNSIRecording.cpp
+++ b/src/VNSIRecording.cpp
@@ -82,7 +82,7 @@ void cVNSIRecording::Close()
 
 int cVNSIRecording::Read(unsigned char* buf, uint32_t buf_size)
 {
-  if (ConnectionLost() && !TryReconnect())
+  if (m_connectionLost && !TryReconnect())
   {
     *buf = 0;
     SleepMs(100);
diff --git a/src/VNSISession.cpp b/src/VNSISession.cpp
index 8d87ffa..98ee97b 100644
--- a/src/VNSISession.cpp
+++ b/src/VNSISession.cpp
@@ -47,6 +47,7 @@ cVNSISession::cVNSISession()
   : m_protocol(0)
   , m_socket(NULL)
   , m_connectionLost(false)
+  , m_abort(false)
 {
 }
 
@@ -57,7 +58,7 @@ cVNSISession::~cVNSISession()
 
 void cVNSISession::Close()
 {
-  if(IsOpen())
+  if (IsOpen())
   {
     m_socket->Close();
   }
@@ -74,14 +75,14 @@ bool cVNSISession::Open(const std::string& hostname, int port, const char *name)
   uint64_t iTarget = iNow + g_iConnectTimeout * 1000;
   if (!m_socket)
     m_socket = new CTcpConnection(hostname.c_str(), port);
-  while (!m_socket->IsOpen() && iNow < iTarget)
+  while (!m_socket->IsOpen() && iNow < iTarget && !m_abort)
   {
     if (!m_socket->Open(iTarget - iNow))
       CEvent::Sleep(100);
     iNow = GetTimeMs();
   }
 
-  if (!m_socket->IsOpen())
+  if (!m_socket->IsOpen() && !m_abort)
   {
     XBMC->Log(LOG_ERROR, "%s - failed to connect to the backend (%s)", __FUNCTION__, m_socket->GetError().c_str());
     return false;
@@ -91,7 +92,7 @@ bool cVNSISession::Open(const std::string& hostname, int port, const char *name)
   m_hostname = hostname;
   m_port = port;
 
-  if(name != NULL)
+  if (name != nullptr)
     m_name = name;
 
   return true;
@@ -334,17 +335,20 @@ bool cVNSISession::ReadSuccess(cRequestPacket* vrp)
   return true;
 }
 
-void cVNSISession::OnReconnect() {
+void cVNSISession::OnReconnect()
+{
 }
 
-void cVNSISession::OnDisconnect() {
+void cVNSISession::OnDisconnect()
+{
 }
 
-bool cVNSISession::TryReconnect() {
-  if(!Open(m_hostname, m_port))
+bool cVNSISession::TryReconnect()
+{
+  if (!Open(m_hostname, m_port))
     return false;
 
-  if(!Login())
+  if (!Login())
     return false;
 
   XBMC->Log(LOG_DEBUG, "%s - reconnected", __FUNCTION__);
diff --git a/src/VNSISession.h b/src/VNSISession.h
index 03d5a25..c680a2d 100644
--- a/src/VNSISession.h
+++ b/src/VNSISession.h
@@ -22,6 +22,7 @@
 
 #include <stdint.h>
 #include <string>
+#include <atomic>
 #include "p8-platform/threads/threads.h"
 
 #include <memory>
@@ -54,6 +55,8 @@ public:
   const std::string& GetServerName() const { return m_server; }
   const std::string& GetVersion() const { return m_version; }
 
+
+
 protected:
 
   void SleepMs(int ms);
@@ -65,7 +68,6 @@ protected:
   virtual void OnReconnect();
 
   virtual void SignalConnectionLost();
-  bool ConnectionLost() const { return m_connectionLost; }
 
   std::string      m_hostname;
   int              m_port;
@@ -74,6 +76,8 @@ protected:
   int              m_protocol;
   std::string      m_server;
   std::string      m_version;
+  bool m_connectionLost;
+  std::atomic_bool m_abort;
 
 private:
 
@@ -81,5 +85,4 @@ private:
 
   P8PLATFORM::CTcpConnection *m_socket;
   P8PLATFORM::CMutex          m_readMutex;
-  bool                      m_connectionLost;
 };
diff --git a/src/client.cpp b/src/client.cpp
index 2b2fcd2..38f3bcb 100644
--- a/src/client.cpp
+++ b/src/client.cpp
@@ -222,24 +222,11 @@ ADDON_STATUS ADDON_Create(void* hdl, void* props)
   try
   {
     VNSIData = new cVNSIData;
-    if (!VNSIData->Open(g_szHostname, g_iPort, NULL, g_szWolMac))
+    m_CurStatus = ADDON_STATUS_OK;
+    if (!VNSIData->Start(g_szHostname, g_iPort, nullptr, g_szWolMac))
     {
       ADDON_Destroy();
-      m_CurStatus = ADDON_STATUS_LOST_CONNECTION;
-      return m_CurStatus;
-    }
-
-    if (!VNSIData->Login())
-    {
-      ADDON_Destroy();
-      m_CurStatus = ADDON_STATUS_LOST_CONNECTION;
-      return m_CurStatus;
-    }
-
-    if (!VNSIData->EnableStatusInterface(g_bHandleMessages))
-    {
-      ADDON_Destroy();
-      m_CurStatus = ADDON_STATUS_LOST_CONNECTION;
+      m_CurStatus = ADDON_STATUS_PERMANENT_FAILURE;
       return m_CurStatus;
     }
   }
@@ -257,7 +244,6 @@ ADDON_STATUS ADDON_Create(void* hdl, void* props)
   hook.iLocalizedStringId = 30107;
   PVR->AddMenuHook(&hook);
 
-  m_CurStatus = ADDON_STATUS_OK;
   return m_CurStatus;
 }
 

-- 
kodi-pvr-vdr-vnsi packaging



More information about the pkg-multimedia-commits mailing list