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 ABILITY_RUNTIME_CONNECTION_OBSERVER_CLIENT_H
17 #define ABILITY_RUNTIME_CONNECTION_OBSERVER_CLIENT_H
18 
19 #include "connection_observer.h"
20 #include "dlp_connection_info.h"
21 
22 namespace OHOS {
23 namespace AbilityRuntime {
24 /**
25  * @class ConnectionObserverClient
26  * ConnectionObserverClient is used to manage connection observer.
27  */
28 class ConnectionObserverClientImpl;
29 class ConnectionObserverClient {
30 public:
31     static ConnectionObserverClient& GetInstance();
32 
33     /**
34      * @brief Destructor.
35      *
36      */
37     virtual ~ConnectionObserverClient() = default;
38 
39     /**
40      * register connection state observer.
41      *
42      * @param observer the observer callback.
43      * @return Returns ERR_OK on success, others on failure.
44      */
45     int32_t RegisterObserver(const std::shared_ptr<ConnectionObserver> &observer);
46 
47     /**
48      * unregister connection state observer.
49      *
50      * @param observer the observer callback.
51      * @return Returns ERR_OK on success, others on failure.
52      */
53     int32_t UnregisterObserver(const std::shared_ptr<ConnectionObserver> &observer);
54 
55     /**
56      * get exist dlp connection infos.
57      *
58      * @param infos output dlp connection result.
59      * @return Returns ERR_OK on success, others on failure.
60      */
61     int32_t GetDlpConnectionInfos(std::vector<DlpConnectionInfo> &infos);
62 
63     /**
64      * Get exist connection data including Extension and Data connection.
65      *
66      * @param connectionData output connection result.
67      * @return Returns ERR_OK on success, others on failure.
68      */
69     int32_t GetConnectionData(std::vector<ConnectionData> &connectionData);
70 
71 private:
72     ConnectionObserverClient();
73     ConnectionObserverClient(const ConnectionObserverClient&) = delete;
74     ConnectionObserverClient(ConnectionObserverClient&&) = delete;
75     ConnectionObserverClient& operator=(const ConnectionObserverClient&) = delete;
76     ConnectionObserverClient& operator=(ConnectionObserverClient&&) = delete;
77 
78     std::shared_ptr<ConnectionObserverClientImpl> clientImpl_;
79 };
80 } // namespace AbilityRuntime
81 } // namespace OHOS
82 #endif // ABILITY_RUNTIME_CONNECTION_OBSERVER_CLIENT_H
83