Jack Jansen | ee735be | 1994-12-14 13:31:11 +0000 | [diff] [blame] | 1 | /*********************************************************** |
Jack Jansen | 42218ce | 1997-01-31 16:15:11 +0000 | [diff] [blame] | 2 | Copyright 1991-1997 by Stichting Mathematisch Centrum, Amsterdam, |
Guido van Rossum | 4410d57 | 1995-02-21 20:58:53 +0000 | [diff] [blame] | 3 | The Netherlands. |
Jack Jansen | ee735be | 1994-12-14 13:31:11 +0000 | [diff] [blame] | 4 | |
| 5 | All Rights Reserved |
| 6 | |
| 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. |
| 14 | |
| 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. |
| 22 | |
| 23 | ******************************************************************/ |
| 24 | |
| 25 | /* Note: This file is partially converted to the new naming standard */ |
| 26 | /* ctbcm objects */ |
| 27 | |
| 28 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 29 | #include "Python.h" |
Jack Jansen | ee735be | 1994-12-14 13:31:11 +0000 | [diff] [blame] | 30 | |
Guido van Rossum | 4410d57 | 1995-02-21 20:58:53 +0000 | [diff] [blame] | 31 | #include "macglue.h" |
| 32 | |
Jack Jansen | ee735be | 1994-12-14 13:31:11 +0000 | [diff] [blame] | 33 | #include <CommResources.h> |
| 34 | #include <Connections.h> |
Jack Jansen | c2952bc | 1998-02-20 15:55:53 +0000 | [diff] [blame] | 35 | #include <CTBUtilities.h> |
Jack Jansen | ee735be | 1994-12-14 13:31:11 +0000 | [diff] [blame] | 36 | #include <ToolUtils.h> |
| 37 | #include <OSUtils.h> |
Guido van Rossum | 4410d57 | 1995-02-21 20:58:53 +0000 | [diff] [blame] | 38 | |
| 39 | #ifndef HAVE_UNIVERSAL_HEADERS |
Jack Jansen | ee735be | 1994-12-14 13:31:11 +0000 | [diff] [blame] | 40 | #define ConnectionCompletionUPP ProcPtr |
| 41 | #define ConnectionChooseIdleUPP ProcPtr |
| 42 | #define NewConnectionCompletionProc(x) (x) |
| 43 | #define NewConnectionChooseIdleProc(x) (x) |
| 44 | #endif |
| 45 | |
| 46 | #define _UnimplementedToolTrap 0xA89F |
| 47 | #define _CommToolboxTrap 0x8B |
| 48 | #define _UnimplementedOSTrap 0x9F |
| 49 | |
Jack Jansen | 377df98 | 1997-04-03 14:48:04 +0000 | [diff] [blame] | 50 | static char *errornames[] = { |
| 51 | "No Error", |
| 52 | "Rejected", /* 1 */ |
| 53 | "Failed", /* 2 */ |
| 54 | "Timeout", /* 3 */ |
| 55 | "Not Open", /* 4 */ |
| 56 | "Not Closed", /* 5 */ |
| 57 | "No Request Pending", /* 6 */ |
| 58 | "Not Supported", /* 7 */ |
| 59 | "No Tools", /* 8 */ |
| 60 | "User Cancel", /* 9 */ |
| 61 | "Error 10", /* 10 */ |
| 62 | "Unknown Error", /* 11 */ |
| 63 | #define MAX_POS_ERROR 11 |
| 64 | }; |
| 65 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 66 | extern PyObject *PyErr_Mac(PyObject *,int); |
Jack Jansen | ee735be | 1994-12-14 13:31:11 +0000 | [diff] [blame] | 67 | |
Jack Jansen | 377df98 | 1997-04-03 14:48:04 +0000 | [diff] [blame] | 68 | static PyObject * |
| 69 | PyCtb_Error(PyObject *errobj, int errcode) |
| 70 | { |
| 71 | if ( errcode > 0 && errcode <= MAX_POS_ERROR ) { |
| 72 | PyErr_SetString(errobj, errornames[errcode]); |
| 73 | return NULL; |
| 74 | } else { |
| 75 | return PyErr_Mac(errobj, errcode); |
| 76 | } |
| 77 | } |
| 78 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 79 | static PyObject *ErrorObject; |
Jack Jansen | ee735be | 1994-12-14 13:31:11 +0000 | [diff] [blame] | 80 | |
| 81 | typedef struct { |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 82 | PyObject_HEAD |
Jack Jansen | ee735be | 1994-12-14 13:31:11 +0000 | [diff] [blame] | 83 | ConnHandle hdl; /* The handle to the connection */ |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 84 | PyObject *callback; /* Python callback routine */ |
Jack Jansen | ee735be | 1994-12-14 13:31:11 +0000 | [diff] [blame] | 85 | int has_callback; /* True if callback not None */ |
| 86 | int err; /* Error to pass to the callback */ |
| 87 | } ctbcmobject; |
| 88 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 89 | staticforward PyTypeObject ctbcmtype; |
Jack Jansen | ee735be | 1994-12-14 13:31:11 +0000 | [diff] [blame] | 90 | |
| 91 | #define is_ctbcmobject(v) ((v)->ob_type == &ctbcmtype) |
| 92 | |
| 93 | static |
| 94 | TrapAvailable(short tNumber, TrapType tType) |
| 95 | { |
| 96 | short unImplemented; |
| 97 | |
| 98 | if (tType == OSTrap) |
| 99 | unImplemented = _UnimplementedOSTrap; |
| 100 | else |
| 101 | unImplemented = _UnimplementedToolTrap; |
| 102 | |
| 103 | return NGetTrapAddress(tNumber, tType) != NGetTrapAddress(unImplemented, tType); |
| 104 | } |
| 105 | |
| 106 | static |
| 107 | initialize_ctb() |
| 108 | { |
| 109 | OSErr err; |
| 110 | static initialized = -1; |
| 111 | |
| 112 | if ( initialized >= 0 ) |
| 113 | return initialized; |
| 114 | initialized = 0; |
| 115 | |
| 116 | if ( !TrapAvailable(_CommToolboxTrap, OSTrap) ) { |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 117 | PyErr_SetString(ErrorObject, "CTB not available"); |
Jack Jansen | ee735be | 1994-12-14 13:31:11 +0000 | [diff] [blame] | 118 | return 0; |
| 119 | } |
| 120 | if ( (err=InitCTBUtilities()) ) { |
Jack Jansen | 377df98 | 1997-04-03 14:48:04 +0000 | [diff] [blame] | 121 | PyCtb_Error(ErrorObject, (int)err); |
Jack Jansen | ee735be | 1994-12-14 13:31:11 +0000 | [diff] [blame] | 122 | return 0; |
| 123 | } |
| 124 | if ( (err=InitCRM()) ) { |
Jack Jansen | 377df98 | 1997-04-03 14:48:04 +0000 | [diff] [blame] | 125 | PyCtb_Error(ErrorObject, (int)err); |
Jack Jansen | ee735be | 1994-12-14 13:31:11 +0000 | [diff] [blame] | 126 | return 0; |
| 127 | } |
| 128 | if ( (err=InitCM()) ) { |
Jack Jansen | 377df98 | 1997-04-03 14:48:04 +0000 | [diff] [blame] | 129 | PyCtb_Error(ErrorObject, (int)err); |
Jack Jansen | ee735be | 1994-12-14 13:31:11 +0000 | [diff] [blame] | 130 | return 0; |
| 131 | } |
| 132 | initialized = 1; |
| 133 | return 1; |
| 134 | } |
| 135 | |
| 136 | static int |
| 137 | ctbcm_pycallback(arg) |
| 138 | void *arg; |
| 139 | { |
| 140 | ctbcmobject *self = (ctbcmobject *)arg; |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 141 | PyObject *args, *rv; |
Jack Jansen | ee735be | 1994-12-14 13:31:11 +0000 | [diff] [blame] | 142 | |
| 143 | if ( !self->has_callback ) /* It could have been removed in the meantime */ |
| 144 | return 0; |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 145 | args = Py_BuildValue("(i)", self->err); |
| 146 | rv = PyEval_CallObject(self->callback, args); |
| 147 | Py_DECREF(args); |
Jack Jansen | ee735be | 1994-12-14 13:31:11 +0000 | [diff] [blame] | 148 | if( rv == NULL ) |
| 149 | return -1; |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 150 | Py_DECREF(rv); |
Jack Jansen | ee735be | 1994-12-14 13:31:11 +0000 | [diff] [blame] | 151 | return 0; |
| 152 | } |
| 153 | |
| 154 | /*DBG*/int ncallback; |
| 155 | static pascal void |
| 156 | ctbcm_ctbcallback(hconn) |
| 157 | ConnHandle hconn; |
| 158 | { |
| 159 | ctbcmobject *self; |
| 160 | |
| 161 | /* XXXX Do I have to do the A5 mumbo-jumbo? */ |
| 162 | ncallback++; /*DBG*/ |
| 163 | self = (ctbcmobject *)CMGetUserData(hconn); |
| 164 | self->err = (int)((*hconn)->errCode); |
| 165 | Py_AddPendingCall(ctbcm_pycallback, (void *)self); |
| 166 | } |
| 167 | |
| 168 | static ctbcmobject * |
| 169 | newctbcmobject(arg) |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 170 | PyObject *arg; |
Jack Jansen | ee735be | 1994-12-14 13:31:11 +0000 | [diff] [blame] | 171 | { |
| 172 | ctbcmobject *self; |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 173 | self = PyObject_NEW(ctbcmobject, &ctbcmtype); |
Jack Jansen | ee735be | 1994-12-14 13:31:11 +0000 | [diff] [blame] | 174 | if (self == NULL) |
| 175 | return NULL; |
| 176 | self->hdl = NULL; |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 177 | Py_INCREF(Py_None); |
| 178 | self->callback = Py_None; |
Jack Jansen | ee735be | 1994-12-14 13:31:11 +0000 | [diff] [blame] | 179 | self->has_callback = 0; |
| 180 | return self; |
| 181 | } |
| 182 | |
| 183 | /* ctbcm methods */ |
| 184 | |
| 185 | static void |
| 186 | ctbcm_dealloc(self) |
| 187 | ctbcmobject *self; |
| 188 | { |
| 189 | if ( self->hdl ) { |
| 190 | (void)CMClose(self->hdl, 0, (ConnectionCompletionUPP)0, 0, 1); |
| 191 | /*XXXX Is this safe? */ |
| 192 | CMDispose(self->hdl); |
| 193 | self->hdl = NULL; |
| 194 | } |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 195 | PyMem_DEL(self); |
Jack Jansen | ee735be | 1994-12-14 13:31:11 +0000 | [diff] [blame] | 196 | } |
| 197 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 198 | static PyObject * |
Jack Jansen | ee735be | 1994-12-14 13:31:11 +0000 | [diff] [blame] | 199 | ctbcm_open(self, args) |
| 200 | ctbcmobject *self; |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 201 | PyObject *args; |
Jack Jansen | ee735be | 1994-12-14 13:31:11 +0000 | [diff] [blame] | 202 | { |
| 203 | long timeout; |
| 204 | OSErr err; |
| 205 | ConnectionCompletionUPP cb_upp = NewConnectionCompletionProc(ctbcm_ctbcallback); |
| 206 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 207 | if (!PyArg_Parse(args, "l", &timeout)) |
Jack Jansen | ee735be | 1994-12-14 13:31:11 +0000 | [diff] [blame] | 208 | return NULL; |
Jack Jansen | 377df98 | 1997-04-03 14:48:04 +0000 | [diff] [blame] | 209 | if ( (err=CMOpen(self->hdl, self->has_callback, cb_upp, timeout)) != 0) |
| 210 | return PyCtb_Error(ErrorObject, (int)err); |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 211 | Py_INCREF(Py_None); |
| 212 | return Py_None; |
Jack Jansen | ee735be | 1994-12-14 13:31:11 +0000 | [diff] [blame] | 213 | } |
| 214 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 215 | static PyObject * |
Jack Jansen | ee735be | 1994-12-14 13:31:11 +0000 | [diff] [blame] | 216 | ctbcm_listen(self, args) |
| 217 | ctbcmobject *self; |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 218 | PyObject *args; |
Jack Jansen | ee735be | 1994-12-14 13:31:11 +0000 | [diff] [blame] | 219 | { |
| 220 | long timeout; |
| 221 | OSErr err; |
| 222 | ConnectionCompletionUPP cb_upp = NewConnectionCompletionProc(ctbcm_ctbcallback); |
| 223 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 224 | if (!PyArg_Parse(args, "l", &timeout)) |
Jack Jansen | ee735be | 1994-12-14 13:31:11 +0000 | [diff] [blame] | 225 | return NULL; |
Jack Jansen | 377df98 | 1997-04-03 14:48:04 +0000 | [diff] [blame] | 226 | if ( (err=CMListen(self->hdl,self->has_callback, cb_upp, timeout)) != 0) |
| 227 | return PyCtb_Error(ErrorObject, (int)err); |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 228 | Py_INCREF(Py_None); |
| 229 | return Py_None; |
Jack Jansen | ee735be | 1994-12-14 13:31:11 +0000 | [diff] [blame] | 230 | } |
| 231 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 232 | static PyObject * |
Jack Jansen | ee735be | 1994-12-14 13:31:11 +0000 | [diff] [blame] | 233 | ctbcm_accept(self, args) |
| 234 | ctbcmobject *self; |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 235 | PyObject *args; |
Jack Jansen | ee735be | 1994-12-14 13:31:11 +0000 | [diff] [blame] | 236 | { |
| 237 | int accept; |
| 238 | OSErr err; |
| 239 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 240 | if (!PyArg_Parse(args, "i", &accept)) |
Jack Jansen | ee735be | 1994-12-14 13:31:11 +0000 | [diff] [blame] | 241 | return NULL; |
Jack Jansen | 377df98 | 1997-04-03 14:48:04 +0000 | [diff] [blame] | 242 | if ( (err=CMAccept(self->hdl, accept)) != 0) |
| 243 | return PyCtb_Error(ErrorObject, (int)err); |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 244 | Py_INCREF(Py_None); |
| 245 | return Py_None; |
Jack Jansen | ee735be | 1994-12-14 13:31:11 +0000 | [diff] [blame] | 246 | } |
| 247 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 248 | static PyObject * |
Jack Jansen | ee735be | 1994-12-14 13:31:11 +0000 | [diff] [blame] | 249 | ctbcm_close(self, args) |
| 250 | ctbcmobject *self; |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 251 | PyObject *args; |
Jack Jansen | ee735be | 1994-12-14 13:31:11 +0000 | [diff] [blame] | 252 | { |
| 253 | int now; |
| 254 | long timeout; |
| 255 | OSErr err; |
| 256 | ConnectionCompletionUPP cb_upp = NewConnectionCompletionProc(ctbcm_ctbcallback); |
| 257 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 258 | if (!PyArg_Parse(args, "(li)", &timeout, &now)) |
Jack Jansen | ee735be | 1994-12-14 13:31:11 +0000 | [diff] [blame] | 259 | return NULL; |
Jack Jansen | 377df98 | 1997-04-03 14:48:04 +0000 | [diff] [blame] | 260 | if ( (err=CMClose(self->hdl, self->has_callback, cb_upp, timeout, now)) != 0) |
| 261 | return PyCtb_Error(ErrorObject, (int)err); |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 262 | Py_INCREF(Py_None); |
| 263 | return Py_None; |
Jack Jansen | ee735be | 1994-12-14 13:31:11 +0000 | [diff] [blame] | 264 | } |
| 265 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 266 | static PyObject * |
Jack Jansen | ee735be | 1994-12-14 13:31:11 +0000 | [diff] [blame] | 267 | ctbcm_read(self, args) |
| 268 | ctbcmobject *self; |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 269 | PyObject *args; |
Jack Jansen | ee735be | 1994-12-14 13:31:11 +0000 | [diff] [blame] | 270 | { |
| 271 | long timeout, len; |
| 272 | int chan; |
| 273 | CMFlags flags; |
| 274 | OSErr err; |
Jack Jansen | 377df98 | 1997-04-03 14:48:04 +0000 | [diff] [blame] | 275 | PyObject *rv, *rrv; |
Jack Jansen | ee735be | 1994-12-14 13:31:11 +0000 | [diff] [blame] | 276 | ConnectionCompletionUPP cb_upp = NewConnectionCompletionProc(ctbcm_ctbcallback); |
| 277 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 278 | if (!PyArg_Parse(args, "(lil)", &len, &chan, &timeout)) |
Jack Jansen | ee735be | 1994-12-14 13:31:11 +0000 | [diff] [blame] | 279 | return NULL; |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 280 | if ((rv=PyString_FromStringAndSize(NULL, len)) == NULL) |
Jack Jansen | ee735be | 1994-12-14 13:31:11 +0000 | [diff] [blame] | 281 | return NULL; |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 282 | if ((err=CMRead(self->hdl, (Ptr)PyString_AsString(rv), &len, (CMChannel)chan, |
Jack Jansen | 377df98 | 1997-04-03 14:48:04 +0000 | [diff] [blame] | 283 | self->has_callback, cb_upp, timeout, &flags)) != 0 && err != cmTimeOut) |
| 284 | return PyCtb_Error(ErrorObject, (int)err); |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 285 | _PyString_Resize(&rv, len); |
Jack Jansen | 377df98 | 1997-04-03 14:48:04 +0000 | [diff] [blame] | 286 | rrv = Py_BuildValue("(Oi)", rv, (int)flags); |
| 287 | Py_DECREF(rv); |
| 288 | return rrv; |
Jack Jansen | ee735be | 1994-12-14 13:31:11 +0000 | [diff] [blame] | 289 | } |
| 290 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 291 | static PyObject * |
Jack Jansen | ee735be | 1994-12-14 13:31:11 +0000 | [diff] [blame] | 292 | ctbcm_write(self, args) |
| 293 | ctbcmobject *self; |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 294 | PyObject *args; |
Jack Jansen | ee735be | 1994-12-14 13:31:11 +0000 | [diff] [blame] | 295 | { |
| 296 | long timeout, len; |
| 297 | int chan, ilen, flags; |
| 298 | OSErr err; |
| 299 | char *buf; |
| 300 | ConnectionCompletionUPP cb_upp = NewConnectionCompletionProc(ctbcm_ctbcallback); |
| 301 | |
Jack Jansen | eeccca9 | 1997-05-07 15:46:31 +0000 | [diff] [blame] | 302 | if (!PyArg_Parse(args, "(s#ili)", &buf, &ilen, &chan, &timeout, &flags)) |
Jack Jansen | ee735be | 1994-12-14 13:31:11 +0000 | [diff] [blame] | 303 | return NULL; |
| 304 | len = ilen; |
| 305 | if ((err=CMWrite(self->hdl, (Ptr)buf, &len, (CMChannel)chan, |
Jack Jansen | 377df98 | 1997-04-03 14:48:04 +0000 | [diff] [blame] | 306 | self->has_callback, cb_upp, timeout, (CMFlags)flags)) != 0 && err != cmTimeOut) |
| 307 | return PyCtb_Error(ErrorObject, (int)err); |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 308 | return PyInt_FromLong((int)len); |
Jack Jansen | ee735be | 1994-12-14 13:31:11 +0000 | [diff] [blame] | 309 | } |
| 310 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 311 | static PyObject * |
Jack Jansen | ee735be | 1994-12-14 13:31:11 +0000 | [diff] [blame] | 312 | ctbcm_status(self, args) |
| 313 | ctbcmobject *self; |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 314 | PyObject *args; |
Jack Jansen | ee735be | 1994-12-14 13:31:11 +0000 | [diff] [blame] | 315 | { |
| 316 | CMBufferSizes sizes; |
| 317 | CMStatFlags flags; |
| 318 | OSErr err; |
Jack Jansen | 377df98 | 1997-04-03 14:48:04 +0000 | [diff] [blame] | 319 | PyObject *rv, *rrv; |
Jack Jansen | ee735be | 1994-12-14 13:31:11 +0000 | [diff] [blame] | 320 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 321 | if (!PyArg_NoArgs(args)) |
Jack Jansen | ee735be | 1994-12-14 13:31:11 +0000 | [diff] [blame] | 322 | return NULL; |
Jack Jansen | 377df98 | 1997-04-03 14:48:04 +0000 | [diff] [blame] | 323 | if ((err=CMStatus(self->hdl, sizes, &flags)) != 0) |
| 324 | return PyCtb_Error(ErrorObject, (int)err); |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 325 | rv = Py_BuildValue("(llllll)", sizes[0], sizes[1], sizes[2], sizes[3], sizes[4], sizes[5]); |
Jack Jansen | ee735be | 1994-12-14 13:31:11 +0000 | [diff] [blame] | 326 | if ( rv == NULL ) |
| 327 | return NULL; |
Jack Jansen | 377df98 | 1997-04-03 14:48:04 +0000 | [diff] [blame] | 328 | rrv = Py_BuildValue("(Ol)", rv, (long)flags); |
| 329 | Py_DECREF(rv); |
| 330 | return rrv; |
Jack Jansen | ee735be | 1994-12-14 13:31:11 +0000 | [diff] [blame] | 331 | } |
| 332 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 333 | static PyObject * |
Jack Jansen | ee735be | 1994-12-14 13:31:11 +0000 | [diff] [blame] | 334 | ctbcm_getconfig(self, args) |
| 335 | ctbcmobject *self; |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 336 | PyObject *args; |
Jack Jansen | ee735be | 1994-12-14 13:31:11 +0000 | [diff] [blame] | 337 | { |
| 338 | char *rv; |
| 339 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 340 | if (!PyArg_NoArgs(args)) |
Jack Jansen | ee735be | 1994-12-14 13:31:11 +0000 | [diff] [blame] | 341 | return NULL; |
| 342 | if ((rv=(char *)CMGetConfig(self->hdl)) == NULL ) { |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 343 | PyErr_SetString(ErrorObject, "CMGetConfig failed"); |
Jack Jansen | ee735be | 1994-12-14 13:31:11 +0000 | [diff] [blame] | 344 | return NULL; |
| 345 | } |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 346 | return PyString_FromString(rv); |
Jack Jansen | ee735be | 1994-12-14 13:31:11 +0000 | [diff] [blame] | 347 | } |
| 348 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 349 | static PyObject * |
Jack Jansen | ee735be | 1994-12-14 13:31:11 +0000 | [diff] [blame] | 350 | ctbcm_setconfig(self, args) |
| 351 | ctbcmobject *self; |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 352 | PyObject *args; |
Jack Jansen | ee735be | 1994-12-14 13:31:11 +0000 | [diff] [blame] | 353 | { |
| 354 | char *cfg; |
Jack Jansen | 377df98 | 1997-04-03 14:48:04 +0000 | [diff] [blame] | 355 | short rv; |
Jack Jansen | ee735be | 1994-12-14 13:31:11 +0000 | [diff] [blame] | 356 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 357 | if (!PyArg_Parse(args, "s", &cfg)) |
Jack Jansen | ee735be | 1994-12-14 13:31:11 +0000 | [diff] [blame] | 358 | return NULL; |
Jack Jansen | 377df98 | 1997-04-03 14:48:04 +0000 | [diff] [blame] | 359 | rv=CMSetConfig(self->hdl, (Ptr)cfg); |
| 360 | return PyInt_FromLong((long)rv); |
Jack Jansen | ee735be | 1994-12-14 13:31:11 +0000 | [diff] [blame] | 361 | } |
| 362 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 363 | static PyObject * |
Jack Jansen | ee735be | 1994-12-14 13:31:11 +0000 | [diff] [blame] | 364 | ctbcm_choose(self, args) |
| 365 | ctbcmobject *self; |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 366 | PyObject *args; |
Jack Jansen | ee735be | 1994-12-14 13:31:11 +0000 | [diff] [blame] | 367 | { |
| 368 | int rv; |
| 369 | Point pt; |
| 370 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 371 | if (!PyArg_NoArgs(args)) |
Jack Jansen | ee735be | 1994-12-14 13:31:11 +0000 | [diff] [blame] | 372 | return NULL; |
| 373 | pt.v = 40; |
| 374 | pt.h = 40; |
| 375 | rv=CMChoose(&self->hdl, pt, (ConnectionChooseIdleUPP)0); |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 376 | return PyInt_FromLong(rv); |
Jack Jansen | ee735be | 1994-12-14 13:31:11 +0000 | [diff] [blame] | 377 | } |
| 378 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 379 | static PyObject * |
Jack Jansen | ee735be | 1994-12-14 13:31:11 +0000 | [diff] [blame] | 380 | ctbcm_idle(self, args) |
| 381 | ctbcmobject *self; |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 382 | PyObject *args; |
Jack Jansen | ee735be | 1994-12-14 13:31:11 +0000 | [diff] [blame] | 383 | { |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 384 | if (!PyArg_NoArgs(args)) |
Jack Jansen | ee735be | 1994-12-14 13:31:11 +0000 | [diff] [blame] | 385 | return NULL; |
| 386 | CMIdle(self->hdl); |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 387 | Py_INCREF(Py_None); |
| 388 | return Py_None; |
Jack Jansen | ee735be | 1994-12-14 13:31:11 +0000 | [diff] [blame] | 389 | } |
| 390 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 391 | static PyObject * |
Jack Jansen | ee735be | 1994-12-14 13:31:11 +0000 | [diff] [blame] | 392 | ctbcm_abort(self, args) |
| 393 | ctbcmobject *self; |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 394 | PyObject *args; |
Jack Jansen | ee735be | 1994-12-14 13:31:11 +0000 | [diff] [blame] | 395 | { |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 396 | if (!PyArg_NoArgs(args)) |
Jack Jansen | ee735be | 1994-12-14 13:31:11 +0000 | [diff] [blame] | 397 | return NULL; |
| 398 | CMAbort(self->hdl); |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 399 | Py_INCREF(Py_None); |
| 400 | return Py_None; |
Jack Jansen | ee735be | 1994-12-14 13:31:11 +0000 | [diff] [blame] | 401 | } |
| 402 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 403 | static PyObject * |
Jack Jansen | ee735be | 1994-12-14 13:31:11 +0000 | [diff] [blame] | 404 | ctbcm_reset(self, args) |
| 405 | ctbcmobject *self; |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 406 | PyObject *args; |
Jack Jansen | ee735be | 1994-12-14 13:31:11 +0000 | [diff] [blame] | 407 | { |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 408 | if (!PyArg_NoArgs(args)) |
Jack Jansen | ee735be | 1994-12-14 13:31:11 +0000 | [diff] [blame] | 409 | return NULL; |
| 410 | CMReset(self->hdl); |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 411 | Py_INCREF(Py_None); |
| 412 | return Py_None; |
Jack Jansen | ee735be | 1994-12-14 13:31:11 +0000 | [diff] [blame] | 413 | } |
| 414 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 415 | static PyObject * |
Jack Jansen | ee735be | 1994-12-14 13:31:11 +0000 | [diff] [blame] | 416 | ctbcm_break(self, args) |
| 417 | ctbcmobject *self; |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 418 | PyObject *args; |
Jack Jansen | ee735be | 1994-12-14 13:31:11 +0000 | [diff] [blame] | 419 | { |
| 420 | long duration; |
| 421 | ConnectionCompletionUPP cb_upp = NewConnectionCompletionProc(ctbcm_ctbcallback); |
| 422 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 423 | if (!PyArg_Parse(args, "l", &duration)) |
Jack Jansen | ee735be | 1994-12-14 13:31:11 +0000 | [diff] [blame] | 424 | return NULL; |
| 425 | CMBreak(self->hdl, duration,self->has_callback, cb_upp); |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 426 | Py_INCREF(Py_None); |
| 427 | return Py_None; |
Jack Jansen | ee735be | 1994-12-14 13:31:11 +0000 | [diff] [blame] | 428 | } |
| 429 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 430 | static struct PyMethodDef ctbcm_methods[] = { |
| 431 | {"Open", (PyCFunction)ctbcm_open}, |
| 432 | {"Close", (PyCFunction)ctbcm_close}, |
| 433 | {"Read", (PyCFunction)ctbcm_read}, |
| 434 | {"Write", (PyCFunction)ctbcm_write}, |
| 435 | {"Status", (PyCFunction)ctbcm_status}, |
| 436 | {"GetConfig", (PyCFunction)ctbcm_getconfig}, |
| 437 | {"SetConfig", (PyCFunction)ctbcm_setconfig}, |
| 438 | {"Choose", (PyCFunction)ctbcm_choose}, |
| 439 | {"Idle", (PyCFunction)ctbcm_idle}, |
| 440 | {"Listen", (PyCFunction)ctbcm_listen}, |
| 441 | {"Accept", (PyCFunction)ctbcm_accept}, |
| 442 | {"Abort", (PyCFunction)ctbcm_abort}, |
| 443 | {"Reset", (PyCFunction)ctbcm_reset}, |
| 444 | {"Break", (PyCFunction)ctbcm_break}, |
Jack Jansen | ee735be | 1994-12-14 13:31:11 +0000 | [diff] [blame] | 445 | {NULL, NULL} /* sentinel */ |
| 446 | }; |
| 447 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 448 | static PyObject * |
Jack Jansen | ee735be | 1994-12-14 13:31:11 +0000 | [diff] [blame] | 449 | ctbcm_getattr(self, name) |
| 450 | ctbcmobject *self; |
| 451 | char *name; |
| 452 | { |
| 453 | if ( strcmp(name, "callback") == 0 ) { |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 454 | Py_INCREF(self->callback); |
Jack Jansen | ee735be | 1994-12-14 13:31:11 +0000 | [diff] [blame] | 455 | return self->callback; |
| 456 | } |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 457 | return Py_FindMethod(ctbcm_methods, (PyObject *)self, name); |
Jack Jansen | ee735be | 1994-12-14 13:31:11 +0000 | [diff] [blame] | 458 | } |
| 459 | |
| 460 | static int |
| 461 | ctbcm_setattr(self, name, v) |
| 462 | ctbcmobject *self; |
| 463 | char *name; |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 464 | PyObject *v; |
Jack Jansen | ee735be | 1994-12-14 13:31:11 +0000 | [diff] [blame] | 465 | { |
| 466 | if ( strcmp(name, "callback") != 0 ) { |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 467 | PyErr_SetString(PyExc_AttributeError, "ctbcm objects have callback attr only"); |
Jack Jansen | ee735be | 1994-12-14 13:31:11 +0000 | [diff] [blame] | 468 | return -1; |
| 469 | } |
| 470 | if ( v == NULL ) { |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 471 | v = Py_None; |
Jack Jansen | ee735be | 1994-12-14 13:31:11 +0000 | [diff] [blame] | 472 | } |
Jack Jansen | 377df98 | 1997-04-03 14:48:04 +0000 | [diff] [blame] | 473 | Py_INCREF(v); |
Jack Jansen | ee735be | 1994-12-14 13:31:11 +0000 | [diff] [blame] | 474 | self->callback = v; |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 475 | self->has_callback = (v != Py_None); |
Jack Jansen | ee735be | 1994-12-14 13:31:11 +0000 | [diff] [blame] | 476 | return 0; |
| 477 | } |
| 478 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 479 | statichere PyTypeObject ctbcmtype = { |
| 480 | PyObject_HEAD_INIT(&PyType_Type) |
Jack Jansen | ee735be | 1994-12-14 13:31:11 +0000 | [diff] [blame] | 481 | 0, /*ob_size*/ |
Jack Jansen | a755e68 | 1997-09-20 17:40:22 +0000 | [diff] [blame] | 482 | "CTBConnectionMgr", /*tp_name*/ |
Jack Jansen | ee735be | 1994-12-14 13:31:11 +0000 | [diff] [blame] | 483 | sizeof(ctbcmobject), /*tp_basicsize*/ |
| 484 | 0, /*tp_itemsize*/ |
| 485 | /* methods */ |
| 486 | (destructor)ctbcm_dealloc, /*tp_dealloc*/ |
| 487 | 0, /*tp_print*/ |
| 488 | (getattrfunc)ctbcm_getattr, /*tp_getattr*/ |
| 489 | (setattrfunc)ctbcm_setattr, /*tp_setattr*/ |
| 490 | 0, /*tp_compare*/ |
| 491 | 0, /*tp_repr*/ |
| 492 | 0, /*tp_as_number*/ |
| 493 | 0, /*tp_as_sequence*/ |
| 494 | 0, /*tp_as_mapping*/ |
| 495 | 0, /*tp_hash*/ |
| 496 | }; |
| 497 | /* --------------------------------------------------------------------- */ |
| 498 | |
| 499 | /* Function of no arguments returning new ctbcm object */ |
| 500 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 501 | static PyObject * |
Jack Jansen | ee735be | 1994-12-14 13:31:11 +0000 | [diff] [blame] | 502 | ctb_cmnew(self, args) |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 503 | PyObject *self; /* Not used */ |
| 504 | PyObject *args; |
Jack Jansen | ee735be | 1994-12-14 13:31:11 +0000 | [diff] [blame] | 505 | { |
| 506 | int strlen; |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 507 | PyObject *sizes_obj; |
Jack Jansen | ee735be | 1994-12-14 13:31:11 +0000 | [diff] [blame] | 508 | char *c_str; |
| 509 | unsigned char p_str[255]; |
| 510 | CMBufferSizes sizes; |
| 511 | short procid; |
| 512 | ConnHandle hdl; |
| 513 | ctbcmobject *rv; |
| 514 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 515 | if (!PyArg_Parse(args, "(s#O)", &c_str, &strlen, &sizes_obj)) |
Jack Jansen | ee735be | 1994-12-14 13:31:11 +0000 | [diff] [blame] | 516 | return NULL; |
| 517 | strncpy((char *)p_str+1, c_str, strlen); |
| 518 | p_str[0] = strlen; |
| 519 | if (!initialize_ctb()) |
| 520 | return NULL; |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 521 | if ( sizes_obj == Py_None ) { |
Jack Jansen | ee735be | 1994-12-14 13:31:11 +0000 | [diff] [blame] | 522 | memset(sizes, '\0', sizeof sizes); |
| 523 | } else { |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 524 | if ( !PyArg_Parse(sizes_obj, "(llllll)", &sizes[0], &sizes[1], &sizes[2], |
Jack Jansen | ee735be | 1994-12-14 13:31:11 +0000 | [diff] [blame] | 525 | &sizes[3], &sizes[4], &sizes[5])) |
| 526 | return NULL; |
| 527 | } |
| 528 | if ( (procid=CMGetProcID(p_str)) < 0 ) |
Jack Jansen | 377df98 | 1997-04-03 14:48:04 +0000 | [diff] [blame] | 529 | return PyCtb_Error(ErrorObject, procid); |
Jack Jansen | ee735be | 1994-12-14 13:31:11 +0000 | [diff] [blame] | 530 | hdl = CMNew(procid, cmNoMenus|cmQuiet, sizes, 0, 0); |
| 531 | if ( hdl == NULL ) { |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 532 | PyErr_SetString(ErrorObject, "CMNew failed"); |
Jack Jansen | ee735be | 1994-12-14 13:31:11 +0000 | [diff] [blame] | 533 | return NULL; |
| 534 | } |
| 535 | rv = newctbcmobject(args); |
| 536 | if ( rv == NULL ) |
| 537 | return NULL; /* XXXX Should dispose of hdl */ |
| 538 | rv->hdl = hdl; |
| 539 | CMSetUserData(hdl, (long)rv); |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 540 | return (PyObject *)rv; |
Jack Jansen | ee735be | 1994-12-14 13:31:11 +0000 | [diff] [blame] | 541 | } |
| 542 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 543 | static PyObject * |
Jack Jansen | ee735be | 1994-12-14 13:31:11 +0000 | [diff] [blame] | 544 | ctb_available(self, args) |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 545 | PyObject *self; |
| 546 | PyObject *args; |
Jack Jansen | ee735be | 1994-12-14 13:31:11 +0000 | [diff] [blame] | 547 | { |
| 548 | int ok; |
| 549 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 550 | if (!PyArg_NoArgs(args)) |
Jack Jansen | ee735be | 1994-12-14 13:31:11 +0000 | [diff] [blame] | 551 | return NULL; |
| 552 | ok = initialize_ctb(); |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 553 | PyErr_Clear(); |
| 554 | return PyInt_FromLong(ok); |
Jack Jansen | ee735be | 1994-12-14 13:31:11 +0000 | [diff] [blame] | 555 | } |
| 556 | |
| 557 | /* List of functions defined in the module */ |
| 558 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 559 | static struct PyMethodDef ctb_methods[] = { |
Jack Jansen | ee735be | 1994-12-14 13:31:11 +0000 | [diff] [blame] | 560 | {"CMNew", ctb_cmnew}, |
| 561 | {"available", ctb_available}, |
| 562 | {NULL, NULL} /* sentinel */ |
| 563 | }; |
| 564 | |
| 565 | |
| 566 | /* Initialization function for the module (*must* be called initctb) */ |
| 567 | |
| 568 | void |
| 569 | initctb() |
| 570 | { |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 571 | PyObject *m, *d, *o; |
Jack Jansen | ee735be | 1994-12-14 13:31:11 +0000 | [diff] [blame] | 572 | |
| 573 | /* Create the module and add the functions */ |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 574 | m = Py_InitModule("ctb", ctb_methods); |
Jack Jansen | ee735be | 1994-12-14 13:31:11 +0000 | [diff] [blame] | 575 | |
| 576 | /* Add some symbolic constants to the module */ |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 577 | d = PyModule_GetDict(m); |
Jack Jansen | ee735be | 1994-12-14 13:31:11 +0000 | [diff] [blame] | 578 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 579 | #define CMCONST(name, value) o = PyInt_FromLong(value); PyDict_SetItemString(d, name, o) |
Jack Jansen | ee735be | 1994-12-14 13:31:11 +0000 | [diff] [blame] | 580 | |
| 581 | CMCONST("cmData", 1); |
| 582 | CMCONST("cmCntl", 2); |
| 583 | CMCONST("cmAttn", 3); |
| 584 | |
| 585 | CMCONST("cmFlagsEOM", 1); |
| 586 | |
| 587 | CMCONST("chooseDisaster", -2); |
| 588 | CMCONST("chooseFailed", -1); |
| 589 | CMCONST("chooseAborted", 0); |
| 590 | CMCONST("chooseOKMinor", 1); |
| 591 | CMCONST("chooseOKMajor", 2); |
| 592 | CMCONST("chooseCancel", 3); |
| 593 | |
| 594 | CMCONST("cmStatusOpening", 1); |
| 595 | CMCONST("cmStatusOpen", 2); |
| 596 | CMCONST("cmStatusClosing", 4); |
| 597 | CMCONST("cmStatusDataAvail", 8); |
| 598 | CMCONST("cmStatusCntlAvail", 0x10); |
| 599 | CMCONST("cmStatusAttnAvail", 0x20); |
| 600 | CMCONST("cmStatusDRPend", 0x40); |
| 601 | CMCONST("cmStatusDWPend", 0x80); |
| 602 | CMCONST("cmStatusCWPend", 0x100); |
| 603 | CMCONST("cmStatusCWPend", 0x200); |
| 604 | CMCONST("cmStatusARPend", 0x400); |
| 605 | CMCONST("cmStatusAWPend", 0x800); |
| 606 | CMCONST("cmStatusBreakPending", 0x1000); |
| 607 | CMCONST("cmStatusListenPend", 0x2000); |
| 608 | CMCONST("cmStatusIncomingCallPresent", 0x4000); |
| 609 | |
Jack Jansen | 55e3927 | 1997-10-07 21:47:25 +0000 | [diff] [blame] | 610 | ErrorObject = PyErr_NewException("ctb.error", NULL, NULL); |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 611 | PyDict_SetItemString(d, "error", ErrorObject); |
Jack Jansen | a755e68 | 1997-09-20 17:40:22 +0000 | [diff] [blame] | 612 | ctbcmtype.ob_type = &PyType_Type; |
| 613 | Py_INCREF(&ctbcmtype); |
| 614 | PyDict_SetItemString(d, "CTBConnectionMgrType", (PyObject *)&ctbcmtype); |
Jack Jansen | ee735be | 1994-12-14 13:31:11 +0000 | [diff] [blame] | 615 | } |