agent error codes updated
[public/netxms.git] / src / server / include / nxcore_jobs.h
CommitLineData
ab621f39
VK
1/*
2** NetXMS - Network Management System
3** Copyright (C) 2003-2009 Victor Kirhenshtein
4**
5** This program is free software; you can redistribute it and/or modify
6** it under the terms of the GNU General Public License as published by
7** the Free Software Foundation; either version 2 of the License, or
8** (at your option) any later version.
9**
10** This program is distributed in the hope that it will be useful,
11** but WITHOUT ANY WARRANTY; without even the implied warranty of
12** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13** GNU General Public License for more details.
14**
15** You should have received a copy of the GNU General Public License
16** along with this program; if not, write to the Free Software
17** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18**
19** File: nxcore_jobs.h
20**
21**/
22
23#ifndef _nxcore_jobs_h_
24#define _nxcore_jobs_h_
25
26
27//
28// Job status
29//
30
31enum ServerJobStatus
32{
33 JOB_PENDING = 0,
34 JOB_ACTIVE,
35 JOB_ON_HOLD,
36 JOB_COMPLETED,
f40831eb
VK
37 JOB_FAILED,
38 JOB_CANCELLED
ab621f39
VK
39};
40
41
42//
43// Job class
44//
45
46class ServerJobQueue;
47
48class NXCORE_EXPORTABLE ServerJob
49{
50private:
51 DWORD m_id;
52 TCHAR *m_type;
53 DWORD m_remoteNode;
54 TCHAR *m_description;
55 ServerJobStatus m_status;
56 int m_progress;
57 TCHAR *m_failureMessage;
58 THREAD m_workerThread;
59 ServerJobQueue *m_owningQueue;
60
61 static DWORD s_freeId;
62 static THREAD_RESULT THREAD_CALL WorkerThreadStarter(void *);
63
64protected:
65 virtual bool run();
66 virtual bool onCancel();
67
68 void markProgress(int pctCompleted);
69 void setFailureMessage(const TCHAR *msg);
70
71public:
72 ServerJob(const TCHAR *type, const TCHAR *description, DWORD node);
73 virtual ~ServerJob();
74
75 void start();
76 bool cancel();
77
78 DWORD getId() { return m_id; }
79 const TCHAR *getType() { return m_type; }
80 const TCHAR *getDescription() { return m_description; }
81 ServerJobStatus getStatus() { return m_status; }
82 int getProgress() { return m_progress; }
83 DWORD getRemoteNode() { return m_remoteNode; }
84 const TCHAR *getFailureMessage() { return CHECK_NULL(m_failureMessage); }
85
86 void setOwningQueue(ServerJobQueue *queue);
87};
88
89
90//
91// Job queue class
92//
93
94class ServerJobQueue
95{
96private:
97 int m_jobCount;
98 ServerJob **m_jobList;
99 MUTEX m_accessMutex;
100
101public:
102 ServerJobQueue();
103 ~ServerJobQueue();
104
105 void add(ServerJob *job);
f40831eb 106 bool cancel(DWORD jobId);
ab621f39
VK
107 void runNext();
108
f40831eb
VK
109 ServerJob *findJob(DWORD jobId);
110
ab621f39
VK
111 void jobCompleted(ServerJob *job);
112
113 DWORD fillMessage(CSCPMessage *msg, DWORD *varIdBase);
114};
115
116
117//
118// Job manager API
119//
120
121bool NXCORE_EXPORTABLE AddJob(ServerJob *job);
122void GetJobList(CSCPMessage *msg);
f40831eb 123DWORD CancelJob(DWORD userId, CSCPMessage *msg);
ab621f39
VK
124
125#endif /* _nxcore_jobs_h_ */