MythTV
master
|
#include <algorithm>
#include <cstdint>
#include <ctime>
#include <QString>
#include <QDir>
#include "mythbaseexp.h"
#include "mythsystem.h"
#include "compat.h"
Go to the source code of this file.
Macros | |
#define | M_QSTRING_UNICODE(str) hasUtf8(str) ? QString::fromUtf8(str) : str |
Functions | |
MBASE_PUBLIC bool | getUptime (time_t &uptime) |
Returns uptime statistics. More... | |
MBASE_PUBLIC bool | getMemStats (int &totalMB, int &freeMB, int &totalVM, int &freeVM) |
Returns memory statistics in megabytes. More... | |
MBASE_PUBLIC bool | hasUtf8 (const char *str) |
Guess whether a string is UTF-8. More... | |
MBASE_PUBLIC bool | ping (const QString &host, int timeout) |
Can we ping host within timeout seconds? More... | |
MBASE_PUBLIC bool | telnet (const QString &host, int port) |
Can we talk to port on host? More... | |
MBASE_PUBLIC long long | copy (QFile &dst, QFile &src, uint block_size=0) |
Copies src file to dst file. More... | |
MBASE_PUBLIC QString | createTempFile (QString name_template="/tmp/mythtv_XXXXXX", bool dir=false) |
MBASE_PUBLIC bool | makeFileAccessible (QString filename) |
Makes a file accessible to all frontends/backends. More... | |
MBASE_PUBLIC QString | getResponse (const QString &query, const QString &def) |
In an interactive shell, prompt the user to input a string. More... | |
MBASE_PUBLIC int | intResponse (const QString &query, int def) |
In an interactive shell, prompt the user to input a number. More... | |
MBASE_PUBLIC QString | getSymlinkTarget (const QString &start_file, QStringList *intermediaries=nullptr, unsigned maxLinks=255) |
MBASE_PUBLIC void | wrapList (QStringList &list, int width) |
float | clamp (float val, float minimum, float maximum) |
int | clamp (int val, int minimum, int maximum) |
float | lerp (float r, float a, float b) |
int | lerp (float r, int a, int b) |
float | sq (float a) |
int | sq (int a) |
static QString | xml_bool_to_string (bool val) |
MBASE_PUBLIC QString | xml_indent (uint level) |
MBASE_PUBLIC bool | IsMACAddress (QString MAC) |
MBASE_PUBLIC bool | WakeOnLAN (QString MAC) |
MBASE_PUBLIC bool | MythWakeup (const QString &wakeUpCommand, uint flags=kMSNone, uint timeout=0) |
MBASE_PUBLIC QString | FileHash (QString filename) |
MBASE_PUBLIC bool | IsPulseAudioRunning (void) |
Is A/V Sync destruction daemon is running on this host? More... | |
MBASE_PUBLIC bool | myth_nice (int val) |
MBASE_PUBLIC void | myth_yield (void) |
MBASE_PUBLIC bool | myth_ioprio (int val) |
range -1..8, smaller is higher priority More... | |
MBASE_PUBLIC bool | MythRemoveDirectory (QDir &aDir) |
MBASE_PUBLIC void | setHttpProxy (void) |
Get network proxy settings from OS, and use for [Q]Http[Comms]. More... | |
MBASE_PUBLIC int | naturalCompare (const QString &_a, const QString &_b, Qt::CaseSensitivity caseSensitivity=Qt::CaseSensitive) |
void | rdtsc (uint64_t &x) |
#define M_QSTRING_UNICODE | ( | str | ) | hasUtf8(str) ? QString::fromUtf8(str) : str |
Definition at line 22 of file mythmiscutil.h.
MBASE_PUBLIC bool getUptime | ( | time_t & | uptime | ) |
Returns uptime statistics.
Definition at line 63 of file mythmiscutil.cpp.
Referenced by StatusBox::doMachineStatus(), BaseRequestHandler::HandleQueryUptime(), MainServer::HandleQueryUptime(), and NetworkControl::processQuery().
MBASE_PUBLIC bool getMemStats | ( | int & | totalMB, |
int & | freeMB, | ||
int & | totalVM, | ||
int & | freeVM | ||
) |
Returns memory statistics in megabytes.
Definition at line 110 of file mythmiscutil.cpp.
Referenced by StatusBox::doMachineStatus(), BaseRequestHandler::HandleQueryMemStats(), MainServer::HandleQueryMemStats(), and NetworkControl::processQuery().
MBASE_PUBLIC bool hasUtf8 | ( | const char * | str | ) |
Guess whether a string is UTF-8.
Definition at line 182 of file mythmiscutil.cpp.
MBASE_PUBLIC 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 234 of file mythmiscutil.cpp.
Referenced by setHttpProxy().
MBASE_PUBLIC bool telnet | ( | const QString & | host, |
int | port | ||
) |
Can we talk to port on host?
Definition at line 269 of file mythmiscutil.cpp.
Referenced by setHttpProxy().
MBASE_PUBLIC long long 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 300 of file mythmiscutil.cpp.
Referenced by GalleryThumbView::Copy(), ImportMusicDialog::copyFile(), VideoOutput::CopyFrame(), mythburn::copyRemote(), mythburn::doProcessFile(), mythburn::doProcessFileProjectX(), VideoVisualGoom::Draw(), PrivateDecoderOMX::GetBufferedFrame(), mythburn::getFileInformation(), PrivateDecoderCrystalHD::GetFrame(), nv_python_libs.common.common_api.Common::getUrlData(), HLSStream::HLSStream(), ImportRecorder::Open(), mythburn::preProcessFile(), trail_space(), nv_python_libs.xsltfunctions.traileraddicts_api.xpathFunctions::traileraddictsLinkGenerationMovie(), and ThumbFinder::updateThumb().
MBASE_PUBLIC QString createTempFile | ( | QString | name_template = "/tmp/mythtv_XXXXXX" , |
bool | dir = false |
||
) |
Definition at line 357 of file mythmiscutil.cpp.
Referenced by DataDirectProcessor::CreateTemp(), DBUtil::CreateTemporaryDBConf(), and FillData::GrabData().
MBASE_PUBLIC bool makeFileAccessible | ( | QString | filename | ) |
Makes a file accessible to all frontends/backends.
This function abstracts the functionality of making a file accessible to all frontends and backends. Currently it contains a permissions hack that makes a file accessible even on a system with an improperly configured environment (umask/group) where the frontend and backend are being run as different users or where a NFS share is used but UID's/GID's differ on different hosts.
Though the function currently only changes the file mode to 0666, by abstracting the functionality, it will be easier to make changes in the future if a better approach is chosen. Similarly, using this function allows the hack to be applied only when required if code is written to detect or allow the user to specify their system is misconfigured.
filename | Path of file to make accessible |
Definition at line 429 of file mythmiscutil.cpp.
Referenced by Content::GetPreviewImage(), DataDirectProcessor::SaveLineupToCache(), and PreviewGenerator::SavePreview().
MBASE_PUBLIC QString getResponse | ( | const QString & | query, |
const QString & | def | ||
) |
In an interactive shell, prompt the user to input a string.
Definition at line 444 of file mythmiscutil.cpp.
Referenced by intResponse(), ChannelData::promptForChannelUpdates(), MythContextPrivate::PromptForDatabaseParams(), and SchemaUpgradeWizard::PromptForUpgrade().
MBASE_PUBLIC int intResponse | ( | const QString & | query, |
int | def | ||
) |
In an interactive shell, prompt the user to input a number.
Definition at line 474 of file mythmiscutil.cpp.
Referenced by MythContextPrivate::PromptForDatabaseParams().
MBASE_PUBLIC QString getSymlinkTarget | ( | const QString & | start_file, |
QStringList * | intermediaries = nullptr , |
||
unsigned | maxLinks = 255 |
||
) |
Definition at line 485 of file mythmiscutil.cpp.
Referenced by CompleteJob(), MainServer::DeleteFile(), ProgramInfo::DiscoverRecordingDirectory(), MythMediaDevice::findMountPath(), MediaMonitor::MediaMonitor(), MythMediaDevice::MythMediaDevice(), and DeleteThread::ProcessNew().
MBASE_PUBLIC void wrapList | ( | QStringList & | list, |
int | width | ||
) |
Definition at line 944 of file mythmiscutil.cpp.
Referenced by CommandLineArg::GetHelpString(), and CommandLineArg::GetLongHelpString().
|
inline |
Definition at line 41 of file mythmiscutil.h.
Referenced by ClassicCommDetector::CleanupFrameInfo(), ProgramInfo::LoadProgramFromRecorded(), RecordingInfo::RecordingInfo(), MythPlayer::ToggleNightMode(), RingBuffer::WaitForAvail(), and RingBuffer::WaitForReadsAllowed().
|
inline |
Definition at line 45 of file mythmiscutil.h.
|
inline |
Definition at line 49 of file mythmiscutil.h.
Referenced by lerp().
|
inline |
Definition at line 53 of file mythmiscutil.h.
|
inline |
Definition at line 57 of file mythmiscutil.h.
Referenced by VideoOutWindow::GetVisibleOSDBounds().
|
inline |
Definition at line 58 of file mythmiscutil.h.
|
inlinestatic |
Definition at line 60 of file mythmiscutil.h.
Referenced by ModulationModeSubtable::toStringXML(), DefinedChannelsMapSubtable::toStringXML(), VirtualChannelMapSubtable::toStringXML(), SystemTimeTable::toStringXML(), SpliceInsertView::toStringXML(), VirtualChannelTable::XMLChannelValues(), CableVirtualChannelTable::XMLChannelValues(), and PSIPTable::XMLValues().
MBASE_PUBLIC QString xml_indent | ( | uint | level | ) |
Definition at line 992 of file mythmiscutil.cpp.
Referenced by VirtualChannelTable::ChannelStringXML(), RecordingQuality::toStringXML(), CarrierDefinitionSubtable::toStringXML(), SpliceDescriptor::toStringXML(), MasterGuideTable::toStringXML(), ModulationModeSubtable::toStringXML(), SCTENetworkInformationTable::toStringXML(), MPEGDescriptor::toStringXML(), NetworkTextTable::toStringXML(), VirtualChannelTable::toStringXML(), DefinedChannelsMapSubtable::toStringXML(), VirtualChannelMapSubtable::toStringXML(), InverseChannelMapSubtable::toStringXML(), PSIPTable::toStringXML(), ShortVirtualChannelTable::toStringXML(), SCTESystemTimeTable::toStringXML(), ProgramAssociationTable::toStringXML(), SystemTimeTable::toStringXML(), ProgramMapTable::toStringXML(), ConditionalAccessTable::toStringXML(), SpliceTimeView::toStringXML(), SpliceInsertView::toStringXML(), SpliceInformationTable::toStringXML(), VirtualChannelTable::XMLChannelValues(), and PSIPTable::XMLValues().
MBASE_PUBLIC bool IsMACAddress | ( | QString | MAC | ) |
Definition at line 537 of file mythmiscutil.cpp.
Referenced by MythWakeup(), and Scheduler::WakeUpSlave().
MBASE_PUBLIC bool WakeOnLAN | ( | QString | MAC | ) |
Definition at line 624 of file mythmiscutil.cpp.
Referenced by MythWakeup(), and Scheduler::WakeUpSlave().
MBASE_PUBLIC bool MythWakeup | ( | const QString & | wakeUpCommand, |
uint | flags = kMSNone , |
||
uint | timeout = 0 |
||
) |
Definition at line 666 of file mythmiscutil.cpp.
Referenced by MythCoreContext::ConnectCommandSocket(), MSqlDatabase::OpenDatabase(), and MythContextPrivate::TestDBconnection().
MBASE_PUBLIC QString FileHash | ( | QString | filename | ) |
Definition at line 583 of file mythmiscutil.cpp.
Referenced by Video::AddVideo(), RemoteFile::GetFileHash(), Content::GetHash(), FileServerHandler::HandleQueryFileHash(), MainServer::HandleQueryFileHash(), UpdateHashes(), and VideoMetadata::VideoFileHash().
MBASE_PUBLIC bool IsPulseAudioRunning | ( | void | ) |
Is A/V Sync destruction daemon is running on this host?
Definition at line 674 of file mythmiscutil.cpp.
Referenced by AudioOutput::OpenAudio(), and PulseHandler::Suspend().
MBASE_PUBLIC bool myth_nice | ( | int | val | ) |
Definition at line 692 of file mythmiscutil.cpp.
Referenced by JobQueue::DoTranscodeThread(), JobQueue::DoUserJobThread(), MythSystemLegacyUnix::Fork(), MythPlayer::InitAVSync(), main(), and NuppelVideoRecorder::run().
MBASE_PUBLIC void myth_yield | ( | void | ) |
Definition at line 706 of file mythmiscutil.cpp.
MBASE_PUBLIC bool myth_ioprio | ( | int | ) |
range -1..8, smaller is higher priority
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 794 of file mythmiscutil.cpp.
Referenced by JobQueue::DoTranscodeThread(), JobQueue::DoUserJobThread(), MythSystemLegacyUnix::Fork(), and main().
MBASE_PUBLIC bool MythRemoveDirectory | ( | QDir & | aDir | ) |
Definition at line 798 of file mythmiscutil.cpp.
Referenced by NativeArchive::doNativeArchive(), MythBurn::MythBurn(), and MythRemoveDirectory().
MBASE_PUBLIC 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 842 of file mythmiscutil.cpp.
Referenced by main().
MBASE_PUBLIC int naturalCompare | ( | const QString & | _a, |
const QString & | _b, | ||
Qt::CaseSensitivity | caseSensitivity = Qt::CaseSensitive |
||
) |
Definition at line 1018 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().
|
inline |
Definition at line 93 of file mythmiscutil.h.