• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2021 HIMSA II K/S - www.himsa.com.
3  * Represented by EHIMA - www.ehima.com
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
18 #pragma once
19 #include <list>
20 
21 #include "types/bluetooth/uuid.h"
22 #include "types/raw_address.h"
23 
24 namespace bluetooth {
25 namespace groups {
26 
27 static constexpr int kGroupUnknown = -1;
28 static const bluetooth::Uuid kGenericContextUuid =
29     bluetooth::Uuid::From16Bit(0x0000);
30 
31 class DeviceGroupsCallbacks {
32  public:
33   virtual ~DeviceGroupsCallbacks() = default;
34 
35   /* Notifies first group appearance.
36    * This callback also contains first group member and uuid of the group.
37    */
38   virtual void OnGroupAdded(const RawAddress& address,
39                             const bluetooth::Uuid& group_uuid,
40                             int group_id) = 0;
41 
42   /* Followed group members are notified with this callback */
43   virtual void OnGroupMemberAdded(const RawAddress& address, int group_id) = 0;
44 
45   /* Group removal callback */
46   virtual void OnGroupRemoved(const bluetooth::Uuid& group_uuid,
47                               int group_id) = 0;
48 
49   /* Callback with group status update */
50   virtual void OnGroupMemberRemoved(const RawAddress& address,
51                                     int group_id) = 0;
52 
53   /* Callback with group information added from storage */
54   virtual void OnGroupAddFromStorage(const RawAddress& address,
55                                      const bluetooth::Uuid& group_uuid,
56                                      int group_id) = 0;
57 };
58 
59 class DeviceGroups {
60  public:
61   virtual ~DeviceGroups() = default;
62   static void Initialize(DeviceGroupsCallbacks* callbacks);
63   static void AddFromStorage(const RawAddress& addr,
64                              const std::vector<uint8_t>& in);
65   static bool GetForStorage(const RawAddress& addr, std::vector<uint8_t>& out);
66   static void CleanUp(DeviceGroupsCallbacks* callbacks);
67   static DeviceGroups* Get();
68   static void DebugDump(int fd);
69   /** To add to the existing group, group_id needs to be provided.
70    *  Otherwise a new group for the given context uuid will be created.
71    */
72   virtual int AddDevice(
73       const RawAddress& addr,
74       bluetooth::Uuid uuid = bluetooth::groups::kGenericContextUuid,
75       int group_id = bluetooth::groups::kGroupUnknown) = 0;
76   virtual int GetGroupId(
77       const RawAddress& addr,
78       bluetooth::Uuid uuid = bluetooth::groups::kGenericContextUuid) const = 0;
79   virtual void RemoveDevice(
80       const RawAddress& addr,
81       int group_id = bluetooth::groups::kGroupUnknown) = 0;
82 };
83 
84 }  // namespace groups
85 }  // namespace bluetooth
86