Make modpython support network modules

This commit is contained in:
Kyle Fuller
2011-08-23 20:03:31 +01:00
parent 9a2fed6923
commit 260421e6e8
4 changed files with 28 additions and 26 deletions

View File

@@ -15,6 +15,7 @@
#include "../Nick.h"
#include "../Chan.h"
#include "../User.h"
#include "../IRCNetwork.h"
#include "../Client.h"
#include "../IRCSock.h"
#include "../Listener.h"
@@ -97,6 +98,7 @@ namespace std {
%include "../Nick.h"
%include "../Chan.h"
%include "../User.h"
%include "../IRCNetwork.h"
%include "../Client.h"
%include "../IRCSock.h"
%include "../Listener.h"
@@ -165,6 +167,15 @@ public:
}
};
%extend CIRCNetwork {
CString __str__() {
return $self->GetName();
}
CString __repr__() {
return "<CIRCNetwork " + $self->GetName() + ">";
}
}
%extend CChan {
CString __str__() {
return $self->GetName();

View File

@@ -23,16 +23,9 @@ class CPyModule : public CModule {
CModPython* m_pModPython;
VWebSubPages* _GetSubPages();
public:
CPyModule(const CString& sModName, const CString& sDataPath,
CPyModule(CUser* pUser, CIRCNetwork* pNetwork, const CString& sModName, const CString& sDataPath,
PyObject* pyObj, CModule* pModPython)
: CModule(NULL, NULL, sModName, sDataPath) {
m_pyObj = pyObj;
Py_INCREF(pyObj);
m_pModPython = reinterpret_cast<CModPython*>(pModPython);
}
CPyModule(CUser* pUser, const CString& sModName, const CString& sDataPath,
PyObject* pyObj, CModule* pModPython)
: CModule(NULL, pUser, sModName, sDataPath) {
: CModule(NULL, pUser, pNetwork, sModName, sDataPath) {
m_pyObj = pyObj;
Py_INCREF(pyObj);
m_pModPython = reinterpret_cast<CModPython*>(pModPython);
@@ -122,12 +115,8 @@ static inline CPyModule* AsPyModule(CModule* p) {
return dynamic_cast<CPyModule*>(p);
}
inline CPyModule* CreateUserPyModule(CUser* pUser, const CString& sModName, const CString& sDataPath, PyObject* pyObj, CModule* pModPython) {
return new CPyModule(pUser, sModName, sDataPath, pyObj, pModPython);
}
inline CPyModule* CreateGlobalPyModule(const CString& sModName, const CString& sDataPath, PyObject* pyObj, CModule* pModPython) {
return new CPyModule(sModName, sDataPath, pyObj, pModPython);
inline CPyModule* CreatePyModule(CUser* pUser, CIRCNetwork* pNetwork, const CString& sModName, const CString& sDataPath, PyObject* pyObj, CModule* pModPython) {
return new CPyModule(pUser, pNetwork, sModName, sDataPath, pyObj, pModPython);
}
class CPyTimer : public CTimer {

View File

@@ -423,7 +423,7 @@ def find_open(modname):
return (None, None)
def load_module(modname, args, module_type, user, retmsg, modpython):
def load_module(modname, args, module_type, user, network, retmsg, modpython):
'''Returns 0 if not found, 1 on loading error, 2 on success'''
if re.search(r'[^a-zA-Z0-9_]', modname) is not None:
retmsg.s = 'Module names can only contain letters, numbers and ' \
@@ -443,14 +443,7 @@ def load_module(modname, args, module_type, user, retmsg, modpython):
return 1
module = cl()
if module_type == CModInfo.UserModule:
module._cmod = CreateUserPyModule(user, modname, datapath, module, modpython)
elif module_type == CModInfo.GlobalModule:
module._cmod = CreateGlobalPyModule(modname, datapath, module, modpython)
else:
retmsg.s = "Module [modpython] doesn't support module type."
return 1
module._cmod = CreatePyModule(user, network, modname, datapath, module, modpython)
module.nv = ModuleNV(module._cmod)
module.SetDescription(cl.description)
module.SetArgs(args)
@@ -463,6 +456,12 @@ def load_module(modname, args, module_type, user, retmsg, modpython):
unload_module(module)
return 1
user.GetModules().push_back(module._cmod)
elif module_type == CModInfo.NetworkModule:
if not network:
retmsg.s = "Module [modpython] needs a network for for NetworkModule."
unload_module(module)
return 1
network.GetModules().push_back(module._cmod)
elif module_type == CModInfo.GlobalModule:
CZNC.Get().GetModules().push_back(module._cmod)
else:
@@ -511,6 +510,8 @@ def unload_module(module):
cmod = module._cmod
if module.GetType() == CModInfo.UserModule:
cmod.GetUser().GetModules().removeModule(cmod)
elif module.GetType() == CModInfo.NetworkModule:
cmod.GetNetwork().GetModules().removeModule(cmod)
elif module.GetType() == CModInfo.GlobalModule:
CZNC.Get().GetModules().removeModule(cmod)
del module._cmod