RilSocket.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
  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. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  5. #ifndef mozilla_ipc_RilSocket_h
  6. #define mozilla_ipc_RilSocket_h
  7. #include "mozilla/ipc/ConnectionOrientedSocket.h"
  8. class JSContext;
  9. class MessageLoop;
  10. namespace mozilla {
  11. namespace dom {
  12. namespace workers {
  13. class WorkerCrossThreadDispatcher;
  14. } // namespace workers
  15. } // namespace dom
  16. } // namespace mozilla
  17. namespace mozilla {
  18. namespace ipc {
  19. class RilSocketConsumer;
  20. class RilSocketIO;
  21. class UnixSocketConnector;
  22. class RilSocket final : public ConnectionOrientedSocket
  23. {
  24. public:
  25. /**
  26. * Constructs an instance of |RilSocket|.
  27. *
  28. * @param aDispatcher The dispatcher class for the received messages.
  29. * @param aConsumer The consumer for the socket.
  30. * @param aIndex An arbitrary index.
  31. */
  32. RilSocket(mozilla::dom::workers::WorkerCrossThreadDispatcher* aDispatcher,
  33. RilSocketConsumer* aConsumer, int aIndex);
  34. /**
  35. * Method to be called whenever data is received. RIL-worker only.
  36. *
  37. * @param aCx The RIL worker's JS context.
  38. * @param aBuffer Data received from the socket.
  39. */
  40. void ReceiveSocketData(JSContext* aCx, UniquePtr<UnixSocketBuffer>& aBuffer);
  41. /**
  42. * Starts a task on the socket that will try to connect to a socket in a
  43. * non-blocking manner.
  44. *
  45. * @param aConnector Connector object for socket type specific functions
  46. * @param aDelayMs Time delay in milliseconds.
  47. * @param aConsumerLoop The socket's consumer thread.
  48. * @param aIOLoop The socket's I/O thread.
  49. * @return NS_OK on success, or an XPCOM error code otherwise.
  50. */
  51. nsresult Connect(UnixSocketConnector* aConnector, int aDelayMs,
  52. MessageLoop* aConsumerLoop, MessageLoop* aIOLoop);
  53. /**
  54. * Starts a task on the socket that will try to connect to a socket in a
  55. * non-blocking manner.
  56. *
  57. * @param aConnector Connector object for socket type specific functions
  58. * @param aDelayMs Time delay in milliseconds.
  59. * @return NS_OK on success, or an XPCOM error code otherwise.
  60. */
  61. nsresult Connect(UnixSocketConnector* aConnector, int aDelayMs = 0);
  62. // Methods for |ConnectionOrientedSocket|
  63. //
  64. nsresult PrepareAccept(UnixSocketConnector* aConnector,
  65. MessageLoop* aConsumerLoop,
  66. MessageLoop* aIOLoop,
  67. ConnectionOrientedSocketIO*& aIO) override;
  68. // Methods for |DataSocket|
  69. //
  70. void SendSocketData(UnixSocketIOBuffer* aBuffer) override;
  71. // Methods for |SocketBase|
  72. //
  73. void Close() override;
  74. void OnConnectSuccess() override;
  75. void OnConnectError() override;
  76. void OnDisconnect() override;
  77. protected:
  78. virtual ~RilSocket();
  79. private:
  80. RilSocketIO* mIO;
  81. RefPtr<mozilla::dom::workers::WorkerCrossThreadDispatcher> mDispatcher;
  82. RilSocketConsumer* mConsumer;
  83. int mIndex;
  84. };
  85. } // namespace ipc
  86. } // namepsace mozilla
  87. #endif // mozilla_ipc_RilSocket_h