Permalink
Browse files

Progress on modpython global hooks.

OnModuleLoading, OnModuleUnloading, OnGetModInfo work fine.
Need to add: OnClientCapLs, OnGetAvailableMods, OnLoginAttempt

See #98
  • Loading branch information...
1 parent 5b50003 commit 5656e14aa2a1b7727ee5cb8ed7cde93412c1dd10 @DarthGandalf DarthGandalf committed Jul 22, 2012
View
@@ -18,7 +18,7 @@
#include "modpython/swigpyrun.h"
#include "modpython/module.h"
-#include "modpython/retstring.h"
+#include "modpython/ret.h"
class CModPython: public CModule {
@@ -197,6 +197,11 @@ class CModPython: public CModule {
Py_CLEAR(pyFunc);
return HALT;
}
+ if (!PyObject_IsTrue(pyRes)) {
+ // python module, but not handled by modpython itself.
+ // some module-loader written on python loaded it?
+ return CONTINUE;
+ }
Py_CLEAR(pyFunc);
Py_CLEAR(pyRes);
bSuccess = true;
@@ -268,6 +268,13 @@
say $out "Py_BuildValue(\"s\", $a->{var}.c_str());";
}
}
+ when (/^bool/) {
+ if ($a->{mod} eq '&') {
+ say $out "CPyRetBool::wrap($a->{var});";
+ } else {
+ say $out "Py_BuildValue(\"l\", (long int)$a->{var});";
+ }
+ }
when (/\*$/) {
(my $t = $a->{type}) =~ s/^const//;
say $out "SWIG_NewInstanceObj(const_cast<$t>($a->{var}), SWIG_TypeQuery(\"$t\"), 0);";
@@ -276,9 +283,6 @@
(my $b = $a->{base}) =~ s/^const//;
say $out "SWIG_NewInstanceObj(const_cast<$b*>(&$a->{var}), SWIG_TypeQuery(\"$b*\"), 0);";
}
- when ('bool') {
- say $out "Py_BuildValue(\"l\", (long int)$a->{var});";
- }
when (/(?:^|::)E/) {
say $out "Py_BuildValue(\"i\", (int)$a->{var});";
}
@@ -31,7 +31,7 @@
#include "../include/znc/Buffer.h"
#include "modpython/module.h"
-#include "modpython/retstring.h"
+#include "modpython/ret.h"
#define stat struct stat
using std::allocator;
@@ -91,6 +91,17 @@ namespace std {
}
}
+/*TODO %typemap(in) bool& to be able to call from python functions which get bool& */
+
+%typemap(out) bool&, bool* {
+ if ($1) {
+ $result = CPyRetBool::wrap(*$1);
+ } else {
+ $result = Py_None;
+ Py_INCREF(Py_None);
+ }
+}
+
#define u_short unsigned short
#define u_int unsigned int
#include "../include/znc/ZNCString.h"
@@ -139,6 +150,18 @@ public:
}
};
+class CPyRetBool {
+ CPyRetBool();
+ public:
+ bool b;
+};
+
+%extend CPyRetBool {
+ bool __bool__() {
+ return $self->b;
+ }
+}
+
%extend CModule {
CString __str__() {
return $self->GetModName();
@@ -211,6 +234,18 @@ public:
}
};
+/* To allow module-loaders to be written on python.
+ * They can call CreatePyModule() to create CModule* object, but one of arguments to CreatePyModule() is "CModule* pModPython"
+ * Pointer to modpython is already accessible to python modules as self.GetModPython(), but it's just a pointer to something, not to CModule*.
+ * So make it known that CModPython is really a CModule.
+ */
+class CModPython : public CModule {
+private:
+ CModPython();
+ CModPython(const CModPython&);
+ ~CModPython();
+};
+
/* Web */
%template(StrPair) std::pair<CString, CString>;
@@ -122,6 +122,7 @@ class CPyModule : public CModule {
virtual EModRet OnModuleUnloading(CModule* pModule, bool& bSuccess, CString& sRetMsg);
virtual EModRet OnGetModInfo(CModInfo& ModInfo, const CString& sModule,
bool& bSuccess, CString& sRetMsg);
+ virtual void OnGetAvailableMods(set<CModInfo>& ssMods, CModInfo::EModuleType eType);
};
static inline CPyModule* AsPyModule(CModule* p) {
@@ -18,4 +18,12 @@ class CPyRetString {
}
};
-
+class CPyRetBool {
+public:
+ bool& b;
+ CPyRetBool(bool& B) : b(B) {}
+ static PyObject* wrap(bool& B) {
+ CPyRetBool* x = new CPyRetBool(B);
+ return SWIG_NewInstanceObj(x, SWIG_TypeQuery("CPyRetBool*"), SWIG_POINTER_OWN);
+ }
+};
View
@@ -549,6 +549,8 @@ def load_module(modname, args, module_type, user, network, retmsg, modpython):
def unload_module(module):
+ if (module not in _py_modules):
+ return False
module.OnShutdown()
_py_modules.discard(module)
cmod = module._cmod
@@ -561,6 +563,7 @@ def unload_module(module):
del module._cmod
cmod.DeletePyModule()
del cmod
+ return True
def unload_all():

0 comments on commit 5656e14

Please sign in to comment.