1 /* 2 * Copyright (c) 2025 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 17 #ifndef BUNDLE_NAME_PARSER_H 18 #define BUNDLE_NAME_PARSER_H 19 20 #include <shared_mutex> 21 #include <string> 22 #include <map> 23 24 #include "json_parser.h" 25 26 namespace OHOS { 27 namespace MMI { 28 29 class BundleNameParser { 30 public: 31 BundleNameParser(const BundleNameParser&) = delete; 32 BundleNameParser& operator=(const BundleNameParser&) = delete; 33 static BundleNameParser& GetInstance(); 34 int32_t Init(); 35 std::string GetBundleName(const std::string &key); 36 37 private: 38 struct BundleNameItem { 39 std::string placeHolder; 40 std::string bundleName; 41 }; 42 43 private: 44 BundleNameParser() = default; 45 ~BundleNameParser() = default; 46 47 int32_t ParseBundleNameMap(const JsonParser &jsonParser); 48 int32_t ParseBundleNameItem(const cJSON *json, BundleNameItem &bundleNameItem); 49 void PrintBundleNames(); 50 51 private: 52 std::map<std::string, std::string> bundleNames_; 53 std::shared_mutex lock_; 54 std::atomic_bool isInitialized_ { false }; 55 }; 56 } // namespace MMI 57 } // namespace OHOS 58 #define BUNDLE_NAME_PARSER OHOS::MMI::BundleNameParser::GetInstance() 59 #endif // BUNDLE_NAME_PARSER_H