1 /* 2 * Copyright (c) 2021-2022 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 #ifndef COMMON_H 16 #define COMMON_H 17 18 #include <string> 19 #include <vector> 20 21 namespace COMMON { 22 bool IsProcessRunning(); // add file lock, only one process can run 23 bool IsProcessExist(std::string& processName, int& pid); // Check if the process exists and get PID 24 int StartProcess(const std::string& processBin, std::vector<char*>& argv); 25 int KillProcess(int pid); 26 void PrintMallinfoLog(const std::string& mallInfoPrefix); 27 FILE* CustomPopen(int& childPid, const std::string& filePath, std::vector<std::string>& argv, const char* type); 28 int CustomPclose(FILE* fp, int childPid); 29 int GetServicePort(); 30 void SplitString(const std::string& str, const std::string &sep, std::vector<std::string>& ret); 31 bool CheckApplicationPermission(int pid, const std::string& processName); 32 bool VerifyPath(const std::string& filePath, const std::vector<std::string>& validPaths); 33 bool ReadFile(const std::string& filePath, const std::vector<std::string>& validPaths, std::string& fileContent); 34 std::string GetErrorMsg(); 35 } // COMMON 36 37 #endif // COMMON_H