object-introspection/oi/OICache.h

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

77 lines
2.1 KiB
C
Raw Permalink Normal View History

2022-12-19 14:37:51 +00:00
/*
* 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>
2023-04-26 16:20:53 +01:00
#include "oi/OICodeGen.h"
#include "oi/OIParser.h"
#include "oi/SymbolService.h"
2022-12-19 14:37:51 +00:00
namespace oi::detail {
2022-12-19 14:37:51 +00:00
class OICache {
public:
OICache(const OICodeGen::Config& generatorConfig)
: generatorConfig(generatorConfig) {
}
std::filesystem::path basePath{};
2022-12-19 14:37:51 +00:00
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;
2022-12-19 14:37:51 +00:00
// 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)>
2022-12-19 14:37:51 +00:00
extensions{".cc", ".o", ".fd", ".gd", ".th", ".pd"};
bool isEnabled() const {
return !basePath.empty();
}
std::optional<std::filesystem::path> getPath(const irequest&, Entity) const;
2022-12-19 14:37:51 +00:00
template <typename T>
bool store(const irequest&, Entity, const T&);
2022-12-19 14:37:51 +00:00
template <typename T>
bool load(const irequest&, Entity, T&);
2022-12-19 14:37:51 +00:00
bool upload(const irequest& req);
bool download(const irequest& req);
2022-12-19 14:37:51 +00:00
private:
std::string generateRemoteHash(const irequest&);
2022-12-19 14:37:51 +00:00
};
} // namespace oi::detail