This file is indexed.

/usr/include/ola/rdm/DiscoveryAgent.h is in libola-dev 0.9.1-1.1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
/*
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 *
 * DiscoveryAgent.h
 * Implements the RDM Discovery algorithm.
 * Copyright (C) 2011 Simon Newton
 */

/**
 * @addtogroup rdm_controller
 * @{
 * @file include/ola/rdm/DiscoveryAgent.h
 * @brief Implements the RDM Discovery algorithm
 * @}
 */

#ifndef INCLUDE_OLA_RDM_DISCOVERYAGENT_H_
#define INCLUDE_OLA_RDM_DISCOVERYAGENT_H_

#include <ola/Callback.h>
#include <ola/rdm/UID.h>
#include <ola/rdm/UIDSet.h>
#include <queue>
#include <stack>
#include <utility>


namespace ola {
namespace rdm {

/**
 * This is the interface for classes which want to act as a discovery
 * controller. Such clases must implement the Mute, UnMute & Discovery Unique
 * Branch (DUB) methods.
 */
class DiscoveryTargetInterface {
 public:
    // Argument is true if the device responded
    typedef ola::BaseCallback1<void, bool> MuteDeviceCallback;
    typedef ola::BaseCallback0<void> UnMuteDeviceCallback;
    // Arguments are a pointer to the data & length of the DUB response,
    // excluding the RDM start code.
    typedef ola::BaseCallback2<void, const uint8_t*, unsigned int>
      BranchCallback;

    virtual ~DiscoveryTargetInterface() {}

    // Mute a device
    virtual void MuteDevice(const UID &target,
                            MuteDeviceCallback *mute_complete) = 0;
    // Un Mute all devices
    virtual void UnMuteAll(UnMuteDeviceCallback *unmute_complete) = 0;

    // Send a branch request
    virtual void Branch(const UID &lower,
                        const UID &upper,
                        BranchCallback *callback) = 0;
};


/**
 * This class controls the discovery algorithm.
 */
class DiscoveryAgent {
 public:
    explicit DiscoveryAgent(DiscoveryTargetInterface *target);
    ~DiscoveryAgent();

    typedef ola::SingleUseCallback2<void, bool, const UIDSet&>
      DiscoveryCompleteCallback;

    void Abort();
    void StartFullDiscovery(DiscoveryCompleteCallback *on_complete);
    void StartIncrementalDiscovery(DiscoveryCompleteCallback *on_complete);

 private:
    /**
     * Represents a range of UIDs (a branch of the UID tree)
     */
    struct UIDRange {
      UIDRange(const UID &lower, const UID &upper, UIDRange *parent)
          : lower(lower),
            upper(upper),
            parent(parent),
            attempt(0),
            failures(0),
            uids_discovered(0),
            branch_corrupt(false) {
      }
      UID lower;
      UID upper;
      UIDRange *parent;  // the parent Range
      unsigned int attempt;  // the # of attempts for this branch
      unsigned int failures;
      unsigned int uids_discovered;
      bool branch_corrupt;  // true if this branch contains a bad device
    };

    typedef std::stack<UIDRange*> UIDRanges;

    DiscoveryTargetInterface *m_target;
    UIDSet m_uids;
    // uids that are misbehaved in some way
    UIDSet m_bad_uids;
    DiscoveryCompleteCallback *m_on_complete;
    // uids to mute during incremental discovery
    std::queue<UID> m_uids_to_mute;
    // Callbacks used by the DiscoveryTarget
    DiscoveryTargetInterface::UnMuteDeviceCallback *m_unmute_callback;
    DiscoveryTargetInterface::MuteDeviceCallback *m_incremental_mute_callback;
    DiscoveryTargetInterface::MuteDeviceCallback *m_branch_mute_callback;
    DiscoveryTargetInterface::BranchCallback *m_branch_callback;
    // The stack of UIDRanges
    UIDRanges m_uid_ranges;
    UID m_muting_uid;  // the uid we're currently trying to mute
    unsigned int m_mute_attempts;
    bool m_tree_corrupt;  // true if there was a problem with discovery

    void InitDiscovery(DiscoveryCompleteCallback *on_complete,
                       bool incremental);

    void UnMuteComplete();
    void MaybeMuteNextDevice();
    void IncrementalMuteComplete(bool status);
    void SendDiscovery();

    void BranchComplete(const uint8_t *data, unsigned int length);
    void BranchMuteComplete(bool status);
    void HandleCollision();
    void FreeCurrentRange();

    static const unsigned int MAX_DUB_RESPONSE_SIZE = 24;
    static const unsigned int MIN_DUB_RESPONSE_SIZE = 17;
    /*
     * The maximum numbers of times we'll retry discovery if we get a
     * collision, but after splitting the range in two no nodes can be found.
     */
    static const unsigned int MAX_EMPTY_BRANCH_ATTEMPTS = 5;
    /*
     * The maximum number of times we'll perform discovery on a branch when we
     * get an inconsistent result (responder not muting, etc.)
     */
    static const unsigned int MAX_BRANCH_FAILURES = 5;
    // The number of times we'll attempt to mute a UID
    static const unsigned int MAX_MUTE_ATTEMPTS = 5;
};
}  // namespace rdm
}  // namespace ola
#endif  // INCLUDE_OLA_RDM_DISCOVERYAGENT_H_