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);
42    int32_t RemoveDraglistener(ITunnelClient &tunnel, DragListenerPtr listener);
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);
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    int32_t GetDragState(ITunnelClient &tunnel, DragState &dragState);
60    int32_t EnterTextEditorArea(ITunnelClient &tunnel, bool enable);
61    int32_t GetDragAction(ITunnelClient &tunnel, DragAction &dragAction);
62    int32_t GetExtraInfo(ITunnelClient &tunnel, std::string &extraInfo);
63    int32_t AddPrivilege(ITunnelClient &tunnel);
64    int32_t EraseMouseIcon(ITunnelClient &tunnel);
65    int32_t AddSelectedPixelMap(ITunnelClient &tunnel, std::shared_ptr<OHOS::Media::PixelMap> pixelMap,
66        std::function<void(bool)> callback);
67
68    int32_t OnNotifyResult(const StreamClient &client, NetPacket &pkt);
69    int32_t OnNotifyHideIcon(const StreamClient& client, NetPacket& pkt);
70    int32_t OnStateChangedMessage(const StreamClient &client, NetPacket &pkt);
71    int32_t OnDragStyleChangedMessage(const StreamClient &client, NetPacket &pkt);
72    int32_t OnAddSelectedPixelMapResult(const StreamClient &client, NetPacket &pkt);
73
74private:
75    mutable std::mutex mtx_;
76    std::shared_ptr<IStartDragListener> startDragListener_ { nullptr };
77    bool hasRegistered_ { false };
78    bool hasSubscriptRegistered_ { false };
79    std::set<DragListenerPtr> dragListeners_;
80    std::set<SubscriptListenerPtr> subscriptListeners_;
81    std::function<void(bool)> addSelectedPixelMapCallback_;
82};
83} // namespace DeviceStatus
84} // namespace Msdp
85} // namespace OHOS
86#endif // INTENTION_DRAG_CLIENT_H
87