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