The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 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 | |
| 25 | namespace android { |
| 26 | |
| 27 | enum { |
Dave Sparks | d6289b1 | 2009-05-07 19:27:32 -0700 | [diff] [blame] | 28 | NOTIFY_CALLBACK = IBinder::FIRST_CALL_TRANSACTION, |
Dave Sparks | 2a04aef | 2009-05-07 12:25:25 -0700 | [diff] [blame] | 29 | DATA_CALLBACK, |
Dave Sparks | 59c1a93 | 2009-07-08 15:56:53 -0700 | [diff] [blame] | 30 | DATA_CALLBACK_TIMESTAMP, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 31 | }; |
| 32 | |
| 33 | class BpCameraClient: public BpInterface<ICameraClient> |
| 34 | { |
| 35 | public: |
| 36 | BpCameraClient(const sp<IBinder>& impl) |
| 37 | : BpInterface<ICameraClient>(impl) |
| 38 | { |
| 39 | } |
| 40 | |
Dave Sparks | 2a04aef | 2009-05-07 12:25:25 -0700 | [diff] [blame] | 41 | // 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 Sparks | 59c1a93 | 2009-07-08 15:56:53 -0700 | [diff] [blame] | 64 | // 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 Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 75 | }; |
| 76 | |
| 77 | IMPLEMENT_META_INTERFACE(CameraClient, "android.hardware.ICameraClient"); |
| 78 | |
| 79 | // ---------------------------------------------------------------------- |
| 80 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 81 | status_t BnCameraClient::onTransact( |
| 82 | uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) |
| 83 | { |
| 84 | switch(code) { |
Dave Sparks | 2a04aef | 2009-05-07 12:25:25 -0700 | [diff] [blame] | 85 | 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 Sparks | 59c1a93 | 2009-07-08 15:56:53 -0700 | [diff] [blame] | 95 | LOGV("DATA_CALLBACK"); |
Dave Sparks | 2a04aef | 2009-05-07 12:25:25 -0700 | [diff] [blame] | 96 | 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 Sparks | 59c1a93 | 2009-07-08 15:56:53 -0700 | [diff] [blame] | 102 | 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 Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 111 | default: |
| 112 | return BBinder::onTransact(code, data, reply, flags); |
| 113 | } |
| 114 | } |
| 115 | |
| 116 | // ---------------------------------------------------------------------------- |
| 117 | |
| 118 | }; // namespace android |
| 119 | |