Skip to content

Commit

Permalink
Expose/promote QNameString in Logging to allow other logging location…
Browse files Browse the repository at this point in the history
…s to get a formatted FullQName
  • Loading branch information
gmarcosb committed Jun 16, 2022
1 parent 51241c3 commit 15639cf
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 61 deletions.
21 changes: 8 additions & 13 deletions build_overrides/pigweed_environment.gni
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
# Copyright (c) 2022 Project CHIP Authors
#
# 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.
# This file is automatically generated by Pigweed's environment setup. Do not
# edit it manually or check it in.
declare_args() {
dir_cipd_arm = "/usr/local/google/home/mboyington/IdeaProjects/connectedhomeip/.environment/cipd/packages/arm"
dir_cipd_pigweed = "/usr/local/google/home/mboyington/IdeaProjects/connectedhomeip/.environment/cipd/packages/pigweed"
dir_cipd_python = "/usr/local/google/home/mboyington/IdeaProjects/connectedhomeip/.environment/cipd/packages/python"
dir_virtual_env = "/usr/local/google/home/mboyington/IdeaProjects/connectedhomeip/.environment/pigweed-venv"
}
80 changes: 33 additions & 47 deletions src/lib/dnssd/minimal_mdns/Logging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,45 @@
* limitations under the License.
*/
#include <lib/dnssd/minimal_mdns/Logging.h>
#include <lib/support/StringBuilder.h>
#include <lib/support/logging/CHIPLogging.h>

namespace mdns {
namespace Minimal {
namespace Logging {

QNameString::QNameString(const mdns::Minimal::FullQName & name)
{
for (unsigned i = 0; i < name.nameCount; i++)
{
if (i != 0)
{
mBuffer.Add(".");
}
mBuffer.Add(name.names[i]);
}
}

QNameString::QNameString(mdns::Minimal::SerializedQNameIterator name)
{
bool first = true;
while (name.Next())
{
if (first)
{
first = false;
}
else
{
mBuffer.Add(".");
}
mBuffer.Add(name.Value());
}
if (!name.IsValid())
{
mBuffer.Add("(!INVALID!)");
}
}

namespace {

#if CHIP_PROGRESS_LOGGING
Expand Down Expand Up @@ -53,52 +85,6 @@ const char * QueryTypeToString(mdns::Minimal::QType type)
}

#endif // CHIP_PROGRESS_LOGGING

class QNameString
{
public:
QNameString(const mdns::Minimal::FullQName & name)
{
for (unsigned i = 0; i < name.nameCount; i++)
{
if (i != 0)
{
mBuffer.Add(".");
}
mBuffer.Add(name.names[i]);
}
}

QNameString(mdns::Minimal::SerializedQNameIterator name)
{
bool first = true;
while (name.Next())
{
if (first)
{
first = false;
}
else
{
mBuffer.Add(".");
}
mBuffer.Add(name.Value());
}
if (!name.IsValid())
{
mBuffer.Add("(!INVALID!)");
}
}

const char * c_str() const { return mBuffer.c_str(); }

bool Fit() const { return mBuffer.Fit(); }

private:
static constexpr size_t kMaxQNameLength = 128;
chip::StringBuilder<kMaxQNameLength> mBuffer;
};

} // namespace

void LogSendingQuery(const mdns::Minimal::Query & query)
Expand Down
18 changes: 18 additions & 0 deletions src/lib/dnssd/minimal_mdns/Logging.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <lib/core/PeerId.h>
#include <lib/dnssd/minimal_mdns/Parser.h>
#include <lib/dnssd/minimal_mdns/Query.h>
#include <lib/support/StringBuilder.h>

namespace mdns {
namespace Minimal {
Expand All @@ -28,6 +29,23 @@ namespace Minimal {
/// MinMdns.
namespace Logging {

// Allows for a FullQName to be represented as a user-readable logging string
class QNameString
{
public:
QNameString(const mdns::Minimal::FullQName & name);

QNameString(mdns::Minimal::SerializedQNameIterator name);

inline const char * c_str() const { return mBuffer.c_str(); }

inline bool Fit() const { return mBuffer.Fit(); }

private:
static constexpr size_t kMaxQNameLength = 128;
chip::StringBuilder<kMaxQNameLength> mBuffer;
};

#if CHIP_MINMDNS_HIGH_VERBOSITY

void LogSendingQuery(const mdns::Minimal::Query & query);
Expand Down
3 changes: 2 additions & 1 deletion src/lib/dnssd/minimal_mdns/responders/QueryResponder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "QueryResponder.h"

#include <lib/dnssd/minimal_mdns/records/Ptr.h>
#include <lib/dnssd/minimal_mdns/Logging.h>

#include <lib/support/logging/CHIPLogging.h>

Expand Down Expand Up @@ -56,7 +57,7 @@ QueryResponderSettings QueryResponderBase::AddResponder(RecordResponder * respon
{
return QueryResponderSettings();
}
ChipLogDetail(Discovery, "Responding with %s", responder->GetQName());
ChipLogDetail(Discovery, "Responding with %s", Logging::QNameString(responder->GetQName()).c_str());

for (size_t i = 0; i < mResponderInfoSize; i++)
{
Expand Down

0 comments on commit 15639cf

Please sign in to comment.