void ClientMain::reminderThread (  )  [private]

Definition at line 398 of file ClientMain.cpp.

00398                                 {
00399         while (working) {
00400                 // wait for the specified period of time
00401                 sleep(pollingPeriod);
00402                 bool goOn = true;
00403                 // send the callback if still working
00404                 if (working) {
00405                         cout << DateFormater::getDate() << "Sending the server an alive statement..." << endl;
00406                         try {
00407                                 bool answerReceived;
00408                                 AliveStatement aliveStatement(pServiceOffer->getSessionId());
00409                                 Message response;
00410                                 answerReceived = sendAndReceive("callback",aliveStatement,response);
00411                                 if (answerReceived) {
00412                                         bool found = false;
00413                                         if ( !found ) try {
00414                                                 GoOnCommand goc = response;
00415                                                 goOn = true;
00416                                                 cout << DateFormater::getDate() << "The server wants us to go on calculating." << endl;
00417                                                 found = true;
00418                                         }
00419                                         catch ( MessageCastException& e ) {}
00420                                         if ( !found ) try {
00421                                                 StopCommand sc = response;
00422                                                 goOn = false;
00423                                                 cout << DateFormater::getDate() << "The server wants us to stop the calculation." << endl;
00424                                                 found = true;
00425                                         }
00426                                         catch ( MessageCastException& e ) {}
00427                                         if ( !found ) {
00428                                                 goOn = false;
00429                                                 cout << DateFormater::getDate() << "Unexpected answer from the server." << endl;
00430                                                 cout << DateFormater::getDate() << "Stopping the calculation." << endl;
00431                                                 // prevents the client to ask for another service
00432                                                 allowRequestService = false;
00433                                         }
00434                                 }
00435                                 else {
00436                                         goOn = false;
00437                                         cout << DateFormater::getDate() << "Can't communicate with server." << endl;
00438                                         cout << DateFormater::getDate() << "Stopping the calculation." << endl;
00439                                         // prevents the client to ask for another service
00440                                         allowRequestService = false;
00441                                 }
00442                         }
00443                         catch ( NetInterfaceException& e ) {
00444                                 goOn = false;
00445                                 cout << DateFormater::getDate() << "Connection failed..." << endl;
00446                                 cout << DateFormater::getDate() << "NetInterface: ";
00447                                 e.print();
00448                                 cout << DateFormater::getDate() << "Stopping the calculation." << endl;
00449                                 // prevents the client to ask for another service
00450                                 allowRequestService = false;
00451                         }
00452                 }
00453                 // stop working and kill the worker thread if the server wants so
00454                 if (!goOn) {
00455                         enterCriticalSection();
00456                         working = false;
00457                         serviceNeeded = false;
00458                         if ( pthread_cancel(worker) ) {
00459                                 cout << DateFormater::getDate() << "Cancelation of the worker failed!" << endl;
00460                         }
00461                         leaveCriticalSection();
00462                 }
00463         }
00464 }


Generated on Wed Jun 25 14:47:08 2008 for keyvil by  doxygen 1.5.1