ICameraService.cpp revision 634a51509ee50475f3e9f8ccf897e90fc72ded31
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 21#include <binder/Parcel.h> 22#include <binder/IPCThreadState.h> 23#include <binder/IServiceManager.h> 24 25#include <camera/ICameraService.h> 26 27namespace android { 28 29class BpCameraService: public BpInterface<ICameraService> 30{ 31public: 32 BpCameraService(const sp<IBinder>& impl) 33 : BpInterface<ICameraService>(impl) 34 { 35 } 36 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 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 58 // connect to camera service 59 virtual sp<ICamera> connect(const sp<ICameraClient>& cameraClient, int cameraId) 60 { 61 Parcel data, reply; 62 data.writeInterfaceToken(ICameraService::getInterfaceDescriptor()); 63 data.writeStrongBinder(cameraClient->asBinder()); 64 data.writeInt32(cameraId); 65 remote()->transact(BnCameraService::CONNECT, data, &reply); 66 return interface_cast<ICamera>(reply.readStrongBinder()); 67 } 68 69 // connect to camera service (pro client) 70 virtual sp<IProCameraUser> connect(const sp<IProCameraCallbacks>& cameraCb, int cameraId) 71 { 72 Parcel data, reply; 73 data.writeInterfaceToken(ICameraService::getInterfaceDescriptor()); 74 data.writeStrongBinder(cameraCb->asBinder()); 75 data.writeInt32(cameraId); 76 remote()->transact(BnCameraService::CONNECT_PRO, data, &reply); 77 return interface_cast<IProCameraUser>(reply.readStrongBinder()); 78 } 79}; 80 81IMPLEMENT_META_INTERFACE(CameraService, "android.hardware.ICameraService"); 82 83// ---------------------------------------------------------------------- 84 85status_t BnCameraService::onTransact( 86 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) 87{ 88 switch(code) { 89 case GET_NUMBER_OF_CAMERAS: { 90 CHECK_INTERFACE(ICameraService, data, reply); 91 reply->writeInt32(getNumberOfCameras()); 92 return NO_ERROR; 93 } break; 94 case GET_CAMERA_INFO: { 95 CHECK_INTERFACE(ICameraService, data, reply); 96 CameraInfo cameraInfo; 97 memset(&cameraInfo, 0, sizeof(cameraInfo)); 98 status_t result = getCameraInfo(data.readInt32(), &cameraInfo); 99 reply->writeInt32(cameraInfo.facing); 100 reply->writeInt32(cameraInfo.orientation); 101 reply->writeInt32(result); 102 return NO_ERROR; 103 } break; 104 case CONNECT: { 105 CHECK_INTERFACE(ICameraService, data, reply); 106 sp<ICameraClient> cameraClient = interface_cast<ICameraClient>(data.readStrongBinder()); 107 sp<ICamera> camera = connect(cameraClient, data.readInt32()); 108 reply->writeStrongBinder(camera->asBinder()); 109 return NO_ERROR; 110 } break; 111 case CONNECT_PRO: { 112 CHECK_INTERFACE(ICameraService, data, reply); 113 sp<IProCameraCallbacks> cameraClient = interface_cast<IProCameraCallbacks>(data.readStrongBinder()); 114 sp<IProCameraUser> camera = connect(cameraClient, data.readInt32()); 115 reply->writeStrongBinder(camera->asBinder()); 116 return NO_ERROR; 117 } break; 118 default: 119 return BBinder::onTransact(code, data, reply, flags); 120 } 121} 122 123// ---------------------------------------------------------------------------- 124 125}; // namespace android 126