| 111 | } |
| 112 | |
| 113 | const CounterSet* CounterDirectory::RegisterCounterSet(const std::string& counterSetName, |
| 114 | uint16_t count, |
| 115 | const arm::pipe::Optional<std::string>& parentCategoryName) |
| 116 | { |
| 117 | // Check that the given counter set name is valid |
| 118 | if (counterSetName.empty() || |
| 119 | !arm::pipe::IsValidSwTraceString<arm::pipe::SwTraceNameCharPolicy>(counterSetName)) |
| 120 | { |
| 121 | throw arm::pipe::InvalidArgumentException("Trying to register a counter set with an invalid name"); |
| 122 | } |
| 123 | |
| 124 | // Check that a counter set with the given name is not already registered |
| 125 | if (IsCounterSetRegistered(counterSetName)) |
| 126 | { |
| 127 | throw arm::pipe::InvalidArgumentException( |
| 128 | fmt::format("Trying to register a counter set already registered (\"{}\")", counterSetName)); |
| 129 | } |
| 130 | |
| 131 | // Peek the next UID, do not get an actual valid UID just now as we don't want to waste a good UID in case |
| 132 | // the registration fails. We'll get a proper one once we're sure that the counter set can be registered |
| 133 | uint16_t counterSetUidPeek = GetNextUid(true); |
| 134 | |
| 135 | // Check that a category with the given (optional) parent category name is already registered |
| 136 | if (parentCategoryName.has_value()) |
| 137 | { |
| 138 | // Get the (optional) parent category name |
| 139 | const std::string& parentCategoryNameValue = parentCategoryName.value(); |
| 140 | if (parentCategoryNameValue.empty()) |
| 141 | { |
| 142 | throw arm::pipe::InvalidArgumentException( |
| 143 | fmt::format("Trying to connect a counter set (UID: {}) to an invalid " |
| 144 | "parent category (name: \"{}\")", |
| 145 | counterSetUidPeek, |
| 146 | parentCategoryNameValue)); |
| 147 | } |
| 148 | |
| 149 | // Check that the given parent category is already registered |
| 150 | auto it = FindCategory(parentCategoryNameValue); |
| 151 | if (it == m_Categories.end()) |
| 152 | { |
| 153 | throw arm::pipe::InvalidArgumentException( |
| 154 | fmt::format("Trying to connect a counter set (UID: {}) to a parent category " |
| 155 | "that is not registered (name: \"{}\")", |
| 156 | counterSetUidPeek, |
| 157 | parentCategoryNameValue)); |
| 158 | } |
| 159 | } |
| 160 | |
| 161 | // Get the counter set UID |
| 162 | uint16_t counterSetUid = GetNextUid(); |
| 163 | ARM_PIPE_ASSERT(counterSetUid == counterSetUidPeek); |
| 164 | |
| 165 | // Create the counter set |
| 166 | CounterSetPtr counterSet = std::make_unique<CounterSet>(counterSetUid, counterSetName, count); |
| 167 | ARM_PIPE_ASSERT(counterSet); |
| 168 | |
| 169 | // Get the raw counter set pointer |
| 170 | const CounterSet* counterSetPtr = counterSet.get(); |
no test coverage detected