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 FOUNDATION_EVENT_CESFWK_SERVICES_INCLUDE_STATIC_SUBSCRIBER_CONNECTION_H
17#define FOUNDATION_EVENT_CESFWK_SERVICES_INCLUDE_STATIC_SUBSCRIBER_CONNECTION_H
18
19#include "ability_connect_callback_stub.h"
20#include "common_event_data.h"
21#include "static_subscriber_proxy.h"
22
23namespace OHOS {
24namespace EventFwk {
25class StaticSubscriberConnection : public AAFwk::AbilityConnectionStub {
26public:
27    /**
28     * Constructor.
29     *
30     * @param event, Indicates the common event data.
31     */
32    explicit StaticSubscriberConnection(const CommonEventData& event) : event_(event) {}
33
34    /**
35     * OnAbilityConnectDone, Ability Manager Service notify caller ability the result of connect.
36     *
37     * @param element, Indicates elementName of service ability.
38     * @param remoteObject, Indicates the session proxy of service ability.
39     * @param resultCode, Returns ERR_OK on success, others on failure.
40     */
41    void OnAbilityConnectDone(
42        const AppExecFwk::ElementName &element, const sptr<IRemoteObject> &remoteObject, int resultCode) override;
43
44    /**
45     * OnAbilityDisconnectDone, Ability Manager Service notify caller ability the result of disconnect.
46     *
47     * @param element, Indicates elementName of service ability.
48     * @param resultCode, Returns ERR_OK on success, others on failure.
49     */
50    void OnAbilityDisconnectDone(const AppExecFwk::ElementName &element, int resultCode) override;
51
52private:
53    sptr<StaticSubscriberProxy> GetProxy(const sptr<IRemoteObject> &remoteObject);
54    sptr<StaticSubscriberProxy> proxy_ = nullptr;
55    std::mutex proxyMutex_;
56
57    CommonEventData event_;
58};
59}  // namespace EventFwk
60}  // namespace OHOS
61#endif  // FOUNDATION_EVENT_CESFWK_SERVICES_INCLUDE_STATIC_SUBSCRIBER_CONNECTION_H
62