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

Side by Side Diff: components/proximity_auth/ble/bluetooth_low_energy_weave_packet_receiver.h

Issue 2053013002: Weave Packet Receiver (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@proximity_auth_weave_migration
Patch Set: code complete built Created 4 years, 6 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
(Empty)
1 // 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.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef COMPONENTS_PROXIMITY_AUTH_BLE_BLUETOOTH_LOW_ENERGY_WEAVE_PACKET_RECEIVER _H_
6 #define COMPONENTS_PROXIMITY_AUTH_BLE_BLUETOOTH_LOW_ENERGY_WEAVE_PACKET_RECEIVER _H_
7
8 #include <stdint.h>
9
10 #include <memory>
11 #include <string>
12 #include <vector>
13
14 #include "components/proximity_auth/ble/bluetooth_low_energy_weave_packet_genera tor.h"
15
16 namespace proximity_auth {
17 // Receive the messages sent with uWeave protocol.
18 // TODO(jingxuy): move the enums from BluetoothLowEnergyWeavePacketGenerator to
19 // a shared location
20 class BluetoothLowEnergyWeavePacketReceiver {
21 public:
22 class Factory {
23 public:
24 static std::unique_ptr<BluetoothLowEnergyWeavePacketReceiver> NewInstance();
25
26 // Exposed for testing.
27 static void SetInstanceForTesting(Factory* factory);
28
29 protected:
30 // Exposed for testing.
31 BluetoothLowEnergyWeavePacketReceiver* BuildInstance();
32
33 private:
34 static Factory* factory_instance_;
35 };
36
37 enum State {
38 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
39 RECEIVING_DATA = 0x01,
40 DATA_READY = 0x02,
41 CONNECTION_CLOSED = 0x03,
42 ERROR = 0x04
43 };
44
45 ~BluetoothLowEnergyWeavePacketReceiver();
46
47 typedef std::vector<uint8_t> Packet;
48
49 // Get the receiver’s state.
50 State GetState();
51
52 // Return the packet size that the receiver parsed out of request/response.
53 uint32_t GetPacketSize();
54
55 // Return something valid only when receiver in CONNECTION_CLOSED
56 BluetoothLowEnergyWeavePacketGenerator::ReasonForClose GetReasonForClose();
57
58 // Returns non empty string only when the receiver is in DATA_READY
59 std::string GetDataMessage();
60
61 // Add a packet that's just been received over Connection to the receiver
62 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.
63
64 protected:
65 BluetoothLowEnergyWeavePacketReceiver();
66
67 private:
68 uint16_t GetShortField(const Packet& packet, uint32_t index);
69 BluetoothLowEnergyWeavePacketGenerator::PacketType GetPacketType(
70 const Packet& packet);
71 BluetoothLowEnergyWeavePacketGenerator::ControlPacketCommand
72 GetControlCommand(const Packet& packet);
73 void VerifyPacketCounter(const Packet& packet);
74 bool IsFirstDataPacket(const Packet& packet);
75 bool IsLastDataPacket(const Packet& packet);
76
77 // Max packet size of the connection.
78 // Default is 0 which means the server will determine the size by observing
79 // ATT_MTU of the client.
80 uint32_t packet_size_;
81
82 // Counter for the number of packets sent, starting at 0
83 uint32_t packet_number_;
84
85 // Current state of the receiver.
86 // Certain functions will only return valid value if the receiver is in the
87 // appropriate state
88 State state_;
89
90 // The reason why the connection was closed if any
91 BluetoothLowEnergyWeavePacketGenerator::ReasonForClose reason_for_close_;
92
93 // The data message if there is one
94 std::vector<uint8_t> data_message_;
95 };
96
97 } // namespace proximity_auth
98
99 #endif // COMPONENTS_PROXIMITY_AUTH_BLE_BLUETOOTH_LOW_ENERGY_WEAVE_PACKET_RECEI VER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698