• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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 #ifndef OHOS_ABILITY_RUNTIME_CONTINUATION_REGISTER_MANAGER_PROXY_H
16 #define OHOS_ABILITY_RUNTIME_CONTINUATION_REGISTER_MANAGER_PROXY_H
17 
18 #include <memory>
19 #include "continuation_register_manager_interface.h"
20 #include "continuation_request.h"
21 #include "continuation_connector.h"
22 
23 namespace OHOS {
24 namespace AppExecFwk {
25 class ContinuationConnector;
26 class Context;
27 class IContinuationDeviceCallback;
28 class RequestCallback;
29 
30 class ContinuationRequestBase : public ContinuationRequest {
31 public:
32     ContinuationRequestBase() = default;
33     virtual ~ContinuationRequestBase() = default;
34 
SetContext(const std::weak_ptr<Context> & context)35     void SetContext(const std::weak_ptr<Context> &context)
36     {
37         context_ = context;
38     }
39 
SetContinuationConnector(const sptr<ContinuationConnector> & continuatinConnector)40     void SetContinuationConnector(const sptr<ContinuationConnector> &continuatinConnector)
41     {
42         continuatinConnector_ = continuatinConnector;
43     }
44 
SetRequestCallback(const std::shared_ptr<RequestCallback> & requestCallback)45     void SetRequestCallback(const std::shared_ptr<RequestCallback> &requestCallback)
46     {
47         requestCallback_ = requestCallback;
48     }
49 
50 protected:
51     std::weak_ptr<Context> context_;
52     sptr<ContinuationConnector> continuatinConnector_;
53     std::shared_ptr<RequestCallback> requestCallback_ = nullptr;
54 };
55 
56 class ContinuationRequestRegister : public ContinuationRequestBase {
57 public:
58     ContinuationRequestRegister(const std::string &bundleName, const ExtraParams &parameter,
59         const std::shared_ptr<IContinuationDeviceCallback> &deviceCallback);
60     virtual ~ContinuationRequestRegister() = default;
61     virtual void Execute() override;
62 
63 private:
64     ExtraParams parameter_;
65     std::shared_ptr<IContinuationDeviceCallback> deviceCallback_ = nullptr;
66     std::string bundleName_ = "";
67 };
68 
69 class ContinuationRequestUnRegister : public ContinuationRequestBase {
70 public:
71     explicit ContinuationRequestUnRegister(int token);
72     virtual ~ContinuationRequestUnRegister() = default;
73     virtual void Execute() override;
74 
75 private:
76     int token_ = 0;
77 };
78 
79 class ContinuationRequestUpdateConnectStatus : public ContinuationRequestBase {
80 public:
81     ContinuationRequestUpdateConnectStatus(int token, const std::string &deviceId, int status);
82     virtual ~ContinuationRequestUpdateConnectStatus() = default;
83     virtual void Execute() override;
84 
85 private:
86     int token_ = 0;
87     std::string deviceId_ = "";
88     int status_;
89 };
90 
91 class ContinuationRequestShowDeviceList : public ContinuationRequestBase {
92 public:
93     ContinuationRequestShowDeviceList(int token, const ExtraParams &parameter);
94     virtual ~ContinuationRequestShowDeviceList() = default;
95     virtual void Execute() override;
96 
97 private:
98     int token_ = 0;
99     ExtraParams parameter_;
100 };
101 
102 class ContinuationRegisterManagerProxy : public IContinuationRegisterManager {
103 public:
104     explicit ContinuationRegisterManagerProxy(const std::weak_ptr<Context> &context);
105     virtual ~ContinuationRegisterManagerProxy();
106 
107     /**
108      * Registers an ability to be migrated with the Device+ control center and obtains the registration token assigned
109      * to the ability.
110      *
111      * @param bundleName Indicates the bundle name of the application whose ability is to be migrated.
112      * @param parameter Indicates the {@link ExtraParams} object containing the extra parameters used to filter
113      * the list of available devices. This parameter can be null.
114      * @param deviceCallback Indicates the callback to be invoked when the connection state of the selected device
115      * changes.
116      * @param requestCallback Indicates the callback to be invoked when the Device+ service is connected.
117      */
118     virtual void Register(const std::string &bundleName, const ExtraParams &parameter,
119         const std::shared_ptr<IContinuationDeviceCallback> &deviceCallback,
120         const std::shared_ptr<RequestCallback> &requestCallback) override;
121 
122     /**
123      * Unregisters a specified ability from the Device+ control center based on the token obtained during ability
124      * registration.
125      *
126      * @param token Indicates the registration token of the ability.
127      * @param requestCallback Indicates the callback to be invoked when the Device+ service is connected.
128      * This parameter can be null.
129      */
130     virtual void Unregister(int token, const std::shared_ptr<RequestCallback> &requestCallback) override;
131 
132     /**
133      * Updates the connection state of the device where the specified ability is successfully migrated.
134      *
135      * @param token Indicates the registration token of the ability.
136      * @param deviceId Indicates the ID of the device whose connection state is to be updated.
137      * @param status Indicates the connection state to update, which can be {@link DeviceConnectState#FAILURE},
138      * {@link DeviceConnectState#IDLE}, {@link DeviceConnectState#CONNECTING}, {@link DeviceConnectState#CONNECTED},
139      * or {@link DeviceConnectState#DIS_CONNECTING}.
140      * @param requestCallback Indicates the callback to be invoked when the Device+ service is connected.
141      * This parameter can be null.
142      */
143     virtual void UpdateConnectStatus(int token, const std::string &deviceId, int status,
144         const std::shared_ptr<RequestCallback> &requestCallback) override;
145 
146     /**
147      * Shows the list of devices that can be selected for ability migration on the distributed network.
148      *
149      * @param token Indicates the registration token of the ability.
150      * @param parameter Indicates the {@link ExtraParams} object containing the extra parameters used to filter
151      * the list of available devices. This parameter can be null.
152      * @param requestCallback Indicates the callback to be invoked when the Device+ service is connected.
153      * This parameter can be null.
154      */
155     virtual void ShowDeviceList(
156         int token, const ExtraParams &parameter, const std::shared_ptr<RequestCallback> &requestCallback) override;
157 
158     /**
159      * Disconnects from the Device+ control center.
160      */
161     virtual void Disconnect(void) override;
162 
163 private:
164     std::weak_ptr<Context> context_;
165     std::weak_ptr<Context> applicationContext_;
166     sptr<ContinuationConnector> continuatinConnector_;
167 
168     void SendRequest(const std::weak_ptr<Context> &context, const std::shared_ptr<ContinuationRequest> &request);
169 };
170 }  // namespace AppExecFwk
171 }  // namespace OHOS
172 #endif  // OHOS_ABILITY_RUNTIME_CONTINUATION_REGISTER_MANAGER_PROXY_H
173