Ticket #1044: 1044.patch

File 1044.patch, 4.5 KB (added by danielk, 15 years ago)

possible fix

  • libs/libmyth/lcddevice.cpp

     
    3131#define LCD_DEVICE_DEBUG 0
    3232
    3333LCD::LCD()
    34    :QObject(NULL, "LCD")
     34    : QObject(NULL, "LCD"),
     35      socket(new QSocket(this)),    socketLock(true),
     36      hostname("localhost"),        port(6545),
     37      connected(false),
     38
     39      retryTimer(new QTimer(this)), LEDTimer(new QTimer(this)),
     40
     41      send_buffer(""),              last_command(QString::null),
     42
     43      lcd_width(0),                 lcd_height(0),
     44
     45      lcd_ready(false),             lcd_showtime(false),
     46      lcd_showmenu(false),          lcd_showgeneric(false),
     47      lcd_showmusic(false),         lcd_showchannel(false),
     48      lcd_showvolume(false),        lcd_showrecstatus(false),
     49      lcd_backlighton(false),       lcd_heartbeaton(false),
     50
     51      lcd_popuptime(0),
     52
     53      lcd_showmusic_items(QString::null),
     54      lcd_keystring(QString::null),
     55
     56      GetLEDMask(NULL)
    3557{
    3658    // Constructor for LCD
    3759    //
     
    3961    // communications with the LDCd daemon.
    4062
    4163#if LCD_DEVICE_DEBUG > 0
    42     VERBOSE(VB_IMPORTANT, "lcddevice: An LCD object now exists (LCD() was called)");
     64    VERBOSE(VB_IMPORTANT, "lcddevice: An LCD object now exists "
     65            "(LCD() was called)");
    4366#endif
    4467
    45     GetLEDMask = NULL;
    46 
    47     socket = new QSocket(this);
    48     connect(socket, SIGNAL(error(int)), this, SLOT(veryBadThings(int)));
    49     connect(socket, SIGNAL(readyRead()), this, SLOT(serverSendingData()));
    50 
    51     lcd_ready = false;
    52    
    53     hostname = "localhost";
    54     port = 6545;
    55    
    56     connected = false;
    57     send_buffer = "";
    58    
    59     retryTimer = new QTimer(this);
    60     connect(retryTimer, SIGNAL(timeout()), this, SLOT(restartConnection()));   
    61 
    62     LEDTimer = new QTimer(this);
    63     connect(LEDTimer, SIGNAL(timeout()), this, SLOT(outputLEDs()));
     68    connect(socket,     SIGNAL(error(int)),  this, SLOT(veryBadThings(int)));
     69    connect(socket,     SIGNAL(readyRead()), this, SLOT(serverSendingData()));
     70    connect(retryTimer, SIGNAL(timeout()),   this, SLOT(restartConnection()));
     71    connect(LEDTimer,   SIGNAL(timeout()),   this, SLOT(outputLEDs()));
    6472}
    6573
    6674bool LCD::m_server_unavailable = false;
     
    102110
    103111bool LCD::connectToHost(const QString &lhostname, unsigned int lport)
    104112{
    105 #if LCD_DEVICE_DEBUG > 0   
     113    QMutexLocker locker(&socketLock);
     114
     115#if LCD_DEVICE_DEBUG > 0
    106116    VERBOSE(VB_IMPORTANT, "lcddevice: connecting to host: "
    107117            << lhostname << " - port: " << lport);
    108118#endif
     
    185195
    186196void LCD::sendToServer(const QString &someText)
    187197{
     198    QMutexLocker locker(&socketLock);
     199
    188200    // Check the socket, make sure the connection is still up
    189201    if (socket->state() == QSocket::Idle)
    190202    {
     
    236248
    237249void LCD::serverSendingData()
    238250{
     251    QMutexLocker locker(&socketLock);
     252
    239253    QString lineFromServer, tempString;
    240254    QStringList aList;
    241255    QStringList::Iterator it;
     
    354368
    355369void LCD::veryBadThings(int anError)
    356370{
     371    QMutexLocker locker(&socketLock);
     372
    357373    // Deal with failures to connect and inabilities to communicate
    358374
    359375    QString err;
     
    616632
    617633void LCD::shutdown()
    618634{
     635    QMutexLocker locker(&socketLock);
     636
    619637#if LCD_DEVICE_DEBUG > 1
    620638    VERBOSE(VB_IMPORTANT, "lcddevice: shutdown");
    621639#endif
     
    628646
    629647void LCD::resetServer()
    630648{
     649    QMutexLocker locker(&socketLock);
     650
    631651    if (!lcd_ready)
    632652        return;
    633653   
  • libs/libmyth/lcddevice.h

     
    22#define LCDDEVICE_H_
    33
    44#include <iostream>
     5using namespace std;
     6
    57#include <qobject.h>
    68#include <qstringlist.h>
    79#include <qvaluevector.h>
    810#include <qsocket.h>
    911#include <qtimer.h>
    1012#include <qdatetime.h>
     13#include <qmutex.h>
    1114
    12 using namespace std;
    13 
    1415enum CHECKED_STATE {CHECKED = 0, UNCHECKED, NOTCHECKABLE };
    1516
    1617class LCDMenuItem
     
    225226    void init();
    226227    void handleKeyPress(QString key);
    227228    QString quotedString(const QString &s);
     229    void describeServer();
    228230   
    229231    QSocket *socket;
     232    QMutex   socketLock;
     233    QString  hostname;
     234    uint     port;
     235    bool     connected;
     236
    230237    QTimer *retryTimer;
    231238    QTimer *LEDTimer;
    232239   
    233     void describeServer();
    234 
    235     bool connected;
    236 
    237240    QString send_buffer;
    238241    QString last_command;
    239     QString hostname;
    240     unsigned int port;
    241242
    242243    int  lcd_width;
    243244    int  lcd_height;