blob: a88fd48b58a1a281b8704b7dd3e8cbf8be25a8cd [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 {
Dave Sparks93b94582009-05-07 19:27:32 -070028 NOTIFY_CALLBACK = IBinder::FIRST_CALL_TRANSACTION,
Dave Sparks9b352332009-05-07 12:25:25 -070029 DATA_CALLBACK,
The Android Open Source Projectedbf3b62009-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 Sparks9b352332009-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 Projectedbf3b62009-03-03 19:31:44 -080063};
64
65IMPLEMENT_META_INTERFACE(CameraClient, "android.hardware.ICameraClient");
66
67// ----------------------------------------------------------------------
68
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080069status_t BnCameraClient::onTransact(
70 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
71{
72 switch(code) {
Dave Sparks9b352332009-05-07 12:25:25 -070073 case NOTIFY_CALLBACK: {
74 LOGV("NOTIFY_CALLBACK");
75 CHECK_INTERFACE(ICameraClient, data, reply);
76 int32_t msgType = data.readInt32();
77 int32_t ext1 = data.readInt32();
78 int32_t ext2 = data.readInt32();
79 notifyCallback(msgType, ext1, ext2);
80 return NO_ERROR;
81 } break;
82 case DATA_CALLBACK: {
83 LOGV("RAW_CALLBACK");
84 CHECK_INTERFACE(ICameraClient, data, reply);
85 int32_t msgType = data.readInt32();
86 sp<IMemory> imageData = interface_cast<IMemory>(data.readStrongBinder());
87 dataCallback(msgType, imageData);
88 return NO_ERROR;
89 } break;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080090 default:
91 return BBinder::onTransact(code, data, reply, flags);
92 }
93}
94
95// ----------------------------------------------------------------------------
96
97}; // namespace android
98