cygprofile: increase timeouts to allow showing web contents
[chromium-blink-merge.git] / extensions / browser / api / webcam_private / visca_webcam.h
blob67ba75973c89c04d782f1928a9795f5cdde14cf2
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.
5 #ifndef EXTENSIONS_BROWSER_API_WEBCAM_PRIVATE_VISCA_WEBCAM_H_
6 #define EXTENSIONS_BROWSER_API_WEBCAM_PRIVATE_VISCA_WEBCAM_H_
8 #include <deque>
10 #include "base/callback.h"
11 #include "base/memory/weak_ptr.h"
12 #include "extensions/browser/api/serial/serial_connection.h"
13 #include "extensions/browser/api/webcam_private/webcam.h"
14 #include "extensions/common/api/serial.h"
16 namespace extensions {
18 class ViscaWebcam : public Webcam {
19 public:
20 ViscaWebcam(const std::string& path, const std::string& extension_id);
22 using OpenCompleteCallback = base::Callback<void(bool)>;
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
26 // the command buffer. After these three steps completes, |open_callback| will
27 // be called.
28 void Open(const OpenCompleteCallback& open_callback);
30 private:
31 ~ViscaWebcam() override;
33 enum InquiryType {
34 INQUIRY_PAN,
35 INQUIRY_TILT,
36 INQUIRY_ZOOM,
39 using CommandCompleteCallback =
40 base::Callback<void(bool, const std::vector<char>&)>;
42 void OpenOnIOThread(const OpenCompleteCallback& open_callback);
43 // Callback function that will be called after the serial connection has been
44 // opened successfully.
45 void OnConnected(const OpenCompleteCallback& open_callback, bool success);
46 // Callback function that will be called after the address has been set
47 // successfully.
48 void OnAddressSetCompleted(const OpenCompleteCallback& open_callback,
49 bool success,
50 const std::vector<char>& response);
51 // Callback function that will be called after the command buffer has been
52 // cleared successfully.
53 void OnClearAllCompleted(const OpenCompleteCallback& open_callback,
54 bool success,
55 const std::vector<char>& response);
57 // Send or queue a command and wait for the camera's response.
58 void Send(const std::vector<char>& command,
59 const CommandCompleteCallback& callback);
60 void OnSendCompleted(const CommandCompleteCallback& callback,
61 int bytes_sent,
62 api::serial::SendError error);
63 void ReceiveLoop(const CommandCompleteCallback& callback);
64 void OnReceiveCompleted(const CommandCompleteCallback& callback,
65 const std::vector<char>& data,
66 api::serial::ReceiveError error);
68 // Callback function that will be called after the send and reply of a command
69 // are both completed.
70 void OnCommandCompleted(const SetPTZCompleteCallback& callback,
71 bool success,
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,
77 bool success,
78 const std::vector<char>& response);
80 // Webcam Overrides:
81 void GetPan(const GetPTZCompleteCallback& callback) override;
82 void GetTilt(const GetPTZCompleteCallback& callback) override;
83 void GetZoom(const GetPTZCompleteCallback& callback) override;
84 void SetPan(int value,
85 int pan_speed,
86 const SetPTZCompleteCallback& callback) override;
87 void SetTilt(int value,
88 int tilt_speed,
89 const SetPTZCompleteCallback& callback) override;
90 void SetZoom(int value, const SetPTZCompleteCallback& callback) override;
91 void SetPanDirection(PanDirection direction,
92 int pan_speed,
93 const SetPTZCompleteCallback& callback) override;
94 void SetTiltDirection(TiltDirection direction,
95 int tilt_speed,
96 const SetPTZCompleteCallback& callback) override;
97 void Reset(bool pan,
98 bool tilt,
99 bool zoom,
100 const SetPTZCompleteCallback& callback) override;
102 const std::string path_;
103 const std::string extension_id_;
105 scoped_ptr<SerialConnection> serial_connection_;
107 // Stores the response for the current command.
108 std::vector<char> data_buffer_;
109 // Queues commands till the current command completes.
110 std::deque<std::pair<std::vector<char>, CommandCompleteCallback>> commands_;
112 // Visca webcam always get/set pan-tilt together. |pan| and |tilt| are used to
113 // store the current value of pan and tilt positions.
114 int pan_;
115 int tilt_;
117 base::WeakPtrFactory<ViscaWebcam> weak_ptr_factory_;
119 DISALLOW_COPY_AND_ASSIGN(ViscaWebcam);
122 } // namespace extensions
124 #endif // EXTENSIONS_BROWSER_API_WEBCAM_PRIVATE_VISCA_WEBCAM_H_