/*
 * Copyright (C) 2019 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 specic language governing permissions and
 * limitations under the License.
 */

#ifndef MEDIAPROVIDER_JNI_FUSEDAEMON_H_
#define MEDIAPROVIDER_JNI_FUSEDAEMON_H_

#include <memory>
#include <string>

#include <android-base/unique_fd.h>

#include "MediaProviderWrapper.h"
#include "jni.h"

struct fuse;
namespace mediaprovider {
namespace fuse {
class FuseDaemon final {
  public:
    FuseDaemon(JNIEnv* env, jobject mediaProvider);

    ~FuseDaemon() = default;

    /**
     * Start the FUSE daemon loop that will handle filesystem calls.
     */
    void Start(android::base::unique_fd fd, const std::string& path,
               const std::vector<std::string>& supported_transcoding_relative_paths);

    /**
     * Checks if the FUSE daemon is started.
     */
    bool IsStarted() const;

    /**
     * Check if file should be opened with FUSE
     */
    bool ShouldOpenWithFuse(int fd, bool for_read, const std::string& path);

    /**
     * Invalidate FUSE VFS dentry cache entry for path
     */
    void InvalidateFuseDentryCache(const std::string& path);

    /**
     * Return path of the original media format file for the given file descriptor.
     */
    const std::string GetOriginalMediaFormatFilePath(int fd) const;

    /**
     * Initialize device id for the FUSE daemon with the FUSE device id of the given path.
     */
    void InitializeDeviceId(const std::string& path);

  private:
    FuseDaemon(const FuseDaemon&) = delete;
    void operator=(const FuseDaemon&) = delete;
    MediaProviderWrapper mp;
    std::atomic_bool active;
    struct ::fuse* fuse;
};

}  // namespace fuse
}  // namespace mediaprovider

#endif  // MEDIAPROVIDER_JNI_FUSEDAEMON_H_
