/*
**
** Copyright 2013, 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_CAMERA_ACTIVITY_CONTROL_H
#define EXYNOS_CAMERA_ACTIVITY_CONTROL_H

#include <cutils/log.h>
#include <utils/threads.h>
#include <utils/RefBase.h>
#include <utils/String8.h>
#include <cutils/properties.h>

#include "ExynosCameraActivityAutofocus.h"
#include "ExynosCameraActivityFlash.h"
#include "ExynosCameraActivitySpecialCapture.h"
#include "ExynosCameraActivityUCTL.h"
#include "ExynosCameraSensorInfoBase.h"
#include "ExynosRect.h"

namespace android{

enum auto_focus_type {
    AUTO_FOCUS_SERVICE      = 0,
    AUTO_FOCUS_HAL,
};

class ExynosCameraActivityControl {
public:

public:
    /* Constructor */
    ExynosCameraActivityControl(int cameraId);

    /* Destructor */
    virtual ~ExynosCameraActivityControl();
    /* Destroy the instance */
    bool            destroy(void);
    /* Check if the instance was created */
    bool            flagCreate(void);
    /* Starts camera auto-focus and registers a callback function to run when the camera is focused. */
    bool            autoFocus(int focusMode, int focusType, bool flagStartFaceDetection, int numOfFace);
    /* Cancel auto-focus operation */
    bool            cancelAutoFocus(void);
    /* Set auto-focus mode */
    void            setAutoFocusMode(int focusMode);
    int             getAutoFocusMode(void);
    /* Set auto-focus area */
    void            setAutoFcousArea(ExynosRect2 rect, int weight);
    /* Sets auto-focus macro position */
    void            setAutoFocusMacroPosition(
                        int oldautoFocusMacroPosition,
                        int autoFocusMacroPosition);
    int             getCAFResult(void);
    /* Check Whether auto-focus running */
    bool            flagFocusing(struct camera2_shot_ext *shot_ext, int focusMode);
    /* Stop auto-focus */
    void            stopAutoFocus(void);
    /* Sets flash mode */
    bool            setFlashMode(int flashMode);
    /* Start pre flash */
    status_t        startPreFlash(int focusMode);
    /* Stop pre flash */
    void            stopPreFlash(void);
    /* Start main flash */
    bool            waitFlashMainReady();

    /* Start main flash */
    int             startMainFlash(void);
    /* Stop main flash */
    void            stopMainFlash(void);
    /* Cancel flash */
    void            cancelFlash(void);
    /* Sets HDR mode */
    void            setHdrMode(bool hdrMode);
#ifdef OIS_CAPTURE
    /* Sets OIS mode */
    void            setOISCaptureMode(bool oisMode);
#endif
    int             getHdrFcount(int index);

    /* Sets FPS Value */
    void            setFpsValue(int fpsValue);
    int             getFpsValue();

    void setHalVersion(int halVersion);

    void            activityBeforeExecFunc(int pipeId, void *args);
    void            activityAfterExecFunc(int pipeId, void *args);
    ExynosCameraActivityFlash *getFlashMgr(void);
    ExynosCameraActivitySpecialCapture *getSpecialCaptureMgr(void);
    ExynosCameraActivityAutofocus *getAutoFocusMgr(void);
    ExynosCameraActivityUCTL *getUCTLMgr(void);

public:
    bool flagAutoFocusRunning;
    bool touchAFMode;
    bool touchAFModeForFlash;

private:
    ExynosCameraActivityAutofocus *m_autofocusMgr;
    ExynosCameraActivityFlash *m_flashMgr;
    ExynosCameraActivitySpecialCapture * m_specialCaptureMgr;
    ExynosCameraActivityUCTL * m_uctlMgr;

    unsigned int m_fpsValue;
    int m_focusMode;

    int  m_halVersion;
};

}

#endif

