rb-wartslib 0.9.10
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +6 -0
- data/COPYING +340 -0
- data/README +79 -0
- data/bin/analyze-order +37 -0
- data/bin/scdump +101 -0
- data/bin/wdump +81 -0
- data/ext/extconf.rb +32 -0
- data/ext/scaddr.c +223 -0
- data/ext/scaddr.h +32 -0
- data/ext/scext.c +52 -0
- data/ext/scfile.c +688 -0
- data/ext/scfile.h +29 -0
- data/ext/sclist.c +632 -0
- data/ext/sclist.h +34 -0
- data/ext/sctrace.c +873 -0
- data/ext/sctrace.h +35 -0
- data/lib/wartslib.rb +27 -0
- data/lib/wartslib/wl-file.rb +85 -0
- data/lib/wartslib/wl-trace.rb +111 -0
- metadata +67 -0
data/ext/scfile.h
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
/*
|
2
|
+
** Ruby bindings to scamper file operations in scamper_file.c.
|
3
|
+
**
|
4
|
+
** --------------------------------------------------------------------------
|
5
|
+
** Copyright (C) 2007 The Regents of the University of California.
|
6
|
+
**
|
7
|
+
** This program is free software; you can redistribute it and/or modify
|
8
|
+
** it under the terms of the GNU General Public License as published by
|
9
|
+
** the Free Software Foundation; either version 2 of the License, or
|
10
|
+
** (at your option) any later version.
|
11
|
+
**
|
12
|
+
** This program is distributed in the hope that it will be useful,
|
13
|
+
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14
|
+
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
15
|
+
** GNU General Public License for more details.
|
16
|
+
**
|
17
|
+
** You should have received a copy of the GNU General Public License
|
18
|
+
** along with this program; if not, write to the Free Software
|
19
|
+
** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
20
|
+
**
|
21
|
+
** $Id: scfile.h,v 1.2 2007/11/29 01:32:24 youngh Exp $
|
22
|
+
**/
|
23
|
+
|
24
|
+
#ifndef __SCFILE_H
|
25
|
+
#define __SCFILE_H
|
26
|
+
|
27
|
+
void Init_scfile(void);
|
28
|
+
|
29
|
+
#endif # __SCFILE_H
|
data/ext/sclist.c
ADDED
@@ -0,0 +1,632 @@
|
|
1
|
+
/*
|
2
|
+
** Ruby bindings to scamper_list_t and scamper_cycle_t.
|
3
|
+
**
|
4
|
+
** --------------------------------------------------------------------------
|
5
|
+
** Copyright (C) 2007 The Regents of the University of California.
|
6
|
+
**
|
7
|
+
** This program is free software; you can redistribute it and/or modify
|
8
|
+
** it under the terms of the GNU General Public License as published by
|
9
|
+
** the Free Software Foundation; either version 2 of the License, or
|
10
|
+
** (at your option) any later version.
|
11
|
+
**
|
12
|
+
** This program is distributed in the hope that it will be useful,
|
13
|
+
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14
|
+
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
15
|
+
** GNU General Public License for more details.
|
16
|
+
**
|
17
|
+
** You should have received a copy of the GNU General Public License
|
18
|
+
** along with this program; if not, write to the Free Software
|
19
|
+
** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
20
|
+
**
|
21
|
+
** $Id: sclist.c,v 1.10 2007/11/29 01:42:07 youngh Exp $
|
22
|
+
**/
|
23
|
+
|
24
|
+
#include <stdlib.h>
|
25
|
+
#include <string.h>
|
26
|
+
#include "ruby.h"
|
27
|
+
|
28
|
+
#if defined(__HAVE_STDINT_H__)
|
29
|
+
#include <stdint.h>
|
30
|
+
#endif
|
31
|
+
|
32
|
+
#include "scamper_file.h"
|
33
|
+
|
34
|
+
#include "sclist.h"
|
35
|
+
|
36
|
+
extern VALUE mWarts;
|
37
|
+
|
38
|
+
static VALUE cList;
|
39
|
+
VALUE cCycle; /* Don't make this static, since it's referenced from scfile.c.*/
|
40
|
+
|
41
|
+
static ID iv_element_type, iv_list;
|
42
|
+
static ID meth_write_cycle_start, meth_write_cycle_stop;
|
43
|
+
static VALUE sym_type, sym_id, sym_start_time, sym_stop_time, sym_hostname;
|
44
|
+
static VALUE sym_list, sym_name, sym_descr, sym_monitor;
|
45
|
+
|
46
|
+
/*-------------------------------------------------------------------------*/
|
47
|
+
|
48
|
+
#define EXTRACT_STR_OPTION(object, opt) \
|
49
|
+
option = rb_hash_aref(options, sym_##opt); \
|
50
|
+
if (NIL_P(option)) { \
|
51
|
+
opt = object->opt; \
|
52
|
+
} \
|
53
|
+
else { \
|
54
|
+
StringValue(option); \
|
55
|
+
opt = RSTRING(option)->ptr; \
|
56
|
+
}
|
57
|
+
|
58
|
+
|
59
|
+
/*-------------------------------------------------------------------------*/
|
60
|
+
|
61
|
+
#define LIST_DEF_ATTR(name) \
|
62
|
+
rb_define_method(cList, #name, sclist_attr_##name, 0);
|
63
|
+
|
64
|
+
#define LIST_NUM_ATTR_FIELD_FUN(name,field) \
|
65
|
+
static VALUE sclist_attr_##name(VALUE self) \
|
66
|
+
{ \
|
67
|
+
scamper_list_t *list; \
|
68
|
+
Data_Get_Struct(self, scamper_list_t, list); \
|
69
|
+
return UINT2NUM(list->field); \
|
70
|
+
}
|
71
|
+
|
72
|
+
#define LIST_NUM_ATTR_FUN(name) LIST_NUM_ATTR_FIELD_FUN(name,name)
|
73
|
+
|
74
|
+
|
75
|
+
#define LIST_STR_ATTR_FIELD_FUN(name,field) \
|
76
|
+
static VALUE sclist_attr_##name(VALUE self) \
|
77
|
+
{ \
|
78
|
+
scamper_list_t *list; \
|
79
|
+
char *ptr; \
|
80
|
+
Data_Get_Struct(self, scamper_list_t, list); \
|
81
|
+
ptr = list->field; \
|
82
|
+
ptr = (ptr ? ptr : ""); \
|
83
|
+
return rb_str_new2(ptr); \
|
84
|
+
}
|
85
|
+
|
86
|
+
#define LIST_STR_ATTR_FUN(name) LIST_STR_ATTR_FIELD_FUN(name,name)
|
87
|
+
|
88
|
+
|
89
|
+
LIST_NUM_ATTR_FUN(id);
|
90
|
+
LIST_STR_ATTR_FUN(name);
|
91
|
+
LIST_STR_ATTR_FUN(descr);
|
92
|
+
LIST_STR_ATTR_FUN(monitor);
|
93
|
+
|
94
|
+
|
95
|
+
/***************************************************************************/
|
96
|
+
|
97
|
+
static void sclist_free(void *data)
|
98
|
+
{
|
99
|
+
if (data) {
|
100
|
+
scamper_list_free((scamper_list_t *)data);
|
101
|
+
}
|
102
|
+
}
|
103
|
+
|
104
|
+
static VALUE sclist_alloc(VALUE klass)
|
105
|
+
{
|
106
|
+
return Data_Wrap_Struct(klass, 0, sclist_free, 0);
|
107
|
+
}
|
108
|
+
|
109
|
+
|
110
|
+
static VALUE sclist_init(VALUE self)
|
111
|
+
{
|
112
|
+
rb_ivar_set(self, iv_element_type, INT2FIX(SCAMPER_FILE_OBJ_LIST));
|
113
|
+
return self;
|
114
|
+
}
|
115
|
+
|
116
|
+
|
117
|
+
static VALUE sclist_cmp(VALUE self, VALUE other)
|
118
|
+
{
|
119
|
+
scamper_list_t *self_list;
|
120
|
+
scamper_list_t *other_list;
|
121
|
+
|
122
|
+
if (other == self) {
|
123
|
+
return INT2FIX(0);
|
124
|
+
}
|
125
|
+
|
126
|
+
/* See Pragmatic Programmer's book. */
|
127
|
+
if (TYPE(other) != T_DATA || RDATA(other)->dfree != sclist_free) {
|
128
|
+
rb_raise(rb_eTypeError, "wrong argument type");
|
129
|
+
}
|
130
|
+
|
131
|
+
Data_Get_Struct(self, scamper_list_t, self_list);
|
132
|
+
Data_Get_Struct(other, scamper_list_t, other_list);
|
133
|
+
|
134
|
+
return INT2FIX(self_list->id < other_list->id ? -1
|
135
|
+
: (self_list->id > other_list->id ? 1 : 0));
|
136
|
+
}
|
137
|
+
|
138
|
+
|
139
|
+
static VALUE sclist_write_to(VALUE self, VALUE file)
|
140
|
+
{
|
141
|
+
return self; /* nothing to do: users shouldn't write lists themselves */
|
142
|
+
}
|
143
|
+
|
144
|
+
|
145
|
+
static VALUE sclist_derive(int argc, VALUE *argv, VALUE self)
|
146
|
+
{
|
147
|
+
scamper_list_t *self_list;
|
148
|
+
scamper_list_t *list;
|
149
|
+
VALUE options, option;
|
150
|
+
unsigned int id;
|
151
|
+
char* name;
|
152
|
+
char* descr;
|
153
|
+
char* monitor;
|
154
|
+
VALUE retval;
|
155
|
+
|
156
|
+
if (rb_scan_args(argc, argv, "01", &options) == 0) {
|
157
|
+
options = rb_hash_new();
|
158
|
+
}
|
159
|
+
|
160
|
+
Data_Get_Struct(self, scamper_list_t, self_list);
|
161
|
+
|
162
|
+
if (TYPE(options) != T_HASH) {
|
163
|
+
rb_raise(rb_eTypeError, "wrong argument type -- expected hash");
|
164
|
+
}
|
165
|
+
|
166
|
+
option = rb_hash_aref(options, sym_id);
|
167
|
+
id = (NIL_P(option) ? self_list->id : NUM2UINT(option));
|
168
|
+
|
169
|
+
EXTRACT_STR_OPTION(self_list, name);
|
170
|
+
EXTRACT_STR_OPTION(self_list, descr);
|
171
|
+
EXTRACT_STR_OPTION(self_list, monitor);
|
172
|
+
|
173
|
+
list = scamper_list_alloc(id, name, descr, monitor);
|
174
|
+
if (!list) {
|
175
|
+
return Qnil;
|
176
|
+
}
|
177
|
+
|
178
|
+
retval = Data_Wrap_Struct(cList, 0, sclist_free, list);
|
179
|
+
if (NIL_P(sclist_init(retval))) {
|
180
|
+
scamper_list_free(list);
|
181
|
+
return Qnil;
|
182
|
+
}
|
183
|
+
|
184
|
+
return retval;
|
185
|
+
}
|
186
|
+
|
187
|
+
|
188
|
+
static VALUE sclist_s_create(VALUE klass, VALUE options)
|
189
|
+
{
|
190
|
+
scamper_list_t *list;
|
191
|
+
VALUE option;
|
192
|
+
unsigned int id;
|
193
|
+
char* name;
|
194
|
+
char* descr;
|
195
|
+
char* monitor;
|
196
|
+
VALUE retval;
|
197
|
+
|
198
|
+
if (TYPE(options) != T_HASH) {
|
199
|
+
rb_raise(rb_eTypeError, "wrong argument type -- expected hash");
|
200
|
+
}
|
201
|
+
|
202
|
+
option = rb_hash_aref(options, sym_id);
|
203
|
+
id = (NIL_P(option) ? 0 : NUM2UINT(option));
|
204
|
+
|
205
|
+
EXTRACT_STR_OPTION(list, name);
|
206
|
+
EXTRACT_STR_OPTION(list, descr);
|
207
|
+
EXTRACT_STR_OPTION(list, monitor);
|
208
|
+
|
209
|
+
list = scamper_list_alloc(id, name, descr, monitor);
|
210
|
+
if (!list) {
|
211
|
+
return Qnil;
|
212
|
+
}
|
213
|
+
|
214
|
+
retval = Data_Wrap_Struct(cList, 0, sclist_free, list);
|
215
|
+
if (NIL_P(sclist_init(retval))) {
|
216
|
+
scamper_list_free(list);
|
217
|
+
return Qnil;
|
218
|
+
}
|
219
|
+
|
220
|
+
return retval;
|
221
|
+
}
|
222
|
+
|
223
|
+
|
224
|
+
/*-------------------------------------------------------------------------*/
|
225
|
+
|
226
|
+
VALUE sclist_create(scamper_list_t *list)
|
227
|
+
{
|
228
|
+
VALUE obj = Data_Wrap_Struct(cList, 0, sclist_free, list);
|
229
|
+
|
230
|
+
if (NIL_P(sclist_init(obj))) {
|
231
|
+
return Qnil;
|
232
|
+
}
|
233
|
+
|
234
|
+
return obj;
|
235
|
+
}
|
236
|
+
|
237
|
+
|
238
|
+
/***************************************************************************/
|
239
|
+
/***************************************************************************/
|
240
|
+
|
241
|
+
void Init_sclist(void)
|
242
|
+
{
|
243
|
+
ID private_class_method_ID, private_ID;
|
244
|
+
ID new_ID, dup_ID, clone_ID;
|
245
|
+
|
246
|
+
iv_element_type = rb_intern("@element_type");
|
247
|
+
|
248
|
+
sym_id = ID2SYM(rb_intern("id"));
|
249
|
+
sym_name = ID2SYM(rb_intern("name"));
|
250
|
+
sym_descr = ID2SYM(rb_intern("descr"));
|
251
|
+
sym_monitor = ID2SYM(rb_intern("monitor"));
|
252
|
+
|
253
|
+
cList = rb_define_class_under(mWarts, "List", rb_cObject);
|
254
|
+
|
255
|
+
rb_include_module(cList, rb_mComparable);
|
256
|
+
|
257
|
+
rb_define_singleton_method(cList, "create", sclist_s_create, 1);
|
258
|
+
|
259
|
+
rb_define_alloc_func(cList, sclist_alloc);
|
260
|
+
|
261
|
+
LIST_DEF_ATTR(id);
|
262
|
+
LIST_DEF_ATTR(name);
|
263
|
+
LIST_DEF_ATTR(descr);
|
264
|
+
LIST_DEF_ATTR(monitor);
|
265
|
+
|
266
|
+
rb_define_attr(cList, "element_type", 1, 0);
|
267
|
+
|
268
|
+
rb_define_method(cList, "initialize", sclist_init, 0);
|
269
|
+
rb_define_method(cList, "derive", sclist_derive, -1);
|
270
|
+
rb_define_method(cList, "<=>", sclist_cmp, 1);
|
271
|
+
rb_define_method(cList, "write_to", sclist_write_to, 1);
|
272
|
+
|
273
|
+
private_class_method_ID = rb_intern("private_class_method");
|
274
|
+
private_ID = rb_intern("private");
|
275
|
+
new_ID = rb_intern("new");
|
276
|
+
dup_ID = rb_intern("dup");
|
277
|
+
clone_ID = rb_intern("clone");
|
278
|
+
|
279
|
+
rb_funcall(cList, private_class_method_ID, 1, ID2SYM(new_ID));
|
280
|
+
rb_funcall(cList, private_ID, 1, ID2SYM(dup_ID));
|
281
|
+
rb_funcall(cList, private_ID, 1, ID2SYM(clone_ID));
|
282
|
+
}
|
283
|
+
|
284
|
+
|
285
|
+
/*=========================================================================*/
|
286
|
+
/*=========================================================================*/
|
287
|
+
|
288
|
+
#define CYCLE_DEF_ATTR(name) \
|
289
|
+
rb_define_method(cCycle, #name, sccycle_attr_##name, 0);
|
290
|
+
|
291
|
+
#define CYCLE_NUM_ATTR_FIELD_FUN(name,field) \
|
292
|
+
static VALUE sccycle_attr_##name(VALUE self) \
|
293
|
+
{ \
|
294
|
+
scamper_cycle_t *cycle; \
|
295
|
+
Data_Get_Struct(self, scamper_cycle_t, cycle); \
|
296
|
+
return UINT2NUM(cycle->field); \
|
297
|
+
}
|
298
|
+
|
299
|
+
#define CYCLE_NUM_ATTR_FUN(name) CYCLE_NUM_ATTR_FIELD_FUN(name,name)
|
300
|
+
|
301
|
+
|
302
|
+
#define CYCLE_STR_ATTR_FIELD_FUN(name,field) \
|
303
|
+
static VALUE sccycle_attr_##name(VALUE self) \
|
304
|
+
{ \
|
305
|
+
scamper_cycle_t *cycle; \
|
306
|
+
char *ptr; \
|
307
|
+
Data_Get_Struct(self, scamper_cycle_t, cycle); \
|
308
|
+
ptr = cycle->field; \
|
309
|
+
ptr = (ptr ? ptr : ""); \
|
310
|
+
return rb_str_new2(ptr); \
|
311
|
+
}
|
312
|
+
|
313
|
+
#define CYCLE_STR_ATTR_FUN(name) CYCLE_STR_ATTR_FIELD_FUN(name,name)
|
314
|
+
|
315
|
+
|
316
|
+
CYCLE_NUM_ATTR_FUN(id);
|
317
|
+
CYCLE_NUM_ATTR_FUN(start_time);
|
318
|
+
CYCLE_NUM_ATTR_FUN(stop_time);
|
319
|
+
CYCLE_STR_ATTR_FUN(hostname);
|
320
|
+
|
321
|
+
|
322
|
+
/*-------------------------------------------------------------------------*/
|
323
|
+
|
324
|
+
#define CYCLE_DEF_QUERY(name) \
|
325
|
+
rb_define_method(cCycle, #name "?", sccycle_query_##name, 0);
|
326
|
+
|
327
|
+
#define CYCLE_QUERY_FUN(name,macro) \
|
328
|
+
static VALUE sccycle_query_##name(VALUE self) \
|
329
|
+
{ \
|
330
|
+
VALUE type = rb_ivar_get(self, iv_element_type); \
|
331
|
+
return (type == INT2FIX(SCAMPER_FILE_OBJ_CYCLE_##macro) ? Qtrue: Qfalse); \
|
332
|
+
}
|
333
|
+
|
334
|
+
CYCLE_QUERY_FUN(start, START);
|
335
|
+
CYCLE_QUERY_FUN(def, DEF);
|
336
|
+
CYCLE_QUERY_FUN(stop, STOP);
|
337
|
+
|
338
|
+
|
339
|
+
/***************************************************************************/
|
340
|
+
|
341
|
+
/*
|
342
|
+
** NOTE: Don't make this function static, since we use it for type checking
|
343
|
+
** in sctrace.c. It's a bit ugly to expose this, but thus is life...
|
344
|
+
*/
|
345
|
+
void sccycle_free(void *data)
|
346
|
+
{
|
347
|
+
if (data) {
|
348
|
+
scamper_cycle_free((scamper_cycle_t *)data);
|
349
|
+
}
|
350
|
+
}
|
351
|
+
|
352
|
+
static VALUE sccycle_alloc(VALUE klass)
|
353
|
+
{
|
354
|
+
return Data_Wrap_Struct(klass, 0, sccycle_free, 0);
|
355
|
+
}
|
356
|
+
|
357
|
+
|
358
|
+
/* {type} should be one of SCAMPER_FILE_OBJ_CYCLE_{START,DEF,STOP}. */
|
359
|
+
static VALUE sccycle_init(VALUE self, VALUE type)
|
360
|
+
{
|
361
|
+
rb_ivar_set(self, iv_element_type, type);
|
362
|
+
return self;
|
363
|
+
}
|
364
|
+
|
365
|
+
|
366
|
+
static VALUE sccycle_cmp(VALUE self, VALUE other)
|
367
|
+
{
|
368
|
+
scamper_cycle_t *self_cycle;
|
369
|
+
scamper_cycle_t *other_cycle;
|
370
|
+
|
371
|
+
if (other == self) {
|
372
|
+
return INT2FIX(0);
|
373
|
+
}
|
374
|
+
|
375
|
+
/* See Pragmatic Programmer's book. */
|
376
|
+
if (TYPE(other) != T_DATA || RDATA(other)->dfree != sccycle_free) {
|
377
|
+
rb_raise(rb_eTypeError, "wrong argument type");
|
378
|
+
}
|
379
|
+
|
380
|
+
Data_Get_Struct(self, scamper_cycle_t, self_cycle);
|
381
|
+
Data_Get_Struct(other, scamper_cycle_t, other_cycle);
|
382
|
+
|
383
|
+
return INT2FIX(self_cycle->id < other_cycle->id ? -1
|
384
|
+
: (self_cycle->id > other_cycle->id ? 1 : 0));
|
385
|
+
}
|
386
|
+
|
387
|
+
|
388
|
+
static VALUE sccycle_write_to(VALUE self, VALUE file)
|
389
|
+
{
|
390
|
+
scamper_cycle_t *cycle;
|
391
|
+
int type;
|
392
|
+
|
393
|
+
Data_Get_Struct(self, scamper_cycle_t, cycle);
|
394
|
+
|
395
|
+
type = FIX2INT(rb_ivar_get(self, iv_element_type));
|
396
|
+
if (type == SCAMPER_FILE_OBJ_CYCLE_START) {
|
397
|
+
rb_funcall(file, meth_write_cycle_start, 1, self);
|
398
|
+
}
|
399
|
+
else if (type == SCAMPER_FILE_OBJ_CYCLE_STOP) {
|
400
|
+
rb_funcall(file, meth_write_cycle_stop, 1, self);
|
401
|
+
}
|
402
|
+
/* else type == SCAMPER_FILE_OBJ_CYCLE_DEF; ignore */
|
403
|
+
|
404
|
+
return self;
|
405
|
+
}
|
406
|
+
|
407
|
+
|
408
|
+
static VALUE sccycle_list(VALUE self)
|
409
|
+
{
|
410
|
+
scamper_cycle_t *cycle;
|
411
|
+
VALUE retval;
|
412
|
+
|
413
|
+
retval = rb_ivar_get(self, iv_list);
|
414
|
+
if (NIL_P(retval)) {
|
415
|
+
Data_Get_Struct(self, scamper_cycle_t, cycle);
|
416
|
+
|
417
|
+
retval = sclist_create(scamper_list_use(cycle->list));
|
418
|
+
rb_ivar_set(self, iv_list, retval);
|
419
|
+
}
|
420
|
+
return retval;
|
421
|
+
}
|
422
|
+
|
423
|
+
|
424
|
+
static VALUE sccycle_derive(int argc, VALUE *argv, VALUE self)
|
425
|
+
{
|
426
|
+
scamper_cycle_t *self_cycle;
|
427
|
+
scamper_list_t *list;
|
428
|
+
scamper_cycle_t *cycle;
|
429
|
+
VALUE options, option;
|
430
|
+
int type;
|
431
|
+
unsigned int id;
|
432
|
+
unsigned int start_time, stop_time;
|
433
|
+
char* hostname;
|
434
|
+
VALUE retval;
|
435
|
+
|
436
|
+
if (rb_scan_args(argc, argv, "01", &options) == 0) {
|
437
|
+
options = rb_hash_new();
|
438
|
+
}
|
439
|
+
|
440
|
+
Data_Get_Struct(self, scamper_cycle_t, self_cycle);
|
441
|
+
|
442
|
+
if (TYPE(options) != T_HASH) {
|
443
|
+
rb_raise(rb_eTypeError, "wrong argument type -- expected hash");
|
444
|
+
}
|
445
|
+
|
446
|
+
option = rb_hash_aref(options, sym_list);
|
447
|
+
if (NIL_P(option)) {
|
448
|
+
list = self_cycle->list;
|
449
|
+
}
|
450
|
+
else {
|
451
|
+
/* See Pragmatic Programmer's book. */
|
452
|
+
if (TYPE(option) != T_DATA || RDATA(option)->dfree != sclist_free) {
|
453
|
+
rb_raise(rb_eTypeError, "wrong list argument type");
|
454
|
+
}
|
455
|
+
|
456
|
+
Data_Get_Struct(option, scamper_list_t, list);
|
457
|
+
}
|
458
|
+
|
459
|
+
option = rb_hash_aref(options, sym_type);
|
460
|
+
if (NIL_P(option)) {
|
461
|
+
type = FIX2INT(rb_ivar_get(self, iv_element_type));
|
462
|
+
}
|
463
|
+
else {
|
464
|
+
type = NUM2INT(option);
|
465
|
+
if (type < SCAMPER_FILE_OBJ_CYCLE_START
|
466
|
+
|| type > SCAMPER_FILE_OBJ_CYCLE_STOP) {
|
467
|
+
rb_raise(rb_eArgError, "invalid cycle type");
|
468
|
+
}
|
469
|
+
}
|
470
|
+
|
471
|
+
option = rb_hash_aref(options, sym_id);
|
472
|
+
id = (NIL_P(option) ? self_cycle->id : NUM2UINT(option));
|
473
|
+
|
474
|
+
option = rb_hash_aref(options, sym_start_time);
|
475
|
+
start_time = (NIL_P(option) ? self_cycle->start_time : NUM2UINT(option));
|
476
|
+
|
477
|
+
option = rb_hash_aref(options, sym_stop_time);
|
478
|
+
stop_time = (NIL_P(option) ? self_cycle->stop_time : NUM2UINT(option));
|
479
|
+
|
480
|
+
EXTRACT_STR_OPTION(self_cycle, hostname);
|
481
|
+
|
482
|
+
cycle = scamper_cycle_alloc(list);
|
483
|
+
if (!cycle) {
|
484
|
+
return Qnil;
|
485
|
+
}
|
486
|
+
|
487
|
+
cycle->id = id;
|
488
|
+
cycle->start_time = start_time;
|
489
|
+
cycle->stop_time = stop_time;
|
490
|
+
cycle->hostname = strdup(hostname);
|
491
|
+
|
492
|
+
retval = Data_Wrap_Struct(cCycle, 0, sccycle_free, cycle);
|
493
|
+
if (NIL_P(sccycle_init(retval, INT2FIX(type)))) {
|
494
|
+
scamper_cycle_free(cycle);
|
495
|
+
return Qnil;
|
496
|
+
}
|
497
|
+
|
498
|
+
return retval;
|
499
|
+
}
|
500
|
+
|
501
|
+
|
502
|
+
static VALUE sccycle_s_create(VALUE klass, VALUE list_value, VALUE options)
|
503
|
+
{
|
504
|
+
scamper_list_t *list;
|
505
|
+
scamper_cycle_t *cycle;
|
506
|
+
VALUE option;
|
507
|
+
int type;
|
508
|
+
unsigned int id;
|
509
|
+
unsigned int start_time, stop_time;
|
510
|
+
char* hostname;
|
511
|
+
VALUE retval;
|
512
|
+
|
513
|
+
/* See Pragmatic Programmer's book. */
|
514
|
+
if (TYPE(list_value) != T_DATA || RDATA(list_value)->dfree != sclist_free) {
|
515
|
+
rb_raise(rb_eTypeError, "wrong list argument type");
|
516
|
+
}
|
517
|
+
|
518
|
+
Data_Get_Struct(list_value, scamper_list_t, list);
|
519
|
+
|
520
|
+
if (TYPE(options) != T_HASH) {
|
521
|
+
rb_raise(rb_eTypeError, "wrong options argument type -- expected hash");
|
522
|
+
}
|
523
|
+
|
524
|
+
option = rb_hash_aref(options, sym_type);
|
525
|
+
type = (NIL_P(option) ? SCAMPER_FILE_OBJ_CYCLE_START : NUM2INT(option));
|
526
|
+
if (type < SCAMPER_FILE_OBJ_CYCLE_START
|
527
|
+
|| type > SCAMPER_FILE_OBJ_CYCLE_STOP) {
|
528
|
+
rb_raise(rb_eArgError, "invalid cycle type");
|
529
|
+
}
|
530
|
+
|
531
|
+
option = rb_hash_aref(options, sym_id);
|
532
|
+
id = (NIL_P(option) ? 0 : NUM2UINT(option));
|
533
|
+
|
534
|
+
option = rb_hash_aref(options, sym_start_time);
|
535
|
+
start_time = (NIL_P(option) ? 0 : NUM2UINT(option));
|
536
|
+
|
537
|
+
option = rb_hash_aref(options, sym_stop_time);
|
538
|
+
stop_time = (NIL_P(option) ? 0 : NUM2UINT(option));
|
539
|
+
|
540
|
+
EXTRACT_STR_OPTION(cycle, hostname);
|
541
|
+
|
542
|
+
cycle = scamper_cycle_alloc(list);
|
543
|
+
if (!cycle) {
|
544
|
+
return Qnil;
|
545
|
+
}
|
546
|
+
|
547
|
+
cycle->id = id;
|
548
|
+
cycle->start_time = start_time;
|
549
|
+
cycle->stop_time = stop_time;
|
550
|
+
cycle->hostname = strdup(hostname);
|
551
|
+
|
552
|
+
retval = Data_Wrap_Struct(cCycle, 0, sccycle_free, cycle);
|
553
|
+
if (NIL_P(sccycle_init(retval, INT2FIX(type)))) {
|
554
|
+
scamper_cycle_free(cycle);
|
555
|
+
return Qnil;
|
556
|
+
}
|
557
|
+
|
558
|
+
return retval;
|
559
|
+
}
|
560
|
+
|
561
|
+
|
562
|
+
/*-------------------------------------------------------------------------*/
|
563
|
+
|
564
|
+
/* {type} should be one of SCAMPER_FILE_OBJ_CYCLE_{START,DEF,STOP}. */
|
565
|
+
VALUE sccycle_create(scamper_cycle_t *cycle, int type)
|
566
|
+
{
|
567
|
+
VALUE obj = Data_Wrap_Struct(cCycle, 0, sccycle_free, cycle);
|
568
|
+
|
569
|
+
if (NIL_P(sccycle_init(obj, INT2FIX(type)))) {
|
570
|
+
return Qnil;
|
571
|
+
}
|
572
|
+
|
573
|
+
return obj;
|
574
|
+
}
|
575
|
+
|
576
|
+
|
577
|
+
/***************************************************************************/
|
578
|
+
/***************************************************************************/
|
579
|
+
|
580
|
+
void Init_sccycle(void)
|
581
|
+
{
|
582
|
+
ID private_class_method_ID, private_ID;
|
583
|
+
ID new_ID, dup_ID, clone_ID;
|
584
|
+
|
585
|
+
iv_element_type = rb_intern("@element_type");
|
586
|
+
iv_list = rb_intern("@list");
|
587
|
+
|
588
|
+
meth_write_cycle_start = rb_intern("write_cycle_start");
|
589
|
+
meth_write_cycle_stop = rb_intern("write_cycle_stop");
|
590
|
+
|
591
|
+
sym_type = ID2SYM(rb_intern("type"));
|
592
|
+
sym_id = ID2SYM(rb_intern("id"));
|
593
|
+
sym_start_time = ID2SYM(rb_intern("start_time"));
|
594
|
+
sym_stop_time = ID2SYM(rb_intern("stop_time"));
|
595
|
+
sym_hostname = ID2SYM(rb_intern("hostname"));
|
596
|
+
sym_list = ID2SYM(rb_intern("list"));
|
597
|
+
|
598
|
+
cCycle = rb_define_class_under(mWarts, "Cycle", rb_cObject);
|
599
|
+
|
600
|
+
rb_include_module(cCycle, rb_mComparable);
|
601
|
+
|
602
|
+
rb_define_singleton_method(cCycle, "create", sccycle_s_create, 2);
|
603
|
+
|
604
|
+
rb_define_alloc_func(cCycle, sccycle_alloc);
|
605
|
+
|
606
|
+
CYCLE_DEF_ATTR(id);
|
607
|
+
CYCLE_DEF_ATTR(start_time);
|
608
|
+
CYCLE_DEF_ATTR(stop_time);
|
609
|
+
CYCLE_DEF_ATTR(hostname);
|
610
|
+
|
611
|
+
CYCLE_DEF_QUERY(start);
|
612
|
+
CYCLE_DEF_QUERY(def);
|
613
|
+
CYCLE_DEF_QUERY(stop);
|
614
|
+
|
615
|
+
rb_define_attr(cCycle, "element_type", 1, 0);
|
616
|
+
|
617
|
+
rb_define_method(cCycle, "initialize", sccycle_init, 1);
|
618
|
+
rb_define_method(cCycle, "list", sccycle_list, 0);
|
619
|
+
rb_define_method(cCycle, "derive", sccycle_derive, -1);
|
620
|
+
rb_define_method(cCycle, "<=>", sccycle_cmp, 1);
|
621
|
+
rb_define_method(cCycle, "write_to", sccycle_write_to, 1);
|
622
|
+
|
623
|
+
private_class_method_ID = rb_intern("private_class_method");
|
624
|
+
private_ID = rb_intern("private");
|
625
|
+
new_ID = rb_intern("new");
|
626
|
+
dup_ID = rb_intern("dup");
|
627
|
+
clone_ID = rb_intern("clone");
|
628
|
+
|
629
|
+
rb_funcall(cCycle, private_class_method_ID, 1, ID2SYM(new_ID));
|
630
|
+
rb_funcall(cCycle, private_ID, 1, ID2SYM(dup_ID));
|
631
|
+
rb_funcall(cCycle, private_ID, 1, ID2SYM(clone_ID));
|
632
|
+
}
|