1 /*
2  * Copyright (c) 2023-2024 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 OHOS_AVCAST_CONTROLLER_STUB_H
17 #define OHOS_AVCAST_CONTROLLER_STUB_H
18 
19 #include <map>
20 #include "iavcast_controller.h"
21 #include "iremote_stub.h"
22 
23 namespace OHOS::AVSession {
24 class AVCastControllerStub : public IRemoteStub<IAVCastController> {
25 public:
26     int32_t OnRemoteRequest(uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option) override;
27 
RegisterCallback(const std::shared_ptr<AVCastControllerCallback> & callback)28     int32_t RegisterCallback(const std::shared_ptr<AVCastControllerCallback>& callback) override
29     {
30         return 0;
31     }
32 
33 private:
34     int32_t HandleSendControlCommand(MessageParcel& data, MessageParcel& reply);
35 
36     int32_t HandleStart(MessageParcel& data, MessageParcel& reply);
37 
38     int32_t HandlePrepare(MessageParcel& data, MessageParcel& reply);
39 
40     int32_t HandleGetDuration(MessageParcel& data, MessageParcel& reply);
41 
42     int32_t HandleGetCastAVPlayBackState(MessageParcel& data, MessageParcel& reply);
43 
44     int32_t HandleGetCurrentItem(MessageParcel& data, MessageParcel& reply);
45 
46     int32_t HandleGetValidCommands(MessageParcel& data, MessageParcel& reply);
47 
48     int32_t HandleSetDisplaySurface(MessageParcel& data, MessageParcel& reply);
49 
50     int32_t HandleSetCastPlaybackFilter(MessageParcel& data, MessageParcel& reply);
51 
52     int32_t HandleProcessMediaKeyResponse(MessageParcel& data, MessageParcel& reply);
53 
54     int32_t HandleRegisterCallbackInner(MessageParcel& data, MessageParcel& reply);
55 
56     int32_t HandleAddAvailableCommand(MessageParcel& data, MessageParcel& reply);
57 
58     int32_t HandleRemoveAvailableCommand(MessageParcel& data, MessageParcel& reply);
59 
60     int32_t HandleDestroy(MessageParcel& data, MessageParcel& reply);
61 
62     static bool CheckInterfaceToken(MessageParcel& data);
63 
64     using HandlerFunc = std::function<int32_t(MessageParcel&, MessageParcel&)>;
65     std::map<uint32_t, HandlerFunc> handlers = {
66         {CAST_CONTROLLER_CMD_SEND_CONTROL_COMMAND,
67             [this](MessageParcel& data, MessageParcel& reply) { return HandleSendControlCommand(data, reply); }},
68         {CAST_CONTROLLER_CMD_START,
69             [this](MessageParcel& data, MessageParcel& reply) { return HandleStart(data, reply); }},
70         {CAST_CONTROLLER_CMD_PREPARE,
71             [this](MessageParcel& data, MessageParcel& reply) { return HandlePrepare(data, reply); }},
72         {CAST_CONTROLLER_CMD_GET_DURATION,
73             [this](MessageParcel& data, MessageParcel& reply) { return HandleGetDuration(data, reply); }},
74         {CAST_CONTROLLER_CMD_GET_CAST_AV_PLAYBACK_STATE,
75             [this](MessageParcel& data, MessageParcel& reply) { return HandleGetCastAVPlayBackState(data, reply); }},
76         {CAST_CONTROLLER_CMD_GET_CURRENT_ITEM,
77             [this](MessageParcel& data, MessageParcel& reply) { return HandleGetCurrentItem(data, reply); }},
78         {CAST_CONTROLLER_CMD_GET_VALID_COMMANDS,
79             [this](MessageParcel& data, MessageParcel& reply) { return HandleGetValidCommands(data, reply); }},
80         {CAST_CONTROLLER_CMD_SET_DISPLAY_SURFACE,
81             [this](MessageParcel& data, MessageParcel& reply) { return HandleSetDisplaySurface(data, reply); }},
82         {CAST_CONTROLLER_CMD_SET_CAST_PLAYBACK_FILTER,
83             [this](MessageParcel& data, MessageParcel& reply) { return HandleSetCastPlaybackFilter(data, reply); }},
84         {CAST_CONTROLLER_CMD_PROVIDE_KEY_RESPONSE,
85             [this](MessageParcel& data, MessageParcel& reply) { return HandleProcessMediaKeyResponse(data, reply); }},
86         {CAST_CONTROLLER_CMD_REGISTER_CALLBACK,
87             [this](MessageParcel& data, MessageParcel& reply) { return HandleRegisterCallbackInner(data, reply); }},
88         {CAST_CONTROLLER_CMD_DESTROY,
89             [this](MessageParcel& data, MessageParcel& reply) { return HandleDestroy(data, reply); }},
90         {CAST_CONTROLLER_CMD_ADD_AVAILABLE_COMMAND,
91             [this](MessageParcel& data, MessageParcel& reply) { return HandleAddAvailableCommand(data, reply); }},
92         {CAST_CONTROLLER_CMD_REMOVE_AVAILABLE_COMMAND,
93             [this](MessageParcel& data, MessageParcel& reply) { return HandleRemoveAvailableCommand(data, reply); }}
94     };
95     std::map<uint32_t, std::string> mapCodeToFuncNameXCollie = {
96         {CAST_CONTROLLER_CMD_SEND_CONTROL_COMMAND, "HandleSendControlCommand"},
97         {CAST_CONTROLLER_CMD_START, "HandleStart"},
98         {CAST_CONTROLLER_CMD_PREPARE, "HandlePrepare"},
99         {CAST_CONTROLLER_CMD_GET_DURATION, "HandleGetDuration"},
100         {CAST_CONTROLLER_CMD_GET_CAST_AV_PLAYBACK_STATE, "HandleGetCastAVPlayBackState"},
101         {CAST_CONTROLLER_CMD_GET_CURRENT_ITEM, "HandleGetCurrentItem"},
102         {CAST_CONTROLLER_CMD_GET_VALID_COMMANDS, "HandleGetValidCommands"},
103         {CAST_CONTROLLER_CMD_SET_DISPLAY_SURFACE, "HandleSetDisplaySurface"},
104         {CAST_CONTROLLER_CMD_SET_CAST_PLAYBACK_FILTER, "HandleSetCastPlaybackFilter"},
105         {CAST_CONTROLLER_CMD_PROVIDE_KEY_RESPONSE, "HandleProvideKeyResponse"},
106         {CAST_CONTROLLER_CMD_REGISTER_CALLBACK, "HandleRegisterCallbackInner"},
107         {CAST_CONTROLLER_CMD_DESTROY, "HandleDestroy"},
108         {CAST_CONTROLLER_CMD_ADD_AVAILABLE_COMMAND, "HandleAddAvailableCommand"},
109         {CAST_CONTROLLER_CMD_REMOVE_AVAILABLE_COMMAND, "HandleRemoveAvailableCommand"}
110     };
111     const size_t defaultIpcCapacity = 1048576; // Increase the IPC default capacity(200K) to 1M
112 };
113 } // namespace OHOS::AVSession
114 #endif // OHOS_AVCAST_CONTROLLER_STUB_H
115