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
46ddbdb35d176266b5ab64c30178f5cb76c5b1b4b4Chih-Chung Chang    // get information about a camera
47ddbdb35d176266b5ab64c30178f5cb76c5b1b4b4Chih-Chung Chang    virtual status_t getCameraInfo(int cameraId,
48ddbdb35d176266b5ab64c30178f5cb76c5b1b4b4Chih-Chung Chang                                   struct CameraInfo* cameraInfo) {
49ddbdb35d176266b5ab64c30178f5cb76c5b1b4b4Chih-Chung Chang        Parcel data, reply;
50ddbdb35d176266b5ab64c30178f5cb76c5b1b4b4Chih-Chung Chang        data.writeInterfaceToken(ICameraService::getInterfaceDescriptor());
51ddbdb35d176266b5ab64c30178f5cb76c5b1b4b4Chih-Chung Chang        data.writeInt32(cameraId);
52ddbdb35d176266b5ab64c30178f5cb76c5b1b4b4Chih-Chung Chang        remote()->transact(BnCameraService::GET_CAMERA_INFO, data, &reply);
53ddbdb35d176266b5ab64c30178f5cb76c5b1b4b4Chih-Chung Chang        cameraInfo->facing = reply.readInt32();
54ddbdb35d176266b5ab64c30178f5cb76c5b1b4b4Chih-Chung Chang        cameraInfo->orientation = reply.readInt32();
55ddbdb35d176266b5ab64c30178f5cb76c5b1b4b4Chih-Chung Chang        return reply.readInt32();
56ddbdb35d176266b5ab64c30178f5cb76c5b1b4b4Chih-Chung Chang    }
57ddbdb35d176266b5ab64c30178f5cb76c5b1b4b4Chih-Chung Chang
583cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian    // connect to camera service
5908ad5efcef90e24db2863c0f85972ed05fe848a2Wu-cheng Li    virtual sp<ICamera> connect(const sp<ICameraClient>& cameraClient, int cameraId)
603cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian    {
613cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian        Parcel data, reply;
623cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian        data.writeInterfaceToken(ICameraService::getInterfaceDescriptor());
633cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian        data.writeStrongBinder(cameraClient->asBinder());
6435a055b8bfc6f3cbea409b2897caf936654519cbChih-Chung Chang        data.writeInt32(cameraId);
653cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian        remote()->transact(BnCameraService::CONNECT, data, &reply);
663cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian        return interface_cast<ICamera>(reply.readStrongBinder());
673cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian    }
683cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian};
693cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian
703cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias AgopianIMPLEMENT_META_INTERFACE(CameraService, "android.hardware.ICameraService");
713cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian
723cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian// ----------------------------------------------------------------------
733cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian
743cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopianstatus_t BnCameraService::onTransact(
753cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian    uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
763cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian{
773cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian    switch(code) {
7835a055b8bfc6f3cbea409b2897caf936654519cbChih-Chung Chang        case GET_NUMBER_OF_CAMERAS: {
7935a055b8bfc6f3cbea409b2897caf936654519cbChih-Chung Chang            CHECK_INTERFACE(ICameraService, data, reply);
8035a055b8bfc6f3cbea409b2897caf936654519cbChih-Chung Chang            reply->writeInt32(getNumberOfCameras());
8135a055b8bfc6f3cbea409b2897caf936654519cbChih-Chung Chang            return NO_ERROR;
8235a055b8bfc6f3cbea409b2897caf936654519cbChih-Chung Chang        } break;
83ddbdb35d176266b5ab64c30178f5cb76c5b1b4b4Chih-Chung Chang        case GET_CAMERA_INFO: {
84ddbdb35d176266b5ab64c30178f5cb76c5b1b4b4Chih-Chung Chang            CHECK_INTERFACE(ICameraService, data, reply);
85ddbdb35d176266b5ab64c30178f5cb76c5b1b4b4Chih-Chung Chang            CameraInfo cameraInfo;
86ddbdb35d176266b5ab64c30178f5cb76c5b1b4b4Chih-Chung Chang            memset(&cameraInfo, 0, sizeof(cameraInfo));
87ddbdb35d176266b5ab64c30178f5cb76c5b1b4b4Chih-Chung Chang            status_t result = getCameraInfo(data.readInt32(), &cameraInfo);
88ddbdb35d176266b5ab64c30178f5cb76c5b1b4b4Chih-Chung Chang            reply->writeInt32(cameraInfo.facing);
89ddbdb35d176266b5ab64c30178f5cb76c5b1b4b4Chih-Chung Chang            reply->writeInt32(cameraInfo.orientation);
90ddbdb35d176266b5ab64c30178f5cb76c5b1b4b4Chih-Chung Chang            reply->writeInt32(result);
91ddbdb35d176266b5ab64c30178f5cb76c5b1b4b4Chih-Chung Chang            return NO_ERROR;
92ddbdb35d176266b5ab64c30178f5cb76c5b1b4b4Chih-Chung Chang        } break;
933cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian        case CONNECT: {
943cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian            CHECK_INTERFACE(ICameraService, data, reply);
953cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian            sp<ICameraClient> cameraClient = interface_cast<ICameraClient>(data.readStrongBinder());
9608ad5efcef90e24db2863c0f85972ed05fe848a2Wu-cheng Li            sp<ICamera> camera = connect(cameraClient, data.readInt32());
973cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian            reply->writeStrongBinder(camera->asBinder());
983cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian            return NO_ERROR;
993cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian        } break;
1003cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian        default:
1013cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian            return BBinder::onTransact(code, data, reply, flags);
1023cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian    }
1033cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian}
1043cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian
1053cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian// ----------------------------------------------------------------------------
1063cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian
1073cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian}; // namespace android
108