File: PROGRAMMING-HOWTO

package info (click to toggle)
srcpd 2.1.7-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,900 kB
  • sloc: ansic: 18,080; sh: 4,579; makefile: 95
file content (188 lines) | stat: -rw-r--r-- 5,707 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
-*- text -*-

Programming of modules for srcpd

Last update: 2012-10-24

0. Overview

All modules can be used multiple and in parallel. 

All modules are included at compile time. Options to disable one or
more of them are provided via configure (see configure --help).

All configuration is done with the srcpd configuration file
»srcpd.conf«. The XML based format needs some discipline, e.g. with
respect to spaces within bus names (developer task) and file/device
names (user task).

1. Start up

During start up _the_ configuration file (compile time build in name
or configurable with the -f option) is read. In the file config-srcpd.c
the function register_bus() calls the hard coded functions from the
respective buses with their DOM sub tree and their effective bus number.

This parsing routine must initialize all data fields of the respecive
global buses array entry and analyse the XML DOM sub tree. The routine 
should also provide useful default values.

The framework expects the following call back function pointers to be
set:

- init_bus: called as "SRCP INIT <bus>"
- term_bus: called as "SRCP TERM <bus>"
- send_rec: called as separate thread. That thread works as endless
  loop to communicate with the real hardware (if any).
- string DESCRIPTION with all supported device groups.

In addition all specific data such as device names etc. must be
available.

2. init_bus

This function is called _before_ the (send_rec)() thread starts. It
opens the hardware communication line, if neccessary.

3. term_bus

This function is called _after_ canceling the (send_rec)() thread to
cleanup. It closes a used communication line.

4. send_rec

This funtion runs an endless loop to process the device queries to
communicate with hardware and read back information. The function gets
a single parameter: the bus number. The return type should be void*, it
will be ignored by now.

Example:
void* thr_sendrec_LOOPBACK (void *v)
{
  bus_t bus = (bus_t) v;
  ...
}

This thread can be supervised by a watchdog to detect blocks. In this
case the thread is canceled and restarted. Note that the init_bus/term_bus
functions are _not_ called.

5. Watchdog

Not every module may need it. If active, the master process checks the
variable watchdog in the »buses«-array and sets it to 0 (zero). If the
value found _is_ already 0 (zero) the rend_rec thread is restarted. A
syslog message is generated.

The send_rec thread has to set this watchdog variable constantly to
a value greater than 0.

6. Debugging

Debugging within the srcpd may be tricky due the potentially many
threads and the lack of a console. To assist _please_ do not use
even temporarily such constructs. Use the function DBG() instead.

This function provides the following user selectable verbosity levels

#define DGB_NONE 0
#define DBG_FATAL 1
#define DBG_ERROR 2
#define DBG_WARN 3
#define DBG_INFO 4
#define DBG_DEBUG 5

A value greater than 5 can be used to disable communication with the
hardware.

7. Sample code

The module loopback (loopback.[hc]) can be used as a starting point
(template) to develop a new module.

8. Queues

Every device group provides it's own queue for every bus. These
queues are filled from the srcp network code. The queues are simple
first-in-first-out queues.

if(!queue_GA_isempty(bus)) {
    unqueueNextGA(&ga);
    process_single_ga(ga);
    setGA(ga)
}

The function unqueueNext<devicegroup>() unqueues the next command.

The function getNext<devicegroup> can be used to read the next command
without removing it from the queue.

The function set<devicegroup> updates the internal data and and sends
the updated information to all INFORMATION sessions.

9. Naming Convention

9.0 Code style

The code is formatted using the »indent« tool. Its settings
should read as follows

 -kr -br -nce -nut -cbi4 -cli4


9.1 Function Names

The thread functions have names prefixed with thr_. Functions related to
SRCP have the command name and the device group in their names (GA,
TERM). Functions used internally by a module have to be declared
»static«. Exported functions (those in the header file) have to contain
the module name in uppercase (e.g. readconfig_LOOPBACK for the loopback
module).

9.2 Bus parameter

All functions are called with the current bus number. Any remaining
data can be found in the array »buses«.

9.3 buses-Array

The array »buses« contains all configuration and working data for the
configured buses. It is currently declared as a static array with 20
entries (0..19).

The data structure reflects the XML configuration structure. Commonly
used data such as pointers to functions, watchdog, description string
etc. and the bus type are provided. Module specific data (such as
data from the XML sub tree) is provided as the (void*) pointer
»driverdata«. This pointer _can_ be NULL.

10. SRCP Hacking

Any changes to the SRCP MUST be covered by the SRCP specification. No
extensions are allowed.

11. Other Operating Systems

Currently the srcpd is very Linux specific, but the most modules can
also be used on other UNIX like systems (FreeBSD and Cygwin are known
to work). 

Operating systems which are very different from UNIX can be supported,
but this will need the respective developer(s).

12. Use of svn

Every one is permitted to read (updates of the public svn server may
have a delay of some hours!). The instructions about how to access can
be found at http://sourceforge.net/projects/srcpd, topic »svn«.

After svn checkout the first to do is a 

 autoreconf -i

After that the usual ./configure && make && make install should do
the work.

Who wants to get write access (and immediate read without the delay)
should contact the project admins.