Open Lighting Architecture: include/ola/rdm/UIDAllocator.h Source File

| Open Lighting Architecture 0.10.9

Loading...
Searching...
No Matches
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
33namespace ola {
34namespace 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
75 UID *AllocateNext() {
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_
UID.h
A RDM unique identifier (UID).
ola::rdm::UIDAllocator::UIDAllocator
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
ola::rdm::UIDAllocator::AllocateNext
UID * AllocateNext()
Allocate the next UID from the pool.
Definition UIDAllocator.h:75
ola::rdm::UIDAllocator::UIDAllocator
UIDAllocator(const UID &uid)
Create a new allocator with the starting UID.
Definition UIDAllocator.h:52
ola::rdm::UID
Represents a RDM UID.
Definition UID.h:57
ola::rdm::UID::ALL_DEVICES
static const uint32_t ALL_DEVICES
The value for the 'all devices' id.
Definition UID.h:271
ola::rdm
PLASA E1.20 Remote Device Management.
Definition AckTimerResponder.cpp:38
ola
The namespace containing all OLA symbols.
Definition Credentials.cpp:44