blob: 424fff760b7c527a85da65c593d03012881ac03f [file] [log] [blame]
// Copyright 2018 The Fuchsia Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef SRC_DEVELOPER_DEBUG_DEBUG_AGENT_LOCAL_STREAM_BACKEND_H_
#define SRC_DEVELOPER_DEBUG_DEBUG_AGENT_LOCAL_STREAM_BACKEND_H_
#include "src/developer/debug/debug_agent/debug_agent.h"
#include "src/developer/debug/ipc/protocol.h"
#include "src/developer/debug/shared/message_loop.h"
#include "src/developer/debug/shared/stream_buffer.h"
namespace debug_ipc {
class MessageReader;
} // namespace debug_ipc
namespace debug_agent {
// This class is meant to receive the raw messages outputted by the debug agent.
// The agent's stream calls this backend to output the data and verifies that
// all the content is sent.
//
// We use this class to intercept the messages sent back from the agent and
// react accordingly. This class is somwhat geared towards tests, mainly in the sense that
// notification handlers are needed as they're needed.
class LocalStreamBackend : public debug::BufferedStream {
public:
LocalStreamBackend();
virtual ~LocalStreamBackend();
// Message dispatcher interface.
// This should be overriden by every test interested in a particular set of
// messages. By default they do nothing.
virtual void HandleAttach(debug_ipc::AttachReply) {}
virtual void HandleNotifyComponentDiscovered(debug_ipc::NotifyComponentDiscovered) {}
virtual void HandleNotifyComponentStarting(debug_ipc::NotifyComponentStarting) {}
virtual void HandleNotifyException(debug_ipc::NotifyException) {}
virtual void HandleNotifyIO(debug_ipc::NotifyIO) {}
virtual void HandleNotifyModules(debug_ipc::NotifyModules) {}
virtual void HandleNotifyProcessExiting(debug_ipc::NotifyProcessExiting) {}
virtual void HandleNotifyProcessStarting(debug_ipc::NotifyProcessStarting) {}
virtual void HandleNotifyThreadExiting(debug_ipc::NotifyThreadExiting) {}
virtual void HandleNotifyThreadStarting(debug_ipc::NotifyThreadStarting) {}
virtual void HandleNotifyLog(debug_ipc::NotifyLog) {}
// BufferedStream implementation.
bool Start() override { return true; }
bool Stop() override { return true; }
bool IsValid() override { return true; }
// The stream will call this function to send the data to whatever backend it
// is connected to. It returns how much of the input message it could actually
// write. For this tests purposes, we always read the whole message.
size_t ConsumeStreamBufferData(const char* data, size_t len) override;
private:
void ResetInternal() override {}
};
} // namespace debug_agent
#endif // SRC_DEVELOPER_DEBUG_DEBUG_AGENT_LOCAL_STREAM_BACKEND_H_