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

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

Issue 2031953003: Weave Packet Generator (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: changed name of ControlPacketCommand to ControlCommand 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 2016 The Chromium Authors. All rights reserved.
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_GENERATO R_H_
6 #define COMPONENTS_PROXIMITY_AUTH_BLE_BLUETOOTH_LOW_ENERGY_WEAVE_PACKET_GENERATO R_H_
7
8 #include <stddef.h>
9 #include <stdint.h>
10
11 #include <memory>
12 #include <string>
13 #include <vector>
14
15 namespace proximity_auth {
16 // Generates the messages sent using the uWeave protocol.
17 class BluetoothLowEnergyWeavePacketGenerator {
18 public:
19 class Factory {
20 public:
21 static std::unique_ptr<BluetoothLowEnergyWeavePacketGenerator>
22 NewInstance();
23
24 // Exposed for testing.
25 static void SetInstanceForTesting(Factory* factory);
26
27 protected:
28 // Exposed for testing.
29 BluetoothLowEnergyWeavePacketGenerator* BuildInstance();
Tim Song 2016/06/09 22:45:35 This should be virtual if you are overriding it in
jingxuy 2016/06/11 00:49:32 this function is protected, the function that call
Kyle Horimoto 2016/06/13 17:55:53 You can just have NewInstance() return the unique_
jingxuy 2016/06/17 00:56:45 Done.
30
31 private:
32 static Factory* factory_instance_;
33 };
34
35 // Determine whether a packet is a control packet or a data packet.
36 enum PacketType { DATA = 0x00, CONTROL = 0x01 };
37
38 // Identify the action intended by the control packet.
39 enum ControlCommand {
40 CONNECTION_REQUEST = 0x00,
41 CONNECTION_RESPONSE = 0x01,
42 CONNECTION_CLOSE = 0x02
43 };
44
45 // Sent with the ConnectionClose control packet.
46 // Identify why the client/server wished to close the connection.
47 enum ReasonForClose {
48 CLOSE_WITHOUT_ERROR = 0x00,
49 UNKNOWN_ERROR = 0x01,
50 NO_COMMON_VERSION_SUPPORTED = 0x02,
51 RECEIVED_PACKET_OUT_OF_SEQUENCE = 0x03,
52 APPLICATION_ERROR = 0x80
53 };
54
55 typedef std::vector<uint8_t> Packet;
56
57 std::unique_ptr<Packet> CreateConnectionRequest();
58 std::unique_ptr<Packet> CreateConnectionResponse();
59 std::unique_ptr<Packet> CreateConnectionClose(
60 ReasonForClose reason_for_close);
61
62 void SetDataPacketSize(uint32_t size);
63
64 std::unique_ptr<std::vector<Packet>> EncodeDataMessage(std::string message);
Tim Song 2016/06/09 22:45:35 Just return a std::vector<Packet>. The compiler wi
jingxuy 2016/06/11 00:49:32 The reason that it's a unique_ptr right now is bec
Kyle Horimoto 2016/06/13 17:55:53 Tim is saying to return a full vector (by value) i
jingxuy 2016/06/17 00:56:45 Hmmm, maybe I was unclear when I asked the questio
65
66 protected:
67 BluetoothLowEnergyWeavePacketGenerator();
68
69 private:
70 Packet* CreateControlPacket();
Tim Song 2016/06/09 22:45:35 Same here. I would return a unique_ptr even in pri
jingxuy 2016/06/11 00:49:32 this is a private helper function, I think it's fi
Kyle Horimoto 2016/06/13 17:55:53 It's generally a best practice to use this everywh
jingxuy 2016/06/17 00:56:45 Done.
71
72 // For error checking.
73 bool IsBit(uint8_t val);
74
75 void SetShortField(Packet* packet, uint32_t index, uint16_t val);
76 void SetPacketTypeBit(Packet* packet, PacketType val);
77 void SetControlCommand(Packet* packet, ControlCommand val);
78 void SetPacketCounter(Packet* packet);
79 void SetDataFirstBit(Packet* packet);
80 void SetDataLastBit(Packet* packet);
81
82 // The default data packet length is 20 unless setDataPacketLength() is called
Tim Song 2016/06/09 22:45:35 nit: set should be capitalized.
jingxuy 2016/06/11 00:49:32 Done.
83 // and specified otherwise.
84 uint32_t packet_size_;
85
86 // Counter for the number of packets sent, starting at 0.
87 uint32_t packet_number_;
88 };
89
90 } // namespace proximity_auth
91
92 #endif // COMPONENTS_PROXIMITY_AUTH_BLE_BLUETOOTH_LOW_ENERGY_WEAVE_PACKET_GENER ATOR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698