blobiohandler.h
00001 /*
00002  * This file is part of signon
00003  *
00004  * Copyright (C) 2009-2011 Nokia Corporation.
00005  * Copyright (C) 2012-2016 Canonical Ltd.
00006  *
00007  * Contact: Alberto Mardegan <alberto.mardegan@canonical.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     bool isReading() const { return m_isReading; }
00049 
00050 public Q_SLOTS:
00051     void readBlob();
00052 
00053 Q_SIGNALS:
00054     void dataReceived(const QVariantMap &map);
00055     void error();
00056 
00057 private:
00058     void setReadNotificationEnabled(bool enable);
00059 
00060     QByteArray variantMapToByteArray(const QVariantMap &map);
00061     QVariantMap byteArrayToVariantMap(const QByteArray &array);
00062     QVector<QByteArray> pageByteArray(const QByteArray &array);
00063 
00064 public:
00065     QIODevice *m_readChannel;
00066     QIODevice *m_writeChannel;
00067     QByteArray m_blobBuffer;
00068     QSocketNotifier *m_readNotifier;
00069     int m_blobSize;
00070     bool m_isReading;
00071 };
00072 
00073 }
00074 
00075 #endif //BLOBIOHANDLER_H