1 /* 2 * Copyright (c) 2022-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 NETMANAGER_BASE_NETCONNECTION_H 17 #define NETMANAGER_BASE_NETCONNECTION_H 18 19 #include <map> 20 21 #include "net_conn_callback_observer.h" 22 #include "net_specifier.h" 23 #include "event_manager.h" 24 25 namespace OHOS::NetManagerStandard { 26 class NetConnection final { 27 public: 28 bool hasNetSpecifier_ = false; 29 bool hasTimeout_ = false; 30 NetManagerStandard::NetSpecifier netSpecifier_; 31 uint32_t timeout_ = 0; 32 uint64_t moduleId_ = 0; 33 34 public: 35 NetConnection(); 36 ~NetConnection() = default; 37 38 [[nodiscard]] sptr<NetConnCallbackObserver> GetObserver() const; 39 40 [[nodiscard]] EventManager *GetEventManager() const; 41 42 static NetConnection *MakeNetConnection(EventManager *eventManager); 43 44 static void DeleteNetConnection(NetConnection *netConnection); 45 46 private: 47 sptr<NetConnCallbackObserver> observer_; 48 49 EventManager *manager_{nullptr}; 50 51 explicit NetConnection(EventManager *eventManager); 52 }; 53 54 extern std::map<NetConnCallbackObserver *, NetConnection *> NET_CONNECTIONS; 55 extern std::mutex g_netConnectionsMutex; 56 } // namespace OHOS::NetManagerStandard 57 58 #endif /* NETMANAGER_BASE_NETCONNECTION_H */ 59