OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 The Chromium 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 EXTENSIONS_BROWSER_API_WEBCAM_PRIVATE_VISCA_WEBCAM_H_ |
| 6 #define EXTENSIONS_BROWSER_API_WEBCAM_PRIVATE_VISCA_WEBCAM_H_ |
| 7 |
| 8 #include <deque> |
| 9 |
| 10 #include "base/callback.h" |
| 11 #include "base/memory/weak_ptr.h" |
| 12 #include "extensions/browser/api/webcam_private/webcam.h" |
| 13 #include "extensions/common/api/serial.h" |
| 14 |
| 15 namespace extensions { |
| 16 |
| 17 class SerialConnection; |
| 18 |
| 19 class ViscaWebcam : public Webcam, public base::SupportsWeakPtr<ViscaWebcam> { |
| 20 public: |
| 21 ViscaWebcam(const std::string& path, const std::string& extension_id); |
| 22 ~ViscaWebcam() override; |
| 23 |
| 24 typedef base::Callback<void(bool)> OpenCallback; |
| 25 void Open(const OpenCallback& callback); |
| 26 |
| 27 private: |
| 28 typedef base::Callback<void(bool, const std::vector<char>&)> |
| 29 CommandCompleteCallback; |
| 30 |
| 31 void OpenOnIOThread(const OpenCallback& callback); |
| 32 void OnConnected(const OpenCallback& callback, bool success); |
| 33 void OnClearAllComplete(const OpenCallback& callback, |
| 34 bool success, const std::vector<char>& data); |
| 35 |
| 36 void Send(const std::vector<char>& data, |
| 37 const CommandCompleteCallback& callback); |
| 38 void OnSendComplete(const CommandCompleteCallback& callback, |
| 39 int bytes_sent, core_api::serial::SendError error); |
| 40 void ReceiveLoop(); |
| 41 void OnReceiveComplete(const std::vector<char>& data, |
| 42 core_api::serial::ReceiveError error); |
| 43 |
| 44 // Webcam: |
| 45 void Reset(bool pan, bool tilt, bool zoom) override; |
| 46 bool GetPan(int* value) override; |
| 47 bool GetTilt(int* value) override; |
| 48 bool GetZoom(int* value) override; |
| 49 bool SetPan(int value) override; |
| 50 bool SetTilt(int value) override; |
| 51 bool SetZoom(int value) override; |
| 52 bool SetPanDirection(PanDirection direction) override; |
| 53 bool SetTiltDirection(TiltDirection direction) override; |
| 54 |
| 55 const std::string path_; |
| 56 const std::string extension_id_; |
| 57 |
| 58 scoped_ptr<SerialConnection> serial_connection_; |
| 59 |
| 60 std::deque<char> data_buffer_; |
| 61 std::deque<std::pair<std::vector<char>, CommandCompleteCallback>> commands_; |
| 62 |
| 63 DISALLOW_COPY_AND_ASSIGN(ViscaWebcam); |
| 64 }; |
| 65 |
| 66 |
| 67 } // namespace extensions |
| 68 |
| 69 #endif // EXTENSIONS_BROWSER_API_WEBCAM_PRIVATE_VISCA_WEBCAM_H_ |
OLD | NEW |