Program Listing for File model_repository.hpp

Return to documentation for file (/workspace/amdinfer/src/amdinfer/core/model_repository.hpp)

// Copyright 2022 Xilinx, Inc.
// Copyright 2022 Advanced Micro Devices, Inc.
//
// 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 GUARD_AMDINFER_CORE_MODEL_REPOSITORY
#define GUARD_AMDINFER_CORE_MODEL_REPOSITORY

#include <efsw/efsw.hpp>  // for FileWatcher, Action, FileWatchListener, Wat...
#include <filesystem>     // for path
#include <memory>         // for unique_ptr
#include <string>         // for string

namespace amdinfer {

class RequestParameters;

class UpdateListener : public efsw::FileWatchListener {
 public:
  void handleFileAction(efsw::WatchID watchid, const std::string& dir,
                        const std::string& filename, efsw::Action action,
                        std::string old_filename) override;
};

class ModelRepository {
 public:
  static void modelLoad(const std::string& model,
                        RequestParameters* parameters);

  static void setRepository(const std::string& repository);
  static void enableRepositoryMonitoring(bool use_polling);

 private:
  class ModelRepositoryImpl {
   public:
    void modelLoad(const std::string& model,
                   RequestParameters* parameters) const;

    void setRepository(const std::string& repository);

    void enableRepositoryMonitoring(bool use_polling);

   private:
    std::filesystem::path repository_;
    std::unique_ptr<efsw::FileWatcher> file_watcher_;
    std::unique_ptr<UpdateListener> listener_;
  };

  inline static ModelRepositoryImpl repo_;
};

}  // namespace amdinfer

#endif  // GUARD_AMDINFER_CORE_MODEL_REPOSITORY