Skip to content

Commit

Permalink
trace discovered services
Browse files Browse the repository at this point in the history
  • Loading branch information
oguzcanoguz committed Nov 14, 2024
1 parent 138fc45 commit 161fcb6
Showing 1 changed file with 29 additions and 28 deletions.
57 changes: 29 additions & 28 deletions services/echo_console/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,65 +106,66 @@ class ConsoleClientConnection

~ConsoleClientConnection();

// Implementation of ConnectionObserver
// void SendStreamAvailable(infra::SharedPtr<infra::StreamWriter>&& writer) override;
// void DataReceived() override;
// ConnectionObserver
void Attached() override;

// Implementation of ConsoleObserver
void Send(const std::string& message) override;

private:
class PeerServiceDiscoveryObserverTracer
: public application::PeerServiceDiscoveryObserver
{
public:
PeerServiceDiscoveryObserverTracer(application::PeerServiceDiscovererEcho& subject, services::Tracer& tracer)
: PeerServiceDiscoveryObserver(subject)
, tracer(tracer)
{}

// Implementation of PeerServiceDiscoveryObserver
void ServicesDiscovered(infra::MemoryRange<uint32_t> services) override
{
tracer.Trace() << "Services discovered: ";
for (auto service : services)
tracer.Continue() << service << " ";
}

private:
services::Tracer& tracer;
};

private:
void CheckDataToBeSent();

private:
services::Tracer& tracer;
std::string dataToBeSent;
infra::SharedPtr<infra::StreamWriter> writer;
service_discovery::ServiceDiscoveryTracer serviceDiscoveryTracer;
service_discovery::ServiceDiscoveryResponseTracer serviceDiscoveryResponseTracer;
infra::Optional<application::PeerServiceDiscovererEcho> peerServiceDiscoverer;
infra::Optional<PeerServiceDiscoveryObserverTracer> peerServiceDiscoveryObserverTracer;
};

ConsoleClientConnection::ConsoleClientConnection(application::Console& console, services::Tracer& tracer)
: application::ConsoleObserver(console)
, services::TracingEchoOnConnection(tracer, *static_cast<services::MethodSerializerFactory*>(this))
, serviceDiscoveryTracer(*this)
, serviceDiscoveryResponseTracer(*this)
, tracer(tracer)
{
services::GlobalTracer().Trace() << "ConsoleClientConnection";
tracer.Trace() << "ConsoleClientConnection";
}

ConsoleClientConnection::~ConsoleClientConnection()
{
services::GlobalTracer().Trace() << "~ConsoleClientConnection";
tracer.Trace() << "~ConsoleClientConnection";
}

// void ConsoleClientConnection::SendStreamAvailable(infra::SharedPtr<infra::StreamWriter>&& writer)
// {
// this->writer = writer;
// writer = nullptr;

// CheckDataToBeSent();
// }

// void ConsoleClientConnection::DataReceived()
// {
// try
// {
// while (true)
// {
// auto stream = services::ConnectionObserver::Subject().ReceiveStream();
// ConsoleObserver::Subject().DataReceived(*stream);
// services::ConnectionObserver::Subject().AckReceived();
// }
// }
// catch (application::Console::IncompletePacket&)
// {}
// }

void ConsoleClientConnection::Attached()
{
peerServiceDiscoverer.Emplace(*this);
peerServiceDiscoveryObserverTracer.Emplace(*peerServiceDiscoverer, tracer);
}

void ConsoleClientConnection::Send(const std::string& message)
Expand Down

0 comments on commit 161fcb6

Please sign in to comment.