michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef dom_src_geolocation_IPC_serialiser michael@0: #define dom_src_geolocation_IPC_serialiser michael@0: michael@0: #include "ipc/IPCMessageUtils.h" michael@0: #include "nsGeoPosition.h" michael@0: #include "nsIDOMGeoPosition.h" michael@0: michael@0: typedef nsIDOMGeoPosition* GeoPosition; michael@0: michael@0: namespace IPC { michael@0: michael@0: template <> michael@0: struct ParamTraits michael@0: { michael@0: typedef nsIDOMGeoPositionCoords* paramType; michael@0: michael@0: // Function to serialize a geoposition michael@0: static void Write(Message *aMsg, const paramType& aParam) michael@0: { michael@0: bool isNull = !aParam; michael@0: WriteParam(aMsg, isNull); michael@0: // If it is a null object, then we are done michael@0: if (isNull) return; michael@0: michael@0: double coordData; michael@0: michael@0: aParam->GetLatitude(&coordData); michael@0: WriteParam(aMsg, coordData); michael@0: michael@0: aParam->GetLongitude(&coordData); michael@0: WriteParam(aMsg, coordData); michael@0: michael@0: aParam->GetAltitude(&coordData); michael@0: WriteParam(aMsg, coordData); michael@0: michael@0: aParam->GetAccuracy(&coordData); michael@0: WriteParam(aMsg, coordData); michael@0: michael@0: aParam->GetAltitudeAccuracy(&coordData); michael@0: WriteParam(aMsg, coordData); michael@0: michael@0: aParam->GetHeading(&coordData); michael@0: WriteParam(aMsg, coordData); michael@0: michael@0: aParam->GetSpeed(&coordData); michael@0: WriteParam(aMsg, coordData); michael@0: } michael@0: michael@0: // Function to de-serialize a geoposition michael@0: static bool Read(const Message* aMsg, void **aIter, paramType* aResult) michael@0: { michael@0: // Check if it is the null pointer we have transfered michael@0: bool isNull; michael@0: if (!ReadParam(aMsg, aIter, &isNull)) return false; michael@0: michael@0: if (isNull) { michael@0: *aResult = 0; michael@0: return true; michael@0: } michael@0: michael@0: double latitude; michael@0: double longitude; michael@0: double altitude; michael@0: double accuracy; michael@0: double altitudeAccuracy; michael@0: double heading; michael@0: double speed; michael@0: michael@0: // It's not important to us where it fails, but rather if it fails michael@0: if (!( ReadParam(aMsg, aIter, &latitude ) michael@0: && ReadParam(aMsg, aIter, &longitude ) michael@0: && ReadParam(aMsg, aIter, &altitude ) michael@0: && ReadParam(aMsg, aIter, &accuracy ) michael@0: && ReadParam(aMsg, aIter, &altitudeAccuracy ) michael@0: && ReadParam(aMsg, aIter, &heading ) michael@0: && ReadParam(aMsg, aIter, &speed ))) return false; michael@0: michael@0: // We now have all the data michael@0: *aResult = new nsGeoPositionCoords(latitude, /* aLat */ michael@0: longitude, /* aLong */ michael@0: altitude, /* aAlt */ michael@0: accuracy, /* aHError */ michael@0: altitudeAccuracy, /* aVError */ michael@0: heading, /* aHeading */ michael@0: speed /* aSpeed */ michael@0: ); michael@0: return true; michael@0: michael@0: } michael@0: michael@0: }; michael@0: michael@0: template <> michael@0: struct ParamTraits michael@0: { michael@0: typedef nsIDOMGeoPosition* paramType; michael@0: michael@0: // Function to serialize a geoposition michael@0: static void Write(Message *aMsg, const paramType& aParam) michael@0: { michael@0: bool isNull = !aParam; michael@0: WriteParam(aMsg, isNull); michael@0: // If it is a null object, then we are done michael@0: if (isNull) return; michael@0: michael@0: DOMTimeStamp timeStamp; michael@0: aParam->GetTimestamp(&timeStamp); michael@0: WriteParam(aMsg, timeStamp); michael@0: michael@0: nsCOMPtr coords; michael@0: aParam->GetCoords(getter_AddRefs(coords)); michael@0: WriteParam(aMsg, coords.get()); michael@0: } michael@0: michael@0: // Function to de-serialize a geoposition michael@0: static bool Read(const Message* aMsg, void **aIter, paramType* aResult) michael@0: { michael@0: // Check if it is the null pointer we have transfered michael@0: bool isNull; michael@0: if (!ReadParam(aMsg, aIter, &isNull)) return false; michael@0: michael@0: if (isNull) { michael@0: *aResult = 0; michael@0: return true; michael@0: } michael@0: michael@0: DOMTimeStamp timeStamp; michael@0: nsIDOMGeoPositionCoords* coords = nullptr; michael@0: michael@0: // It's not important to us where it fails, but rather if it fails michael@0: if (!ReadParam(aMsg, aIter, &timeStamp) || michael@0: !ReadParam(aMsg, aIter, &coords)) { michael@0: nsCOMPtr tmpcoords = coords; michael@0: return false; michael@0: } michael@0: michael@0: *aResult = new nsGeoPosition(coords, timeStamp); michael@0: michael@0: return true; michael@0: }; michael@0: michael@0: }; michael@0: michael@0: } michael@0: michael@0: #endif