@@ -223,6 +223,9 @@ namespace Aws
223
223
Crt::String StatusToString ();
224
224
};
225
225
226
+ /* *
227
+ * Handler interface for connection lifecycle events.
228
+ */
226
229
class AWS_EVENTSTREAMRPC_API ConnectionLifecycleHandler
227
230
{
228
231
public:
@@ -255,7 +258,9 @@ namespace Aws
255
258
const Crt::Optional<Crt::ByteBuf> &payload);
256
259
};
257
260
258
- /* User data passed to callbacks for a new stream. */
261
+ /* *
262
+ * User data passed to callbacks for a new stream.
263
+ */
259
264
class AWS_EVENTSTREAMRPC_API ContinuationCallbackData
260
265
{
261
266
public:
@@ -273,6 +278,9 @@ namespace Aws
273
278
Crt::Allocator *allocator;
274
279
};
275
280
281
+ /* *
282
+ * Handler interface for continuation events.
283
+ */
276
284
class AWS_EVENTSTREAMRPC_API ClientContinuationHandler
277
285
{
278
286
public:
@@ -299,23 +307,63 @@ namespace Aws
299
307
ContinuationCallbackData *m_callbackData;
300
308
};
301
309
310
+ /* *
311
+ * A wrapper for event-stream-rpc client continuation.
312
+ */
302
313
class AWS_EVENTSTREAMRPC_API ClientContinuation final
303
314
{
304
315
public:
316
+ /* *
317
+ * Create a new continuation.
318
+ *
319
+ * @note continuation_option's callbacks will not be invoked, and nothing will be sent across
320
+ * the wire until Activate() is invoked.
321
+ * @param connection Connection on which open a new stream.
322
+ * @param continuationHandler A set of callbacks that will be invoked for continuation events.
323
+ * @param allocator Allocator to use.
324
+ */
305
325
ClientContinuation (
306
326
ClientConnection *connection,
307
327
ClientContinuationHandler &continuationHandler,
308
328
Crt::Allocator *allocator) noexcept ;
309
329
~ClientContinuation () noexcept ;
330
+
331
+ /* *
332
+ * Initiate a new client stream. Send new message for the new stream.
333
+ * @param operation Name for the operation to be invoked by the peer endpoint.
334
+ * @param headers Headers for the eventstream message.
335
+ * @param payload Payload for the eventstream message.
336
+ * @param messageType Message type for the message.
337
+ * @param messageFlags Bitmask of aws_event_stream_rpc_message_flag values.
338
+ * @param onMessageFlushCallback Callback to be invoked upon the message being flushed to the underlying
339
+ * transport.
340
+ * @return Future that will be resolved when the message has either been written to the wire or it fails.
341
+ */
310
342
std::future<RpcError> Activate (
311
343
const Crt::String &operation,
312
344
const Crt::List<EventStreamHeader> &headers,
313
345
const Crt::Optional<Crt::ByteBuf> &payload,
314
346
MessageType messageType,
315
347
uint32_t messageFlags,
316
348
OnMessageFlushCallback onMessageFlushCallback) noexcept ;
349
+
350
+ /* *
351
+ * Check if the continuation has been closed.
352
+ * @return True if the continuation has been closed, false otherwise.
353
+ */
317
354
bool IsClosed () noexcept ;
318
355
void Release () noexcept ;
356
+
357
+ /* *
358
+ * Send message on the continuation.
359
+ * @param headers List of additional event stream headers to include on the message.
360
+ * @param payload Message payload.
361
+ * @param messageType Message type for the message.
362
+ * @param messageFlags Bitmask of aws_event_stream_rpc_message_flag values.
363
+ * @param onMessageFlushCallback Callback to be invoked upon the message being flushed to the underlying
364
+ * transport.
365
+ * @return Future that will be resolved when the message has either been written to the wire or it fails.
366
+ */
319
367
std::future<RpcError> SendMessage (
320
368
const Crt::List<EventStreamHeader> &headers,
321
369
const Crt::Optional<Crt::ByteBuf> &payload,
@@ -329,6 +377,7 @@ namespace Aws
329
377
ClientContinuationHandler &m_continuationHandler;
330
378
struct aws_event_stream_rpc_client_continuation_token *m_continuationToken;
331
379
ContinuationCallbackData *m_callbackData;
380
+
332
381
static void s_onContinuationMessage (
333
382
struct aws_event_stream_rpc_client_continuation_token *continuationToken,
334
383
const struct aws_event_stream_rpc_message_args *messageArgs,
@@ -338,6 +387,9 @@ namespace Aws
338
387
void *userData) noexcept ;
339
388
};
340
389
390
+ /* *
391
+ * Base class for types used by operations.
392
+ */
341
393
class AWS_EVENTSTREAMRPC_API AbstractShapeBase
342
394
{
343
395
public:
@@ -351,6 +403,9 @@ namespace Aws
351
403
Crt::Allocator *m_allocator;
352
404
};
353
405
406
+ /* *
407
+ * Base class for errors used by operations.
408
+ */
354
409
class AWS_EVENTSTREAMRPC_API OperationError : public AbstractShapeBase
355
410
{
356
411
public:
@@ -394,6 +449,9 @@ namespace Aws
394
449
RPC_ERROR
395
450
};
396
451
452
+ /* *
453
+ * A wrapper for operation result.
454
+ */
397
455
class AWS_EVENTSTREAMRPC_API TaggedResult
398
456
{
399
457
public:
@@ -410,9 +468,28 @@ namespace Aws
410
468
*/
411
469
operator bool () const noexcept ;
412
470
471
+ /* *
472
+ * Get operation result.
473
+ * @return A pointer to the resulting object in case of success, nullptr otherwise.
474
+ */
413
475
AbstractShapeBase *GetOperationResponse () const noexcept ;
476
+
477
+ /* *
478
+ * Get error for a failed operation.
479
+ * @return A pointer to the error object in case of failure, nullptr otherwise.
480
+ */
414
481
OperationError *GetOperationError () const noexcept ;
482
+
483
+ /* *
484
+ * Get RPC-level error.
485
+ * @return A pointer to the error object in case of RPC-level failure, nullptr otherwise.
486
+ */
415
487
RpcError GetRpcError () const noexcept ;
488
+
489
+ /* *
490
+ * Get the type of the result with which the operation has completed.
491
+ * @return Result type.
492
+ */
416
493
ResultType GetResultType () const noexcept { return m_responseType; }
417
494
418
495
private:
@@ -463,20 +540,67 @@ namespace Aws
463
540
Crt::Allocator *allocator) const noexcept = 0;
464
541
};
465
542
543
+ /* *
544
+ * All generated model types implement this interface, including errors.
545
+ */
466
546
class AWS_EVENTSTREAMRPC_API OperationModelContext
467
547
{
468
548
public:
469
549
OperationModelContext (const ServiceModel &serviceModel) noexcept ;
550
+
551
+ /* *
552
+ * Parse the given string into an initial response object.
553
+ * @param stringView String to parse the response from.
554
+ * @param allocator Allocator to use.
555
+ * @return The initial response object.
556
+ */
470
557
virtual Crt::ScopedResource<AbstractShapeBase> AllocateInitialResponseFromPayload (
471
558
Crt::StringView stringView,
472
559
Crt::Allocator *allocator) const noexcept = 0;
560
+
561
+ /* *
562
+ * Parse the given string into a streaming response object.
563
+ * @param stringView String to parse the response from.
564
+ * @param allocator Allocator to use.
565
+ * @return The streaming response object.
566
+ */
473
567
virtual Crt::ScopedResource<AbstractShapeBase> AllocateStreamingResponseFromPayload (
474
568
Crt::StringView stringView,
475
569
Crt::Allocator *allocator) const noexcept = 0;
570
+
571
+ /* *
572
+ * Get the initial response type name.
573
+ * @return The initial response type name.
574
+ */
476
575
virtual Crt::String GetInitialResponseModelName () const noexcept = 0;
576
+
577
+ /* *
578
+ * Get the request type name.
579
+ * @return The request type name.
580
+ */
477
581
virtual Crt::String GetRequestModelName () const noexcept = 0;
582
+
583
+ /* *
584
+ * Get the streaming response type name.
585
+ * @return The streaming response type name.
586
+ */
478
587
virtual Crt::Optional<Crt::String> GetStreamingResponseModelName () const noexcept = 0;
588
+
589
+ /* *
590
+ * Returns the canonical operation name associated with this context across any client language.
591
+ * Namespace included.
592
+ * Example: aws.greengrass#SubscribeToTopic
593
+ * @return The canonical operation name associated with this context across any client language.
594
+ */
479
595
virtual Crt::String GetOperationName () const noexcept = 0;
596
+
597
+ /* *
598
+ * Parse the given string into an operation error.
599
+ * @param errorModelName The model name.
600
+ * @param stringView String to parse the error from.
601
+ * @param allocator Allocator to use.
602
+ * @return The operation error.
603
+ */
480
604
Crt::ScopedResource<OperationError> AllocateOperationErrorFromPayload (
481
605
const Crt::String &errorModelName,
482
606
Crt::StringView stringView,
@@ -489,6 +613,9 @@ namespace Aws
489
613
const ServiceModel &m_serviceModel;
490
614
};
491
615
616
+ /* *
617
+ * Interface for an RPC operation.
618
+ */
492
619
class AWS_EVENTSTREAMRPC_API ClientOperation : public ClientContinuationHandler
493
620
{
494
621
public:
@@ -504,18 +631,48 @@ namespace Aws
504
631
bool operator =(const ClientOperation &clientOperation) noexcept = delete ;
505
632
bool operator =(ClientOperation &&clientOperation) noexcept = delete ;
506
633
634
+ /* *
635
+ * Close the stream on which operation is sent.
636
+ * @note This function sends a message with the message flag set to terminate the stream.
637
+ * @param onMessageFlushCallback Callback to invoke when the closing message is flushed to the underlying
638
+ * transport.
639
+ * @return Future which will be resolved once the message is sent.
640
+ */
507
641
std::future<RpcError> Close (OnMessageFlushCallback onMessageFlushCallback = nullptr ) noexcept ;
642
+
643
+ /* *
644
+ * Get an operation result.
645
+ * @return Future which will be resolved when the corresponding RPC request completes.
646
+ */
508
647
std::future<TaggedResult> GetOperationResult () noexcept ;
648
+
649
+ /* *
650
+ * Set the launch mode for executing operations. The mode is set to std::launch::deferred by default.
651
+ * @param mode The launch mode to use.
652
+ */
509
653
void WithLaunchMode (std::launch mode) noexcept ;
510
654
511
655
protected:
656
+ /* *
657
+ * Initiate a new client stream. Send the shape for the new stream.
658
+ * @param shape A parameter for RPC operation.
659
+ * @param onMessageFlushCallback Callback to invoke when the shape is flushed to the underlying transport.
660
+ * @return Future which will be resolved once the message is sent.
661
+ */
512
662
std::future<RpcError> Activate (
513
663
const AbstractShapeBase *shape,
514
664
OnMessageFlushCallback onMessageFlushCallback) noexcept ;
515
665
std::future<RpcError> SendStreamEvent (
516
666
AbstractShapeBase *shape,
517
667
OnMessageFlushCallback onMessageFlushCallback) noexcept ;
668
+
669
+ /* *
670
+ * Returns the canonical model name associated with this operation across any client language.
671
+ * Namespace included.
672
+ * @return The model name.
673
+ */
518
674
virtual Crt::String GetModelName () const noexcept = 0;
675
+
519
676
const OperationModelContext &m_operationModelContext;
520
677
std::launch m_asyncLaunchMode;
521
678
@@ -566,6 +723,9 @@ namespace Aws
566
723
std::condition_variable m_closeReady;
567
724
};
568
725
726
+ /* *
727
+ * Class representing a connection to an RPC server.
728
+ */
569
729
class AWS_EVENTSTREAMRPC_API ClientConnection final
570
730
{
571
731
public:
@@ -576,6 +736,13 @@ namespace Aws
576
736
ClientConnection (ClientConnection &&) noexcept ;
577
737
ClientConnection &operator =(ClientConnection &&) noexcept ;
578
738
739
+ /* *
740
+ * Initiates a new outgoing event-stream-rpc connection.
741
+ * @param connectionOptions Connection options.
742
+ * @param connectionLifecycleHandler Handler to process connection lifecycle events.
743
+ * @param clientBootstrap ClientBootstrap object to run the connection on.
744
+ * @return Future that will be resolved when connection either succeeds or fails.
745
+ */
579
746
std::future<RpcError> Connect (
580
747
const ConnectionConfig &connectionOptions,
581
748
ConnectionLifecycleHandler *connectionLifecycleHandler,
@@ -591,10 +758,23 @@ namespace Aws
591
758
const Crt::Optional<Crt::ByteBuf> &payload,
592
759
OnMessageFlushCallback onMessageFlushCallback) noexcept ;
593
760
761
+ /* *
762
+ * Create a new stream.
763
+ * @note Activate() must be called on the stream for it to actually initiate the new stream.
764
+ * @param clientContinuationHandler Handler to process continuation events.
765
+ * @return A newly created continuation.
766
+ */
594
767
ClientContinuation NewStream (ClientContinuationHandler &clientContinuationHandler) noexcept ;
595
768
769
+ /* *
770
+ * Close the connection.
771
+ */
596
772
void Close () noexcept ;
597
773
774
+ /* *
775
+ * Check if the connection is open.
776
+ * @return True if the connection is open, false otherwise.
777
+ */
598
778
bool IsOpen () const noexcept
599
779
{
600
780
if (this ->m_underlyingConnection == nullptr )
@@ -608,7 +788,7 @@ namespace Aws
608
788
}
609
789
610
790
/* *
611
- * @return true if the instance is in a valid state , false otherwise.
791
+ * @return true if the connection is open , false otherwise.
612
792
*/
613
793
operator bool () const noexcept { return IsOpen (); }
614
794
@@ -660,6 +840,10 @@ namespace Aws
660
840
void *userData) noexcept ;
661
841
662
842
static void s_protocolMessageCallback (int errorCode, void *userData) noexcept ;
843
+
844
+ /* *
845
+ * Sends a message on the connection. These must be connection level messages (not application messages).
846
+ */
663
847
static std::future<RpcError> s_sendProtocolMessage (
664
848
ClientConnection *connection,
665
849
const Crt::List<EventStreamHeader> &headers,
0 commit comments