Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rework the 'Connect to Sensor' abstract operation #300

Merged
merged 1 commit into from
Oct 4, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 20 additions & 27 deletions index.bs
Original file line number Diff line number Diff line change
Expand Up @@ -599,8 +599,13 @@ for each [=sensor types|type=]
simply by instantiating the corresponding {{Sensor}} subclass.

Indeed, without specific information identifying a particular [=device sensor|sensor=]
of a given [=sensor type|type=],
the <dfn export>default sensor</dfn> is chosen.
of a given [=sensor type|type=], the <dfn export>default sensor</dfn> is chosen by the
user agent.

If the underlying platform provides an interface to find the [=default sensor=],
the user agent must choose the sensor offered by the platform, otherwise the user agent
itself defines which of the [=device sensor|sensors=] present on the device is
the [=default sensor=].

<div class="example">
Listening to the default accelerometer changes:
Expand Down Expand Up @@ -704,10 +709,6 @@ whose [=inherited interfaces=] contains {{Sensor}}.

A [=sensor type=] has a [=ordered set|set=] of <dfn export>associated sensors</dfn>.

If a [=sensor type=] has more than one [=platform sensor=],
it must have a set of associated <dfn export>identifying parameters</dfn>
to select the right [=platform sensor=] to associate to each new {{Sensor}} objects.

A [=sensor type=] may have a [=default sensor=].

A [=sensor type=] has an associated {{PermissionName}}.
Expand Down Expand Up @@ -964,14 +965,6 @@ with the internal slots described in the following table:
notified after a new [=sensor reading=] was reported.
It is initially false.</td>
</tr>
<tr>
<td><dfn attribute for=Sensor>\[[identifyingParameters]]</dfn></td>
<td>
A [=sensor type=]-specific group of [=dictionary members=]
used to select the correct [=platform sensor=]
to associate to this {{Sensor}} object.
</td>
</tr>
</tbody>
</table>

Expand Down Expand Up @@ -1016,7 +1009,8 @@ and "timestamp" as arguments.
or "activated", then return.
1. Set |sensor_instance|.{{[[state]]}} to "activating".
1. Run these sub-steps [=in parallel=]:
1. let |connected| be the result of invoking [=connect to sensor=].
1. let |connected| be the result of invoking [=connect to sensor=] with |sensor_instance|
as argument.
1. If |connected| is false, then
1. Let |e| be the result of [=created|creating=] a
"{{NotReadableError!!exception}}" {{DOMException}}.
Expand Down Expand Up @@ -1143,8 +1137,6 @@ Gets the {{Error}} object passed to {{SensorErrorEventInit}}.
Note: there is not guarantee that the requested |options|.{{frequency!!dict-member}}
can be respected. The actual [=sampling frequency=] can be calculated using
{{Sensor}} {{Sensor/timestamp!!attribute}} attributes.
1. If [=identifying parameters=] in |options| are set, then:
1. Set |sensor_instance|.{{[[identifyingParameters]]}} to [=identifying parameters=].
1. Set |sensor_instance|.{{[[state]]}} to "idle".
1. Return |sensor_instance|.
</div>
Expand All @@ -1160,16 +1152,18 @@ Gets the {{Error}} object passed to {{SensorErrorEventInit}}.
:: True if sensor instance was associated with a [=platform sensor=],
false otherwise.

1. If |sensor_instance|.{{[[identifyingParameters]]}} is set and
|sensor_instance|.{{[[identifyingParameters]]}} allows
a unique [=platform sensor=] to be identified, then:
1. let |sensor| be that [=platform sensor=],
1. associate |sensor_instance| with |sensor|.
1. Return true.
1. If the [=sensor type=] of |sensor_instance| has an associated [=default sensor=]
and there is a corresponding [=platform sensor=] on the device, then
1. associate |sensor_instance| with [=default sensor=].
1. Let |type| be the [=sensor type=] of |sensor_instance|.
1. If the device has a single [=device sensor=] which can provide [=sensor readings|readings=]
for |type|, then
1. Associate |sensor_instance| with a [=platform sensor=] corresponding
to this [=device sensor=].
1. Return true.
1. If the device has multiple [=device sensors=] which can provide [=sensor readings|readings=]
for |type|, then
1. If |type| has an associated [=default sensor=], then

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If platform does not have concept of default sensor, false would be returned, is that expected?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but that's not a platform concept, default sensor is defined in an extension API, e.g. here https://www.w3.org/TR/accelerometer/#model, so if a device has multiple accelerometers, the UA will assume one of them to be the default.

Copy link

@alexshalamov alexshalamov Oct 4, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks, additional text addresses my concern about vague definition of default sensor.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Outside this change in Sensor.start(), where you invoke this connect to sensor abstract operation, you should change:

let connected be the result of invoking connect to sensor.

To

let connected be the result of invoking connect to sensor with sensor_instance as argument.

Might be a separate patch, or could be rolled into this one since related.

1. Associate |sensor_instance| with a [=platform sensor=] corresponding
to [=default sensor=].
1. Return true.
1. Return false.
</div>

Expand Down Expand Up @@ -1528,7 +1522,6 @@ for each [=sensor types=]:
For [=sensor types=] where multiple [=device sensor|sensors=] are common,
[=extension specifications=] may choose not to define a [=default sensor=],
especially when doing so would not make sense.
- A set of [=identifying parameters=]. TODO: replace that by an abstract operation.

<h3 id="permission-api">Extending the Permission API</h3>

Expand Down
Loading