1 /* 2 * Copyright (c) 2021-2024 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef OHOS_RESTOOL_ID_WORKER_H 17 #define OHOS_RESTOOL_ID_WORKER_H 18 19 #include <vector> 20 #include "id_defined_parser.h" 21 #include "resource_data.h" 22 #include "resource_item.h" 23 #include "resource_util.h" 24 #include "singleton.h" 25 26 namespace OHOS { 27 namespace Global { 28 namespace Restool { 29 class IdWorker : public Singleton<IdWorker> { 30 public: 31 uint32_t Init(ResourceIdCluster &type, int64_t start = 0x01000000); 32 int64_t GenerateId(ResType resType, const std::string &name); 33 std::vector<ResourceId> GetHeaderId() const; 34 int64_t GetId(ResType resType, const std::string &name) const; 35 int64_t GetSystemId(ResType resType, const std::string &name) const; 36 int64_t LoadIdFromHap(std::map<int64_t, std::vector<ResourceItem>> &items); 37 38 private: 39 int64_t GenerateAppId(ResType resType, const std::string &name); 40 int64_t GenerateSysId(ResType resType, const std::string &name); 41 uint64_t GetMaxId(uint64_t startId) const; 42 int64_t GetCurId(); 43 uint64_t appId_; 44 uint64_t maxId_; 45 ResourceIdCluster type_; 46 std::map<std::pair<ResType, std::string>, int64_t> ids_; 47 std::map<std::pair<ResType, std::string>, ResourceId> sysDefinedIds_; 48 std::map<std::pair<ResType, std::string>, ResourceId> appDefinedIds_; 49 std::vector<int64_t> delIds_; 50 std::map<std::pair<ResType, std::string>, int64_t> cacheIds_; 51 }; 52 } 53 } 54 } 55 #endif 56