loc_api: Repackage as a new GPS HAL module.

Signed-off-by: Mike Lockwood <lockwood@android.com>
diff --git a/loc_api/Android.mk b/loc_api/Android.mk
index 39bc741..293b2da 100755
--- a/loc_api/Android.mk
+++ b/loc_api/Android.mk
@@ -6,6 +6,6 @@
 # ·         Neither the name of the QUALCOMM USA, INC.  nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. 
 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
-ifeq ($(BOARD_GPS_LIBRARIES),libloc_api)
+ifneq ($(GPS_LOC_API_HARDWARE),)
 include $(call all-subdir-makefiles)
 endif
diff --git a/loc_api/libloc_api/Android.mk b/loc_api/libloc_api/Android.mk
index bc8e4ae..040a57c 100755
--- a/loc_api/libloc_api/Android.mk
+++ b/loc_api/libloc_api/Android.mk
@@ -6,14 +6,12 @@
 #·         Neither the name of the QUALCOMM USA, Inc.  nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. 
 #THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
-ifneq ($(BUILD_TINY_ANDROID),true)
-
 AMSS_VERSION:=6356
 
 LOCAL_PATH := $(call my-dir)
 include $(CLEAR_VARS)
 
-LOCAL_MODULE := libloc_api
+LOCAL_MODULE := gps.$(GPS_LOC_API_HARDWARE)
 
 LOCAL_STATIC_LIBRARIES:= \
     libloc_api-rpc 
@@ -27,7 +25,8 @@
     loc_eng.cpp \
     loc_eng_ioctl.cpp \
     loc_eng_xtra.cpp \
-    loc_eng_ni.cpp
+    loc_eng_ni.cpp \
+    gps.c
 
 LOCAL_CFLAGS += \
     -fno-short-enums 
@@ -39,7 +38,7 @@
 	$(TARGET_OUT_HEADERS)/librpc
 
 LOCAL_PRELINK_MODULE := false
-include $(BUILD_SHARED_LIBRARY)
+LOCAL_MODULE_PATH := $(TARGET_OUT_SHARED_LIBRARIES)/hw
 
-endif # not BUILD_TINY_ANDROID
+include $(BUILD_SHARED_LIBRARY)
 
diff --git a/loc_api/libloc_api/gps.c b/loc_api/libloc_api/gps.c
new file mode 100644
index 0000000..ec6fbd0
--- /dev/null
+++ b/loc_api/libloc_api/gps.c
@@ -0,0 +1,66 @@
+/******************************************************************************
+  @file:  gps.c
+  @brief:
+
+  DESCRIPTION
+    This file defines the implemenation for GPS hardware abstraction layer.
+
+  INITIALIZATION AND SEQUENCING REQUIREMENTS
+
+  -----------------------------------------------------------------------------
+Copyright (c) 2009, QUALCOMM USA, INC.
+
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
+
+·         Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 
+
+·         Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 
+
+·         Neither the name of the QUALCOMM USA, INC.  nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. 
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+  -----------------------------------------------------------------------------
+
+******************************************************************************/
+
+#include <hardware/gps.h>
+
+#include <stdlib.h>
+
+extern const GpsInterface* get_gps_interface();
+
+const GpsInterface* gps__get_gps_interface(struct gps_device_t* dev)
+{
+    return get_gps_interface();
+}
+
+static int open_gps(const struct hw_module_t* module, char const* name,
+        struct hw_device_t** device)
+{
+    struct gps_device_t *dev = malloc(sizeof(struct gps_device_t));
+    memset(dev, 0, sizeof(*dev));
+
+    dev->common.tag = HARDWARE_DEVICE_TAG;
+    dev->common.version = 0;
+    dev->common.module = (struct hw_module_t*)module;
+    dev->get_gps_interface = gps__get_gps_interface;
+
+    *device = (struct hw_device_t*)dev;
+    return 0;
+}
+
+static struct hw_module_methods_t gps_module_methods = {
+    .open = open_gps
+};
+
+const struct hw_module_t HAL_MODULE_INFO_SYM = {
+    .tag = HARDWARE_MODULE_TAG,
+    .version_major = 1,
+    .version_minor = 0,
+    .id = GPS_HARDWARE_MODULE_ID,
+    .name = "loc_api GPS Module",
+    .author = "Qualcomm USA, Inc.",
+    .methods = &gps_module_methods,
+};
diff --git a/loc_api/libloc_api/loc_eng.cpp b/loc_api/libloc_api/loc_eng.cpp
index fd1db4e..d8f5c27 100755
--- a/loc_api/libloc_api/loc_eng.cpp
+++ b/loc_api/libloc_api/loc_eng.cpp
@@ -46,7 +46,6 @@
 #include "loc_api_rpc_glue.h"
 #include "loc_apicb_appinit.h"
 
-#include <hardware_legacy/gps.h>
 #include <cutils/properties.h>
 #include <cutils/sched_policy.h>
 #include <utils/SystemClock.h>
@@ -101,6 +100,7 @@
 // Defines the GpsInterface in gps.h
 static const GpsInterface sLocEngInterface =
 {
+    sizeof(GpsInterface),
     loc_eng_init,
     loc_eng_start,
     loc_eng_stop,
@@ -114,6 +114,7 @@
 
 static const AGpsInterface sLocEngAGpsInterface =
 {
+    sizeof(AGpsInterface),
     loc_eng_agps_init,
     loc_eng_agps_data_conn_open,
     loc_eng_agps_data_conn_closed,
@@ -708,7 +709,8 @@
     LOGV ("loc_eng_report_position: location report, valid mask = 0x%x, sess status = %d\n",
          (uint32) location_report_ptr->valid_mask, location_report_ptr->session_status);
 
-    memset (&location, 0, sizeof (GpsLocation));
+    memset (&location, 0, sizeof(location));
+    location.size = sizeof(location);
     if (location_report_ptr->valid_mask & RPC_LOC_POS_VALID_SESSION_STATUS)
     {
         // Not a position report, return
@@ -818,6 +820,7 @@
             {
                 if (sv_info_ptr->system == RPC_LOC_SV_SYSTEM_GPS)
                 {
+                    SvStatus.sv_list[SvStatus.num_svs].size = sizeof(GpsSvStatus);
                     SvStatus.sv_list[SvStatus.num_svs].prn = sv_info_ptr->prn;
 
                     // We only have the data field to report gps eph and alm mask
@@ -906,7 +909,8 @@
 
     LOGV ("loc_eng_report_status: event = %d\n", status_report_ptr->event);
 
-    memset (&status, 0, sizeof (GpsStatus));
+    memset (&status, 0, sizeof(status));
+    status.size = sizeof(status);
     status.status = GPS_STATUS_NONE;
     if (status_report_ptr->event == RPC_LOC_STATUS_EVENT_ENGINE_STATE)
     {
@@ -1351,6 +1355,7 @@
 static void* loc_eng_process_deferred_action (void* arg)
 {
     AGpsStatus      status;
+    status.size = sizeof(status);
     status.type = AGPS_TYPE_SUPL;
 
     LOGD("loc_eng_process_deferred_action started\n");
@@ -1428,3 +1433,9 @@
     LOGD("loc_eng_process_deferred_action thread exiting\n");
     return NULL;
 }
+
+// for gps.c
+extern "C" const GpsInterface* get_gps_interface()
+{
+    return &sLocEngInterface;
+}
diff --git a/loc_api/libloc_api/loc_eng.h b/loc_api/libloc_api/loc_eng.h
index 979e423..f13df31 100755
--- a/loc_api/libloc_api/loc_eng.h
+++ b/loc_api/libloc_api/loc_eng.h
@@ -47,7 +47,7 @@
 
 #include <loc_eng_ioctl.h>
 #include <loc_eng_xtra.h>
-#include <hardware_legacy/gps_ni.h>
+#include <hardware/gps.h>
 
 #define LOC_IOCTL_DEFAULT_TIMEOUT 1000 // 1000 milli-seconds
 
diff --git a/loc_api/libloc_api/loc_eng_ioctl.cpp b/loc_api/libloc_api/loc_eng_ioctl.cpp
index ff9d481..87ca5b0 100755
--- a/loc_api/libloc_api/loc_eng_ioctl.cpp
+++ b/loc_api/libloc_api/loc_eng_ioctl.cpp
@@ -44,7 +44,7 @@
 #include <rpc/rpc.h>
 #include <loc_api_rpc_glue.h>
 
-#include <hardware_legacy/gps.h>
+#include <hardware/gps.h>
 
 #include <loc_eng.h>
 
diff --git a/loc_api/libloc_api/loc_eng_ni.cpp b/loc_api/libloc_api/loc_eng_ni.cpp
index d923855..9888d4d 100755
--- a/loc_api/libloc_api/loc_eng_ni.cpp
+++ b/loc_api/libloc_api/loc_eng_ni.cpp
@@ -37,8 +37,6 @@
 #include <unistd.h>
 #include <time.h>
 
-#include <hardware_legacy/gps.h>
-
 #include <rpc/rpc.h>
 #include <loc_api_rpc_glue.h>
 #include <loc_eng.h>
@@ -59,6 +57,7 @@
 
 const GpsNiInterface sLocEngNiInterface =
 {
+    sizeof(GpsNiInterface),
     loc_eng_ni_init,
     loc_eng_ni_respond,
 };
@@ -251,6 +250,7 @@
 static void loc_ni_request_handler(const char *msg, const rpc_loc_ni_event_s_type *ni_req)
 {
     GpsNiNotification notif;
+    notif.size = sizeof(notif);
     strlcpy(notif.text, "[text]", sizeof notif.text);    // defaults
     strlcpy(notif.requestor_id, "[requestor id]", sizeof notif.requestor_id);
 
diff --git a/loc_api/libloc_api/loc_eng_ni.h b/loc_api/libloc_api/loc_eng_ni.h
index b975b94..be23405 100755
--- a/loc_api/libloc_api/loc_eng_ni.h
+++ b/loc_api/libloc_api/loc_eng_ni.h
@@ -29,7 +29,7 @@
 #ifndef LOC_ENG_NI_H
 #define LOC_ENG_NI_H
 
-#include <hardware_legacy/gps_ni.h>
+#include <hardware/gps.h>
 
 #define LOC_NI_NO_RESPONSE_TIME            20                      /* secs */
 
diff --git a/loc_api/libloc_api/loc_eng_xtra.cpp b/loc_api/libloc_api/loc_eng_xtra.cpp
index a321653..9dda092 100755
--- a/loc_api/libloc_api/loc_eng_xtra.cpp
+++ b/loc_api/libloc_api/loc_eng_xtra.cpp
@@ -43,8 +43,6 @@
 #include <rpc/rpc.h>
 #include <loc_api_rpc_glue.h>
 
-#include <hardware_legacy/gps.h>
-
 #include <loc_eng.h>
 
 #define LOG_TAG "lib_locapi"
@@ -62,6 +60,7 @@
 
 const GpsXtraInterface sLocEngXTRAInterface =
 {
+    sizeof(GpsXtraInterface),
     qct_loc_eng_xtra_init,
     qct_loc_eng_inject_xtra_data,
 };
diff --git a/loc_api/libloc_api/loc_eng_xtra.h b/loc_api/libloc_api/loc_eng_xtra.h
index 839fc06..b5c7945 100755
--- a/loc_api/libloc_api/loc_eng_xtra.h
+++ b/loc_api/libloc_api/loc_eng_xtra.h
@@ -34,6 +34,8 @@
 #ifndef LOC_ENG_XTRA_H
 #define LOC_ENG_XTRA_H
 
+#include <hardware/gps.h>
+
 extern const GpsXtraInterface sLocEngXTRAInterface;
 
 // Module data