]> git.vomp.tv Git - vompclient.git/blob - tfeed.cc
WOptionPane CWFs
[vompclient.git] / tfeed.cc
1 /*
2     Copyright 2008 Marten Richter
3     
4     This file is part of VOMP.
5     
6     VOMP is free software; you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation; either version 2 of the License, or
9     (at your option) any later version.
10     VOMP is distributed in the hope that it will be useful,
11     but WITHOUT ANY WARRANTY; without even the implied warranty of
12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13     GNU General Public License for more details.
14     
15     You should have received a copy of the GNU General Public License
16     along with VOMP.  If not, see <https://www.gnu.org/licenses/>.
17 */
18
19 #include "log.h"
20 #include "demuxer.h"
21 #include "callback.h"
22 #include "util.h"
23
24 #include "tfeed.h"
25
26 TFeed::TFeed(Callback* tcb): cb(*tcb)
27 {
28   teletextEnabled = 1;
29 }
30   
31 void TFeed::disable()
32 {
33   teletextEnabled = 0;
34 }
35
36 void TFeed::enable()
37 {
38   teletextEnabled = 1;
39 }
40
41 void TFeed::start()
42 {
43   teletextEnabled = 1;
44
45   threadStartProtect.lock();
46   feedThread = std::thread( [this]
47   {
48     threadStartProtect.lock();
49     threadStartProtect.unlock();
50     threadMethod();
51   });
52   threadStartProtect.unlock();
53 }
54
55 void TFeed::stop()
56 {
57   if (!feedThread.joinable()) return;
58   stopThread = true;
59   feedThread.join();
60   stopThread = false;
61 }
62
63 void TFeed::threadMethod()
64 {
65   bool tlen;
66   
67   while(1)
68   {
69     if (stopThread) return;
70
71     tlen = Demuxer::getInstance()->writeTeletext();
72     
73     if (tlen)
74     {
75       cb.call(this);
76 //        Log::getInstance()->log("Tfeed", Log::DEBUG, "written");
77     }
78     else
79     {
80       //MILLISLEEP(100);
81         MILLISLEEP(20); //Performance Issue Marten
82     }
83   }
84 }