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 #include "dcamera_sink_callback_stub.h"
17 #include "distributed_camera_errno.h"
18 #include "distributed_hardware_log.h"
19 #include "ipc_object_stub.h"
20 #include "ipc_types.h"
21 #include "message_parcel.h"
22 namespace OHOS { class MessageOption; }
23 
24 namespace OHOS {
25 namespace DistributedHardware {
DCameraSinkCallbackStub()26 DCameraSinkCallbackStub::DCameraSinkCallbackStub() : IRemoteStub(true)
27 {
28     memberFuncMap_[NOTIFY_RESOURCEINFO] = &DCameraSinkCallbackStub::OnNotifyResourceInfoInner;
29 }
30 
~DCameraSinkCallbackStub()31 DCameraSinkCallbackStub::~DCameraSinkCallbackStub()
32 {}
33 
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)34 int32_t DCameraSinkCallbackStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply,
35     MessageOption &option)
36 {
37     DHLOGI("DCameraSinkCallbackStub OnRemoteRequest code: %{public}u", code);
38     std::u16string desc = DCameraSinkCallbackStub::GetDescriptor();
39     std::u16string remoteDesc = data.ReadInterfaceToken();
40     if (desc != remoteDesc) {
41         DHLOGE("remoteDesc is invalid!");
42         return ERR_INVALID_DATA;
43     }
44 
45     switch (code) {
46         case NOTIFY_RESOURCEINFO:
47             return OnNotifyResourceInfoInner(data, reply);
48         default:
49             DHLOGE("Invalid OnRemoteRequest code=%{public}d", code);
50             return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
51     }
52     return DCAMERA_NOT_FOUND;
53 }
54 
OnNotifyResourceInfoInner(MessageParcel & data,MessageParcel & reply)55 int32_t DCameraSinkCallbackStub::OnNotifyResourceInfoInner(MessageParcel &data, MessageParcel &reply)
56 {
57     DHLOGI("DCameraSinkCallbackStub OnNotifyResourceInfoInner");
58     int32_t ret = DCAMERA_OK;
59     bool isSensitive;
60     bool isSameAccout;
61     do {
62         ResourceEventType type = static_cast<ResourceEventType>(data.ReadInt32());
63         std::string subtype = data.ReadString();
64         std::string networkId = data.ReadString();
65         ret = OnNotifyResourceInfo(type, subtype, networkId, isSensitive, isSameAccout);
66     } while (0);
67     reply.WriteInt32(ret);
68     reply.WriteBool(isSensitive);
69     reply.WriteBool(isSameAccout);
70     return DCAMERA_OK;
71 }
72 } // namespace DistributedHardware
73 } // namespace OHOS
74