#ifndef VENDOR_SAMSUNG_SECURITY_DRK_LOCKGUARD_H
#define VENDOR_SAMSUNG_SECURITY_DRK_LOCKGUARD_H

#include <stdint.h>
#include <mutex>
#include <time.h>
#include "systemConfig.h"

namespace vendor   {
namespace samsung  {
namespace hardware {
namespace security {
namespace drk      {

#define MAX_LOCK    2
#define DRK_LOCK    0
#define ETC_LOCK    1

using namespace std;

class LockGuard
{
private:
    static time_t         mStart;
    static time_t         mEnd;
    static timed_mutex    mLock[MAX_LOCK];
    uint32_t              mPrevpid;
    uint32_t              mPrevcmd;
    uint32_t              mTimeOut;

private:
    bool     lock(uint32_t idx);
    void     unlock(uint32_t idx);
    void     startTimer();
    bool     checkTimer();

public:
    LockGuard();
    LockGuard(uint32_t timeline);
    ~LockGuard();

    int32_t  setTimeout(uint32_t into);
    int32_t  Enter(uint32_t cmd, uint32_t pid);
    void     Leave(uint32_t cmd, int32_t ret);
    void     Clear();
};

}  // namespace drk
}  // namespace security
}  // namespace hardware
}  // namespace samsung
}  // namespace vendor

#endif
