--- embedaddon/smartmontools/dev_interface.h 2012/02/21 16:32:16 1.1.1.1 +++ embedaddon/smartmontools/dev_interface.h 2012/10/09 09:36:45 1.1.1.2 @@ -3,7 +3,7 @@ * * Home page of code is: http://smartmontools.sourceforge.net * - * Copyright (C) 2008-11 Christian Franke + * Copyright (C) 2008-12 Christian Franke * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -18,20 +18,14 @@ #ifndef DEV_INTERFACE_H #define DEV_INTERFACE_H -#define DEV_INTERFACE_H_CVSID "$Id: dev_interface.h,v 1.1.1.1 2012/02/21 16:32:16 misho Exp $\n" +#define DEV_INTERFACE_H_CVSID "$Id: dev_interface.h,v 1.1.1.2 2012/10/09 09:36:45 misho Exp $\n" +#include "utility.h" + #include #include #include -#if !defined(__GNUC__) && !defined(__attribute__) -#define __attribute__(x) /**/ -#endif - -#ifdef _MSC_VER // Disable MSVC warning -#pragma warning(disable:4250) // 'class1' : inherits 'class2::member' via dominance -#endif - ///////////////////////////////////////////////////////////////////////////// // Common functionality for all device types @@ -153,11 +147,15 @@ class smart_device (public) const char * get_errmsg() const { return m_err.msg.c_str(); } + /// Return true if last error indicates an unsupported system call. + /// Default implementation returns true on ENOSYS and ENOTSUP. + virtual bool is_syscall_unsup() const; + /// Set last error number and message. /// Printf()-like formatting is supported. /// Returns false always to allow use as a return expression. bool set_err(int no, const char * msg, ...) - __attribute__ ((format (printf, 3, 4))); + __attribute_format_printf(3, 4); /// Set last error info struct. bool set_err(const error_info & err) @@ -189,7 +187,7 @@ class smart_device (public) /// Open device with autodetection support. /// May return another device for further access. /// In this case, the original pointer is no longer valid. - /// Default Implementation calls 'open()' and returns 'this'. + /// Default implementation calls 'open()' and returns 'this'. virtual smart_device * autodetect_open(); /////////////////////////////////////////////// @@ -204,14 +202,6 @@ class smart_device (public) virtual void release(const smart_device * dev); protected: - /// Set dynamic downcast for ATA - void this_is_ata(ata_device * ata); - // {see below;} - - /// Set dynamic downcast for SCSI - void this_is_scsi(scsi_device * scsi); - // {see below;} - /// Get interface which produced this object. smart_interface * smi() { return m_intf; } @@ -223,9 +213,14 @@ class smart_device (public) private: smart_interface * m_intf; device_info m_info; + error_info m_err; + + // Pointers for to_ata(), to_scsi(), + // set by ATA/SCSI interface classes. + friend class ata_device; ata_device * m_ata_ptr; + friend class scsi_device; scsi_device * m_scsi_ptr; - error_info m_err; // Prevent copy/assigment smart_device(const smart_device &); @@ -518,10 +513,14 @@ class ata_device (protected) bool multi_sector_support = false, bool ata_48bit_support = false); + /// Hide/unhide ATA interface. + void hide_ata(bool hide = true) + { m_ata_ptr = (!hide ? this : 0); } + /// Default constructor, registers device as ATA. ata_device() : smart_device(never_called) - { this_is_ata(this); } + { hide_ata(false); } }; @@ -540,31 +539,18 @@ class scsi_device (public) virtual bool scsi_pass_through(scsi_cmnd_io * iop) = 0; protected: + /// Hide/unhide SCSI interface. + void hide_scsi(bool hide = true) + { m_scsi_ptr = (!hide ? this : 0); } + /// Default constructor, registers device as SCSI. scsi_device() : smart_device(never_called) - { this_is_scsi(this); } + { hide_scsi(false); } }; ///////////////////////////////////////////////////////////////////////////// - -// Set dynamic downcasts -// Note that due to virtual inheritance, -// (ata == this) does not imply ((void*)ata == (void*)this)) - -inline void smart_device::this_is_ata(ata_device * ata) -{ - m_ata_ptr = (ata == this ? ata : 0); -} - -inline void smart_device::this_is_scsi(scsi_device * scsi) -{ - m_scsi_ptr = (scsi == this ? scsi : 0); -} - - -///////////////////////////////////////////////////////////////////////////// /// Smart pointer class for device pointers template @@ -748,6 +734,19 @@ class smart_interface (public) /// TODO: Remove this hack. virtual std::string get_app_examples(const char * appname); + /// Get microseconds since some unspecified starting point. + /// Used only for command duration measurements in debug outputs. + /// Returns -1 if unsupported. + /// Default implementation uses clock_gettime(), gettimeofday() or ftime(). + virtual int64_t get_timer_usec(); + + /// Disable/Enable system auto standby/sleep mode. + /// Return false if unsupported or if system is running + /// on battery. + /// Default implementation returns false. + virtual bool disable_system_auto_standby(bool disable); + + /////////////////////////////////////////////// // Last error information @@ -763,12 +762,13 @@ class smart_interface (public) /// Set last error number and message. /// Printf()-like formatting is supported. - void set_err(int no, const char * msg, ...) - __attribute__ ((format (printf, 3, 4))); + /// Returns false always to allow use as a return expression. + bool set_err(int no, const char * msg, ...) + __attribute_format_printf(3, 4); /// Set last error info struct. - void set_err(const smart_device::error_info & err) - { m_err = err; } + bool set_err(const smart_device::error_info & err) + { m_err = err; return false; } /// Clear last error info. void clear_err() @@ -776,11 +776,11 @@ class smart_interface (public) /// Set last error number and default message. /// Message is retrieved from get_msg_for_errno(no). - void set_err(int no); + bool set_err(int no); /// Set last error number and default message to any error_info. /// Used by set_err(no). - void set_err_var(smart_device::error_info * err, int no); + bool set_err_var(smart_device::error_info * err, int no); /// Convert error number into message, used by set_err(no). /// Default implementation returns strerror(no).