1c29fa5a6Sopenharmony_ci/*
2c29fa5a6Sopenharmony_ci * Copyright (c) 2024 Huawei Device Co., Ltd.
3c29fa5a6Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4c29fa5a6Sopenharmony_ci * you may not use this file except in compliance with the License.
5c29fa5a6Sopenharmony_ci * You may obtain a copy of the License at
6c29fa5a6Sopenharmony_ci *
7c29fa5a6Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8c29fa5a6Sopenharmony_ci *
9c29fa5a6Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10c29fa5a6Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11c29fa5a6Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12c29fa5a6Sopenharmony_ci * See the License for the specific language governing permissions and
13c29fa5a6Sopenharmony_ci * limitations under the License.
14c29fa5a6Sopenharmony_ci */
15c29fa5a6Sopenharmony_ci
16c29fa5a6Sopenharmony_ci#ifndef COOPERATE_MOUSE_LOCATION_H
17c29fa5a6Sopenharmony_ci#define COOPERATE_MOUSE_LOCATION_H
18c29fa5a6Sopenharmony_ci
19c29fa5a6Sopenharmony_ci#include <mutex>
20c29fa5a6Sopenharmony_ci#include <set>
21c29fa5a6Sopenharmony_ci#include <unordered_map>
22c29fa5a6Sopenharmony_ci
23c29fa5a6Sopenharmony_ci#include "nocopyable.h"
24c29fa5a6Sopenharmony_ci#include "pointer_event.h"
25c29fa5a6Sopenharmony_ci
26c29fa5a6Sopenharmony_ci#include "cooperate_events.h"
27c29fa5a6Sopenharmony_ci#include "i_context.h"
28c29fa5a6Sopenharmony_ci#include "i_event_listener.h"
29c29fa5a6Sopenharmony_ci
30c29fa5a6Sopenharmony_cinamespace OHOS {
31c29fa5a6Sopenharmony_cinamespace Msdp {
32c29fa5a6Sopenharmony_cinamespace DeviceStatus {
33c29fa5a6Sopenharmony_cinamespace Cooperate {
34c29fa5a6Sopenharmony_ciclass MouseLocation {
35c29fa5a6Sopenharmony_cistruct LocationInfo {
36c29fa5a6Sopenharmony_ci    int32_t displayX { -1 };
37c29fa5a6Sopenharmony_ci    int32_t displayY { -1 };
38c29fa5a6Sopenharmony_ci    int32_t displayWidth { -1 };
39c29fa5a6Sopenharmony_ci    int32_t displayHeight { -1 };
40c29fa5a6Sopenharmony_ci};
41c29fa5a6Sopenharmony_ci
42c29fa5a6Sopenharmony_cipublic:
43c29fa5a6Sopenharmony_ci    MouseLocation(IContext *context);
44c29fa5a6Sopenharmony_ci    ~MouseLocation() = default;
45c29fa5a6Sopenharmony_ci    DISALLOW_COPY_AND_MOVE(MouseLocation);
46c29fa5a6Sopenharmony_ci    void AddListener(const RegisterEventListenerEvent &event);
47c29fa5a6Sopenharmony_ci    void RemoveListener(const UnregisterEventListenerEvent &event);
48c29fa5a6Sopenharmony_ci    void ProcessData(std::shared_ptr<MMI::PointerEvent> pointerEvent);
49c29fa5a6Sopenharmony_ci    void OnSubscribeMouseLocation(const DSoftbusSubscribeMouseLocation &notice);
50c29fa5a6Sopenharmony_ci    void OnUnSubscribeMouseLocation(const DSoftbusUnSubscribeMouseLocation &notice);
51c29fa5a6Sopenharmony_ci    void OnReplySubscribeMouseLocation(const DSoftbusReplySubscribeMouseLocation &notice);
52c29fa5a6Sopenharmony_ci    void OnReplyUnSubscribeMouseLocation(const DSoftbusReplyUnSubscribeMouseLocation &notice);
53c29fa5a6Sopenharmony_ci    void OnRemoteMouseLocation(const DSoftbusSyncMouseLocation &notice);
54c29fa5a6Sopenharmony_ci    void OnClientDied(const ClientDiedEvent &event);
55c29fa5a6Sopenharmony_ci    void OnSoftbusSessionClosed(const DSoftbusSessionClosed &notice);
56c29fa5a6Sopenharmony_ci
57c29fa5a6Sopenharmony_ciprivate:
58c29fa5a6Sopenharmony_ci    int32_t SubscribeMouseLocation(const DSoftbusSubscribeMouseLocation &event);
59c29fa5a6Sopenharmony_ci    int32_t UnSubscribeMouseLocation(const DSoftbusUnSubscribeMouseLocation &event);
60c29fa5a6Sopenharmony_ci    int32_t SyncMouseLocation(const DSoftbusSyncMouseLocation &event);
61c29fa5a6Sopenharmony_ci    int32_t ReplySubscribeMouseLocation(const DSoftbusReplySubscribeMouseLocation &event);
62c29fa5a6Sopenharmony_ci    int32_t ReplyUnSubscribeMouseLocation(const DSoftbusReplyUnSubscribeMouseLocation &event);
63c29fa5a6Sopenharmony_ci    int32_t SendPacket(const std::string &remoteNetworkId, NetPacket &packet);
64c29fa5a6Sopenharmony_ci    void ReportMouseLocationToListener(const std::string &networkId, const LocationInfo &locationInfo, int32_t pid);
65c29fa5a6Sopenharmony_ci    void TransferToLocationInfo(std::shared_ptr<MMI::PointerEvent> pointerEvent, LocationInfo &locationInfo);
66c29fa5a6Sopenharmony_ci    void SyncLocationToRemote(const std::string &remoteNetworkId, const LocationInfo &locationInfo);
67c29fa5a6Sopenharmony_ci    bool HasRemoteSubscriber();
68c29fa5a6Sopenharmony_ci    bool HasLocalListener();
69c29fa5a6Sopenharmony_ci
70c29fa5a6Sopenharmony_ciprivate:
71c29fa5a6Sopenharmony_ci    std::mutex mutex_;
72c29fa5a6Sopenharmony_ci    IContext *context_ { nullptr };
73c29fa5a6Sopenharmony_ci    std::string localNetworkId_;
74c29fa5a6Sopenharmony_ci    std::set<int32_t> localListeners_;
75c29fa5a6Sopenharmony_ci    std::set<std::string> remoteSubscribers_;
76c29fa5a6Sopenharmony_ci    std::unordered_map<std::string, std::set<int32_t>> listeners_;
77c29fa5a6Sopenharmony_ci};
78c29fa5a6Sopenharmony_ci} // namespace Cooperate
79c29fa5a6Sopenharmony_ci} // namespace DeviceStatus
80c29fa5a6Sopenharmony_ci} // namespace Msdp
81c29fa5a6Sopenharmony_ci} // namespace OHOS
82c29fa5a6Sopenharmony_ci#endif // COOPERATE_MOUSE_LOCATION_H
83