* Copyright (c) Huawei Technologies Co., Ltd. 2025. All rights reserved.
*
* 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 FUNCTION_MASTER_INSTANCE_MANAGER_INSTANCE_FAMILY_H
#define FUNCTION_MASTER_INSTANCE_MANAGER_INSTANCE_FAMILY_H
#include <list>
#include <memory>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include "common/resource_view/resource_type.h"
namespace functionsystem::instance_manager {
using InstanceInfo = resource_view::InstanceInfo;
struct InstanceFamilyEntry {
std::unordered_set<std::string> childrenInstanceID{};
std::shared_ptr<InstanceInfo> info{ nullptr };
};
class InstanceFamilyCaches {
public:
InstanceFamilyCaches();
std::list<std::shared_ptr<InstanceInfo>> GetAllDescendantsOf(const std::string &instanceID,
bool noDetachedInstance = true);
void RemoveInstance(const std::string &instanceID);
bool IsInstanceExists(const std::string &instanceID);
void AddInstance(std::shared_ptr<InstanceInfo> info);
*
* get instance by instanceID
*
* @param instanceID instanceID
* @return instance info
*/
std::shared_ptr<InstanceInfo> GetInstance(const std::string &instanceID);
void SyncInstances(const std::unordered_map<std::string, std::shared_ptr<InstanceInfo>> &infos);
std::unordered_map<std::string, InstanceFamilyEntry> GetFamily() const;
private:
std::unordered_map<std::string, InstanceFamilyEntry> family_;
};
}
#endif