// ABCBook.cpp: implementation of the ABCBook class. // ////////////////////////////////////////////////////////////////////// #include "ABCCommon.h" #include "ABCBook.h" ////////////////////////////////////////////////////////////////////// // Construction/Destruction ////////////////////////////////////////////////////////////////////// ABCBook::ABCBook() : m_uiISBN(0) { } ABCBook::~ABCBook() { } bool ABCBook::AddOrder( unsigned int uiPrice, unsigned int uiISBN, const char *pszName, const char *pszAuthor) { /* Copy the Book purchase to our Book object. */ m_uiISBN = uiISBN; m_uiPrice = uiPrice; strcpy(&m_szTitle[0],pszName); strcpy(&m_szAuthor[0],pszAuthor); WriteObject(); return true; } void ABCBook::WriteObject() { /* Save the type of object we are. This will be used by the class factory on the server side to determine which type of class to allocate. */ *this << ABC_BOOK; *this << m_uiPrice << m_uiISBN << m_szTitle << m_szAuthor; /* The 1 line call above is equivalent to the 4 lines below. We can use the << and >> operators because we know that the data which we store is not > the current RTR maximum = 65535 byes. WriteToStream(m_uiISBN); WriteToStream(m_uiPrice); WriteToStream(m_szTitle); WriteToStream(m_szAuthor); */ } void ABCBook::ReadObject() { /* The first data is the type of class we should be. Validate that everything is fine. */ unsigned int uiClassType = 0; *this >> uiClassType; assert(uiClassType == ABC_BOOK); /* Populate this object with the data */ *this >> m_uiPrice >> m_uiISBN >> m_szTitle >> m_szAuthor; /* The 1 line call above is equivalent to the 4 lines below. ReadFromStream(m_uiISBN); ReadFromStream(m_uiPrice); ReadFromStream(m_szTitle,GetLogicalBufferLength()); ReadFromStream(m_szAuthor,GetLogicalBufferLength()); */ } abc_status ABCBook::ProcessOrder() { // It is here that we would process the request for this book. // For this sample simply print out the Book order. cout <<"ABCBook::ProcessOrder()" << endl; cout << " " << "ISBN = " << m_uiISBN << endl; cout << " " << "Price = " << m_uiPrice << endl; cout << " " << "Title = " << m_szTitle << endl; cout << " " << "Author = " << m_szAuthor << endl; return ABCOrderSucceeded; }