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