CSC/ECE 517 Spring 2019 - M1902 Refactor bluetooth support for better maintainability: Difference between revisions

From Expertiza_Wiki
Jump to navigation Jump to search
(No difference)

Revision as of 00:56, 26 March 2019

Introduction

Servo

Servo is a prototype web browser engine, developed on 64-bit macOS, 64-bit Linux, 64-bit Windows, and Android. The goal is to create a new layout engine using a modern programming language (Rust), and using parallelism and code safety, to achieve greater security and performance versus contemporary browsers.

For more information, click here

Rust

Rust is a new open-source systems programming language created by Mozilla and a community of volunteers, designed to help developers create fast, secure applications which take full advantage of the powerful features of modern multi-core processors. It prevents segmentation faults and guarantees thread safety, all with an easy-to-learn syntax. Rust is syntactically similar to C++, but is designed to provide better memory safety while maintaining high performance.

For more information, click here

WebBluetooth - Problem Statement

The WebBluetooth specification allows websites to interact with active bluetooth devices in the vicinity of a user. Servo is a new, experimental browser that implements this specification; since bluetooth support requires lots of per-platform code, the current implementation is messy. The goal of this project is to implement clean separation of a cross-platform interface from the specific per-platform implementation to make the code more maintainable.

Implementation

The refactoring mainly involved converting value of type from enum to trait. Traits make it easier to add new implementations to the code than enum. Trait objects points to an instance of a type that implements the trait we specify. Trait object can be created by by specifying some sort of pointer, such as a & reference or a Box<T> smart pointer, and then specifying the relevant trait, and adding a dyn keyword.

Steps

  • To convert the BluetoothAdapter type from an enum to a trait.
  • To create a new adapter.rs file (and therefore module) that contains implementations of this new trait for all platforms.
  • To modify Servo's integration to use this new trait, replacing uses of the old BluetoothAdapter enum with a trait object.
  • To convert the BluetoothDiscoverySession type from an enum to a trait.
  • To create a new discovery_session.rs file that contains implementations of this new trait for all platforms.
  • To modify Servo's integration to use this new trait, replacing uses of the old BluetoothDiscoverySession enum with a trait object.

Files(to be)modified

In servo repository,

  • servo/components/bluetooth/lib.rs

In devices repository,

  • devices/src/bluetooth.rs