Changeset 6049 for trunk/src/kernel32/hmevent.cpp
- Timestamp:
- Jun 19, 2001, 12:50:26 PM (24 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/kernel32/hmevent.cpp
r5332 r6049 1 /* $Id: hmevent.cpp,v 1. 4 2001-03-19 19:27:13sandervl Exp $ */1 /* $Id: hmevent.cpp,v 1.5 2001-06-19 10:50:24 sandervl Exp $ */ 2 2 3 3 /* 4 * Win32 Event Semaphore implementation 5 * 6 * TODO: Inheritance 7 * TODO: Does DCE_POSTONE work in Warp 3 or 4 with no FP applied? 8 * TODO: No inheritance when CreateEvent is called for existing named event semaphore? 9 * (see HMCreateEvent in handlemanager.cpp) 10 * TODO: Name collisions with files & mutex not allowed. Check if this can happen in OS/2 11 * 4 12 * Project Odin Software License can be found in LICENSE.TXT 5 * Win32 Unified Handle Manager for OS/26 * Copyright 1999 Patrick Haller (haller@zebra.fh-weingarten.de)13 * 14 * Copyright 2001 Sander van Leeuwen (sandervl@xs4all.nl) 7 15 */ 8 16 … … 22 30 *****************************************************************************/ 23 31 32 #ifdef USE_OS2SEMAPHORES 33 #define INCL_DOSSEMAPHORES 34 #include <os2wrap.h> 35 #include <win32type.h> 36 #include <win32api.h> 37 #include <winconst.h> 38 #else 24 39 #include <os2win.h> 40 #endif 41 25 42 #include <stdlib.h> 26 43 #include <string.h> … … 30 47 #include "HandleManager.H" 31 48 #include "HMEvent.h" 49 #include "oslibdos.h" 32 50 33 51 #define DBG_LOCALLOG DBG_hmevent 34 52 #include "dbglocal.h" 53 54 #ifndef DCE_AUTORESET 55 #define DCE_AUTORESET 0x1000 /* DosCreateEventSem option to auto-reset */ 56 /* event semaphore on post. */ 57 #define DCE_POSTONE 0x0800 /* DosCreateEventSem option to post only */ 58 /* waiter and auto-reset the semaphore when*/ 59 /* there are multiple waiters. */ 60 #endif 35 61 36 62 /***************************************************************************** … … 65 91 LPCTSTR lpszEventName) 66 92 { 67 HANDLE hOpen32; 93 #ifdef USE_OS2SEMAPHORES 94 APIRET rc; 95 HEV hev; 96 char szSemName[CCHMAXPATH]; 68 97 69 98 dprintf(("KERNEL32: HandleManager::Event::CreateEvent(%08xh,%08xh,%08xh,%08xh,%s)\n", … … 74 103 lpszEventName)); 75 104 105 if(lpszEventName) { 106 strcpy(szSemName, "\\SEM32\\"); 107 strcat(szSemName, lpszEventName); 108 lpszEventName = szSemName; 109 } 110 //Manual reset means all threads waiting on the event semaphore will be 111 //unblocked and the app must manually reset the event semaphore 112 //Automatic reset -> only one waiting thread unblocked & state reset 113 rc = DosCreateEventSem(lpszEventName, &hev, (fManualReset) ? 0 : DCE_POSTONE, fInitialState); 114 115 if(rc) { 116 dprintf(("DosCreateEventSem %x failed with rc %d", pHMHandleData->hHMHandle, rc)); 117 pHMHandleData->hHMHandle = 0; 118 return error2WinError(rc); 119 } 120 pHMHandleData->dwAccess = EVENT_ALL_ACCESS_W; 121 pHMHandleData->dwFlags = fManualReset; 122 pHMHandleData->hHMHandle = hev; 123 return ERROR_SUCCESS_W; 124 #else 125 HANDLE hOpen32; 126 127 dprintf(("KERNEL32: HandleManager::Event::CreateEvent(%08xh,%08xh,%08xh,%08xh,%s)\n", 128 pHMHandleData, 129 lpsa, 130 fManualReset, 131 fInitialState, 132 lpszEventName)); 133 76 134 hOpen32 = O32_CreateEvent(lpsa, // call Open32 77 135 fManualReset, … … 86 144 else 87 145 return (O32_GetLastError()); 146 #endif 88 147 } 89 148 … … 105 164 LPCTSTR lpszEventName) 106 165 { 107 HANDLE hOpen32; 166 #ifdef USE_OS2SEMAPHORES 167 HEV hev; 168 APIRET rc; 169 char szSemName[CCHMAXPATH]; 108 170 109 171 dprintf(("KERNEL32: HandleManager::Event::OpenEvent(%08xh,%08xh,%s)\n", … … 112 174 lpszEventName)); 113 175 176 if(lpszEventName == NULL) { 177 pHMHandleData->hHMHandle = 0; 178 return ERROR_INVALID_PARAMETER_W; 179 } 180 181 strcpy(szSemName, "\\SEM32\\"); 182 strcat(szSemName, lpszEventName); 183 rc = DosOpenEventSem(szSemName, &hev); 184 if(rc) { 185 dprintf(("DosOpenEventSem %x failed with rc %d", pHMHandleData->hHMHandle, rc)); 186 pHMHandleData->hHMHandle = 0; 187 return error2WinError(rc); 188 } 189 pHMHandleData->hHMHandle = hev; 190 return ERROR_SUCCESS_W; 191 #else 192 HANDLE hOpen32; 193 194 dprintf(("KERNEL32: HandleManager::Event::OpenEvent(%08xh,%08xh,%s)\n", 195 pHMHandleData, 196 fInheritHandle, 197 lpszEventName)); 198 114 199 hOpen32 = O32_OpenEvent(pHMHandleData->dwAccess, // call Open32 115 200 fInheritHandle, … … 123 208 else 124 209 return (O32_GetLastError()); 125 } 126 210 #endif 211 } 212 213 /***************************************************************************** 214 * Name : HMDeviceEventClass::CloseHandle 215 * Purpose : close the handle 216 * Parameters: PHMHANDLEDATA pHMHandleData 217 * Variables : 218 * Result : API returncode 219 * Remark : 220 * Status : 221 * 222 * Author : 223 *****************************************************************************/ 224 225 #ifdef USE_OS2SEMAPHORES 226 BOOL HMDeviceEventClass::CloseHandle(PHMHANDLEDATA pHMHandleData) 227 { 228 APIRET rc; 229 230 if(pHMHandleData->hHMHandle) { 231 rc = DosCloseEventSem((HEV)pHMHandleData->hHMHandle); 232 if(rc) { 233 dprintf(("DosCloseEventSem %x failed with rc %d", pHMHandleData->hHMHandle, rc)); 234 SetLastError(error2WinError(rc)); 235 return FALSE; 236 } 237 } 238 return TRUE; 239 } 240 #endif 241 242 /***************************************************************************** 243 * Name : HMDeviceEventClass::DuplicateHandle 244 * Purpose : 245 * Parameters: 246 * various parameters as required 247 * Variables : 248 * Result : 249 * Remark : the standard behaviour is to return an error code for non- 250 * existant request codes 251 * Status : 252 * 253 * Author : 254 *****************************************************************************/ 255 #ifdef USE_OS2SEMAPHORES 256 BOOL HMDeviceEventClass::DuplicateHandle(PHMHANDLEDATA pHMHandleData, HANDLE srcprocess, 257 PHMHANDLEDATA pHMSrcHandle, 258 HANDLE destprocess, 259 PHANDLE desthandle, 260 DWORD fdwAccess, 261 BOOL fInherit, 262 DWORD fdwOptions, 263 DWORD fdwOdinOptions) 264 { 265 APIRET rc; 266 HEV hev; 267 268 dprintf(("KERNEL32:HandleManager::DuplicateHandle %s(%08x,%08x,%08x,%08x,%08x) - NOT IMPLEMENTED!!!!!!!!\n", 269 lpHMDeviceName, 270 pHMHandleData, 271 srcprocess, pHMSrcHandle, destprocess, desthandle)); 272 273 if(srcprocess != destprocess) { 274 DebugInt3(); 275 SetLastError(ERROR_ACCESS_DENIED_W); 276 return FALSE; 277 } 278 hev = (HEV)pHMSrcHandle->hHMHandle; 279 rc = DosOpenEventSem(NULL, &hev); 280 if(rc) { 281 dprintf(("DosOpenEventSem %x failed with rc %d", pHMSrcHandle->hHMHandle, rc)); 282 pHMHandleData->hHMHandle = 0; 283 SetLastError(error2WinError(rc)); 284 return FALSE; 285 } 286 pHMHandleData->dwAccess = fdwAccess; 287 pHMHandleData->dwFlags = pHMSrcHandle->dwFlags; //fManualReset 288 pHMHandleData->hHMHandle = hev; 289 SetLastError(ERROR_SUCCESS_W); 290 return TRUE; 291 } 292 #endif 127 293 128 294 /***************************************************************************** … … 140 306 BOOL HMDeviceEventClass::SetEvent(PHMHANDLEDATA pHMHandleData) 141 307 { 142 //testestest 308 #ifdef USE_OS2SEMAPHORES 309 APIRET rc; 310 143 311 dprintf(("KERNEL32: HandleManager::Event::SetEvent(%08xh)\n", 144 312 pHMHandleData->hHMHandle)); 145 313 314 if(!(pHMHandleData->dwAccess & EVENT_MODIFY_STATE_W) ) 315 { 316 dprintf(("ERROR: Access denied!!")); 317 SetLastError(ERROR_ACCESS_DENIED_W); 318 return FALSE; 319 } 320 321 rc = DosPostEventSem(pHMHandleData->hHMHandle); 322 if(rc) { 323 dprintf(("DosPostEventSem %x failed with rc %d", pHMHandleData->hHMHandle, rc)); 324 SetLastError(error2WinError(rc)); 325 return FALSE; 326 } 327 SetLastError(ERROR_SUCCESS_W); 328 return TRUE; 329 #else 330 dprintf(("KERNEL32: HandleManager::Event::SetEvent(%08xh)\n", 331 pHMHandleData->hHMHandle)); 332 146 333 return (O32_SetEvent(pHMHandleData->hHMHandle)); 334 #endif 147 335 } 148 336 … … 162 350 BOOL HMDeviceEventClass::PulseEvent(PHMHANDLEDATA pHMHandleData) 163 351 { 352 #ifdef USE_OS2SEMAPHORES 353 APIRET rc; 354 ULONG count; 355 164 356 dprintf2(("KERNEL32: HandleManager::Event::PulseEvent(%08xh)\n", 165 357 pHMHandleData->hHMHandle)); 166 358 359 if(!(pHMHandleData->dwAccess & EVENT_MODIFY_STATE_W) ) 360 { 361 dprintf(("ERROR: Access denied!!")); 362 SetLastError(ERROR_ACCESS_DENIED_W); 363 return FALSE; 364 } 365 366 rc = DosPostEventSem(pHMHandleData->hHMHandle); 367 if(rc) { 368 dprintf(("DosPostEventSem %x failed with rc %d", pHMHandleData->hHMHandle, rc)); 369 SetLastError(error2WinError(rc)); 370 return FALSE; 371 } 372 if(pHMHandleData->dwFlags == TRUE) {//fManualReset 373 rc = DosResetEventSem(pHMHandleData->hHMHandle, &count); 374 if(rc) { 375 dprintf(("DosResetEventSem %x failed with rc %d", pHMHandleData->hHMHandle, rc)); 376 SetLastError(error2WinError(rc)); 377 return FALSE; 378 } 379 } 380 SetLastError(ERROR_SUCCESS_W); 381 return TRUE; 382 #else 383 dprintf2(("KERNEL32: HandleManager::Event::PulseEvent(%08xh)\n", 384 pHMHandleData->hHMHandle)); 385 167 386 return (O32_PulseEvent(pHMHandleData->hHMHandle)); 387 #endif 168 388 } 169 389 … … 183 403 BOOL HMDeviceEventClass::ResetEvent(PHMHANDLEDATA pHMHandleData) 184 404 { 405 #ifdef USE_OS2SEMAPHORES 406 APIRET rc; 407 ULONG count; 408 185 409 dprintf2(("KERNEL32: HandleManager::Event::ResetEvent(%08xh)\n", 186 410 pHMHandleData->hHMHandle)); 187 411 412 if(!(pHMHandleData->dwAccess & EVENT_MODIFY_STATE_W) ) 413 { 414 dprintf(("ERROR: Access denied!!")); 415 SetLastError(ERROR_ACCESS_DENIED_W); 416 return FALSE; 417 } 418 419 rc = DosResetEventSem(pHMHandleData->hHMHandle, &count); 420 if(rc) { 421 dprintf(("DosResetEventSem %x failed with rc %d", pHMHandleData->hHMHandle, rc)); 422 SetLastError(error2WinError(rc)); 423 return FALSE; 424 } 425 SetLastError(ERROR_SUCCESS_W); 426 return TRUE; 427 #else 428 dprintf2(("KERNEL32: HandleManager::Event::ResetEvent(%08xh)\n", 429 pHMHandleData->hHMHandle)); 430 188 431 return (O32_ResetEvent(pHMHandleData->hHMHandle)); 189 } 190 432 #endif 433 } 434
Note:
See TracChangeset
for help on using the changeset viewer.