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 COMMUNICATION_NETMANAGER_BASE_GET_TRAFFIC_STATS_BY_NETWORK_CONTEXT_H 17 #define COMMUNICATION_NETMANAGER_BASE_GET_TRAFFIC_STATS_BY_NETWORK_CONTEXT_H 18 19 #include <cstddef> 20 #include <cstdint> 21 #include <vector> 22 23 #include <napi/native_api.h> 24 25 #include "base_context.h" 26 #include "net_stats_info.h" 27 28 namespace OHOS { 29 namespace NetManagerStandard { 30 class GetTrafficStatsByNetworkContext final : public BaseContext { 31 public: 32 GetTrafficStatsByNetworkContext() = delete; 33 explicit GetTrafficStatsByNetworkContext(napi_env env, EventManager *manager); 34 35 void SetNetBearType(uint32_t bearerType); 36 void SetStartTime(uint32_t startTime); 37 void SetEndTime(uint32_t endTime); 38 void SetSimId(uint32_t simId); 39 uint32_t GetNetBearType() const; 40 uint32_t GetStartTime() const; 41 uint32_t GetEndTime() const; 42 uint32_t GetSimId() const; 43 44 std::unordered_map<uint32_t, NetStatsInfo> &GetNetStatsInfo(); 45 46 void ParseParams(napi_value *params, size_t paramsCount); 47 48 private: 49 bool CheckParamsType(napi_value *params, size_t paramsCount); 50 51 bool CheckNetworkParams(napi_value *params, size_t paramsCount); 52 53 private: 54 uint32_t netBearType_ = 0; 55 uint32_t startTime_ = 0; 56 uint32_t endTime_ = 0; 57 uint32_t simId_ = UINT32_MAX; 58 59 std::unordered_map<uint32_t, NetStatsInfo> stats_; 60 }; 61 } // namespace NetManagerStandard 62 } // namespace OHOS 63 64 #endif // COMMUNICATION_NETMANAGER_BASE_GET_TRAFFIC_STATS_BY_NETWORK_CONTEXT_H