• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2016 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 "GnssHAL_GnssNavigationMessageInterface"
18 
19 #include <log/log.h>
20 
21 #include "GnssNavigationMessage.h"
22 
23 namespace android {
24 namespace hardware {
25 namespace gnss {
26 namespace V1_0 {
27 namespace implementation {
28 
29 sp<IGnssNavigationMessageCallback> GnssNavigationMessage::sGnssNavigationMsgCbIface = nullptr;
30 
31 GpsNavigationMessageCallbacks GnssNavigationMessage::sGnssNavigationMessageCb = {
32     .size = sizeof(GpsNavigationMessageCallbacks),
33     .navigation_message_callback = nullptr,
34     .gnss_navigation_message_callback = gnssNavigationMessageCb
35 };
36 
GnssNavigationMessage(const GpsNavigationMessageInterface * gpsNavigationMessageIface)37 GnssNavigationMessage::GnssNavigationMessage(
38         const GpsNavigationMessageInterface* gpsNavigationMessageIface) :
39     mGnssNavigationMessageIface(gpsNavigationMessageIface) {}
40 
gnssNavigationMessageCb(LegacyGnssNavigationMessage * message)41 void GnssNavigationMessage::gnssNavigationMessageCb(LegacyGnssNavigationMessage* message) {
42     if (sGnssNavigationMsgCbIface == nullptr) {
43         ALOGE("%s: GnssNavigation Message Callback Interface configured incorrectly", __func__);
44         return;
45     }
46 
47     if (message == nullptr) {
48         ALOGE("%s, received invalid GnssNavigationMessage from GNSS HAL", __func__);
49         return;
50     }
51 
52     IGnssNavigationMessageCallback::GnssNavigationMessage navigationMsg;
53 
54     navigationMsg.svid = message->svid;
55     navigationMsg.type =
56             static_cast<IGnssNavigationMessageCallback::GnssNavigationMessageType>(message->type);
57     navigationMsg.status = message->status;
58     navigationMsg.messageId = message->message_id;
59     navigationMsg.submessageId = message->submessage_id;
60     navigationMsg.data.setToExternal(message->data, message->data_length);
61 
62     auto ret = sGnssNavigationMsgCbIface->gnssNavigationMessageCb(navigationMsg);
63     if (!ret.isOk()) {
64         ALOGE("%s: Unable to invoke callback", __func__);
65     }
66 }
67 
68 // Methods from ::android::hardware::gnss::V1_0::IGnssNavigationMessage follow.
setCallback(const sp<IGnssNavigationMessageCallback> & callback)69 Return<GnssNavigationMessage::GnssNavigationMessageStatus> GnssNavigationMessage::setCallback(
70         const sp<IGnssNavigationMessageCallback>& callback)  {
71     if (mGnssNavigationMessageIface == nullptr) {
72         ALOGE("%s: GnssNavigationMessage not available", __func__);
73         return GnssNavigationMessageStatus::ERROR_GENERIC;
74     }
75 
76     sGnssNavigationMsgCbIface = callback;
77 
78     return static_cast<GnssNavigationMessage::GnssNavigationMessageStatus>(
79             mGnssNavigationMessageIface->init(&sGnssNavigationMessageCb));
80 }
81 
close()82 Return<void> GnssNavigationMessage::close()  {
83     if (mGnssNavigationMessageIface == nullptr) {
84         ALOGE("%s: GnssNavigationMessage not available", __func__);
85     } else {
86         mGnssNavigationMessageIface->close();
87     }
88     return Void();
89 }
90 
91 }  // namespace implementation
92 }  // namespace V1_0
93 }  // namespace gnss
94 }  // namespace hardware
95 }  // namespace android
96