-
Notifications
You must be signed in to change notification settings - Fork 62
/
mercury.h
1369 lines (1239 loc) · 44.4 KB
/
mercury.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* Copyright (c) 2013-2022 UChicago Argonne, LLC and The HDF Group.
* Copyright (c) 2022-2023 Intel Corporation.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#ifndef MERCURY_H
#define MERCURY_H
#include "mercury_header.h"
#include "mercury_types.h"
#include "mercury_core.h"
#include <stdio.h>
/*************************************/
/* Public Type and Struct Definition */
/*************************************/
/* See mercury_types.h */
/*****************/
/* Public Macros */
/*****************/
/* See mercury_types.h */
/*********************/
/* Public Prototypes */
/*********************/
#ifdef __cplusplus
extern "C" {
#endif
/**
* Get Mercury version number.
*
* \param major_p [OUT] pointer to unsigned integer
* \param minor_p [OUT] pointer to unsigned integer
* \param patch_p [OUT] pointer to unsigned integer
*
* \return HG_SUCCESS or corresponding HG error code
*/
HG_PUBLIC hg_return_t
HG_Version_get(
unsigned int *major_p, unsigned int *minor_p, unsigned int *patch_p);
/**
* Convert error return code to string (null terminated).
*
* \param errnum [IN] error return code
*
* \return String
*/
HG_PUBLIC const char *
HG_Error_to_string(hg_return_t errnum) HG_WARN_UNUSED_RESULT;
/**
* Get information on protocols that are supported by underlying NA plugins. If
* \info_string is NULL, a list of all supported protocols by all plugins will
* be returned. The returned list must be freed using
* HG_Free_na_protocol_info().
*
* \param info_string [IN] NULL or "<protocol>" or "<plugin+protocol>"
* \param na_protocol_info_p [OUT] linked-list of protocol infos
*
* \return HG_SUCCESS or corresponding NA error code
*/
static HG_INLINE hg_return_t
HG_Get_na_protocol_info(
const char *info_string, struct na_protocol_info **na_protocol_info_p);
/**
* Free protocol info.
*
* \param na_protocol_info [IN/OUT] linked-list of protocol infos
*/
static HG_INLINE void
HG_Free_na_protocol_info(struct na_protocol_info *na_protocol_info);
/**
* Initialize the Mercury layer.
* Must be finalized with HG_Finalize().
*
* \param na_info_string [IN] host address with port number (e.g.,
* "tcp://localhost:3344" or
* "bmi+tcp://localhost:3344")
* \param na_listen [IN] listen for incoming connections
*
* \return Pointer to HG class or NULL in case of failure
*/
HG_PUBLIC hg_class_t *
HG_Init(const char *na_info_string, uint8_t na_listen) HG_WARN_UNUSED_RESULT;
/**
* Initialize the Mercury layer with options provided by init_info.
* Must be finalized with HG_Finalize(). Using this routine limits the info
* struct version to 2.2 version. It is recommended to use \HG_Init_opt2() for
* mercury versions >= 2.3.0.
* \remark HG_Init_opt() may become HG_Init() in the future.
*
* \param na_info_string [IN] host address with port number (e.g.,
* "tcp://localhost:3344" or
* "bmi+tcp://localhost:3344")
* \param na_listen [IN] listen for incoming connections
* \param hg_init_info [IN] (Optional) HG init info, NULL if no info
*
* \return Pointer to HG class or NULL in case of failure
*/
HG_PUBLIC hg_class_t *
HG_Init_opt(const char *na_info_string, uint8_t na_listen,
const struct hg_init_info *hg_init_info) HG_WARN_UNUSED_RESULT;
/**
* Initialize the Mercury layer with options provided by init_info.
* Must be finalized with HG_Finalize().
* \remark HG_Init_opt() may become HG_Init() in the future.
*
* \param na_info_string [IN] host address with port number (e.g.,
* "tcp://localhost:3344" or
* "bmi+tcp://localhost:3344")
* \param na_listen [IN] listen for incoming connections
* \param version [IN] API version of the init info struct
* \param hg_init_info [IN] (Optional) HG init info, NULL if no info
*
* \return Pointer to HG class or NULL in case of failure
*/
HG_PUBLIC hg_class_t *
HG_Init_opt2(const char *na_info_string, uint8_t na_listen,
unsigned int version,
const struct hg_init_info *hg_init_info) HG_WARN_UNUSED_RESULT;
/**
* Finalize the Mercury layer.
*
* \param hg_class [IN] pointer to HG class
*
* \return HG_SUCCESS or corresponding HG error code
*/
HG_PUBLIC hg_return_t
HG_Finalize(hg_class_t *hg_class);
/**
* Clean up all temporary files that were created in previous HG instances.
* While temporary resources (e.g., tmp files) are cleaned up on a call
* to HG_Finalize(), this routine gives a chance to programs that terminate
* abnormally to easily clean up those resources.
*/
HG_PUBLIC void
HG_Cleanup(void);
/**
* Set the log level for HG. That setting is valid for all HG classes.
*
* \param level [IN] level string, valid values are:
* "none", "error", "warning", "debug"
*/
HG_PUBLIC void
HG_Set_log_level(const char *level);
/**
* Set the log sub-system for HG. That setting is valid for all HG classes.
*
* \param subsys [IN] string of subsystems, format is:
* subsys1,subsys2,subsys3,etc
* subsystem can be turned off, e.g.:
* ~subsys1
*/
HG_PUBLIC void
HG_Set_log_subsys(const char *subsys);
/**
* Set the log function to use for HG. That setting is valid for all HG classes.
*
* \param log_func [IN] function to use
*/
HG_PUBLIC void
HG_Set_log_func(int (*log_func)(FILE *stream, const char *format, ...));
/**
* Set the file stream to use for logging output.
* This setting is valid for all HG classes.
*
* \param level [IN] level string, valid values are:
* "error", "warning", "debug"
* \param stream [IN] file stream pointer
*/
HG_PUBLIC void
HG_Set_log_stream(const char *level, FILE *stream);
/**
* Dump diagnostic counters into the existing log stream.
*/
HG_PUBLIC void
HG_Diag_dump_counters(void);
/**
* Obtain the name of the given class.
*
* \param hg_class [IN] pointer to HG class
*
* \return the name of the class, or NULL if not a valid class
*/
static HG_INLINE const char *
HG_Class_get_name(const hg_class_t *hg_class) HG_WARN_UNUSED_RESULT;
/**
* Obtain the protocol of the given class.
*
* \param hg_class [IN] pointer to HG class
*
* \return the name of the class's transport, or NULL if not a valid class
*/
static HG_INLINE const char *
HG_Class_get_protocol(const hg_class_t *hg_class) HG_WARN_UNUSED_RESULT;
/**
* Test whether class is listening or not.
*
* \param hg_class [IN] pointer to HG class
*
* \return true if listening or false if not, or not a valid class
*/
static HG_INLINE bool
HG_Class_is_listening(const hg_class_t *hg_class) HG_WARN_UNUSED_RESULT;
/**
* Obtain the maximum eager size for sending RPC inputs, for a given class.
* NOTE: This doesn't currently work when using XDR encoding.
*
* \param hg_class [IN] pointer to HG class
*
* \return the maximum size, or 0 if hg_class is not a valid class or XDR is
* being used
*/
static HG_INLINE hg_size_t
HG_Class_get_input_eager_size(const hg_class_t *hg_class) HG_WARN_UNUSED_RESULT;
/**
* Obtain the maximum eager size for sending RPC outputs, for a given class.
* NOTE: This doesn't currently work when using XDR encoding.
*
* \param hg_class [IN] pointer to HG class
*
* \return the maximum size, or 0 if hg_class is not a valid class or XDR is
* being used
*/
static HG_INLINE hg_size_t
HG_Class_get_output_eager_size(
const hg_class_t *hg_class) HG_WARN_UNUSED_RESULT;
/**
* Set offset used for serializing / deserializing input. This allows upper
* layers to manually define a reserved space that can be used for the
* definition of custom headers. The actual input is encoded / decoded
* using the defined offset. By default, no offset is set.
*
* \param hg_class [IN] pointer to HG class
* \param offset [IN] offset size
*
* \return HG_SUCCESS or corresponding HG error code
*/
static HG_INLINE hg_return_t
HG_Class_set_input_offset(hg_class_t *hg_class, hg_size_t offset);
/**
* Set offset used for serializing / deserializing output. This allows upper
* layers to manually define a reserved space that can be used for the
* definition of custom headers. The actual output is encoded / decoded
* using the defined offset. By default, no offset is set.
*
* \param hg_class [IN] pointer to HG class
* \param offset [IN] offset size
*
* \return HG_SUCCESS or corresponding HG error code
*/
static HG_INLINE hg_return_t
HG_Class_set_output_offset(hg_class_t *hg_class, hg_size_t offset);
/**
* Associate user data to class. When HG_Finalize() is called,
* free_callback (if defined) is called to free the associated data.
*
* \param hg_class [IN] pointer to HG class
* \param data [IN] pointer to user data
* \param free_callback [IN] pointer to function
*
* \return HG_SUCCESS or corresponding HG error code
*/
static HG_INLINE hg_return_t
HG_Class_set_data(
hg_class_t *hg_class, void *data, void (*free_callback)(void *));
/**
* Retrieve previously associated data from a given class.
*
* \param hg_class [IN] pointer to HG class
*
* \return Pointer to user data or NULL if not set or any error has occurred
*/
static HG_INLINE void *
HG_Class_get_data(const hg_class_t *hg_class) HG_WARN_UNUSED_RESULT;
/**
* Get diagnostic counters associated to HG class.
* (Requires debug enabled build)
*
* \param hg_class [IN] pointer to HG class
* \param diag_counters [IN/OUT] pointer to counters struct
*
* \return HG_SUCCESS or corresponding HG error code
*/
HG_PUBLIC hg_return_t
HG_Class_get_counters(
const hg_class_t *hg_class, struct hg_diag_counters *diag_counters);
/**
* Set callback to be called on HG handle creation. Handles are created
* both on HG_Create() and HG_Context_create() calls. This allows upper layers
* to create and attach data to a handle (using HG_Set_data()) and later
* retrieve it using HG_Get_data().
*
* \param hg_class [IN] pointer to HG class
* \param callback [IN] pointer to function callback
* \param arg [IN] pointer to data passed to callback
*
* \return HG_SUCCESS or corresponding HG error code
*/
HG_PUBLIC hg_return_t
HG_Class_set_handle_create_callback(hg_class_t *hg_class,
hg_return_t (*callback)(hg_handle_t, void *), void *arg);
/**
* Create a new context. Must be destroyed by calling HG_Context_destroy().
*
* \remark This routine is internally equivalent to:
* - HG_Core_context_create()
* - If listening
* - HG_Core_context_post() with repost set to HG_TRUE
*
* \param hg_class [IN] pointer to HG class
*
* \return Pointer to HG context or NULL in case of failure
*/
HG_PUBLIC hg_context_t *
HG_Context_create(hg_class_t *hg_class) HG_WARN_UNUSED_RESULT;
/**
* Create a new context with a user-defined context identifier. The context
* identifier can be used to route RPC requests to specific contexts by using
* HG_Set_target_id().
* Context must be destroyed by calling HG_Context_destroy().
*
* \remark This routine is internally equivalent to:
* - HG_Core_context_create_id() with specified context ID
* - If listening
* - HG_Core_context_post() with repost set to HG_TRUE
*
* \param hg_class [IN] pointer to HG class
* \param id [IN] user-defined context ID
*
* \return Pointer to HG context or NULL in case of failure
*/
HG_PUBLIC hg_context_t *
HG_Context_create_id(hg_class_t *hg_class, uint8_t id) HG_WARN_UNUSED_RESULT;
/**
* Destroy a context created by HG_Context_create(). If listening and
* HG_Context_unpost() has not already been called, also cancels previously
* posted requests.
*
* \param context [IN] pointer to HG context
*
* \return HG_SUCCESS or corresponding HG error code
*/
HG_PUBLIC hg_return_t
HG_Context_destroy(hg_context_t *context);
/**
* Unpost pre-posted requests if listening. This prevents any further RPCs
* from being received by that context.
*
* \param context [IN] pointer to HG context
*
* \return HG_SUCCESS or corresponding HG error code
*/
HG_PUBLIC hg_return_t
HG_Context_unpost(hg_context_t *context);
/**
* Retrieve the class used to create the given context.
*
* \param context [IN] pointer to HG context
*
* \return Pointer to associated HG class or NULL if not a valid context
*/
static HG_INLINE hg_class_t *
HG_Context_get_class(const hg_context_t *context) HG_WARN_UNUSED_RESULT;
/**
* Retrieve context ID from context (max value of 255).
*
* \param context [IN] pointer to HG context
*
* \return Non-negative integer (max value of 255) or 0 if no ID has been set
*/
static HG_INLINE uint8_t
HG_Context_get_id(const hg_context_t *context) HG_WARN_UNUSED_RESULT;
/**
* Associate user data to context. When HG_Context_destroy() is called,
* free_callback (if defined) is called to free the associated data.
*
* \param context [IN] pointer to HG context
* \param data [IN] pointer to user data
* \param free_callback [IN] pointer to function
*
* \return HG_SUCCESS or corresponding HG error code
*/
static HG_INLINE hg_return_t
HG_Context_set_data(
hg_context_t *context, void *data, void (*free_callback)(void *));
/**
* Retrieve previously associated data from a given context.
*
* \param context [IN] pointer to HG context
*
* \return Pointer to user data or NULL if not set or any error has occurred
*/
static HG_INLINE void *
HG_Context_get_data(const hg_context_t *context) HG_WARN_UNUSED_RESULT;
/**
* Dynamically register a function func_name as an RPC as well as the
* RPC callback executed when the RPC request ID associated to func_name is
* received. Associate input and output proc to function ID, so that they can
* be used to serialize and deserialize function parameters.
*
* \param hg_class [IN] pointer to HG class
* \param func_name [IN] unique name associated to function
* \param in_proc_cb [IN] pointer to input proc callback
* \param out_proc_cb [IN] pointer to output proc callback
* \param rpc_cb [IN] RPC callback
*
* \return unique ID associated to the registered function
*/
HG_PUBLIC hg_id_t
HG_Register_name(hg_class_t *hg_class, const char *func_name,
hg_proc_cb_t in_proc_cb, hg_proc_cb_t out_proc_cb,
hg_rpc_cb_t rpc_cb) HG_WARN_UNUSED_RESULT;
/*
* Indicate whether HG_Register_name() has been called for the RPC specified by
* func_name.
*
* \param hg_class [IN] pointer to HG class
* \param func_name [IN] function name
* \param id_p [OUT] registered RPC ID
* \param flag_p [OUT] pointer to boolean
*
* \return HG_SUCCESS or corresponding HG error code
*/
HG_PUBLIC hg_return_t
HG_Registered_name(hg_class_t *hg_class, const char *func_name, hg_id_t *id_p,
uint8_t *flag_p);
/**
* Dynamically register an RPC ID as well as the RPC callback executed when the
* RPC request ID is received. Associate input and output proc to id, so that
* they can be used to serialize and deserialize function parameters.
*
* \param hg_class [IN] pointer to HG class
* \param id [IN] ID to use to register RPC
* \param in_proc_cb [IN] pointer to input proc callback
* \param out_proc_cb [IN] pointer to output proc callback
* \param rpc_cb [IN] RPC callback
*
* \return HG_SUCCESS or corresponding HG error code
*/
HG_PUBLIC hg_return_t
HG_Register(hg_class_t *hg_class, hg_id_t id, hg_proc_cb_t in_proc_cb,
hg_proc_cb_t out_proc_cb, hg_rpc_cb_t rpc_cb);
/**
* Deregister RPC ID. Further requests with RPC ID will return an error, it
* is therefore up to the user to make sure that all requests for that RPC ID
* have been treated before it is unregistered.
*
* \param hg_class [IN] pointer to HG class
* \param id [IN] registered function ID
*
* \return HG_SUCCESS or corresponding HG error code
*/
HG_PUBLIC hg_return_t
HG_Deregister(hg_class_t *hg_class, hg_id_t id);
/**
* Indicate whether HG_Register() has been called.
*
* \param hg_class [IN] pointer to HG class
* \param id [IN] function ID
* \param flag_p [OUT] pointer to boolean
*
* \return HG_SUCCESS or corresponding HG error code
*/
HG_PUBLIC hg_return_t
HG_Registered(hg_class_t *hg_class, hg_id_t id, uint8_t *flag_p);
/**
* Indicate whether HG_Register() has been called, and if so return pointers
* to proc callback functions for the RPC.
*
* \param hg_class [IN] pointer to HG class
* \param id [IN] function ID
* \param flag_p [OUT] pointer to boolean
* \param in_proc_cb_p [OUT] pointer to input encoder cb
* \param out_proc_cb_p [OUT] pointer to output encoder cb
*
* \return HG_SUCCESS or corresponding HG error code
*/
HG_PUBLIC hg_return_t
HG_Registered_proc_cb(hg_class_t *hg_class, hg_id_t id, uint8_t *flag_p,
hg_proc_cb_t *in_proc_cb_p, hg_proc_cb_t *out_proc_cb_p);
/**
* Register and associate user data to registered function. When HG_Finalize()
* is called, free_callback (if defined) is called to free the registered
* data.
*
* \param hg_class [IN] pointer to HG class
* \param id [IN] registered function ID
* \param data [IN] pointer to data
* \param free_callback [IN] pointer to function
*
* \return HG_SUCCESS or corresponding HG error code
*/
HG_PUBLIC hg_return_t
HG_Register_data(hg_class_t *hg_class, hg_id_t id, void *data,
void (*free_callback)(void *));
/**
* Indicate whether HG_Register_data() has been called and return associated
* data.
*
* \param hg_class [IN] pointer to HG class
* \param id [IN] registered function ID
*
* \return Pointer to data or NULL
*/
HG_PUBLIC void *
HG_Registered_data(hg_class_t *hg_class, hg_id_t id) HG_WARN_UNUSED_RESULT;
/**
* Disable response for a given RPC ID. This allows an origin process to send an
* RPC to a target without waiting for a response. The RPC completes locally and
* the callback on the origin is therefore pushed to the completion queue once
* the RPC send is completed. By default, all RPCs expect a response to
* be sent back.
*
* \param hg_class [IN] pointer to HG class
* \param id [IN] registered function ID
* \param disable [IN] boolean (HG_TRUE to disable
* HG_FALSE to re-enable)
*
* \return HG_SUCCESS or corresponding HG error code
*/
HG_PUBLIC hg_return_t
HG_Registered_disable_response(
hg_class_t *hg_class, hg_id_t id, uint8_t disable);
/**
* Check if response is disabled for a given RPC ID
* (i.e., HG_Registered_disable_response() has been called for this RPC ID).
*
* \param hg_class [IN] pointer to HG class
* \param id [IN] registered function ID
* \param disabled_p [OUT] boolean (HG_TRUE if disabled
* HG_FALSE if enabled)
*
* \return HG_SUCCESS or corresponding HG error code
*/
HG_PUBLIC hg_return_t
HG_Registered_disabled_response(
hg_class_t *hg_class, hg_id_t id, uint8_t *disabled_p);
/**
* Lookup an addr from a peer address/name. Addresses need to be
* freed by calling HG_Addr_free(). After completion, user callback is
* placed into a completion queue and can be triggered using HG_Trigger().
*
* \param context [IN] pointer to context of execution
* \param callback [IN] pointer to function callback
* \param arg [IN] pointer to data passed to callback
* \param name [IN] lookup name
* \param op_id [OUT] pointer to returned operation ID (unused)
*
* \return HG_SUCCESS or corresponding HG error code
*/
HG_PUBLIC hg_return_t
HG_Addr_lookup1(hg_context_t *context, hg_cb_t callback, void *arg,
const char *name, hg_op_id_t *op_id_p);
/* This will map to HG_Addr_lookup2() in the future */
#ifndef HG_Addr_lookup
# define HG_Addr_lookup HG_Addr_lookup1
#endif
/**
* Lookup an addr from a peer address/name. Addresses need to be
* freed by calling HG_Addr_free().
*
* \remark This is the immediate version of HG_Addr_lookup1().
*
* \param hg_class [IN/OUT] pointer to HG class
* \param name [IN] lookup name
* \param addr_p [OUT] pointer to abstract address
*
* \return HG_SUCCESS or corresponding HG error code
*/
HG_PUBLIC hg_return_t
HG_Addr_lookup2(hg_class_t *hg_class, const char *name, hg_addr_t *addr_p);
/**
* Free the addr.
*
* \param hg_class [IN] pointer to HG class
* \param addr [IN] abstract address
*
* \return HG_SUCCESS or corresponding HG error code
*/
HG_PUBLIC hg_return_t
HG_Addr_free(hg_class_t *hg_class, hg_addr_t addr);
/**
* Hint that the address is no longer valid. This may happen if the peer is
* no longer responding. This can be used to force removal of the
* peer address from the list of the peers, before freeing it and reclaim
* resources.
*
* \param hg_class [IN] pointer to HG class
* \param addr [IN] abstract address
*
* \return HG_SUCCESS or corresponding HG error code
*/
HG_PUBLIC hg_return_t
HG_Addr_set_remove(hg_class_t *hg_class, hg_addr_t addr);
/**
* Access self address. Address must be freed with HG_Addr_free().
*
* \param hg_class [IN] pointer to HG class
* \param addr_p [OUT] pointer to abstract address
*
* \return HG_SUCCESS or corresponding HG error code
*/
HG_PUBLIC hg_return_t
HG_Addr_self(hg_class_t *hg_class, hg_addr_t *addr_p);
/**
* Duplicate an existing HG abstract address. The duplicated address can be
* stored for later use and the origin address be freed safely. The duplicated
* address must be freed with HG_Addr_free().
*
* \param hg_class [IN] pointer to HG class
* \param addr [IN] abstract address
* \param new_addr_p [OUT] pointer to abstract address
*
* \return HG_SUCCESS or corresponding HG error code
*/
HG_PUBLIC hg_return_t
HG_Addr_dup(hg_class_t *hg_class, hg_addr_t addr, hg_addr_t *new_addr_p);
/**
* Compare two addresses.
*
* \param hg_class [IN] pointer to HG class
* \param addr1 [IN] abstract address
* \param addr2 [IN] abstract address
*
* \return HG_TRUE if addresses are determined to be equal, HG_FALSE otherwise
*/
HG_PUBLIC uint8_t
HG_Addr_cmp(hg_class_t *hg_class, hg_addr_t addr1,
hg_addr_t addr2) HG_WARN_UNUSED_RESULT;
/**
* Convert an addr to a string (returned string includes the terminating
* null byte '\0'). If buf is NULL, the address is not converted and only
* the required size of the buffer is returned. If the input value passed
* through buf_size is too small, HG_SIZE_ERROR is returned and the buf_size
* output is set to the minimum size required.
*
* \param hg_class [IN] pointer to HG class
* \param buf [IN/OUT] pointer to destination buffer
* \param buf_size_p [IN/OUT] pointer to buffer size
* \param addr [IN] abstract address
*
* \return HG_SUCCESS or corresponding HG error code
*/
HG_PUBLIC hg_return_t
HG_Addr_to_string(
hg_class_t *hg_class, char *buf, hg_size_t *buf_size_p, hg_addr_t addr);
/**
* Initiate a new HG RPC using the specified function ID and the local/remote
* target defined by addr. The HG handle created can be used to query input
* and output, as well as issuing the RPC by calling HG_Forward().
* After completion the handle must be freed using HG_Destroy().
*
* \param context [IN] pointer to HG context
* \param addr [IN] abstract network address of destination
* \param id [IN] registered function ID
* \param handle_p [OUT] pointer to HG handle
*
* \return HG_SUCCESS or corresponding HG error code
*/
HG_PUBLIC hg_return_t
HG_Create(
hg_context_t *context, hg_addr_t addr, hg_id_t id, hg_handle_t *handle_p);
/**
* Destroy HG handle. Decrement reference count, resources associated to the
* handle are freed when the reference count is null.
*
* \param handle [IN] HG handle
*
* \return HG_SUCCESS or corresponding HG error code
*/
HG_PUBLIC hg_return_t
HG_Destroy(hg_handle_t handle);
/**
* Reset an existing HG handle to make it reusable for RPC forwarding.
* Both target address and RPC ID can be modified at this time.
* Operations on that handle must be completed in order to reset that handle
* safely.
*
* \param handle [IN] HG handle
* \param addr [IN] abstract network address of destination
* \param id [IN] registered function ID
*
* \return HG_SUCCESS or corresponding HG error code
*/
HG_PUBLIC hg_return_t
HG_Reset(hg_handle_t handle, hg_addr_t addr, hg_id_t id);
/**
* Increment ref count on handle.
*
* \param handle [IN] HG handle
*
* \return HG_SUCCESS or corresponding HG error code
*/
static HG_INLINE hg_return_t
HG_Ref_incr(hg_handle_t hg_handle);
/**
* Retrieve ref count from handle.
*
* \param handle [IN] HG handle
*
* \return Non-negative value or negative if the handle is not valid
*/
static HG_INLINE int32_t
HG_Ref_get(hg_handle_t handle) HG_WARN_UNUSED_RESULT;
/**
* Get info from handle.
*
* \remark Users must call HG_Addr_dup() to safely re-use the addr field.
*
* \param handle [IN] HG handle
*
* \return Pointer to info or NULL in case of failure
*/
static HG_INLINE const struct hg_info *
HG_Get_info(hg_handle_t handle) HG_WARN_UNUSED_RESULT;
/**
* Associate user data to handle. When HG_Destroy() is called,
* free_callback (if defined) is called to free the associated data.
*
* \param handle [IN] HG handle
* \param data [IN] pointer to user data
* \param free_callback [IN] pointer to function
*
* \return HG_SUCCESS or corresponding HG error code
*/
static HG_INLINE hg_return_t
HG_Set_data(hg_handle_t handle, void *data, void (*free_callback)(void *));
/**
* Retrieve previously associated data from a given handle.
*
* \param handle [IN] HG handle
*
* \return Pointer to user data or NULL if not set or any error has occurred
*/
static HG_INLINE void *
HG_Get_data(hg_handle_t handle) HG_WARN_UNUSED_RESULT;
/**
* Retrieve input payload size from a given handle.
*
* \param handle [IN] HG handle
*
* \return Non-negative value or zero if no payload or the handle is not valid
*/
HG_PUBLIC hg_size_t
HG_Get_input_payload_size(hg_handle_t handle);
/**
* Get input from handle (requires registration of input proc to deserialize
* parameters). Input must be freed using HG_Free_input().
*
* \remark This is equivalent to:
* - HG_Core_get_input()
* - Call hg_proc to deserialize parameters
*
* \remark The input buffer may be released automatically after that call if the
* release_input_early init info parameter has been set when initializing the
* HG class.
*
* \param handle [IN] HG handle
* \param in_struct [IN/OUT] pointer to input structure
*
* \return HG_SUCCESS or corresponding HG error code
*/
HG_PUBLIC hg_return_t
HG_Get_input(hg_handle_t handle, void *in_struct);
/**
* Free resources allocated when deserializing the input.
* User may copy parameters contained in the input structure before calling
* HG_Free_input().
*
* \param handle [IN] HG handle
* \param in_struct [IN/OUT] pointer to input structure
*
* \return HG_SUCCESS or corresponding HG error code
*/
HG_PUBLIC hg_return_t
HG_Free_input(hg_handle_t handle, void *in_struct);
/**
* Retrieve output payload size from a given handle.
*
* \param handle [IN] HG handle
*
* \return Non-negative value or zero if no payload or the handle is not valid
*/
HG_PUBLIC hg_size_t
HG_Get_output_payload_size(hg_handle_t handle);
/**
* Get output from handle (requires registration of output proc to deserialize
* parameters). Output must be freed using HG_Free_output().
*
* \remark This is equivalent to:
* - HG_Core_get_output()
* - Call hg_proc to deserialize parameters
*
*
* \param handle [IN] HG handle
* \param out_struct [IN/OUT] pointer to output structure
*
* \return HG_SUCCESS or corresponding HG error code
*/
HG_PUBLIC hg_return_t
HG_Get_output(hg_handle_t handle, void *out_struct);
/**
* Free resources allocated when deserializing the output.
* User may copy parameters contained in the output structure before calling
* HG_Free_output().
*
* \param handle [IN] HG handle
* \param out_struct [IN/OUT] pointer to input structure
*
* \return HG_SUCCESS or corresponding HG error code
*/
HG_PUBLIC hg_return_t
HG_Free_output(hg_handle_t handle, void *out_struct);
/**
* Get raw input buffer from handle that can be used for encoding and decoding
* parameters.
*
* \remark Can be used for manual encoding / decoding when HG proc routines
* cannot be automatically used or there is need for special handling before
* HG_Get_input() can be called, for instance when using a custom header.
* To use proc routines conjunctively, HG_Class_set_input_offset() can be used
* to define the offset at which HG_Forward() / HG_Get_input() will start
* encoding / decoding the input parameters.
*
* \remark in_buf_size argument will be ignored if NULL
*
* \param handle [IN] HG handle
* \param in_buf_p [OUT] pointer to input buffer
* \param in_buf_size_p [OUT] pointer to input buffer size
*
* \return HG_SUCCESS or corresponding HG error code
*/
HG_PUBLIC hg_return_t
HG_Get_input_buf(hg_handle_t handle, void **in_buf_p, hg_size_t *in_buf_size_p);
/**
* Release input buffer from handle so that it can be re-used early.
*
* \remark HG_Release_input_buf() may only be called when using
* HG_Get_input_buf(). When using HG_Get_input(), the input buffer may
* internally be released after HG_Get_input() is called. Note also that
* if HG_Release_input_buf() is not called, the input buffer will later be
* released when calling HG_Destroy().
*
* \param handle [IN] HG handle
*
* \return HG_SUCCESS or corresponding HG error code
*/
HG_PUBLIC hg_return_t
HG_Release_input_buf(hg_handle_t handle);
/**
* Get raw output buffer from handle that can be used for encoding and decoding
* parameters.
*
* \remark Can be used for manual encoding / decoding when HG proc routines
* cannot be automatically used or there is need for special handling before
* HG_Get_output() can be called, for instance when using a custom header.
* To use proc routines conjunctively, HG_Class_set_output_offset() can be used
* to define the offset at which HG_Respond() / HG_Get_output() will start
* encoding / decoding the output parameters.
*
* \remark out_buf_size argument will be ignored if NULL
*
* \param handle [IN] HG handle
* \param out_buf_p [OUT] pointer to output buffer
* \param out_buf_size_p [OUT] pointer to output buffer size
*
* \return HG_SUCCESS or corresponding HG error code
*/
HG_PUBLIC hg_return_t
HG_Get_output_buf(
hg_handle_t handle, void **out_buf_p, hg_size_t *out_buf_size_p);
/**
* Get raw extra input buffer from handle that can be used for encoding and
* decoding parameters. This buffer is only valid if the input payload is large
* enough that it cannot fit into an eager buffer.
*
* \remark NULL pointer will be returned if there is no associated buffer.
*
* \remark in_buf_size argument will be ignored if NULL.
*
* \param handle [IN] HG handle
* \param in_buf_p [OUT] pointer to input buffer
* \param in_buf_size_p [OUT] pointer to input buffer size
*
* \return HG_SUCCESS or corresponding HG error code
*/
HG_PUBLIC hg_return_t
HG_Get_input_extra_buf(
hg_handle_t handle, void **in_buf_p, hg_size_t *in_buf_size_p);
/**
* Get raw extra output buffer from handle that can be used for encoding and
* decoding parameters. This buffer is only valid if the output payload is large
* enough that it cannot fit into an eager buffer.
*
* \remark NULL pointer will be returned if there is no associated buffer.
*
* \remark out_buf_size argument will be ignored if NULL.
*
* \param handle [IN] HG handle
* \param out_buf_p [OUT] pointer to output buffer
* \param out_buf_size_p [OUT] pointer to output buffer size
*
* \return HG_SUCCESS or corresponding HG error code
*/
HG_PUBLIC hg_return_t
HG_Get_output_extra_buf(
hg_handle_t handle, void **out_buf_p, hg_size_t *out_buf_size_p);
/**
* Set target context ID that will receive and process the RPC request
* (ID is defined on target context creation, see HG_Context_create_id()).
*
* \param handle [IN] HG handle
* \param id [IN] user-defined target context ID
*
* \return HG_SUCCESS or corresponding HG error code
*/
static HG_INLINE hg_return_t
HG_Set_target_id(hg_handle_t handle, uint8_t id);
/**