1 /***********************************************************
2 Copyright 1991-1995 by Stichting Mathematisch Centrum, Amsterdam,
7 Permission to use, copy, modify, and distribute this software and its
8 documentation for any purpose and without fee is hereby granted,
9 provided that the above copyright notice appear in all copies and that
10 both that copyright notice and this permission notice appear in
11 supporting documentation, and that the names of Stichting Mathematisch
12 Centrum or CWI not be used in advertising or publicity pertaining to
13 distribution of the software without specific, written prior permission.
15 STICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO
16 THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
17 FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE
18 FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
19 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
20 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
21 OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
23 ******************************************************************/
26 #include "InterslipLib.h"
29 static PyObject
*ErrorObject
;
31 /* ----------------------------------------------------- */
33 static char pyis_open__doc__
[] =
34 "Load the interslip driver (optional)"
39 PyObject
*self
; /* Not used */
44 if (!PyArg_ParseTuple(args
, ""))
48 PyErr_Mac(ErrorObject
, err
);
55 static char pyis_connect__doc__
[] =
56 "Tell the driver to start a connect"
60 pyis_connect(self
, args
)
61 PyObject
*self
; /* Not used */
66 if (!PyArg_ParseTuple(args
, ""))
70 PyErr_Mac(ErrorObject
, err
);
77 static char pyis_disconnect__doc__
[] =
78 "Tell the interslip driver to start a disconnect"
82 pyis_disconnect(self
, args
)
83 PyObject
*self
; /* Not used */
88 if (!PyArg_ParseTuple(args
, ""))
90 err
= is_disconnect();
92 PyErr_Mac(ErrorObject
, err
);
99 static char pyis_status__doc__
[] =
100 "Return (numeric_status, message_seqnum, message_string) status tuple"
104 pyis_status(self
, args
)
105 PyObject
*self
; /* Not used */
112 if (!PyArg_ParseTuple(args
, ""))
114 err
= is_status(&status
, &seqnum
, &message
);
116 PyErr_Mac(ErrorObject
, err
);
119 return Py_BuildValue("iiO&", (int)status
, (int)seqnum
, PyMac_BuildStr255
, message
);
122 static char pyis_getconfig__doc__
[] =
123 "Return configuration data (ibaud, obaud, flags, idrvname, odrvname, cfgname)"
127 pyis_getconfig(self
, args
)
128 PyObject
*self
; /* Not used */
131 long baudrate
, flags
;
132 Str255 idrvname
, odrvname
, cfgname
;
136 if (!PyArg_ParseTuple(args
, ""))
138 err
= is_getconfig(&baudrate
, &flags
, idrvname
, odrvname
, cfgname
);
140 PyErr_Mac(ErrorObject
, err
);
143 ibaud
= (baudrate
>> 16) & 0xffff;
144 obaud
= baudrate
& 0xffff;
145 return Py_BuildValue("iiiO&O&O&", ibaud
, obaud
, (int)flags
, PyMac_BuildStr255
, idrvname
,
146 PyMac_BuildStr255
, odrvname
, PyMac_BuildStr255
, cfgname
);
149 static char pyis_setconfig__doc__
[] =
150 "Set configuration data (ibaud, obaud, flags, idrvname, odrvname, cfgname)"
154 pyis_setconfig(self
, args
)
155 PyObject
*self
; /* Not used */
160 Str255 idrvname
, odrvname
, cfgname
;
164 if (!PyArg_ParseTuple(args
, "iiiO&O&O&", &ibaud
, &obaud
, &flags
, PyMac_GetStr255
, idrvname
,
165 PyMac_GetStr255
, odrvname
, PyMac_GetStr255
, cfgname
))
167 baudrate
= (ibaud
<< 16) | obaud
;
168 err
= is_setconfig(baudrate
, (long)flags
, idrvname
, odrvname
, cfgname
);
170 PyErr_Mac(ErrorObject
, err
);
177 /* List of methods defined in the module */
179 static struct PyMethodDef pyis_methods
[] = {
180 {"open", pyis_open
, 1, pyis_open__doc__
},
181 {"connect", pyis_connect
, 1, pyis_connect__doc__
},
182 {"disconnect", pyis_disconnect
, 1, pyis_disconnect__doc__
},
183 {"status", pyis_status
, 1, pyis_status__doc__
},
184 {"getconfig", pyis_getconfig
, 1, pyis_getconfig__doc__
},
185 {"setconfig", pyis_setconfig
, 1, pyis_setconfig__doc__
},
187 {NULL
, NULL
} /* sentinel */
191 /* Initialization function for the module (*must* be called initinterslip) */
193 static char interslip_module_documentation
[] =
202 /* Create the module and add the functions */
203 m
= Py_InitModule4("interslip", pyis_methods
,
204 interslip_module_documentation
,
205 (PyObject
*)NULL
,PYTHON_API_VERSION
);
207 /* Add some symbolic constants to the module */
208 d
= PyModule_GetDict(m
);
209 ErrorObject
= PyString_FromString("interslip.error");
210 PyDict_SetItemString(d
, "error", ErrorObject
);
212 /* XXXX Add constants here */
214 PyDict_SetItemString(d
, "IDLE", PyInt_FromLong(IS_IDLE
));
215 PyDict_SetItemString(d
, "WMODEM", PyInt_FromLong(IS_WMODEM
));
216 PyDict_SetItemString(d
, "DIAL", PyInt_FromLong(IS_DIAL
));
217 PyDict_SetItemString(d
, "LOGIN", PyInt_FromLong(IS_LOGIN
));
218 PyDict_SetItemString(d
, "RUN", PyInt_FromLong(IS_RUN
));
219 PyDict_SetItemString(d
, "DISC", PyInt_FromLong(IS_DISC
));
221 /* Check for errors */
222 if (PyErr_Occurred())
223 Py_FatalError("can't initialize module interslip");