LCOV - code coverage report
Current view: directory - objdir/dist/include - nsGeoPositionIPCSerialiser.h (source / functions) Found Hit Coverage
Test: app.info Lines: 103 0 0.0 %
Date: 2012-06-02 Functions: 6 0 0.0 %

       1                 : /* ***** BEGIN LICENSE BLOCK *****
       2                 :  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
       3                 :  *
       4                 :  * The contents of this file are subject to the Mozilla Public License Version
       5                 :  * 1.1 (the "License"); you may not use this file except in compliance with
       6                 :  * the License. You may obtain a copy of the License at
       7                 :  * http://www.mozilla.org/MPL/
       8                 :  *
       9                 :  * Software distributed under the License is distributed on an "AS IS" basis,
      10                 :  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
      11                 :  * for the specific language governing rights and limitations under the
      12                 :  * License.
      13                 :  *
      14                 :  * The Original Code is Mozilla geolocation code.
      15                 :  *
      16                 :  * The Initial Developer of the Original Code is Mozilla Foundation.
      17                 :  * Portions created by the Initial Developer are Copyright (C) 2010
      18                 :  * the Initial Developer. All Rights Reserved.
      19                 :  *
      20                 :  * Contributor(s):
      21                 :  *  Mike Kristoffersen <moz@mikek.dk> (Original Author)
      22                 :  *
      23                 :  * Alternatively, the contents of this file may be used under the terms of
      24                 :  * either the GNU General Public License Version 2 or later (the "GPL"), or
      25                 :  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
      26                 :  * in which case the provisions of the GPL or the LGPL are applicable instead
      27                 :  * of those above. If you wish to allow use of your version of this file only
      28                 :  * under the terms of either the GPL or the LGPL, and not to allow others to
      29                 :  * use your version of this file under the terms of the MPL, indicate your
      30                 :  * decision by deleting the provisions above and replace them with the notice
      31                 :  * and other provisions required by the GPL or the LGPL. If you do not delete
      32                 :  * the provisions above, a recipient may use your version of this file under
      33                 :  * the terms of any one of the MPL, the GPL or the LGPL.
      34                 :  *
      35                 :  * ***** END LICENSE BLOCK ***** */
      36                 : 
      37                 : #ifndef dom_src_geolocation_IPC_serialiser
      38                 : #define dom_src_geolocation_IPC_serialiser
      39                 : 
      40                 : #include "IPC/IPCMessageUtils.h"
      41                 : #include "nsGeoPosition.h"
      42                 : #include "nsIDOMGeoPosition.h"
      43                 : 
      44                 : typedef nsIDOMGeoPositionAddress  *GeoPositionAddress;
      45                 : typedef nsGeoPositionCoords       *GeoPositionCoords;
      46                 : typedef nsIDOMGeoPosition         *GeoPosition;
      47                 : 
      48                 : namespace IPC {
      49                 : 
      50                 : template <>
      51                 : struct ParamTraits<GeoPositionAddress>
      52                 : {
      53                 :   typedef GeoPositionAddress paramType;
      54                 : 
      55                 :   // Function to serialize a geo position address
      56               0 :   static void Write(Message *aMsg, const paramType& aParam)
      57                 :   {
      58               0 :     bool isNull = !aParam;
      59               0 :     WriteParam(aMsg, isNull);
      60                 :     // If it is null, then we are done
      61               0 :     if (isNull) return;
      62                 : 
      63               0 :     nsString addressLine;
      64                 : 
      65               0 :     aParam->GetStreetNumber(addressLine);
      66               0 :     WriteParam(aMsg, addressLine);
      67                 : 
      68               0 :     aParam->GetStreet(addressLine);
      69               0 :     WriteParam(aMsg, addressLine);
      70                 : 
      71               0 :     aParam->GetPremises(addressLine);
      72               0 :     WriteParam(aMsg, addressLine);
      73                 : 
      74               0 :     aParam->GetCity(addressLine);
      75               0 :     WriteParam(aMsg, addressLine);
      76                 : 
      77               0 :     aParam->GetCounty(addressLine);
      78               0 :     WriteParam(aMsg, addressLine);
      79                 : 
      80               0 :     aParam->GetRegion(addressLine);
      81               0 :     WriteParam(aMsg, addressLine);
      82                 : 
      83               0 :     aParam->GetCountry(addressLine);
      84               0 :     WriteParam(aMsg, addressLine);
      85                 : 
      86               0 :     aParam->GetPostalCode(addressLine);
      87               0 :     WriteParam(aMsg, addressLine);
      88                 :   }
      89                 : 
      90                 :   // Function to de-serialize a geoposition
      91               0 :   static bool Read(const Message* aMsg, void **aIter, paramType* aResult)
      92                 :   {
      93                 :     // Check if it is the null pointer we have transfered
      94                 :     bool isNull;
      95               0 :     if (!ReadParam(aMsg, aIter, &isNull)) return false;
      96                 : 
      97               0 :     if (isNull) {
      98               0 :       *aResult = 0;
      99               0 :       return true;
     100                 :     }
     101                 : 
     102                 :     // We need somewhere to store the address before we create the object
     103               0 :     nsString streetNumber;
     104               0 :     nsString street;
     105               0 :     nsString premises;
     106               0 :     nsString city;
     107               0 :     nsString county;
     108               0 :     nsString region;
     109               0 :     nsString country;
     110               0 :     nsString postalCode;
     111                 : 
     112                 :     // It's not important to us where it fails, but rather if it fails
     113               0 :     if (!(ReadParam(aMsg, aIter, &streetNumber) &&
     114               0 :           ReadParam(aMsg, aIter, &street      ) &&
     115               0 :           ReadParam(aMsg, aIter, &premises    ) &&
     116               0 :           ReadParam(aMsg, aIter, &city        ) &&
     117               0 :           ReadParam(aMsg, aIter, &county      ) &&
     118               0 :           ReadParam(aMsg, aIter, &region      ) &&
     119               0 :           ReadParam(aMsg, aIter, &country     ) &&
     120               0 :           ReadParam(aMsg, aIter, &postalCode  ))) return false;
     121                 : 
     122                 :     // We now have all the data
     123                 :     *aResult = new nsGeoPositionAddress(streetNumber, /* aStreetNumber */
     124                 :                                         street,       /* aStreet       */
     125                 :                                         premises,     /* aPremises     */
     126                 :                                         city,         /* aCity         */
     127                 :                                         county,       /* aCounty       */
     128                 :                                         region,       /* aRegion       */
     129                 :                                         country,      /* aCountry      */
     130                 :                                         postalCode    /* aPostalCode   */
     131               0 :                                        );
     132               0 :     return true;
     133                 :   }
     134                 : } ;
     135                 : 
     136                 : template <>
     137                 : struct ParamTraits<GeoPositionCoords>
     138                 : {
     139                 :   typedef GeoPositionCoords paramType;
     140                 : 
     141                 :   // Function to serialize a geoposition
     142               0 :   static void Write(Message *aMsg, const paramType& aParam)
     143                 :   {
     144               0 :     bool isNull = !aParam;
     145               0 :     WriteParam(aMsg, isNull);
     146                 :     // If it is a null object, then we are done
     147               0 :     if (isNull) return;
     148                 : 
     149                 :     double coordData;
     150                 : 
     151               0 :     aParam->GetLatitude(&coordData);
     152               0 :     WriteParam(aMsg, coordData);
     153                 : 
     154               0 :     aParam->GetLongitude(&coordData);
     155               0 :     WriteParam(aMsg, coordData);
     156                 : 
     157               0 :     aParam->GetAltitude(&coordData);
     158               0 :     WriteParam(aMsg, coordData);
     159                 : 
     160               0 :     aParam->GetAccuracy(&coordData);
     161               0 :     WriteParam(aMsg, coordData);
     162                 : 
     163               0 :     aParam->GetAltitudeAccuracy(&coordData);
     164               0 :     WriteParam(aMsg, coordData);
     165                 : 
     166               0 :     aParam->GetHeading(&coordData);
     167               0 :     WriteParam(aMsg, coordData);
     168                 : 
     169               0 :     aParam->GetSpeed(&coordData);
     170               0 :     WriteParam(aMsg, coordData);
     171                 :   }
     172                 : 
     173                 :   // Function to de-serialize a geoposition
     174               0 :   static bool Read(const Message* aMsg, void **aIter, paramType* aResult)
     175                 :   {
     176                 :     // Check if it is the null pointer we have transfered
     177                 :     bool isNull;
     178               0 :     if (!ReadParam(aMsg, aIter, &isNull)) return false;
     179                 : 
     180               0 :     if (isNull) {
     181               0 :       *aResult = 0;
     182               0 :       return true;
     183                 :     }
     184                 : 
     185                 :     double latitude;
     186                 :     double longitude;
     187                 :     double altitude;
     188                 :     double accuracy;
     189                 :     double altitudeAccuracy;
     190                 :     double heading;
     191                 :     double speed;
     192                 : 
     193                 :     // It's not important to us where it fails, but rather if it fails
     194               0 :     if (!(   ReadParam(aMsg, aIter, &latitude         )
     195               0 :           && ReadParam(aMsg, aIter, &longitude        )
     196               0 :           && ReadParam(aMsg, aIter, &altitude         )
     197               0 :           && ReadParam(aMsg, aIter, &accuracy         )
     198               0 :           && ReadParam(aMsg, aIter, &altitudeAccuracy )
     199               0 :           && ReadParam(aMsg, aIter, &heading          )
     200               0 :           && ReadParam(aMsg, aIter, &speed            ))) return false;
     201                 : 
     202                 :     // We now have all the data
     203                 :     *aResult = new nsGeoPositionCoords(latitude,         /* aLat     */
     204                 :                                        longitude,        /* aLong    */
     205                 :                                        altitude,         /* aAlt     */
     206                 :                                        accuracy,         /* aHError  */
     207                 :                                        altitudeAccuracy, /* aVError  */
     208                 :                                        heading,          /* aHeading */
     209                 :                                        speed             /* aSpeed   */
     210               0 :                                       );
     211               0 :     return true;
     212                 : 
     213                 :   }
     214                 : 
     215                 : };
     216                 : 
     217                 : template <>
     218                 : struct ParamTraits<GeoPosition>
     219                 : {
     220                 :   typedef GeoPosition paramType;
     221                 : 
     222                 :   // Function to serialize a geoposition
     223               0 :   static void Write(Message *aMsg, const paramType& aParam)
     224                 :   {
     225               0 :     bool isNull = !aParam;
     226               0 :     WriteParam(aMsg, isNull);
     227                 :     // If it is a null object, then we are done
     228               0 :     if (isNull) return;
     229                 : 
     230                 :     DOMTimeStamp timeStamp;
     231               0 :     aParam->GetTimestamp(&timeStamp);
     232               0 :     WriteParam(aMsg, timeStamp);
     233                 : 
     234               0 :     nsCOMPtr<nsIDOMGeoPositionCoords> coords;
     235               0 :     aParam->GetCoords(getter_AddRefs(coords));
     236               0 :     GeoPositionCoords simpleCoords = static_cast<GeoPositionCoords>(coords.get());
     237               0 :     WriteParam(aMsg, simpleCoords);
     238                 : 
     239               0 :     nsCOMPtr<nsIDOMGeoPositionAddress> address;
     240               0 :     aParam->GetAddress(getter_AddRefs(address));
     241               0 :     GeoPositionAddress simpleAddress = address.get();
     242               0 :     WriteParam(aMsg, simpleAddress);
     243                 :   }
     244                 : 
     245                 :   // Function to de-serialize a geoposition
     246               0 :   static bool Read(const Message* aMsg, void **aIter, paramType* aResult)
     247                 :   {
     248                 :     // Check if it is the null pointer we have transfered
     249                 :     bool isNull;
     250               0 :     if (!ReadParam(aMsg, aIter, &isNull)) return false;
     251                 : 
     252               0 :     if (isNull) {
     253               0 :       *aResult = 0;
     254               0 :       return true;
     255                 :     }
     256                 : 
     257                 :     DOMTimeStamp timeStamp;
     258               0 :     GeoPositionCoords coords = nsnull;
     259                 :     GeoPositionAddress address;
     260                 : 
     261                 :     // It's not important to us where it fails, but rather if it fails
     262               0 :     if (!(   ReadParam(aMsg, aIter, &timeStamp)
     263               0 :           && ReadParam(aMsg, aIter, &coords   )
     264               0 :           && ReadParam(aMsg, aIter, &address  ))) {
     265                 :           // note it is fine to do "delete nsnull" in case coords hasn't
     266                 :           // been allocated and we will never have a case where address
     267                 :           // gets allocated and we end here
     268               0 :           delete coords;
     269               0 :           return false;
     270                 :       }
     271                 : 
     272               0 :     *aResult = new nsGeoPosition(coords, address, timeStamp);
     273                 : 
     274               0 :     return true;
     275                 :   };
     276                 : 
     277                 : };
     278                 : 
     279                 : }
     280                 : 
     281                 : #endif

Generated by: LCOV version 1.7