1/* 2** 3** Copyright 2013, 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/ICameraServiceListener.h> 26 27namespace android { 28 29namespace { 30 enum { 31 STATUS_CHANGED = IBinder::FIRST_CALL_TRANSACTION, 32 TORCH_STATUS_CHANGED, 33 }; 34}; // namespace anonymous 35 36class BpCameraServiceListener: public BpInterface<ICameraServiceListener> 37{ 38 39public: 40 BpCameraServiceListener(const sp<IBinder>& impl) 41 : BpInterface<ICameraServiceListener>(impl) 42 { 43 } 44 45 virtual void onStatusChanged(Status status, int32_t cameraId) 46 { 47 Parcel data, reply; 48 data.writeInterfaceToken(ICameraServiceListener::getInterfaceDescriptor()); 49 50 data.writeInt32(static_cast<int32_t>(status)); 51 data.writeInt32(cameraId); 52 53 remote()->transact(STATUS_CHANGED, 54 data, 55 &reply, 56 IBinder::FLAG_ONEWAY); 57 } 58 59 virtual void onTorchStatusChanged(TorchStatus status, const String16 &cameraId) 60 { 61 Parcel data, reply; 62 data.writeInterfaceToken(ICameraServiceListener::getInterfaceDescriptor()); 63 64 data.writeInt32(static_cast<int32_t>(status)); 65 data.writeString16(cameraId); 66 67 remote()->transact(TORCH_STATUS_CHANGED, 68 data, 69 &reply, 70 IBinder::FLAG_ONEWAY); 71 } 72}; 73 74IMPLEMENT_META_INTERFACE(CameraServiceListener, "android.hardware.ICameraServiceListener"); 75 76// ---------------------------------------------------------------------- 77 78status_t BnCameraServiceListener::onTransact(uint32_t code, const Parcel& data, Parcel* reply, 79 uint32_t flags) { 80 switch(code) { 81 case STATUS_CHANGED: { 82 CHECK_INTERFACE(ICameraServiceListener, data, reply); 83 84 Status status = static_cast<Status>(data.readInt32()); 85 int32_t cameraId = data.readInt32(); 86 87 onStatusChanged(status, cameraId); 88 89 return NO_ERROR; 90 } break; 91 case TORCH_STATUS_CHANGED: { 92 CHECK_INTERFACE(ICameraServiceListener, data, reply); 93 94 TorchStatus status = static_cast<TorchStatus>(data.readInt32()); 95 String16 cameraId = data.readString16(); 96 97 onTorchStatusChanged(status, cameraId); 98 99 return NO_ERROR; 100 } break; 101 default: 102 return BBinder::onTransact(code, data, reply, flags); 103 } 104} 105 106// ---------------------------------------------------------------------------- 107 108}; // namespace android 109