-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbtrecordmodule.c
More file actions
137 lines (106 loc) · 3.38 KB
/
btrecordmodule.c
File metadata and controls
137 lines (106 loc) · 3.38 KB
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
/*
* Python interface to btrecord
*
* Author: Joshua Root <jmr@gelato.unsw.edu.au>
*
* Copyright (C) 2007,2008 The University of New South Wales
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "Python.h"
#include "list.h"
#include "btrecord.h"
static PyObject *ErrorObject;
/* ----------------------------------------------------- */
static char btrecordmodule_setOutFile__doc__[] =
""
;
struct io_stream *stream;
struct ifile_info *iip;
extern struct list_head input_files;
static PyObject *
btrecordmodule_setOutFile(PyObject *self /* Not used */, PyObject *args)
{
iip = malloc(sizeof(struct ifile_info));
if (!iip)
return PyErr_NoMemory();
if (!PyArg_ParseTuple(args, "ss", &iip->file_name, &iip->devnm))
return NULL;
iip->cpu = 0;
iip->tpkts = 0;
iip->genesis = 0;
list_add_tail(&iip->head, &input_files);
stream = stream_open(iip);
Py_INCREF(Py_None);
return Py_None;
}
static char btrecordmodule_addOp__doc__[] =
""
;
static PyObject *
btrecordmodule_addOp(PyObject *self /* Not used */, PyObject *args)
{
struct io_spec spec;
if (!PyArg_ParseTuple(args, "iIKK", &spec.rw, &spec.bytes,
&spec.sector, &spec.time))
return NULL;
spec.rw = !spec.rw;
/* printf("spec=%d,%u,%llu,%llu\n", spec.rw, spec.bytes, spec.sector,
spec.time); */
stream_add_io(stream, &spec);
Py_INCREF(Py_None);
return Py_None;
}
static char btrecordmodule_done__doc__[] =
""
;
static PyObject *
btrecordmodule_done(PyObject *self /* Not used */, PyObject *args)
{
if (!PyArg_ParseTuple(args, ""))
return NULL;
stream_close(stream);
free(iip);
Py_INCREF(Py_None);
return Py_None;
}
/* List of methods defined in the module */
static struct PyMethodDef btrecordmodule_methods[] = {
{"setOutFile", (PyCFunction)btrecordmodule_setOutFile, METH_VARARGS, btrecordmodule_setOutFile__doc__},
{"addOp", (PyCFunction)btrecordmodule_addOp, METH_VARARGS, btrecordmodule_addOp__doc__},
{"done", (PyCFunction)btrecordmodule_done, METH_VARARGS, btrecordmodule_done__doc__},
{NULL, (PyCFunction)NULL, 0, NULL} /* sentinel */
};
/* Initialization function for the module (*must* be called initbtrecord) */
static char btrecord_module_documentation[] =
""
;
void
initbtrecord()
{
PyObject *m, *d;
/* Create the module and add the functions */
m = Py_InitModule4("btrecord", btrecordmodule_methods,
btrecord_module_documentation,
(PyObject*)NULL,PYTHON_API_VERSION);
/* Add some symbolic constants to the module */
d = PyModule_GetDict(m);
ErrorObject = PyString_FromString("btrecord.error");
PyDict_SetItemString(d, "error", ErrorObject);
/* XXXX Add constants here */
/* Check for errors */
if (PyErr_Occurred())
Py_FatalError("can't initialize module btrecord");
}