dom/src/geolocation/nsGeoPositionIPCSerialiser.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/src/geolocation/nsGeoPositionIPCSerialiser.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,150 @@
     1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.7 +
     1.8 +#ifndef dom_src_geolocation_IPC_serialiser
     1.9 +#define dom_src_geolocation_IPC_serialiser
    1.10 +
    1.11 +#include "ipc/IPCMessageUtils.h"
    1.12 +#include "nsGeoPosition.h"
    1.13 +#include "nsIDOMGeoPosition.h"
    1.14 +
    1.15 +typedef nsIDOMGeoPosition* GeoPosition;
    1.16 +
    1.17 +namespace IPC {
    1.18 +
    1.19 +template <>
    1.20 +struct ParamTraits<nsIDOMGeoPositionCoords*>
    1.21 +{
    1.22 +  typedef nsIDOMGeoPositionCoords* paramType;
    1.23 +
    1.24 +  // Function to serialize a geoposition
    1.25 +  static void Write(Message *aMsg, const paramType& aParam)
    1.26 +  {
    1.27 +    bool isNull = !aParam;
    1.28 +    WriteParam(aMsg, isNull);
    1.29 +    // If it is a null object, then we are done
    1.30 +    if (isNull) return;
    1.31 +
    1.32 +    double coordData;
    1.33 +
    1.34 +    aParam->GetLatitude(&coordData);
    1.35 +    WriteParam(aMsg, coordData);
    1.36 +
    1.37 +    aParam->GetLongitude(&coordData);
    1.38 +    WriteParam(aMsg, coordData);
    1.39 +
    1.40 +    aParam->GetAltitude(&coordData);
    1.41 +    WriteParam(aMsg, coordData);
    1.42 +
    1.43 +    aParam->GetAccuracy(&coordData);
    1.44 +    WriteParam(aMsg, coordData);
    1.45 +
    1.46 +    aParam->GetAltitudeAccuracy(&coordData);
    1.47 +    WriteParam(aMsg, coordData);
    1.48 +
    1.49 +    aParam->GetHeading(&coordData);
    1.50 +    WriteParam(aMsg, coordData);
    1.51 +
    1.52 +    aParam->GetSpeed(&coordData);
    1.53 +    WriteParam(aMsg, coordData);
    1.54 +  }
    1.55 +
    1.56 +  // Function to de-serialize a geoposition
    1.57 +  static bool Read(const Message* aMsg, void **aIter, paramType* aResult)
    1.58 +  {
    1.59 +    // Check if it is the null pointer we have transfered
    1.60 +    bool isNull;
    1.61 +    if (!ReadParam(aMsg, aIter, &isNull)) return false;
    1.62 +
    1.63 +    if (isNull) {
    1.64 +      *aResult = 0;
    1.65 +      return true;
    1.66 +    }
    1.67 +
    1.68 +    double latitude;
    1.69 +    double longitude;
    1.70 +    double altitude;
    1.71 +    double accuracy;
    1.72 +    double altitudeAccuracy;
    1.73 +    double heading;
    1.74 +    double speed;
    1.75 +
    1.76 +    // It's not important to us where it fails, but rather if it fails
    1.77 +    if (!(   ReadParam(aMsg, aIter, &latitude         )
    1.78 +          && ReadParam(aMsg, aIter, &longitude        )
    1.79 +          && ReadParam(aMsg, aIter, &altitude         )
    1.80 +          && ReadParam(aMsg, aIter, &accuracy         )
    1.81 +          && ReadParam(aMsg, aIter, &altitudeAccuracy )
    1.82 +          && ReadParam(aMsg, aIter, &heading          )
    1.83 +          && ReadParam(aMsg, aIter, &speed            ))) return false;
    1.84 +
    1.85 +    // We now have all the data
    1.86 +    *aResult = new nsGeoPositionCoords(latitude,         /* aLat     */
    1.87 +                                       longitude,        /* aLong    */
    1.88 +                                       altitude,         /* aAlt     */
    1.89 +                                       accuracy,         /* aHError  */
    1.90 +                                       altitudeAccuracy, /* aVError  */
    1.91 +                                       heading,          /* aHeading */
    1.92 +                                       speed             /* aSpeed   */
    1.93 +                                      );
    1.94 +    return true;
    1.95 +
    1.96 +  }
    1.97 +
    1.98 +};
    1.99 +
   1.100 +template <>
   1.101 +struct ParamTraits<nsIDOMGeoPosition*>
   1.102 +{
   1.103 +  typedef nsIDOMGeoPosition* paramType;
   1.104 +
   1.105 +  // Function to serialize a geoposition
   1.106 +  static void Write(Message *aMsg, const paramType& aParam)
   1.107 +  {
   1.108 +    bool isNull = !aParam;
   1.109 +    WriteParam(aMsg, isNull);
   1.110 +    // If it is a null object, then we are done
   1.111 +    if (isNull) return;
   1.112 +
   1.113 +    DOMTimeStamp timeStamp;
   1.114 +    aParam->GetTimestamp(&timeStamp);
   1.115 +    WriteParam(aMsg, timeStamp);
   1.116 +
   1.117 +    nsCOMPtr<nsIDOMGeoPositionCoords> coords;
   1.118 +    aParam->GetCoords(getter_AddRefs(coords));
   1.119 +    WriteParam(aMsg, coords.get());
   1.120 +  }
   1.121 +
   1.122 +  // Function to de-serialize a geoposition
   1.123 +  static bool Read(const Message* aMsg, void **aIter, paramType* aResult)
   1.124 +  {
   1.125 +    // Check if it is the null pointer we have transfered
   1.126 +    bool isNull;
   1.127 +    if (!ReadParam(aMsg, aIter, &isNull)) return false;
   1.128 +
   1.129 +    if (isNull) {
   1.130 +      *aResult = 0;
   1.131 +      return true;
   1.132 +    }
   1.133 +
   1.134 +    DOMTimeStamp timeStamp;
   1.135 +    nsIDOMGeoPositionCoords* coords = nullptr;
   1.136 +
   1.137 +    // It's not important to us where it fails, but rather if it fails
   1.138 +    if (!ReadParam(aMsg, aIter, &timeStamp) ||
   1.139 +        !ReadParam(aMsg, aIter, &coords)) {
   1.140 +      nsCOMPtr<nsIDOMGeoPositionCoords> tmpcoords = coords;
   1.141 +      return false;
   1.142 +    }
   1.143 +
   1.144 +    *aResult = new nsGeoPosition(coords, timeStamp);
   1.145 +
   1.146 +    return true;
   1.147 +  };
   1.148 +
   1.149 +};
   1.150 +
   1.151 +}
   1.152 +
   1.153 +#endif

mercurial