Chromium Code Reviews| Index: components/proximity_auth/ble/bluetooth_low_energy_weave_packet_receiver.h |
| diff --git a/components/proximity_auth/ble/bluetooth_low_energy_weave_packet_receiver.h b/components/proximity_auth/ble/bluetooth_low_energy_weave_packet_receiver.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..422a422d83f5cc25380650645891b83223a089a9 |
| --- /dev/null |
| +++ b/components/proximity_auth/ble/bluetooth_low_energy_weave_packet_receiver.h |
| @@ -0,0 +1,99 @@ |
| +// Copyright 2015 The Chromium Authors. All rights reserved. |
|
Tim Song
2016/06/09 22:08:35
nit:2016
jingxuy
2016/06/09 23:29:04
Done.
|
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef COMPONENTS_PROXIMITY_AUTH_BLE_BLUETOOTH_LOW_ENERGY_WEAVE_PACKET_RECEIVER_H_ |
| +#define COMPONENTS_PROXIMITY_AUTH_BLE_BLUETOOTH_LOW_ENERGY_WEAVE_PACKET_RECEIVER_H_ |
| + |
| +#include <stdint.h> |
| + |
| +#include <memory> |
| +#include <string> |
| +#include <vector> |
| + |
| +#include "components/proximity_auth/ble/bluetooth_low_energy_weave_packet_generator.h" |
| + |
| +namespace proximity_auth { |
| +// Receive the messages sent with uWeave protocol. |
| +// TODO(jingxuy): move the enums from BluetoothLowEnergyWeavePacketGenerator to |
| +// a shared location |
| +class BluetoothLowEnergyWeavePacketReceiver { |
| + public: |
| + class Factory { |
| + public: |
| + static std::unique_ptr<BluetoothLowEnergyWeavePacketReceiver> NewInstance(); |
| + |
| + // Exposed for testing. |
| + static void SetInstanceForTesting(Factory* factory); |
| + |
| + protected: |
| + // Exposed for testing. |
| + BluetoothLowEnergyWeavePacketReceiver* BuildInstance(); |
| + |
| + private: |
| + static Factory* factory_instance_; |
| + }; |
| + |
| + enum State { |
| + EXCHANGING_CONTROLS = 0x00, |
|
Tim Song
2016/06/09 22:08:35
A better name for this state might be CONNECTING.
jingxuy
2016/06/09 23:29:04
Currently connecting and connected are the same st
Kyle Horimoto
2016/06/09 23:59:45
Shouldn't the "connected" state equivalent to rece
jingxuy
2016/06/11 00:10:46
I think what Tim has as connected is the equivalen
|
| + RECEIVING_DATA = 0x01, |
| + DATA_READY = 0x02, |
| + CONNECTION_CLOSED = 0x03, |
| + ERROR = 0x04 |
| + }; |
| + |
| + ~BluetoothLowEnergyWeavePacketReceiver(); |
| + |
| + typedef std::vector<uint8_t> Packet; |
| + |
| + // Get the receiver’s state. |
| + State GetState(); |
| + |
| + // Return the packet size that the receiver parsed out of request/response. |
| + uint32_t GetPacketSize(); |
| + |
| + // Return something valid only when receiver in CONNECTION_CLOSED |
| + BluetoothLowEnergyWeavePacketGenerator::ReasonForClose GetReasonForClose(); |
| + |
| + // Returns non empty string only when the receiver is in DATA_READY |
| + std::string GetDataMessage(); |
| + |
| + // Add a packet that's just been received over Connection to the receiver |
| + void ReceivePacket(const Packet& packet); |
|
Tim Song
2016/06/09 22:08:35
Perhaps you should return the current state as wel
jingxuy
2016/06/09 23:29:04
Done.
|
| + |
| + protected: |
| + BluetoothLowEnergyWeavePacketReceiver(); |
| + |
| + private: |
| + uint16_t GetShortField(const Packet& packet, uint32_t index); |
| + BluetoothLowEnergyWeavePacketGenerator::PacketType GetPacketType( |
| + const Packet& packet); |
| + BluetoothLowEnergyWeavePacketGenerator::ControlPacketCommand |
| + GetControlCommand(const Packet& packet); |
| + void VerifyPacketCounter(const Packet& packet); |
| + bool IsFirstDataPacket(const Packet& packet); |
| + bool IsLastDataPacket(const Packet& packet); |
| + |
| + // Max packet size of the connection. |
| + // Default is 0 which means the server will determine the size by observing |
| + // ATT_MTU of the client. |
| + uint32_t packet_size_; |
| + |
| + // Counter for the number of packets sent, starting at 0 |
| + uint32_t packet_number_; |
| + |
| + // Current state of the receiver. |
| + // Certain functions will only return valid value if the receiver is in the |
| + // appropriate state |
| + State state_; |
| + |
| + // The reason why the connection was closed if any |
| + BluetoothLowEnergyWeavePacketGenerator::ReasonForClose reason_for_close_; |
| + |
| + // The data message if there is one |
| + std::vector<uint8_t> data_message_; |
| +}; |
| + |
| +} // namespace proximity_auth |
| + |
| +#endif // COMPONENTS_PROXIMITY_AUTH_BLE_BLUETOOTH_LOW_ENERGY_WEAVE_PACKET_RECEIVER_H_ |