Prashant Malani | f07c952 | 2017-04-11 14:54:29 -0700 | [diff] [blame^] | 1 | // Copyright 2017 The Chromium OS Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef MIDIS_CLIENT_H_ |
| 6 | #define MIDIS_CLIENT_H_ |
| 7 | |
| 8 | #include <memory> |
| 9 | |
| 10 | #include <base/files/scoped_file.h> |
| 11 | #include <base/memory/weak_ptr.h> |
| 12 | #include <brillo/message_loops/message_loop.h> |
| 13 | |
| 14 | namespace midis { |
| 15 | |
| 16 | class Client { |
| 17 | public: |
| 18 | ~Client(); |
| 19 | static std::unique_ptr<Client> Create(base::ScopedFD fd); |
| 20 | |
| 21 | private: |
| 22 | explicit Client(base::ScopedFD fd); |
| 23 | // Start monitoring the client socket fd for messages from the client. |
| 24 | bool StartMonitoring(); |
| 25 | // Stop the task which was watching the client socket df. |
| 26 | void StopMonitoring(); |
| 27 | void HandleClientMessages(); |
| 28 | |
| 29 | base::ScopedFD client_fd_; |
| 30 | brillo::MessageLoop::TaskId msg_taskid_; |
| 31 | base::WeakPtrFactory<Client> weak_factory_; |
| 32 | |
| 33 | DISALLOW_COPY_AND_ASSIGN(Client); |
| 34 | }; |
| 35 | |
| 36 | } // namespace midis |
| 37 | |
| 38 | #endif // MIDIS_CLIENT_H_ |