CIRCT 22.0.0git
Loading...
Searching...
No Matches
RpcClient.h
Go to the documentation of this file.
1//===- RpcClient.h - ESI Cosim RPC client -----------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file contains the gRPC client implementation for ESI cosimulation.
10// It wraps all gRPC/protobuf dependencies so they don't leak into other
11// headers.
12//
13// DO NOT EDIT!
14// This file is distributed as part of an ESI package. The source for this file
15// should always be modified within CIRCT (lib/dialect/ESI/runtime/cpp).
16//
17//===----------------------------------------------------------------------===//
18
19// NOLINTNEXTLINE(llvm-header-guard)
20#ifndef ESI_BACKENDS_RPCCLIENT_H
21#define ESI_BACKENDS_RPCCLIENT_H
22
23#include "esi/Common.h"
24
25#include <functional>
26#include <memory>
27#include <string>
28#include <vector>
29
30namespace esi {
31namespace backends {
32namespace cosim {
33
34/// A gRPC client for communicating with the cosimulation server.
35/// This class wraps all gRPC/protobuf dependencies.
36class RpcClient {
37public:
38 RpcClient(const std::string &hostname, uint16_t port);
40
41 // Non-copyable.
42 RpcClient(const RpcClient &) = delete;
43 RpcClient &operator=(const RpcClient &) = delete;
44
45 /// Get the ESI version from the manifest.
46 uint32_t getEsiVersion() const;
47
48 /// Get the compressed manifest from the server.
49 std::vector<uint8_t> getCompressedManifest() const;
50
51 /// Channel direction as reported by the server.
53
54 /// Description of a channel from the server.
55 struct ChannelDesc {
56 std::string name;
57 std::string type;
59 };
60
61 /// Get the channel description for a channel name.
62 /// Returns true if the channel was found.
63 bool getChannelDesc(const std::string &channelName, ChannelDesc &desc) const;
64
65 /// List all channels available on the server.
66 std::vector<ChannelDesc> listChannels() const;
67
68 /// Send a message to a server-bound channel.
69 void writeToServer(const std::string &channelName, const MessageData &data);
70
71 /// Callback type for receiving messages from a client-bound channel.
72 /// Return true if the message was consumed, false to retry.
73 using ReadCallback = std::function<bool(const MessageData &)>;
74
75 /// Abstract handle for a read channel connection.
76 /// Destructor disconnects from the channel.
78 public:
79 virtual ~ReadChannelConnection() = default;
80 virtual void disconnect() = 0;
81 };
82
83 /// Connect to a client-bound channel and receive messages via callback.
84 /// Returns a handle that disconnects when destroyed.
85 std::unique_ptr<ReadChannelConnection>
86 connectClientReceiver(const std::string &channelName, ReadCallback callback);
87
88private:
89 class Impl;
90 std::unique_ptr<Impl> impl;
91};
92
93} // namespace cosim
94} // namespace backends
95} // namespace esi
96
97#endif // ESI_BACKENDS_RPCCLIENT_H
A logical chunk of data representing serialized data.
Definition Common.h:113
Abstract handle for a read channel connection.
Definition RpcClient.h:77
A gRPC client for communicating with the cosimulation server.
Definition RpcClient.h:36
ChannelDirection
Channel direction as reported by the server.
Definition RpcClient.h:52
std::unique_ptr< ReadChannelConnection > connectClientReceiver(const std::string &channelName, ReadCallback callback)
Connect to a client-bound channel and receive messages via callback.
std::vector< uint8_t > getCompressedManifest() const
Get the compressed manifest from the server.
uint32_t getEsiVersion() const
Get the ESI version from the manifest.
void writeToServer(const std::string &channelName, const MessageData &data)
Send a message to a server-bound channel.
bool getChannelDesc(const std::string &channelName, ChannelDesc &desc) const
Get the channel description for a channel name.
RpcClient & operator=(const RpcClient &)=delete
std::function< bool(const MessageData &)> ReadCallback
Callback type for receiving messages from a client-bound channel.
Definition RpcClient.h:73
std::vector< ChannelDesc > listChannels() const
List all channels available on the server.
std::unique_ptr< Impl > impl
Definition RpcClient.h:90
RpcClient(const RpcClient &)=delete
Definition esi.py:1
Description of a channel from the server.
Definition RpcClient.h:55