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

Side by Side Diff: device/bluetooth/bluetooth_profile.h

Issue 13862023: Add abstract BluetoothProfile class (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 8 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2013 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 DEVICE_BLUETOOTH_BLUETOOTH_PROFILE_H_
6 #define DEVICE_BLUETOOTH_BLUETOOTH_PROFILE_H_
7
8 #include <string>
9
10 #include "base/callback.h"
11 #include "base/memory/ref_counted.h"
12
13 namespace device {
14
15 class BluetoothSocket;
16
17 // BluetoothProfile represents an implementation of either a client or server
18 // of a particular specified profile (aka service or protocol in other
19 // standards).
20 //
21 // Profile implementations are created by registering them through the static
22 // BluetoothProfile::Register() method and are always identified by a UUID
23 // which in any method may be specified in the short or long form.
24 //
25 // The lifecycle of BluetoothProfile instances is managed by the implementation
26 // but they are guaranteed to exist once provided to a Register() callback until
27 // the instance's Unregister() method is called, so others may hold on to
28 // pointers to them.
29 class BluetoothProfile {
30 public:
31 // Register an implementation of the profile with UUID |uuid|, the
32 // corresponding profile object will be created and returned by
33 // |callback|. If the profile cannot be registered, NULL will be passed.
34 //
35 // This pointer is not owned by the received, but will not be freed unless
36 // its Unregister() method is called.
37 typedef base::Callback<void(BluetoothProfile*)> ProfileCallback;
38 static void Register(const std::string& uuid,
39 const ProfileCallback& callback);
40
41 // Unregister the profile, once called any pointers to the profile should be
42 // discarded.
43 virtual void Unregister() = 0;
44
45 // Set the connection callback for the profile to |callback|, any successful
46 // connection initiated by BluetoothDevice::ConnectToProfile() or incoming
47 // connections from devices, will have a BluetoothSocket created and passed
48 // to this callback.
49 //
50 // The socket will be closed when all references are released; none of the
51 // BluetoothProfile, or BluetoothAdapter or BluetoothDevice objects are
52 // guaranteed to hold a reference so this may be outlive all of them.
youngki 2013/04/10 01:28:49 s/may be outlive/may outlive/
youngki 2013/04/10 19:39:05 Make sure to fix this before committing.
keybuk 2013/04/17 22:38:35 Done.
53 typedef base::Callback<void(scoped_refptr<BluetoothSocket>)> SocketCallback;
54 virtual void SetConnectionCallback(const SocketCallback& callback) = 0;
youngki 2013/04/10 01:28:49 Since bluetooth.onConnection is an event and we ar
youngki 2013/04/10 16:38:19 Or, if we want to keep this interface, we could ac
55
56 // Human readable name of the Profile, e.g. "Health Device".
youngki 2013/04/10 01:28:49 So all the below methods are for the profiles expo
57 // Exported in the adapter's SDP or GATT tables where relevant.
58 virtual void SetName(const std::string& name) = 0;
59 virtual std::string GetName() const = 0;
60
61 // RFCOMM channel used by the profile.
62 // Exported in the adapter's SDP or GATT tables where relevant.
63 virtual void SetChannel(uint16 channel) = 0;
64 virtual uint16 GetChannel() const = 0;
65
66 // L2CAP PSM number.
67 // Exported in the adapter's SDP or GATT tables where relevant.
68 virtual void SetPSM(uint16 psm) = 0;
69 virtual uint16 GetPSM() const = 0;
70
71 // Specifies whether pairing (and encryption) is required to be able to
72 // connect. Defaults to false.
73 virtual void SetRequireAuthentication(bool require_authentication) = 0;
74 virtual bool GetRequireAuthentication() const = 0;
75
76 // Specifies whether user authorization is required to be able to connect.
77 // Defaults to false.
78 virtual void SetRequireAuthorization(bool require_authorization) = 0;
79 virtual bool GetRequireAuthorization() const = 0;
80
81 // Implemented version of the profile.
82 // Exported in the adapter's SDP or GATT tables where relevant.
83 virtual void SetVersion(uint16 version) = 0;
84 virtual uint16 GetVersion() const = 0;
85
86 // Implemented feature set of the profile.
87 // Exported in the adapter's SDP or GATT tables where relevant.
88 virtual void SetFeatures(uint16 features) = 0;
89 virtual uint16 GetFeatures() const = 0;
90
91 private:
92 BluetoothProfile();
93 virtual ~BluetoothProfile();
youngki 2013/04/11 18:33:41 Shouldn't the destructor be protected? Otherwise t
keybuk 2013/04/17 22:38:35 Unregister() should be doing the deletion - so it
youngki 2013/04/19 16:26:36 I think you are trying to follow RefCounted model
keybuk 2013/04/19 17:58:18 I don't like patterns where you get an object via
youngki 2013/04/19 18:20:39 sounds good
94 };
95
96 } // namespace device
97
98 #endif /* DEVICE_BLUETOOTH_BLUETOOTH_PROFILE_H_ */
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698