MythTV  0.26-pre
mythhdd.cpp
Go to the documentation of this file.
00001 #include "mythhdd.h"
00002 #include "mythlogging.h"
00003 
00011 MythHDD *MythHDD::Get(QObject* par, const char* devicePath, bool SuperMount,
00012                       bool AllowEject)
00013 {
00014     return new MythHDD(par, devicePath, SuperMount, AllowEject);
00015 }
00016 
00022 MythHDD::MythHDD(QObject *par, const char *DevicePath,
00023                  bool SuperMount, bool AllowEject)
00024     : MythMediaDevice(par, DevicePath, SuperMount, AllowEject)
00025 {
00026     LOG(VB_MEDIA, LOG_INFO, "MythHDD::MythHDD " + m_DevicePath);
00027     m_Status = MEDIASTAT_NOTMOUNTED;
00028     m_MediaType = MEDIATYPE_DATA;       // default type is data
00029 }
00030 
00034 MythMediaStatus MythHDD::checkMedia(void)
00035 {
00036     if (m_Status == MEDIASTAT_ERROR)
00037         return m_Status;
00038 
00039     if (isMounted())
00040     {
00041         // A lazy way to present volume name for the user to eject.
00042         // Hotplug devices are usually something like /media/VOLUME
00043         m_VolumeID = m_MountPath;
00044 
00045         // device is mounted, trigger event
00046         if (m_Status != MEDIASTAT_MOUNTED)
00047             m_Status = MEDIASTAT_NOTMOUNTED;
00048 
00049         return setStatus(MEDIASTAT_MOUNTED);
00050     }
00051 
00052     // device is not mounted
00053     switch (m_Status)
00054     {
00055         case MEDIASTAT_NOTMOUNTED:
00056             // a removable device was just plugged in try to mount it.
00057             LOG(VB_MEDIA, LOG_INFO, "MythHDD::checkMedia try mounting " +
00058                 m_DevicePath);
00059 
00060             if (mount())
00061                 return setStatus(MEDIASTAT_MOUNTED);
00062 
00063             return setStatus(MEDIASTAT_ERROR);
00064 
00065         case MEDIASTAT_MOUNTED:
00066             // device was mounted and someone unmounted it.
00067             return setStatus(MEDIASTAT_NOTMOUNTED);
00068 
00069         default:
00070             // leave device state as is
00071             return m_Status;
00072     }
00073 }
00074 
00075 //virtual
00076 MythMediaError MythHDD::eject(bool)
00077 {
00078     setStatus(MEDIASTAT_UNPLUGGED);
00079     return MEDIAERR_UNSUPPORTED;
00080 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends