[pywin32-checkins] pywin32/win32/src PythonService.cpp,1.22,1.23
OLD project page for the Python extensions for Windows
Brought to you by:
mhammond
From: Mark H. <mha...@us...> - 2008-02-07 03:33:15
|
Update of /cvsroot/pywin32/pywin32/win32/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv8131/src Modified Files: PythonService.cpp Log Message: Take advantage of all RegisterServiceCtrlHandler() functionality in a backwards compatible way, including a demo. Index: PythonService.cpp =================================================================== RCS file: /cvsroot/pywin32/pywin32/win32/src/PythonService.cpp,v retrieving revision 1.22 retrieving revision 1.23 diff -C2 -d -r1.22 -r1.23 *** PythonService.cpp 22 Jan 2008 11:58:01 -0000 1.22 --- PythonService.cpp 7 Feb 2008 03:33:15 -0000 1.23 *************** *** 93,96 **** --- 93,97 ---- SERVICE_STATUS_HANDLE sshStatusHandle; // the handle for this service. PyObject *obServiceCtrlHandler; // The Python control handler for the service. + BOOL bUseEx; // does this handler expect the extra args? } PY_SERVICE_TABLE_ENTRY; *************** *** 317,323 **** { PyObject *nameOb, *obCallback; // @pyparm <o PyUnicode>|serviceName||The name of the service. This is provided in args[0] of the service class __init__ method. // @pyparm object|callback||The Python function that performs as the control function. This will be called with an integer status argument. ! if (!PyArg_ParseTuple(args, "OO", &nameOb, &obCallback)) return NULL; if (!PyCallable_Check(obCallback)) { --- 318,326 ---- { PyObject *nameOb, *obCallback; + BOOL bUseEx = FALSE; // @pyparm <o PyUnicode>|serviceName||The name of the service. This is provided in args[0] of the service class __init__ method. // @pyparm object|callback||The Python function that performs as the control function. This will be called with an integer status argument. ! // @pyparm bool|extra_args|False|Is this callback expecting the additional 2 args passed by HandlerEx? ! if (!PyArg_ParseTuple(args, "OO|i", &nameOb, &obCallback, &bUseEx)) return NULL; if (!PyCallable_Check(obCallback)) { *************** *** 336,339 **** --- 339,343 ---- Py_XDECREF(pe->obServiceCtrlHandler); pe->obServiceCtrlHandler = obCallback; + pe->bUseEx = bUseEx; Py_INCREF(obCallback); if (bServiceDebug) { // If debugging, get out now, and give None back. *************** *** 341,351 **** return Py_None; } ! if (g_RegisterServiceCtrlHandlerEx) { ! // Use 2K/XP extended registration if available ! pe->sshStatusHandle = g_RegisterServiceCtrlHandlerEx(szName, service_ctrl_ex, pe); ! } else { ! // Otherwise fall back to NT ! pe->sshStatusHandle = RegisterServiceCtrlHandler(szName, service_ctrl); ! } PyWinObject_FreeWCHAR(szName); PyObject *rc; --- 345,355 ---- return Py_None; } ! if (g_RegisterServiceCtrlHandlerEx) { ! // Use 2K/XP extended registration if available ! pe->sshStatusHandle = g_RegisterServiceCtrlHandlerEx(szName, service_ctrl_ex, pe); ! } else { ! // Otherwise fall back to NT ! pe->sshStatusHandle = RegisterServiceCtrlHandler(szName, service_ctrl); ! } PyWinObject_FreeWCHAR(szName); PyObject *rc; *************** *** 706,709 **** --- 710,714 ---- PythonServiceTable[0].sshStatusHandle = 0; PythonServiceTable[0].obServiceCtrlHandler = NULL; + PythonServiceTable[0].bUseEx = 0; return TRUE; } *************** *** 750,753 **** --- 755,759 ---- PythonServiceTable[i].sshStatusHandle = 0; PythonServiceTable[i].obServiceCtrlHandler = NULL; + PythonServiceTable[i].bUseEx = 0; return TRUE; } *************** *** 910,914 **** // we are running on NT or 2K/XP. ! DWORD WINAPI dispatchServiceCtrl(DWORD dwCtrlCode, PY_SERVICE_TABLE_ENTRY *pse) { --- 916,921 ---- // we are running on NT or 2K/XP. ! DWORD WINAPI dispatchServiceCtrl(DWORD dwCtrlCode, DWORD dwEventType, ! LPVOID eventData, PY_SERVICE_TABLE_ENTRY *pse) { *************** *** 921,925 **** DWORD dwResult; CEnterLeavePython celp; ! PyObject *args = Py_BuildValue("(l)", dwCtrlCode); PyObject *result = PyObject_CallObject(pse->obServiceCtrlHandler, args); Py_XDECREF(args); --- 928,959 ---- DWORD dwResult; CEnterLeavePython celp; ! PyObject *args; ! if (pse->bUseEx) { ! PyObject *sub; ! switch (dwEventType) { ! case SERVICE_CONTROL_DEVICEEVENT: ! sub = PyWinObject_FromPARAM((LPARAM)eventData); ! break; ! case SERVICE_CONTROL_POWEREVENT: { ! POWERBROADCAST_SETTING *pbs = (POWERBROADCAST_SETTING *)eventData; ! sub = Py_BuildValue("NN", ! PyWinObject_FromIID(pbs->PowerSetting), ! PyString_FromStringAndSize((char *)pbs->Data, pbs->DataLength)); ! break; ! } ! case SERVICE_CONTROL_SESSIONCHANGE: { ! WTSSESSION_NOTIFICATION *sn = (WTSSESSION_NOTIFICATION *)eventData; ! sub = Py_BuildValue("(i)", sn->dwSessionId); ! break; ! } ! default: ! sub = Py_None; ! Py_INCREF(sub); ! break; ! } ! args = Py_BuildValue("(llN)", dwCtrlCode, dwEventType, sub); ! } else { ! args = Py_BuildValue("(l)", dwCtrlCode); ! } PyObject *result = PyObject_CallObject(pse->obServiceCtrlHandler, args); Py_XDECREF(args); *************** *** 944,948 **** { PY_SERVICE_TABLE_ENTRY *pse = (PY_SERVICE_TABLE_ENTRY *)lpContext; ! return dispatchServiceCtrl(dwCtrlCode, pse); } --- 978,982 ---- { PY_SERVICE_TABLE_ENTRY *pse = (PY_SERVICE_TABLE_ENTRY *)lpContext; ! return dispatchServiceCtrl(dwCtrlCode, dwEventType, lpEventData, pse); } *************** *** 951,955 **** ) { ! dispatchServiceCtrl(dwCtrlCode, &PythonServiceTable[0]); } --- 985,989 ---- ) { ! dispatchServiceCtrl(dwCtrlCode, 0, NULL, &PythonServiceTable[0]); } |