fixed incorrect handling of pathes ending with \
[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,
37 JOB_FAILED
38};
39
40
41//
42// Job class
43//
44
45class ServerJobQueue;
46
47class NXCORE_EXPORTABLE ServerJob
48{
49private:
50 DWORD m_id;
51 TCHAR *m_type;
52 DWORD m_remoteNode;
53 TCHAR *m_description;
54 ServerJobStatus m_status;
55 int m_progress;
56 TCHAR *m_failureMessage;
57 THREAD m_workerThread;
58 ServerJobQueue *m_owningQueue;
59
60 static DWORD s_freeId;
61 static THREAD_RESULT THREAD_CALL WorkerThreadStarter(void *);
62
63protected:
64 virtual bool run();
65 virtual bool onCancel();
66
67 void markProgress(int pctCompleted);
68 void setFailureMessage(const TCHAR *msg);
69
70public:
71 ServerJob(const TCHAR *type, const TCHAR *description, DWORD node);
72 virtual ~ServerJob();
73
74 void start();
75 bool cancel();
76
77 DWORD getId() { return m_id; }
78 const TCHAR *getType() { return m_type; }
79 const TCHAR *getDescription() { return m_description; }
80 ServerJobStatus getStatus() { return m_status; }
81 int getProgress() { return m_progress; }
82 DWORD getRemoteNode() { return m_remoteNode; }
83 const TCHAR *getFailureMessage() { return CHECK_NULL(m_failureMessage); }
84
85 void setOwningQueue(ServerJobQueue *queue);
86};
87
88
89//
90// Job queue class
91//
92
93class ServerJobQueue
94{
95private:
96 int m_jobCount;
97 ServerJob **m_jobList;
98 MUTEX m_accessMutex;
99
100public:
101 ServerJobQueue();
102 ~ServerJobQueue();
103
104 void add(ServerJob *job);
105 void runNext();
106
107 void jobCompleted(ServerJob *job);
108
109 DWORD fillMessage(CSCPMessage *msg, DWORD *varIdBase);
110};
111
112
113//
114// Job manager API
115//
116
117bool NXCORE_EXPORTABLE AddJob(ServerJob *job);
118void GetJobList(CSCPMessage *msg);
119
120
121#endif /* _nxcore_jobs_h_ */