Home | History | Annotate | Download | only in BroadcastRadio
      1 /**
      2  * Copyright (C) 2017 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 #ifndef _ANDROID_SERVER_BROADCASTRADIO_CONVERT_H
     18 #define _ANDROID_SERVER_BROADCASTRADIO_CONVERT_H
     19 
     20 #include "types.h"
     21 
     22 #include "JavaRef.h"
     23 
     24 #include <android/hardware/broadcastradio/1.1/types.h>
     25 #include <jni.h>
     26 
     27 namespace android {
     28 
     29 void register_android_server_broadcastradio_convert(JNIEnv *env);
     30 
     31 namespace server {
     32 namespace BroadcastRadio {
     33 namespace convert {
     34 
     35 namespace V1_0 = hardware::broadcastradio::V1_0;
     36 namespace V1_1 = hardware::broadcastradio::V1_1;
     37 
     38 hardware::hidl_vec<hardware::hidl_string> StringListToHal(JNIEnv *env, jobject jList);
     39 
     40 JavaRef<jobject> VendorInfoFromHal(JNIEnv *env, const hardware::hidl_vec<V1_1::VendorKeyValue> &info);
     41 hardware::hidl_vec<V1_1::VendorKeyValue> VendorInfoToHal(JNIEnv *env, jobject jInfo);
     42 
     43 JavaRef<jobject> ModulePropertiesFromHal(JNIEnv *env, const V1_0::Properties &properties,
     44         jint moduleId, const std::string& serviceName);
     45 JavaRef<jobject> ModulePropertiesFromHal(JNIEnv *env, const V1_1::Properties &properties,
     46         jint moduleId, const std::string& serviceName);
     47 
     48 JavaRef<jobject> BandConfigFromHal(JNIEnv *env, const V1_0::BandConfig &config, Region region);
     49 V1_0::BandConfig BandConfigToHal(JNIEnv *env, jobject jConfig, Region &region);
     50 
     51 V1_0::Direction DirectionToHal(bool directionDown);
     52 
     53 JavaRef<jobject> MetadataFromHal(JNIEnv *env, const hardware::hidl_vec<V1_0::MetaData> &metadata);
     54 JavaRef<jobject> ProgramInfoFromHal(JNIEnv *env, const V1_0::ProgramInfo &info, V1_0::Band band);
     55 JavaRef<jobject> ProgramInfoFromHal(JNIEnv *env, const V1_1::ProgramInfo &info);
     56 
     57 V1_1::ProgramSelector ProgramSelectorToHal(JNIEnv *env, jobject jSelector);
     58 
     59 void ThrowParcelableRuntimeException(JNIEnv *env, const std::string& msg);
     60 
     61 // These three are only for internal use by template functions below.
     62 bool __ThrowIfFailedHidl(JNIEnv *env,
     63         const hardware::details::return_status &hidlResult);
     64 bool __ThrowIfFailed(JNIEnv *env, const V1_0::Result halResult);
     65 bool __ThrowIfFailed(JNIEnv *env, const V1_1::ProgramListResult halResult);
     66 
     67 template <typename T>
     68 bool ThrowIfFailed(JNIEnv *env, const hardware::Return<void> &hidlResult, const T halResult) {
     69     return __ThrowIfFailedHidl(env, hidlResult) || __ThrowIfFailed(env, halResult);
     70 }
     71 
     72 template <typename T>
     73 bool ThrowIfFailed(JNIEnv *env, const hardware::Return<T> &hidlResult) {
     74     return __ThrowIfFailedHidl(env, hidlResult) || __ThrowIfFailed(env, static_cast<T>(hidlResult));
     75 }
     76 
     77 template <>
     78 bool ThrowIfFailed(JNIEnv *env, const hardware::Return<void> &hidlResult);
     79 
     80 } // namespace convert
     81 } // namespace BroadcastRadio
     82 } // namespace server
     83 } // namespace android
     84 
     85 #endif // _ANDROID_SERVER_BROADCASTRADIO_CONVERT_H
     86