1 /* 2 * Copyright (c) 2021-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 HISYSEVENT_TRANSPORT_H 17 #define HISYSEVENT_TRANSPORT_H 18 19 #include <list> 20 #include <mutex> 21 #include <string> 22 23 #include "raw_data.h" 24 25 namespace OHOS { 26 namespace HiviewDFX { 27 using namespace Encoded; 28 class Transport { 29 public: 30 static Transport& GetInstance(); 31 int SendData(RawData& rawData); 32 33 private: Transport()34 Transport() {} ~Transport()35 ~Transport() {} 36 Transport& operator=(const Transport&) = delete; 37 Transport(const Transport&) = delete; 38 Transport& operator=(const Transport&&) = delete; 39 Transport(const Transport&&) = delete; 40 41 private: 42 void AddFailedData(RawData& rawData); 43 void InitRecvBuffer(int socketId); 44 void RetrySendFailedData(); 45 int SendToHiSysEventDataSource(RawData& rawData); 46 47 private: 48 static Transport instance_; 49 static constexpr std::size_t RETRY_QUEUE_SIZE = 10; 50 static constexpr int RETRY_TIMES = 3; 51 std::mutex mutex_; 52 std::list<RawData> retryDataList_; 53 }; 54 } // namespace HiviewDFX 55 } // namespace OHOS 56 57 #endif // HISYSEVENT_TRANSPORT_H 58