qthighway/xqserviceutil/src/xqsharablefile.cpp
changeset 24 9d760f716ca8
parent 14 6fbed849b4f4
equal deleted inserted replaced
19:46686fb6258c 24:9d760f716ca8
    21 
    21 
    22 #include "xqservicelog.h"
    22 #include "xqservicelog.h"
    23 #include "xqsharablefile.h"
    23 #include "xqsharablefile.h"
    24 #include <QVariant>
    24 #include <QVariant>
    25 
    25 
    26 
    26 /*!
       
    27     \class XQSharableFile
       
    28     \inpublicgroup QtBaseModule
       
    29 
       
    30     \ingroup ipc
       
    31     \brief Encapsulates needed functionality to pass one Symbian data-caged file handle to service provider.
       
    32 */
       
    33 
       
    34 /*!
       
    35     Constructor.
       
    36 */
    27 XQSharableFile::XQSharableFile() :
    37 XQSharableFile::XQSharableFile() :
    28    mHandle(0)
    38    mHandle(0)
    29 {
    39 {
    30     XQSERVICE_DEBUG_PRINT("XQSharableFile::XQSharableFile");
    40     XQSERVICE_DEBUG_PRINT("XQSharableFile::XQSharableFile");
    31 }
    41 }
    32 
    42 
       
    43 /*!
       
    44     Constructor.
       
    45     \param file Existing and valid file handle to be set to this XQSharableFile.
       
    46 */
    33 XQSharableFile::XQSharableFile(RFile &file)
    47 XQSharableFile::XQSharableFile(RFile &file)
    34 {
    48 {
    35     XQSERVICE_DEBUG_PRINT("XQSharableFile::XQSharableFile(RFile)");
    49     XQSERVICE_DEBUG_PRINT("XQSharableFile::XQSharableFile(RFile)");
    36     setHandle(file);
    50     setHandle(file);
    37 }
    51 }
    38 
    52 
       
    53 /*!
       
    54     Destroys the descriptor.
       
    55 
       
    56     \b Note!
       
    57     The destructor does not close the file handle. 
       
    58     You have to close it via the close() method.
       
    59 */
    39 XQSharableFile::~XQSharableFile()
    60 XQSharableFile::~XQSharableFile()
    40 {
    61 {
    41     XQSERVICE_DEBUG_PRINT("XQSharableFile::~XQSharableFile");
    62     XQSERVICE_DEBUG_PRINT("XQSharableFile::~XQSharableFile");
    42     // One need to call close() explicitelly when all done
    63     // One need to call close() explicitelly when all done
    43 }
    64 }
    44 
    65 
    45 
    66 /*!
       
    67     Sets the existing and valid sharable file. Use this
       
    68     function if you obtained the handle from the other APIs.
       
    69     \return True if the handle is valid and can be set, 
       
    70             false otherwise.
       
    71 */
    46 bool XQSharableFile::setHandle(RFile &file)
    72 bool XQSharableFile::setHandle(RFile &file)
    47 {
    73 {
    48     XQSERVICE_DEBUG_PRINT("XQSharableFile::setHandle");
    74     XQSERVICE_DEBUG_PRINT("XQSharableFile::setHandle");
    49     
    75     
    50     TFileName name;
    76     TFileName name;
    63     XQSERVICE_DEBUG_PRINT("%s", qPrintable(s));
    89     XQSERVICE_DEBUG_PRINT("%s", qPrintable(s));
    64 
    90 
    65     return true;
    91     return true;
    66 }
    92 }
    67 
    93 
       
    94 /*!
       
    95     Gets the set handle, if any.
       
    96     \param handle Reference to handle to be set with
       
    97                   this XQSharableFile's handle.
       
    98     \return True if the handle is valid, false otherwise.
       
    99 */
    68 bool XQSharableFile::getHandle(RFile &handle) const
   100 bool XQSharableFile::getHandle(RFile &handle) const
    69 {
   101 {
    70     XQSERVICE_DEBUG_PRINT("XQSharableFile::getHandle");
   102     XQSERVICE_DEBUG_PRINT("XQSharableFile::getHandle");
    71     QString s = QString("File handle is %1").arg(mHandle);
   103     QString s = QString("File handle is %1").arg(mHandle);
    72     if (mHandle == 0)
   104     if (mHandle == 0)
    73         return false;
   105         return false;
    74     handle = *((RFile *)&mHandle);
   106     handle = *((RFile *)&mHandle);
    75     return true;
   107     return true;
    76 }
   108 }
    77 
   109 
    78 
   110 /*!
       
   111     Get file name associated with this XQSharableFile.
       
   112     \return Full file name associated with this XQSharableFile.
       
   113 */
    79 QString XQSharableFile::fileName() const
   114 QString XQSharableFile::fileName() const
    80 {
   115 {
    81     XQSERVICE_DEBUG_PRINT("XQSharableFile::fileName");
   116     XQSERVICE_DEBUG_PRINT("XQSharableFile::fileName");
    82     return mFileName;
   117     return mFileName;
    83 }
   118 }
    84 
   119 
       
   120 /*!
       
   121     Checks if this XQSharableFile is valid, that is if the associated
       
   122     file handle is valid.
       
   123     \return True if file handle of this XQSharableFile is valid,
       
   124             false otherwise.
       
   125 */
    85 bool XQSharableFile::isValid() const
   126 bool XQSharableFile::isValid() const
    86 {
   127 {
    87     XQSERVICE_DEBUG_PRINT("XQSharableFile::isValid=%d", mHandle != 0);
   128     XQSERVICE_DEBUG_PRINT("XQSharableFile::isValid=%d", mHandle != 0);
    88     return mHandle != 0;
   129     return mHandle != 0;
    89 }
   130 }
    90 
   131 
       
   132 /*!
       
   133     Creates and sets the sharable file handle of the given file.
       
   134     The file can be private, data-caged directory.
       
   135     Currently only supported access mode is R/O.
       
   136     \b Note! After opening the file, it should be closed by calling close().
       
   137     \param fileName File to be opened.
       
   138     \return True if the file name was ok and the file was opened successfuly,
       
   139             false otherwise.
       
   140 */
    91 bool XQSharableFile::open(const QString &fileName)
   141 bool XQSharableFile::open(const QString &fileName)
    92 {
   142 {
    93     close();   // Close possibly existing old one
   143     close();   // Close possibly existing old one
    94 
   144 
    95     QString symbianFileName = fileName;
   145     QString symbianFileName = fileName;
   114 
   164 
   115     this->setHandle(f);
   165     this->setHandle(f);
   116     return true;
   166     return true;
   117 }
   167 }
   118 
   168 
       
   169 /*!
       
   170     Close the sharable file handle.
       
   171     <b>It is very important to close the handle if it is no longer needed.</b>
       
   172 */
   119 void XQSharableFile::close()
   173 void XQSharableFile::close()
   120 {
   174 {
   121     XQSERVICE_DEBUG_PRINT("XQSharableFile::close");
   175     XQSERVICE_DEBUG_PRINT("XQSharableFile::close");
   122     RFile f;
   176     RFile f;
   123     if (getHandle(f))
   177     if (getHandle(f))
   130         mSharableFS.Close();
   184         mSharableFS.Close();
   131     }
   185     }
   132     
   186     
   133 }
   187 }
   134 
   188 
   135 
   189 /*!
       
   190     Serializes XQSharableFile into a stream.
       
   191     \param s Stream to which this XQSharableFile will be serialized.
       
   192 */
   136 template <typename Stream> void XQSharableFile::serialize(Stream &s) const
   193 template <typename Stream> void XQSharableFile::serialize(Stream &s) const
   137 {
   194 {
   138     XQSERVICE_DEBUG_PRINT("XQSharableFile::serialize");
   195     XQSERVICE_DEBUG_PRINT("XQSharableFile::serialize");
   139     s << mFileName;
   196     s << mFileName;
   140     s << mHandle;
   197     s << mHandle;
   141     QString str = QString("\tFile handle is %1").arg(mHandle);
   198     QString str = QString("\tFile handle is %1").arg(mHandle);
   142     XQSERVICE_DEBUG_PRINT("%s", qPrintable(str));
   199     XQSERVICE_DEBUG_PRINT("%s", qPrintable(str));
   143 }
   200 }
   144 
   201 
       
   202 /*!
       
   203     Deserializes XQSharableFile from a stream.
       
   204     \param s Stream from which XQSharableFile will be deserialized.
       
   205 */
   145 template <typename Stream> void XQSharableFile::deserialize(Stream &s)
   206 template <typename Stream> void XQSharableFile::deserialize(Stream &s)
   146 {
   207 {
   147     XQSERVICE_DEBUG_PRINT("XQSharableFile::deserialize");
   208     XQSERVICE_DEBUG_PRINT("XQSharableFile::deserialize");
   148     
   209     
   149     s >> mFileName;
   210     s >> mFileName;
   152     QString str = QString("\tFile handle is %1").arg(mHandle);
   213     QString str = QString("\tFile handle is %1").arg(mHandle);
   153     XQSERVICE_DEBUG_PRINT("%s", qPrintable(str));
   214     XQSERVICE_DEBUG_PRINT("%s", qPrintable(str));
   154     
   215     
   155 }
   216 }
   156 
   217 
       
   218 /*!
       
   219     Compares two XQSharableFile objects.
       
   220     \return True if both XQSharableFile objects are equal, false otherwise.
       
   221 */
   157 bool XQSharableFile::operator==( const XQSharableFile &other )
   222 bool XQSharableFile::operator==( const XQSharableFile &other )
   158 {
   223 {
   159     return (mFileName == other.mFileName) && (mHandle == other.mHandle);
   224     return (mFileName == other.mFileName) && (mHandle == other.mHandle);
   160 }
   225 }
   161 
   226