blob: c74298a84bb97e0f1d9dc67a1720399692cef980 [file] [log] [blame]
Mathias Agopian3cf61352010-02-09 17:46:37 -08001/*
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
Chih-Chung Chang35a055b2010-05-06 16:36:58 +080037 // 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 Changddbdb352010-06-10 13:32:16 +080046 // 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
Mathias Agopian3cf61352010-02-09 17:46:37 -080058 // connect to camera service
Wu-cheng Li2fd24402012-02-23 19:01:00 -080059 virtual sp<ICamera> connect(const sp<ICameraClient>& cameraClient, int cameraId,
60 bool force, bool keep)
Mathias Agopian3cf61352010-02-09 17:46:37 -080061 {
62 Parcel data, reply;
63 data.writeInterfaceToken(ICameraService::getInterfaceDescriptor());
64 data.writeStrongBinder(cameraClient->asBinder());
Chih-Chung Chang35a055b2010-05-06 16:36:58 +080065 data.writeInt32(cameraId);
Wu-cheng Li2fd24402012-02-23 19:01:00 -080066 data.writeInt32(force);
67 data.writeInt32(keep);
Mathias Agopian3cf61352010-02-09 17:46:37 -080068 remote()->transact(BnCameraService::CONNECT, data, &reply);
69 return interface_cast<ICamera>(reply.readStrongBinder());
70 }
71};
72
73IMPLEMENT_META_INTERFACE(CameraService, "android.hardware.ICameraService");
74
75// ----------------------------------------------------------------------
76
77status_t BnCameraService::onTransact(
78 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
79{
80 switch(code) {
Chih-Chung Chang35a055b2010-05-06 16:36:58 +080081 case GET_NUMBER_OF_CAMERAS: {
82 CHECK_INTERFACE(ICameraService, data, reply);
83 reply->writeInt32(getNumberOfCameras());
84 return NO_ERROR;
85 } break;
Chih-Chung Changddbdb352010-06-10 13:32:16 +080086 case GET_CAMERA_INFO: {
87 CHECK_INTERFACE(ICameraService, data, reply);
88 CameraInfo cameraInfo;
89 memset(&cameraInfo, 0, sizeof(cameraInfo));
90 status_t result = getCameraInfo(data.readInt32(), &cameraInfo);
91 reply->writeInt32(cameraInfo.facing);
92 reply->writeInt32(cameraInfo.orientation);
93 reply->writeInt32(result);
94 return NO_ERROR;
95 } break;
Mathias Agopian3cf61352010-02-09 17:46:37 -080096 case CONNECT: {
97 CHECK_INTERFACE(ICameraService, data, reply);
98 sp<ICameraClient> cameraClient = interface_cast<ICameraClient>(data.readStrongBinder());
Wu-cheng Li2fd24402012-02-23 19:01:00 -080099 const int cameraId = data.readInt32();
100 const int force = data.readInt32();
101 const int keep = data.readInt32();
102 sp<ICamera> camera = connect(cameraClient, cameraId, force, keep);
Mathias Agopian3cf61352010-02-09 17:46:37 -0800103 reply->writeStrongBinder(camera->asBinder());
104 return NO_ERROR;
105 } break;
106 default:
107 return BBinder::onTransact(code, data, reply, flags);
108 }
109}
110
111// ----------------------------------------------------------------------------
112
113}; // namespace android