summaryrefslogtreecommitdiff
path: root/rpc++/rpc++.texi
blob: 71ed33017b76d8153e230eabd775db6f049e8bdf (plain)
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
\input texinfo   @c -*-texinfo-*-
@tex
% They are redefined in texinfo, but I need them
\gdef\`#1{{\accent18 #1}}
\gdef\'#1{{\accent19 #1}}
\gdef\[{{[}}
\gdef\]{{]}}
@end tex
@comment %**start of header (This is for running Texinfo on a region.)
@setfilename rpc++.info
@settitle A C++ Interface to Remote Procedure Calls
@setchapternewpage on
@comment %**end of header (This is for running Texinfo on a region.)

@c You'll have to define the following additional texinfo-formats to
@c run texinfo on this file.
@c
@c   (put '\& 'texinfo-format 'texinfo-format-\&)
@c   (defun texinfo-format-\& ()
@c     (texinfo-discard-command)
@c     (insert "&"))
@c
@c   (put '\[ 'texinfo-format 'texinfo-format-\[)
@c   (defun texinfo-format-\[ ()
@c     (texinfo-discard-command)
@c     (insert "["))
@c
@c   (put '\] 'texinfo-format 'texinfo-format-\])
@c   (defun texinfo-format-\] ()
@c     (texinfo-discard-command)
@c     (insert "]"))

@ifinfo
This file documents a C++ interface to Sun remote procedure calls.

Copyright @copyright{} 1992 Michael N. Lipp
Permission is granted to make and distribute verbatim copies of
this manual provided the copyright notice and this permission notice
are preserved on all copies.

@ignore
Permission is granted to process this file through @TeX{} and print the
results, provided the printed document carries copying permission
notice identical to this one except for the removal of this paragraph
(this paragraph not being relevant to the printed manual).

@end ignore
Permission is granted to copy and distribute modified versions of this
manual under the conditions for verbatim copying, provided also that the
section entitled ``GNU Library General Public License'' is included exactly as
in the original, and provided that the entire resulting derived work is
distributed under the terms of a permission notice identical to this one.

Permission is granted to copy and distribute translations of this manual
into another language, under the above conditions for modified versions,
except that the section entitled ``GNU Library General Public License'' and
this permission notice may be included in translations approved by the
Free Software Foundation instead of in the original English.
@end ifinfo

@titlepage

@title A C++ Interface
@title to Sun Remote Procedure Calls
@sp 1
@subtitle @authorfont{by Michael N. Lipp}
@sp 20
@subtitle{for version 2.2}
@subtitle{Technische Hochschule Darmstadt, Institut f@"ur Datentechnik}

@comment  The following two commands start the copyright page.
@page
@vskip 0pt plus 1filll
Copyright @copyright{} 1992 Michael N. Lipp

Permission is granted to make and distribute verbatim copies of
this manual provided the copyright notice and this permission notice
are preserved on all copies.

Permission is granted to copy and distribute modified versions of this
manual under the conditions for verbatim copying, provided also that the
section entitled ``GNU Library General Public License'' is included exactly as
in the original, and provided that the entire resulting derived work is
distributed under the terms of a permission notice identical to this one.

Permission is granted to copy and distribute translations of this manual
into another language, under the above conditions for modified versions,
except that the section entitled ``GNU Library General Public License'' may be
included in a translation approved by the author instead of in the original
English.
@end titlepage

@node Top, Overview, (dir), (dir)

@menu
* Overview::                    Overview
* Installation::                Installation
* Classes::                     The Classes
* Caveats::                     Caveats
* References::                  References
* Copying::                     GNU LIBRARY GENERAL PUBLIC LICENSE
* Data Type Index::             Data Type Index
* Function Index::              Function and Method Index
* Concept Index::               Concept Index

 --- The Detailed Node Listing ---

The classes

* XdrInfo::                     @code{XdrInfo}
* RpcRequest::                  @code{RpcRequest}
* Callbacks::                   @code{Callbacks}
* RpcService::                  @code{RpcService}
* RpcStub::                     @code{RpcStub}

Callbacks

* RpcCallback::                 @code{RpcCallback}
* RpcMethodCall::               @code{RpcMethodCall}
* Calling Conventions::         @code{Calling Conventions}

Caveats

* Global objects::              Global objects
* Destruction rules::           Destruction rules
* Matching server and clients::  Matching server and clients
@end menu

@node    Overview, Installation, Top, Top
@comment node-name,     next,           previous, up
@chapter Overview
@cindex Overview

This document describes my C++ interface to Sun Remote Procedure Calls.
It is based on sources from Peter Bersen that I got from some newsgroup,
though I don't remember which one. I liked the basic idea but disliked
several aspects of the interface details. So I adapted it to my likes. I
intended some minor changes but soon found myself renaming classes,
changing method parameters, introducing new classes, etc. The result is
by no way compatible with the original version. It is, I hope,
nevertheless useful.

Basically, the interface defines six class: @code{XdrInfo},
@code{RpcRequest}, @code{RpcCallback}/@code{RpcMethodCall},
@code{RpcService} and @code{RpcStub}.

@code{XdrInfo} objects describe the external data representation of a
type. There are predefined @code{XdrInfo}s for the basic types.
@code{RpcRequest} objects describe the available procedure calls. They
are constructed from a unique request number, the @code{XdrInfo}s of the
procedure's arguments and its return type. @code{RpcCallback} is an
object that holds a pointer to a function and information about the
number of its arguments. @code{RpcMethodCall} is a template that in a
similar way holds a pointer to an object and one of its methods and
Information about the number of its arguments.

An @code{RpcRequest} and its matching @code{RpcCallback} or
@code{RpcMethodCall} may be registered with an @code{RpcService}.
Exactly one object of type @code{RpcService} may be instantiated in a
program that implements an RPC server. Method @code{Provide ()} is a
loop that waits for requests and dispatches them.

A client program instantiates an object of type @code{RpcStub}.  The
constructor establishes a connection to the server specified by its
arguments. Procedures of the server may be invoked using method
@code{Call (@dots{})}.

@node    Installation, Classes, Overview, Top
@comment node-name,     next,           previous, up
@chapter Installation
@cindex Installation

The rpc++ library has successfully been tested using a patched gcc-2.2.2
on a SparcStation running SunOS 4.1.[12] and a 386 system running
Interactive Unix (a SYSV 3.2). Patching gcc-2.2.2 was necessary because
the unpatched version can't handle typedefs that are local to templates.
The bug report with patches can be found in the source directory in file
@code{gcc-2.2.2.fix}.

As a prerequisite to using RPCs with C++ you need ANSI-C/C++ conformant
header files for RPC. I have provided such files in the directory
@code{StdHdrs/rpc} of the source tree. To avoid any copyright conflicts,
they are derived from the public available RPC source code rather than
from the files that come with SunOS 4.1.X. The differences are minor.
The SunOS 4.1.X files define some additional functions. You have to
either copy the files from @code{StdHdrs/rpc} or patched files from your
@code{/usr/include/rpc} to a directory where gcc can find them. If you
don't want to install them globally in gcc's include directory, you can
include them by using an additional ``@code{-I}'' flag during
compilation.

In SunOS you can simply type `@code{make install INSTROOT=@dots{}}'
which will make the library and install it in @code{INSTROOT/lib} and
the header files in @code{INSTROOT/include/rpc++}.  Other Unices will
probably have problems with the `install' command. Type only `make' and
copy the resulting @code{librpc++.a} to your local library directory and
the files @code{rpc++/*} to an @code{rpc++}-subdirectory of your local
include directory.

@node    Classes, Caveats, Installation, Top
@comment node-name,     next,           previous,	up
@chapter The classes

@menu
* XdrInfo::                     @code{XdrInfo}
* RpcRequest::                  @code{RpcRequest}
* Callbacks::                   @code{Callbacks}
* RpcService::                  @code{RpcService}
* RpcStub::                     @code{RpcStub}
@end menu

@node    XdrInfo, RpcRequest,  , Classes
@comment node-name,     next,           previous, up
@section @code{XdrInfo}
@cindex @code{XdrInfo}

Declared in: @code{"rpc++/xdr++.h"}

@deftp Class XdrInfo
Class XdrInfo describes serializers. It combines the xdrproc_t with the
size info (the size of the data to be converted) usually needed if you
want to apply a serializer.
@end deftp

There is only one constructor for @code{XdrInfo}:

@deftypefn Constructor {} XdrInfo (xdrproc_t @var{t}, size_t @var{s})
Construct an @code{XdrInfo} for a type. The type can be converted to an
external data representation (serielized) with function @var{t}. Its
size (in bytes, from @code{sizeof (type)}), is @var{s}.
@end deftypefn

The methods query the information given to the constructor:

@deftypefn Method xdrproc_t Proc () const
Return the conversion function stored in an @code{XdrInfo}.
@end deftypefn

@deftypefn Method size_t Size () const
Return the size of the type described by the @code{XdrInfo}.
@end deftypefn

There are a number of predefined @code{XdrInfo}s. They are defined as
static members of a class @code{Xdr} for scoping reasons.

@defvr XdrInfo Xdr::Xchar
The conversion and size information for a character.
@end defvr

@defvr XdrInfo Xdr::Xshort
The conversion and size information for a short integer.
@end defvr

@defvr XdrInfo Xdr::Xint
The conversion and size information for an integer.
@end defvr

@defvr XdrInfo Xdr::Xlong
The conversion and size information for a long integer.
@end defvr

@defvr XdrInfo Xdr::Xuchar
The conversion and size information for an unsigned character.
@end defvr

@defvr XdrInfo Xdr::Xushort
The conversion and size information for an unsigned short integer.
@end defvr

@defvr XdrInfo Xdr::Xulong
The conversion and size information for an unsigned long integer.
@end defvr

@defvr XdrInfo Xdr::Xfloat
The conversion and size information for a float.
@end defvr

@defvr XdrInfo Xdr::Xdouble
The conversion and size information for a double.
@end defvr

@defvr XdrInfo Xdr::Xenum_t
The conversion and size information for any enumeration type.
@end defvr

@defvr XdrInfo Xdr::Xbool_t
The conversion and size information for a bool.
@end defvr

@defvr XdrInfo Xdr::Xvoid
A special @code{XdrInfo} for the return type of a procedure that returns
nothing.
@end defvr

@defvr XdrInfo Xdr::Xnull
A special @code{XdrInfo} for the return type of a procedure that is to
be executed batched or asynchronously (@pxref{RpcRequest}).
@end defvr

@page
@node    RpcRequest, Callbacks, XdrInfo, Classes
@comment node-name,     next,           previous, up
@section @code{RpcRequest}
@cindex @code{RpcRequest}

Declared in: @code{"rpc++/request.h"}

@deftp Class RpcRequest
RpcRequest is a class that specifies a request for a procedure that is
part of (registered with) a service.
@end deftp

There are several constructors for @code{RpcRequest}. They vary in the
number of @code{XdrInfo}s used to describe the input parameters of the
procedure.

@deftypefn Constructor {} RpcRequest (u_long @var{reqid}, const XdrInfo* @var{out}, ReqType @var{t}=normal)
@end deftypefn
@deftypefn Constructor {} RpcRequest (u_long @var{reqid}, const XdrInfo* @var{out}, const XdrInfo* @var{in1}, ReqType @var{t}=normal)
@end deftypefn
@deftypefn Constructor {} RpcRequest (u_long @var{reqid}, const XdrInfo* @var{out}, const XdrInfo* @var{in1}, const XdrInfo* @var{in2}, ReqType @var{t}=normal)
These constructors construct an @code{RpcRequest} for a procedure with
zero, one or two arguments. Additional similar constructors are defined
for procedures with up to seven arguments. @var{reqid} uniquely
identifies the request (the procedure of the server). @var{reqid} may
not be 0. The @code{XdrInfo*}s following @var{reqid} specify the types of
the input parameters. They are followed by the @code{XdrInfo*} that
describes the type of the value returned by the RPC. If no value is
returned, @code{&Xdr::Xvoid} must be given as argument
(@pxref{XdrInfo}). The final optional argument @var{t} specifies the
call mode: @code{RpcRequest::normal}, @code{RpcRequest::batched} or
@code{RpcRequest::async} (see below).
@end deftypefn

@deftypefn Constructor {} RpcRequest (u_long @var{reqid}, const XdrInfo* @var{out}, const XdrInfo** @var{intypes}, ReqType @var{t}=normal)
This constructor can be used to construct an @code{RpcRequest} with an
arbitrary number of arguments. The pointers to @code{XdrInfo} are passed
in an array. The number of elements in the array must be one more than
the number of parameters and the last element must be zero.
@end deftypefn

If the request type @var{t} is @code{RpcRequest::normal}, method
@code{Call} (@pxref{RpcStub}) assembles the message to the server, sends
it, waits for a reply and returns the result.

If the request type is @code{RpcRequest::batched}, method
@code{RpcStub::Call} assembles the message to the server and puts it in
a buffer. Messages are only flushed if the buffer is full or
@code{RpcStub::Call} is used with a @code{normal} or @code{async}
request.

If the request type is @code{RpcRequest::async}, method
@code{RpcStub::Call} (@pxref{RpcStub}) assembles the message to the
server and sends it, as with @code{normal}. It does, however, not wait
for a result. Mode @code{async} is implemented by calling the underlying
RPC--function @code{clnt_call} with a timeout of zero.

As in both non--normal cases (@code{batched} and @code{async})
@code{RpcStub::Call} does not wait for a return value from the server,
the return type of the @code{RpcRequest} must be specified as
@code{&Xdr::Xnull}.

Note that requests that are registered for a service are stored in an
array using the request identification as the index, so keep ids small.

Normally, requests should be specified in a header file included by both
the server and the client program (@pxref{Matching server and clients}).

@page
@node    Callbacks, RpcService, RpcRequest, Classes
@comment node-name,     next,           previous, up
@section Callbacks
@cindex Callbacks

If a server receives a request from a client, it needs to know how a
particular procedure is to be invoked. This information is specified
using objects @code{RpcCallback} or @code{RpcMethodCall} when the
procedure resp.@ method is specified.

The class
@deftp Class AnyRpcCallback
@end deftp
serves as an abstract base class for the two kinds of callbacks.

The following sections describe the constructors for @code{RpcCallback}
and @code{RpcMethodCall} and the calling conventions for the functions
or methods called back.

@menu
* RpcCallback::                 @code{RpcCallback}
* RpcMethodCall::               @code{RpcMethodCall}
* Calling Conventions::         @code{Calling Conventions}
@end menu

@node    RpcCallback, RpcMethodCall,  , Callbacks
@comment node-name,     next,           previous, up
@subsection @code{RpcCallback}
@cindex @code{RpcCallback}

Declared in: @code{"rpc++/callback.h"}

@deftp Class RpcCallback
An @code{RpcCallback} describes a function that is to be called by the
server on request from the client.
@end deftp

@deftypefn Constructor {} RpcCallback (void* (*)() @var{proc})
@end deftypefn
@deftypefn Constructor {} RpcCallback (void* (*)(void*) @var{proc})
@end deftypefn
@deftypefn Constructor {} RpcCallback (void* (*)(void*, void*) @var{proc})
Construct an @code{RpcCallback} for a function that takes zero, one or
two arguments and returns a result. Constructors for functions with
up to seven arguments are defined.
@end deftypefn
@deftypefn Constructor {} RpcCallback (void* (*)(void**) @var{proc})
Construct an @code{RpcCallback} for a function that takes an arbitrary
number of arguments and returns a result.
@end deftypefn

@deftypefn Constructor {} RpcCallback (void (*)() @var{proc})
@end deftypefn
@deftypefn Constructor {} RpcCallback (void (*)(void*) @var{proc})
@end deftypefn
@deftypefn Constructor {} RpcCallback (void (*)(void*, void*) @var{proc})
Construct an @code{RpcCallback} for a function that takes zero, one or
two arguments and returns no result. Constructors for functions with
up to seven arguments are defined.
@end deftypefn
@deftypefn Constructor {} RpcCallback (void (*)(void**) @var{proc})
Construct an @code{RpcCallback} for a function that takes an arbitrary
number of arguments and return no result.
@end deftypefn

@deftypefn Constructor {} RpcCallback (void* (*)(RpcService*) @var{proc})
@end deftypefn
@deftypefn Constructor {} RpcCallback (void* (*)(void*, RpcService*) @var{proc})
@end deftypefn
@deftypefn Constructor {} RpcCallback (void* (*)(void*, void*, RpcService*) @var{proc})
Construct an @code{RpcCallback} for a function that takes zero, one or
two arguments and returns a result. Constructors for functions with
up to seven arguments are defined. Upon invocation, a pointer to the
object of type @code{RpcService} that received the request and called
the function is passed as an additional argument.
@end deftypefn
@deftypefn Constructor {} RpcCallback (void* (*)(void**) @var{proc})
Construct an @code{RpcCallback} for a function that takes an arbitrary
number of arguments and returns a result. Upon invocation, a pointer to the
object of type @code{RpcService} that received the request and called
the function is passed as an additional argument.
@end deftypefn

@deftypefn Constructor {} RpcCallback (void (*)(RpcService*) @var{proc})
@end deftypefn
@deftypefn Constructor {} RpcCallback (void (*)(void*, RpcService*) @var{proc})
@end deftypefn
@deftypefn Constructor {} RpcCallback (void (*)(void*, void*, RpcService*) @var{proc})
Construct an @code{RpcCallback} for a function that takes zero, one or
two arguments and returns a result. Constructors for functions with
up to seven arguments are defined. Upon invocation, a pointer to the
object of type @code{RpcService} that received the request and called
the function is passed as an additional argument.
@end deftypefn
@deftypefn Constructor {} RpcCallback (void (*)(void**) @var{proc})
Construct an @code{RpcCallback} for a function that takes an arbitrary
number of arguments and returns a result. Upon invocation, a pointer to the
object of type @code{RpcService} that received the request and called
the function is passed as an additional argument.
@end deftypefn

@node    RpcMethodCall, Calling Conventions, RpcCallback, Callbacks
@comment node-name,     next,           previous, up
@subsection @code{RpcMethodCall}
@cindex @code{RpcMethodCall}

Declared in: @code{"rpc++/callback.h"}

@deftp Class RpcMethodCall
An @code{RpcMethodCall} describes a method of an object that is to be
called by the server on request from the client.
@end deftp

@deftypefn Constructor {} RpcMethodCall <class T> (void* (T::*)() @var{proc})
@end deftypefn
@deftypefn Constructor {} RpcMethodCall <class T> (void* (T::*)(void*) @var{proc})
@end deftypefn
@deftypefn Constructor {} RpcMethodCall <class T> (void* (T::*)(void*, void*) @var{proc})
Construct an @code{RpcMethodCall} for an object and one of its methods that
takes zero, one or two arguments and returns a result. Constructors for
methods with up to seven arguments are defined.
@end deftypefn
@deftypefn Constructor {} RpcMethodCall <class T> (void* (T::*)(void**) @var{proc})
Construct an @code{RpcMethodCall} for an object and one of its methods
that takes an arbitrary number of arguments and returns a result.
@end deftypefn

@deftypefn Constructor {} RpcMethodCall <class T> (void (T::*)() @var{proc})
@end deftypefn
@deftypefn Constructor {} RpcMethodCall <class T> (void (T::*)(void*) @var{proc})
@end deftypefn
@deftypefn Constructor {} RpcMethodCall <class T> (void (T::*)(void*, void*) @var{proc})
Construct an @code{RpcMethodCall} for an object and one of its methods
that takes zero, one or two arguments and returns no result.
Constructors for methods with up to seven arguments are defined.
@end deftypefn
@deftypefn Constructor {} RpcMethodCall <class T> (void (T::*)(void**) @var{proc})
Construct an @code{RpcMethodCall} for an object and one of its methods
that takes an arbitrary number of arguments and return no result.
@end deftypefn

@deftypefn Constructor {} RpcMethodCall <class T> (void* (T::*)(RpcService*) @var{proc})
@end deftypefn
@deftypefn Constructor {} RpcMethodCall <class T> (void* (T::*)(void*, RpcService*) @var{proc})
@end deftypefn
@deftypefn Constructor {} RpcMethodCall <class T> (void* (T::*)(void*, void*, RpcService*) @var{proc})
Construct an @code{RpcMethodCall} for an object and one of its methods
that takes zero, one or two arguments and returns a result. Constructors
for methods with up to seven arguments are defined. Upon invocation, a
pointer to the object of type @code{RpcService} that received the
request and called the method is passed as an additional argument.
@end deftypefn
@deftypefn Constructor {} RpcMethodCall <class T> (void* (T::*)(void**) @var{proc})
Construct an @code{RpcMethodCall} for an object and one of its methods
that takes an arbitrary number of arguments and returns a result. Upon
invocation, a pointer to the object of type @code{RpcService} that
received the request and called the method is passed as an additional
argument.
@end deftypefn

@deftypefn Constructor {} RpcMethodCall <class T> (void (T::*)(RpcService*) @var{proc})
@end deftypefn
@deftypefn Constructor {} RpcMethodCall <class T> (void (T::*)(void*, RpcService*) @var{proc})
@end deftypefn
@deftypefn Constructor {} RpcMethodCall <class T> (void (T::*)(void*, void*, RpcService*) @var{proc})
Construct an @code{RpcMethodCall} for an object and one of its methods
that takes zero, one or two arguments and returns a result. Constructors
for methods with up to seven arguments are defined. Upon invocation, a
pointer to the object of type @code{RpcService} that received the
request and called the method is passed as an additional argument.
@end deftypefn
@deftypefn Constructor {} RpcMethodCall <class T> (void (T::*)(void**) @var{proc})
Construct an @code{RpcMethodCall} for an object and one of its methods
that takes an arbitrary number of arguments and returns a result. Upon
invocation, a pointer to the object of type @code{RpcService} that
received the request and called the method is passed as an additional
argument.
@end deftypefn

@node    Calling Conventions,  , RpcMethodCall, Callbacks
@comment node-name,     next,           previous, up
@subsection @code{Calling Conventions}
@cindex @code{calling conventions}

As could be seen from the parameter types in the constructors, functions
and methods that are called in response to a request from a client know
only about pointers to void as arguments and result values because their
real type is coded in the @code{RpcRequest} and not known at compile
time. The only way to avoid this is to implement some kind of rpcgen++.
However, I never liked this kind of tools and I'm willing to risk a bit
of type unsafeness in this case.

When a procedure (or method) is called, its arguments point to values
(the variants with an arbitrary number of arguments receive an array of
pointers to values) of the types specified in the constructor of the
@code{RpcRequest} that led to the invocation of the procedure. I
recommend to access the values and assign them to local variables of the
procedure in the first statements. E.g.:
@example
void* Add (void* s1p, void* s2p)
@{
  int s1 = *(int*)s1p;
  int s2 = *(int*)s2p;
  ...
@end example

The return value of the procedure is a pointer to the result. Therefore,
results may never be put in automatic variables. They must be global or
static. E.g.:
@example
  ...
  static int sum;
  sum = s1 + s2;
  return (void*)&sum;
@}
@end example

Note the special case of strings (defined as parameters or return values
using @code{Xdr::Xwrapstring}, @pxref{XdrInfo}). If you think of a
string as being defined as a type ``@code{typedef char* string}'', it is
obvious that a string is passed as argument or returned as result by a
@code{string*}, i.e., a @code{char**}. E.g.:
@example
void* Capitalize (void* strp)
@{
  static char* str;
  str = *(char**)strp;
  str[0] = toupper (str[0]);
  return (void*)&str;
@}
@end example

@page
@node    RpcService, RpcStub, Callbacks, Classes
@comment node-name,     next,           previous, up
@section @code{RpcService}
@cindex @code{RpcService}

Declared in: @code{"rpc++/service.h"}

@deftp Class RpcService
An object of type @code{RpcService} provides the server capabilities
within a program.
@end deftp

There are two constructors for @code{RpcService}:

@deftypefn Constructor {} RpcService (u_long @var{prog}, u_long @var{vers})
Construct an object representing the @var{vers}'th version of program
(service) number @code{prog}.
@end deftypefn
@deftypefn Constructor {} RpcService (u_long @var{vers})
Construct an object representing the @var{vers}'th version of a transient
program (service).
@end deftypefn

@deftypefn Method bool OK ()
Returns TRUE if the service is ready for operation, i.e., has successfully
been established during construction.
@end deftypefn

The number of a service, especially a transient service, can be obtained
with method @code{@w{Program ()}}:

@deftypefn Method u_long Program ()
Returns the number of the program (service). This is either the number
passed as an argument to the constructor or a number from the transient
program area.
@end deftypefn

The next step after the construction of an @code{RpcService} is to
register the requests handled by the service:

@deftypefn Method {virtual void} Register (const RpcRequest& @var{req}, const AnyRpcCallback& @var{cb})
Associate request @var{req} with the procedure or object/method pair
specified by @code{cb}. The usual way to call @code{Register} is
@example
@{
  RpcService svc (...);
  svc.register (addreq, RpcCallback (Add));
  ...
@}
@end example
@end deftypefn

After all requests have been registered, the object of type
@code{RpcService} can provide the service:
@deftypefn Method void Provide ()
Repeatedly wait for a request and handle it by calling the procedure or
method registered for it.
@end deftypefn

@deftypefn Method {virtual void*} HandleError ()
@code{HandleError} is a protected method that is called when an error
occurs. The cause of the error is stored in a protected member variable
@code{errorState}. If the default error handling (shown below) is not
appropriate for your application, derive your own class from
@code{RpcService} that implements a different error handling policy. If
you consider an error recoverable, reset @code{errorState} to
@code{RpcService::noError} in your error handler. Else, @code{OK ()}
keeps returning FALSE.
@example
void RpcService::HandleError ()
@{
  switch (errorState)
    @{
    case reconstructionAttempt:
      cerr << "rpc++: Attempt to construct another instance of RpcService.\n";
      exit (1);
    case cantCreateTCPService:
      cerr << "rpc++: can't create tcp service.\n";
      exit(1);
    case cantRegisterService:
      cerr << form ("rpc++: can't register (%d, %d, tcp).", prog, vers);
      exit(1);
    case cantSendReply:
      cerr << "rpc++: can't reply to RPC call.\n";
      break;
    case invalidResult:
      cerr << "rpc++: registered routine has return NULL pointer.\n";
      abort ();
    case notRegistered:
      cerr << "rpc++: requested RPC routine not registered.\n";
      break;
    case cantGetArgs:
      cerr << "rpc++: can't get procedure arguments.\n";
      break;
    case cantFreeArgs:
      cerr << "rpc++: can't free XDR arguments.\n";
      break;
    @}
  errorState = noError;
@}
@end example
@end deftypefn

If the program that provides the service has other things to do as well,
i.e., does not only handle requests, it usually has its own main loop
that handles events. This loop must be extended to handle RPC events,
i.e., if anything happens on the RPC file descriptors, it must call
@code{svc_getreqset} just as @code{Provide ()} does.
@example
void RpcService::Provide ()
@{
  int dtbsz = getdtablesize();
  fd_set readfds;

  for(;;)
    @{
      readfds = svc_fdset;
      switch(select (dtbsz, &readfds, 0, 0, 0))
        @{
        case -1:
          if (errno != EBADF)
            continue;
          cerr << "PRC++: select: " << sys_errlist[errno] << '\n';
          return;
          break;
        case 0:
          continue;
        default:
          svc_getreqset (&readfds);
          break;
        @}
    @}
@}
@end example

The following methods are only available during the execution of a
callback, i.e., they can be applied to @code{RpcService} if a pointer to
the invoking object has been declared as last parameter of a callback
routine.

@deftypefn Method {struct sockaddr_in*} Caller ()
Return the socket address information of the calling host.
@end deftypefn

@deftypefn Method char* CallerName ()
Return the name of the calling host.
@end deftypefn

@deftypefn Method void Reply ()
@end deftypefn
@deftypefn Method void Reply (void* @var{res})
Normally, a request to the server terminates when the callback completes
(either with or without returning a value, depending on the return
type). In some cases it is desirable to reply to the client before all
the actions related to the request have been completed. This allows the
client to resume execution. The result (if any) must of course not
depend on the functions still to be executed.
@end deftypefn

@deftypefn Method void Interrupt ()
This is the proper way to terminate the loop entered by calling
@code{Provide()}. After return from the callback that invoked
@code{Interrupt()} method @code{Provide()} will return.
@end deftypefn

@page
@node    RpcStub,  , RpcService, Classes
@comment node-name,     next,           previous, up
@section @code{RpcStub}
@cindex @code{RpcStub}

Declared in: @code{"rpc++/stub.h"}

@deftp Class RpcStub
An @code{RpcStub} represents the client side of a connection.
@end deftp

There are two constructors for @code{RpcStub} that vary in the position
of their arguments only:

@deftypefn Constructor {} RpcStub (u_long @code{prognum}, u_long @code{versnum}, char* @var{hostname}="localhost", timeval @var{timeout}=defaultTimeout, bool @var{connect}=TRUE)
@end deftypefn
@deftypefn Constructor {} RpcStub (u_long @code{prognum}, u_long @code{versnum}, char* @var{hostname}="localhost", bool @var{connect}=TRUE, timeval @var{timeout}=defaultTimeout)
Construct an @code{RpcStub} that connects to the @var{versnum}'th
version of program (service) @var{prognum} on host @var{hostname}. The
timeout for successful completion of communication operations is
@var{timeout} which defaults to 25 seconds. Unless @var{connect} is
false, the constructor makes a connection attempt.
@end deftypefn

There are various methods:

@deftypefn Method void Reconnect ()
Connect to the server. Usually this method is called if the connection
was not to be established by the constructor or if the connection
attempt failed and is to be repeated.
@end deftypefn

@deftypefn Method bool OK ()
Returns TRUE if the stub is ready for operation, i.e., connected to a
server.
@end deftypefn

@deftypefn Method CLIENT* Service ()
Access to the standard RPC level. Returns the handle that identifies the
server.
@end deftypefn

@deftypefn Method timeval GetTimeout () const
Returns the default timeout for network operations.
@end deftypefn

@deftypefn Method void SetTimeout (timeval& @var{timo})
Sets the default timeout for network operations
@end deftypefn

@deftypefn Method void* Call (RpcRequest& @var{req}, bool @var{handle_errors}=TRUE)
@end deftypefn
@deftypefn Method void* Call (RpcRequest& @var{req}, void* @var{in1}, bool @var{handle_errors}=TRUE)
@end deftypefn
@deftypefn Method void* Call (RpcRequest& @var{req}, void* @var{in1}, @var{in2} bool @var{handle_errors}=TRUE)
Request the operation specified by @var{req} from the server, passing
zero, one or two arguments. There are declarations of this method for up
two seven arguments. Arguments are passed as pointers to the argument
values. The value returned by @code{Call} is a pointer to the result
returned by the server. The result is valid until @code{Call} is called
again. If @var{handle_errors} is FALSE and an error occurs, @code{Call}
simply returns 0. Else, it calls method @code{HandleError} (see below).
@end deftypefn
@deftypefn Method void* Call (RpcRequest& @var{req}, void** @var{invals}, bool @var{handle_errors}=TRUE)
The variant of @code{Call} that handles an arbitrary number of
arguments.  Pointers to the arguments are passed in an array in
parameter @var{invals}. The size of the array must match the number of
arguments given to the constructor of @var{req}.
@end deftypefn

@deftypefn Method {virtual void*} HandleError ()
@code{HandleError} is a protected method that is called when an error
occurs. The cause of the error is stored in a protected member variable
@code{errorState}. If the default error handling policy (shown below) is
not appropriate for your application, derive your own class from
@code{RpcStub} that implements a different one. If you consider an error
recoverable, reset @code{errorState} to @code{RpcStub::noError} in your
error handler. Else, @code{OK ()} keeps returning FALSE.  If an error
occurs during a @code{Call} and parameter @var{handle_errors} is TRUE,
@code{Call} invokes @code{HandleError} and returns its result as result
of the call.
@example
void* RpcStub::HandleError ()
@{
  switch (errorState)
    @{
    case notConnected:
      cerr << "rpc++: Stub has not been connected to server.\n";
    case cantCreate:
      cerr << clnt_spcreateerror ("rpc++") << '\n';
      break;
    case cantCall:
      cerr << clnt_sperror (svc, "rpc++") << '\n';
      exit (1);
    @}
  return 0;
@}
@end example
@end deftypefn

While no or little improvement of coding quality can be gained from
deriving a service specific class from @code{RpcService}, the opposite
is true for @code{RpcStub}.  A service specific derivation may define
methods that have the ``real'' argument lists instead of pointers to
void. These methods are simply implemented by casting the arguments and
(inline) calling one of the @code{Call}--methods. Apart from better
type checking, this has the advantage of keeping details like the
available @code{RpcRequest}s local to the definition of the derived
class (see the example in the @code{example}--directory).

@node Caveats, References, Classes, Top
@comment  node-name,  next,  previous,  up
@chapter Caveats
@cindex Caveats

@menu
* Global objects::              Global objects
* Destruction rules::           Destruction rules
* Matching server and clients::  Matching server and clients
@end menu

@node Global objects, Destruction rules,  , Caveats
@comment  node-name,  next,  previous,  up
@section Global objects
@cindex Global objects

As a general C++ rule, be careful with global objects. The sequence of
constructor invocations for global objects is not defined. This is the
reason, why @code{RpcRequests} are constructed from pointers to
@code{XdrInfo}s rather than from @code{XdrInfo}s.

Both @code{XdrInfo}s and @code{RpcRequest}s tend to be instantiated as
global objects or static member variables. If the constructor of
@code{RpcRequest} received @code{XdrInfo}s instead of pointers and
copied the information contained in the @code{XdrInfo} (the solution I
had preferred), it may happen that the @code{XdrInfo} has not been
constructed yet and thus contains invalid data.

The same problem occurs if you want to define a global
``alias--@code{XdrInfo}'' matching a ``@code{typedef int myint}''.
Don't use @code{XdrInfo Xmyint (Xdr::Xint)} as this may copy the
uninitialized @code{Xdr::Xint}. Use @code{XdrInfo& Xmyint = Xdr::Xint}
instead.

@node Destruction rules, Matching server and clients, Global objects, Caveats
@comment  node-name,  next,  previous,  up
@section Destruction rules
@cindex Destruction rules

Objects of type @code{XdrInfo} are resources that can be used more than
once, i.e., in different @code{RpcRequest}s. If they were handled
properly, references to @code{XdrInfo} would be counted and the
@code{XdrInfo} destructed automatically if the last reference is
removed (unless it is the @code{XdrInfo} of a predefined type).

Such a resource management for @code{XdrInfo}s has been considered
unnecessary as @code{XdrInfo}s will rarely be dynamic objects. If the
user allocates an @code{XdrInfo} on the stack or the heap, it is his
responsibility to assure that the object is valid until the last
@code{RpcResource} that uses it has been destructed.

@node Matching server and clients,  , Destruction rules, Caveats
@comment  node-name,  next,  previous,  up
@section Matching server and clients

In order to make sure that the server and the clients agree about the
protocol, all @code{RpcRequest}s for a service should be declared in a
header file and instantiated in a corresponding source file. The header
file and the compiled source file make the ``library'' that provides the
service. Thus a server consists of three files: the server executable, a
header file defining the service that is to be included in client
sources and an object file which must be linked to the client
executable.

@c ======================================================================

@node References, Copying, Caveats, Top
@comment  node-name,  next,  previous,  up
@unnumbered References

Margaret A. Ellis, @cite{The Annotated C++ Reference Manual},
Addison-Wesley, 1990.

Stanley B. Lippmann, @cite{A C++ Primer}, Addison-Wesley, 1989.

Bjarne Stroustrup, @cite{The C++ Programming Language}, Addison-Wesley,
1986.

Sun Microsystems, @cite{Network Programming}, March 1990.

@c ======================================================================

@node Copying, Data Type Index, References, Top
@appendix GNU LIBRARY GENERAL PUBLIC LICENSE
@center Version 2, June 1991

@display
Copyright @copyright{} 1991 Free Software Foundation, Inc.
675 Mass Ave, Cambridge, MA 02139, USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
@end display

@unnumberedsec Preamble

  The licenses for most software are designed to take away your
freedom to share and change it.  By contrast, the GNU General Public
Licenses are intended to guarantee your freedom to share and change
free software---to make sure the software is free for all its users.

  This license, the Library General Public License, applies to some
specially designated Free Software Foundation software, and to any
other libraries whose authors decide to use it.  You can use it for
your libraries, too.

  When we speak of free software, we are referring to freedom, not
price.  Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
this service if you wish), that you receive source code or can get it
if you want it, that you can change the software or use pieces of it
in new free programs; and that you know you can do these things.

  To protect your rights, we need to make restrictions that forbid
anyone to deny you these rights or to ask you to surrender the rights.
These restrictions translate to certain responsibilities for you if
you distribute copies of the library, or if you modify it.

  For example, if you distribute copies of the library, whether gratis
or for a fee, you must give the recipients all the rights that we gave
you.  You must make sure that they, too, receive or can get the source
code.  If you link a program with the library, you must provide
complete object files to the recipients so that they can relink them
with the library, after making changes to the library and recompiling
it.  And you must show them these terms so they know their rights.

  Our method of protecting your rights has two steps: (1) copyright
the library, and (2) offer you this license which gives you legal
permission to copy, distribute and/or modify the library.

  Also, for each distributor's protection, we want to make certain
that everyone understands that there is no warranty for this free
library.  If the library is modified by someone else and passed on, we
want its recipients to know that what they have is not the original
version, so that any problems introduced by others will not reflect on
the original authors' reputations.

  Finally, any free program is threatened constantly by software
patents.  We wish to avoid the danger that companies distributing free
software will individually obtain patent licenses, thus in effect
transforming the program into proprietary software.  To prevent this,
we have made it clear that any patent must be licensed for everyone's
free use or not licensed at all.

  Most GNU software, including some libraries, is covered by the ordinary
GNU General Public License, which was designed for utility programs.  This
license, the GNU Library General Public License, applies to certain
designated libraries.  This license is quite different from the ordinary
one; be sure to read it in full, and don't assume that anything in it is
the same as in the ordinary license.

  The reason we have a separate public license for some libraries is that
they blur the distinction we usually make between modifying or adding to a
program and simply using it.  Linking a program with a library, without
changing the library, is in some sense simply using the library, and is
analogous to running a utility program or application program.  However, in
a textual and legal sense, the linked executable is a combined work, a
derivative of the original library, and the ordinary General Public License
treats it as such.

  Because of this blurred distinction, using the ordinary General
Public License for libraries did not effectively promote software
sharing, because most developers did not use the libraries.  We
concluded that weaker conditions might promote sharing better.

  However, unrestricted linking of non-free programs would deprive the
users of those programs of all benefit from the free status of the
libraries themselves.  This Library General Public License is intended to
permit developers of non-free programs to use free libraries, while
preserving your freedom as a user of such programs to change the free
libraries that are incorporated in them.  (We have not seen how to achieve
this as regards changes in header files, but we have achieved it as regards
changes in the actual functions of the Library.)  The hope is that this
will lead to faster development of free libraries.

  The precise terms and conditions for copying, distribution and
modification follow.  Pay close attention to the difference between a
``work based on the library'' and a ``work that uses the library''.  The
former contains code derived from the library, while the latter only
works together with the library.

  Note that it is possible for a library to be covered by the ordinary
General Public License rather than by this special one.

@iftex
@unnumberedsec TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
@end iftex
@ifinfo
@center TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
@end ifinfo

@enumerate
@item
This License Agreement applies to any software library which
contains a notice placed by the copyright holder or other authorized
party saying it may be distributed under the terms of this Library
General Public License (also called ``this License'').  Each licensee is
addressed as ``you''.

  A ``library'' means a collection of software functions and/or data
prepared so as to be conveniently linked with application programs
(which use some of those functions and data) to form executables.

  The ``Library'', below, refers to any such software library or work
which has been distributed under these terms.  A ``work based on the
Library'' means either the Library or any derivative work under
copyright law: that is to say, a work containing the Library or a
portion of it, either verbatim or with modifications and/or translated
straightforwardly into another language.  (Hereinafter, translation is
included without limitation in the term ``modification''.)

  ``Source code'' for a work means the preferred form of the work for
making modifications to it.  For a library, complete source code means
all the source code for all modules it contains, plus any associated
interface definition files, plus the scripts used to control compilation
and installation of the library.

  Activities other than copying, distribution and modification are not
covered by this License; they are outside its scope.  The act of
running a program using the Library is not restricted, and output from
such a program is covered only if its contents constitute a work based
on the Library (independent of the use of the Library in a tool for
writing it).  Whether that is true depends on what the Library does
and what the program that uses the Library does.

@item
You may copy and distribute verbatim copies of the Library's
complete source code as you receive it, in any medium, provided that
you conspicuously and appropriately publish on each copy an
appropriate copyright notice and disclaimer of warranty; keep intact
all the notices that refer to this License and to the absence of any
warranty; and distribute a copy of this License along with the
Library.

  You may charge a fee for the physical act of transferring a copy,
and you may at your option offer warranty protection in exchange for a
fee.

@item
You may modify your copy or copies of the Library or any portion
of it, thus forming a work based on the Library, and copy and
distribute such modifications or work under the terms of Section 1
above, provided that you also meet all of these conditions:

@enumerate
@item
The modified work must itself be a software library.

@item
You must cause the files modified to carry prominent notices
stating that you changed the files and the date of any change.

@item
You must cause the whole of the work to be licensed at no
charge to all third parties under the terms of this License.

@item
If a facility in the modified Library refers to a function or a
table of data to be supplied by an application program that uses
the facility, other than as an argument passed when the facility
is invoked, then you must make a good faith effort to ensure that,
in the event an application does not supply such function or
table, the facility still operates, and performs whatever part of
its purpose remains meaningful.

(For example, a function in a library to compute square roots has
a purpose that is entirely well-defined independent of the
application.  Therefore, Subsection 2d requires that any
application-supplied function or table used by this function must
be optional: if the application does not supply it, the square
root function must still compute square roots.)
@end enumerate

These requirements apply to the modified work as a whole.  If
identifiable sections of that work are not derived from the Library,
and can be reasonably considered independent and separate works in
themselves, then this License, and its terms, do not apply to those
sections when you distribute them as separate works.  But when you
distribute the same sections as part of a whole which is a work based
on the Library, the distribution of the whole must be on the terms of
this License, whose permissions for other licensees extend to the
entire whole, and thus to each and every part regardless of who wrote
it.

Thus, it is not the intent of this section to claim rights or contest
your rights to work written entirely by you; rather, the intent is to
exercise the right to control the distribution of derivative or
collective works based on the Library.

In addition, mere aggregation of another work not based on the Library
with the Library (or with a work based on the Library) on a volume of
a storage or distribution medium does not bring the other work under
the scope of this License.

@item
You may opt to apply the terms of the ordinary GNU General Public
License instead of this License to a given copy of the Library.  To do
this, you must alter all the notices that refer to this License, so
that they refer to the ordinary GNU General Public License, version 2,
instead of to this License.  (If a newer version than version 2 of the
ordinary GNU General Public License has appeared, then you can specify
that version instead if you wish.)  Do not make any other change in
these notices.

  Once this change is made in a given copy, it is irreversible for
that copy, so the ordinary GNU General Public License applies to all
subsequent copies and derivative works made from that copy.

  This option is useful when you wish to copy part of the code of
the Library into a program that is not a library.

@item
You may copy and distribute the Library (or a portion or
derivative of it, under Section 2) in object code or executable form
under the terms of Sections 1 and 2 above provided that you accompany
it with the complete corresponding machine-readable source code, which
must be distributed under the terms of Sections 1 and 2 above on a
medium customarily used for software interchange.

  If distribution of object code is made by offering access to copy
from a designated place, then offering equivalent access to copy the
source code from the same place satisfies the requirement to
distribute the source code, even though third parties are not
compelled to copy the source along with the object code.

@item
A program that contains no derivative of any portion of the
Library, but is designed to work with the Library by being compiled or
linked with it, is called a ``work that uses the Library''.  Such a
work, in isolation, is not a derivative work of the Library, and
therefore falls outside the scope of this License.

  However, linking a ``work that uses the Library'' with the Library
creates an executable that is a derivative of the Library (because it
contains portions of the Library), rather than a ``work that uses the
library''.  The executable is therefore covered by this License.
Section 6 states terms for distribution of such executables.

  When a ``work that uses the Library'' uses material from a header file
that is part of the Library, the object code for the work may be a
derivative work of the Library even though the source code is not.
Whether this is true is especially significant if the work can be
linked without the Library, or if the work is itself a library.  The
threshold for this to be true is not precisely defined by law.

  If such an object file uses only numerical parameters, data
structure layouts and accessors, and small macros and small inline
functions (ten lines or less in length), then the use of the object
file is unrestricted, regardless of whether it is legally a derivative
work.  (Executables containing this object code plus portions of the
Library will still fall under Section 6.)

  Otherwise, if the work is a derivative of the Library, you may
distribute the object code for the work under the terms of Section 6.
Any executables containing that work also fall under Section 6,
whether or not they are linked directly with the Library itself.

@item
As an exception to the Sections above, you may also compile or
link a ``work that uses the Library'' with the Library to produce a
work containing portions of the Library, and distribute that work
under terms of your choice, provided that the terms permit
modification of the work for the customer's own use and reverse
engineering for debugging such modifications.

  You must give prominent notice with each copy of the work that the
Library is used in it and that the Library and its use are covered by
this License.  You must supply a copy of this License.  If the work
during execution displays copyright notices, you must include the
copyright notice for the Library among them, as well as a reference
directing the user to the copy of this License.  Also, you must do one
of these things:

@enumerate
@item
Accompany the work with the complete corresponding
machine-readable source code for the Library including whatever
changes were used in the work (which must be distributed under
Sections 1 and 2 above); and, if the work is an executable linked
with the Library, with the complete machine-readable ``work that
uses the Library'', as object code and/or source code, so that the
user can modify the Library and then relink to produce a modified
executable containing the modified Library.  (It is understood
that the user who changes the contents of definitions files in the
Library will not necessarily be able to recompile the application
to use the modified definitions.)

@item
Accompany the work with a written offer, valid for at
least three years, to give the same user the materials
specified in Subsection 6a, above, for a charge no more
than the cost of performing this distribution.

@item
If distribution of the work is made by offering access to copy
from a designated place, offer equivalent access to copy the above
specified materials from the same place.

@item
Verify that the user has already received a copy of these
materials or that you have already sent this user a copy.
@end enumerate

  For an executable, the required form of the ``work that uses the
Library'' must include any data and utility programs needed for
reproducing the executable from it.  However, as a special exception,
the source code distributed need not include anything that is normally
distributed (in either source or binary form) with the major
components (compiler, kernel, and so on) of the operating system on
which the executable runs, unless that component itself accompanies
the executable.

  It may happen that this requirement contradicts the license
restrictions of other proprietary libraries that do not normally
accompany the operating system.  Such a contradiction means you cannot
use both them and the Library together in an executable that you
distribute.

@item
You may place library facilities that are a work based on the
Library side-by-side in a single library together with other library
facilities not covered by this License, and distribute such a combined
library, provided that the separate distribution of the work based on
the Library and of the other library facilities is otherwise
permitted, and provided that you do these two things:

@enumerate
@item
Accompany the combined library with a copy of the same work
based on the Library, uncombined with any other library
facilities.  This must be distributed under the terms of the
Sections above.

@item
Give prominent notice with the combined library of the fact
that part of it is a work based on the Library, and explaining
where to find the accompanying uncombined form of the same work.
@end enumerate

@item
You may not copy, modify, sublicense, link with, or distribute
the Library except as expressly provided under this License.  Any
attempt otherwise to copy, modify, sublicense, link with, or
distribute the Library is void, and will automatically terminate your
rights under this License.  However, parties who have received copies,
or rights, from you under this License will not have their licenses
terminated so long as such parties remain in full compliance.

@item
You are not required to accept this License, since you have not
signed it.  However, nothing else grants you permission to modify or
distribute the Library or its derivative works.  These actions are
prohibited by law if you do not accept this License.  Therefore, by
modifying or distributing the Library (or any work based on the
Library), you indicate your acceptance of this License to do so, and
all its terms and conditions for copying, distributing or modifying
the Library or works based on it.

@item
Each time you redistribute the Library (or any work based on the
Library), the recipient automatically receives a license from the
original licensor to copy, distribute, link with or modify the Library
subject to these terms and conditions.  You may not impose any further
restrictions on the recipients' exercise of the rights granted herein.
You are not responsible for enforcing compliance by third parties to
this License.

@item
If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues),
conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License.  If you cannot
distribute so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you
may not distribute the Library at all.  For example, if a patent
license would not permit royalty-free redistribution of the Library by
all those who receive copies directly or indirectly through you, then
the only way you could satisfy both it and this License would be to
refrain entirely from distribution of the Library.

If any portion of this section is held invalid or unenforceable under any
particular circumstance, the balance of the section is intended to apply,
and the section as a whole is intended to apply in other circumstances.

It is not the purpose of this section to induce you to infringe any
patents or other property right claims or to contest validity of any
such claims; this section has the sole purpose of protecting the
integrity of the free software distribution system which is
implemented by public license practices.  Many people have made
generous contributions to the wide range of software distributed
through that system in reliance on consistent application of that
system; it is up to the author/donor to decide if he or she is willing
to distribute software through any other system and a licensee cannot
impose that choice.

This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License.

@item
If the distribution and/or use of the Library is restricted in
certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Library under this License may add
an explicit geographical distribution limitation excluding those countries,
so that distribution is permitted only in or among countries not thus
excluded.  In such case, this License incorporates the limitation as if
written in the body of this License.

@item
The Free Software Foundation may publish revised and/or new
versions of the Library General Public License from time to time.
Such new versions will be similar in spirit to the present version,
but may differ in detail to address new problems or concerns.

Each version is given a distinguishing version number.  If the Library
specifies a version number of this License which applies to it and
``any later version'', you have the option of following the terms and
conditions either of that version or of any later version published by
the Free Software Foundation.  If the Library does not specify a
license version number, you may choose any version ever published by
the Free Software Foundation.

@item
If you wish to incorporate parts of the Library into other free
programs whose distribution conditions are incompatible with these,
write to the author to ask for permission.  For software which is
copyrighted by the Free Software Foundation, write to the Free
Software Foundation; we sometimes make exceptions for this.  Our
decision will be guided by the two goals of preserving the free status
of all derivatives of our free software and of promoting the sharing
and reuse of software generally.

@iftex
@heading NO WARRANTY
@end iftex
@ifinfo
@center NO WARRANTY
@end ifinfo

@item
BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
OTHER PARTIES PROVIDE THE LIBRARY ``AS IS'' WITHOUT WARRANTY OF ANY
KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE.  THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
LIBRARY IS WITH YOU.  SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME
THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.

@item
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU
FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR
CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
DAMAGES.
@end enumerate

@iftex
@heading END OF TERMS AND CONDITIONS
@end iftex
@ifinfo
@center END OF TERMS AND CONDITIONS
@end ifinfo

@page
@unnumberedsec How to Apply These Terms to Your New Libraries

  If you develop a new library, and you want it to be of the greatest
possible use to the public, we recommend making it free software that
everyone can redistribute and change.  You can do so by permitting
redistribution under these terms (or, alternatively, under the terms of the
ordinary General Public License).

  To apply these terms, attach the following notices to the library.  It is
safest to attach them to the start of each source file to most effectively
convey the exclusion of warranty; and each file should have at least the
``copyright'' line and a pointer to where the full notice is found.

@smallexample
@var{one line to give the library's name and a brief idea of what it does.}
Copyright (C) @var{year}  @var{name of author}

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Library General Public License for more details.

You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
@end smallexample

Also add information on how to contact you by electronic and paper mail.

You should also get your employer (if you work as a programmer) or your
school, if any, to sign a ``copyright disclaimer'' for the library, if
necessary.  Here is a sample; alter the names:

@example
Yoyodyne, Inc., hereby disclaims all copyright interest in the
library `Frob' (a library for tweaking knobs) written by James Random Hacker.

@var{signature of Ty Coon}, 1 April 1990
Ty Coon, President of Vice
@end example

That's all there is to it!

@c ========================================================================

@page
@node    Data Type Index, Function Index, Copying, Top
@comment node-name,     next, previous,		up
@unnumbered Data Type Index

@printindex tp

@node  Function Index, Concept Index, Data Type Index, Top
@comment  node-name,  next,  previous,  up
@unnumbered Function and Method Index

@printindex fn

@node    Concept Index,  , Function Index, Top
@comment node-name,     next, previous,      up
@unnumbered Concept Index

@printindex cp

@contents
@bye