1 /* 2 * Copyright (c) 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 DRM_API_OPERATION_H 17 #define DRM_API_OPERATION_H 18 #include <string> 19 20 namespace OHOS { 21 namespace DrmStandard { 22 #define DRM_API_OPERATION_CONFIG_PATH "/etc/drm/drm_api_operation.cfg" 23 struct ApiReportConfig { 24 std::string config_name; 25 std::string config_appId; 26 std::string config_routeInfo; 27 int config_timeout = 0; 28 int config_row = 0; 29 }; 30 31 struct ApiEvent { 32 std::string domain; 33 std::string name; 34 bool isRealTime = false; 35 }; 36 37 struct ApiEventConfig { 38 ApiEvent event1; 39 ApiEvent event2; 40 ApiEvent event3; 41 }; 42 43 class ConfigParser { 44 public: 45 static int64_t AddProcessor(); 46 static void WriteEndEvent(const int result, const int errCode, std::string apiName, int64_t beginTime); 47 ConfigParser(const ConfigParser&) = delete; 48 ConfigParser& operator=(const ConfigParser&) = delete; 49 50 private: ConfigParser()51 ConfigParser() {} ~ConfigParser()52 ~ConfigParser() {} 53 static bool LoadConfigurationFile(const std::string &configFile); 54 static void GetConfigurationParams(ApiReportConfig &reportConfig, ApiEventConfig &eventConfig); 55 static std::string Trim(const std::string &str); 56 static std::pair<std::string, std::string> ParseKeyValue(const std::string &line); 57 static bool TryParseInt(const std::string& str, int& out); 58 static void ParseReportConfig(std::istringstream &stream, ApiReportConfig &reportConfig); 59 static void ParseEvent(std::istringstream &stream, ApiEvent &event); 60 static void ParseEventConfig(std::istringstream &stream, ApiEventConfig &eventConfig); 61 static void ParseApiOperationManagement(std::istringstream &stream, ApiReportConfig &reportConfig, 62 ApiEventConfig &eventConfig); 63 static std::string g_fileContent; 64 static std::mutex g_apiOperationMutex; 65 static int64_t g_processorId; 66 }; 67 } // namespace DrmStandard 68 } // namespace OHOS 69 #endif // DRM_API_OPERATION_H