1 /*
2  * Copyright (c) 2023 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 OHOS_FORM_FWK_FORM_RENDER_CONNECTION_H
17 #define OHOS_FORM_FWK_FORM_RENDER_CONNECTION_H
18 
19 #include <unordered_set>
20 
21 #include "form_ability_connection.h"
22 #include "form_item_info.h"
23 #include "want.h"
24 
25 namespace OHOS {
26 namespace AppExecFwk {
27 /**
28  * @class FormRenderConnection
29  * Form Render Connection Stub.
30  */
31 class FormRenderConnection : public FormAbilityConnection {
32 public:
33     FormRenderConnection(const FormRecord &formRecord, const WantParams &wantParams);
34     FormRenderConnection() = delete; // disable default constructor.
35     virtual ~FormRenderConnection() = default;
36 
37     /**
38      * @brief OnAbilityConnectDone, AbilityMs notify caller ability the result of connect.
39      *
40      * @param element service ability's ElementName.
41      * @param remoteObject the session proxy of service ability.
42      * @param resultCode ERR_OK on success, others on failure.
43      */
44     void OnAbilityConnectDone(const AppExecFwk::ElementName &element,
45         const sptr<IRemoteObject> &remoteObject, int resultCode) override;
46 
47     /**
48      * @brief OnAbilityDisconnectDone, AbilityMs notify caller ability the result of disconnect.
49      * @param element service ability's ElementName.
50      * @param resultCode ERR_OK on success, others on failure.
51      */
52     virtual void OnAbilityDisconnectDone(const AppExecFwk::ElementName &element, int resultCode) override;
53 
54     /**
55      * @brief Set connectState to CONNECTING.
56      */
57     void SetStateConnecting();
58 
59     /**
60      * @brief Set connectState to DISCONNECTED.
61      */
62     void SetStateDisconnected();
63 
64     void UpdateWantParams(const WantParams &wantParams);
65 
66     void UpdateFormRecord(const FormRecord &formRecord);
67 
68 private:
69     enum class ConnectState {
70         DISCONNECTED,
71         CONNECTING,
72         CONNECTED,
73     };
74 
75     FormRecord formRecord_;
76     WantParams wantParams_;
77     ConnectState connectState_ = ConnectState::DISCONNECTED;
78     DISALLOW_COPY_AND_MOVE(FormRenderConnection);
79 };
80 } // namespace AppExecFwk
81 } // namespace OHOS
82 #endif // OHOS_FORM_FWK_FORM_RENDER_CONNECTION_H
83