Home | History | Annotate | Download | only in radio
      1 /*
      2 **
      3 ** Copyright 2015, 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 <radio/IRadioClient.h>
     25 
     26 namespace android {
     27 
     28 enum {
     29     ON_EVENT = IBinder::FIRST_CALL_TRANSACTION,
     30 };
     31 
     32 class BpRadioClient: public BpInterface<IRadioClient>
     33 {
     34 
     35 public:
     36     BpRadioClient(const sp<IBinder>& impl)
     37         : BpInterface<IRadioClient>(impl)
     38     {
     39     }
     40 
     41     virtual void onEvent(const sp<IMemory>& eventMemory)
     42     {
     43         Parcel data, reply;
     44         data.writeInterfaceToken(IRadioClient::getInterfaceDescriptor());
     45         data.writeStrongBinder(IInterface::asBinder(eventMemory));
     46         remote()->transact(ON_EVENT,
     47                            data,
     48                            &reply);
     49     }
     50 };
     51 
     52 IMPLEMENT_META_INTERFACE(RadioClient,
     53                          "android.hardware.IRadioClient");
     54 
     55 // ----------------------------------------------------------------------
     56 
     57 status_t BnRadioClient::onTransact(
     58     uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
     59 {
     60     switch(code) {
     61         case ON_EVENT: {
     62             CHECK_INTERFACE(IRadioClient, data, reply);
     63             sp<IMemory> eventMemory = interface_cast<IMemory>(
     64                 data.readStrongBinder());
     65             onEvent(eventMemory);
     66             return NO_ERROR;
     67         } break;
     68         default:
     69             return BBinder::onTransact(code, data, reply, flags);
     70     }   return NO_ERROR;
     71 }
     72 
     73 // ----------------------------------------------------------------------------
     74 
     75 }; // namespace android
     76