1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef dom_src_geolocation_IPC_serialiser
8 #define dom_src_geolocation_IPC_serialiser
10 #include "ipc/IPCMessageUtils.h"
11 #include "mozilla/dom/GeolocationPosition.h"
12 #include "nsIDOMGeoPosition.h"
17 struct ParamTraits
<nsIDOMGeoPositionCoords
*> {
18 // Function to serialize a geoposition
19 static void Write(MessageWriter
* aWriter
, nsIDOMGeoPositionCoords
* aParam
) {
20 bool isNull
= !aParam
;
21 WriteParam(aWriter
, isNull
);
22 // If it is a null object, then we are done
27 aParam
->GetLatitude(&coordData
);
28 WriteParam(aWriter
, coordData
);
30 aParam
->GetLongitude(&coordData
);
31 WriteParam(aWriter
, coordData
);
33 aParam
->GetAltitude(&coordData
);
34 WriteParam(aWriter
, coordData
);
36 aParam
->GetAccuracy(&coordData
);
37 WriteParam(aWriter
, coordData
);
39 aParam
->GetAltitudeAccuracy(&coordData
);
40 WriteParam(aWriter
, coordData
);
42 aParam
->GetHeading(&coordData
);
43 WriteParam(aWriter
, coordData
);
45 aParam
->GetSpeed(&coordData
);
46 WriteParam(aWriter
, coordData
);
49 // Function to de-serialize a geoposition
50 static bool Read(MessageReader
* aReader
,
51 RefPtr
<nsIDOMGeoPositionCoords
>* aResult
) {
52 // Check if it is the null pointer we have transfered
54 if (!ReadParam(aReader
, &isNull
)) return false;
65 double altitudeAccuracy
;
69 // It's not important to us where it fails, but rather if it fails
70 if (!(ReadParam(aReader
, &latitude
) && ReadParam(aReader
, &longitude
) &&
71 ReadParam(aReader
, &altitude
) && ReadParam(aReader
, &accuracy
) &&
72 ReadParam(aReader
, &altitudeAccuracy
) &&
73 ReadParam(aReader
, &heading
) && ReadParam(aReader
, &speed
)))
76 // We now have all the data
77 *aResult
= new nsGeoPositionCoords(latitude
, /* aLat */
78 longitude
, /* aLong */
80 accuracy
, /* aHError */
81 altitudeAccuracy
, /* aVError */
82 heading
, /* aHeading */
90 struct ParamTraits
<nsIDOMGeoPosition
*> {
91 // Function to serialize a geoposition
92 static void Write(MessageWriter
* aWriter
, nsIDOMGeoPosition
* aParam
) {
93 bool isNull
= !aParam
;
94 WriteParam(aWriter
, isNull
);
95 // If it is a null object, then we are done
98 EpochTimeStamp timeStamp
;
99 aParam
->GetTimestamp(&timeStamp
);
100 WriteParam(aWriter
, timeStamp
);
102 nsCOMPtr
<nsIDOMGeoPositionCoords
> coords
;
103 aParam
->GetCoords(getter_AddRefs(coords
));
104 WriteParam(aWriter
, coords
);
107 // Function to de-serialize a geoposition
108 static bool Read(MessageReader
* aReader
, RefPtr
<nsIDOMGeoPosition
>* aResult
) {
109 // Check if it is the null pointer we have transfered
111 if (!ReadParam(aReader
, &isNull
)) return false;
118 EpochTimeStamp timeStamp
;
119 RefPtr
<nsIDOMGeoPositionCoords
> coords
;
121 // It's not important to us where it fails, but rather if it fails
122 if (!ReadParam(aReader
, &timeStamp
) || !ReadParam(aReader
, &coords
)) {
126 *aResult
= new nsGeoPosition(coords
, timeStamp
);