Ticket #5228: iptvchannelfetcher.path

File iptvchannelfetcher.path, 3.6 KB (added by Michaël Burtin <mburtin@…>, 12 years ago)

Patch to convert IPTVChannelFetche thread from pthead to QThread

Line 
1Index: libs/libmythtv/iptv/iptvchannelfetcher.cpp
2===================================================================
3--- libs/libmythtv/iptv/iptvchannelfetcher.cpp  (révision 17084)
4+++ libs/libmythtv/iptv/iptvchannelfetcher.cpp  (copie de travail)
5@@ -11,12 +11,10 @@
6 #include "channelutil.h"
7 #include "urlfetcher.h"
8 #include "iptvchannelfetcher.h"
9-
10+
11 #define LOC QString("IPTVChanFetch: ")
12 #define LOC_ERR QString("IPTVChanFetch, Error: ")
13 
14-void *run_scan_thunk(void*);
15-
16 static bool parse_chan_info(const QString   &rawdata,
17                             IPTVChannelInfo &info,
18                             QString         &channum,
19@@ -26,6 +24,15 @@
20                          QString       &channum,
21                          QString       &name);
22 
23+/** \fn IPTVChannelFetcherThread::run(void)
24+*   \brief Thunk that allows iptvfetcher Qthread to
25+*         call IPTVChannelFetcher::RunScan().
26+*/
27+void IPTVChannelFetcherThread::run(void)
28+{
29+    iptvfetcher->RunScan();
30+}
31+
32 IPTVChannelFetcher::IPTVChannelFetcher(
33     uint cardid, const QString &inputname, uint sourceid) :
34     _cardid(cardid),       _inputname(Q3DeepCopy<QString>(inputname)),
35@@ -57,7 +64,7 @@
36         _stop_now = true;
37         _lock.unlock();
38 
39-        pthread_join(_thread, NULL);
40+        _thread.wait();
41         return;
42     }
43 
44@@ -76,7 +83,8 @@
45 
46     _stop_now = false;
47 
48-    pthread_create(&_thread, NULL, run_scan_thunk, this);
49+    _thread.iptvfetcher = this;
50+    _thread.start(QThread::NormalPriority);
51 
52     while (!_thread_running && !_stop_now)
53         usleep(5000);
54@@ -86,14 +94,6 @@
55     return _thread_running;
56 }
57 
58-void *run_scan_thunk(void *param)
59-{
60-    IPTVChannelFetcher *chanscan = (IPTVChannelFetcher*) param;
61-    chanscan->RunScan();
62-
63-    return NULL;
64-}
65-
66 void IPTVChannelFetcher::RunScan(void)
67 {
68     _thread_running = true;
69@@ -113,7 +113,7 @@
70     emit ServiceScanPercentComplete(5);
71     emit ServiceScanUpdateText(tr("Downloading Playlist"));
72 
73-    QString playlist = DownloadPlaylist(url, false);
74+    QString playlist = DownloadPlaylist(url, true);
75 
76     if (_stop_now || playlist.isEmpty())
77     {
78Index: libs/libmythtv/iptv/iptvchannelfetcher.h
79===================================================================
80--- libs/libmythtv/iptv/iptvchannelfetcher.h    (révision 17084)
81+++ libs/libmythtv/iptv/iptvchannelfetcher.h    (copie de travail)
82@@ -1,21 +1,28 @@
83 #ifndef _IPTVCHANNELFETCHER_H_
84 #define _IPTVCHANNELFETCHER_H_
85 
86-// POSIX headers
87-#include <pthread.h>
88-
89 // Qt headers
90 #include <qobject.h>
91 #include <qmutex.h>
92+#include <qthread.h>
93 
94 // MythTV headers
95 #include "iptvchannelinfo.h"
96 
97+class IPTVChannelFetcher;
98+
99+class IPTVChannelFetcherThread : public QThread
100+{
101+  public:
102+    virtual void run();
103+    IPTVChannelFetcher   *iptvfetcher;
104+};
105+
106 class IPTVChannelFetcher : public QObject
107 {
108     Q_OBJECT
109 
110-    friend void *run_scan_thunk(void *param);
111+    friend class IPTVChannelFetcherThread;
112 
113   public:
114     IPTVChannelFetcher(uint cardid, const QString &inputname, uint sourceid);
115@@ -37,13 +44,15 @@
116     /// \brief Signals that the scan is complete
117     void ServiceScanComplete(void);
118 
119+  protected:
120+    void RunScan(void);
121+
122   private:
123     ~IPTVChannelFetcher();
124     void SetTotalNumChannels(uint val) { _chan_cnt = (val) ? val : 1; }
125     void SetNumChannelsParsed(uint);
126     void SetNumChannelsInserted(uint);
127     void SetMessage(const QString &status);
128-    void RunScan(void);
129 
130   private:
131     uint      _cardid;
132@@ -52,7 +61,7 @@
133     uint      _chan_cnt;
134     bool      _thread_running;
135     bool      _stop_now;
136-    pthread_t _thread;
137+    IPTVChannelFetcherThread _thread;
138     QMutex    _lock;
139 };