]>
Commit | Line | Data |
---|---|---|
5eb34a26 | 1 | #include "AliStorageClientThread.h" |
5eb34a26 | 2 | |
5eb34a26 | 3 | #include <signal.h> |
4 | #include <fstream> | |
5 | #include <iostream> | |
6 | ||
5eb34a26 | 7 | using namespace std; |
5eb34a26 | 8 | |
186c4b6e | 9 | bool gClientQuit = false; |
5eb34a26 | 10 | void GotSignalClient(int){gClientQuit = true;} |
11 | ||
12 | AliStorageClientThread::AliStorageClientThread() : | |
186c4b6e | 13 | fDIMListenerThread(0), |
14 | fEventsCollectorThread(0), | |
15 | fCommunicationThread(0), | |
5eb34a26 | 16 | fConnectionStatus(STATUS_WAITING), |
17 | fReceivingStatus(STATUS_WAITING), | |
18 | fSavingStatus(STATUS_WAITING), | |
5eb34a26 | 19 | fCurrentStorageSize(0), |
20 | fMaximumStorageSize(0), | |
21 | fStoragePath(""), | |
22 | fNumberOfEventsInFile(0), | |
23 | fStorageOccupationLevel(0), | |
24 | fRemoveEventsPercentage(0) | |
5eb34a26 | 25 | { |
186c4b6e | 26 | // make sure that when program is closed destructor will be called |
27 | struct sigaction sa; | |
28 | memset(&sa,0,sizeof(sa)); | |
29 | sa.sa_handler = GotSignalClient; | |
30 | sigfillset(&sa.sa_mask); | |
31 | sigaction(SIGINT,&sa,NULL); | |
2614f1cb | 32 | |
186c4b6e | 33 | ifstream configFile (GetConfigFilePath()); |
34 | if (configFile.is_open()) | |
35 | { | |
36 | string line; | |
37 | int from,to; | |
38 | while(configFile.good()) | |
39 | { | |
40 | getline(configFile,line); | |
41 | from = line.find("\"")+1; | |
42 | to = line.find_last_of("\""); | |
43 | if(line.find("STORAGE_PATH=")==0){ | |
44 | fStoragePath=line.substr(from,to-from); | |
45 | } | |
46 | else if(line.find("MAX_SIZE=")==0){ | |
47 | fMaximumStorageSize=atoi(line.substr(from,to-from).c_str()); | |
48 | } | |
49 | else if(line.find("MAX_OCCUPATION=")==0){ | |
50 | fStorageOccupationLevel=atoi(line.substr(from,to-from).c_str()); | |
51 | } | |
52 | else if(line.find("REMOVE_PERCENT=")==0){ | |
53 | fRemoveEventsPercentage=atoi(line.substr(from,to-from).c_str()); | |
54 | } | |
55 | else if(line.find("EVENTS_IN_FILE=")==0){ | |
56 | fNumberOfEventsInFile=atoi(line.substr(from,to-from).c_str()); | |
57 | } | |
58 | } | |
59 | if(configFile.eof()){configFile.clear();} | |
60 | configFile.close(); | |
61 | } | |
62 | else{cout<<"CLIENT -- Unable to open config file"<<endl;} | |
63 | ||
64 | //create directory for storage if it doesn't exist | |
65 | gSystem->Exec(Form("mkdir -p %s",fStoragePath.c_str())); | |
66 | ||
67 | fDIMListenerThread = new AliDIMListenerThread(); | |
68 | fEventsCollectorThread = new AliEventsCollectorThread(this); | |
69 | fCommunicationThread = new AliCommunicationThread(this); | |
5eb34a26 | 70 | } |
71 | ||
186c4b6e | 72 | AliStorageClientThread::~AliStorageClientThread() |
5eb34a26 | 73 | { |
186c4b6e | 74 | while(!gClientQuit){sleep(1);} |
36100d03 | 75 | if(fDIMListenerThread){delete fDIMListenerThread;} |
186c4b6e | 76 | fEventsCollectorThread->Kill(); |
77 | fCommunicationThread->Kill(); | |
36100d03 | 78 | } |