1 /* 2 * Copyright (c) 2023-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 #ifndef FILEMANAGEMENT_DFS_SERVICE_CONNECTION_DETECTOR_H 17 #define FILEMANAGEMENT_DFS_SERVICE_CONNECTION_DETECTOR_H 18 19 #include "os_account_manager.h" 20 21 #include <fstream> 22 #include <string> 23 24 namespace OHOS { 25 namespace Storage { 26 namespace DistributedFile { 27 using namespace std; 28 const std::string HMDFS_PATH = "/mnt/hmdfs/<currentUserId>/account"; 29 const std::string SYS_HMDFS_PATH = "/sys/fs/hmdfs/"; 30 const std::string CONNECTION_STATUS_FILE_NAME = "status"; 31 const std::string CURRENT_USER_ID_FLAG = "<currentUserId>"; 32 constexpr int32_t MAX_RETRY = 50; 33 constexpr int32_t CHECK_SESSION_DELAY_TIME = 200000; 34 constexpr int32_t NO_ERROR = 0; 35 constexpr int DISMATCH = 0; 36 constexpr int MATCH = 1; 37 class ConnectionDetector { 38 public: 39 static bool GetConnectionStatus(const std::string &targetDir, const std::string &networkId); 40 static int32_t RepeatGetConnectionStatus(const std::string &targetDir, const std::string &networkId); 41 static std::string ParseHmdfsPath(); 42 static uint64_t MocklispHash(const string &str); 43 44 private: 45 static std::string GetCellByIndex(const std::string &str, int targetIndex); 46 static bool MatchConnectionStatus(ifstream &inputFile); 47 static bool MatchConnectionGroup(const std::string &fileName, const string &networkId); 48 static bool CheckValidDir(const std::string &path); 49 static int32_t GetCurrentUserId(); 50 }; 51 } // namespace DistributedFile 52 } // namespace Storage 53 } // namespace OHOS 54 #endif // FILEMANAGEMENT_DFS_SERVICE_CONNECTION_DETECTOR_H 55