blob: 4c6c2014cd299de1a31d91eea800c158eb3c0e5f [file] [log] [blame]
// Copyright 2022 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_DEVICES_USB_LIB_USB_MONITOR_UTIL_INCLUDE_USB_MONITOR_UTIL_USB_MONITOR_UTIL_H_
#define SRC_DEVICES_USB_LIB_USB_MONITOR_UTIL_INCLUDE_USB_MONITOR_UTIL_USB_MONITOR_UTIL_H_
#include <fuchsia/hardware/usb/request/c/banjo.h>
#include <atomic>
#include <fbl/mutex.h>
#ifdef __cplusplus
// Stores fields the UsbMonitor stores
struct UsbMonitorStats {
unsigned int num_records;
};
// Records USB transactions and statistics on them.
class UsbMonitor {
public:
// Start recording USB transactions. These are currently stored as traces.
void Start();
// Stop recording USB transactions.
void Stop();
// True if USB transaction recording is started.
bool Started() const;
// Records a new usb request.
void AddRecord(usb_request_t* request);
// Returns statistics on the currently stored USB transactions.
UsbMonitorStats GetStats() const;
private:
bool started_ __TA_GUARDED(mutex_){false};
std::atomic_uint num_records_{0};
mutable fbl::Mutex mutex_;
};
#endif // __cplusplus
#endif // SRC_DEVICES_USB_LIB_USB_MONITOR_UTIL_INCLUDE_USB_MONITOR_UTIL_USB_MONITOR_UTIL_H_