2 * Copyright (C) 2010 Apple Inc. All rights reserved.
3 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies)
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
15 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
16 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
18 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
19 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
20 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
22 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
23 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
24 * THE POSSIBILITY OF SUCH DAMAGE.
28 #include "WorkQueue.h"
30 #include <QLocalSocket>
34 #include <wtf/Threading.h>
35 #include "NotImplemented.h"
37 class WorkQueue::WorkItemQt : public QObject {
40 WorkItemQt(WorkQueue* workQueue, WorkItem* workItem)
44 , m_workItem(workItem)
48 WorkItemQt(WorkQueue* workQueue, QObject* source, const char* signal, WorkItem* workItem)
52 , m_workItem(workItem)
54 connect(m_source, m_signal, SLOT(execute()), Qt::QueuedConnection);
64 if (m_queue->m_isValid)
65 m_workItem->execute();
68 virtual void timerEvent(QTimerEvent*)
80 QSocketNotifier* WorkQueue::registerSocketEventHandler(int socketDescriptor, QSocketNotifier::Type type, PassOwnPtr<WorkItem> workItem)
84 QSocketNotifier* notifier = new QSocketNotifier(socketDescriptor, type, 0);
85 notifier->setEnabled(false);
86 notifier->moveToThread(m_workThread);
87 WorkQueue::WorkItemQt* itemQt = new WorkQueue::WorkItemQt(this, notifier, SIGNAL(activated(int)), workItem.leakPtr());
88 itemQt->moveToThread(m_workThread);
89 notifier->setEnabled(true);
93 void WorkQueue::platformInitialize(const char*)
95 m_workThread = new QThread();
96 m_workThread->start();
99 void WorkQueue::platformInvalidate()
101 m_workThread->exit();
102 m_workThread->wait();
104 deleteAllValues(m_signalListeners);
107 void WorkQueue::scheduleWork(PassOwnPtr<WorkItem> item)
109 WorkQueue::WorkItemQt* itemQt = new WorkQueue::WorkItemQt(this, item.leakPtr());
110 itemQt->startTimer(0);
111 itemQt->moveToThread(m_workThread);
114 void WorkQueue::scheduleWorkAfterDelay(PassOwnPtr<WorkItem>, double)
119 void WorkQueue::scheduleWorkOnTermination(WebKit::PlatformProcessIdentifier process, PassOwnPtr<WorkItem> workItem)
121 WorkQueue::WorkItemQt* itemQt = new WorkQueue::WorkItemQt(this, process, SIGNAL(finished(int, QProcess::ExitStatus)), workItem.leakPtr());
122 itemQt->moveToThread(m_workThread);
125 #include "WorkQueueQt.moc"