1 /*********************************************************************
2 Project : GUSI - Grand unified socket interface
3 File : GUSISIOUX.cp - Interface to Metrowerks SIOUX library
4 Author : Matthias Neeracher
8 Revision 1.1 1998/08/18 14:52:38 jack
9 Putting Python-specific GUSI modifications under CVS.
11 *********************************************************************/
13 #include <GUSIFile_P.h>
20 /************************ SIOUXSocket members ************************/
22 /* This declaration lies about the return type */
23 extern "C" void SIOUXHandleOneEvent(EventRecord *userevent);
25 GUSIEvtHandler GUSISIOUXEvents[] = {
26 SIOUXHandleOneEvent, // nullEvent
28 SIOUXHandleOneEvent, // mouseDown
29 SIOUXHandleOneEvent, // mouseUp
34 SIOUXHandleOneEvent, // updateEvt
35 SIOUXHandleOneEvent, // diskEvt
36 SIOUXHandleOneEvent, // activateEvt
45 SIOUXHandleOneEvent, // osEvt
58 /************************ Declaration of SIOUXSocket ************************/
60 class SIOUXSocket : public Socket {
61 friend class SIOUXSocketDomain;
65 virtual ~SIOUXSocket();
68 void DoInitialize(void);
70 virtual int read(void * buffer, int buflen);
71 virtual int write(void * buffer, int buflen);
72 virtual int select(Boolean * canRead, Boolean * canWrite, Boolean * exception);
73 virtual int ioctl(unsigned int request, void *argp);
77 class SIOUXSocketDomain : public FileSocketDomain {
78 SIOUXSocket * singleton;
80 SIOUXSocketDomain() : FileSocketDomain(AF_UNSPEC, true, false), singleton(nil) { }
82 virtual Boolean Yours(const GUSIFileRef & ref, Request request);
83 virtual Socket * open(const GUSIFileRef & ref, int oflag);
90 /************************ SIOUXSocket members ************************/
92 void SIOUXSocket::DoInitialize()
94 if ( initialized ) return;
97 GUSISetEvents(GUSISIOUXEvents);
100 SIOUXSocket::SIOUXSocket()
103 if ( !GUSIConfig.DelayConsole() )
107 SIOUXSocket::~SIOUXSocket()
112 int SIOUXSocket::ioctl(unsigned int request, void *)
114 if ( !initialized) DoInitialize();
119 return GUSI_error(EOPNOTSUPP);
123 int SIOUXSocket::read(void * buffer, int buflen)
125 if ( !initialized) DoInitialize();
128 return ReadCharsFromConsole((char *) buffer, buflen);
131 int SIOUXSocket::write(void * buffer, int buflen)
133 if ( !initialized) DoInitialize();
134 return WriteCharsToConsole((char *) buffer, buflen);
137 static Boolean input_pending()
139 QHdrPtr eventQueue = LMGetEventQueue();
140 EvQElPtr element = (EvQElPtr)eventQueue->qHead;
142 // now, count the number of pending keyDown events.
143 while (element != nil) {
144 if (element->evtQWhat == keyDown || element->evtQWhat == autoKey)
146 element = (EvQElPtr)element->qLink;
152 int SIOUXSocket::select(Boolean * canRead, Boolean * canWrite, Boolean * exception)
156 if ( !initialized) DoInitialize();
160 if (*canRead = input_pending())
174 int SIOUXSocket::isatty()
179 /********************* SIOUXSocketDomain members **********************/
183 extern void GUSISetupMSLSIOUX();
187 extern "C" void GUSIwithSIOUXSockets()
189 static SIOUXSocketDomain SIOUXSockets;
190 SIOUXSockets.DontStrip();
198 Boolean SIOUXSocketDomain::Yours(const GUSIFileRef & ref, FileSocketDomain::Request request)
200 if (ref.spec || (request != willOpen && request != willStat))
203 switch (ref.name[4] | 0x20) {
205 if ((ref.name[5] | 0x20) != 't' || (ref.name[6] | 0x20) != 'd')
207 switch (ref.name[7] | 0x20) {
209 if ((ref.name[8] | 0x20) != 'n' || ref.name[9])
213 if ((ref.name[8] | 0x20) != 'u' || (ref.name[9] | 0x20) != 't' || ref.name[10])
217 if ((ref.name[8] | 0x20) != 'r' || (ref.name[9] | 0x20) != 'r' || ref.name[10])
224 if ( (ref.name[5] | 0x20) != 'o' || (ref.name[6] | 0x20) != 'n'
225 || (ref.name[7] | 0x20) != 's' || (ref.name[8] | 0x20) != 'o'
226 || (ref.name[9] | 0x20) != 'l' || (ref.name[10] | 0x20) != 'e')
228 switch (ref.name[11]) {
239 Socket * SIOUXSocketDomain::open(const GUSIFileRef &, int)
242 singleton = new SIOUXSocket();