blob: c6cf75c5e951d91f4ce5be0f8c84a9f0118d73a6 [file] [log] [blame]
The Android Open Source Project9066cfe2009-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 {
Dave Sparksd6289b12009-05-07 19:27:32 -070028 NOTIFY_CALLBACK = IBinder::FIRST_CALL_TRANSACTION,
Dave Sparks2a04aef2009-05-07 12:25:25 -070029 DATA_CALLBACK,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080030};
31
32class BpCameraClient: public BpInterface<ICameraClient>
33{
34public:
35 BpCameraClient(const sp<IBinder>& impl)
36 : BpInterface<ICameraClient>(impl)
37 {
38 }
39
Dave Sparks2a04aef2009-05-07 12:25:25 -070040 // generic callback from camera service to app
41 void notifyCallback(int32_t msgType, int32_t ext1, int32_t ext2)
42 {
43 LOGV("notifyCallback");
44 Parcel data, reply;
45 data.writeInterfaceToken(ICameraClient::getInterfaceDescriptor());
46 data.writeInt32(msgType);
47 data.writeInt32(ext1);
48 data.writeInt32(ext2);
49 remote()->transact(NOTIFY_CALLBACK, data, &reply, IBinder::FLAG_ONEWAY);
50 }
51
52 // generic data callback from camera service to app with image data
53 void dataCallback(int32_t msgType, const sp<IMemory>& imageData)
54 {
55 LOGV("dataCallback");
56 Parcel data, reply;
57 data.writeInterfaceToken(ICameraClient::getInterfaceDescriptor());
58 data.writeInt32(msgType);
59 data.writeStrongBinder(imageData->asBinder());
60 remote()->transact(DATA_CALLBACK, data, &reply, IBinder::FLAG_ONEWAY);
61 }
62
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080063};
64
65IMPLEMENT_META_INTERFACE(CameraClient, "android.hardware.ICameraClient");
66
67// ----------------------------------------------------------------------
68
69#define CHECK_INTERFACE(interface, data, reply) \
70 do { if (!data.enforceInterface(interface::getInterfaceDescriptor())) { \
71 LOGW("Call incorrectly routed to " #interface); \
72 return PERMISSION_DENIED; \
73 } } while (0)
74
75status_t BnCameraClient::onTransact(
76 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
77{
78 switch(code) {
Dave Sparks2a04aef2009-05-07 12:25:25 -070079 case NOTIFY_CALLBACK: {
80 LOGV("NOTIFY_CALLBACK");
81 CHECK_INTERFACE(ICameraClient, data, reply);
82 int32_t msgType = data.readInt32();
83 int32_t ext1 = data.readInt32();
84 int32_t ext2 = data.readInt32();
85 notifyCallback(msgType, ext1, ext2);
86 return NO_ERROR;
87 } break;
88 case DATA_CALLBACK: {
89 LOGV("RAW_CALLBACK");
90 CHECK_INTERFACE(ICameraClient, data, reply);
91 int32_t msgType = data.readInt32();
92 sp<IMemory> imageData = interface_cast<IMemory>(data.readStrongBinder());
93 dataCallback(msgType, imageData);
94 return NO_ERROR;
95 } break;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080096 default:
97 return BBinder::onTransact(code, data, reply, flags);
98 }
99}
100
101// ----------------------------------------------------------------------------
102
103}; // namespace android
104