blob: 0fdb85a7a8390af65755dd8431768470b96ce86e [file] [log] [blame]
Igor Murashkin634a5152013-02-20 17:15:11 -08001/*
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 "IProCameraCallbacks"
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/IProCameraCallbacks.h>
30
Igor Murashkine7ee7632013-06-11 18:10:18 -070031#include "camera/CameraMetadata.h"
Igor Murashkina91537e2013-02-21 12:02:29 -080032
Igor Murashkin634a5152013-02-20 17:15:11 -080033namespace android {
34
35enum {
36 NOTIFY_CALLBACK = IBinder::FIRST_CALL_TRANSACTION,
Igor Murashkin53765732013-02-20 17:41:57 -080037 LOCK_STATUS_CHANGED,
Igor Murashkina91537e2013-02-21 12:02:29 -080038 RESULT_RECEIVED,
Igor Murashkin634a5152013-02-20 17:15:11 -080039};
40
41class BpProCameraCallbacks: public BpInterface<IProCameraCallbacks>
42{
43public:
44 BpProCameraCallbacks(const sp<IBinder>& impl)
45 : BpInterface<IProCameraCallbacks>(impl)
46 {
47 }
48
49 // generic callback from camera service to app
50 void notifyCallback(int32_t msgType, int32_t ext1, int32_t ext2)
51 {
52 ALOGV("notifyCallback");
53 Parcel data, reply;
54 data.writeInterfaceToken(IProCameraCallbacks::getInterfaceDescriptor());
55 data.writeInt32(msgType);
56 data.writeInt32(ext1);
57 data.writeInt32(ext2);
58 remote()->transact(NOTIFY_CALLBACK, data, &reply, IBinder::FLAG_ONEWAY);
59 }
60
Igor Murashkin53765732013-02-20 17:41:57 -080061 void onLockStatusChanged(LockStatus newLockStatus) {
62 ALOGV("onLockStatusChanged");
63 Parcel data, reply;
64 data.writeInterfaceToken(IProCameraCallbacks::getInterfaceDescriptor());
65 data.writeInt32(newLockStatus);
66 remote()->transact(LOCK_STATUS_CHANGED, data, &reply,
67 IBinder::FLAG_ONEWAY);
68 }
Igor Murashkina91537e2013-02-21 12:02:29 -080069
70 void onResultReceived(int32_t frameId, camera_metadata* result) {
71 ALOGV("onResultReceived");
72 Parcel data, reply;
73 data.writeInterfaceToken(IProCameraCallbacks::getInterfaceDescriptor());
74 data.writeInt32(frameId);
Igor Murashkine7ee7632013-06-11 18:10:18 -070075 CameraMetadata::writeToParcel(data, result);
Igor Murashkina91537e2013-02-21 12:02:29 -080076 remote()->transact(RESULT_RECEIVED, data, &reply, IBinder::FLAG_ONEWAY);
77 }
Igor Murashkin634a5152013-02-20 17:15:11 -080078};
79
80IMPLEMENT_META_INTERFACE(ProCameraCallbacks,
81 "android.hardware.IProCameraCallbacks");
82
83// ----------------------------------------------------------------------
84
85status_t BnProCameraCallbacks::onTransact(
86 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
87{
Igor Murashkin53765732013-02-20 17:41:57 -080088 ALOGV("onTransact - code = %d", code);
Igor Murashkin634a5152013-02-20 17:15:11 -080089 switch(code) {
90 case NOTIFY_CALLBACK: {
91 ALOGV("NOTIFY_CALLBACK");
92 CHECK_INTERFACE(IProCameraCallbacks, data, reply);
93 int32_t msgType = data.readInt32();
94 int32_t ext1 = data.readInt32();
95 int32_t ext2 = data.readInt32();
96 notifyCallback(msgType, ext1, ext2);
97 return NO_ERROR;
98 } break;
Igor Murashkin53765732013-02-20 17:41:57 -080099 case LOCK_STATUS_CHANGED: {
100 ALOGV("LOCK_STATUS_CHANGED");
101 CHECK_INTERFACE(IProCameraCallbacks, data, reply);
102 LockStatus newLockStatus
103 = static_cast<LockStatus>(data.readInt32());
104 onLockStatusChanged(newLockStatus);
105 return NO_ERROR;
106 } break;
Igor Murashkina91537e2013-02-21 12:02:29 -0800107 case RESULT_RECEIVED: {
108 ALOGV("RESULT_RECEIVED");
109 CHECK_INTERFACE(IProCameraCallbacks, data, reply);
110 int32_t frameId = data.readInt32();
111 camera_metadata_t *result = NULL;
Igor Murashkine7ee7632013-06-11 18:10:18 -0700112 CameraMetadata::readFromParcel(data, &result);
Igor Murashkina91537e2013-02-21 12:02:29 -0800113 onResultReceived(frameId, result);
114 return NO_ERROR;
115 break;
116 }
Igor Murashkin634a5152013-02-20 17:15:11 -0800117 default:
118 return BBinder::onTransact(code, data, reply, flags);
119 }
120}
121
122// ----------------------------------------------------------------------------
123
124}; // namespace android
125