@@ -176,6 +176,35 @@ class WasmBase : public std::enable_shared_from_this<WasmBase> {
176
176
uint32_t nextGaugeMetricId () { return next_gauge_metric_id_ += kMetricIdIncrement ; }
177
177
uint32_t nextHistogramMetricId () { return next_histogram_metric_id_ += kMetricIdIncrement ; }
178
178
179
+ enum class CalloutType : uint32_t {
180
+ HttpCall = 0 ,
181
+ GrpcCall = 1 ,
182
+ GrpcStream = 2 ,
183
+ };
184
+ static const uint32_t kCalloutTypeMask = 0x3 ; // Enough to cover the 3 types.
185
+ static const uint32_t kCalloutIncrement = 0x4 ; // Enough to cover the 3 types.
186
+ bool isHttpCallId (uint32_t callout_id) {
187
+ return (callout_id & kCalloutTypeMask ) == static_cast <uint32_t >(CalloutType::HttpCall);
188
+ }
189
+ bool isGrpcCallId (uint32_t callout_id) {
190
+ return (callout_id & kCalloutTypeMask ) == static_cast <uint32_t >(CalloutType::GrpcCall);
191
+ }
192
+ bool isGrpcStreamId (uint32_t callout_id) {
193
+ return (callout_id & kCalloutTypeMask ) == static_cast <uint32_t >(CalloutType::GrpcStream);
194
+ }
195
+ uint32_t nextHttpCallId () {
196
+ // TODO(PiotrSikora): re-add rollover protection (requires at least 1 billion callouts).
197
+ return next_http_call_id_ += kCalloutIncrement ;
198
+ }
199
+ uint32_t nextGrpcCallId () {
200
+ // TODO(PiotrSikora): re-add rollover protection (requires at least 1 billion callouts).
201
+ return next_grpc_call_id_ += kCalloutIncrement ;
202
+ }
203
+ uint32_t nextGrpcStreamId () {
204
+ // TODO(PiotrSikora): re-add rollover protection (requires at least 1 billion callouts).
205
+ return next_grpc_stream_id_ += kCalloutIncrement ;
206
+ }
207
+
179
208
protected:
180
209
friend class ContextBase ;
181
210
class ShutdownHandle ;
@@ -279,6 +308,11 @@ class WasmBase : public std::enable_shared_from_this<WasmBase> {
279
308
uint32_t next_gauge_metric_id_ = static_cast <uint32_t >(MetricType::Gauge);
280
309
uint32_t next_histogram_metric_id_ = static_cast <uint32_t >(MetricType::Histogram);
281
310
311
+ // HTTP/gRPC callouts.
312
+ uint32_t next_http_call_id_ = static_cast <uint32_t >(CalloutType::HttpCall);
313
+ uint32_t next_grpc_call_id_ = static_cast <uint32_t >(CalloutType::GrpcCall);
314
+ uint32_t next_grpc_stream_id_ = static_cast <uint32_t >(CalloutType::GrpcStream);
315
+
282
316
// Actions to be done after the call into the VM returns.
283
317
std::deque<std::function<void ()>> after_vm_call_actions_;
284
318
0 commit comments