TelemetryComms.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2; -*- */
  2. /* This Source Code Form is subject to the terms of the Mozilla Public
  3. * License, v. 2.0. If a copy of the MPL was not distributed with this
  4. */
  5. #ifndef Telemetry_Comms_h__
  6. #define Telemetry_Comms_h__
  7. #include "ipc/IPCMessageUtils.h"
  8. namespace mozilla {
  9. namespace Telemetry {
  10. enum ID : uint32_t;
  11. struct Accumulation
  12. {
  13. mozilla::Telemetry::ID mId;
  14. uint32_t mSample;
  15. };
  16. struct KeyedAccumulation
  17. {
  18. mozilla::Telemetry::ID mId;
  19. uint32_t mSample;
  20. nsCString mKey;
  21. };
  22. } // namespace Telemetry
  23. } // namespace mozilla
  24. namespace IPC {
  25. template<>
  26. struct
  27. ParamTraits<mozilla::Telemetry::Accumulation>
  28. {
  29. typedef mozilla::Telemetry::Accumulation paramType;
  30. static void Write(Message* aMsg, const paramType& aParam)
  31. {
  32. aMsg->WriteUInt32(aParam.mId);
  33. WriteParam(aMsg, aParam.mSample);
  34. }
  35. static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult)
  36. {
  37. if (!aMsg->ReadUInt32(aIter, reinterpret_cast<uint32_t*>(&(aResult->mId))) ||
  38. !ReadParam(aMsg, aIter, &(aResult->mSample))) {
  39. return false;
  40. }
  41. return true;
  42. }
  43. };
  44. template<>
  45. struct
  46. ParamTraits<mozilla::Telemetry::KeyedAccumulation>
  47. {
  48. typedef mozilla::Telemetry::KeyedAccumulation paramType;
  49. static void Write(Message* aMsg, const paramType& aParam)
  50. {
  51. aMsg->WriteUInt32(aParam.mId);
  52. WriteParam(aMsg, aParam.mSample);
  53. WriteParam(aMsg, aParam.mKey);
  54. }
  55. static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult)
  56. {
  57. if (!aMsg->ReadUInt32(aIter, reinterpret_cast<uint32_t*>(&(aResult->mId))) ||
  58. !ReadParam(aMsg, aIter, &(aResult->mSample)) ||
  59. !ReadParam(aMsg, aIter, &(aResult->mKey))) {
  60. return false;
  61. }
  62. return true;
  63. }
  64. };
  65. } // namespace IPC
  66. #endif // Telemetry_Comms_h__