1 #include "AliCommunicationThread.h"
2 #include "AliStorageEventManager.h"
9 AliCommunicationThread::AliCommunicationThread(AliStorageClientThread *onlineReconstructionManager) :
11 fManager(onlineReconstructionManager),
12 fCommunicationThread(0)
14 //create two-way communication thread
15 fCommunicationThread = new TThread("fCommunicationThread",Dispatch,(void*)this);
16 fCommunicationThread->Run();
19 AliCommunicationThread::~AliCommunicationThread()
21 if(fCommunicationThread){delete fCommunicationThread;}
24 void AliCommunicationThread::Kill()
26 if(fCommunicationThread)
29 fCommunicationThread->Join();
30 fCommunicationThread->Kill();
34 void AliCommunicationThread::CommunicationHandle()
36 AliStorageEventManager *eventManager = AliStorageEventManager::GetEventManagerInstance();
37 storageSockets socket = CLIENT_COMMUNICATION_REP;
38 eventManager->CreateSocket(socket);
40 struct clientRequestStruct *request;
41 struct clientRequestStruct *response = new struct clientRequestStruct;
43 cout<<"CLIENT -- Communication stated"<<endl;
49 cout<<"COMMUNICATION -- waiting for requests"<<endl;
50 request = eventManager->GetClientStruct(socket,5000);
54 lock_guard<mutex> lock(mtx);
55 cout<<"COMMUNICATION -- received request"<<endl;
56 switch(request->messageType)
58 case REQUEST_CONNECTION:
59 eventManager->Send((long)fManager->fConnectionStatus,socket);
61 case REQUEST_RECEIVING:
62 eventManager->Send((long)fManager->fReceivingStatus,socket);
65 eventManager->Send((long)fManager->fSavingStatus,socket);
67 case REQUEST_CURRENT_SIZE:
68 eventManager->Send((long)fManager->fCurrentStorageSize,socket);
70 case REQUEST_GET_PARAMS:
71 response->maxStorageSize = fManager->fMaximumStorageSize;
72 response->maxOccupation = fManager->fStorageOccupationLevel;
73 response->removeEvents = fManager->fRemoveEventsPercentage;
74 response->eventsInChunk = fManager->fNumberOfEventsInFile;
76 eventManager->Send(response,socket);
78 case REQUEST_SET_PARAMS:
79 SetStorageParams(request->maxStorageSize,
80 request->maxOccupation,
81 request->removeEvents,
82 request->eventsInChunk);
84 fManager->fMaximumStorageSize = request->maxStorageSize;
85 fManager->fStorageOccupationLevel = request->maxOccupation;
86 fManager->fRemoveEventsPercentage = request->removeEvents;
87 fManager->fNumberOfEventsInFile = request->eventsInChunk;
89 eventManager->Send(true,socket);
95 else{cout<<"COMMUNICATION -- received NO request"<<endl;}
99 void AliCommunicationThread::SetStorageParams(int maxStorageSize,int maxOccupation,int removeEvents,int eventsInChunk)
101 cout<<maxStorageSize<<endl<<maxOccupation<<endl<<removeEvents<<endl<<eventsInChunk<<endl;
104 ifstream configFile (GetConfigFilePath());
105 ofstream tmpFile("tmpFile.bla");
107 if (configFile.is_open())
112 while(configFile.good())
114 getline(configFile,line);
115 from = line.find("\"")+1;
116 to = line.find_last_of("\"");
118 if(line.find("MAX_SIZE=")==0){
119 tmpLine = Form("MAX_SIZE=\"%d\"",maxStorageSize);
121 else if(line.find("MAX_OCCUPATION=")==0){
122 tmpLine = Form("MAX_OCCUPATION=\"%d\"",maxOccupation);
124 else if(line.find("REMOVE_PERCENT=")==0){
125 tmpLine = Form("REMOVE_PERCENT=\"%d\"",removeEvents);
127 else if(line.find("EVENTS_IN_FILE=")==0){
128 tmpLine = Form("EVENTS_IN_FILE=\"%d\"",eventsInChunk);
133 if(configFile.eof()){configFile.clear();}
136 rename("tmpFile.bla",GetConfigFilePath());
138 else{cout<<"CLIENT -- Unable to open config file"<<endl;}