Esempio n. 1
0
bool
CCBListener::SendMsgToCCB(ClassAd &msg,bool blocking)
{
	if( !m_sock ) {
		Daemon ccb(DT_COLLECTOR,m_ccb_address.Value());

		int cmd = -1;
		msg.LookupInteger( ATTR_COMMAND, cmd );
		if( cmd != CCB_REGISTER ) {
			dprintf(D_ALWAYS,"CCBListener: no connection to CCB server %s"
					" when trying to send command %d\n",
					m_ccb_address.Value(), cmd );
			return false;
		}

		// Specifying USE_TMP_SEC_SESSION to force a fresh security
		// session.  Otherwise we can end up in a catch-22 where we
		// are trying to reconnect to the CCB server and we try to use
		// a cached security session which is no longer valid, but our
		// CCB server cannot send us the invalidation message because
		// we are trying to reconnect to it.  Expring this session
		// right away is also a good idea, because if we are just
		// starting up, the return address associated with it will not
		// have any CCB information attached, which again means that
		// the CCB server has no way to invalidate it.

		if( blocking ) {
			m_sock = ccb.startCommand( cmd, Stream::reli_sock, CCB_TIMEOUT, NULL, NULL, false, USE_TMP_SEC_SESSION );
			if( m_sock ) {
				Connected();
			}
			else {
				Disconnected();
				return false;
			}
		}
		else if( !m_waiting_for_connect ) {
			m_sock = ccb.makeConnectedSocket(Stream::reli_sock, CCB_TIMEOUT, 0, NULL, true /*nonblocking*/ );
			if( !m_sock ) {
				Disconnected();
				return false;
			}
			m_waiting_for_connect = true;
			incRefCount(); // do not let ourselves be deleted until called back
			ccb.startCommand_nonblocking( cmd, m_sock, CCB_TIMEOUT, NULL, CCBListener::CCBConnectCallback, this, NULL, false, USE_TMP_SEC_SESSION );
			return false;
		}
	}

	return WriteMsgToCCB(msg);
}
main()
{
    char option;
    AbstractPizza* ap1;
    while( option != 'n' )
    {
        order o2;
        o2.incrementordernumber();
        o2.menu();
        int choice;
        cout<<"\n\t\t********ORDER NUMBER:\t"<<o2.returnordernumber()<<"**********\n";
        choice=5;
        while(!(choice>=1 && choice<=4))
            {
                cout<<"\nPlease Enter Your Choice between 1 & 4:\t\t";
                cin>>choice;
            }
            switch(choice)
            {
        case(1):
                ap1= new ChickenTikkaPizza;
        break;
        case(2):
                ap1= new BeefRoastPizza;
        break;
        case(3):
                ap1= new FourSeasonPizza;
        break;
        case(4):
                ap1= new HawiianPizza;
        break;
        }
        o2.inputperson();
        char choice2='l';
              
        do
        {
            cout<<"\nPlease enter c to pay via credit card and p to pay via cash:\t";
            fflush(stdin);
            cin>>choice2;
        }
        while(!(choice2=='c' || choice2=='p'));
        if(choice2=='c')      
        {
            o2.c1input();
            creditcard cca(12, 2004, 1111222);
            creditcard ccb(12, 2004, 1234567);
            creditcard ccc(12, 2004, 9876543);
            creditcard ccd(12, 2004, 1212121);
            system("cls");
            if( ( o2.comparecredit(cca) || o2.comparecredit(ccb) || o2.comparecredit(ccc) || o2.comparecredit(ccd) ) && ( o2.returnc1size() >= ap1->returnprice() ) )
            {
                cout<<"\n\n\n\n\n\n****Your Account Balance\t"<<o2.returnc1size()<<"\n****Your Order Cost\t\t"<<ap1->returnprice()<<"\n****Balance after transaction\t"<<o2.returnc1size()-ap1->returnprice() ;
                ap1->bake();
            }
            else
            {
                if(!( o2.comparecredit(cca) || o2.comparecredit(ccb) || o2.comparecredit(ccc) || o2.comparecredit(ccd) ))
                cout<<"\n\n\n\n\n\nINVALID CREDIT CARD NUMBER , ORDER COULD NOT BE PROCESSED";
                else if(! ( o2.returnc1size() >= ap1->returnprice() ) )
                cout<<"\n\n\n\n\n\nINSUFFICIENT FUNDS , ORDER COULD NOT BE PROCESSED";
            }
        }
        else
            cout<<"\nThanks for paying by CASH";
        choice2='l';
        o2.displayperson();
        fflush(stdin);
        option=getch();
    }
    delete ap1;
    return 0;
}