WorkingDirManager.h
3.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#ifndef WORKINGDIRMANAGER_H
#define WORKINGDIRMANAGER_H
#include <string>
#include "WorkingDirListLoader.h"
#include "../Application/Application.h"
#define WORKINGDIR_LIST_FILE "list.xml"
//max try to find a unique id for a new working dir
#define WORKINGDIR_MAX_TRY 10
//name of the testdir
#define WORKINGDIR_TEST_ID "testdir"
//name of the lokc file
#define WORKINGDIR_LOCK_FILE "lock"
//time to wait between two test to know if a working dir is locked (in seconds)
#define WORKINGDIR_LOCK_SLEEPTIME 1
//timeout (in seconds) during what a process can wait to lock a dir
#define WORKINGDIR_LOCK_WAITTIMEOUT 600
using namespace TREPS::Application;
namespace TREPS
{
namespace WorkingDirManager
{
class WorkingDirManagerClass
{
public:
WorkingDirManagerClass(void);
~WorkingDirManagerClass(void);
//create a new workind dir - add it in the list file
string createNewDir(bool useTestDir);
//get the path to a working dir from operation id
string getWorkingDirFromId(const char *id);
//remove a working dir from operation id
bool removeWorkingDirFromId(const char *id);
//get the full path of the source file from operation id
string getSourcePathFromId(const char *id);
//get the full path to the result file from operation id
string getResultPathFromId(const char *id);
//get the full path to the export file from operation id
string getExportedPathFromId(const char *id);
//get the full path to the transformation request file from operation id
string getTransformationRequestFromId(const char *id);
//get the full path to the lock file from operation id
//if operation is null, get the full path tot the lock of the general working dir
string getLockFilePath(const char *id = NULL);
//set a working dir active for log
//lockFileName become the new log file in the workind dir
void setActiveForLog(const char *id, const char *logFileName);
//lock a working dir
//if id is null, lock the general working dir
bool lockDir(const char *id = NULL);
//unlock a working dir
//if id is null, unlock the general working dir
void unlockDir(const char *id = NULL);
//get the current status from operation id
string getStatusFromId(const char *id);
//set the current status from operation id
bool setStatusFromId(const char *id, const char *requestId, const char *status);
//reset the current status from operation id
void resetStatusFromId(const char *id);
private:
ApplicationClass *app;
string mainDir;
//loader for the operations list file
WorkingDirListLoaderClass *listLoader;
//get tje full path of the operations list file
string getListFilePath(void);
//clean old working dir
bool cleanOldWorkingDirs(void);
//manager initialization
//if clean == true, clean old working dir
bool init(bool clean = false);
//get the PID that currently block a dircetory
int getCrtLockedPID(const char *lockPath);
//try to modify a lock file for this process
bool tryToModifyLockFile(const char *lockPath, bool unlock);
};
}
}
#endif