Skip to content

Commit

Permalink
Converts MythSocket from Qt3 based MSocketDevice to Qt4 QTcpSocket.
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-kristjansson committed Oct 11, 2012
1 parent 4587563 commit 0b106b1
Show file tree
Hide file tree
Showing 35 changed files with 1,100 additions and 1,597 deletions.
38 changes: 19 additions & 19 deletions mythplugins/mythzoneminder/mythzoneminder/zmclient.cpp
Expand Up @@ -97,7 +97,7 @@ bool ZMClient::connectToHost(const QString &lhostname, unsigned int lport)

m_socket = new MythSocket();
//m_socket->setCallbacks(this);
if (!m_socket->connect(m_hostname, m_port))
if (!m_socket->ConnectToHost(m_hostname, m_port))
{
m_socket->DecrRef();
m_socket = NULL;
Expand Down Expand Up @@ -133,33 +133,35 @@ bool ZMClient::connectToHost(const QString &lhostname, unsigned int lport)

bool ZMClient::sendReceiveStringList(QStringList &strList)
{
QStringList origStrList = strList;

bool ok = false;
if (m_bConnected)
{
m_socket->writeStringList(strList);
ok = m_socket->readStringList(strList, false);
}
ok = m_socket->SendReceiveStringList(strList);

if (!ok)
{
LOG(VB_GENERAL, LOG_NOTICE, "Connection to mythzmserver lost");

if (!connectToHost(m_hostname, m_port))
{
LOG(VB_GENERAL, LOG_ERR, "Re connection to mythzmserver failed");
LOG(VB_GENERAL, LOG_ERR, "Re-connection to mythzmserver failed");
return false;
}

// try to resend
m_socket->writeStringList(strList);
ok = m_socket->readStringList(strList, false);
// try to resend
strList = origStrList;
ok = m_socket->SendReceiveStringList(strList);
if (!ok)
{
m_bConnected = false;
return false;
}
}

if (strList.empty())
return false;

// the server sends "UNKNOWN_COMMAND" if it did not recognise the command
if (strList[0] == "UNKNOWN_COMMAND")
{
Expand Down Expand Up @@ -231,7 +233,7 @@ void ZMClient::shutdown()
QMutexLocker locker(&m_socketLock);

if (m_socket)
m_socket->close();
m_socket->DisconnectFromHost();

m_zmclientReady = false;
m_bConnected = false;
Expand Down Expand Up @@ -456,7 +458,8 @@ bool ZMClient::readData(unsigned char *data, int dataSize)

while (dataSize > 0)
{
qint64 sret = m_socket->readBlock((char*) data + read, dataSize);
qint64 sret = m_socket->Read(
(char*) data + read, dataSize, 100 /*ms*/);
if (sret > 0)
{
read += sret;
Expand All @@ -466,18 +469,17 @@ bool ZMClient::readData(unsigned char *data, int dataSize)
timer.start();
}
}
else if (sret < 0 && m_socket->error() != MSocketDevice::NoError)
else if (sret < 0)
{
LOG(VB_GENERAL, LOG_ERR, QString("readData: Error, readBlock %1")
.arg(m_socket->errorToString()));
m_socket->close();
LOG(VB_GENERAL, LOG_ERR, "readData: Error, readBlock");
m_socket->DisconnectFromHost();
return false;
}
else if (!m_socket->isValid())
else if (!m_socket->IsConnected())
{
LOG(VB_GENERAL, LOG_ERR,
"readData: Error, socket went unconnected");
m_socket->close();
m_socket->DisconnectFromHost();
return false;
}
else
Expand All @@ -499,8 +501,6 @@ bool ZMClient::readData(unsigned char *data, int dataSize)
LOG(VB_GENERAL, LOG_ERR, "Error, readData timeout (readBlock)");
return false;
}

usleep(500);
}
}

Expand Down
2 changes: 0 additions & 2 deletions mythtv/libs/libmyth/mythcontext.cpp
Expand Up @@ -26,7 +26,6 @@ using namespace std;
#include "dbutil.h"
#include "DisplayRes.h"
#include "mythmediamonitor.h"
#include "mythsocketthread.h"

#include "mythdb.h"
#include "mythdirs.h"
Expand Down Expand Up @@ -1168,7 +1167,6 @@ MythContext::~MythContext()
if (MThreadPool::globalInstance()->activeThreadCount())
LOG(VB_GENERAL, LOG_INFO, "Waiting for threads to exit.");

ShutdownRRT();
MThreadPool::globalInstance()->waitForDone();
logStop();

Expand Down
9 changes: 4 additions & 5 deletions mythtv/libs/libmythbase/libmythbase.pro
Expand Up @@ -11,7 +11,7 @@ QMAKE_CLEAN += $(TARGET) $(TARGETA) $(TARGETD) $(TARGET0) $(TARGET1) $(TARGET2)

# Input
HEADERS += mthread.h mthreadpool.h
HEADERS += mythsocket.h mythsocket_cb.h mythsocketthread.h msocketdevice.h
HEADERS += mythsocket.h mythsocket_cb.h
HEADERS += mythbaseexp.h mythdbcon.h mythdb.h mythdbparams.h oldsettings.h
HEADERS += verbosedefs.h mythversion.h compat.h mythconfig.h
HEADERS += mythobservable.h mythevent.h httpcomms.h mcodecs.h
Expand All @@ -28,7 +28,7 @@ HEADERS += plist.h bswap.h signalhandling.h mythtimezone.h mythdate.h
HEADERS += ffmpeg-mmx.h

SOURCES += mthread.cpp mthreadpool.cpp
SOURCES += mythsocket.cpp mythsocketthread.cpp msocketdevice.cpp
SOURCES += mythsocket.cpp
SOURCES += mythdbcon.cpp mythdb.cpp mythdbparams.cpp oldsettings.cpp
SOURCES += mythobservable.cpp mythevent.cpp httpcomms.cpp mcodecs.cpp
SOURCES += mythdirs.cpp mythsignalingtimer.cpp
Expand All @@ -42,9 +42,8 @@ SOURCES += referencecounter.cpp mythcommandlineparser.cpp
SOURCES += filesysteminfo.cpp hardwareprofile.cpp serverpool.cpp
SOURCES += plist.cpp signalhandling.cpp mythtimezone.cpp mythdate.cpp

win32:SOURCES += msocketdevice_win.cpp
unix {
SOURCES += msocketdevice_unix.cpp system-unix.cpp
SOURCES += system-unix.cpp
HEADERS += system-unix.h
QMAKE_CXXFLAGS += -fno-strict-aliasing
}
Expand All @@ -60,7 +59,7 @@ inc.files = mythdbcon.h mythdbparams.h mythbaseexp.h mythdb.h
inc.files += compat.h mythversion.h mythconfig.h mythconfig.mak version.h
inc.files += mythobservable.h mythevent.h httpcomms.h mcodecs.h verbosedefs.h
inc.files += mythtimer.h lcddevice.h exitcodes.h mythdirs.h mythstorage.h
inc.files += mythsocket.h mythsocket_cb.h msocketdevice.h mythlogging.h
inc.files += mythsocket.h mythsocket_cb.h mythlogging.h
inc.files += mythcorecontext.h mythsystem.h storagegroup.h loggingserver.h
inc.files += mythcoreutil.h mythlocale.h mythdownloadmanager.h
inc.files += mythtranslation.h iso639.h iso3166.h mythmedia.h mythmiscutil.h
Expand Down

0 comments on commit 0b106b1

Please sign in to comment.