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