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 INTENTION_DRAG_CLIENT_H
17#define INTENTION_DRAG_CLIENT_H
18
19#include "nocopyable.h"
20
21#include <set>
22
23#include "i_drag_listener.h"
24#include "i_subscript_listener.h"
25#include "i_tunnel_client.h"
26#include "i_start_drag_listener.h"
27#include "socket_client.h"
28#include "transaction/rs_transaction.h"
29
30namespace OHOS {
31namespace Msdp {
32namespace DeviceStatus {
33class DragClient final {
34public:
35    DragClient() = default;
36    ~DragClient() = default;
37    DISALLOW_COPY_AND_MOVE(DragClient);
38
39    int32_t StartDrag(ITunnelClient &tunnel, const DragData &dragData, std::shared_ptr<IStartDragListener> listener);
40    int32_t StopDrag(ITunnelClient &tunnel, const DragDropResult &dropResult);
41    int32_t AddDraglistener(ITunnelClient &tunnel, DragListenerPtr listener, bool isJsCaller = false);
42    int32_t RemoveDraglistener(ITunnelClient &tunnel, DragListenerPtr listener, bool isJsCaller = false);
43    int32_t AddSubscriptListener(ITunnelClient &tunnel, SubscriptListenerPtr listener);
44    int32_t RemoveSubscriptListener(ITunnelClient &tunnel, SubscriptListenerPtr listener);
45    int32_t SetDragWindowVisible(ITunnelClient &tunnel, bool visible, bool isForce);
46    int32_t UpdateDragStyle(ITunnelClient &tunnel, DragCursorStyle style, int32_t eventId = -1);
47    int32_t UpdateShadowPic(ITunnelClient &tunnel, const ShadowInfo &shadowInfo);
48    int32_t GetDragTargetPid(ITunnelClient &tunnel);
49    int32_t GetUdKey(ITunnelClient &tunnel, std::string &udKey);
50    int32_t GetShadowOffset(ITunnelClient &tunnel, ShadowOffset &shadowOffset);
51    int32_t GetDragData(ITunnelClient &tunnel, DragData &dragData);
52    int32_t UpdatePreviewStyle(ITunnelClient &tunnel, const PreviewStyle &previewStyle);
53    int32_t UpdatePreviewStyleWithAnimation(ITunnelClient &tunnel,
54        const PreviewStyle &previewStyle, const PreviewAnimation &animation);
55    int32_t RotateDragWindowSync(ITunnelClient &tunnel,
56        const std::shared_ptr<Rosen::RSTransaction>& rsTransaction = nullptr);
57    int32_t SetDragWindowScreenId(ITunnelClient &tunnel, uint64_t displayId, uint64_t screenId);
58    int32_t GetDragSummary(ITunnelClient &tunnel, std::map<std::string, int64_t> &summary,
59        bool isJsCaller = false);
60    int32_t GetDragState(ITunnelClient &tunnel, DragState &dragState);
61    int32_t EnableUpperCenterMode(ITunnelClient &tunnel, bool enable);
62    int32_t GetDragAction(ITunnelClient &tunnel, DragAction &dragAction);
63    int32_t GetExtraInfo(ITunnelClient &tunnel, std::string &extraInfo);
64    int32_t AddPrivilege(ITunnelClient &tunnel);
65    int32_t EraseMouseIcon(ITunnelClient &tunnel);
66    int32_t AddSelectedPixelMap(ITunnelClient &tunnel, std::shared_ptr<OHOS::Media::PixelMap> pixelMap,
67        std::function<void(bool)> callback);
68    int32_t SetMouseDragMonitorState(ITunnelClient &tunnel, bool state);
69
70    int32_t OnNotifyResult(const StreamClient &client, NetPacket &pkt);
71    int32_t OnNotifyHideIcon(const StreamClient& client, NetPacket& pkt);
72    int32_t OnStateChangedMessage(const StreamClient &client, NetPacket &pkt);
73    int32_t OnDragStyleChangedMessage(const StreamClient &client, NetPacket &pkt);
74    int32_t OnAddSelectedPixelMapResult(const StreamClient &client, NetPacket &pkt);
75    void OnConnected(ITunnelClient &tunnel);
76    void OnDisconnected(ITunnelClient &tunnel);
77
78private:
79    mutable std::mutex mtx_;
80    std::shared_ptr<IStartDragListener> startDragListener_ { nullptr };
81    bool hasRegistered_ { false };
82    bool hasSubscriptRegistered_ { false };
83    std::set<DragListenerPtr> dragListeners_;
84    std::set<DragListenerPtr> connectedDragListeners_;
85    std::set<SubscriptListenerPtr> subscriptListeners_;
86    std::function<void(bool)> addSelectedPixelMapCallback_;
87};
88} // namespace DeviceStatus
89} // namespace Msdp
90} // namespace OHOS
91#endif // INTENTION_DRAG_CLIENT_H
92