Bumping manifests a=b2g-bump
[gecko.git] / ipc / netd / Netd.h
blob31d0dc03cc13f66a9a49b219be5fbb3c9d48c54d
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
3 * You can obtain one at http://mozilla.org/MPL/2.0/. */
5 #ifndef mozilla_system_netd_h__
6 #define mozilla_system_netd_h__
8 #include "nsISupportsImpl.h"
9 #include "nsAutoPtr.h"
10 #include "base/message_loop.h"
11 #include "mozilla/FileUtils.h"
13 #define MAX_COMMAND_SIZE 4096
15 namespace mozilla {
16 namespace ipc {
19 * Represents raw data going to or coming from the Netd socket.
21 struct NetdCommand
23 uint8_t mData[MAX_COMMAND_SIZE];
25 // Number of octets in mData.
26 size_t mSize;
29 class NetdConsumer
31 protected:
32 virtual ~NetdConsumer() { }
34 public:
35 NS_INLINE_DECL_REFCOUNTING(NetdConsumer)
37 virtual void MessageReceived(NetdCommand* aMessage) = 0;
40 class NetdWriteTask : public Task
42 virtual void Run();
45 class NetdClient : public MessageLoopForIO::LineWatcher
47 virtual ~NetdClient();
49 public:
50 NS_INLINE_DECL_REFCOUNTING(NetdClient)
51 typedef std::queue<NetdCommand*> NetdCommandQueue;
53 NetdClient();
54 static void Start();
55 static void SendNetdCommandIOThread(NetdCommand* aMessage);
57 private:
58 void WriteNetdCommand();
59 virtual void OnError();
60 virtual void OnLineRead(int aFd, nsDependentCSubstring& aMessage);
61 virtual void OnFileCanWriteWithoutBlocking(int aFd);
62 bool OpenSocket();
64 MessageLoopForIO *mIOLoop;
65 MessageLoopForIO::FileDescriptorWatcher mReadWatcher;
66 MessageLoopForIO::FileDescriptorWatcher mWriteWatcher;
67 ScopedClose mSocket;
68 NetdCommandQueue mOutgoingQ;
69 nsAutoPtr<NetdCommand> mCurrentNetdCommand;
70 size_t mCurrentWriteOffset;
71 size_t mReConnectTimes;
74 void StartNetd(NetdConsumer *);
75 void StopNetd();
76 void SendNetdCommand(NetdCommand *);
78 } // namespace ipc
79 } // namespace mozilla
81 #endif // mozilla_system_netd_h__