#include "AliCommunicationThread.h" #include "AliStorageEventManager.h" #include #include using namespace std; AliCommunicationThread::AliCommunicationThread(AliStorageClientThread *onlineReconstructionManager) : fFinished(false), fManager(onlineReconstructionManager), fCommunicationThread(0) { //create two-way communication thread fCommunicationThread = new TThread("fCommunicationThread",Dispatch,(void*)this); fCommunicationThread->Run(); } AliCommunicationThread::~AliCommunicationThread() { if(fCommunicationThread){delete fCommunicationThread;} } void AliCommunicationThread::Kill() { if(fCommunicationThread) { fFinished=true; fCommunicationThread->Join(); fCommunicationThread->Kill(); } } void AliCommunicationThread::CommunicationHandle() { AliStorageEventManager *eventManager = AliStorageEventManager::GetEventManagerInstance(); storageSockets socket = CLIENT_COMMUNICATION_REP; eventManager->CreateSocket(socket); struct clientRequestStruct *request; struct clientRequestStruct *response = new struct clientRequestStruct; cout<<"CLIENT -- Communication stated"<GetClientStruct(socket,5000); if(request) { // lock_guard lock(mtx); cout<<"COMMUNICATION -- received request"<messageType) { case REQUEST_CONNECTION: eventManager->Send((long)fManager->fConnectionStatus,socket); break; case REQUEST_RECEIVING: eventManager->Send((long)fManager->fReceivingStatus,socket); break; case REQUEST_SAVING: eventManager->Send((long)fManager->fSavingStatus,socket); break; case REQUEST_CURRENT_SIZE: eventManager->Send((long)fManager->fCurrentStorageSize,socket); break; case REQUEST_GET_PARAMS: response->maxStorageSize = fManager->fMaximumStorageSize; response->maxOccupation = fManager->fStorageOccupationLevel; response->removeEvents = fManager->fRemoveEventsPercentage; response->eventsInChunk = fManager->fNumberOfEventsInFile; eventManager->Send(response,socket); break; case REQUEST_SET_PARAMS: SetStorageParams(request->maxStorageSize, request->maxOccupation, request->removeEvents, request->eventsInChunk); fManager->fMaximumStorageSize = request->maxStorageSize; fManager->fStorageOccupationLevel = request->maxOccupation; fManager->fRemoveEventsPercentage = request->removeEvents; fManager->fNumberOfEventsInFile = request->eventsInChunk; eventManager->Send(true,socket); break; default:break; } delete request; } else{cout<<"COMMUNICATION -- received NO request"<