Modules: Add a module version of CJob

Signed-off-by: Uli Schlachter <psychon@znc.in>
This commit is contained in:
Uli Schlachter
2014-08-06 15:32:41 +02:00
parent 0fddbba230
commit 308df21511
3 changed files with 89 additions and 0 deletions
+37
View File
@@ -19,6 +19,7 @@
#include <znc/zncconfig.h>
#include <znc/WebModules.h>
#include <znc/Threads.h>
#include <znc/main.h>
#include <set>
#include <queue>
@@ -177,6 +178,29 @@ private:
FPTimer_t m_pFBCallback;
};
#ifdef HAVE_PTHREAD
/// A CJob version which can be safely used in modules. The job will be
/// cancelled when the module is unloaded.
class CModuleJob : public CJob {
public:
CModuleJob(CModule *pModule, const CString& sName, const CString& sDesc)
: CJob(), m_pModule(pModule), m_sName(sName), m_sDescription(sDesc) {
}
virtual ~CModuleJob();
// Getters
CModule* GetModule() const { return m_pModule; }
const CString& GetName() const { return m_sName; }
const CString& GetDescription() const { return m_sDescription; }
// !Getters
protected:
CModule* m_pModule;
const CString m_sName;
const CString m_sDescription;
};
#endif
class CModInfo {
public:
typedef CModule* (*ModLoader)(ModHandle p, CUser* pUser, CIRCNetwork* pNetwork, const CString& sModName, const CString& sModPath);
@@ -885,6 +909,16 @@ public:
virtual void ListSockets();
// !Socket stuff
#ifdef HAVE_PTHREAD
// Job stuff
void AddJob(CModuleJob *pJob);
void CancelJob(CModuleJob *pJob);
bool CancelJob(const CString& sJobName);
void CancelJobs(const std::set<CModuleJob*>& sJobs);
bool UnlinkJob(CModuleJob *pJob);
// !Job stuff
#endif
// Command stuff
/// Register the "Help" command.
void AddHelpCommand();
@@ -1052,6 +1086,9 @@ protected:
CString m_sDescription;
std::set<CTimer*> m_sTimers;
std::set<CSocket*> m_sSockets;
#ifdef HAVE_PTHREAD
std::set<CModuleJob*> m_sJobs;
#endif
ModHandle m_pDLL;
CSockManager* m_pManager;
CUser* m_pUser;
+2
View File
@@ -213,6 +213,8 @@ private:
* After you create a new instance of your class, you can pass it to
* CThreadPool()::Get().addJob(job) to start it. The thread pool automatically
* deletes your class after it finished.
*
* For modules you should use CModuleJob instead.
*/
class CJob {
public: