Task.h revision ded1d3c45be0307b175bd0cace12749e39814b84
1/*
2 * Copyright (C) 2013 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef ANDROID_HWUI_TASK_H
18#define ANDROID_HWUI_TASK_H
19
20#include <utils/RefBase.h>
21#include <utils/Trace.h>
22
23#include "Future.h"
24
25namespace android {
26namespace uirenderer {
27
28class TaskBase: public RefBase {
29public:
30    TaskBase() { }
31    virtual ~TaskBase() { }
32};
33
34template<typename T>
35class Task: public TaskBase {
36public:
37    Task(): mFuture(new Future<T>()) { }
38    virtual ~Task() { }
39
40    T getResult() const {
41        return mFuture->get();
42    }
43
44    void setResult(T result) {
45        mFuture->produce(result);
46    }
47
48protected:
49    const sp<Future<T> >& future() const {
50        return mFuture;
51    }
52
53private:
54    sp<Future<T> > mFuture;
55};
56
57}; // namespace uirenderer
58}; // namespace android
59
60#endif // ANDROID_HWUI_TASK_H
61