// ABCOrderTaker.cpp: implementation of the ABCOrderTaker class. // ////////////////////////////////////////////////////////////////////// #include "ABCCommon.h" #include "ABCOrderTaker.h" ////////////////////////////////////////////////////////////////////// // Construction/Destruction ////////////////////////////////////////////////////////////////////// ABCOrderTaker::ABCOrderTaker() : m_bRegistered(false) { } ABCOrderTaker::~ABCOrderTaker() { } abc_status ABCOrderTaker::SendOrder(ABCOrder *pOrder) { abc_status sStatus; /* Register with RTR if we haven't already done so. This will make sure we are ready to start sending data. */ sStatus = Register(); if (ABCSuccess != sStatus) return false; // If we can't register with RTR then exit /* Start the Transaction */ cout << "StartTransaction..." << endl; sStatus = StartTransaction(); print_status_on_failure(sStatus); /* Send this Book Order object to a server capable of processing it. */ cout << "SendApplicationMessage..." << endl; sStatus = SendApplicationMessage(pOrder); print_status_on_failure(sStatus); /* Let RTR know that this is the only object being sent and that we are done with our work. */ cout << "AcceptTransaction..." << endl; sStatus = AcceptTransaction(); print_status_on_failure(sStatus); /* Determine if the server successfully processed the request */ return DetermineOutcome(); } rtr_status_t ABCOrderTaker::Register() { rtr_status_t sStatus = RTR_STS_OK; if(false == m_bRegistered) { /* If RTR is not already started then start it now. */ sStatus = StartRTR(); /* Create a Facility if not already created. */ sStatus = CreateFacility(); /* Register our facility with RTR. */ sStatus = RegisterFacility(ABCFacility); print_status_on_failure(sStatus); if(RTR_STS_OK == sStatus) { m_bRegistered = true; } // ABC Handlers sStatus = RegisterHandlers(&m_rtrHandlers,&m_rtrHandlers); print_status_on_failure(sStatus); } return sStatus; } abc_status ABCOrderTaker::DetermineOutcome() { RTRData *pResult = NULL; abc_status sStatus = ABCSuccess; // // Simply wait for RTR to send us an accepted or rejected. // We can dispatch everything we get and let the default // handlers process what we don't care about. // bool bDone = false; while (!bDone) { sStatus = Receive(&pResult); print_status_on_failure(sStatus); if(ABCSuccess != sStatus) break; sStatus = pResult->Dispatch(); if (ABCOrderSucceeded == sStatus) { cout << "Transaction succeeded..." << endl; bDone = true; } else if (ABCOrderFailed == sStatus) { cout << "Transaction failed..." << endl; bDone = true; } } delete pResult; return sStatus; }