blob: 42b4da41bb15cd41938f269f70df1362a1c5cc2f [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,
Dave Sparks59c1a932009-07-08 15:56:53 -070030 DATA_CALLBACK_TIMESTAMP,
The Android Open Source Project9066cfe2009-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
Dave Sparks2a04aef2009-05-07 12:25:25 -070041 // generic callback from camera service to app
42 void notifyCallback(int32_t msgType, int32_t ext1, int32_t ext2)
43 {
44 LOGV("notifyCallback");
45 Parcel data, reply;
46 data.writeInterfaceToken(ICameraClient::getInterfaceDescriptor());
47 data.writeInt32(msgType);
48 data.writeInt32(ext1);
49 data.writeInt32(ext2);
50 remote()->transact(NOTIFY_CALLBACK, data, &reply, IBinder::FLAG_ONEWAY);
51 }
52
53 // generic data callback from camera service to app with image data
54 void dataCallback(int32_t msgType, const sp<IMemory>& imageData)
55 {
56 LOGV("dataCallback");
57 Parcel data, reply;
58 data.writeInterfaceToken(ICameraClient::getInterfaceDescriptor());
59 data.writeInt32(msgType);
60 data.writeStrongBinder(imageData->asBinder());
61 remote()->transact(DATA_CALLBACK, data, &reply, IBinder::FLAG_ONEWAY);
62 }
63
Dave Sparks59c1a932009-07-08 15:56:53 -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 Project9066cfe2009-03-03 19:31:44 -080075};
76
77IMPLEMENT_META_INTERFACE(CameraClient, "android.hardware.ICameraClient");
78
79// ----------------------------------------------------------------------
80
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080081status_t BnCameraClient::onTransact(
82 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
83{
84 switch(code) {
Dave Sparks2a04aef2009-05-07 12:25:25 -070085 case NOTIFY_CALLBACK: {
86 LOGV("NOTIFY_CALLBACK");
87 CHECK_INTERFACE(ICameraClient, data, reply);
88 int32_t msgType = data.readInt32();
89 int32_t ext1 = data.readInt32();
90 int32_t ext2 = data.readInt32();
91 notifyCallback(msgType, ext1, ext2);
92 return NO_ERROR;
93 } break;
94 case DATA_CALLBACK: {
Dave Sparks59c1a932009-07-08 15:56:53 -070095 LOGV("DATA_CALLBACK");
Dave Sparks2a04aef2009-05-07 12:25:25 -070096 CHECK_INTERFACE(ICameraClient, data, reply);
97 int32_t msgType = data.readInt32();
98 sp<IMemory> imageData = interface_cast<IMemory>(data.readStrongBinder());
99 dataCallback(msgType, imageData);
100 return NO_ERROR;
101 } break;
Dave Sparks59c1a932009-07-08 15:56:53 -0700102 case DATA_CALLBACK_TIMESTAMP: {
103 LOGV("DATA_CALLBACK_TIMESTAMP");
104 CHECK_INTERFACE(ICameraClient, data, reply);
105 nsecs_t timestamp = data.readInt64();
106 int32_t msgType = data.readInt32();
107 sp<IMemory> imageData = interface_cast<IMemory>(data.readStrongBinder());
108 dataCallbackTimestamp(timestamp, msgType, imageData);
109 return NO_ERROR;
110 } break;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800111 default:
112 return BBinder::onTransact(code, data, reply, flags);
113 }
114}
115
116// ----------------------------------------------------------------------------
117
118}; // namespace android
119