1 /*
2 **
3 ** Copyright 2014, 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 #include <binder/IMemory.h>
21 #include <binder/Parcel.h>
22 #include <binder/IPCThreadState.h>
23 #include <binder/IServiceManager.h>
24 #include <soundtrigger/ISoundTriggerClient.h>
25
26 namespace android {
27
28 enum {
29 ON_RECOGNITION_EVENT = IBinder::FIRST_CALL_TRANSACTION,
30 ON_SOUNDMODEL_EVENT,
31 ON_SERVICE_STATE_CHANGE
32 };
33
34 class BpSoundTriggerClient: public BpInterface<ISoundTriggerClient>
35 {
36
37 public:
BpSoundTriggerClient(const sp<IBinder> & impl)38 BpSoundTriggerClient(const sp<IBinder>& impl)
39 : BpInterface<ISoundTriggerClient>(impl)
40 {
41 }
42
onRecognitionEvent(const sp<IMemory> & eventMemory)43 virtual void onRecognitionEvent(const sp<IMemory>& eventMemory)
44 {
45 Parcel data, reply;
46 data.writeInterfaceToken(ISoundTriggerClient::getInterfaceDescriptor());
47 data.writeStrongBinder(IInterface::asBinder(eventMemory));
48 remote()->transact(ON_RECOGNITION_EVENT,
49 data,
50 &reply);
51 }
52
onSoundModelEvent(const sp<IMemory> & eventMemory)53 virtual void onSoundModelEvent(const sp<IMemory>& eventMemory)
54 {
55 Parcel data, reply;
56 data.writeInterfaceToken(ISoundTriggerClient::getInterfaceDescriptor());
57 data.writeStrongBinder(IInterface::asBinder(eventMemory));
58 remote()->transact(ON_SOUNDMODEL_EVENT,
59 data,
60 &reply);
61 }
onServiceStateChange(const sp<IMemory> & eventMemory)62 virtual void onServiceStateChange(const sp<IMemory>& eventMemory)
63 {
64 Parcel data, reply;
65 data.writeInterfaceToken(ISoundTriggerClient::getInterfaceDescriptor());
66 data.writeStrongBinder(IInterface::asBinder(eventMemory));
67 remote()->transact(ON_SERVICE_STATE_CHANGE,
68 data,
69 &reply);
70 }
71 };
72
73 IMPLEMENT_META_INTERFACE(SoundTriggerClient,
74 "android.hardware.ISoundTriggerClient");
75
76 // ----------------------------------------------------------------------
77
onTransact(uint32_t code,const Parcel & data,Parcel * reply,uint32_t flags)78 status_t BnSoundTriggerClient::onTransact(
79 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
80 {
81 switch(code) {
82 case ON_RECOGNITION_EVENT: {
83 CHECK_INTERFACE(ISoundTriggerClient, data, reply);
84 sp<IMemory> eventMemory = interface_cast<IMemory>(
85 data.readStrongBinder());
86 onRecognitionEvent(eventMemory);
87 return NO_ERROR;
88 } break;
89 case ON_SOUNDMODEL_EVENT: {
90 CHECK_INTERFACE(ISoundTriggerClient, data, reply);
91 sp<IMemory> eventMemory = interface_cast<IMemory>(
92 data.readStrongBinder());
93 onSoundModelEvent(eventMemory);
94 return NO_ERROR;
95 } break;
96 case ON_SERVICE_STATE_CHANGE: {
97 CHECK_INTERFACE(ISoundTriggerClient, data, reply);
98 sp<IMemory> eventMemory = interface_cast<IMemory>(
99 data.readStrongBinder());
100 onServiceStateChange(eventMemory);
101 return NO_ERROR;
102 } break;
103 default:
104 return BBinder::onTransact(code, data, reply, flags);
105 }
106 }
107
108 // ----------------------------------------------------------------------------
109
110 }; // namespace android
111