Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(154)

Side by Side Diff: extensions/browser/api/webcam_private/visca_webcam.h

Issue 1281263003: Change webcamPrivate.set/get/reset to async APIs. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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, 36 INQUIRY_PAN_TILT,
38 INQUIRY_ZOOM, 37 INQUIRY_ZOOM,
39 }; 38 };
40 39
41 using CommandCompleteCallback = 40 using CommandCompleteCallback =
42 base::Callback<void(bool, const std::vector<char>&)>; 41 base::Callback<void(bool, const std::vector<char>&)>;
43 42
44 void OpenOnIOThread(const OpenCompleteCallback& open_callback); 43 void OpenOnIOThread(const OpenCompleteCallback& open_callback);
(...skipping 14 matching lines...) Expand all
59 // Send or queue a command and wait for the camera's response. 58 // Send or queue a command and wait for the camera's response.
60 void Send(const std::vector<char>& command, 59 void Send(const std::vector<char>& command,
61 const CommandCompleteCallback& callback); 60 const CommandCompleteCallback& callback);
62 void OnSendCompleted(const CommandCompleteCallback& callback, 61 void OnSendCompleted(const CommandCompleteCallback& callback,
63 int bytes_sent, 62 int bytes_sent,
64 api::serial::SendError error); 63 api::serial::SendError error);
65 void ReceiveLoop(const CommandCompleteCallback& callback); 64 void ReceiveLoop(const CommandCompleteCallback& callback);
66 void OnReceiveCompleted(const CommandCompleteCallback& callback, 65 void OnReceiveCompleted(const CommandCompleteCallback& callback,
67 const std::vector<char>& data, 66 const std::vector<char>& data,
68 api::serial::ReceiveError error); 67 api::serial::ReceiveError error);
68
69 // Callback function that will be called after the send and reply of a command 69 // 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 70 // are both completed.
71 // necessory. 71 void OnCommandCompleted(const SetPTZCompleteCallback& callback,
72 void OnCommandCompleted(CommandType type, 72 bool success,
73 int* value, 73 const std::vector<char>& response);
74 // Callback function that will be called after the send and reply of an
75 // inquiry are both completed.
76 void OnInquiryCompleted(InquiryType type,
77 const GetPTZCompleteCallback& callback,
74 bool success, 78 bool success,
75 const std::vector<char>& response); 79 const std::vector<char>& response);
76 80
77 // Webcam Overrides: 81 // Webcam Overrides:
78 void Reset(bool pan, bool tilt, bool zoom) override; 82 void GetPan(const GetPTZCompleteCallback& callback) override;
79 bool GetPan(int* value) override; 83 void GetTilt(const GetPTZCompleteCallback& callback) override;
80 bool GetTilt(int* value) override; 84 void GetZoom(const GetPTZCompleteCallback& callback) override;
81 bool GetZoom(int* value) override; 85 void SetPan(int value, const SetPTZCompleteCallback& callback) override;
82 bool SetPan(int value) override; 86 void SetTilt(int value, const SetPTZCompleteCallback& callback) override;
83 bool SetTilt(int value) override; 87 void SetZoom(int value, const SetPTZCompleteCallback& callback) override;
84 bool SetZoom(int value) override; 88 void SetPanDirection(PanDirection direction,
85 bool SetPanDirection(PanDirection direction) override; 89 const SetPTZCompleteCallback& callback) override;
86 bool SetTiltDirection(TiltDirection direction) override; 90 void SetTiltDirection(TiltDirection direction,
91 const SetPTZCompleteCallback& callback) override;
92 void Reset(bool pan,
93 bool tilt,
94 bool zoom,
95 const SetPTZCompleteCallback& callback) override;
87 96
88 const std::string path_; 97 const std::string path_;
89 const std::string extension_id_; 98 const std::string extension_id_;
90 99
91 scoped_ptr<SerialConnection> serial_connection_; 100 scoped_ptr<SerialConnection> serial_connection_;
92 101
93 // Stores the response for the current command. 102 // Stores the response for the current command.
94 std::vector<char> data_buffer_; 103 std::vector<char> data_buffer_;
95 // Queues commands till the current command completes. 104 // Queues commands till the current command completes.
96 std::deque<std::pair<std::vector<char>, CommandCompleteCallback>> commands_; 105 std::deque<std::pair<std::vector<char>, CommandCompleteCallback>> commands_;
97 106
98 // Visca webcam always get/set pan-tilt together. |pan| and |tilt| are used to 107 // Visca webcam always get/set pan-tilt together. |pan| and |tilt| are used to
99 // store the current value of pan and tilt positions. 108 // store the current value of pan and tilt positions.
100 int pan_; 109 int pan_;
101 int tilt_; 110 int tilt_;
102 111
103 base::WeakPtrFactory<ViscaWebcam> weak_ptr_factory_; 112 base::WeakPtrFactory<ViscaWebcam> weak_ptr_factory_;
104 113
105 DISALLOW_COPY_AND_ASSIGN(ViscaWebcam); 114 DISALLOW_COPY_AND_ASSIGN(ViscaWebcam);
106 }; 115 };
107 116
108 } // namespace extensions 117 } // namespace extensions
109 118
110 #endif // EXTENSIONS_BROWSER_API_WEBCAM_PRIVATE_VISCA_WEBCAM_H_ 119 #endif // EXTENSIONS_BROWSER_API_WEBCAM_PRIVATE_VISCA_WEBCAM_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698