MCPcopy Create free account
hub / github.com/mhammond/pywin32 / dispatchServiceCtrl

Function dispatchServiceCtrl

win32/src/PythonService.cpp:941–1004  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

939// we are running on NT or 2K/XP.
940
941DWORD WINAPI dispatchServiceCtrl(DWORD dwCtrlCode, DWORD dwEventType,
942 LPVOID eventData,
943 PY_SERVICE_TABLE_ENTRY *pse)
944{
945 if (pse->obServiceCtrlHandler==NULL) { // Python is in error.
946 if (!bServiceDebug)
947 SetServiceStatus( pse->sshStatusHandle, &errorStatus );
948 return ERROR_CALL_NOT_IMPLEMENTED;
949 }
950 // Ensure we have a context for our thread.
951 DWORD dwResult;
952 CEnterLeavePython celp;
953 PyObject *args;
954 if (pse->bUseEx) {
955 PyObject *sub;
956 switch (dwCtrlCode) {
957 case SERVICE_CONTROL_DEVICEEVENT:
958 sub = PyWinObject_FromPARAM((LPARAM)eventData);
959 break;
960 case SERVICE_CONTROL_POWEREVENT: {
961 if (dwEventType == PBT_POWERSETTINGCHANGE) {
962 POWERBROADCAST_SETTING *pbs = (POWERBROADCAST_SETTING *)eventData;
963 sub = Py_BuildValue("NN",
964 PyWinObject_FromIID(pbs->PowerSetting),
965 PyString_FromStringAndSize((char *)pbs->Data, pbs->DataLength));
966 } else {
967 sub = Py_None;
968 Py_INCREF(Py_None);
969 }
970 break;
971 }
972 case SERVICE_CONTROL_SESSIONCHANGE: {
973 WTSSESSION_NOTIFICATION *sn = (WTSSESSION_NOTIFICATION *)eventData;
974 sub = Py_BuildValue("(i)", sn->dwSessionId);
975 break;
976 }
977 default:
978 sub = Py_None;
979 Py_INCREF(sub);
980 break;
981 }
982 args = Py_BuildValue("(llN)", dwCtrlCode, dwEventType, sub);
983 } else {
984 args = Py_BuildValue("(l)", dwCtrlCode);
985 }
986 PyObject *result = PyObject_CallObject(pse->obServiceCtrlHandler, args);
987 Py_XDECREF(args);
988 if (result==NULL) {
989 ReportPythonError(PYS_E_SERVICE_CONTROL_FAILED);
990 dwResult = ERROR_CALL_NOT_IMPLEMENTED; // correct code?
991 }
992 else if (result == Py_None)
993 dwResult = NOERROR;
994 else{
995 dwResult = PyInt_AsUnsignedLongMask(result);
996 if (dwResult == -1 && PyErr_Occurred()){
997 ReportPythonError(PYS_E_SERVICE_CONTROL_FAILED);
998 dwResult = ERROR_SERVICE_SPECIFIC_ERROR;

Callers 2

service_ctrl_exFunction · 0.85
service_ctrlFunction · 0.85

Calls 3

PyWinObject_FromPARAMFunction · 0.85
PyWinObject_FromIIDFunction · 0.85
ReportPythonErrorFunction · 0.85

Tested by

no test coverage detected