Edric Milaret | fe39094 | 2015-08-04 13:41:03 -0400 | [diff] [blame] | 1 | /*************************************************************************** |
Anthony LĂ©onard | 2fde81d | 2017-04-17 10:06:55 -0400 | [diff] [blame] | 2 | * Copyright (C) 2017 by Savoir-faire Linux * |
Edric Milaret | fe39094 | 2015-08-04 13:41:03 -0400 | [diff] [blame] | 3 | * Author: Edric Ladent Milaret <edric.ladent-milaret@savoirfairelinux.com>* |
| 4 | * * |
| 5 | * This program is free software; you can redistribute it and/or modify * |
| 6 | * it under the terms of the GNU General Public License as published by * |
| 7 | * the Free Software Foundation; either version 3 of the License, or * |
| 8 | * (at your option) any later version. * |
| 9 | * * |
| 10 | * This program is distributed in the hope that it will be useful, * |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
| 13 | * GNU General Public License for more details. * |
| 14 | * * |
| 15 | * You should have received a copy of the GNU General Public License * |
| 16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. * |
| 17 | **************************************************************************/ |
| 18 | |
| 19 | #include "shmclient.h" |
| 20 | |
| 21 | #include <QTextStream> |
| 22 | |
| 23 | ShmClient::ShmClient(QSharedMemory* shm, QSystemSemaphore *sem) : |
| 24 | shm_(shm), |
| 25 | sem_(sem) |
| 26 | { |
| 27 | start(); |
| 28 | } |
| 29 | |
| 30 | void ShmClient::run() |
| 31 | { |
| 32 | while (true) { |
| 33 | |
| 34 | sem_->acquire(); |
| 35 | |
| 36 | shm_->lock(); |
| 37 | |
| 38 | char const *from = (char const*)shm_->data(); |
| 39 | |
| 40 | QString uri = ""; |
| 41 | QTextStream stream(&uri); |
| 42 | |
| 43 | while (from && *from) |
| 44 | { |
| 45 | stream << *from; |
| 46 | ++from; |
| 47 | } |
| 48 | |
| 49 | shm_->unlock(); |
| 50 | |
| 51 | emit RingEvent(uri); |
| 52 | } |
| 53 | } |