| 1 | /* |
| 2 | * Copyright (C) 2014 Canonical Ltd. |
| 3 | * |
| 4 | * Contact: Alberto Mardegan <[email protected]> |
| 5 | * |
| 6 | * This file is part of lomiri-online-accounts-ui and lomiri-online-accounts- |
| 7 | * service |
| 8 | * |
| 9 | * This program is free software: you can redistribute it and/or modify it |
| 10 | * under the terms of the GNU General Public License version 3, as published |
| 11 | * by the Free Software Foundation. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, but |
| 14 | * WITHOUT ANY WARRANTY; without even the implied warranties of |
| 15 | * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR |
| 16 | * PURPOSE. See the GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License along |
| 19 | * with this program. If not, see <http://www.gnu.org/licenses/>. |
| 20 | */ |
| 21 | |
| 22 | #include "ipc.h"cxx . . $ `<file>/online-accounts-common/ipc.h`/ |
| 23 | |
| 24 | #include <QByteArray> |
| 25 | #include <QFile> |
| 26 | #include <QIODevice> |
| 27 | #include <QSocketNotifier> |
| 28 | |
| 29 | using namespace OnlineAccountsUi; |
| 30 | |
| 31 | static const QByteArraycxx . . $ QByteArray# welcomeMessagecxx . . $ welcomeMessage. = "OAUinitIPC"cxx . . $ QByteArray#QByteArray(34d26762b42c433a).; |
| 32 | |
| 33 | namespace OnlineAccountsUicxx . . $ OnlineAccountsUi/ { |
| 34 | |
| 35 | class IpcPrivatecxx . . $ OnlineAccountsUi/IpcPrivate#: public QObjectcxx . . $ QObject# |
| 36 | { |
| 37 | Q_OBJECTcxx . . $ `<external>/1208926524888476972/qobjectdefs.h:170:9`! |
| 38 | Q_DECLARE_PUBLICcxx . . $ `<external>/15045578679651060896/qglobal.h:1172:9`!(Ipc) |
| 39 | |
| 40 | public: |
| 41 | inline IpcPrivatecxx . . $ OnlineAccountsUi/IpcPrivate#IpcPrivate(376c24c72f71a3a1).(Ipccxx . . $ OnlineAccountsUi/Ipc# *ipc); |
| 42 | ~cxx . . $ OnlineAccountsUi/IpcPrivate#`~IpcPrivate`(ced63f7c635d850d).IpcPrivatecxx . . $ OnlineAccountsUi/IpcPrivate#() {}; |
| 43 | |
| 44 | void setChannelscxx . . $ OnlineAccountsUi/IpcPrivate#setChannels(c7a06fe2f8c4cd06).(QIODevicecxx . . $ QIODevice# *readChannel, QIODevicecxx . . $ QIODevice# *writeChannel); |
| 45 | |
| 46 | private Q_SLOTScxx . . $ `<external>/1208926524888476972/qobjectdefs.h:92:10`!: |
| 47 | void onReadyReadcxx . . $ OnlineAccountsUi/IpcPrivate#onReadyRead(49f6e7a06ebc5aa8).(); |
| 48 | |
| 49 | private: |
| 50 | bool waitWelcomeMessagecxx . . $ OnlineAccountsUi/IpcPrivate#waitWelcomeMessage(c9857a73d68e59ba).(); |
| 51 | |
| 52 | private: |
| 53 | QIODevicecxx . . $ QIODevice# *m_readChannelcxx . . $ OnlineAccountsUi/IpcPrivate#m_readChannel.; |
| 54 | QIODevicecxx . . $ QIODevice# *m_writeChannelcxx . . $ OnlineAccountsUi/IpcPrivate#m_writeChannel.; |
| 55 | int m_expectedLengthcxx . . $ OnlineAccountsUi/IpcPrivate#m_expectedLength.; |
| 56 | bool m_gotWelcomeMessagecxx . . $ OnlineAccountsUi/IpcPrivate#m_gotWelcomeMessage.; |
| 57 | QByteArraycxx . . $ QByteArray# m_readBuffercxx . . $ OnlineAccountsUi/IpcPrivate#m_readBuffer.; |
| 58 | mutable Ipccxx . . $ OnlineAccountsUi/Ipc# *q_ptrcxx . . $ OnlineAccountsUi/IpcPrivate#q_ptr.; |
| 59 | }; |
| 60 | |
| 61 | }; // namespace |
| 62 | |
| 63 | IpcPrivatecxx . . $ OnlineAccountsUi/IpcPrivate#::IpcPrivatecxx . . $ OnlineAccountsUi/IpcPrivate#IpcPrivate(376c24c72f71a3a1).(Ipccxx . . $ OnlineAccountsUi/Ipc# *ipc): |
| 64 | QObjectcxx . . $ QObject#QObject(749de1b6ae65bddd).(ipc), |
| 65 | m_readChannelcxx . . $ OnlineAccountsUi/IpcPrivate#m_readChannel.(0), |
| 66 | m_writeChannelcxx . . $ OnlineAccountsUi/IpcPrivate#m_writeChannel.(0), |
| 67 | m_expectedLengthcxx . . $ OnlineAccountsUi/IpcPrivate#m_expectedLength.(0), |
| 68 | m_gotWelcomeMessagecxx . . $ OnlineAccountsUi/IpcPrivate#m_gotWelcomeMessage.(false), |
| 69 | q_ptrcxx . . $ OnlineAccountsUi/IpcPrivate#q_ptr.(ipc) |
| 70 | { |
| 71 | } |
| 72 | |
| 73 | void IpcPrivatecxx . . $ OnlineAccountsUi/IpcPrivate#::setChannelscxx . . $ OnlineAccountsUi/IpcPrivate#setChannels(c7a06fe2f8c4cd06).(QIODevicecxx . . $ QIODevice# *readChannel, QIODevicecxx . . $ QIODevice# *writeChannel) |
| 74 | { |
| 75 | m_readChannelcxx . . $ OnlineAccountsUi/IpcPrivate#m_readChannel. = readChannel; |
| 76 | m_writeChannelcxx . . $ OnlineAccountsUi/IpcPrivate#m_writeChannel. = writeChannel; |
| 77 | QObjectcxx . . $ QObject#::connectcxx . . $ QObject#connect(158df1d9a01a3410).(m_readChannelcxx . . $ OnlineAccountsUi/IpcPrivate#m_readChannel., SIGNALcxx . . $ `<external>/1208926524888476972/qobjectdefs.h:271:10`!(readyRead()), |
| 78 | this, SLOTcxx . . $ `<external>/1208926524888476972/qobjectdefs.h:270:10`!(onReadyRead())); |
| 79 | /* QFile need special handling */ |
| 80 | QFilecxx . . $ QFile# *file = qobject_castcxx . . $ qobject_cast(c988cfc0ca08742e).<QFilecxx . . $ QFile#*>(m_readChannelcxx . . $ OnlineAccountsUi/IpcPrivate#m_readChannel.); |
| 81 | if (file != 0) { |
| 82 | QSocketNotifiercxx . . $ QSocketNotifier# *notifier = new QSocketNotifiercxx . . $ QSocketNotifier#(file->handlecxx . . $ QFileDevice#handle(455f465bc33b4cdf).(), |
| 83 | QSocketNotifiercxx . . $ QSocketNotifier#::Readcxx . . $ QSocketNotifier#Read., |
| 84 | this); |
| 85 | QObjectcxx . . $ QObject#::connectcxx . . $ QObject#connect(158df1d9a01a3410).(notifier, SIGNALcxx . . $ `<external>/1208926524888476972/qobjectdefs.h:271:10`!(activated(int)), |
| 86 | this, SLOTcxx . . $ `<external>/1208926524888476972/qobjectdefs.h:270:10`!(onReadyRead())); |
| 87 | } else { |
| 88 | /* If the read channel is not a QFile, it means it's not the standard |
| 89 | * input, therefore we won't have the need to wait for the welcome |
| 90 | * message. */ |
| 91 | m_gotWelcomeMessagecxx . . $ OnlineAccountsUi/IpcPrivate#m_gotWelcomeMessage. = true; |
| 92 | } |
| 93 | onReadyReadcxx . . $ OnlineAccountsUi/IpcPrivate#onReadyRead(49f6e7a06ebc5aa8).(); |
| 94 | |
| 95 | file = qobject_castcxx . . $ qobject_cast(c988cfc0ca08742e).<QFilecxx . . $ QFile#*>(m_writeChannelcxx . . $ OnlineAccountsUi/IpcPrivate#m_writeChannel.); |
| 96 | if (file != 0) { |
| 97 | m_writeChannelcxx . . $ OnlineAccountsUi/IpcPrivate#m_writeChannel.->writecxx . . $ QIODevice#write(4ee2750a0be83987).(welcomeMessagecxx . . $ welcomeMessage.); |
| 98 | } |
| 99 | } |
| 100 | |
| 101 | void IpcPrivatecxx . . $ OnlineAccountsUi/IpcPrivate#::onReadyReadcxx . . $ OnlineAccountsUi/IpcPrivate#onReadyRead(49f6e7a06ebc5aa8).() |
| 102 | { |
| 103 | Q_Qcxx . . $ `<external>/15045578679651060896/qglobal.h:1178:9`!(Ipc); |
| 104 | |
| 105 | while (true) { |
| 106 | if (m_expectedLengthcxx . . $ OnlineAccountsUi/IpcPrivate#m_expectedLength. == 0) { |
| 107 | /* We are beginning a new read */ |
| 108 | |
| 109 | /* skip all noise */ |
| 110 | if (!waitWelcomeMessagecxx . . $ OnlineAccountsUi/IpcPrivate#waitWelcomeMessage(c9857a73d68e59ba).()) break; |
| 111 | |
| 112 | int length; |
| 113 | int bytesRead = m_readChannelcxx . . $ OnlineAccountsUi/IpcPrivate#m_readChannel.->readcxx . . $ QIODevice#read(2e638bc8ed65be6c).((char *)&length, |
| 114 | sizeof(length)); |
| 115 | if (bytesRead < int(sizeof(length))) break; |
| 116 | m_expectedLengthcxx . . $ OnlineAccountsUi/IpcPrivate#m_expectedLength. = length; |
| 117 | m_readBuffercxx . . $ OnlineAccountsUi/IpcPrivate#m_readBuffer..clearcxx . . $ QByteArray#clear(49f6e7a06ebc5aa8).(); |
| 118 | } |
| 119 | |
| 120 | int neededBytes = m_expectedLengthcxx . . $ OnlineAccountsUi/IpcPrivate#m_expectedLength. - m_readBuffercxx . . $ OnlineAccountsUi/IpcPrivate#m_readBuffer..lengthcxx . . $ QByteArray#length(455f465bc33b4cdf).(); |
| 121 | QByteArraycxx . . $ QByteArray# buffer = m_readChannelcxx . . $ OnlineAccountsUi/IpcPrivate#m_readChannel.->readcxx . . $ QIODevice#read(1117a85f2fd4e5c8).(neededBytes); |
| 122 | m_readBuffercxx . . $ OnlineAccountsUi/IpcPrivate#m_readBuffer. +=cxx . . $ QByteArray#`operator+=`(85c7caed82076bbb). buffer; |
| 123 | if (buffer.lengthcxx . . $ QByteArray#length(455f465bc33b4cdf).() < neededBytes) break; |
| 124 | if (m_readBuffercxx . . $ OnlineAccountsUi/IpcPrivate#m_readBuffer..lengthcxx . . $ QByteArray#length(455f465bc33b4cdf).() == m_expectedLengthcxx . . $ OnlineAccountsUi/IpcPrivate#m_expectedLength.) { |
| 125 | Q_EMITcxx . . $ `<external>/1208926524888476972/qobjectdefs.h:95:10`! q->dataReadycxx . . $ OnlineAccountsUi/Ipc#dataReady(ce30c813b115780d).(m_readBuffercxx . . $ OnlineAccountsUi/IpcPrivate#m_readBuffer.); |
| 126 | m_expectedLengthcxx . . $ OnlineAccountsUi/IpcPrivate#m_expectedLength. = 0; |
| 127 | } |
| 128 | } |
| 129 | } |
| 130 | |
| 131 | bool IpcPrivatecxx . . $ OnlineAccountsUi/IpcPrivate#::waitWelcomeMessagecxx . . $ OnlineAccountsUi/IpcPrivate#waitWelcomeMessage(c9857a73d68e59ba).() |
| 132 | { |
| 133 | if (m_gotWelcomeMessagecxx . . $ OnlineAccountsUi/IpcPrivate#m_gotWelcomeMessage.) return true; |
| 134 | |
| 135 | /* All Qt applications on the Nexus 4 write some dust to stdout when |
| 136 | * starting. So, skip all input until a well-defined welcome message is |
| 137 | * found */ |
| 138 | |
| 139 | QByteArraycxx . . $ QByteArray# buffercxx . . $ QByteArray#QByteArray(ced63f7c635d850d).; |
| 140 | int startCheckIndex = 0; |
| 141 | do { |
| 142 | buffer =cxx . . $ QByteArray#`operator=`(c3d647c78c52d790). m_readChannelcxx . . $ OnlineAccountsUi/IpcPrivate#m_readChannel.->peekcxx . . $ QIODevice#peek(1117a85f2fd4e5c8).(40); |
| 143 | int found = buffer.indexOfcxx . . $ QByteArray#indexOf(50f9d009d9ac8fda).(welcomeMessagecxx . . $ welcomeMessage., startCheckIndex); |
| 144 | int skip = (found >= 0) ? found : buffer.lengthcxx . . $ QByteArray#length(455f465bc33b4cdf).() - welcomeMessagecxx . . $ welcomeMessage..lengthcxx . . $ QByteArray#length(455f465bc33b4cdf).(); |
| 145 | if (found >= 0) { |
| 146 | buffer =cxx . . $ QByteArray#`operator=`(c3d647c78c52d790). m_readChannelcxx . . $ OnlineAccountsUi/IpcPrivate#m_readChannel.->readcxx . . $ QIODevice#read(1117a85f2fd4e5c8).(skip + welcomeMessagecxx . . $ welcomeMessage..lengthcxx . . $ QByteArray#length(455f465bc33b4cdf).()); |
| 147 | m_gotWelcomeMessagecxx . . $ OnlineAccountsUi/IpcPrivate#m_gotWelcomeMessage. = true; |
| 148 | return true; |
| 149 | } |
| 150 | if (skip > 0) { |
| 151 | buffer =cxx . . $ QByteArray#`operator=`(c3d647c78c52d790). m_readChannelcxx . . $ OnlineAccountsUi/IpcPrivate#m_readChannel.->readcxx . . $ QIODevice#read(1117a85f2fd4e5c8).(skip); |
| 152 | } else { |
| 153 | buffer.clearcxx . . $ QByteArray#clear(49f6e7a06ebc5aa8).(); |
| 154 | } |
| 155 | } while (!buffer.isEmptycxx . . $ QByteArray#isEmpty(50ce9a9e25b4a850).()); |
| 156 | |
| 157 | return false; |
| 158 | } |
| 159 | |
| 160 | Ipccxx . . $ OnlineAccountsUi/Ipc#::Ipccxx . . $ OnlineAccountsUi/Ipc#Ipc(749de1b6ae65bddd).(QObjectcxx . . $ QObject# *parent): |
| 161 | QObjectcxx . . $ QObject#QObject(749de1b6ae65bddd).(parent), |
| 162 | d_ptrcxx . . $ OnlineAccountsUi/Ipc#d_ptr.(new IpcPrivatecxx . . $ OnlineAccountsUi/IpcPrivate#IpcPrivate(376c24c72f71a3a1).(this)) |
| 163 | { |
| 164 | } |
| 165 | |
| 166 | Ipccxx . . $ OnlineAccountsUi/Ipc#::~cxx . . $ OnlineAccountsUi/Ipc#`~Ipc`(ced63f7c635d850d).Ipccxx . . $ OnlineAccountsUi/Ipc#() |
| 167 | { |
| 168 | } |
| 169 | |
| 170 | void Ipccxx . . $ OnlineAccountsUi/Ipc#::setChannelscxx . . $ OnlineAccountsUi/Ipc#setChannels(c7a06fe2f8c4cd06).(QIODevicecxx . . $ QIODevice# *readChannel, QIODevicecxx . . $ QIODevice# *writeChannel) |
| 171 | { |
| 172 | Q_Dcxx . . $ `<external>/15045578679651060896/qglobal.h:1177:9`!(Ipc); |
| 173 | d->setChannelscxx . . $ OnlineAccountsUi/IpcPrivate#setChannels(c7a06fe2f8c4cd06).(readChannel, writeChannel); |
| 174 | } |
| 175 | |
| 176 | void Ipccxx . . $ OnlineAccountsUi/Ipc#::writecxx . . $ OnlineAccountsUi/Ipc#write(45672f3c6961a244).(const QByteArraycxx . . $ QByteArray# &data) |
| 177 | { |
| 178 | Q_Dcxx . . $ `<external>/15045578679651060896/qglobal.h:1177:9`!(Ipc); |
| 179 | int length = data.countcxx . . $ QByteArray#count(455f465bc33b4cdf).(); |
| 180 | d->m_writeChannelcxx . . $ OnlineAccountsUi/IpcPrivate#m_writeChannel.->writecxx . . $ QIODevice#write(93d4069f65218ea4).((char *)&length, sizeof(length)); |
| 181 | d->m_writeChannelcxx . . $ OnlineAccountsUi/IpcPrivate#m_writeChannel.->writecxx . . $ QIODevice#write(4ee2750a0be83987).(data); |
| 182 | d->m_writeChannelcxx . . $ OnlineAccountsUi/IpcPrivate#m_writeChannel.->waitForBytesWrittencxx . . $ QIODevice#waitForBytesWritten(83c267b20bac841a).(-1); |
| 183 | } |
| 184 | |
| 185 | #include "ipc.moc"cxx . . $ `<file>/build/online-accounts-service/src/lomiri-online-accounts-service_autogen/include/ipc.moc`/ |