2015-05-03 19:32:37 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-05-21 11:12:37 +00:00
|
|
|
/* 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/. */
|
2010-09-21 04:16:37 +00:00
|
|
|
|
|
|
|
#ifndef dom_src_geolocation_IPC_serialiser
|
|
|
|
#define dom_src_geolocation_IPC_serialiser
|
|
|
|
|
2012-08-28 12:41:04 +00:00
|
|
|
#include "ipc/IPCMessageUtils.h"
|
2010-09-21 04:16:37 +00:00
|
|
|
#include "nsGeoPosition.h"
|
|
|
|
#include "nsIDOMGeoPosition.h"
|
|
|
|
|
2013-01-07 05:57:00 +00:00
|
|
|
typedef nsIDOMGeoPosition* GeoPosition;
|
2010-09-21 04:16:37 +00:00
|
|
|
|
|
|
|
namespace IPC {
|
|
|
|
|
|
|
|
template <>
|
2013-01-07 05:57:00 +00:00
|
|
|
struct ParamTraits<nsIDOMGeoPositionCoords*>
|
2010-09-21 04:16:37 +00:00
|
|
|
{
|
2013-01-07 05:57:00 +00:00
|
|
|
typedef nsIDOMGeoPositionCoords* paramType;
|
2010-09-21 04:16:37 +00:00
|
|
|
|
|
|
|
// 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, void **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 <>
|
2013-01-07 05:57:00 +00:00
|
|
|
struct ParamTraits<nsIDOMGeoPosition*>
|
2010-09-21 04:16:37 +00:00
|
|
|
{
|
2013-01-07 05:57:00 +00:00
|
|
|
typedef nsIDOMGeoPosition* paramType;
|
2010-09-21 04:16:37 +00:00
|
|
|
|
|
|
|
// 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);
|
|
|
|
|
2010-12-15 12:57:00 +00:00
|
|
|
nsCOMPtr<nsIDOMGeoPositionCoords> coords;
|
2010-09-21 04:16:37 +00:00
|
|
|
aParam->GetCoords(getter_AddRefs(coords));
|
2013-01-07 05:57:00 +00:00
|
|
|
WriteParam(aMsg, coords.get());
|
2010-09-21 04:16:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Function to de-serialize a geoposition
|
|
|
|
static bool Read(const Message* aMsg, void **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;
|
2013-01-07 05:57:00 +00:00
|
|
|
nsIDOMGeoPositionCoords* coords = nullptr;
|
2010-09-21 04:16:37 +00:00
|
|
|
|
|
|
|
// It's not important to us where it fails, but rather if it fails
|
2013-01-07 05:57:00 +00:00
|
|
|
if (!ReadParam(aMsg, aIter, &timeStamp) ||
|
|
|
|
!ReadParam(aMsg, aIter, &coords)) {
|
|
|
|
nsCOMPtr<nsIDOMGeoPositionCoords> tmpcoords = coords;
|
|
|
|
return false;
|
|
|
|
}
|
2010-09-21 04:16:37 +00:00
|
|
|
|
2012-03-09 06:16:25 +00:00
|
|
|
*aResult = new nsGeoPosition(coords, timeStamp);
|
2010-09-21 04:16:37 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|