ICameraServiceListener.cpp revision bfc9915f482520eb9676c6d2dbf7f1ac078d937d
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    };
33}; // namespace anonymous
34
35class BpCameraServiceListener: public BpInterface<ICameraServiceListener>
36{
37
38public:
39    BpCameraServiceListener(const sp<IBinder>& impl)
40        : BpInterface<ICameraServiceListener>(impl)
41    {
42    }
43
44    virtual void onStatusChanged(Status status, int32_t cameraId)
45    {
46        Parcel data, reply;
47        data.writeInterfaceToken(
48                              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
60IMPLEMENT_META_INTERFACE(CameraServiceListener,
61                         "android.hardware.ICameraServiceListener");
62
63// ----------------------------------------------------------------------
64
65status_t BnCameraServiceListener::onTransact(
66    uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
67{
68    switch(code) {
69        case STATUS_CHANGED: {
70            CHECK_INTERFACE(ICameraServiceListener, data, reply);
71
72            Status status = static_cast<Status>(data.readInt32());
73            int32_t cameraId = data.readInt32();
74
75            onStatusChanged(status, cameraId);
76
77            return NO_ERROR;
78        } break;
79        default:
80            return BBinder::onTransact(code, data, reply, flags);
81    }
82}
83
84// ----------------------------------------------------------------------------
85
86}; // namespace android
87