summaryrefslogtreecommitdiff
path: root/system/bta/include/bta_groups.h
blob: 3ff618728261cc25704c4da547b4c6ad0cc281f8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/*
 * Copyright 2021 HIMSA II K/S - www.himsa.com.
 * Represented by EHIMA - www.ehima.com
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#pragma once
#include <list>

#include "types/bluetooth/uuid.h"
#include "types/raw_address.h"

namespace bluetooth {
namespace groups {

static constexpr int kGroupUnknown = -1;
static const bluetooth::Uuid kGenericContextUuid =
    bluetooth::Uuid::From16Bit(0x0000);

class DeviceGroupsCallbacks {
 public:
  virtual ~DeviceGroupsCallbacks() = default;

  /* Notifies first group appearance.
   * This callback also contains first group member and uuid of the group.
   */
  virtual void OnGroupAdded(const RawAddress& address,
                            const bluetooth::Uuid& group_uuid,
                            int group_id) = 0;

  /* Followed group members are notified with this callback */
  virtual void OnGroupMemberAdded(const RawAddress& address, int group_id) = 0;

  /* Group removal callback */
  virtual void OnGroupRemoved(const bluetooth::Uuid& group_uuid,
                              int group_id) = 0;

  /* Callback with group status update */
  virtual void OnGroupMemberRemoved(const RawAddress& address,
                                    int group_id) = 0;

  /* Callback with group information added from storage */
  virtual void OnGroupAddFromStorage(const RawAddress& address,
                                     const bluetooth::Uuid& group_uuid,
                                     int group_id) = 0;
};

class DeviceGroups {
 public:
  virtual ~DeviceGroups() = default;
  static void Initialize(DeviceGroupsCallbacks* callbacks);
  static void AddFromStorage(const RawAddress& addr,
                             const std::vector<uint8_t>& in);
  static bool GetForStorage(const RawAddress& addr, std::vector<uint8_t>& out);
  static void CleanUp(DeviceGroupsCallbacks* callbacks);
  static DeviceGroups* Get();
  static void DebugDump(int fd);
  /** To add to the existing group, group_id needs to be provided.
   *  Otherwise a new group for the given context uuid will be created.
   */
  virtual int AddDevice(
      const RawAddress& addr,
      bluetooth::Uuid uuid = bluetooth::groups::kGenericContextUuid,
      int group_id = bluetooth::groups::kGroupUnknown) = 0;
  virtual int GetGroupId(
      const RawAddress& addr,
      bluetooth::Uuid uuid = bluetooth::groups::kGenericContextUuid) const = 0;
  virtual void RemoveDevice(
      const RawAddress& addr,
      int group_id = bluetooth::groups::kGroupUnknown) = 0;
};

}  // namespace groups
}  // namespace bluetooth