• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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_device_stub.h"
17 #include <hdf_base.h>
18 #include <hdf_log.h>
19 #include "distributed_hardware_log.h"
20 #include "ipc_data_utils.h"
21 #include "istream_operator.h"
22 #include "istream_operator_callback.h"
23 #include "metadata_utils.h"
24 
25 #ifndef BALTIMORE_CAMERA
26 #include "cmd_common.h"
27 #endif
28 
29 namespace OHOS {
30 namespace DistributedHardware {
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)31 int32_t DCameraDeviceStub::OnRemoteRequest(uint32_t code, MessageParcel& data, MessageParcel& reply,
32     MessageOption& option)
33 {
34     int32_t ret = HDF_SUCCESS;
35     switch (code) {
36         case CMD_CAMERA_DEVICE_GET_STREAM_OPERATOR: {
37             ret = DCDeviceStubGetStreamOperator(data, reply, option);
38             break;
39         }
40         case CMD_CAMERA_DEVICE_UPDATE_SETTINGS: {
41             ret = DCDeviceStubUpdateSettings(data, reply, option);
42             break;
43         }
44         case CMD_CAMERA_DEVICE_SET_RESULT_MODE: {
45             ret = DCDeviceStubSetResultMode(data, reply, option);
46             break;
47         }
48         case CMD_CAMERA_DEVICE_GET_ENABLED_RESULTS: {
49             ret = DCDeviceStubGetEnabledReuslts(data, reply, option);
50             break;
51         }
52         case CMD_CAMERA_DEVICE_ENABLE_RESULT: {
53             ret = DCDeviceStubEnableResult(data, reply, option);
54             break;
55         }
56         case CMD_CAMERA_DEVICE_DISABLE_RESULT: {
57             ret = DCDeviceStubDisableResult(data, reply, option);
58             break;
59         }
60         case CMD_CAMERA_DEVICE_CLOSE: {
61             ret = DCDeviceStubClose(data, reply, option);
62             break;
63         }
64         default: {
65             ret = IPCObjectStub::OnRemoteRequest(code, data, reply, option);
66         }
67     }
68     return ret;
69 }
70 
DCDeviceStubGetStreamOperator(MessageParcel & data,MessageParcel & reply,MessageOption & option)71 int32_t DCameraDeviceStub::DCDeviceStubGetStreamOperator(MessageParcel& data, MessageParcel& reply,
72     MessageOption& option)
73 {
74     DHLOGI("DCameraDeviceStub::DCDeviceStubGetStreamOperator entry.");
75     if (data.ReadInterfaceToken() != DCameraDeviceStub::GetDescriptor()) {
76         DHLOGE("Invalid token.");
77         return HDF_FAILURE;
78     }
79 
80     sptr<IStreamOperatorCallback> spStreamOperatorCallback = nullptr;
81     bool flag = data.ReadBool();
82     if (flag) {
83         sptr<IRemoteObject> remoteObj = data.ReadRemoteObject();
84         spStreamOperatorCallback = OHOS::iface_cast<IStreamOperatorCallback>(remoteObj);
85         if (spStreamOperatorCallback == nullptr) {
86             DHLOGE("Read operator callback failed.");
87             return HDF_FAILURE;
88         }
89     }
90 
91     OHOS::sptr<IStreamOperator> streamOperator = nullptr;
92     CamRetCode ret = GetStreamOperator(spStreamOperatorCallback, streamOperator);
93     if (!reply.WriteInt32(static_cast<int32_t>(ret))) {
94         DHLOGE("Get stream operator failed.");
95         return HDF_FAILURE;
96     }
97 
98     bool nullFlag = (streamOperator != nullptr);
99     if (!reply.WriteBool(nullFlag)) {
100         DHLOGE("Write stream operator flag failed.");
101         return INVALID_ARGUMENT;
102     }
103 
104     if (nullFlag && !reply.WriteRemoteObject(streamOperator->AsObject())) {
105         DHLOGE("Write stream operator failed.");
106         return HDF_FAILURE;
107     }
108     return HDF_SUCCESS;
109 }
110 
DCDeviceStubUpdateSettings(MessageParcel & data,MessageParcel & reply,MessageOption & option)111 int32_t DCameraDeviceStub::DCDeviceStubUpdateSettings(MessageParcel& data, MessageParcel& reply, MessageOption& option)
112 {
113     DHLOGI("DCameraDeviceStub::DCDeviceStubUpdateSettings entry.");
114     if (data.ReadInterfaceToken() != DCameraDeviceStub::GetDescriptor()) {
115         DHLOGE("Invalid token.");
116         return HDF_FAILURE;
117     }
118 
119     std::shared_ptr<Camera::CameraMetadata> metadata = nullptr;
120     Camera::MetadataUtils::DecodeCameraMetadata(data, metadata);
121 
122     CamRetCode ret = UpdateSettings(metadata);
123     if (!reply.WriteInt32(static_cast<int32_t>(ret))) {
124         DHLOGE("Get stream operator failed.");
125         return HDF_FAILURE;
126     }
127     return HDF_SUCCESS;
128 }
129 
DCDeviceStubSetResultMode(MessageParcel & data,MessageParcel & reply,MessageOption & option)130 int32_t DCameraDeviceStub::DCDeviceStubSetResultMode(MessageParcel& data, MessageParcel& reply, MessageOption& option)
131 {
132     DHLOGI("DCameraDeviceStub::DCDeviceStubSetResultMode entry.");
133     if (data.ReadInterfaceToken() != DCameraDeviceStub::GetDescriptor()) {
134         DHLOGE("Invalid token.");
135         return HDF_FAILURE;
136     }
137 
138     ResultCallbackMode mode = static_cast<ResultCallbackMode>(data.ReadInt32());
139     CamRetCode ret = SetResultMode(mode);
140     if (!reply.WriteInt32(static_cast<int32_t>(ret))) {
141         DHLOGE("Write retcode failed.");
142         return HDF_FAILURE;
143     }
144     return HDF_SUCCESS;
145 }
146 
DCDeviceStubGetEnabledReuslts(MessageParcel & data,MessageParcel & reply,MessageOption & option)147 int32_t DCameraDeviceStub::DCDeviceStubGetEnabledReuslts(MessageParcel& data, MessageParcel& reply,
148     MessageOption& option)
149 {
150     DHLOGI("DCameraDeviceStub::DCDeviceStubGetEnabledReuslts entry.");
151     if (data.ReadInterfaceToken() != DCameraDeviceStub::GetDescriptor()) {
152         DHLOGE("Invalid token.");
153         return HDF_FAILURE;
154     }
155 
156     std::vector<int32_t> results;
157     CamRetCode ret = GetEnabledResults(results);
158     if (!reply.WriteInt32(static_cast<CamRetCode>(ret))) {
159         DHLOGE("Write retcode failed.");
160         return HDF_FAILURE;
161     }
162 
163     if (!reply.WriteInt32Vector(results)) {
164         DHLOGE("Write results failed.");
165         return HDF_FAILURE;
166     }
167     return HDF_SUCCESS;
168 }
169 
DCDeviceStubEnableResult(MessageParcel & data,MessageParcel & reply,MessageOption & option)170 int32_t DCameraDeviceStub::DCDeviceStubEnableResult(MessageParcel& data, MessageParcel& reply, MessageOption& option)
171 {
172     DHLOGI("DCameraDeviceStub::DCDeviceStubEnableResult entry.");
173     if (data.ReadInterfaceToken() != DCameraDeviceStub::GetDescriptor()) {
174         DHLOGE("Invalid token.");
175         return HDF_FAILURE;
176     }
177 
178     std::vector<int32_t> results;
179     if (!data.ReadInt32Vector(&results)) {
180         DHLOGE("Read results failed.");
181         return HDF_FAILURE;
182     }
183 
184     CamRetCode ret = EnableResult(results);
185     if (!reply.WriteInt32(static_cast<CamRetCode>(ret))) {
186         DHLOGE("Write retcode failed.");
187         return HDF_FAILURE;
188     }
189 
190     if (!reply.WriteInt32Vector(results)) {
191         DHLOGE("Write results failed.");
192         return HDF_FAILURE;
193     }
194     return HDF_SUCCESS;
195 }
196 
DCDeviceStubDisableResult(MessageParcel & data,MessageParcel & reply,MessageOption & option)197 int32_t DCameraDeviceStub::DCDeviceStubDisableResult(MessageParcel& data, MessageParcel& reply, MessageOption& option)
198 {
199     DHLOGI("DCameraDeviceStub::DCDeviceStubDisableResult entry.");
200     if (data.ReadInterfaceToken() != DCameraDeviceStub::GetDescriptor()) {
201         DHLOGE("Invalid token.");
202         return HDF_FAILURE;
203     }
204 
205     std::vector<int32_t> results;
206     if (!data.ReadInt32Vector(&results)) {
207         DHLOGE("Read results failed.");
208         return HDF_FAILURE;
209     }
210 
211     CamRetCode ret = DisableResult(results);
212     if (!reply.WriteInt32(static_cast<CamRetCode>(ret))) {
213         DHLOGE("Write retcode failed.");
214         return HDF_FAILURE;
215     }
216 
217     if (!reply.WriteInt32Vector(results)) {
218         DHLOGE("Write results failed.");
219         return HDF_FAILURE;
220     }
221     return HDF_SUCCESS;
222 }
223 
DCDeviceStubClose(MessageParcel & data,MessageParcel & reply,MessageOption & option)224 int32_t DCameraDeviceStub::DCDeviceStubClose(MessageParcel& data, MessageParcel& reply, MessageOption& option)
225 {
226     DHLOGI("DCameraDeviceStub::DCDeviceStubClose entry.");
227     if (data.ReadInterfaceToken() != DCameraDeviceStub::GetDescriptor()) {
228         DHLOGE("Invalid token.");
229         return HDF_FAILURE;
230     }
231 
232     Close();
233     return HDF_SUCCESS;
234 }
235 } // end namespace DistributedHardware
236 } // end namespace OHOS