File: applguide.html

package info (click to toggle)
linpac 0.16pre3-3
  • links: PTS
  • area: main
  • in suites: woody
  • size: 2,328 kB
  • ctags: 2,582
  • sloc: cpp: 16,514; sh: 7,991; ansic: 4,061; makefile: 211; perl: 101
file content (542 lines) | stat: -rw-r--r-- 26,968 bytes parent folder | download
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
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
<head>
   <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
   <meta name="GENERATOR" content="Mozilla/4.7 [en] (X11; I; Linux 2.2.17 i586) [Netscape]">
</head>
<body>

<center>
<h1>
LinPac - Packet Radio Terminal for Linux&nbsp;
<hr WIDTH="100%"></h1></center>

<center>Version 0.16
<p>(c) 1998 - 2001 by Radek Burget OK2JBG</center>

<br>&nbsp;
<center>
<h2>
Extrenal Application Programming Guide</h2></center>
<b>Contents</b>
<p>1 <a href="#POS1">Introduction</a>
<p>2 <a href="#POS2">What is an extrenal program</a>
<p>3 <a href="#POS3">How do applications communicate with LinPac</a>
<p>4 <a href="#POS4">Using the application library</a>
<br>4.1 <a href="#POS4_1">The simplest application</a>
<p>5 <a href="#POS5">Application programming</a>
<br>5.1 <a href="#POS5_1">Events</a>
<br>5.2 <a href="#POS5_2">Sending and receiving events</a>
<br>5.3 <a href="#POS5_3">Synchronization</a>
<br>5.4 <a href="#POS5_4">Shared memory</a>
<br>5.5 <a href="#POS5_5">Connection status</a>
<p>6 <a href="#POS6">The application library interface</a>
<br>6.1 <a href="#POS6_1">Constants</a>
<br>6.2 <a href="#POS6_2">Data structures</a>
<br>6.3 <a href="#POS6_3">Global variables</a>
<br>6.4 <a href="#POS6_4">Functions</a>
<br>6.4.1 <a href="#POS6_4_1">Uninterruptable versions of some system calls</a>
<br>6.4.2 <a href="#POS6_4_2">Basic communication functions</a>
<br>6.4.3 <a href="#POS6_4_3">Automatic event handling functions</a>
<br>6.4.4 <a href="#POS6_4_4">Environment functions</a>
<br>6.4.5 <a href="#POS6_4_5">User functions</a>
<br>6.4.6 <a href="#POS6_4_6">Tool functions</a>
<p><a NAME="POS1"></a>
<h2>
1 Introduction</h2>
This guide is written for programmers who want to add some new functions
to LinPac. In following text the basic knowledge about Linux programming
is assumed. It's also recommended to read the user manual first.
<p><a NAME="POS2"></a>
<h2>
2 What is an external program</h2>
An external program is a standard Linux application which uses LinPac to
communicate with remote user. There are basicaly two types of LinPac external
programs:
<ul>
<li>
Normal programs that can be used without LinPac too. LinPac allows to redirect
the input stream (stdin) of the application and any of the output streams
(stdout, stderr) or both of them. LinPac can also provide the CR/LF conversions
in this streams. This parametres are set when adding the external program
to LinPac - see the section 7 "Creating new commands" in the user manual.</li>

<li>
Application written using the application interface of LinPac. This applications
can share some information with LinPac and they can control almost all
functions of LinPac.</li>
</ul>
There are no specialities when creating an application of the first type.
Just write the program to work on the Linux console and add it to LinPac.
Following sections of this guide are dedicated to the second type of applications.
<p><a NAME="POS3"></a>
<h2>
3 How do applications communicate with LinPac</h2>
There are two types of communication between LinPac and the application:
<ul>
<li>
<b>Shared memory:</b> LinPac holds some information like connected station
callsigns, connection status and internal variables in the shared memory
block. Each application can attach this data and read or modify them.</li>

<li>
<b>Named pipes:</b> There are two named pipes, one for reading data from
application and other for sending data to application.</li>
</ul>
Shared memory and the pipes are maintained by the application interface
library and shouldn't be contrlled directly.
<p><a NAME="POS4"></a>
<h2>
4 Using the application library</h2>
During LinPac installation the application library <tt>liblinpac</tt> is
created and installed by default to <tt>/usr/local/lib</tt>. The interface
to this library is contained in the file <tt>lpapp.h</tt> and it's installed
by default to <tt>/usr/local/include/linpac</tt>. Next chapter shows how
to use the library with the user program.
<p><a NAME="POS4_1"></a>
<h3>
4.1 The simplest application</h3>
Following application example just tries to contact LinPac and prints the
result.
<p><tt>---------------------------- File test1.cc ---------------------------</tt>
<br><tt>#include &lt;stdio.h></tt>
<br><tt>#include &lt;unistd.h></tt>
<br><tt>#include &lt;linpac/lpapp.h></tt>
<p><tt>int main()</tt>
<br><tt>{</tt>
<br><tt>&nbsp; if (start_appl(LP_PIPE_PATH))</tt>
<br><tt>&nbsp; {</tt>
<br><tt>&nbsp;&nbsp;&nbsp;&nbsp; printf("Application started\n");</tt>
<br><tt>&nbsp;&nbsp;&nbsp;&nbsp; sleep(1);</tt>
<br><tt>&nbsp;&nbsp;&nbsp;&nbsp; printf("Application finished\n");</tt>
<br><tt>&nbsp;&nbsp;&nbsp;&nbsp; end_appl();</tt>
<br><tt>&nbsp; }</tt>
<br><tt>&nbsp; else</tt>
<br><tt>&nbsp; {</tt>
<br><tt>&nbsp;&nbsp;&nbsp;&nbsp; printf("LinPac is not running\n");</tt>
<br><tt>&nbsp;&nbsp;&nbsp;&nbsp; return 1;</tt>
<br><tt>&nbsp; }</tt>
<p><tt>&nbsp; return 0;</tt>
<br><tt>}</tt>
<p><tt>-----------------------------------------------------------------</tt>
<p>The function <tt>start_appl()</tt> tries to contact LinPac and returns
<b>1</b>
in case of succes or <b>0</b> when LinPac cannot be connected (probably
it's not running). This function should precede the usage of any other
application library function. The <tt>LP_PIPE_PATH</tt> constant contains
the path to LinPac named pipe.
<p>The function <tt>end_appl()</tt> closes the connection to LinPac.
<p>How to compile this example:
<p><tt>gcc -o test1 test1.cc -llinpac</tt>
<p>This example just detects if LinPac is running and it can be executed
directly from the shell. When running from the shell, no streams are redirected
to LinPac and the application seems to run on channel 0 of LinPac. It's
useful for some applications that are used to control linpac from outside.
However it's not a typical case.
<p>For most of the applications it's better to copy the executable to the
<tt>$LINPACDIR/bin</tt>
directory and add it to the file
<br><tt>$LINPACDIR/bin/commands</tt> as described in the <a href="manual.html">user
manual</a>. After this the application can be executed as the LinPac command.
In this case the streams are properly redirected and the application output
is visible in LinPac window. It's also possible to select the channel for
running the application.
<p><a NAME="POS5"></a>
<h2>
5 Application programming</h2>
<a NAME="POS5_1"></a>
<h3>
5.1 Events</h3>
LinPac is completely driven by events. Each part of LinPac including the
application can generate the event to inform other parts (internal modules
or applications) that something has happend. Each event is sent to all
LinPac components and application. For example when some station connects
to some LinPac channel, the internal AX.25 interface generates the event
reporting that the station has connected and includes its callsign. All
components and applications now know who has connected and they can do
some actions (the output window prints the information about the connect,
the macro processor executes the cinit.mac macro ...). Each application
can handle all the events too and it can generate events which are handled
by other components.
<p>The event is represented by the following structure:
<p><tt>struct Event</tt>
<br><tt>{</tt>
<br><tt>&nbsp; int type;</tt>
<br><tt>&nbsp; int chn;</tt>
<br><tt>&nbsp; int x,y;</tt>
<br><tt>&nbsp; char ch;</tt>
<br><tt>&nbsp; void *data;</tt>
<br><tt>};</tt>
<p>The meaning of each field is following:
<p><b><tt>type</tt></b> - Determines the type of the event. Actually it
says what happend. There is a symbolic constant defined for each known
event.
<br><b><tt>chn</tt></b> - It says the channel for which the event applies
(for example if the type of the event reports some data received, the chn
field contains the number of the channel which has received data). There
are many events that apply for all the channels. For this events this field
is not significant.
<br><b><tt>x</tt></b>, <b><tt>y</tt></b> - The meaning of field depends
on the event type. The y field is usually not used (it's used by some internale
events only).
<br><b><tt>ch</tt></b> - This field is used by some internal events only.
<br><b><tt>data</tt></b> - Depends on the type of the event too. It usually
points to some string data or a char buffer.
<p>All the event types are described in the <a href="events.txt">event
list</a>.
<p><a NAME="POS5_2"></a>
<h3>
5.2 Sending and receiving events</h3>
For sending events the function
<p><tt>int emit_event(int chn, int type, int x, void *data);</tt>
<p>is used. This generates new event using specified values. Each argument
corresponds with one of the fields in the Event structure.
<p>There are two modes of handling the incomming events:
<p><b><i>a) Reading each event on demand</i></b>
<br>This mode is started by the <tt>event_handling_off()</tt> call. In
this mode events are read using the function
<p><tt>int get_event(Event *ev);</tt>
<p>This function returns 0 when no event is available. When there is some
event available, it returns 1 and fills the Event structure with the received
event data.
<p><b>WARNING1</b>: The <tt>data</tt> field in your Event structure must
point to some dynamicaly allocated buffer. The size of the buffer is reallocated
automaticaly after receiving an event. When the <tt>data</tt> field is
set to NULL, new buffer is allocated. This field <u>must not</u> be uninitialized.
<p><b>WARNING2</b>: The application _must_ read all events in this mode.
It's not a good idea to stop reading the events because the event queue
can overflow and cause serious problems.
<p><b><i>b) Automatical event processing</i></b>
<br>This mode is started by the <tt>event_handling_on()</tt> call. All
the events are read automaticaly. The user can define his own function
that is called automaticaly when an event occurs. When there's no such
function defined, all events are discarted.
<p>The event handling function must have following prototype:
<p><tt>void some_function(Event *ev);</tt>
<p>(the function name can be different). After initializing the application
the event handling function must be registered using the function <tt>set_event_handler(</tt>)
from the apllication library.
<p>Following example is an application that prints the types of all events
received and stops when an event <tt>EV_ABORT</tt> is received. This event
can be generated using the <tt>:ABort</tt> command in LinPac.
<p><tt>---------------------------------------------------------------------------</tt>
<br><tt>#include &lt;stdio.h></tt>
<br><tt>#include &lt;linpac/lpapp.h></tt>
<p><tt>int aborted = 0;</tt>
<p><tt>//User event handling function. This function is called each time</tt>
<br><tt>//an event occurs</tt>
<br><tt>void my_event_handler(Event *ev)</tt>
<br><tt>{</tt>
<br><tt>&nbsp; printf("The event of type %i has been received\n", ev->type);</tt>
<br><tt>&nbsp; if (ev->type == EV_ABORT) aborted = 1;</tt>
<br><tt>}</tt>
<p><tt>int main()</tt>
<br><tt>{</tt>
<br><tt>&nbsp; if (start_appl(LP_PIPE_PATH))</tt>
<br><tt>&nbsp; {</tt>
<br><tt>&nbsp;&nbsp;&nbsp; event_handling_on(); //turn on automatical event
handling&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;set_event_handler(my_event_handler);
//define own event handler</tt>
<p><tt>&nbsp;&nbsp;&nbsp; printf("Application started\n");</tt>
<br><tt>&nbsp;&nbsp;&nbsp; printf("Stop with the ':Abort' command\n");</tt>
<p><tt>&nbsp;&nbsp;&nbsp; do ; while(!aborted); //wait until application
is aborted</tt>
<p><tt>&nbsp;&nbsp;&nbsp; printf("Application finished\n");</tt>
<p><tt>&nbsp;&nbsp;&nbsp; end_appl();</tt>
<br><tt>&nbsp; }</tt>
<br><tt>&nbsp; else</tt>
<br><tt>&nbsp; {</tt>
<br><tt>&nbsp;&nbsp;&nbsp; printf("LinPac is not running\n");</tt>
<br><tt>&nbsp;&nbsp;&nbsp; return 1;</tt>
<br><tt>&nbsp; }</tt>
<p><tt>&nbsp; return 0;</tt>
<br><tt>}</tt>
<p><tt>----------------------------------------------------------------------------</tt>
<p><b>WARNING</b>: Note that some system calls can be interrupted when
the event is received. Interrupted system call returns the error result
and sets errno to EAGAIN (for example the read() call returns -1) and it
must be called again. To avoid this use the interrupt-safe versions of
the system calls contained in the application library (see <a href="#POS6_3_1">chapter
6.3.1</a>)
<p><a NAME="POS5_3"></a>
<h3>
5.3 Synchronization</h3>
The event generated by an applicatoin is sent to all the modules and applications
including the application that has generated the event. When there's the
need to wait until the event is accepted by LinPac, the simplest way is
to wait until the event we have sent is received back.
<p>For testing that all the events were processed there is an event <tt>EV_VOID</tt>.
It's not handled by any module. After sending all events just generate
the <tt>EV_VOID</tt> event and wait until it returns. After that it's sure
that all previous events have been processed.
<p><a NAME="POS5_4"></a>
<h3>
5.4 Shared memory</h3>
All the shared data are represented by folowing structure:
<p><tt>struct shared_data</tt>
<br><tt>{</tt>
<br><tt>&nbsp; /* channel info */</tt>
<br><tt>&nbsp; char call[10];&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /* callsign
for each channel */</tt>
<br><tt>&nbsp; char cwit[10];&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /* connected
with callsign */</tt>
<br><tt>&nbsp; char cphy[10];&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /* physical
connection to */</tt>
<br><tt>&nbsp; int port;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
/* connected on which port */</tt>
<br><tt>&nbsp; int state;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
/* connection status */</tt>
<br><tt>};</tt>
<p>The fields have following meaning:
<p><b>call</b> - callsign of the channel that was set using the :mycall
command cwit - callsign of station connected to the channel
<br><b>cphy</b> - callsign of the station we are physicaly connected to.
In case of direct connection cphy is equal to cwit.
<br><b>port</b> - port used for the connection. 0 means the first port
in axports, 1 is the second one...
<br><b>state</b> - connection status. Following states can occur:
<br><tt>ST_DISC</tt> - disconnected
<br><tt>ST_DISP</tt> - disconnecting
<br><tt>ST_TIME</tt> - disconnecting for timeout
<br><tt>ST_CONN</tt> - connected
<br><tt>ST_CONP </tt>- connecting in progress
<p>When the application is initialized, the <tt>start_appl()</tt> function
creates the array of these structures:
<p><tt>shared_data []shd</tt>
<p>Thus the callsign of the first channel is <tt>shd[1].call</tt> etc.
<br>The contents of the structure is managed by LinPac and it's not recommended
to modify the fields within an application (except some special cases).
Better way to change this fields is to generate appropriate event (e.g.
EV_CALL_CHANGE).
<p><a NAME="POS5_5"></a>
<h3>
5.5 Connection status</h3>
There are two special events reserved for obtaining the AX.25 connection
status. When the application wants to get the status of the connection
on certain LinPac channel, it generates the EV_STAT_REQ event on this channel.
As the answer LinPac generates the EV_STATUS event. The <b>data</b> field
of this event points to the ax25_status structure (see <a href="#POS6_2">chapter
6.2</a>). When there is no active connection on the channel, no EV_STATUS
event is generated.
<p><a NAME="POS6"></a>
<h2>
6 The application library interface</h2>
<a NAME="POS6_1"></a>
<h3>
6.1 Constants</h3>
<b><tt>LPAPP_VERSION</tt></b> - version of LinPac that the linrary came
with
<br><b><tt>MAX_CHN </tt></b>- number of regular LinPac's channels
<br><b><tt>ENV_SIZE</tt></b> - environment size for channel
<br><b><tt>AXPORTS</tt></b> - path to axports file
<p><b><tt>ST_xxxx</tt></b> - connection status constants (see chapter 5.4)
<p><a NAME="POS6_2"></a>
<h3>
6.2 Data structures</h3>
<i>struct ax25_status</i> - contains the AX.25 connection status:
<p><tt>typedef struct</tt>
<br><tt>{</tt>
<br><tt>&nbsp; char devname[8];</tt>
<br><tt>&nbsp; int state;</tt>
<br><tt>&nbsp; int vs, vr, va;</tt>
<br><tt>&nbsp; int t1, t2, t3, t1max, t2max, t3max;</tt>
<br><tt>&nbsp; int idle, idlemax;</tt>
<br><tt>&nbsp; int n2, n2max;</tt>
<br><tt>&nbsp; int rtt;</tt>
<br><tt>&nbsp; int window;</tt>
<br><tt>&nbsp; int paclen;</tt>
<br><tt>&nbsp; bool dama;</tt>
<br><tt>&nbsp; int sendq, recvq;</tt>
<br><tt>} ax25_status;</tt>
<p><i>struct shared_config</i> - contains the information of current linpac
configuration. There is the pointer <tt>lp_config</tt> defined, which points
to this structure.
<p><tt>typedef struct</tt>
<br><tt>{</tt>
<br><tt>&nbsp; bool remote;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
//Remote is on</tt>
<p><tt>&nbsp; bool cbell;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
//connection bell on</tt>
<br><tt>&nbsp; bool knax;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
//incomming frame bell on</tt>
<p><tt>&nbsp; char def_port[32];&nbsp;&nbsp; //Default port name</tt>
<br><tt>&nbsp; char unportname[32]; //Unproto port name</tt>
<br><tt>&nbsp; int unport;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
//Unproto port number (0..n)</tt>
<p><tt>&nbsp; int info_level;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
//Statusline: 0=none 1=short 2=full</tt>
<br><tt>&nbsp; char no_name[32];&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
//Default name of stn (%N)</tt>
<br><tt>&nbsp; char timezone[8];&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
//Local timezone name</tt>
<br><tt>&nbsp; int qso_start_line, qso_end_line, //Screen divisions</tt>
<br><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; mon_start_line, mon_end_line,</tt>
<br><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; edit_start_line, edit_end_line,</tt>
<br><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; stat_line, chn_line;</tt>
<br><tt>&nbsp; int max_x;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
//screen length</tt>
<br><tt>&nbsp; bool swap_edit;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
//swap editor with qso-window</tt>
<br><tt>&nbsp; bool fixpath;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
//use fixed paths only</tt>
<br><tt>&nbsp; bool daemon;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
//linpac works as daemon</tt>
<br><tt>&nbsp; bool monitor;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
//monitor on/off</tt>
<br><tt>&nbsp; bool no_monitor;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
//monitor not installed</tt>
<br><tt>&nbsp; bool listen;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
//listening to connection requests</tt>
<br><tt>&nbsp; bool disable_spyd;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
//disable ax25spyd usage</tt>
<br><tt>&nbsp; bool mon_bin;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
//monitor shows binary data</tt>
<br><tt>&nbsp; char monparms[10];&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
//arguments to 'listen' program</tt>
<br><tt>&nbsp; int maxchn;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
//number of channels</tt>
<br><tt>&nbsp; int envsize;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
//environment size</tt>
<br><tt>&nbsp; time_t last_act;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
//last activity (seconds)</tt>
<br><tt>} shared_config;</tt>
<p>When LinPac runs in daemon mode all the screen-depended fields have
undefined values.
<p><a NAME="POS6_3"></a>
<h3>
6.3 Global variables</h3>
<b><tt>shared_data *shd</tt></b> - pointer to shared structure (see
<a href="#POS5_4">chapter
5.4</a>)
<br><b><tt>shared_config *lp_config</tt></b> - pointer to linpac config
structure (see <a href="#POS6_2">chapter 6.2</a>)
<br><b><tt>int app_chn</tt></b> - channel number this application is running
on
<br><b><tt>int app_pid</tt></b> - the PID of this application
<p><a NAME="POS6_4"></a>
<h3>
6.4 Functions</h3>
<a NAME="POS6_4_1"></a>
<h4>
6.4.1 Uninterruptable versions of some system calls</h4>
Following functions work the same way as the original system calls, but
they are interrupt-safe (they don't fail with <tt>errno == EAGAIN</tt>).
<p><tt>size_t safe_read(int fd, void *buf, size_t count);</tt>
<br><tt>size_t safe_write(int fd, const void *buf, size_t count);</tt>
<br><tt>char *safe_fgets(char *s, int size, FILE *stream);</tt>
<br><tt>int safe_fgetc(FILE *stream);</tt>
<p><a NAME="POS6_4_2"></a>
<h4>
6.4.2 Basic communication functions</h4>
<b><tt>int start_appl(char *pipename)</tt></b>
<br>Starts the communication with LinPac. The <tt>pipename</tt> parameter
contains the name of the named pipe used for communication (use LP_PIPE_PATH
here). Non-zero return value means success, zero value means that LinPac
cannot be contacted (probably it's not running).
<p><b><tt>int get_event(Event *ev)</tt></b>
<br>Read the event from the queue. Non-zero return value means succesful
read, zero value means that the event queue is empty. The <tt>data</tt>
field of the event structure <u>must</u> be initialized before using this
function (to NULL or to some buffer). This function shouldn't be used when
automatic event processing is used.
<p><b><tt>int emit_event(int chn, int type, int x, void *data)</tt></b>
<br>Generate new event. The arguments correspond with the fields in the
event structure. Return value is always 0.
<p><b><tt>void wait_event(int chn, int type)</tt></b>
<br>Wait until the event with the same <tt>chn</tt> and <tt>type</tt> values
are received.
<p><b><tt>void wait_init(int chn, int type)</tt></b>
<br>The same as <tt>wait_event()</tt> but returns immediately, waiting
is provided by following function <tt>wait_realize()</tt>.
<p><b><tt>void wait_realize()</tt></b>
<br>Realizes waiting initialized by <tt>wait_init()</tt>. All the events
that arrived since last wait_init() call are registered. <tt>wait_realize()</tt>
can exit immediately if the event has already arrived.
<p><b><tt>void discard_event(Event *ev)</tt></b>
<br>Free the memory used by the data field of Event structure received
using <tt>get_event()</tt>.
<p><b><tt>void clear_pipe()</tt></b>
<br>Removes all events from the event queue. This has no use when automatic
event processing is on.
<p><b><tt>void end_appl()</tt></b>
<br>Closes the connection to LinPac.
<p><a NAME="POS6_4_3"></a>
<h4>
6.4.3 Automatic event handling functions</h4>
<b><tt>void event_handling_on()</tt></b>
<br>Switches the automatic event handling on. From this point each event
is automaticaly read from the queue, treated with an event handler function
(if defined) and discarted.
<p><b><tt>void event_handling_off()</tt></b>
<br>Switches the automatic event handling off. Events must be read from
the queue using the get_event() function.
<p><b><tt>void set_event_handler(handler_type handler)</tt></b>
<br>Defines the event handler function - a function like
<br><tt>void my_handler(Event *ev)</tt>
<p>The event handler is called automaticaly each time some event is received
and the automatic event handling is on.
<p><a NAME="POS6_4_4"></a>
<h4>
6.4.4 Environment functions</h4>
LinPac owns its own environment for storing the variables. Each application
can share and modify this environment using following functions. The environment
is separated for each channel.
<p><b><tt>void set_var(int chn, char *name, char *contents)</tt></b>
<br>Change the value of the variable. 'name' is the name of the variable,
<tt>contents</tt>
is the new value. <tt>chn</tt> is the channel number (0..MAXCHN) When the
variable doesn't exist, it's created.
<p><b><tt>void del_var(int chn, char *var)</tt></b>
<br>Delete the variable. 'var' is the pointer to the begining of the variable
in the environment (pointer to the statement NAME=VALUE)
<p><b><tt>char *find_var(int chn, char *name)</tt></b>
<br>Returns the poiner to the begining of the variable in channel environment.
<p><b><tt>char *get_var(int chn, char *name)</tt></b>
<br>Returns the pointer to the value of the variable. <tt>name</tt> is
the name of the variable.
<p><b><tt>char *env_end(int chn)</tt></b>
<br>Returns the pointer to end of the environment (behind the last variable).
<p><b><tt>char *clear_var_names(int chn, char *name)</tt></b>
<br>Delete all variables for which the contents of 'name' is the left substring
of their name. ($name*)
<p><a NAME="POS6_4_5"></a>
<h4>
6.4.5 User functions</h4>
<b><tt>void appl_result(const char *fmt, ...)</tt></b>
<br>Set the result of the application. This function generates the EV_APP_RESULT
event with the message string. The argument format is the same as for <tt>printf()</tt>
<p><b><tt>void statline(const char *fmt, ...)</tt></b>
<br>Displays or changes the additional status line. Using this function
can be displayed one status line only. This function generates the EV_CHANGE_STLINE
event with the x field (line ID) containing the PID of the application.
For displaying more than one status line for the application other EV_CHANGE_STLINE
events must be generated manualy.
<p><b><tt>void remove_statline()</tt></b>
<br>Removes the status line.
<p><b><tt>void disable_screen()</tt></b>
<br>Disables displaying the data in the QSO window on application's channel.
The EV_DISABLE_SCREEN event is used.
<p><b><tt>void enable_screen()</tt></b>
<br>Enables displaying the data in the QSO window. The EV_ENABLE_SCREEN
event is generated.
<p><a NAME="POS6_4_6"></a>
<h4>
6.4.6 Tool functions</h4>
<b><tt>char *time_stamp(int utc)</tt></b>
<br>Returns the pointer to a c-string that contains actual time. If
<tt>utc</tt>=0
then local time is used else the UTC time is used.
<p><b><tt>char *date_stamp(int utc)</tt></b>
<br>Returns the date-string.
<p><b><tt>void replace_macros(int chn, char *s)</tt></b>
<br>Replaces the variables in the string (<tt>%xxx</tt>) with their values.
The <tt>%(command)</tt> macro is not replaced.
<p><b><tt>void get_port_name(int n)</tt></b>
<br>Returns the name of the n-th port in axports (starting with 0).
<p>
<hr>
<center>
<p><i><font size=-1>Last update: 29.1.2001</font></i></center>

</body>
</html>