diff --git a/private/qtjolie-branch/includes/CMakeLists.txt b/private/qtjolie-branch/includes/CMakeLists.txt index 01e371bf9..d275299dc 100644 --- a/private/qtjolie-branch/includes/CMakeLists.txt +++ b/private/qtjolie-branch/includes/CMakeLists.txt @@ -4,5 +4,6 @@ install( FILES QtJolie/Message QtJolie/MetaService QtJolie/PendingCall + QtJolie/PendingCallWatcher QtJolie/Value DESTINATION ${INCLUDE_INSTALL_DIR}/QtJolie COMPONENT Devel) diff --git a/private/qtjolie-branch/includes/QtJolie/PendingCallWatcher b/private/qtjolie-branch/includes/QtJolie/PendingCallWatcher new file mode 100644 index 000000000..518acc9cc --- /dev/null +++ b/private/qtjolie-branch/includes/QtJolie/PendingCallWatcher @@ -0,0 +1,2 @@ +#include "../qtjolie/pendingcallwatcher.h" + diff --git a/private/qtjolie-branch/qtjolie/CMakeLists.txt b/private/qtjolie-branch/qtjolie/CMakeLists.txt index f516d65b6..cb1520049 100644 --- a/private/qtjolie-branch/qtjolie/CMakeLists.txt +++ b/private/qtjolie-branch/qtjolie/CMakeLists.txt @@ -5,7 +5,16 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR} ${QT_INCLUDE_DIR}) -set(qtjolie_LIB_SRCS client.cpp clientthread.cpp value.cpp fault.cpp message.cpp metaservice.cpp pendingcall.cpp) +set(qtjolie_LIB_SRCS + client.cpp + clientthread.cpp + value.cpp + fault.cpp + message.cpp + metaservice.cpp + pendingcall.cpp + pendingcallwatcher.cpp +) kde4_add_library(QtJolie SHARED ${qtjolie_LIB_SRCS}) @@ -23,4 +32,5 @@ install(FILES message.h metaservice.h pendingcall.h + pendingcallwatcher.h DESTINATION ${INCLUDE_INSTALL_DIR}/qtjolie) diff --git a/private/qtjolie-branch/qtjolie/client.cpp b/private/qtjolie-branch/qtjolie/client.cpp index c2b7b41ce..89316ae0e 100644 --- a/private/qtjolie-branch/qtjolie/client.cpp +++ b/private/qtjolie-branch/qtjolie/client.cpp @@ -24,6 +24,7 @@ #include "clientthread_p.h" #include "message.h" #include "pendingcall.h" +#include "pendingcallwatcher.h" using namespace Jolie; @@ -60,7 +61,7 @@ PendingCall Client::asyncCall(const Message &message) Message Client::call(const Message &message) { - PendingCall pending = asyncCall(message); + PendingCallWatcher pending(asyncCall(message)); pending.waitForFinished(); return pending.reply(); } diff --git a/private/qtjolie-branch/qtjolie/pendingcall.cpp b/private/qtjolie-branch/qtjolie/pendingcall.cpp index 516d53279..112c52952 100644 --- a/private/qtjolie-branch/qtjolie/pendingcall.cpp +++ b/private/qtjolie-branch/qtjolie/pendingcall.cpp @@ -1,6 +1,6 @@ /** * This file is part of the KDE project - * Copyright (C) 2008 Kevin Ottens + * Copyright (C) 2009 Kevin Ottens * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -20,6 +20,7 @@ #include "pendingcall.h" #include "pendingcall_p.h" +#include "pendingcallwatcher.h" using namespace Jolie; @@ -44,22 +45,6 @@ PendingCall &PendingCall::operator=(const PendingCall &other) return *this; } -bool PendingCall::isFinished() const -{ - return d->isFinished; -} - -Message PendingCall::reply() const -{ - return d->reply; -} - -void PendingCall::waitForFinished() -{ - PendingCallWaiter waiter; - waiter.waitForFinished(d.data()); -} - void PendingCallPrivate::setReply(const Message &message) { Q_ASSERT(message.id()==id); @@ -69,8 +54,12 @@ void PendingCallPrivate::setReply(const Message &message) foreach (PendingCallWaiter *waiter, waiters) { waiter->eventLoop.quit(); } - waiters.clear(); + + foreach (PendingCallWatcher *watcher, watchers) { + emit watcher->finished(watcher); + } + watchers.clear(); } void PendingCallWaiter::waitForFinished(PendingCallPrivate *pendingCall) diff --git a/private/qtjolie-branch/qtjolie/pendingcall.h b/private/qtjolie-branch/qtjolie/pendingcall.h index 864eaa3b3..c6908c917 100644 --- a/private/qtjolie-branch/qtjolie/pendingcall.h +++ b/private/qtjolie-branch/qtjolie/pendingcall.h @@ -1,6 +1,6 @@ /** * This file is part of the KDE project - * Copyright (C) 2008 Kevin Ottens + * Copyright (C) 2009 Kevin Ottens * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -37,13 +37,9 @@ public: PendingCall &operator=(const PendingCall &other); - bool isFinished() const; - Message reply() const; - - void waitForFinished(); - private: friend class Client; + friend class PendingCallWatcher; PendingCall(); // Not defined PendingCall(QExplicitlySharedDataPointer dd); diff --git a/private/qtjolie-branch/qtjolie/pendingcall_p.h b/private/qtjolie-branch/qtjolie/pendingcall_p.h index 15e90ab23..6e59bdf8e 100644 --- a/private/qtjolie-branch/qtjolie/pendingcall_p.h +++ b/private/qtjolie-branch/qtjolie/pendingcall_p.h @@ -1,6 +1,6 @@ /** * This file is part of the KDE project - * Copyright (C) 2008 Kevin Ottens + * Copyright (C) 2009 Kevin Ottens * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -31,6 +31,7 @@ namespace Jolie { class PendingCallPrivate; +class PendingCallWatcher; class PendingCallWaiter { @@ -52,12 +53,14 @@ public: private: friend class PendingCall; + friend class PendingCallWatcher; friend class PendingCallWaiter; qint64 id; bool isFinished; Message reply; QList waiters; + QList watchers; }; } // namespace Jolie diff --git a/private/qtjolie-branch/qtjolie/pendingcallwatcher.cpp b/private/qtjolie-branch/qtjolie/pendingcallwatcher.cpp new file mode 100644 index 000000000..221f90eb3 --- /dev/null +++ b/private/qtjolie-branch/qtjolie/pendingcallwatcher.cpp @@ -0,0 +1,53 @@ +/** + * This file is part of the KDE project + * Copyright (C) 2008 Kevin Ottens + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "pendingcallwatcher.h" + +#include "pendingcall_p.h" + +using namespace Jolie; + +PendingCallWatcher::PendingCallWatcher(const PendingCall &other, QObject *parent) + : QObject(parent), PendingCall(other.d) +{ + d->watchers << this; +} + +PendingCallWatcher::~PendingCallWatcher() +{ + d->watchers.removeAll(this); +} + +bool PendingCallWatcher::isFinished() const +{ + return d->isFinished; +} + +Message PendingCallWatcher::reply() const +{ + return d->reply; +} + +void PendingCallWatcher::waitForFinished() +{ + PendingCallWaiter waiter; + waiter.waitForFinished(d.data()); +} + diff --git a/private/qtjolie-branch/qtjolie/pendingcallwatcher.h b/private/qtjolie-branch/qtjolie/pendingcallwatcher.h new file mode 100644 index 000000000..0f714c7ed --- /dev/null +++ b/private/qtjolie-branch/qtjolie/pendingcallwatcher.h @@ -0,0 +1,54 @@ +/** + * This file is part of the KDE project + * Copyright (C) 2008 Kevin Ottens + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef QTJOLIE_PENDINGCALLWATCHER_H +#define QTJOLIE_PENDINGCALLWATCHER_H + +#include + +#include + +namespace Jolie +{ +class Q_DECL_EXPORT PendingCallWatcher : public QObject, public PendingCall +{ + Q_OBJECT +public: + PendingCallWatcher(const PendingCall &call, QObject *parent=0); + ~PendingCallWatcher(); + + bool isFinished() const; + Message reply() const; + + void waitForFinished(); + +Q_SIGNALS: + void finished(Jolie::PendingCallWatcher *self); + +private: + friend class PendingCallPrivate; + + PendingCallWatcher(); // Not defined +}; + +} // namespace Jolie + +#endif +