Commit ecc2c842 authored by delima02's avatar delima02 Committed by Commit Bot

Change GET to fail only if all retrievals fail + callback for set/reset.

Bug: 139488757
Change-Id: If51b977f7b9b3bc50a83a6328cebfdb6e0138aa5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1808715
Commit-Queue: Juan Pablo De Lima <jpdelima@chromium.org>
Reviewed-by: default avatarSteven Bennetts <stevenjb@chromium.org>
Reviewed-by: default avatarZachary Kuznia <zork@chromium.org>
Auto-Submit: Juan Pablo De Lima <jpdelima@chromium.org>
Cr-Commit-Position: refs/heads/master@{#706455}
parent 2949cca9
......@@ -176,10 +176,10 @@ class WebcamPrivateGetFunction : public ExtensionFunction {
int min_focus_;
int max_focus_;
int focus_;
bool get_pan_;
bool get_tilt_;
bool get_zoom_;
bool get_focus_;
bool got_pan_;
bool got_tilt_;
bool got_zoom_;
bool got_focus_;
bool success_;
DISALLOW_COPY_AND_ASSIGN(WebcamPrivateGetFunction);
......
......@@ -373,11 +373,11 @@ WebcamPrivateGetFunction::WebcamPrivateGetFunction()
min_focus_(0),
max_focus_(0),
focus_(0),
get_pan_(false),
get_tilt_(false),
get_zoom_(false),
get_focus_(false),
success_(true) {}
got_pan_(false),
got_tilt_(false),
got_zoom_(false),
got_focus_(false),
success_(false) {}
WebcamPrivateGetFunction::~WebcamPrivateGetFunction() {
}
......@@ -405,73 +405,82 @@ ExtensionFunction::ResponseAction WebcamPrivateGetFunction::Run() {
return did_respond() ? AlreadyResponded() : RespondLater();
}
// Retrieve webcam parameters. Will respond a config holding the requested
// values if any of the requests succeeds. Otherwise will respond an error.
void WebcamPrivateGetFunction::OnGetWebcamParameters(InquiryType type,
bool success,
int value,
int min_value,
int max_value) {
if (!success_)
return;
success_ = success_ && success;
success_ = success_ || success;
if (!success_) {
Respond(Error(kGetWebcamPTZError));
} else {
switch (type) {
case INQUIRY_PAN:
switch (type) {
case INQUIRY_PAN:
if (success) {
min_pan_ = min_value;
max_pan_ = max_value;
pan_ = value;
get_pan_ = true;
break;
case INQUIRY_TILT:
}
got_pan_ = true;
break;
case INQUIRY_TILT:
if (success) {
min_tilt_ = min_value;
max_tilt_ = max_value;
tilt_ = value;
get_tilt_ = true;
break;
case INQUIRY_ZOOM:
}
got_tilt_ = true;
break;
case INQUIRY_ZOOM:
if (success) {
min_zoom_ = min_value;
max_zoom_ = max_value;
zoom_ = value;
get_zoom_ = true;
break;
case INQUIRY_FOCUS:
}
got_zoom_ = true;
break;
case INQUIRY_FOCUS:
if (success) {
min_focus_ = min_value;
max_focus_ = max_value;
focus_ = value;
get_focus_ = true;
break;
}
if (get_pan_ && get_tilt_ && get_zoom_ && get_focus_) {
webcam_private::WebcamCurrentConfiguration result;
if (min_pan_ != max_pan_) {
result.pan_range = std::make_unique<webcam_private::Range>();
result.pan_range->min = min_pan_;
result.pan_range->max = max_pan_;
}
if (min_tilt_ != max_tilt_) {
result.tilt_range = std::make_unique<webcam_private::Range>();
result.tilt_range->min = min_tilt_;
result.tilt_range->max = max_tilt_;
}
if (min_zoom_ != max_zoom_) {
result.zoom_range = std::make_unique<webcam_private::Range>();
result.zoom_range->min = min_zoom_;
result.zoom_range->max = max_zoom_;
}
if (min_focus_ != max_focus_) {
result.focus_range = std::make_unique<webcam_private::Range>();
result.focus_range->min = min_focus_;
result.focus_range->max = max_focus_;
}
got_focus_ = true;
break;
}
if (got_pan_ && got_tilt_ && got_zoom_ && got_focus_) {
if (!success_) {
Respond(Error(kGetWebcamPTZError));
return;
}
result.pan = pan_;
result.tilt = tilt_;
result.zoom = zoom_;
result.focus = focus_;
Respond(OneArgument(result.ToValue()));
webcam_private::WebcamCurrentConfiguration result;
if (min_pan_ != max_pan_) {
result.pan_range = std::make_unique<webcam_private::Range>();
result.pan_range->min = min_pan_;
result.pan_range->max = max_pan_;
}
if (min_tilt_ != max_tilt_) {
result.tilt_range = std::make_unique<webcam_private::Range>();
result.tilt_range->min = min_tilt_;
result.tilt_range->max = max_tilt_;
}
if (min_zoom_ != max_zoom_) {
result.zoom_range = std::make_unique<webcam_private::Range>();
result.zoom_range->min = min_zoom_;
result.zoom_range->max = max_zoom_;
}
if (min_focus_ != max_focus_) {
result.focus_range = std::make_unique<webcam_private::Range>();
result.focus_range->min = min_focus_;
result.focus_range->max = max_focus_;
}
result.pan = pan_;
result.tilt = tilt_;
result.zoom = zoom_;
result.focus = focus_;
Respond(OneArgument(result.ToValue()));
}
}
......
......@@ -52,13 +52,22 @@ namespace webcamPrivate {
// Close a serial port connection to a webcam.
static void closeWebcam(DOMString webcamId);
// Retrieve webcam parameters. Will respond with a config holding the
// requested values that are available, or default values for those that
// aren't. If none of the requests succeed, will respond with an error.
static void get(DOMString webcamId, WebcamConfigurationCallback callback);
static void set(DOMString webcamId, WebcamConfiguration config);
// A callback is included here which is invoked when the function responds.
// No configuration is returned through it.
static void set(DOMString webcamId, WebcamConfiguration config,
WebcamConfigurationCallback callback);
// Reset a webcam. Note: the value of the parameter have no effect, it's the
// presence of the parameter that matters. E.g.: reset(webcamId, {pan: 0,
// tilt: 1}); will reset pan & tilt, but not zoom.
static void reset(DOMString webcamId, WebcamConfiguration config);
// A callback is included here which is invoked when the function responds.
// No configuration is returned through it.
static void reset(DOMString webcamId, WebcamConfiguration config,
WebcamConfigurationCallback callback);
};
};
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment