ISoundTriggerClient.cpp 3.6 KB

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