1 /*
2  * Copyright (c) 2022 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 
33 public:
34     NetConnection();
35     ~NetConnection() = default;
36 
37     [[nodiscard]] sptr<NetConnCallbackObserver> GetObserver() const;
38 
39     [[nodiscard]] EventManager *GetEventManager() const;
40 
41     static NetConnection *MakeNetConnection(EventManager *eventManager);
42 
43     static void DeleteNetConnection(NetConnection *netConnection);
44 
45 private:
46     sptr<NetConnCallbackObserver> observer_;
47 
48     EventManager *manager_;
49 
50     explicit NetConnection(EventManager *eventManager);
51 };
52 
53 extern std::map<NetConnCallbackObserver *, NetConnection *> NET_CONNECTIONS;
54 extern std::mutex g_netConnectionsMutex;
55 } // namespace OHOS::NetManagerStandard
56 
57 #endif /* NETMANAGER_BASE_NETCONNECTION_H */
58