BufferedMesgBroadcaster.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. #region Copyright
  2. ////////////////////////////////////////////////////////////////////////////////
  3. // The following FIT Protocol software provided may be used with FIT protocol
  4. // devices only and remains the copyrighted property of Dynastream Innovations Inc.
  5. // The software is being provided on an "as-is" basis and as an accommodation,
  6. // and therefore all warranties, representations, or guarantees of any kind
  7. // (whether express, implied or statutory) including, without limitation,
  8. // warranties of merchantability, non-infringement, or fitness for a particular
  9. // purpose, are specifically disclaimed.
  10. //
  11. // Copyright 2016 Dynastream Innovations Inc.
  12. ////////////////////////////////////////////////////////////////////////////////
  13. // ****WARNING**** This file is auto-generated! Do NOT edit this file.
  14. // Profile Version = 16.60Release
  15. // Tag = production-akw-16.60.00-0-g5d3d436
  16. ////////////////////////////////////////////////////////////////////////////////
  17. #endregion
  18. using System;
  19. using System.Collections.Generic;
  20. using System.Diagnostics;
  21. using System.Text;
  22. using System.IO;
  23. using Dynastream.Utility;
  24. using Dynastream.Fit;
  25. namespace Dynastream.Fit
  26. {
  27. public delegate void MesgBroadcastEventHandler(object sender, MesgBroadcastEventArgs e);
  28. public delegate void IncomingMesgEventHandler(object sender, IncomingMesgEventArgs e);
  29. public class MesgBroadcastEventArgs : EventArgs
  30. {
  31. public List<Mesg> mesgs = null;
  32. public MesgBroadcastEventArgs()
  33. {
  34. }
  35. public MesgBroadcastEventArgs(List<Mesg> newMesgs)
  36. {
  37. mesgs = newMesgs;
  38. }
  39. }
  40. public class IncomingMesgEventArgs : EventArgs
  41. {
  42. public Mesg mesg = null;
  43. public IncomingMesgEventArgs()
  44. {
  45. }
  46. public IncomingMesgEventArgs(Mesg newMesg)
  47. {
  48. mesg = new Mesg(newMesg);
  49. }
  50. }
  51. /// <summary>
  52. /// <para>
  53. /// BufferedMesgBroadcaster intercepts the incoming messages
  54. /// from the given decode stream, buffers them, and offers
  55. /// an opportunity to edit the messages before broadcasting
  56. /// the messages to all registered listeners.
  57. /// </para>
  58. /// <para>
  59. /// To edit the messages, an IMesgBroadcastPlugin must be
  60. /// registered. All registered IMesgBroadcastPlugins are given
  61. /// the opportunity to see each message as they are decoded,
  62. /// as well as to see and edit the final list of
  63. /// messages before broadcast to listeners
  64. /// </para>
  65. /// </summary>
  66. public class BufferedMesgBroadcaster : MesgBroadcaster
  67. {
  68. #region Fields
  69. private List<Mesg> mesgs = new List<Mesg>();
  70. public event MesgBroadcastEventHandler MesgBroadcastEvent;
  71. public event IncomingMesgEventHandler IncomingMesgEvent;
  72. #endregion
  73. #region Methods
  74. public void RegisterMesgBroadcastPlugin(IMesgBroadcastPlugin plugin)
  75. {
  76. MesgBroadcastEvent += plugin.OnBroadcast;
  77. IncomingMesgEvent += plugin.OnIncomingMesg;
  78. }
  79. public new void OnMesg(object sender, MesgEventArgs e)
  80. {
  81. // Notify any subscribers of either our general mesg event or specific profile mesg event
  82. mesgs.Add(e.mesg);
  83. if (IncomingMesgEvent != null)
  84. {
  85. IncomingMesgEvent(sender, new IncomingMesgEventArgs(e.mesg));
  86. }
  87. }
  88. public void Broadcast()
  89. {
  90. if (MesgBroadcastEvent != null)
  91. {
  92. MesgBroadcastEvent(this, new MesgBroadcastEventArgs(mesgs));
  93. }
  94. foreach (Mesg mesg in mesgs)
  95. {
  96. base.OnMesg(this, new MesgEventArgs(mesg));
  97. }
  98. }
  99. #endregion
  100. }
  101. } // namespace