Open Lighting Architecture  Latest Git
UIDAllocator.h
Go to the documentation of this file.
1 /*
2  * This library is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU Lesser General Public
4  * License as published by the Free Software Foundation; either
5  * version 2.1 of the License, or (at your option) any later version.
6  *
7  * This library is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10  * Lesser General Public License for more details.
11  *
12  * You should have received a copy of the GNU Lesser General Public
13  * License along with this library; if not, write to the Free Software
14  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
15  *
16  * UIDAllocator.h
17  * A class to allocate UIDs
18  * Copyright (C) 2013 Simon Newton
19  */
20 
28 #ifndef INCLUDE_OLA_RDM_UIDALLOCATOR_H_
29 #define INCLUDE_OLA_RDM_UIDALLOCATOR_H_
30 
31 #include <ola/rdm/UID.h>
32 
33 namespace ola {
34 namespace rdm {
35 
46 class UIDAllocator {
47  public:
52  explicit UIDAllocator(const UID &uid)
53  : m_esta_id(uid.ManufacturerId()),
54  m_device_id(uid.DeviceId()),
55  m_last_device_id(UID::ALL_DEVICES) {
56  }
57 
64  UIDAllocator(const UID &uid, uint32_t last_device_id)
65  : m_esta_id(uid.ManufacturerId()),
66  m_device_id(uid.DeviceId()),
67  m_last_device_id(last_device_id) {
68  }
69 
76  if (m_device_id == UID::ALL_DEVICES || m_device_id > m_last_device_id)
77  return NULL;
78 
79  return new UID(m_esta_id, m_device_id++);
80  }
81 
82  private:
83  uint16_t m_esta_id;
84  uint32_t m_device_id;
85  uint32_t m_last_device_id;
86 };
87 } // namespace rdm
88 } // namespace ola
89 #endif // INCLUDE_OLA_RDM_UIDALLOCATOR_H_
A RDM unique identifier (UID).
static const uint32_t ALL_DEVICES
The value for the &#39;all devices&#39; id.
Definition: UID.h:304
UID * AllocateNext()
Allocate the next UID from the pool.
Definition: UIDAllocator.h:75
Allocate UIDs from a pool.
Definition: UIDAllocator.h:46
Represents a RDM UID.
Definition: UID.h:57
UIDAllocator(const UID &uid, uint32_t last_device_id)
Create a new allocator with the starting UID that ends at the specified last_device_id.
Definition: UIDAllocator.h:64
The namespace containing all OLA symbols.
Definition: Credentials.cpp:44
UIDAllocator(const UID &uid)
Create a new allocator with the starting UID.
Definition: UIDAllocator.h:52