blobiohandler.h

00001 /*
00002  * This file is part of signon
00003  *
00004  * Copyright (C) 2009-2011 Nokia Corporation.
00005  *
00006  * Contact: Aurel Popirtac <ext-aurel.popirtac@nokia.com>
00007  * Contact: Alberto Mardegan <alberto.mardegan@nokia.com>
00008  *
00009  * This library is free software; you can redistribute it and/or
00010  * modify it under the terms of the GNU Lesser General Public License
00011  * version 2.1 as published by the Free Software Foundation.
00012  *
00013  * This library is distributed in the hope that it will be useful, but
00014  * WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00016  * Lesser General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU Lesser General Public
00019  * License along with this library; if not, write to the Free Software
00020  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
00021  * 02110-1301 USA
00022  */
00023 
00024 #ifndef BLOBIOHANDLER_H
00025 #define BLOBIOHANDLER_H
00026 
00027 #include <QObject>
00028 #include <QIODevice>
00029 #include <QVariantMap>
00030 #include <QSocketNotifier>
00031 
00032 namespace SignOn {
00033 
00034 class BlobIOHandler : public QObject
00035 {
00036     Q_OBJECT
00037 
00038 public:
00039     BlobIOHandler(QIODevice *inputChannel,
00040                   QIODevice *outputChannel,
00041                   QObject *parent = 0);
00042     //sync call
00043     bool sendData(const QVariantMap &map);
00044     //async call
00045     void receiveData(int expectedDataSize);
00046 
00047     void setReadChannelSocketNotifier(QSocketNotifier *notifier);
00048 
00049 public Q_SLOTS:
00050     void readBlob();
00051 
00052 Q_SIGNALS:
00053     void dataReceived(const QVariantMap &map);
00054     void error();
00055 
00056 private:
00057     void setReadNotificationEnabled(bool enable);
00058 
00059     QByteArray variantMapToByteArray(const QVariantMap &map);
00060     QVariantMap byteArrayToVariantMap(const QByteArray &array);
00061     QVector<QByteArray> pageByteArray(const QByteArray &array);
00062 
00063 public:
00064     QIODevice *m_readChannel;
00065     QIODevice *m_writeChannel;
00066     QByteArray m_blobBuffer;
00067     QSocketNotifier *m_readNotifier;
00068     int m_blobSize;
00069 };
00070 
00071 }
00072 
00073 #endif //BLOBIOHANDLER_H