Ignore:
Timestamp:
Jun 18, 2009, 11:53:26 AM (16 years ago)
Author:
ydario
Message:

Kernel32 updates.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/kernel32/hmevent.cpp

    r9748 r21302  
    1515 */
    1616
    17 #undef DEBUG_LOCAL
    18 //#define DEBUG_LOCAL
    19 
    2017
    2118/*****************************************************************************
     
    4239#include "oslibdos.h"
    4340
     41#include "hmhandle.h"
     42
     43
    4444#define DBG_LOCALLOG    DBG_hmevent
    4545#include "dbglocal.h"
    4646
    47 /*****************************************************************************
    48  * Defines                                                                   *
    49  *****************************************************************************/
    50 
    51 /*****************************************************************************
    52  * Structures                                                                *
    53  *****************************************************************************/
    54 
    55 /*****************************************************************************
    56  * Local Prototypes                                                          *
    57  *****************************************************************************/
     47
     48/*****************************************************************************
     49 * Name      : HANDLE  HMCreateEvent
     50 * Purpose   : Wrapper for the CreateEvent() API
     51 * Parameters:
     52 * Variables :
     53 * Result    :
     54 * Remark    :
     55 * Status    :
     56 *
     57 * Author    : Patrick Haller [Wed, 1998/02/11 20:44]
     58 *****************************************************************************/
     59
     60HANDLE WIN32API CreateEventA(LPSECURITY_ATTRIBUTES lpsa,
     61                             BOOL                  bManualReset,
     62                             BOOL                  bInitialState,
     63                             LPCTSTR               lpName)
     64{
     65  PHMHANDLE pHandle;
     66  DWORD     rc;                                     /* API return code */
     67
     68
     69  if(lpName) { //check if shared event semaphore already exists
     70      dprintf(("Event semaphore name %s", lpName));
     71      //TODO: No inheritance??
     72      HANDLE handle = OpenEventA(EVENT_ALL_ACCESS, FALSE, lpName);
     73      if(handle) {
     74          dprintf(("CreateEvent: return handle of existing event semaphore %x", handle));
     75          SetLastError(ERROR_ALREADY_EXISTS);
     76          return handle;
     77      }
     78  }
     79
     80  pHandle = HMHandleGetFreePtr(HMTYPE_EVENTSEM);                         /* get free handle */
     81  if (pHandle == NULL)                            /* oops, no free handles ! */
     82  {
     83    SetLastError(ERROR_NOT_ENOUGH_MEMORY);      /* use this as error message */
     84    return 0;
     85  }
     86
     87  /* call the device handler */
     88  rc = pHandle->pDeviceHandler->CreateEvent(&pHandle->hmHandleData,
     89                                   lpsa,
     90                                   bManualReset,
     91                                   bInitialState,
     92                                   lpName);
     93  if (rc != NO_ERROR)     /* oops, creation failed within the device handler */
     94  {
     95    HMHandleFree(pHandle->hmHandleData.hWin32Handle);
     96    SetLastError(rc);         
     97    return 0;                           /* signal error */
     98  }
     99  else
     100    SetLastError(ERROR_SUCCESS); //@@@PH 1999/10/27 rc5desg requires this?
     101
     102  return pHandle->hmHandleData.hWin32Handle;                                   /* return valid handle */
     103}
     104
     105/*****************************************************************************
     106 * Name      : BOOL CreateEventW
     107 * Purpose   : forward call to Open32
     108 * Parameters:
     109 * Variables :
     110 * Result    :
     111 * Remark    : handle translation is done in CreateEventA
     112 * Status    :
     113 *
     114 * Author    : Patrick Haller [Fri, 1998/06/12 03:44]
     115 *****************************************************************************/
     116
     117HANDLE WIN32API CreateEventW(LPSECURITY_ATTRIBUTES arg1,
     118                             BOOL arg2, BOOL arg3,
     119                             LPCWSTR arg4)
     120{
     121  HANDLE rc;
     122  char  *astring;
     123
     124  if (arg4 != NULL) // support for unnamed semaphores
     125    astring = UnicodeToAsciiString((LPWSTR)arg4);
     126  else
     127    astring = NULL;
     128
     129  rc = CreateEventA(arg1,
     130                    arg2,
     131                    arg3,
     132                    astring);
     133
     134  if (astring != NULL)
     135    FreeAsciiString(astring);
     136
     137  return(rc);
     138}
     139
     140/*****************************************************************************
     141 * Name      : HANDLE  HMOpenEvent
     142 * Purpose   : Wrapper for the OpenEvent() API
     143 * Parameters:
     144 * Variables :
     145 * Result    :
     146 * Remark    :
     147 * Status    :
     148 *
     149 * Author    : Patrick Haller [Wed, 1998/02/11 20:44]
     150 *****************************************************************************/
     151
     152HANDLE WIN32API OpenEventA(DWORD   fdwAccess,
     153                           BOOL    fInherit,
     154                           LPCTSTR lpName)
     155{
     156  PHMHANDLE pHandle;
     157  DWORD     rc;                                     /* API return code */
     158
     159  if(lpName) {
     160      dprintf(("Event semaphore name %s", lpName));
     161  }
     162
     163  pHandle = HMHandleGetFreePtr(HMTYPE_EVENTSEM);                         /* get free handle */
     164  if (pHandle == NULL)                            /* oops, no free handles ! */
     165  {
     166    SetLastError(ERROR_NOT_ENOUGH_MEMORY);      /* use this as error message */
     167    return 0;
     168  }
     169  pHandle->hmHandleData.dwAccess   = fdwAccess;
     170                                                  /* call the device handler */
     171  rc = pHandle->pDeviceHandler->OpenEvent(&pHandle->hmHandleData,
     172                                 fInherit,
     173                                 lpName);
     174  if (rc != NO_ERROR)     /* oops, creation failed within the device handler */
     175  {
     176    HMHandleFree(pHandle->hmHandleData.hWin32Handle);
     177    SetLastError(rc);
     178    return 0;                           /* signal error */
     179  }
     180  else
     181    SetLastError(ERROR_SUCCESS); //@@@PH 1999/10/27 rc5desg requires this?
     182
     183  return pHandle->hmHandleData.hWin32Handle;                                   /* return valid handle */
     184}
     185
     186/*****************************************************************************
     187 * Name      : HMSetEvent
     188 * Purpose   : router function for SetEvent
     189 * Parameters:
     190 * Variables :
     191 * Result    :
     192 * Remark    :
     193 * Status    :
     194 *
     195 * Author    : Patrick Haller [Wed, 1999/06/17 20:44]
     196 *****************************************************************************/
     197
     198BOOL WIN32API SetEvent(HANDLE hEvent)
     199{
     200  DWORD     dwResult;                /* result from the device handler's API */
     201  PHMHANDLE pHMHandle;       /* pointer to the handle structure in the table */
     202
     203                                                          /* validate handle */
     204  pHMHandle = HMHandleQueryPtr(hEvent);              /* get the index */
     205  if (pHMHandle == NULL)                                     /* error ? */
     206  {
     207    return FALSE; //last error set by HMHandleQueryPtr (ERROR_INVALID_HANDLE)
     208  }
     209
     210  dwResult = pHMHandle->pDeviceHandler->SetEvent(&pHMHandle->hmHandleData);
     211
     212  return (dwResult);                                  /* deliver return code */
     213}
     214
     215
     216/*****************************************************************************
     217 * Name      : HMPulseEvent
     218 * Purpose   : router function for PulseEvent
     219 * Parameters:
     220 * Variables :
     221 * Result    :
     222 * Remark    :
     223 * Status    :
     224 *
     225 * Author    : Patrick Haller [Wed, 1999/06/17 20:44]
     226 *****************************************************************************/
     227
     228BOOL WIN32API PulseEvent(HANDLE hEvent)
     229{
     230  DWORD     dwResult;                /* result from the device handler's API */
     231  PHMHANDLE pHMHandle;       /* pointer to the handle structure in the table */
     232
     233                                                          /* validate handle */
     234  pHMHandle = HMHandleQueryPtr(hEvent);              /* get the index */
     235  if (pHMHandle == NULL)                                     /* error ? */
     236  {
     237    return FALSE; //last error set by HMHandleQueryPtr (ERROR_INVALID_HANDLE)
     238  }
     239
     240  dwResult = pHMHandle->pDeviceHandler->PulseEvent(&pHMHandle->hmHandleData);
     241
     242  return (dwResult);                                  /* deliver return code */
     243}
     244
     245
     246/*****************************************************************************
     247 * Name      : HMResetEvent
     248 * Purpose   : router function for ResetEvent
     249 * Parameters:
     250 * Variables :
     251 * Result    :
     252 * Remark    :
     253 * Status    :
     254 *
     255 * Author    : Patrick Haller [Wed, 1999/06/17 20:44]
     256 *****************************************************************************/
     257
     258BOOL WIN32API ResetEvent(HANDLE hEvent)
     259{
     260  DWORD     dwResult;                /* result from the device handler's API */
     261  PHMHANDLE pHMHandle;       /* pointer to the handle structure in the table */
     262
     263                                                          /* validate handle */
     264  pHMHandle = HMHandleQueryPtr(hEvent);              /* get the index */
     265  if (pHMHandle == NULL)                                     /* error ? */
     266  {
     267    return FALSE; //last error set by HMHandleQueryPtr (ERROR_INVALID_HANDLE)
     268  }
     269
     270  dwResult = pHMHandle->pDeviceHandler->ResetEvent(&pHMHandle->hmHandleData);
     271
     272  return (dwResult);                                  /* deliver return code */
     273}
    58274
    59275
     
    90306                            lpszEventName);
    91307
     308  dprintf(("KERNEL32: HandleManager::Semaphore::CreateEvent hOpen32 = %p, pHMHandleData->hHMHandle = %p\n", hOpen32, pHMHandleData->hHMHandle));
     309
    92310  if (0 != hOpen32)                            // check success
    93311  {
Note: See TracChangeset for help on using the changeset viewer.