Added 'list_only' option (and modified 'run()' to respect it).
[python/dscho.git] / Mac / Demo / interslip / interslipmodule.c
blobdc2c7a8da8858120f34489d9d09c8c7c52e4407a
1 /***********************************************************
2 Copyright 1991-1995 by Stichting Mathematisch Centrum, Amsterdam,
3 The Netherlands.
5 All Rights Reserved
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 ******************************************************************/
25 #include "Python.h"
26 #include "InterslipLib.h"
27 #include "macglue.h"
29 static PyObject *ErrorObject;
31 /* ----------------------------------------------------- */
33 static char pyis_open__doc__[] =
34 "Load the interslip driver (optional)"
37 static PyObject *
38 pyis_open(self, args)
39 PyObject *self; /* Not used */
40 PyObject *args;
42 OSErr err;
44 if (!PyArg_ParseTuple(args, ""))
45 return NULL;
46 err = is_open();
47 if ( err ) {
48 PyErr_Mac(ErrorObject, err);
49 return NULL;
51 Py_INCREF(Py_None);
52 return Py_None;
55 static char pyis_connect__doc__[] =
56 "Tell the driver to start a connect"
59 static PyObject *
60 pyis_connect(self, args)
61 PyObject *self; /* Not used */
62 PyObject *args;
64 OSErr err;
66 if (!PyArg_ParseTuple(args, ""))
67 return NULL;
68 err = is_connect();
69 if ( err ) {
70 PyErr_Mac(ErrorObject, err);
71 return NULL;
73 Py_INCREF(Py_None);
74 return Py_None;
77 static char pyis_disconnect__doc__[] =
78 "Tell the interslip driver to start a disconnect"
81 static PyObject *
82 pyis_disconnect(self, args)
83 PyObject *self; /* Not used */
84 PyObject *args;
86 OSErr err;
88 if (!PyArg_ParseTuple(args, ""))
89 return NULL;
90 err = is_disconnect();
91 if ( err ) {
92 PyErr_Mac(ErrorObject, err);
93 return NULL;
95 Py_INCREF(Py_None);
96 return Py_None;
99 static char pyis_status__doc__[] =
100 "Return (numeric_status, message_seqnum, message_string) status tuple"
103 static PyObject *
104 pyis_status(self, args)
105 PyObject *self; /* Not used */
106 PyObject *args;
108 long status, seqnum;
109 StringPtr message;
110 OSErr err;
112 if (!PyArg_ParseTuple(args, ""))
113 return NULL;
114 err = is_status(&status, &seqnum, &message);
115 if ( err ) {
116 PyErr_Mac(ErrorObject, err);
117 return NULL;
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)"
126 static PyObject *
127 pyis_getconfig(self, args)
128 PyObject *self; /* Not used */
129 PyObject *args;
131 long baudrate, flags;
132 Str255 idrvname, odrvname, cfgname;
133 OSErr err;
134 int ibaud, obaud;
136 if (!PyArg_ParseTuple(args, ""))
137 return NULL;
138 err = is_getconfig(&baudrate, &flags, idrvname, odrvname, cfgname);
139 if ( err ) {
140 PyErr_Mac(ErrorObject, err);
141 return NULL;
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)"
153 static PyObject *
154 pyis_setconfig(self, args)
155 PyObject *self; /* Not used */
156 PyObject *args;
158 long baudrate;
159 int flags;
160 Str255 idrvname, odrvname, cfgname;
161 OSErr err;
162 int ibaud, obaud;
164 if (!PyArg_ParseTuple(args, "iiiO&O&O&", &ibaud, &obaud, &flags, PyMac_GetStr255, idrvname,
165 PyMac_GetStr255, odrvname, PyMac_GetStr255, cfgname))
166 return NULL;
167 baudrate = (ibaud << 16) | obaud;
168 err = is_setconfig(baudrate, (long)flags, idrvname, odrvname, cfgname);
169 if ( err ) {
170 PyErr_Mac(ErrorObject, err);
171 return NULL;
173 Py_INCREF(Py_None);
174 return Py_None;
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[] =
197 void
198 initinterslip()
200 PyObject *m, *d;
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");