• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-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 DEVICESTATUS_CLIENT_H
17 #define DEVICESTATUS_CLIENT_H
18 
19 #include <functional>
20 #include <map>
21 
22 #include <singleton.h>
23 
24 #include "devicestatus_common.h"
25 #include "drag_data.h"
26 #include "i_coordination_listener.h"
27 #include "i_devicestatus.h"
28 #include "stationary_callback.h"
29 #include "stationary_data.h"
30 
31 namespace OHOS {
32 namespace Msdp {
33 namespace DeviceStatus {
34 class DeviceStatusClient final : public DelayedRefSingleton<DeviceStatusClient> {
DECLARE_DELAYED_REF_SINGLETON(DeviceStatusClient)35     DECLARE_DELAYED_REF_SINGLETON(DeviceStatusClient)
36 
37 public:
38     std::map<Type, int32_t> GetTypeMap()
39     {
40         return typeMap_;
41     }
42     DISALLOW_COPY_AND_MOVE(DeviceStatusClient);
43 
44     int32_t SubscribeCallback(Type type, ActivityEvent event, ReportLatencyNs latency,
45         sptr<IRemoteDevStaCallback> callback);
46     int32_t UnsubscribeCallback(Type type, ActivityEvent event, sptr<IRemoteDevStaCallback> callback);
47     Data GetDeviceStatusData(const Type type);
48     void RegisterDeathListener(std::function<void()> deathListener);
49     int32_t RegisterCoordinationListener();
50     int32_t UnregisterCoordinationListener();
51     int32_t PrepareCoordination(int32_t userData);
52     int32_t UnprepareCoordination(int32_t userData);
53     int32_t ActivateCoordination(int32_t userData, const std::string &remoteNetworkId, int32_t startDeviceId);
54     int32_t DeactivateCoordination(int32_t userData, bool isUnchained);
55     int32_t GetCoordinationState(int32_t userData, const std::string &deviceId);
56     int32_t StartDrag(const DragData &dragData);
57     int32_t StopDrag(DragResult result, bool hasCustomAnimation);
58     int32_t UpdateDragStyle(DragCursorStyle style);
59     int32_t GetDragTargetPid();
60     int32_t GetUdKey(std::string &udKey);
61     int32_t AddDraglistener();
62     int32_t RemoveDraglistener();
63     int32_t SetDragWindowVisible(bool visible);
64     int32_t GetShadowOffset(int32_t& offsetX, int32_t& offsetY, int32_t& width, int32_t& height);
65     int32_t UpdateShadowPic(const ShadowInfo &shadowInfo);
66     int32_t AllocSocketPair(int32_t moduleType);
67     int32_t GetClientSocketFdOfAllocedSocketPair() const;
68 
69 private:
70     class DeviceStatusDeathRecipient : public IRemoteObject::DeathRecipient {
71     public:
72         DeviceStatusDeathRecipient() = default;
73         ~DeviceStatusDeathRecipient() = default;
74         void OnRemoteDied(const wptr<IRemoteObject>& remote);
75 
76     private:
77         DISALLOW_COPY_AND_MOVE(DeviceStatusDeathRecipient);
78     };
79 
80     ErrCode Connect();
81     void ResetProxy(const wptr<IRemoteObject>& remote);
82 
83     sptr<Idevicestatus> devicestatusProxy_ { nullptr };
84     sptr<IRemoteObject::DeathRecipient> deathRecipient_ { nullptr };
85     std::mutex mutex_;
86     int32_t tokenType_ { -1 };
87     int32_t socketFd_ { -1 };
88     std::map<Type, int32_t> typeMap_;
89     std::function<void()> deathListener_ { nullptr };
90 };
91 } // namespace DeviceStatus
92 } // namespace Msdp
93 } // namespace OHOS
94 #endif // DEVICESTATUS_CLIENT_H
95