/*
 * Copyright (C) 2017 The Android Open Source Project
 *
 * 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 PERFETTO_PERFETTO_BASE_SCOPED_FILE_H_
#define PERFETTO_PERFETTO_BASE_SCOPED_FILE_H_

#include <dirent.h>
#include <unistd.h>

#include "perfetto_base/logging.h"

namespace perfetto {
namespace base {

// RAII classes for auto-releasing fds and dirs.
template <typename T, int (*CloseFunction)(T), T InvalidValue>
class ScopedResource {
 public:
  explicit ScopedResource(T t = InvalidValue) : t_(t) {}
  ScopedResource(ScopedResource&& other) noexcept {
    t_ = other.t_;
    other.t_ = InvalidValue;
  }
  ScopedResource& operator=(ScopedResource&& other) {
    reset(other.t_);
    other.t_ = InvalidValue;
    return *this;
  }
  T get() const { return t_; }
  T operator*() const { return t_; }
  explicit operator bool() const { return t_ != InvalidValue; }
  void reset(T r = InvalidValue) {
    if (t_ != InvalidValue) {
      int res = CloseFunction(t_);
      PERFETTO_CHECK(res == 0);
    }
    t_ = r;
  }
  ~ScopedResource() { reset(InvalidValue); }

 private:
  ScopedResource(const ScopedResource&) = delete;
  ScopedResource& operator=(const ScopedResource&) = delete;

  T t_;
};

using ScopedFile = ScopedResource<int, close, -1>;
using ScopedDir = ScopedResource<DIR*, closedir, nullptr>;

}  // namespace base
}  // namespace perfetto

#endif  // PERFETTO_PERFETTO_BASE_SCOPED_FILE_H_
