1 /*
2  * Copyright 2019 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #define LOG_TAG "IRegionSamplingListener"
18 //#define LOG_NDEBUG 0
19 
20 #include <gui/IRegionSamplingListener.h>
21 
22 namespace android {
23 
24 namespace { // Anonymous
25 
26 enum class Tag : uint32_t {
27     ON_SAMPLE_COLLECTED = IBinder::FIRST_CALL_TRANSACTION,
28     LAST = ON_SAMPLE_COLLECTED,
29 };
30 
31 } // Anonymous namespace
32 
33 class BpRegionSamplingListener : public SafeBpInterface<IRegionSamplingListener> {
34 public:
BpRegionSamplingListener(const sp<IBinder> & impl)35     explicit BpRegionSamplingListener(const sp<IBinder>& impl)
36           : SafeBpInterface<IRegionSamplingListener>(impl, "BpRegionSamplingListener") {}
37 
38     ~BpRegionSamplingListener() override;
39 
onSampleCollected(float medianLuma)40     void onSampleCollected(float medianLuma) override {
41         callRemoteAsync<decltype(
42                 &IRegionSamplingListener::onSampleCollected)>(Tag::ON_SAMPLE_COLLECTED, medianLuma);
43     }
44 };
45 
46 // Out-of-line virtual method definitions to trigger vtable emission in this translation unit (see
47 // clang warning -Wweak-vtables)
48 BpRegionSamplingListener::~BpRegionSamplingListener() = default;
49 
50 IMPLEMENT_META_INTERFACE(RegionSamplingListener, "android.gui.IRegionSamplingListener");
51 
onTransact(uint32_t code,const Parcel & data,Parcel * reply,uint32_t flags)52 status_t BnRegionSamplingListener::onTransact(uint32_t code, const Parcel& data, Parcel* reply,
53                                               uint32_t flags) {
54     if (code < IBinder::FIRST_CALL_TRANSACTION || code > static_cast<uint32_t>(Tag::LAST)) {
55         return BBinder::onTransact(code, data, reply, flags);
56     }
57     auto tag = static_cast<Tag>(code);
58     switch (tag) {
59         case Tag::ON_SAMPLE_COLLECTED:
60             return callLocalAsync(data, reply, &IRegionSamplingListener::onSampleCollected);
61     }
62 }
63 
64 } // namespace android
65