ICameraService.cpp revision 35a055b8bfc6f3cbea409b2897caf936654519cb
13cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian/* 23cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian** 33cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian** Copyright 2008, The Android Open Source Project 43cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian** 53cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian** Licensed under the Apache License, Version 2.0 (the "License"); 63cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian** you may not use this file except in compliance with the License. 73cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian** You may obtain a copy of the License at 83cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian** 93cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian** http://www.apache.org/licenses/LICENSE-2.0 103cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian** 113cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian** Unless required by applicable law or agreed to in writing, software 123cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian** distributed under the License is distributed on an "AS IS" BASIS, 133cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 143cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian** See the License for the specific language governing permissions and 153cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian** limitations under the License. 163cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian*/ 173cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian 183cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian#include <stdint.h> 193cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian#include <sys/types.h> 203cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian 213cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian#include <binder/Parcel.h> 223cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian#include <binder/IPCThreadState.h> 233cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian#include <binder/IServiceManager.h> 243cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian 253cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian#include <camera/ICameraService.h> 263cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian 273cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopiannamespace android { 283cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian 293cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopianclass BpCameraService: public BpInterface<ICameraService> 303cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian{ 313cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopianpublic: 323cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian BpCameraService(const sp<IBinder>& impl) 333cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian : BpInterface<ICameraService>(impl) 343cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian { 353cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian } 363cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian 3735a055b8bfc6f3cbea409b2897caf936654519cbChih-Chung Chang // get number of cameras available 3835a055b8bfc6f3cbea409b2897caf936654519cbChih-Chung Chang virtual int32_t getNumberOfCameras() 3935a055b8bfc6f3cbea409b2897caf936654519cbChih-Chung Chang { 4035a055b8bfc6f3cbea409b2897caf936654519cbChih-Chung Chang Parcel data, reply; 4135a055b8bfc6f3cbea409b2897caf936654519cbChih-Chung Chang data.writeInterfaceToken(ICameraService::getInterfaceDescriptor()); 4235a055b8bfc6f3cbea409b2897caf936654519cbChih-Chung Chang remote()->transact(BnCameraService::GET_NUMBER_OF_CAMERAS, data, &reply); 4335a055b8bfc6f3cbea409b2897caf936654519cbChih-Chung Chang return reply.readInt32(); 4435a055b8bfc6f3cbea409b2897caf936654519cbChih-Chung Chang } 4535a055b8bfc6f3cbea409b2897caf936654519cbChih-Chung Chang 463cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian // connect to camera service 4735a055b8bfc6f3cbea409b2897caf936654519cbChih-Chung Chang virtual sp<ICamera> connect(const sp<ICameraClient>& cameraClient, int cameraId) 483cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian { 493cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian Parcel data, reply; 503cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian data.writeInterfaceToken(ICameraService::getInterfaceDescriptor()); 513cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian data.writeStrongBinder(cameraClient->asBinder()); 5235a055b8bfc6f3cbea409b2897caf936654519cbChih-Chung Chang data.writeInt32(cameraId); 533cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian remote()->transact(BnCameraService::CONNECT, data, &reply); 543cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian return interface_cast<ICamera>(reply.readStrongBinder()); 553cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian } 563cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian}; 573cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian 583cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias AgopianIMPLEMENT_META_INTERFACE(CameraService, "android.hardware.ICameraService"); 593cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian 603cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian// ---------------------------------------------------------------------- 613cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian 623cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopianstatus_t BnCameraService::onTransact( 633cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) 643cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian{ 653cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian switch(code) { 6635a055b8bfc6f3cbea409b2897caf936654519cbChih-Chung Chang case GET_NUMBER_OF_CAMERAS: { 6735a055b8bfc6f3cbea409b2897caf936654519cbChih-Chung Chang CHECK_INTERFACE(ICameraService, data, reply); 6835a055b8bfc6f3cbea409b2897caf936654519cbChih-Chung Chang reply->writeInt32(getNumberOfCameras()); 6935a055b8bfc6f3cbea409b2897caf936654519cbChih-Chung Chang return NO_ERROR; 7035a055b8bfc6f3cbea409b2897caf936654519cbChih-Chung Chang } break; 713cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian case CONNECT: { 723cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian CHECK_INTERFACE(ICameraService, data, reply); 733cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian sp<ICameraClient> cameraClient = interface_cast<ICameraClient>(data.readStrongBinder()); 7435a055b8bfc6f3cbea409b2897caf936654519cbChih-Chung Chang sp<ICamera> camera = connect(cameraClient, data.readInt32()); 753cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian reply->writeStrongBinder(camera->asBinder()); 763cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian return NO_ERROR; 773cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian } break; 783cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian default: 793cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian return BBinder::onTransact(code, data, reply, flags); 803cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian } 813cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian} 823cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian 833cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian// ---------------------------------------------------------------------------- 843cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian 853cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian}; // namespace android 863cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian 87