dom/src/geolocation/nsGeoPositionIPCSerialiser.h

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

michael@0 1 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 2 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 4
michael@0 5 #ifndef dom_src_geolocation_IPC_serialiser
michael@0 6 #define dom_src_geolocation_IPC_serialiser
michael@0 7
michael@0 8 #include "ipc/IPCMessageUtils.h"
michael@0 9 #include "nsGeoPosition.h"
michael@0 10 #include "nsIDOMGeoPosition.h"
michael@0 11
michael@0 12 typedef nsIDOMGeoPosition* GeoPosition;
michael@0 13
michael@0 14 namespace IPC {
michael@0 15
michael@0 16 template <>
michael@0 17 struct ParamTraits<nsIDOMGeoPositionCoords*>
michael@0 18 {
michael@0 19 typedef nsIDOMGeoPositionCoords* paramType;
michael@0 20
michael@0 21 // Function to serialize a geoposition
michael@0 22 static void Write(Message *aMsg, const paramType& aParam)
michael@0 23 {
michael@0 24 bool isNull = !aParam;
michael@0 25 WriteParam(aMsg, isNull);
michael@0 26 // If it is a null object, then we are done
michael@0 27 if (isNull) return;
michael@0 28
michael@0 29 double coordData;
michael@0 30
michael@0 31 aParam->GetLatitude(&coordData);
michael@0 32 WriteParam(aMsg, coordData);
michael@0 33
michael@0 34 aParam->GetLongitude(&coordData);
michael@0 35 WriteParam(aMsg, coordData);
michael@0 36
michael@0 37 aParam->GetAltitude(&coordData);
michael@0 38 WriteParam(aMsg, coordData);
michael@0 39
michael@0 40 aParam->GetAccuracy(&coordData);
michael@0 41 WriteParam(aMsg, coordData);
michael@0 42
michael@0 43 aParam->GetAltitudeAccuracy(&coordData);
michael@0 44 WriteParam(aMsg, coordData);
michael@0 45
michael@0 46 aParam->GetHeading(&coordData);
michael@0 47 WriteParam(aMsg, coordData);
michael@0 48
michael@0 49 aParam->GetSpeed(&coordData);
michael@0 50 WriteParam(aMsg, coordData);
michael@0 51 }
michael@0 52
michael@0 53 // Function to de-serialize a geoposition
michael@0 54 static bool Read(const Message* aMsg, void **aIter, paramType* aResult)
michael@0 55 {
michael@0 56 // Check if it is the null pointer we have transfered
michael@0 57 bool isNull;
michael@0 58 if (!ReadParam(aMsg, aIter, &isNull)) return false;
michael@0 59
michael@0 60 if (isNull) {
michael@0 61 *aResult = 0;
michael@0 62 return true;
michael@0 63 }
michael@0 64
michael@0 65 double latitude;
michael@0 66 double longitude;
michael@0 67 double altitude;
michael@0 68 double accuracy;
michael@0 69 double altitudeAccuracy;
michael@0 70 double heading;
michael@0 71 double speed;
michael@0 72
michael@0 73 // It's not important to us where it fails, but rather if it fails
michael@0 74 if (!( ReadParam(aMsg, aIter, &latitude )
michael@0 75 && ReadParam(aMsg, aIter, &longitude )
michael@0 76 && ReadParam(aMsg, aIter, &altitude )
michael@0 77 && ReadParam(aMsg, aIter, &accuracy )
michael@0 78 && ReadParam(aMsg, aIter, &altitudeAccuracy )
michael@0 79 && ReadParam(aMsg, aIter, &heading )
michael@0 80 && ReadParam(aMsg, aIter, &speed ))) return false;
michael@0 81
michael@0 82 // We now have all the data
michael@0 83 *aResult = new nsGeoPositionCoords(latitude, /* aLat */
michael@0 84 longitude, /* aLong */
michael@0 85 altitude, /* aAlt */
michael@0 86 accuracy, /* aHError */
michael@0 87 altitudeAccuracy, /* aVError */
michael@0 88 heading, /* aHeading */
michael@0 89 speed /* aSpeed */
michael@0 90 );
michael@0 91 return true;
michael@0 92
michael@0 93 }
michael@0 94
michael@0 95 };
michael@0 96
michael@0 97 template <>
michael@0 98 struct ParamTraits<nsIDOMGeoPosition*>
michael@0 99 {
michael@0 100 typedef nsIDOMGeoPosition* paramType;
michael@0 101
michael@0 102 // Function to serialize a geoposition
michael@0 103 static void Write(Message *aMsg, const paramType& aParam)
michael@0 104 {
michael@0 105 bool isNull = !aParam;
michael@0 106 WriteParam(aMsg, isNull);
michael@0 107 // If it is a null object, then we are done
michael@0 108 if (isNull) return;
michael@0 109
michael@0 110 DOMTimeStamp timeStamp;
michael@0 111 aParam->GetTimestamp(&timeStamp);
michael@0 112 WriteParam(aMsg, timeStamp);
michael@0 113
michael@0 114 nsCOMPtr<nsIDOMGeoPositionCoords> coords;
michael@0 115 aParam->GetCoords(getter_AddRefs(coords));
michael@0 116 WriteParam(aMsg, coords.get());
michael@0 117 }
michael@0 118
michael@0 119 // Function to de-serialize a geoposition
michael@0 120 static bool Read(const Message* aMsg, void **aIter, paramType* aResult)
michael@0 121 {
michael@0 122 // Check if it is the null pointer we have transfered
michael@0 123 bool isNull;
michael@0 124 if (!ReadParam(aMsg, aIter, &isNull)) return false;
michael@0 125
michael@0 126 if (isNull) {
michael@0 127 *aResult = 0;
michael@0 128 return true;
michael@0 129 }
michael@0 130
michael@0 131 DOMTimeStamp timeStamp;
michael@0 132 nsIDOMGeoPositionCoords* coords = nullptr;
michael@0 133
michael@0 134 // It's not important to us where it fails, but rather if it fails
michael@0 135 if (!ReadParam(aMsg, aIter, &timeStamp) ||
michael@0 136 !ReadParam(aMsg, aIter, &coords)) {
michael@0 137 nsCOMPtr<nsIDOMGeoPositionCoords> tmpcoords = coords;
michael@0 138 return false;
michael@0 139 }
michael@0 140
michael@0 141 *aResult = new nsGeoPosition(coords, timeStamp);
michael@0 142
michael@0 143 return true;
michael@0 144 };
michael@0 145
michael@0 146 };
michael@0 147
michael@0 148 }
michael@0 149
michael@0 150 #endif

mercurial