| 1 |
.\" -*- mode: troff; coding: utf-8 -*- |
| 2 |
.\" Automatically generated by Pod::Man 5.0102 (Pod::Simple 3.45) |
| 3 |
.\" |
| 4 |
.\" Standard preamble: |
| 5 |
.\" ======================================================================== |
| 6 |
.de Sp \" Vertical space (when we can't use .PP) |
| 7 |
.if t .sp .5v |
| 8 |
.if n .sp |
| 9 |
.. |
| 10 |
.de Vb \" Begin verbatim text |
| 11 |
.ft CW |
| 12 |
.nf |
| 13 |
.ne \\$1 |
| 14 |
.. |
| 15 |
.de Ve \" End verbatim text |
| 16 |
.ft R |
| 17 |
.fi |
| 18 |
.. |
| 19 |
.\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>. |
| 20 |
.ie n \{\ |
| 21 |
. ds C` "" |
| 22 |
. ds C' "" |
| 23 |
'br\} |
| 24 |
.el\{\ |
| 25 |
. ds C` |
| 26 |
. ds C' |
| 27 |
'br\} |
| 28 |
.\" |
| 29 |
.\" Escape single quotes in literal strings from groff's Unicode transform. |
| 30 |
.ie \n(.g .ds Aq \(aq |
| 31 |
.el .ds Aq ' |
| 32 |
.\" |
| 33 |
.\" If the F register is >0, we'll generate index entries on stderr for |
| 34 |
.\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index |
| 35 |
.\" entries marked with X<> in POD. Of course, you'll have to process the |
| 36 |
.\" output yourself in some meaningful fashion. |
| 37 |
.\" |
| 38 |
.\" Avoid warning from groff about undefined register 'F'. |
| 39 |
.de IX |
| 40 |
.. |
| 41 |
.nr rF 0 |
| 42 |
.if \n(.g .if rF .nr rF 1 |
| 43 |
.if (\n(rF:(\n(.g==0)) \{\ |
| 44 |
. if \nF \{\ |
| 45 |
. de IX |
| 46 |
. tm Index:\\$1\t\\n%\t"\\$2" |
| 47 |
.. |
| 48 |
. if !\nF==2 \{\ |
| 49 |
. nr % 0 |
| 50 |
. nr F 2 |
| 51 |
. \} |
| 52 |
. \} |
| 53 |
.\} |
| 54 |
.rr rF |
| 55 |
.\" ======================================================================== |
| 56 |
.\" |
| 57 |
.IX Title "Test2::IPC::Driver 3perl" |
| 58 |
.TH Test2::IPC::Driver 3perl 2025-11-16 "perl v5.40.1" "Perl Programmers Reference Guide" |
| 59 |
.\" For nroff, turn off justification. Always turn off hyphenation; it makes |
| 60 |
.\" way too many mistakes in technical documents. |
| 61 |
.if n .ad l |
| 62 |
.nh |
| 63 |
.SH NAME |
| 64 |
Test2::IPC::Driver \- Base class for Test2 IPC drivers. |
| 65 |
.SH SYNOPSIS |
| 66 |
.IX Header "SYNOPSIS" |
| 67 |
.Vb 1 |
| 68 |
\& package Test2::IPC::Driver::MyDriver; |
| 69 |
\& |
| 70 |
\& use base \*(AqTest2::IPC::Driver\*(Aq; |
| 71 |
\& |
| 72 |
\& ... |
| 73 |
.Ve |
| 74 |
.SH METHODS |
| 75 |
.IX Header "METHODS" |
| 76 |
.ie n .IP $self\->abort($msg) 4 |
| 77 |
.el .IP \f(CW$self\fR\->abort($msg) 4 |
| 78 |
.IX Item "$self->abort($msg)" |
| 79 |
If an IPC encounters a fatal error it should use this. This will print the |
| 80 |
message to STDERR with \f(CW\*(AqIPC Fatal Error: \*(Aq\fR prefixed to it, then it will |
| 81 |
forcefully exit 255. IPC errors may occur in threads or processes other than |
| 82 |
the main one, this method provides the best chance of the harness noticing the |
| 83 |
error. |
| 84 |
.ie n .IP $self\->abort_trace($msg) 4 |
| 85 |
.el .IP \f(CW$self\fR\->abort_trace($msg) 4 |
| 86 |
.IX Item "$self->abort_trace($msg)" |
| 87 |
This is the same as \f(CW\*(C`$ipc\->abort($msg)\*(C'\fR except that it uses |
| 88 |
\&\f(CW\*(C`Carp::longmess\*(C'\fR to add a stack trace to the message. |
| 89 |
.SH "LOADING DRIVERS" |
| 90 |
.IX Header "LOADING DRIVERS" |
| 91 |
Test2::IPC::Driver has an \f(CWimport()\fR method. All drivers inherit this import |
| 92 |
method. This import method registers the driver. |
| 93 |
.PP |
| 94 |
In most cases you just need to load the desired IPC driver to make it work. You |
| 95 |
should load this driver as early as possible. A warning will be issued if you |
| 96 |
load it too late for it to be effective. |
| 97 |
.PP |
| 98 |
.Vb 2 |
| 99 |
\& use Test2::IPC::Driver::MyDriver; |
| 100 |
\& ... |
| 101 |
.Ve |
| 102 |
.SH "WRITING DRIVERS" |
| 103 |
.IX Header "WRITING DRIVERS" |
| 104 |
.Vb 3 |
| 105 |
\& package Test2::IPC::Driver::MyDriver; |
| 106 |
\& use strict; |
| 107 |
\& use warnings; |
| 108 |
\& |
| 109 |
\& use base \*(AqTest2::IPC::Driver\*(Aq; |
| 110 |
\& |
| 111 |
\& sub is_viable { |
| 112 |
\& return 0 if $^O eq \*(Aqwin32\*(Aq; # Will not work on windows. |
| 113 |
\& return 1; |
| 114 |
\& } |
| 115 |
\& |
| 116 |
\& sub add_hub { |
| 117 |
\& my $self = shift; |
| 118 |
\& my ($hid) = @_; |
| 119 |
\& |
| 120 |
\& ... # Make it possible to contact the hub |
| 121 |
\& } |
| 122 |
\& |
| 123 |
\& sub drop_hub { |
| 124 |
\& my $self = shift; |
| 125 |
\& my ($hid) = @_; |
| 126 |
\& |
| 127 |
\& ... # Nothing should try to reach the hub anymore. |
| 128 |
\& } |
| 129 |
\& |
| 130 |
\& sub send { |
| 131 |
\& my $self = shift; |
| 132 |
\& my ($hid, $e, $global) = @_; |
| 133 |
\& |
| 134 |
\& ... # Send the event to the proper hub. |
| 135 |
\& |
| 136 |
\& # This may notify other procs/threads that there is a pending event. |
| 137 |
\& Test2::API::test2_ipc_set_pending($uniq_val); |
| 138 |
\& } |
| 139 |
\& |
| 140 |
\& sub cull { |
| 141 |
\& my $self = shift; |
| 142 |
\& my ($hid) = @_; |
| 143 |
\& |
| 144 |
\& my @events = ...; # Here is where you get the events for the hub |
| 145 |
\& |
| 146 |
\& return @events; |
| 147 |
\& } |
| 148 |
\& |
| 149 |
\& sub waiting { |
| 150 |
\& my $self = shift; |
| 151 |
\& |
| 152 |
\& ... # Notify all listening procs and threads that the main |
| 153 |
\& ... # process/thread is waiting for them to finish. |
| 154 |
\& } |
| 155 |
\& |
| 156 |
\& 1; |
| 157 |
.Ve |
| 158 |
.SS "METHODS SUBCLASSES MUST IMPLEMENT" |
| 159 |
.IX Subsection "METHODS SUBCLASSES MUST IMPLEMENT" |
| 160 |
.ie n .IP $ipc\->is_viable 4 |
| 161 |
.el .IP \f(CW$ipc\fR\->is_viable 4 |
| 162 |
.IX Item "$ipc->is_viable" |
| 163 |
This should return true if the driver works in the current environment. This |
| 164 |
should return false if it does not. This is a CLASS method. |
| 165 |
.ie n .IP $ipc\->add_hub($hid) 4 |
| 166 |
.el .IP \f(CW$ipc\fR\->add_hub($hid) 4 |
| 167 |
.IX Item "$ipc->add_hub($hid)" |
| 168 |
This is used to alert the driver that a new hub is expecting events. The driver |
| 169 |
should keep track of the process and thread ids, the hub should only be dropped |
| 170 |
by the proc+thread that started it. |
| 171 |
.Sp |
| 172 |
.Vb 3 |
| 173 |
\& sub add_hub { |
| 174 |
\& my $self = shift; |
| 175 |
\& my ($hid) = @_; |
| 176 |
\& |
| 177 |
\& ... # Make it possible to contact the hub |
| 178 |
\& } |
| 179 |
.Ve |
| 180 |
.ie n .IP $ipc\->drop_hub($hid) 4 |
| 181 |
.el .IP \f(CW$ipc\fR\->drop_hub($hid) 4 |
| 182 |
.IX Item "$ipc->drop_hub($hid)" |
| 183 |
This is used to alert the driver that a hub is no longer accepting events. The |
| 184 |
driver should keep track of the process and thread ids, the hub should only be |
| 185 |
dropped by the proc+thread that started it (This is the drivers responsibility |
| 186 |
to enforce). |
| 187 |
.Sp |
| 188 |
.Vb 3 |
| 189 |
\& sub drop_hub { |
| 190 |
\& my $self = shift; |
| 191 |
\& my ($hid) = @_; |
| 192 |
\& |
| 193 |
\& ... # Nothing should try to reach the hub anymore. |
| 194 |
\& } |
| 195 |
.Ve |
| 196 |
.ie n .IP "$ipc\->send($hid, $event);" 4 |
| 197 |
.el .IP "\f(CW$ipc\fR\->send($hid, \f(CW$event\fR);" 4 |
| 198 |
.IX Item "$ipc->send($hid, $event);" |
| 199 |
.PD 0 |
| 200 |
.ie n .IP "$ipc\->send($hid, $event, $global);" 4 |
| 201 |
.el .IP "\f(CW$ipc\fR\->send($hid, \f(CW$event\fR, \f(CW$global\fR);" 4 |
| 202 |
.IX Item "$ipc->send($hid, $event, $global);" |
| 203 |
.PD |
| 204 |
Used to send events from the current process/thread to the specified hub in its |
| 205 |
process+thread. |
| 206 |
.Sp |
| 207 |
.Vb 3 |
| 208 |
\& sub send { |
| 209 |
\& my $self = shift; |
| 210 |
\& my ($hid, $e) = @_; |
| 211 |
\& |
| 212 |
\& ... # Send the event to the proper hub. |
| 213 |
\& |
| 214 |
\& # This may notify other procs/threads that there is a pending event. |
| 215 |
\& Test2::API::test2_ipc_set_pending($uniq_val); |
| 216 |
\& } |
| 217 |
.Ve |
| 218 |
.Sp |
| 219 |
If \f(CW$global\fR is true then the driver should send the event to all hubs in all |
| 220 |
processes and threads. |
| 221 |
.ie n .IP "@events = $ipc\->cull($hid)" 4 |
| 222 |
.el .IP "\f(CW@events\fR = \f(CW$ipc\fR\->cull($hid)" 4 |
| 223 |
.IX Item "@events = $ipc->cull($hid)" |
| 224 |
Used to collect events that have been sent to the specified hub. |
| 225 |
.Sp |
| 226 |
.Vb 3 |
| 227 |
\& sub cull { |
| 228 |
\& my $self = shift; |
| 229 |
\& my ($hid) = @_; |
| 230 |
\& |
| 231 |
\& my @events = ...; # Here is where you get the events for the hub |
| 232 |
\& |
| 233 |
\& return @events; |
| 234 |
\& } |
| 235 |
.Ve |
| 236 |
.ie n .IP $ipc\->\fBwaiting()\fR 4 |
| 237 |
.el .IP \f(CW$ipc\fR\->\fBwaiting()\fR 4 |
| 238 |
.IX Item "$ipc->waiting()" |
| 239 |
This is called in the parent process when it is complete and waiting for all |
| 240 |
child processes and threads to complete. |
| 241 |
.Sp |
| 242 |
.Vb 2 |
| 243 |
\& sub waiting { |
| 244 |
\& my $self = shift; |
| 245 |
\& |
| 246 |
\& ... # Notify all listening procs and threads that the main |
| 247 |
\& ... # process/thread is waiting for them to finish. |
| 248 |
\& } |
| 249 |
.Ve |
| 250 |
.SS "METHODS SUBCLASSES MAY IMPLEMENT OR OVERRIDE" |
| 251 |
.IX Subsection "METHODS SUBCLASSES MAY IMPLEMENT OR OVERRIDE" |
| 252 |
.ie n .IP $ipc\->driver_abort($msg) 4 |
| 253 |
.el .IP \f(CW$ipc\fR\->driver_abort($msg) 4 |
| 254 |
.IX Item "$ipc->driver_abort($msg)" |
| 255 |
This is a hook called by \f(CW\*(C`Test2::IPC::Driver\->abort()\*(C'\fR. This is your |
| 256 |
chance to cleanup when an abort happens. You cannot prevent the abort, but you |
| 257 |
can gracefully except it. |
| 258 |
.SH SOURCE |
| 259 |
.IX Header "SOURCE" |
| 260 |
The source code repository for Test2 can be found at |
| 261 |
<https://github.com/Test\-More/test\-more/>. |
| 262 |
.SH MAINTAINERS |
| 263 |
.IX Header "MAINTAINERS" |
| 264 |
.IP "Chad Granum <[email protected]>" 4 |
| 265 |
.IX Item "Chad Granum <[email protected]>" |
| 266 |
.SH AUTHORS |
| 267 |
.IX Header "AUTHORS" |
| 268 |
.PD 0 |
| 269 |
.IP "Chad Granum <[email protected]>" 4 |
| 270 |
.IX Item "Chad Granum <[email protected]>" |
| 271 |
.PD |
| 272 |
.SH COPYRIGHT |
| 273 |
.IX Header "COPYRIGHT" |
| 274 |
Copyright 2020 Chad Granum <[email protected]>. |
| 275 |
.PP |
| 276 |
This program is free software; you can redistribute it and/or |
| 277 |
modify it under the same terms as Perl itself. |
| 278 |
.PP |
| 279 |
See <https://dev.perl.org/licenses/> |