summaryrefslogtreecommitdiffstats
path: root/runtime/transport/transport.h
blob: 871e37b39d548ce3f616dff2fbb457fb32ec86e2 (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
#ifndef _TRANSPORT_TRANSPORT_H_ /* -*- linux-c -*- */
#define _TRANSPORT_TRANSPORT_H_

/** @file transport.h
 * @brief Header file for stp transport
 */

#include "transport_msgs.h"

/* The size of print buffers. This limits the maximum */
/* amount of data a print can send. */
#define STP_BUFFER_SIZE 8192

static int _stp_ctl_write(int type, void *data, unsigned len);

static int _stp_transport_init(void);
static void _stp_transport_close(void);

/* STP_CTL_BUFFER_SIZE is the maximum size of a message */
/* exchanged on the control channel. */
#if STP_TRANSPORT_VERSION == 1
/* Old transport sends print output on control channel */
#define STP_CTL_BUFFER_SIZE STP_BUFFER_SIZE
#else
#define STP_CTL_BUFFER_SIZE 256
#endif

/* how often the work queue wakes up and checks buffers */
#define STP_WORK_TIMER (HZ/100)

static unsigned _stp_nsubbufs;
static unsigned _stp_subbuf_size;

static int _stp_transport_init(void);
static void _stp_transport_close(void);

static int _stp_lock_transport_dir(void);
static void _stp_unlock_transport_dir(void);

static struct dentry *_stp_get_root_dir(void);
static struct dentry *_stp_get_module_dir(void);

static int _stp_transport_fs_init(const char *module_name);
static void _stp_transport_fs_close(void);

static void _stp_attach(void);
static void _stp_detach(void);
static void _stp_handle_start(struct _stp_msg_start *st);

static uid_t _stp_uid;
static gid_t _stp_gid;

static int _stp_ctl_attached;

static int _stp_bufsize;


enum _stp_transport_state {
	STP_TRANSPORT_STOPPED,
	STP_TRANSPORT_INITIALIZED,
	STP_TRANSPORT_RUNNING,
};

/*
 * All transports must provide the following functions.
 */

/*
 * _stp_transport_get_state
 *
 * This function returns the current transport state.
 */
static enum _stp_transport_state _stp_transport_get_state(void);

/*
 * _stp_transport_data_fs_init
 *
 * This function allocates any buffers needed, creates files,
 * etc. needed for this transport.
 */
static int _stp_transport_data_fs_init(void);

/* 
 * _stp_transport_data_fs_start
 *
 * This function actually starts the transport.
 */
static void _stp_transport_data_fs_start(void);

/* 
 * _stp_transport_data_fs_start
 *
 * This function stops the transport without doing any cleanup.
 */
static void _stp_transport_data_fs_stop(void);

/* 
 * _stp_transport_data_fs_close
 *
 * This function cleans up items created by
 * _stp_transport_data_fs_init().
 */
static void _stp_transport_data_fs_close(void);

/*
 * _stp_transport_data_fs_overwrite - set data overwrite mode
 * overwrite:		boolean
 *
 * When in overwrite mode and the transport buffers are full, older
 * data gets overwritten.
 */
static void _stp_transport_data_fs_overwrite(int overwrite);

/*
 * _stp_data_write_reserve - reserve bytes
 * size_request:	number of bytes to reserve
 * entry:		allocated buffer is returned here
 *
 * This function attempts to reserve size_request number of bytes,
 * returning the number of bytes actually reserved.  The allocated
 * buffer is returned in entry.  Note that the number of bytes
 * allocated may be less than the number of bytes requested.
 */
static size_t _stp_data_write_reserve(size_t size_request, void **entry);


/*
 * _stp_data_entry_data - return data pointer from entry
 * entry:		entry
 *
 * This function returns the data pointer from entry.
 */
static unsigned char *_stp_data_entry_data(void *entry);

/*
 * _stp_data_write_commit - 
 * entry:		pointer returned by _stp-data_write_reserve()
 *
 * This function notifies the transport that the bytes in entry are
 * ready to be written.  
 */
static int _stp_data_write_commit(void *entry);

#endif /* _TRANSPORT_TRANSPORT_H_ */