dom/src/geolocation/nsGeoPositionIPCSerialiser.h

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

mercurial