| OLD | NEW | 
|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 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 EXTENSIONS_BROWSER_API_WEBCAM_PRIVATE_VISCA_WEBCAM_H_ | 5 #ifndef EXTENSIONS_BROWSER_API_WEBCAM_PRIVATE_VISCA_WEBCAM_H_ | 
| 6 #define EXTENSIONS_BROWSER_API_WEBCAM_PRIVATE_VISCA_WEBCAM_H_ | 6 #define EXTENSIONS_BROWSER_API_WEBCAM_PRIVATE_VISCA_WEBCAM_H_ | 
| 7 | 7 | 
| 8 #include <deque> | 8 #include <deque> | 
| 9 | 9 | 
| 10 #include "base/callback.h" | 10 #include "base/callback.h" | 
| (...skipping 12 matching lines...) Expand all  Loading... | 
| 23 | 23 | 
| 24   // Open and initialize the web camera. This is done by the following three | 24   // Open and initialize the web camera. This is done by the following three | 
| 25   // steps (in order): 1. Open the serial port;  2. Request address; 3. Clear | 25   // steps (in order): 1. Open the serial port;  2. Request address; 3. Clear | 
| 26   // the command buffer. After these three steps completes, |open_callback| will | 26   // the command buffer. After these three steps completes, |open_callback| will | 
| 27   // be called. | 27   // be called. | 
| 28   void Open(const OpenCompleteCallback& open_callback); | 28   void Open(const OpenCompleteCallback& open_callback); | 
| 29 | 29 | 
| 30  private: | 30  private: | 
| 31   ~ViscaWebcam() override; | 31   ~ViscaWebcam() override; | 
| 32 | 32 | 
| 33   enum CommandType { | 33   enum InquiryType { | 
| 34     COMMAND, |  | 
| 35     INQUIRY_PAN, | 34     INQUIRY_PAN, | 
| 36     INQUIRY_TILT, | 35     INQUIRY_TILT, | 
| 37     INQUIRY_PAN_TILT, |  | 
| 38     INQUIRY_ZOOM, | 36     INQUIRY_ZOOM, | 
| 39   }; | 37   }; | 
| 40 | 38 | 
| 41   using CommandCompleteCallback = | 39   using CommandCompleteCallback = | 
| 42       base::Callback<void(bool, const std::vector<char>&)>; | 40       base::Callback<void(bool, const std::vector<char>&)>; | 
| 43 | 41 | 
| 44   void OpenOnIOThread(const OpenCompleteCallback& open_callback); | 42   void OpenOnIOThread(const OpenCompleteCallback& open_callback); | 
| 45   // Callback function that will be called after the serial connection has been | 43   // Callback function that will be called after the serial connection has been | 
| 46   // opened successfully. | 44   // opened successfully. | 
| 47   void OnConnected(const OpenCompleteCallback& open_callback, bool success); | 45   void OnConnected(const OpenCompleteCallback& open_callback, bool success); | 
| (...skipping 11 matching lines...) Expand all  Loading... | 
| 59   // Send or queue a command and wait for the camera's response. | 57   // Send or queue a command and wait for the camera's response. | 
| 60   void Send(const std::vector<char>& command, | 58   void Send(const std::vector<char>& command, | 
| 61             const CommandCompleteCallback& callback); | 59             const CommandCompleteCallback& callback); | 
| 62   void OnSendCompleted(const CommandCompleteCallback& callback, | 60   void OnSendCompleted(const CommandCompleteCallback& callback, | 
| 63                        int bytes_sent, | 61                        int bytes_sent, | 
| 64                        api::serial::SendError error); | 62                        api::serial::SendError error); | 
| 65   void ReceiveLoop(const CommandCompleteCallback& callback); | 63   void ReceiveLoop(const CommandCompleteCallback& callback); | 
| 66   void OnReceiveCompleted(const CommandCompleteCallback& callback, | 64   void OnReceiveCompleted(const CommandCompleteCallback& callback, | 
| 67                           const std::vector<char>& data, | 65                           const std::vector<char>& data, | 
| 68                           api::serial::ReceiveError error); | 66                           api::serial::ReceiveError error); | 
|  | 67 | 
| 69   // Callback function that will be called after the send and reply of a command | 68   // Callback function that will be called after the send and reply of a command | 
| 70   // are both completed. Update |value| according to |type| and |response| if | 69   // are both completed. | 
| 71   // necessory. | 70   void OnCommandCompleted(const SetPTZCompleteCallback& callback, | 
| 72   void OnCommandCompleted(CommandType type, | 71                           bool success, | 
| 73                           int* value, | 72                           const std::vector<char>& response); | 
|  | 73   // Callback function that will be called after the send and reply of an | 
|  | 74   // inquiry are both completed. | 
|  | 75   void OnInquiryCompleted(InquiryType type, | 
|  | 76                           const GetPTZCompleteCallback& callback, | 
| 74                           bool success, | 77                           bool success, | 
| 75                           const std::vector<char>& response); | 78                           const std::vector<char>& response); | 
| 76 | 79 | 
| 77   // Webcam Overrides: | 80   // Webcam Overrides: | 
| 78   void Reset(bool pan, bool tilt, bool zoom) override; | 81   void GetPan(const GetPTZCompleteCallback& callback) override; | 
| 79   bool GetPan(int* value) override; | 82   void GetTilt(const GetPTZCompleteCallback& callback) override; | 
| 80   bool GetTilt(int* value) override; | 83   void GetZoom(const GetPTZCompleteCallback& callback) override; | 
| 81   bool GetZoom(int* value) override; | 84   void SetPan(int value, const SetPTZCompleteCallback& callback) override; | 
| 82   bool SetPan(int value) override; | 85   void SetTilt(int value, const SetPTZCompleteCallback& callback) override; | 
| 83   bool SetTilt(int value) override; | 86   void SetZoom(int value, const SetPTZCompleteCallback& callback) override; | 
| 84   bool SetZoom(int value) override; | 87   void SetPanDirection(PanDirection direction, | 
| 85   bool SetPanDirection(PanDirection direction) override; | 88                        const SetPTZCompleteCallback& callback) override; | 
| 86   bool SetTiltDirection(TiltDirection direction) override; | 89   void SetTiltDirection(TiltDirection direction, | 
|  | 90                         const SetPTZCompleteCallback& callback) override; | 
|  | 91   void Reset(bool pan, | 
|  | 92              bool tilt, | 
|  | 93              bool zoom, | 
|  | 94              const SetPTZCompleteCallback& callback) override; | 
| 87 | 95 | 
| 88   const std::string path_; | 96   const std::string path_; | 
| 89   const std::string extension_id_; | 97   const std::string extension_id_; | 
| 90 | 98 | 
| 91   scoped_ptr<SerialConnection> serial_connection_; | 99   scoped_ptr<SerialConnection> serial_connection_; | 
| 92 | 100 | 
| 93   // Stores the response for the current command. | 101   // Stores the response for the current command. | 
| 94   std::vector<char> data_buffer_; | 102   std::vector<char> data_buffer_; | 
| 95   // Queues commands till the current command completes. | 103   // Queues commands till the current command completes. | 
| 96   std::deque<std::pair<std::vector<char>, CommandCompleteCallback>> commands_; | 104   std::deque<std::pair<std::vector<char>, CommandCompleteCallback>> commands_; | 
| 97 | 105 | 
| 98   // Visca webcam always get/set pan-tilt together. |pan| and |tilt| are used to | 106   // Visca webcam always get/set pan-tilt together. |pan| and |tilt| are used to | 
| 99   // store the current value of pan and tilt positions. | 107   // store the current value of pan and tilt positions. | 
| 100   int pan_; | 108   int pan_; | 
| 101   int tilt_; | 109   int tilt_; | 
| 102 | 110 | 
| 103   base::WeakPtrFactory<ViscaWebcam> weak_ptr_factory_; | 111   base::WeakPtrFactory<ViscaWebcam> weak_ptr_factory_; | 
| 104 | 112 | 
| 105   DISALLOW_COPY_AND_ASSIGN(ViscaWebcam); | 113   DISALLOW_COPY_AND_ASSIGN(ViscaWebcam); | 
| 106 }; | 114 }; | 
| 107 | 115 | 
| 108 }  // namespace extensions | 116 }  // namespace extensions | 
| 109 | 117 | 
| 110 #endif  // EXTENSIONS_BROWSER_API_WEBCAM_PRIVATE_VISCA_WEBCAM_H_ | 118 #endif  // EXTENSIONS_BROWSER_API_WEBCAM_PRIVATE_VISCA_WEBCAM_H_ | 
| OLD | NEW | 
|---|