Пример #1
0
	virtual EModRet OnModuleUnloading(CModule* pModule, bool& bSuccess, CString& sRetMsg) {
		CPyModule* pMod = AsPyModule(pModule);
		if (pMod) {
			CString sModName = pMod->GetModName();
			PyObject* pyFunc = PyObject_GetAttrString(m_PyZNCModule, "unload_module");
			if (!pyFunc) {
				sRetMsg = GetPyExceptionStr();
				DEBUG("modpython: " << sRetMsg);
				bSuccess = false;
				return HALT;
			}
			PyObject* pyRes = PyObject_CallFunctionObjArgs(pyFunc, pMod->GetPyObj(), NULL);
			if (!pyRes) {
				sRetMsg = GetPyExceptionStr();
				DEBUG("modpython: " << sRetMsg);
				bSuccess = false;
				Py_CLEAR(pyFunc);
				return HALT;
			}
			Py_CLEAR(pyFunc);
			Py_CLEAR(pyRes);
			bSuccess = true;
			sRetMsg = "Module [" + sModName + "] unloaded";
			return HALT;
		}
		return CONTINUE;
	}
Пример #2
0
	EModRet OnModuleUnloading(CModule* pModule, bool& bSuccess, CString& sRetMsg) override {
		CPyModule* pMod = AsPyModule(pModule);
		if (pMod) {
			CString sModName = pMod->GetModName();
			PyObject* pyFunc = PyObject_GetAttrString(m_PyZNCModule, "unload_module");
			if (!pyFunc) {
				sRetMsg = GetPyExceptionStr();
				DEBUG("modpython: " << sRetMsg);
				bSuccess = false;
				return HALT;
			}
			PyObject* pyRes = PyObject_CallFunctionObjArgs(pyFunc, pMod->GetPyObj(), nullptr);
			if (!pyRes) {
				sRetMsg = GetPyExceptionStr();
				DEBUG("modpython: " << sRetMsg);
				bSuccess = false;
				Py_CLEAR(pyFunc);
				return HALT;
			}
			if (!PyObject_IsTrue(pyRes)) {
				// python module, but not handled by modpython itself.
				// some module-provider written on python loaded it?
				return CONTINUE;
			}
			Py_CLEAR(pyFunc);
			Py_CLEAR(pyRes);
			bSuccess = true;
			sRetMsg = "Module [" + sModName + "] unloaded";
			return HALT;
		}
		return CONTINUE;
	}