1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/ipc/netd/Netd.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,81 @@ 1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this file, 1.6 + * You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.7 + 1.8 +#ifndef mozilla_system_netd_h__ 1.9 +#define mozilla_system_netd_h__ 1.10 + 1.11 +#include "nsISupportsImpl.h" 1.12 +#include "nsAutoPtr.h" 1.13 +#include "base/message_loop.h" 1.14 +#include "mozilla/FileUtils.h" 1.15 + 1.16 +#define MAX_COMMAND_SIZE 4096 1.17 + 1.18 +namespace mozilla { 1.19 +namespace ipc { 1.20 + 1.21 +/* 1.22 + * Represents raw data going to or coming from the Netd socket. 1.23 + */ 1.24 +struct NetdCommand 1.25 +{ 1.26 + uint8_t mData[MAX_COMMAND_SIZE]; 1.27 + 1.28 + // Number of octets in mData. 1.29 + size_t mSize; 1.30 +}; 1.31 + 1.32 +class NetdConsumer 1.33 +{ 1.34 +protected: 1.35 + virtual ~NetdConsumer() { } 1.36 + 1.37 +public: 1.38 + NS_INLINE_DECL_REFCOUNTING(NetdConsumer) 1.39 + 1.40 + virtual void MessageReceived(NetdCommand* aMessage) = 0; 1.41 +}; 1.42 + 1.43 +class NetdWriteTask : public Task 1.44 +{ 1.45 + virtual void Run(); 1.46 +}; 1.47 + 1.48 +class NetdClient : public MessageLoopForIO::LineWatcher 1.49 +{ 1.50 + virtual ~NetdClient(); 1.51 + 1.52 +public: 1.53 + NS_INLINE_DECL_REFCOUNTING(NetdClient) 1.54 + typedef std::queue<NetdCommand*> NetdCommandQueue; 1.55 + 1.56 + NetdClient(); 1.57 + static void Start(); 1.58 + static void SendNetdCommandIOThread(NetdCommand* aMessage); 1.59 + 1.60 +private: 1.61 + void WriteNetdCommand(); 1.62 + virtual void OnError(); 1.63 + virtual void OnLineRead(int aFd, nsDependentCSubstring& aMessage); 1.64 + virtual void OnFileCanWriteWithoutBlocking(int aFd); 1.65 + bool OpenSocket(); 1.66 + 1.67 + MessageLoopForIO *mIOLoop; 1.68 + MessageLoopForIO::FileDescriptorWatcher mReadWatcher; 1.69 + MessageLoopForIO::FileDescriptorWatcher mWriteWatcher; 1.70 + ScopedClose mSocket; 1.71 + NetdCommandQueue mOutgoingQ; 1.72 + nsAutoPtr<NetdCommand> mCurrentNetdCommand; 1.73 + size_t mCurrentWriteOffset; 1.74 + size_t mReConnectTimes; 1.75 +}; 1.76 + 1.77 +void StartNetd(NetdConsumer *); 1.78 +void StopNetd(); 1.79 +void SendNetdCommand(NetdCommand *); 1.80 + 1.81 +} // namespace ipc 1.82 +} // namespace mozilla 1.83 + 1.84 +#endif // mozilla_system_netd_h__