Changeset 4265 for trunk/src/wnaspi32/aspilib.cpp
- Timestamp:
- Sep 15, 2000, 3:25:50 PM (25 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wnaspi32/aspilib.cpp
r4260 r4265 1 /* $Id: aspilib.cpp,v 1. 4 2000-09-14 19:09:16 sandervl Exp $ */1 /* $Id: aspilib.cpp,v 1.5 2000-09-15 13:25:46 sandervl Exp $ */ 2 2 /* 3 3 * ASPI Router Library … … 21 21 #include <stdio.h> 22 22 #include <misc.h> 23 #include "aspilib.h" 23 #include "aspilib.h" 24 25 #define WNASPI32_MUTEX_NAME "\\SEM32\\ODIN\\ASPIROUT" 24 26 25 27 //*************************************************************************** … … 30 32 //* * 31 33 //*************************************************************************** 32 scsiObj::scsiObj() : buffer(NULL) 34 scsiObj::scsiObj() : buffer(NULL), hmtxDriver(0) 33 35 { 34 36 memset(&SRBlock, 0, sizeof(SRBlock)); … … 202 204 BOOL scsiObj::init(ULONG bufsize) 203 205 { 204 BOOL success; 205 ULONG rc; 206 207 rc = DosAllocMem(&buffer, bufsize, OBJ_TILE | PAG_READ | PAG_WRITE | PAG_COMMIT); 208 if (rc) return FALSE; 209 success=openDriver(); // call openDriver member function 210 if (!success) return FALSE; 211 success=initSemaphore(); // call initSemaphore member function 212 if (!success) return FALSE; 213 214 success=initBuffer(); 215 216 return TRUE; 206 BOOL success; 207 APIRET rc; 208 209 210 rc = DosCreateMutexSem(WNASPI32_MUTEX_NAME, (HMTX*)&hmtxDriver, 211 0, TRUE); 212 if(rc == ERROR_DUPLICATE_NAME) { 213 rc = DosOpenMutexSem(WNASPI32_MUTEX_NAME, (HMTX*)&hmtxDriver); 214 } 215 if(rc != NO_ERROR) { 216 dprintf(("scsiObj::init: DosCreate/OpenMutexSem failed! (rc=%d)", rc)); 217 return FALSE; 218 } 219 220 rc = DosAllocMem(&buffer, bufsize, OBJ_TILE | PAG_READ | PAG_WRITE | PAG_COMMIT); 221 if (rc) return FALSE; 222 success=openDriver(); // call openDriver member function 223 if (!success) return FALSE; 224 success=initSemaphore(); // call initSemaphore member function 225 if (!success) return FALSE; 226 227 success=initBuffer(); 228 229 return TRUE; 217 230 } 218 231 … … 239 252 if (!success) 240 253 { 241 printf("closeSemaphore() unsuccessful.\n");254 dprintf(("scsiObj::close: closeSemaphore() unsuccessful.")); 242 255 return FALSE; 243 256 } … … 245 258 if (!success) 246 259 { 260 dprintf(("scsiObj::close: closeDriver() unsucessful.")); 247 261 return FALSE; 248 printf("closeDriver() unsucessful.\n");249 262 } 250 263 rc = DosFreeMem(buffer); 251 264 if (rc) 252 265 { 253 printf("DosFreeMem unsuccessful. return code: %ld\n", rc);266 dprintf(("scsiObj::close: DosFreeMem unsuccessful. return code: %ld", rc)); 254 267 return FALSE; 255 268 } 269 if(hmtxDriver) { 270 rc = DosCloseMutexSem((HMTX)hmtxDriver); 271 if(rc != NO_ERROR) { 272 dprintf(("scsiObj::close: DosCloseMutexSem unsuccessful. return code: %ld", rc)); 273 return FALSE; 274 } 275 } 276 256 277 return TRUE; 257 278 } … … 451 472 //*************************************************************************** 452 473 //*************************************************************************** 453 BOOL fGainDrvAccess( BOOL fWait, 454 ULONG *phSem) 455 { 456 ULONG rc; 457 rc = DosCreateMutexSem ( "\\SEM32\\ODIN\\ASPIROUT", 458 (HMTX*)phSem, 459 0, 460 TRUE); 461 if(NO_ERROR==rc) 462 return TRUE; 463 if((ERROR_DUPLICATE_NAME!=rc)||(!fWait)) 464 return FALSE; 465 rc = DosOpenMutexSem ( "\\SEM32\\ODIN\\ASPIROUT", 466 (HMTX*)phSem); 467 if(NO_ERROR!=rc) 468 return FALSE; 469 470 rc = DosRequestMutexSem( (HMTX)(*phSem), 471 SEM_INDEFINITE_WAIT); 472 473 if(NO_ERROR!=rc) 474 return FALSE; 475 476 return TRUE; 477 } 478 //*************************************************************************** 479 //*************************************************************************** 480 BOOL fReleaseDrvAccess(ULONG hSem) 481 { 482 ULONG rc; 483 BOOL frc = TRUE; 484 485 rc = DosReleaseMutexSem((HMTX)hSem); 486 if(NO_ERROR!=rc) 487 frc=FALSE; 488 489 rc = DosCloseMutexSem((HMTX)hSem); 490 if(NO_ERROR!=rc) 491 frc=FALSE; 492 493 return frc; 494 } 474 BOOL scsiObj::access(BOOL fWait) 475 { 476 APIRET rc; 477 478 if(!fWait) { 479 rc = DosRequestMutexSem((HMTX) hmtxDriver, SEM_INDEFINITE_WAIT); 480 } 481 else rc = DosRequestMutexSem((HMTX) hmtxDriver, 100); 482 483 if(rc != NO_ERROR) { 484 dprintf(("scsiObj::access: DosRequestMutexSem failed with rc = %d", rc)); 485 return FALSE; 486 } 487 return TRUE; 488 } 489 //*************************************************************************** 490 //*************************************************************************** 491 BOOL scsiObj::release() 492 { 493 APIRET rc; 494 495 rc = DosReleaseMutexSem((HMTX)hmtxDriver); 496 if(rc != NO_ERROR) { 497 dprintf(("scsiObj::access: DosReleaseMutexSem failed with rc = %d", rc)); 498 return FALSE; 499 } 500 501 return TRUE; 502 } 503 //*************************************************************************** 504 //***************************************************************************
Note:
See TracChangeset
for help on using the changeset viewer.