object-introspection/oi/OICache.h
2023-07-26 18:01:38 +01:00

77 lines
2.1 KiB
C++

/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* 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.
*/
#pragma once
#include <array>
#include <filesystem>
#include <memory>
#include <optional>
#include "oi/OICodeGen.h"
#include "oi/OIParser.h"
#include "oi/SymbolService.h"
namespace oi::detail {
class OICache {
public:
OICache(const OICodeGen::Config& generatorConfig)
: generatorConfig(generatorConfig) {
}
std::filesystem::path basePath{};
std::shared_ptr<SymbolService> symbols{};
bool downloadedRemote = false;
bool enableUpload = false;
bool enableDownload = false;
bool abortOnLoadFail = false;
// We need the generator config to download the cache
// with the matching configuration.
const OICodeGen::Config& generatorConfig;
// Entity is used to index the `extensions` array
// So we must keep the Entity enum and `extensions` array in sync!
enum class Entity {
Source,
Object,
FuncDescs,
GlobalDescs,
TypeHierarchy,
PaddingInfo,
MAX
};
static constexpr std::array<const char*, static_cast<size_t>(Entity::MAX)>
extensions{".cc", ".o", ".fd", ".gd", ".th", ".pd"};
bool isEnabled() const {
return !basePath.empty();
}
std::optional<std::filesystem::path> getPath(const irequest&, Entity) const;
template <typename T>
bool store(const irequest&, Entity, const T&);
template <typename T>
bool load(const irequest&, Entity, T&);
bool upload(const irequest& req);
bool download(const irequest& req);
private:
std::string generateRemoteHash(const irequest&);
};
} // namespace oi::detail