SubProtocolBase.cs 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using SuperSocket.SocketBase;
  6. using SuperSocket.SocketBase.Command;
  7. using SuperSocket.SocketBase.Config;
  8. using SuperSocket.SocketBase.Logging;
  9. using SuperSocket.SocketBase.Protocol;
  10. using SuperWebSocket.Config;
  11. namespace SuperWebSocket.SubProtocol
  12. {
  13. /// <summary>
  14. /// SubProtocol basis
  15. /// </summary>
  16. /// <typeparam name="TWebSocketSession">The type of the web socket session.</typeparam>
  17. public abstract class SubProtocolBase<TWebSocketSession> : ISubProtocol<TWebSocketSession>
  18. where TWebSocketSession : WebSocketSession<TWebSocketSession>, new()
  19. {
  20. private SubProtocolBase()
  21. {
  22. }
  23. /// <summary>
  24. /// Initializes a new instance of the <see cref="SubProtocolBase&lt;TWebSocketSession&gt;"/> class.
  25. /// </summary>
  26. /// <param name="name">The name.</param>
  27. public SubProtocolBase(string name)
  28. {
  29. Name = name;
  30. }
  31. /// <summary>
  32. /// Gets the name.
  33. /// </summary>
  34. public string Name { get; private set; }
  35. /// <summary>
  36. /// Initializes with the specified config.
  37. /// </summary>
  38. /// <param name="appServer">The app server.</param>
  39. /// <param name="protocolConfig">The protocol config.</param>
  40. /// <param name="logger">The logger.</param>
  41. /// <returns></returns>
  42. public abstract bool Initialize(IAppServer appServer, SubProtocolConfig protocolConfig, ILog logger);
  43. /// <summary>
  44. /// Gets or sets the sub request parser.
  45. /// </summary>
  46. /// <value>
  47. /// The sub request parser.
  48. /// </value>
  49. public IRequestInfoParser<SubRequestInfo> SubRequestParser { get; protected set; }
  50. /// <summary>
  51. /// Tries the get command.
  52. /// </summary>
  53. /// <param name="name">The name.</param>
  54. /// <param name="command">The command.</param>
  55. /// <returns></returns>
  56. public abstract bool TryGetCommand(string name, out ISubCommand<TWebSocketSession> command);
  57. }
  58. }