blob: e5687fef68bfc0a8506c2a839053b2bddb784a69 [file] [log] [blame]
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -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 <utils/Parcel.h>
22#include <utils/IPCThreadState.h>
23#include <utils/IServiceManager.h>
24
25#include <ui/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 // connect to camera service
38 virtual sp<ICamera> connect(const sp<ICameraClient>& cameraClient)
39 {
40 Parcel data, reply;
41 data.writeInterfaceToken(ICameraService::getInterfaceDescriptor());
42 data.writeStrongBinder(cameraClient->asBinder());
43 remote()->transact(BnCameraService::CONNECT, data, &reply);
44 return interface_cast<ICamera>(reply.readStrongBinder());
45 }
46};
47
48IMPLEMENT_META_INTERFACE(CameraService, "android.hardware.ICameraService");
49
50// ----------------------------------------------------------------------
51
52#define CHECK_INTERFACE(interface, data, reply) \
53 do { if (!data.enforceInterface(interface::getInterfaceDescriptor())) { \
54 LOGW("Call incorrectly routed to " #interface); \
55 return PERMISSION_DENIED; \
56 } } while (0)
57
58status_t BnCameraService::onTransact(
59 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
60{
61 switch(code) {
62 case CONNECT: {
63 CHECK_INTERFACE(ICameraService, data, reply);
64 sp<ICameraClient> cameraClient = interface_cast<ICameraClient>(data.readStrongBinder());
65 sp<ICamera> camera = connect(cameraClient);
66 reply->writeStrongBinder(camera->asBinder());
67 return NO_ERROR;
68 } break;
69 default:
70 return BBinder::onTransact(code, data, reply, flags);
71 }
72}
73
74// ----------------------------------------------------------------------------
75
76}; // namespace android
77