blob: 59a6cf2b4ebf5ca17da4cce407f9cb3501237301 [file] [log] [blame]
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001/*
2**
3** Copyright 2008, 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 "ICameraClient"
20#include <utils/Log.h>
21#include <stdint.h>
22#include <sys/types.h>
23#include <ui/ICameraClient.h>
24
25namespace android {
26
27enum {
Jean-Baptiste Queru9660d302009-05-20 11:28:04 -070028 NOTIFY_CALLBACK = IBinder::FIRST_CALL_TRANSACTION,
29 DATA_CALLBACK,
Jean-Baptiste Queru02f54242009-07-29 14:25:07 -070030 DATA_CALLBACK_TIMESTAMP,
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080031};
32
33class BpCameraClient: public BpInterface<ICameraClient>
34{
35public:
36 BpCameraClient(const sp<IBinder>& impl)
37 : BpInterface<ICameraClient>(impl)
38 {
39 }
40
Jean-Baptiste Queru9660d302009-05-20 11:28:04 -070041 // generic callback from camera service to app
42 void notifyCallback(int32_t msgType, int32_t ext1, int32_t ext2)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080043 {
Jean-Baptiste Queru9660d302009-05-20 11:28:04 -070044 LOGV("notifyCallback");
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080045 Parcel data, reply;
46 data.writeInterfaceToken(ICameraClient::getInterfaceDescriptor());
Jean-Baptiste Queru9660d302009-05-20 11:28:04 -070047 data.writeInt32(msgType);
48 data.writeInt32(ext1);
49 data.writeInt32(ext2);
50 remote()->transact(NOTIFY_CALLBACK, data, &reply, IBinder::FLAG_ONEWAY);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080051 }
52
Jean-Baptiste Queru9660d302009-05-20 11:28:04 -070053 // generic data callback from camera service to app with image data
54 void dataCallback(int32_t msgType, const sp<IMemory>& imageData)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080055 {
Jean-Baptiste Queru9660d302009-05-20 11:28:04 -070056 LOGV("dataCallback");
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080057 Parcel data, reply;
58 data.writeInterfaceToken(ICameraClient::getInterfaceDescriptor());
Jean-Baptiste Queru9660d302009-05-20 11:28:04 -070059 data.writeInt32(msgType);
60 data.writeStrongBinder(imageData->asBinder());
61 remote()->transact(DATA_CALLBACK, data, &reply, IBinder::FLAG_ONEWAY);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080062 }
63
Jean-Baptiste Queru02f54242009-07-29 14:25:07 -070064 // generic data callback from camera service to app with image data
65 void dataCallbackTimestamp(nsecs_t timestamp, int32_t msgType, const sp<IMemory>& imageData)
66 {
67 LOGV("dataCallback");
68 Parcel data, reply;
69 data.writeInterfaceToken(ICameraClient::getInterfaceDescriptor());
70 data.writeInt64(timestamp);
71 data.writeInt32(msgType);
72 data.writeStrongBinder(imageData->asBinder());
73 remote()->transact(DATA_CALLBACK_TIMESTAMP, data, &reply, IBinder::FLAG_ONEWAY);
74 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080075};
76
77IMPLEMENT_META_INTERFACE(CameraClient, "android.hardware.ICameraClient");
78
79// ----------------------------------------------------------------------
80
81#define CHECK_INTERFACE(interface, data, reply) \
82 do { if (!data.enforceInterface(interface::getInterfaceDescriptor())) { \
83 LOGW("Call incorrectly routed to " #interface); \
84 return PERMISSION_DENIED; \
85 } } while (0)
86
87status_t BnCameraClient::onTransact(
88 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
89{
90 switch(code) {
Jean-Baptiste Queru9660d302009-05-20 11:28:04 -070091 case NOTIFY_CALLBACK: {
92 LOGV("NOTIFY_CALLBACK");
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080093 CHECK_INTERFACE(ICameraClient, data, reply);
Jean-Baptiste Queru9660d302009-05-20 11:28:04 -070094 int32_t msgType = data.readInt32();
95 int32_t ext1 = data.readInt32();
96 int32_t ext2 = data.readInt32();
97 notifyCallback(msgType, ext1, ext2);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080098 return NO_ERROR;
99 } break;
Jean-Baptiste Queru9660d302009-05-20 11:28:04 -0700100 case DATA_CALLBACK: {
Jean-Baptiste Queru02f54242009-07-29 14:25:07 -0700101 LOGV("DATA_CALLBACK");
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800102 CHECK_INTERFACE(ICameraClient, data, reply);
Jean-Baptiste Queru9660d302009-05-20 11:28:04 -0700103 int32_t msgType = data.readInt32();
104 sp<IMemory> imageData = interface_cast<IMemory>(data.readStrongBinder());
105 dataCallback(msgType, imageData);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800106 return NO_ERROR;
107 } break;
Jean-Baptiste Queru02f54242009-07-29 14:25:07 -0700108 case DATA_CALLBACK_TIMESTAMP: {
109 LOGV("DATA_CALLBACK_TIMESTAMP");
110 CHECK_INTERFACE(ICameraClient, data, reply);
111 nsecs_t timestamp = data.readInt64();
112 int32_t msgType = data.readInt32();
113 sp<IMemory> imageData = interface_cast<IMemory>(data.readStrongBinder());
114 dataCallbackTimestamp(timestamp, msgType, imageData);
115 return NO_ERROR;
116 } break;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800117 default:
118 return BBinder::onTransact(code, data, reply, flags);
119 }
120}
121
122// ----------------------------------------------------------------------------
123
124}; // namespace android
125