source: trunk/src/kernel32/console/vio32Client.h@ 5120

Last change on this file since 5120 was 5024, checked in by sandervl, 25 years ago

added preliminary console code

File size: 5.5 KB
Line 
1#if !defined (KBD32_CLIENT_H)
2#define KBD32_CLIENT_H
3
4#define INCL_WIN
5#define INCL_DOS
6#define INCL_VIO
7#define INCL_SUB
8#define INCL_DOSERRORS
9#define INCL_WINSWITCHLIST
10#include <os2.h>
11#include "DosQuerySysState2.h"
12#include <stdio.h>
13#include <stdlib.h>
14
15#include "vio32SharedData.h"
16#include "vio32Errors.h"
17
18//#define VIO32_PREFILTER 0x00000
19//#define VIO32_POSTFILTER 0x10000
20
21//
22class kbd32Client{
23 // semaphore to allow muliple threads to use the structures of VIO32
24 HMTX mux;
25 // semaphore used to access shared memory
26 HMTX accessSemaphore;
27 /// the shared memory address.
28 kbd32SharedData *SharedData;
29 /// when the kbd32 is active = TRUE
30 BOOL patched;
31 /// the message queue used to collect all the messages
32 HQUEUE primaryQ;
33 /// the message queue where the processed messages are written to
34 HQUEUE secondaryQ;
35 /// a semaphore used to wait on the primary Q
36 HEV primaryQSem;
37 /// a semaphore used to wait on the secondary Q
38 HEV secondaryQSem;
39 /// the id of the thread listening to VIO kbd api
40 TID kbdThreadId;
41 /// the id of the thread listening to a monitor
42 TID kbdMonitorThreadId;
43 /// the id of the thread listening to the mou events
44 TID mouThreadId;
45 /// the id of the thread elaborating data
46 TID dataProcessingThreadId;
47 /// a flag to get the threads to exit.
48 BOOL threadsMustContinue;
49 /// the monitor handles
50 HMONITOR mon;
51 /// the monitor handles
52 MONIN monin;
53 /// the monitor handles
54 MONOUT monout;
55 ///
56 HMOU mou;
57 ///
58 ULONG applicationType;
59 ///
60 ULONG applicationPid;
61 ///
62 HWND hwndFrame;
63 ///
64 HWND hwndClient;
65 //
66 VIO32EVENTINFO events[MAX_SECONDARY_Q_LEN];
67 //
68 VIO32EVENTINFO *pos;
69 // filters acting on the data stream as soon as it gets to the main Q
70 vio32Filter *inputFilters;
71 // filters acting on the data read
72 vio32Filter *outputFilters;
73 // the status of the keyboard + mouse buttons
74 VIO32STATUSINFO keyStatus;
75 ///
76 APIRET _removeFilter(VOID *filterData,vio32Filter *&list);
77public:
78
79 ///
80 VOID kbdThread();
81 ///
82 VOID mouThread();
83 ///
84 VOID kbdMonitorThread();
85 ///
86 VOID dataProcessingThread();
87 /// do all the general initialization needed for Open
88 APIRET init();
89 /// clean - up all the initialization done by init();
90 VOID finish();
91 /// gets a buffer
92 VIO32EVENTINFO *getBuffer(){
93 if (pos >= (&events[MAX_PRIMARY_Q_LEN])) pos = &events[0];
94 return pos;
95 }
96 /// automatically updates the pointer
97 void advanceBuffer() { pos++; }
98
99 ///
100 VIO32STATUSINFO &KeyStatus() { return keyStatus; }
101
102public:
103 ///
104 void SharedLock() { DosRequestMutexSem(accessSemaphore,SEM_INDEFINITE_WAIT); }
105 ///
106 void SharedUnlock() { DosReleaseMutexSem(accessSemaphore); }
107 ///
108 void LocalLock() { DosRequestMutexSem(mux,SEM_INDEFINITE_WAIT); }
109 ///
110 void LocalUnlock() { DosReleaseMutexSem(mux); }
111 /// this initialization simply connects to the shared memory or creates it
112 kbd32Client();
113 ///
114 ~kbd32Client();
115 ///
116 APIRET Open();
117 ///
118 APIRET Close();
119 ///
120 APIRET GetKeyStroke(KBD32KEYINFO *key,ULONG msecTimeout);
121 ///
122 APIRET GetMouse(VIO32MOUINFO *mou,ULONG msecTimeout);
123 ///
124 APIRET GetEvent(VIO32EVENTINFO *event,ULONG *eventType,ULONG msecTimeout);
125 ///
126 APIRET PeekEvent(VIO32EVENTINFO *event,ULONG *eventType,ULONG position);
127 ///
128 APIRET FlushEventQ();
129 ///
130 APIRET GetEventQSize(ULONG *size,ULONG msecTimeout);
131 ///
132 APIRET WriteEvent(VIO32EVENTINFO *event, ULONG *eventType);
133 /// copies the kbd status to the user provided variable status. Will flush all the events..
134 APIRET GetKeyStatus(VIO32STATUSINFO *status);
135 ///
136 APIRET SetMode(ULONG mode){
137 if (patched==FALSE) return VIO32_NOTOPENED;
138 if (SharedData == NULL) return VIO32_SHMEMNOTALLOCATED;
139 return SharedData->SetMode(mode,applicationPid);
140 }
141 ///
142 APIRET GetMode(ULONG *mode){
143 if (patched==FALSE) return VIO32_NOTOPENED;
144 if (SharedData == NULL) return VIO32_SHMEMNOTALLOCATED;
145 if (mode==NULL) return VIO32_INVALIDPARAM;
146 return SharedData->GetMode(*mode,applicationPid);
147 }
148 /// filter content is copied into a new allocated structure
149 APIRET AddFilter(vio32Filter *filter,ULONG &where);
150 ///
151 APIRET RemoveFilter(VOID *filterData);
152
153};
154
155extern kbd32Client kbd32ClientInstance;
156
157// the filter that deals with KBD messages and MOU messages and FOCUS messages in order to produce the correct KBD32 messages and MOU32 messages
158extern vio32Filter kbdMapper;
159#define KBD32_REMAPPER_NAME "KbdMapper"
160
161#endif
Note: See TracBrowser for help on using the repository browser.