Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

SignRequestHandler.cc

00001 /*
00002  * Copyright 2003 Michael A. Marsh, Cornell University. All rights reserved.
00003  * This software is released under the modified BSD license.
00004  * See the file LICENSE in the top-level directory for details.
00005  */
00006 //
00007 // $Id: SignRequestHandler.cc,v 1.3 2004/05/19 15:56:59 mmarsh Exp $
00008 //
00009 // $Log: SignRequestHandler.cc,v $
00010 // Revision 1.3  2004/05/19 15:56:59  mmarsh
00011 // *** empty log message ***
00012 //
00013 // Revision 1.2  2003/11/04 22:31:51  mmarsh
00014 // *** empty log message ***
00015 //
00016 //
00017 
00018 #include "SignRequestHandler.h"
00019 #include "SignRequestEvent.h"
00020 #include "ServerState.h"
00021 
00022 #include "ServerExceptions.h"
00023 
00024 using namespace CODEX_Server;
00025 
00027 bool
00028 SignRequestHandler::handler( SignRequestEvent& event )
00029 {
00030    // If the broadcast does not reach a quorum, the event will be
00031    // re-queued.
00032    CODEX_Quorum::QuorumSystem* qs = ServerState::instance()->quorumSystem();
00033    if ( NULL == qs )
00034    {
00035       throw NoQuorumSystemException( __FILE__ , __LINE__ );
00036    }
00037    try
00038    {
00039       struct timeval tv;
00040       gettimeofday(&tv,0);
00041       if ( ( tv.tv_sec - event.time() ) < 3 )
00042       {
00043          return false;
00044       }
00045       event.updateTime( tv.tv_sec );
00046       if ( ! event.bcast() )
00047       {
00048          event.setBcast();
00049          bool bVal = qs->broadcastMessage( event.message(),
00050                                            event.retVals(),
00051                                            event.cb() );
00052          bool retVal = false;
00053          CODEX_Quorum::ReturnVector::const_iterator itr =
00054             event.retVals().begin();
00055          CODEX_Quorum::ReturnVector::const_iterator end =
00056             event.retVals().end();
00057          unsigned int nGood = 0;
00058          for ( ; itr != end ; ++itr )
00059          {
00060             if ( itr->returnCode() ==
00061                  CODEX_Quorum::RemoteServerReturn::kSuccess )
00062             {
00063                ++nGood;
00064             }
00065          }
00066          if ( nGood >= qs->quorumSize() )
00067          {
00068             retVal = true;
00069          }
00070          return retVal;
00071       }
00072       else
00073       {
00074          // We don't want to register the callback again.
00075          bool bVal = qs->broadcastMessage( event.message(),
00076                                            event.retVals(),
00077                                            NULL );
00078          bool retVal = false;
00079          CODEX_Quorum::ReturnVector::const_iterator itr =
00080             event.retVals().begin();
00081          CODEX_Quorum::ReturnVector::const_iterator end =
00082             event.retVals().end();
00083          unsigned int nGood = 0;
00084          for ( ; itr != end ; ++itr )
00085          {
00086             if ( itr->returnCode() ==
00087                  CODEX_Quorum::RemoteServerReturn::kSuccess )
00088             {
00089                ++nGood;
00090             }
00091          }
00092          if ( nGood >= qs->quorumSize() )
00093          {
00094             retVal = true;
00095          }
00096          return retVal;
00097       }
00098    }
00099    catch ( ... )
00100    {
00101       return false;
00102    }
00103 }

Generated on Fri May 6 17:41:15 2005 for COrnell Data EXchange (CODEX) by  doxygen 1.4.1