MythTV
master
|
#include "mythmiscutil.h"
#include <array>
#include <cerrno>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <unistd.h>
#include <fcntl.h>
#include <sched.h>
#include "compat.h"
#include <QReadWriteLock>
#include <QNetworkProxy>
#include <QStringList>
#include <QDataStream>
#include <QUdpSocket>
#include <QFileInfo>
#include <QFile>
#include <QDir>
#include <QUrl>
#include <QHostAddress>
#include <QRegularExpression>
#include <QRegularExpressionMatchIterator>
#include "mythcorecontext.h"
#include "exitcodes.h"
#include "mythlogging.h"
#include "mythsocket.h"
#include "mythcoreutil.h"
#include "mythsystemlegacy.h"
#include "mythconfig.h"
Go to the source code of this file.
Enumerations | |
enum | states { START, INTEXT, INSQUOTE, INDQUOTE, ESCTEXT, ESCSQUOTE, ESCDQUOTE } |
Functions | |
bool | getUptime (time_t &uptime) |
Returns uptime statistics. More... | |
bool | getMemStats (int &totalMB, int &freeMB, int &totalVM, int &freeVM) |
Returns memory statistics in megabytes. More... | |
loadArray | getLoadAvgs (void) |
Returns the system load averages. More... | |
bool | hasUtf8 (const char *str) |
Guess whether a string is UTF-8. More... | |
bool | ping (const QString &host, int timeout) |
Can we ping host within timeout seconds? More... | |
bool | telnet (const QString &host, int port) |
Can we talk to port on host? More... | |
long long | copy (QFile &dst, QFile &src, uint block_size) |
Copies src file to dst file. More... | |
QString | createTempFile (QString name_template, bool dir) |
bool | makeFileAccessible (const QString &filename) |
QString | getResponse (const QString &query, const QString &def) |
In an interactive shell, prompt the user to input a string. More... | |
int | intResponse (const QString &query, int def) |
In an interactive shell, prompt the user to input a number. More... | |
QString | getSymlinkTarget (const QString &start_file, QStringList *intermediaries, unsigned maxLinks) |
bool | IsMACAddress (const QString &MAC) |
QString | FileHash (const QString &filename) |
bool | WakeOnLAN (const QString &MAC) |
bool | MythWakeup (const QString &wakeUpCommand, uint flags, uint timeout) |
bool | IsPulseAudioRunning (void) |
Is A/V Sync destruction daemon is running on this host? More... | |
bool | myth_nice (int val) |
void | myth_yield (void) |
bool | myth_ioprio (int) |
Allows setting the I/O priority of the current process/thread. More... | |
bool | MythRemoveDirectory (QDir &aDir) |
void | setHttpProxy (void) |
Get network proxy settings from OS, and use for [Q]Http[Comms]. More... | |
void | wrapList (QStringList &list, int width) |
QString | xml_indent (uint level) |
int | naturalCompare (const QString &_a, const QString &_b, Qt::CaseSensitivity caseSensitivity) |
QString | MythFormatTimeMs (int msecs, const QString &fmt) |
Format a milliseconds time value. More... | |
QString | MythFormatTime (int secs, const QString &fmt) |
Format a seconds time value. More... | |
QStringList | MythSplitCommandString (const QString &line) |
enum states |
Enumerator | |
---|---|
START | |
INTEXT | |
INSQUOTE | |
INDQUOTE | |
ESCTEXT | |
ESCSQUOTE | |
ESCDQUOTE |
Definition at line 1246 of file mythmiscutil.cpp.
getUptime | ( | time_t & | uptime | ) |
Returns uptime statistics.
Definition at line 68 of file mythmiscutil.cpp.
Referenced by StatusBox::doMachineStatus(), BaseRequestHandler::HandleQueryUptime(), MainServer::HandleQueryUptime(), and NetworkControl::processQuery().
getMemStats | ( | int & | totalMB, |
int & | freeMB, | ||
int & | totalVM, | ||
int & | freeVM | ||
) |
Returns memory statistics in megabytes.
Definition at line 111 of file mythmiscutil.cpp.
Referenced by StatusBox::doMachineStatus(), BaseRequestHandler::HandleQueryMemStats(), MainServer::HandleQueryMemStats(), and NetworkControl::processQuery().
getLoadAvgs | ( | void | ) |
Returns the system load averages.
Definition at line 178 of file mythmiscutil.cpp.
Referenced by StatusBox::doMachineStatus(), HttpStatus::FillStatusXML(), BaseRequestHandler::HandleQueryLoad(), MainServer::HandleQueryLoad(), and NetworkControl::processQuery().
bool hasUtf8 | ( | const char * | str | ) |
Guess whether a string is UTF-8.
Definition at line 195 of file mythmiscutil.cpp.
bool ping | ( | const QString & | host, |
int | timeout | ||
) |
Can we ping host within timeout seconds?
Different operating systems use different parameters to specify a timeout to the ping command. FreeBSD and derivatives use '-t'; Linux and derivatives use '-w'. Using the right parameter also eliminates the need for the old behavior of falling back to pinging the localhost with and without a timeout, in order to characterize whether the right parameter was used in the first place.
Definition at line 247 of file mythmiscutil.cpp.
Referenced by CardUtil::IsVBoxPresent(), and setHttpProxy().
bool telnet | ( | const QString & | host, |
int | port | ||
) |
Can we talk to port on host?
Definition at line 278 of file mythmiscutil.cpp.
Referenced by setHttpProxy().
copy | ( | QFile & | dst, |
QFile & | src, | ||
uint | block_size | ||
) |
Copies src file to dst file.
If the dst file is open, it must be open for writing. If the src file is open, if must be open for reading.
The files will be in the same open or close state after this function runs as they were prior to this function being called.
This function does not care if the files are actual files. For compatibility with pipes and socket streams the file location will not be reset to 0 at the end of this function. If the function is successful the file pointers will be at the end of the copied data.
dst | Destination QFile |
src | Source QFile |
block_size | Optional block size in bytes, must be at least 1024, otherwise the default of 16 KB will be used. |
Definition at line 309 of file mythmiscutil.cpp.
Referenced by MythNVDECInterop::Acquire(), TeletextReader::AddPageHeader(), TeletextReader::AddTeletextData(), RTjpeg::bcomp(), GalleryThumbView::Copy(), ImportMusicDialog::copyFile(), mythburn::copyRemote(), ProgramAssociationTable::CreateBlank(), ProgramMapTable::CreateBlank(), MythRAOPConnection::decodeAudioPacket(), mythburn::doProcessFile(), mythburn::doProcessFileProjectX(), MythRenderOpenGL::DrawBitmap(), dvb_decode_text(), NuppelVideoRecorder::FormatTT(), Jitterometer::GetCPUStat(), mythburn::getFileInformation(), ProgramInfoCache::GetOrdered(), MythVAAPIInteropDRM::GetReferenceFrames(), MythVTBSurfaceInterop::GetReferenceFrames(), nv_python_libs.common.common_api.Common::getUrlData(), HLSStream::HLSStream(), TSPacket::InitPayload(), ImportRecorder::Open(), MythBinaryPList::ParseBinaryDate(), MythBinaryPList::ParseBinaryReal(), mythburn::preProcessFile(), ChannelImporter::Process(), MythRAOPConnection::ProcessRequest(), AudioOutputNULL::readOutputData(), MythDVDBuffer::SafeRead(), DiSEqCDevTree::SendCommand(), nv_python_libs.xsltfunctions.traileraddicts_api.xpathFunctions::traileraddictsLinkGenerationMovie(), ThumbFinder::updateThumb(), and NuppelVideoRecorder::WriteFileHeader().
QString createTempFile | ( | QString | name_template, |
bool | dir | ||
) |
Definition at line 369 of file mythmiscutil.cpp.
Referenced by DBUtil::CreateTemporaryDBConf(), and FillData::GrabData().
bool makeFileAccessible | ( | const QString & | filename | ) |
Definition at line 441 of file mythmiscutil.cpp.
Referenced by Content::GetPreviewImage(), and PreviewGenerator::SavePreview().
QString getResponse | ( | const QString & | query, |
const QString & | def | ||
) |
In an interactive shell, prompt the user to input a string.
Definition at line 456 of file mythmiscutil.cpp.
Referenced by intResponse(), ChannelData::promptForChannelUpdates(), MythContextPrivate::PromptForDatabaseParams(), and SchemaUpgradeWizard::PromptForUpgrade().
int intResponse | ( | const QString & | query, |
int | def | ||
) |
In an interactive shell, prompt the user to input a number.
Definition at line 486 of file mythmiscutil.cpp.
Referenced by MythContextPrivate::PromptForDatabaseParams().
QString getSymlinkTarget | ( | const QString & | start_file, |
QStringList * | intermediaries, | ||
unsigned | maxLinks | ||
) |
Definition at line 497 of file mythmiscutil.cpp.
Referenced by CompleteJob(), MainServer::DeleteFile(), ProgramInfo::DiscoverRecordingDirectory(), MythMediaDevice::findMountPath(), MediaMonitor::MediaMonitor(), MythMediaDevice::MythMediaDevice(), and DeleteThread::ProcessNew().
bool IsMACAddress | ( | const QString & | MAC | ) |
Definition at line 549 of file mythmiscutil.cpp.
Referenced by MythWakeup(), and Scheduler::WakeUpSlave().
QString FileHash | ( | const QString & | filename | ) |
Definition at line 594 of file mythmiscutil.cpp.
Referenced by Video::AddVideo(), RemoteFile::GetFileHash(), Content::GetHash(), FileServerHandler::HandleQueryFileHash(), MainServer::HandleQueryFileHash(), UpdateHashes(), and VideoMetadata::VideoFileHash().
bool WakeOnLAN | ( | const QString & | MAC | ) |
Definition at line 635 of file mythmiscutil.cpp.
Referenced by MythWakeup(), and Scheduler::WakeUpSlave().
Definition at line 676 of file mythmiscutil.cpp.
Referenced by MythCoreContext::ConnectCommandSocket(), MSqlDatabase::OpenDatabase(), and MythContextPrivate::TestDBconnection().
bool IsPulseAudioRunning | ( | void | ) |
Is A/V Sync destruction daemon is running on this host?
Definition at line 684 of file mythmiscutil.cpp.
Referenced by AudioOutput::OpenAudio(), and PulseHandler::Suspend().
bool myth_nice | ( | int | val | ) |
Definition at line 702 of file mythmiscutil.cpp.
Referenced by JobQueue::DoTranscodeThread(), JobQueue::DoUserJobThread(), MythSystemLegacyUnix::Fork(), MythPlayer::InitFrameInterval(), main(), and NuppelVideoRecorder::run().
void myth_yield | ( | void | ) |
Definition at line 716 of file mythmiscutil.cpp.
bool myth_ioprio | ( | int | ) |
Allows setting the I/O priority of the current process/thread.
range -1..8, smaller is higher priority
As of November 14th, 2010 this only works on Linux when using the CFQ I/O Scheduler. The range is -1 to 8, with -1 being real-time priority 0 through 7 being standard best-time priorities and 8 being the idle priority. The deadline and noop I/O Schedulers will ignore this but are much less likely to starve video playback to feed the transcoder or flagger. (noop is only recommended for SSDs.)
Since a process needs to have elevated priviledges to use either the real-time or idle priority this will try priorities 0 or 7 respectively if -1 or 8 do not work. It will not report an error on these conditions as they will be the common case.
Only Linux on i386, ppc, x86_64 and ia64 are currently supported. This is a no-op on all other architectures and platforms.
Definition at line 804 of file mythmiscutil.cpp.
Referenced by JobQueue::DoTranscodeThread(), JobQueue::DoUserJobThread(), MythSystemLegacyUnix::Fork(), and main().
bool MythRemoveDirectory | ( | QDir & | aDir | ) |
Definition at line 808 of file mythmiscutil.cpp.
Referenced by NativeArchive::doNativeArchive(), MythBurn::MythBurn(), and MythRemoveDirectory().
void setHttpProxy | ( | void | ) |
Get network proxy settings from OS, and use for [Q]Http[Comms].
The HTTP_PROXY environment var. is parsed for values like; "proxy-host", "proxy-host:8080", "http://host:8080" and "http"//user:password@host:1080", and that is used for any Qt-based Http fetches. We also test connectivity here with ping and telnet, and warn if it fails.
If there is was no env. var, we use Qt to get proxy settings from the OS, and search through them for a proxy server we can connect to.
Definition at line 852 of file mythmiscutil.cpp.
Referenced by main().
void wrapList | ( | QStringList & | list, |
int | width | ||
) |
Definition at line 961 of file mythmiscutil.cpp.
Referenced by CommandLineArg::GetHelpString(), and CommandLineArg::GetLongHelpString().
QString xml_indent | ( | uint | level | ) |
Definition at line 1007 of file mythmiscutil.cpp.
Referenced by VirtualChannelTable::ChannelStringXML(), RecordingQuality::toStringXML(), CarrierDefinitionSubtable::toStringXML(), SpliceDescriptor::toStringXML(), MasterGuideTable::toStringXML(), ModulationModeSubtable::toStringXML(), SCTENetworkInformationTable::toStringXML(), NetworkTextTable::toStringXML(), VirtualChannelTable::toStringXML(), DefinedChannelsMapSubtable::toStringXML(), MPEGDescriptor::toStringXML(), VirtualChannelMapSubtable::toStringXML(), InverseChannelMapSubtable::toStringXML(), ShortVirtualChannelTable::toStringXML(), PSIPTable::toStringXML(), SCTESystemTimeTable::toStringXML(), ProgramAssociationTable::toStringXML(), SystemTimeTable::toStringXML(), ProgramMapTable::toStringXML(), ConditionalAccessTable::toStringXML(), SpliceTimeView::toStringXML(), SpliceInsertView::toStringXML(), SpliceInformationTable::toStringXML(), VirtualChannelTable::XMLChannelValues(), and PSIPTable::XMLValues().
int naturalCompare | ( | const QString & | _a, |
const QString & | _b, | ||
Qt::CaseSensitivity | caseSensitivity | ||
) |
Definition at line 1033 of file mythmiscutil.cpp.
Referenced by comp_sorttitle_lt(), comp_sorttitle_lt_rev(), lt_callsign(), lt_smart(), VideoFilterSettings::meta_less_than(), TitleSort::operator()(), ProgramCountSort::operator()(), ProgramRecCountSort::operator()(), ProgramLastRecordSort::operator()(), ProgramAvgDelaySort::operator()(), plTitleSort::operator()(), plPrevTitleSort::operator()(), SingleValueImp::sort(), metadata_path_sort::sort(), VideoMetadataImp::sortBefore(), Bookmark::sortByName(), and NewsSite::sortByName().
QString MythFormatTimeMs | ( | int | msecs, |
const QString & | fmt | ||
) |
Format a milliseconds time value.
Convert a millisecond time value into a textual representation of the value.
msecs | The time value in milliseconds. |
fmt | A formatting string specifying how to output the time. See QTime::toString for the a definition fo valid formatting characters. |
Definition at line 1233 of file mythmiscutil.cpp.
Referenced by DeleteMap::CreateTimeString(), LyricsLine::formatTime(), commDetector2::frameToTimestamp(), commDetector2::frameToTimestampms(), AvFormatDecoder::OpenFile(), MusicMetadata::toMap(), and MythBDBuffer::UpdateTitleInfo().
QString MythFormatTime | ( | int | secs, |
const QString & | fmt | ||
) |
Format a seconds time value.
Convert a second time value into a textual representation of the value.
secs | The time value in seconds. |
mft | A formatting string specifying how to output the time. See QTime::toString for the a definition fo valid formatting characters. |
Definition at line 1238 of file mythmiscutil.cpp.
Referenced by CommBreakMap::AutoCommercialSkip(), CommBreakMap::DoSkipCommercials(), ThumbFinder::frameToTime(), MusicCommon::getTimeString(), MythBDPlayer::GetTitleName(), TV::MenuItemDisplayPlayback(), TV::ShowLCDDVDInfo(), MythPlayerOverlayUI::UpdateSliderInfo(), and uptimeStr().
QStringList MythSplitCommandString | ( | const QString & | line | ) |
Definition at line 1260 of file mythmiscutil.cpp.
Referenced by MythExternRecApp::Cleanup(), MythExternRecApp::DataStarted(), MythExternRecApp::LoadChannels(), MythExternRecApp::NewEpisodeStarting(), MythExternRecApp::StartStreaming(), and MythExternRecApp::TuneChannel().