/*
 * Copyright (C) 2015, Samsung Electronics Co. LTD
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef EXYNOS_VISION_THREAD_H
#define EXYNOS_VISION_THREAD_H

#include <utils/threads.h>

namespace android {

template<typename T>
class ExynosVisionThread : public Thread {

typedef bool (T::*thread_loop)(void);
public:
    ExynosVisionThread(
        T *hw,
        thread_loop loop,
        const char *name,
        int32_t priority = PRIORITY_DEFAULT)
    {
        m_hardware   = hw;
        m_threadLoop = loop;
        m_name       = name;
        m_priority   = priority;
        m_flatStart  = false;
    }

    virtual ~ExynosVisionThread()
    {
    }

    virtual status_t readyToRun() {
        m_flatStart = true;

        return Thread::readyToRun();
    }

    virtual status_t setup(
        T *hw,
        thread_loop loop,
        const char *name,
        int32_t priority = PRIORITY_DEFAULT)
    {
        m_hardware   = hw;
        m_threadLoop = loop;
        m_name       = name;
        m_priority   = priority;
        return NO_ERROR;
    }

    virtual status_t run(void) {

        ALOGV("DEBUG(%s):Thread(%s) start running", __FUNCTION__, m_name);

        return Thread::run(m_name, m_priority, 0);
    }

    virtual status_t run(int32_t priority, size_t stack = 0) {

        ALOGV("DEBUG(%s):Thread(%s) start running", __FUNCTION__, m_name);
        if (m_priority != priority)
            m_priority = priority;

        return Thread::run(m_name, m_priority, stack);
    }

    virtual void stop(void) {
        m_flatStart = false;
        requestExit();
    }

    bool        visionThreadExitPending() const
    {
        return exitPending();
    }

private:
    virtual bool threadLoop() {
        bool ret = (m_hardware->*m_threadLoop)();

        if (m_flatStart == false)
            ret = m_flatStart;

        return ret;
    }

private:
    T           *m_hardware;
    const char  *m_name;
    thread_loop m_threadLoop;
    int32_t     m_priority;
    bool        m_flatStart;
};

}; // namespace android
#endif
