File: skills.h

package info (click to toggle)
nws 2.11-3
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 2,700 kB
  • ctags: 2,820
  • sloc: ansic: 28,849; sh: 3,289; java: 1,205; makefile: 697; perl: 12
file content (237 lines) | stat: -rwxr-xr-x 6,741 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
/* $Id: skills.h,v 1.39 2004/10/20 06:01:19 graziano Exp $ */

#ifndef SKILLS_H
#define SKILLS_H

#ifdef __cplusplus
extern "C" {
#endif

/*
** The skills module serves as a nameserver-aware wrapper around the sensor
** experiment modules.  By going through this module, sensor control modules
** can focus on scheduling experiments, rather than on the details of how to
** invoke them and interpret the results.  Concentrating skill control in a
** single module also allows multiple controls to support overlapping skills
** without needing to declare duplicated, and therefore fragile, skill names,
** option values, and the like.
*/

#include "config_nws.h"

#include "register.h"

#ifdef EXPERIMENTAL
	/* we don't have experimental skills right now */
#	define EXPERIMENTAL_SKILLS 0
#	define EXPERIMENTAL_RESOURCES 0
#else
#	define EXPERIMENTAL_SKILLS 0
#	define EXPERIMENTAL_RESOURCES 0
#endif

/* # of known skills and # of resources we are measuring */
#define RESOURCE_COUNT (12 + EXPERIMENTAL_RESOURCES)
#define SKILL_COUNT (9 + EXPERIMENTAL_SKILLS)
  
/* Skills supported by this sensor and the resources they measure. */
typedef enum {cpuMonitor=0, diskMonitor, memoryMonitor, tcpConnectMonitor,
	tcpMessageMonitor, filesystemMonitor, availabilityMonitor, 
	startMonitor, memorySpeedMonitor 
} KnownSkills;


typedef enum {availableCpu=0, currentCpu, freeDisk, freeMemory, connectTimeTcp, 
	bandwidthTcp, latencyTcp, fsreadSpeed, fswriteSpeed ,upTime,
	startTime, memorySpeed 
} MeasuredResources;


/*
 * The result of invoking a skill: a measured resource, the options that apply
 * to the measurement, an indication of whether or not the measurement
 * succeeded, and, if it did, the actual measurement value.  Note that we're
 * assuming here that all resource measurements can be expressed in one double
 * value.  This is presently true, but may need to be revisited.
 */
typedef struct {
	MeasuredResources resource;
	char *options;
	int succeeded;
	double measurement;
} SkillResult;


/**
 * A convenience function that scans #options# for a setting for #name#.
 * if there are multiple settings, a comma separated lists of the
 * settings is returned.  * #options# is a tab separated list of
 * name:value. 
 * Returns the associated value if found, else #defaultValue#.  
 *
 * The return value needs to be freed.
 */
char *
GetOptionValue(const char *options,
               const char *name,
               const char *defaultValue);


/**
 * Returns a unit label for use when registering series of #resource#.
 */
const char *
ResourceLabel(MeasuredResources resource);


/**
 * Returns a string representation of #resource#. 
 */
const char *
ResourceName(MeasuredResources resource);


/**
 * Returns 1 or 0 depending on whether or not the system supports conducting
 * #skill# experiments configured by #options# for the specific #control#.
 *
 * ALL_CONTROLS is the number of control supported by NWS.
 */
#define ALL_CONTROLS 2
#define PERIODIC_CONTROL 0
#define CLIQUE_CONTROL 1
int
SkillAvailableForControl(	KnownSkills skill,
				const char *options,
				int control);
#define SkillAvailable(skill, options) \
	SkillAvailableForControl(skill, options, ALL_CONTROLS)


/*
** Returns a string representation of #skill#.  The return value is volatile
** and will be overwritten by subsequent calls.
*/
const char *
SkillName(KnownSkills skill);


/**
 * Draws from the tab-delimited list #options# the subset that applies to
 * #skill#. If the same option is specified multpile time (ie nice:0
 * nice:1) the resulting option will have all the values comma separated
 * (nice:0,1).  Returns the result in #len#-length #toWhere#.
 */
void
SkillOptions(	KnownSkills skill,
		const char *options,
		char *toWhere,
		int len);


/**
 * Returns the format of #option# (for example 0_to_1_int) or NULL if no
 * option was found. The return value need to be freed.
 */
char *
SkillOptionFormat(const char *option);

/**
 * Returns the system default for #option# and #skill# or NULL if no
 * defaults are available. The return value needs to be freed by the
 * caller.
 */
char *
SkillOptionDefault(	const KnownSkills skill,
			const char *option);

/**
 * Returns the list of options (comma separates) supported by #skill# or
 * NULL in case of error or no options.
 */
const char *
SkillSupportedOptions(const KnownSkills skill);


/**
 * Returns a pointer to the list of resources measured by #skill# in
 * #resources# and its length in #length#. #resources# can be NULL (in
 * which case no MeasuredResources are returned) but #length cannot.
 *
 * Returns 1 on success, 0 on failure.
 */
int
SkillResources(KnownSkills skill,
               const MeasuredResources **resources,
               int *length);


/**
 * Prepares the skill module for use. #options# is a list of options
 * in the form of option:value tab delimited (most notably fork:yes or
 * fork:no will be passed). Returns 1 if successful, else 0. 
 */
int
SkillsInit(	const char *options);


/**
 * Free the memory associate with #results#. There are #howMany# results.
 */
void
FreeSkillResults(	int howMany,
			SkillResult **results);

/**
 * Attempts to conduct #skill# experiments configured by #options#.  Returns
 * the results of the experiments in the array #results# and the length of this
 * array in #length#.  Returns failure results if the skill does not complete
 * within #timeOut# seconds (-1 means automatic timeouts). #results# need
 * to be freed with FreeSkillResults.
 */
void
UseSkill(KnownSkills skill,
         const char *options,
         double timeOut,
         SkillResult **results,
         int *length);


/**
 * This is used only by experiments writer: append a result to
 * #length#-long #results# and adjust #length# accordingly (so you better
 * start #length# from 0).
 * The result (#measurement#) is been taken for #resource#, with the
 * #options#, and if #succeeded# is 1 the experiment succeeded. 
 */
void
AppendResult(	MeasuredResources resource,
		const char *options,
		int succeeded,
		double measurement,
		int *length,
		SkillResult **results);

/**
 * Sends the SKILL_EXPERIMENT to sensor #cookie#, asking it to execute
 * UseSkill. #opts# contains a \t delimited list of options, one of
 * which needs to be a skillName. The function can wait #tout# seconds
 * for the results. If succesful returns 1, and the ResourceName in
 * #resources# and the results in #results# with #howMany# telling how
 * many results there are. Every entry in #resources# needs to be freed,
 * while #d# needs to be allocated by the caller. 
 */
int
RemoteUseSkill(	struct host_cookie *cookie,
		char *opts,
		double timeout,
		char ***resources,
		double *d,
		int *howMany);


#ifdef __cplusplus
}
#endif

#endif