blob: 19763d7bbbff8af0f7d1f4e2a757de785dff7077 [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
29#include <camera/photography/ICameraDeviceCallbacks.h>
30#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
60 void onResultReceived(int32_t frameId, const CameraMetadata& result) {
61 ALOGV("onResultReceived");
62 Parcel data, reply;
63 data.writeInterfaceToken(ICameraDeviceCallbacks::getInterfaceDescriptor());
64 data.writeInt32(frameId);
65 result.writeToParcel(&data);
66 remote()->transact(RESULT_RECEIVED, data, &reply, IBinder::FLAG_ONEWAY);
67 data.writeNoException();
68 }
69};
70
71IMPLEMENT_META_INTERFACE(CameraDeviceCallbacks,
72 "android.hardware.photography.ICameraDeviceCallbacks");
73
74// ----------------------------------------------------------------------
75
76status_t BnCameraDeviceCallbacks::onTransact(
77 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
78{
79 ALOGV("onTransact - code = %d", code);
80 switch(code) {
81 case NOTIFY_CALLBACK: {
82 ALOGV("NOTIFY_CALLBACK");
83 CHECK_INTERFACE(ICameraDeviceCallbacks, data, reply);
84 int32_t msgType = data.readInt32();
85 int32_t ext1 = data.readInt32();
86 int32_t ext2 = data.readInt32();
87 notifyCallback(msgType, ext1, ext2);
88 data.readExceptionCode();
89 return NO_ERROR;
90 } break;
91 case RESULT_RECEIVED: {
92 ALOGV("RESULT_RECEIVED");
93 CHECK_INTERFACE(ICameraDeviceCallbacks, data, reply);
94 int32_t frameId = data.readInt32();
95 CameraMetadata result;
96 result.readFromParcel(const_cast<Parcel*>(&data));
97 onResultReceived(frameId, result);
98 data.readExceptionCode();
99 return NO_ERROR;
100 break;
101 }
102 default:
103 return BBinder::onTransact(code, data, reply, flags);
104 }
105}
106
107// ----------------------------------------------------------------------------
108
109}; // namespace android
110