blob: 3cec1f47761fbf8d29f51e596f41352900ec9a6c [file] [log] [blame]
Igor Murashkine7ee7632013-06-11 18:10:18 -07001/*
2**
3** Copyright 2013, The Android Open Source Project
4**
5** Licensed under the Apache License, Version 2.0 (the "License");
6** you may not use this file except in compliance with the License.
7** You may obtain a copy of the License at
8**
9** http://www.apache.org/licenses/LICENSE-2.0
10**
11** Unless required by applicable law or agreed to in writing, software
12** distributed under the License is distributed on an "AS IS" BASIS,
13** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14** See the License for the specific language governing permissions and
15** limitations under the License.
16*/
17
18//#define LOG_NDEBUG 0
19#define LOG_TAG "ICameraDeviceCallbacks"
20#include <utils/Log.h>
21#include <stdint.h>
22#include <sys/types.h>
23
24#include <binder/Parcel.h>
25#include <gui/IGraphicBufferProducer.h>
26#include <gui/Surface.h>
27#include <utils/Mutex.h>
28
Eino-Ville Talvala7b82efe2013-07-25 17:12:35 -070029#include <camera/camera2/ICameraDeviceCallbacks.h>
Igor Murashkine7ee7632013-06-11 18:10:18 -070030#include "camera/CameraMetadata.h"
31
32namespace android {
33
34enum {
35 NOTIFY_CALLBACK = IBinder::FIRST_CALL_TRANSACTION,
36 RESULT_RECEIVED,
37};
38
39class BpCameraDeviceCallbacks: public BpInterface<ICameraDeviceCallbacks>
40{
41public:
42 BpCameraDeviceCallbacks(const sp<IBinder>& impl)
43 : BpInterface<ICameraDeviceCallbacks>(impl)
44 {
45 }
46
47 // generic callback from camera service to app
48 void notifyCallback(int32_t msgType, int32_t ext1, int32_t ext2)
49 {
50 ALOGV("notifyCallback");
51 Parcel data, reply;
52 data.writeInterfaceToken(ICameraDeviceCallbacks::getInterfaceDescriptor());
53 data.writeInt32(msgType);
54 data.writeInt32(ext1);
55 data.writeInt32(ext2);
56 remote()->transact(NOTIFY_CALLBACK, data, &reply, IBinder::FLAG_ONEWAY);
57 data.writeNoException();
58 }
59
Zhijun He11d0d442013-07-31 09:50:58 -070060 void onResultReceived(int32_t requestId, const CameraMetadata& result) {
Igor Murashkine7ee7632013-06-11 18:10:18 -070061 ALOGV("onResultReceived");
62 Parcel data, reply;
63 data.writeInterfaceToken(ICameraDeviceCallbacks::getInterfaceDescriptor());
Zhijun He11d0d442013-07-31 09:50:58 -070064 data.writeInt32(requestId);
65 data.writeInt32(1); // to mark presence of metadata object
Igor Murashkine7ee7632013-06-11 18:10:18 -070066 result.writeToParcel(&data);
67 remote()->transact(RESULT_RECEIVED, data, &reply, IBinder::FLAG_ONEWAY);
68 data.writeNoException();
69 }
70};
71
72IMPLEMENT_META_INTERFACE(CameraDeviceCallbacks,
Eino-Ville Talvala7b82efe2013-07-25 17:12:35 -070073 "android.hardware.camera2.ICameraDeviceCallbacks");
Igor Murashkine7ee7632013-06-11 18:10:18 -070074
75// ----------------------------------------------------------------------
76
77status_t BnCameraDeviceCallbacks::onTransact(
78 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
79{
80 ALOGV("onTransact - code = %d", code);
81 switch(code) {
82 case NOTIFY_CALLBACK: {
83 ALOGV("NOTIFY_CALLBACK");
84 CHECK_INTERFACE(ICameraDeviceCallbacks, data, reply);
85 int32_t msgType = data.readInt32();
86 int32_t ext1 = data.readInt32();
87 int32_t ext2 = data.readInt32();
88 notifyCallback(msgType, ext1, ext2);
89 data.readExceptionCode();
90 return NO_ERROR;
91 } break;
92 case RESULT_RECEIVED: {
93 ALOGV("RESULT_RECEIVED");
94 CHECK_INTERFACE(ICameraDeviceCallbacks, data, reply);
Zhijun He11d0d442013-07-31 09:50:58 -070095 int32_t requestId = data.readInt32();
Igor Murashkine7ee7632013-06-11 18:10:18 -070096 CameraMetadata result;
Zhijun He11d0d442013-07-31 09:50:58 -070097 if (data.readInt32() != 0) {
98 result.readFromParcel(const_cast<Parcel*>(&data));
99 } else {
100 ALOGW("No metadata object is present in result");
101 }
102 onResultReceived(requestId, result);
Igor Murashkine7ee7632013-06-11 18:10:18 -0700103 data.readExceptionCode();
104 return NO_ERROR;
105 break;
106 }
107 default:
108 return BBinder::onTransact(code, data, reply, flags);
109 }
110}
111
112// ----------------------------------------------------------------------------
113
114}; // namespace android