| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef ATHENA_SYSTEM_DEVICE_SOCKET_LISTENER_H_ | 5 #ifndef ATHENA_SYSTEM_DEVICE_SOCKET_LISTENER_H_ |
| 6 #define ATHENA_SYSTEM_DEVICE_SOCKET_LISTENER_H_ | 6 #define ATHENA_SYSTEM_DEVICE_SOCKET_LISTENER_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
| 12 | 12 |
| 13 namespace base { | 13 namespace base { |
| 14 class TaskRunner; | 14 class TaskRunner; |
| 15 } | 15 } |
| 16 | 16 |
| 17 namespace athena { | 17 namespace athena { |
| 18 | 18 |
| 19 // This class reads device-data from a socket. | 19 // This class reads device-data from a socket. |
| 20 class DeviceSocketListener { | 20 class DeviceSocketListener { |
| 21 public: | 21 public: |
| 22 DeviceSocketListener(const std::string& socket_parth, | 22 DeviceSocketListener(const std::string& socket_parth, |
| 23 size_t data_size); | 23 size_t data_size); |
| 24 virtual ~DeviceSocketListener(); | 24 virtual ~DeviceSocketListener(); |
| 25 | 25 |
| 26 static void CreateSocketManager( | 26 static void CreateSocketManager( |
| 27 scoped_refptr<base::TaskRunner> io_task_runner); | 27 scoped_refptr<base::TaskRunner> io_task_runner); |
| 28 static void ShutdownSocketManager(); | 28 static void ShutdownSocketManager(); |
| 29 | 29 |
| 30 // This is called on the IO thread when data is available on the socket. | 30 // This is called on the FILE thread when data is available on the socket. |
| 31 // |data| is guaranteed to be of exactly |data_size| length. Note that the | 31 // |data| is guaranteed to be of exactly |data_size| length. Note that the |
| 32 // implementation must not mutate or free the data. | 32 // implementation must not mutate or free the data. |
| 33 virtual void OnDataAvailableOnIO(const void* data) = 0; | 33 virtual void OnDataAvailableOnFILE(const void* data) = 0; |
| 34 | 34 |
| 35 protected: | 35 protected: |
| 36 void StartListening(); | 36 void StartListening(); |
| 37 void StopListening(); | 37 void StopListening(); |
| 38 | 38 |
| 39 private: | 39 private: |
| 40 const std::string socket_path_; | 40 const std::string socket_path_; |
| 41 size_t data_size_; | 41 size_t data_size_; |
| 42 | 42 |
| 43 DISALLOW_COPY_AND_ASSIGN(DeviceSocketListener); | 43 DISALLOW_COPY_AND_ASSIGN(DeviceSocketListener); |
| 44 }; | 44 }; |
| 45 | 45 |
| 46 } // namespace athena | 46 } // namespace athena |
| 47 | 47 |
| 48 #endif // ATHENA_SYSTEM_DEVICE_SOCKET_LISTENER_H_ | 48 #endif // ATHENA_SYSTEM_DEVICE_SOCKET_LISTENER_H_ |
| OLD | NEW |