• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2009, Google Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are
6  * met:
7  *
8  *     * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  *     * Redistributions in binary form must reproduce the above
11  * copyright notice, this list of conditions and the following disclaimer
12  * in the documentation and/or other materials provided with the
13  * distribution.
14  *     * Neither the name of Google Inc. nor the names of its
15  * contributors may be used to endorse or promote products derived from
16  * this software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  */
30 
31 #ifndef GenericWorkerTask_h
32 #define GenericWorkerTask_h
33 
34 #if ENABLE(WORKERS)
35 
36 #include "WorkerMessagingProxy.h"
37 #include "ScriptExecutionContext.h"
38 #include <wtf/PassRefPtr.h>
39 
40 namespace WebCore {
41     class GenericWorkerTaskBase : public ScriptExecutionContext::Task {
42     protected:
GenericWorkerTaskBase(WorkerMessagingProxy * messagingProxy)43         GenericWorkerTaskBase(WorkerMessagingProxy* messagingProxy) : m_messagingProxy(messagingProxy)
44         {
45         }
46 
canPerformTask()47         bool canPerformTask()
48         {
49             return !m_messagingProxy->askedToTerminate();
50         }
51 
52         WorkerMessagingProxy* m_messagingProxy;
53     };
54 
55     template<typename P1, typename MP1, typename P2, typename MP2, typename P3, typename MP3, typename P4, typename MP4, typename P5, typename MP5, typename P6, typename MP6>
56     class GenericWorkerTask6 : public GenericWorkerTaskBase {
57     public:
58         typedef void (*Method)(ScriptExecutionContext*, MP1, MP2, MP3, MP4, MP5, MP6);
59         typedef GenericWorkerTask6<P1, MP1, P2, MP2, P3, MP3, P4, MP4, P5, MP5, P6, MP6> GenericWorkerTask;
60 
create(WorkerMessagingProxy * messagingProxy,Method method,const P1 & parameter1,const P2 & parameter2,const P3 & parameter3,const P4 & parameter4,const P5 & parameter5,const P6 & parameter6)61         static PassRefPtr<GenericWorkerTask> create(WorkerMessagingProxy* messagingProxy, Method method, const P1& parameter1, const P2& parameter2, const P3& parameter3, const P4& parameter4, const P5& parameter5, const P6& parameter6)
62         {
63             return adoptRef(new GenericWorkerTask(messagingProxy, method, parameter1, parameter2, parameter3, parameter4, parameter5, parameter6));
64         }
65 
66     private:
GenericWorkerTask6(WorkerMessagingProxy * messagingProxy,Method method,const P1 & parameter1,const P2 & parameter2,const P3 & parameter3,const P4 & parameter4,const P5 & parameter5,const P6 & parameter6)67         GenericWorkerTask6(WorkerMessagingProxy* messagingProxy, Method method, const P1& parameter1, const P2& parameter2, const P3& parameter3, const P4& parameter4, const P5& parameter5, const P6& parameter6)
68             : GenericWorkerTaskBase(messagingProxy)
69             , m_method(method)
70             , m_parameter1(parameter1)
71             , m_parameter2(parameter2)
72             , m_parameter3(parameter3)
73             , m_parameter4(parameter4)
74             , m_parameter5(parameter5)
75             , m_parameter6(parameter6)
76         {
77         }
78 
performTask(ScriptExecutionContext * context)79         virtual void performTask(ScriptExecutionContext* context)
80         {
81             if (!canPerformTask())
82                 return;
83             (*m_method)(context, m_parameter1, m_parameter2, m_parameter3, m_parameter4, m_parameter5, m_parameter6);
84         }
85 
86     private:
87         Method m_method;
88         P1 m_parameter1;
89         P2 m_parameter2;
90         P3 m_parameter3;
91         P4 m_parameter4;
92         P5 m_parameter5;
93         P6 m_parameter6;
94     };
95 
96     template<typename P1, typename MP1, typename P2, typename MP2, typename P3, typename MP3, typename P4, typename MP4, typename P5, typename MP5, typename P6, typename MP6>
createCallbackTask(WorkerMessagingProxy * messagingProxy,void (* method)(ScriptExecutionContext *,MP1,MP2,MP3,MP4,MP5,MP6),const P1 & parameter1,const P2 & parameter2,const P3 & parameter3,const P4 & parameter4,const P5 & parameter5,const P6 & parameter6)97     PassRefPtr<GenericWorkerTask6<P1, MP1, P2, MP2, P3, MP3, P4, MP4, P5, MP5, P6, MP6> > createCallbackTask(
98         WorkerMessagingProxy* messagingProxy,
99         void (*method)(ScriptExecutionContext*, MP1, MP2, MP3, MP4, MP5, MP6),
100         const P1& parameter1, const P2& parameter2, const P3& parameter3, const P4& parameter4, const P5& parameter5, const P6& parameter6)
101     {
102         return GenericWorkerTask6<P1, MP1, P2, MP2, P3, MP3, P4, MP4, P5, MP5, P6, MP6>::create(messagingProxy, method, parameter1, parameter2, parameter3, parameter4, parameter5, parameter6);
103     }
104 
105 } // namespace WebCore
106 
107 #endif // ENABLE(WORKERS)
108 
109 #endif // GenericWorkerTask_h
110