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 | #include <stdint.h> |
| 19 | #include <sys/types.h> |
| 20 | |
Mathias Agopian | 0795272 | 2009-05-19 19:08:10 -0700 | [diff] [blame] | 21 | #include <binder/Parcel.h> |
| 22 | #include <binder/IPCThreadState.h> |
| 23 | #include <binder/IServiceManager.h> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 24 | |
Mathias Agopian | 000479f | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 25 | #include <camera/ICameraService.h> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 26 | |
| 27 | namespace android { |
| 28 | |
| 29 | class BpCameraService: public BpInterface<ICameraService> |
| 30 | { |
| 31 | public: |
| 32 | BpCameraService(const sp<IBinder>& impl) |
| 33 | : BpInterface<ICameraService>(impl) |
| 34 | { |
| 35 | } |
| 36 | |
Chih-Chung Chang | e25cc65 | 2010-05-06 16:36:58 +0800 | [diff] [blame] | 37 | // get number of cameras available |
| 38 | virtual int32_t getNumberOfCameras() |
| 39 | { |
| 40 | Parcel data, reply; |
| 41 | data.writeInterfaceToken(ICameraService::getInterfaceDescriptor()); |
| 42 | remote()->transact(BnCameraService::GET_NUMBER_OF_CAMERAS, data, &reply); |
| 43 | return reply.readInt32(); |
| 44 | } |
| 45 | |
Chih-Chung Chang | b8bb78f | 2010-06-10 13:32:16 +0800 | [diff] [blame] | 46 | // get information about a camera |
| 47 | virtual status_t getCameraInfo(int cameraId, |
| 48 | struct CameraInfo* cameraInfo) { |
| 49 | Parcel data, reply; |
| 50 | data.writeInterfaceToken(ICameraService::getInterfaceDescriptor()); |
| 51 | data.writeInt32(cameraId); |
| 52 | remote()->transact(BnCameraService::GET_CAMERA_INFO, data, &reply); |
| 53 | cameraInfo->facing = reply.readInt32(); |
| 54 | cameraInfo->orientation = reply.readInt32(); |
| 55 | return reply.readInt32(); |
| 56 | } |
| 57 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 58 | // connect to camera service |
Chih-Chung Chang | e25cc65 | 2010-05-06 16:36:58 +0800 | [diff] [blame] | 59 | virtual sp<ICamera> connect(const sp<ICameraClient>& cameraClient, int cameraId) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 60 | { |
| 61 | Parcel data, reply; |
| 62 | data.writeInterfaceToken(ICameraService::getInterfaceDescriptor()); |
| 63 | data.writeStrongBinder(cameraClient->asBinder()); |
Chih-Chung Chang | e25cc65 | 2010-05-06 16:36:58 +0800 | [diff] [blame] | 64 | data.writeInt32(cameraId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 65 | remote()->transact(BnCameraService::CONNECT, data, &reply); |
| 66 | return interface_cast<ICamera>(reply.readStrongBinder()); |
| 67 | } |
| 68 | }; |
| 69 | |
| 70 | IMPLEMENT_META_INTERFACE(CameraService, "android.hardware.ICameraService"); |
| 71 | |
| 72 | // ---------------------------------------------------------------------- |
| 73 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 74 | status_t BnCameraService::onTransact( |
| 75 | uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) |
| 76 | { |
| 77 | switch(code) { |
Chih-Chung Chang | e25cc65 | 2010-05-06 16:36:58 +0800 | [diff] [blame] | 78 | case GET_NUMBER_OF_CAMERAS: { |
| 79 | CHECK_INTERFACE(ICameraService, data, reply); |
| 80 | reply->writeInt32(getNumberOfCameras()); |
| 81 | return NO_ERROR; |
| 82 | } break; |
Chih-Chung Chang | b8bb78f | 2010-06-10 13:32:16 +0800 | [diff] [blame] | 83 | case GET_CAMERA_INFO: { |
| 84 | CHECK_INTERFACE(ICameraService, data, reply); |
| 85 | CameraInfo cameraInfo; |
| 86 | memset(&cameraInfo, 0, sizeof(cameraInfo)); |
| 87 | status_t result = getCameraInfo(data.readInt32(), &cameraInfo); |
| 88 | reply->writeInt32(cameraInfo.facing); |
| 89 | reply->writeInt32(cameraInfo.orientation); |
| 90 | reply->writeInt32(result); |
| 91 | return NO_ERROR; |
| 92 | } break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 93 | case CONNECT: { |
| 94 | CHECK_INTERFACE(ICameraService, data, reply); |
| 95 | sp<ICameraClient> cameraClient = interface_cast<ICameraClient>(data.readStrongBinder()); |
Chih-Chung Chang | e25cc65 | 2010-05-06 16:36:58 +0800 | [diff] [blame] | 96 | sp<ICamera> camera = connect(cameraClient, data.readInt32()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 97 | reply->writeStrongBinder(camera->asBinder()); |
| 98 | return NO_ERROR; |
| 99 | } break; |
| 100 | default: |
| 101 | return BBinder::onTransact(code, data, reply, flags); |
| 102 | } |
| 103 | } |
| 104 | |
| 105 | // ---------------------------------------------------------------------------- |
| 106 | |
| 107 | }; // namespace android |
| 108 | |