quic/qbox
Loading...
Searching...
No Matches
monitor.h
1/*
2 * Copyright (c) 2023-2024 Qualcomm Innovation Center, Inc. All Rights Reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#ifndef _GREENSOCS_MONITOR_H
8#define _GREENSOCS_MONITOR_H
9
18#include <cci_configuration>
19#include <systemc>
20#include <tlm>
21#include <scp/report.h>
22#include <scp/helpers.h>
23#include <tlm_utils/simple_initiator_socket.h>
24#include <tlm_utils/simple_target_socket.h>
25#include <ports/initiator-signal-socket.h>
26#include <ports/target-signal-socket.h>
27#include <tlm_sockets_buswidth.h>
28#include <libgssync.h>
29#include "crow.h"
30#include <thread>
31#include <future>
32#include <qkmultithread.h>
33#include <chrono>
34#include <atomic>
35#include <ports/biflow-socket.h>
36
37#define MAX_ASIO_BUF_LEN (1024ULL * 16ULL)
38#define MAX_BUFFER 1000
39
40namespace gs {
41
42template <unsigned int BUSWIDTH = DEFAULT_TLM_BUSWIDTH>
43class monitor : public sc_core::sc_module
44{
45 SCP_LOGGER();
46
47 class biflow_ws
48 {
49 public:
50 std::vector<crow::websocket::connection*> m_conns;
52 std::string buffer;
53 const char* name;
54
55 public:
56 void bind(biflow_bindable& other)
57 {
58 socket.bind(other);
59 socket.can_receive_any();
60 }
61 void b_transport(tlm::tlm_generic_payload& txn, sc_core::sc_time& t)
62 {
63 /* NB we are ignoring the templated type here, as we're simply sending strings, if the type is not a
64 * character, this will produce some sort of rubbish! */
65 char* ptr = (char*)txn.get_data_ptr();
66 std::string data(ptr, txn.get_data_length());
67 buffer = (buffer + data);
68 if (buffer.size() > MAX_BUFFER) buffer = buffer.substr(buffer.size() - MAX_BUFFER);
69 for (auto conn : m_conns) {
70 conn->send_text(data);
71 }
72 }
73 void enqueue(std::string data)
74 {
75 for (auto c : data) {
76 socket.enqueue(c);
77 }
78 }
79 biflow_ws(gs::biflow_multibindable& o, const char* n)
80 : socket(sc_core::sc_gen_unique_name("monitor_biflow_backend")), name(n)
81 {
82 socket.register_b_transport(this, &biflow_ws::b_transport);
83 bind(o);
84 }
85 void set_conn(crow::websocket::connection* c)
86 {
87 m_conns.push_back(c);
88 c->send_text(buffer);
89 }
90 void clear_conn(crow::websocket::connection* c)
91 {
92 auto i = std::find(m_conns.begin(), m_conns.end(), c);
93 if (i != m_conns.end()) {
94 m_conns.erase(i);
95 }
96 }
97 };
98 std::map<std::string, std::unique_ptr<biflow_ws>> biflows;
99
100public:
101 monitor(const sc_core::sc_module_name& nm);
102
103 ~monitor();
104
105private:
106 void init_monitor();
107
108 void before_end_of_elaboration() override;
109
110 void end_of_elaboration() override;
111
112 void end_of_simulation() override;
113
114public:
115 cci::cci_param<uint32_t> p_server_port;
116 cci::cci_param<std::string> p_html_doc_template_dir_path;
117 cci::cci_param<std::string> p_html_doc_name;
118 cci::cci_param<bool> p_use_html_presentation;
119
120private:
121 crow::SimpleApp m_app;
122 std::future<void> m_app_future;
123 gs::runonsysc m_sc;
124 std::vector<tlm_quantumkeeper_multithread*> m_qks;
125};
126} // namespace gs
127
128extern "C" void module_register();
129
130#endif
Definition target.h:160
Definition monitor.h:44
Definition runonsysc.h:23
Tool which reads a Lua configuration file and sets parameters.
Definition biflow.cc:10
Definition biflow-socket.h:55
Definition biflow-socket.h:68