1 /* 2 * Copyright (c) 2021 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 SENDFILE_H 17 #define SENDFILE_H 18 19 #include <mutex> 20 #include <unordered_map> 21 #include <vector> 22 #include "event_agent.h" 23 #include "trans_event.h" 24 25 namespace OHOS { 26 namespace Storage { 27 namespace DistributedFile { 28 class SendFile { 29 public: 30 enum { 31 NAPI_SENDFILE_NO_ERROR = 0, 32 NAPI_SENDFILE_SA_ERROR = -1, 33 NAPI_SENDFILE_IPC_ERROR = -2, 34 NAPI_SENDFILE_DEVICE_ID_ERROR = -3, 35 NAPI_SENDFILE_GET_AGENT_ERROR = -4, 36 NAPI_SENDFILE_APP_AGENT_ERROR = -5, 37 NAPI_SENDFILE_PARA_ERROR = -6, 38 NAPI_SENDFILE_AGENT_ERROR = -7, 39 NAPI_SENDFILE_SEND_ERROR = -8, 40 NAPI_SENDFILE_FD_ERROR = -9, 41 NAPI_SENDFILE_UNKNOWN_ERROR = -99, 42 }; 43 SendFile()44 SendFile() {} ~SendFile()45 virtual ~SendFile() {} 46 static int32_t JoinCidToAppId(const std::string &cid, const std::string &AppId = BUNDLE_ID_); 47 static int32_t DisjoinCidToAppId(const std::string &cid, const std::string &AppId = BUNDLE_ID_); 48 static int32_t EmitTransEvent(TransEvent &event, const std::string &cid, const std::string &AppId = BUNDLE_ID_); 49 static int32_t WriteFile(int32_t fd, const std::string &fileName); 50 static int32_t RegisterCallback(); 51 static int32_t ExecSendFile(const std::string &deviceId, const std::vector<std::string>& srcList, 52 const std::vector<std::string>& dstList, uint32_t num); 53 54 static std::mutex g_uidMutex; 55 static std::unordered_map<std::string, EventAgent*> mapUidToEventAgent_; 56 static inline const std::string BUNDLE_ID_ {"SendFileHapUid"}; 57 static inline const std::string APP_PATH {"/data/accounts/account_0/appdata/"}; 58 static inline const int32_t FILE_BLOCK_SIZE {1024}; 59 static inline const int32_t MAX_SEND_FILE_HAP_NUMBER {50}; 60 static inline const int32_t SENDFILE_NAPI_BUF_LENGTH {64}; 61 }; 62 } // namespace DistributedFile 63 } // namespace Storage 64 } // namespace OHOS 65 #endif // SENDFILE_H