Commit a040e07a by Andrew Dahl

Initial Commit - Book class mostly done - Server/Client Examples

parents
This diff is collapsed. Click to expand it.
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>BookServer</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.cdt.managedbuilder.core.genmakebuilder</name>
<triggers>clean,full,incremental,</triggers>
<arguments>
<dictionary>
<key>?name?</key>
<value></value>
</dictionary>
<dictionary>
<key>org.eclipse.cdt.make.core.append_environment</key>
<value>true</value>
</dictionary>
<dictionary>
<key>org.eclipse.cdt.make.core.autoBuildTarget</key>
<value>all</value>
</dictionary>
<dictionary>
<key>org.eclipse.cdt.make.core.buildArguments</key>
<value></value>
</dictionary>
<dictionary>
<key>org.eclipse.cdt.make.core.buildCommand</key>
<value>make</value>
</dictionary>
<dictionary>
<key>org.eclipse.cdt.make.core.buildLocation</key>
<value>${workspace_loc:/BookServer/Debug}</value>
</dictionary>
<dictionary>
<key>org.eclipse.cdt.make.core.cleanBuildTarget</key>
<value>clean</value>
</dictionary>
<dictionary>
<key>org.eclipse.cdt.make.core.contents</key>
<value>org.eclipse.cdt.make.core.activeConfigSettings</value>
</dictionary>
<dictionary>
<key>org.eclipse.cdt.make.core.enableAutoBuild</key>
<value>false</value>
</dictionary>
<dictionary>
<key>org.eclipse.cdt.make.core.enableCleanBuild</key>
<value>true</value>
</dictionary>
<dictionary>
<key>org.eclipse.cdt.make.core.enableFullBuild</key>
<value>true</value>
</dictionary>
<dictionary>
<key>org.eclipse.cdt.make.core.fullBuildTarget</key>
<value>all</value>
</dictionary>
<dictionary>
<key>org.eclipse.cdt.make.core.stopOnError</key>
<value>true</value>
</dictionary>
<dictionary>
<key>org.eclipse.cdt.make.core.useDefaultBuildCmd</key>
<value>true</value>
</dictionary>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.cdt.core.cnature</nature>
<nature>org.eclipse.cdt.core.ccnature</nature>
<nature>org.eclipse.cdt.managedbuilder.core.managedBuildNature</nature>
<nature>org.eclipse.cdt.managedbuilder.core.ScannerConfigNature</nature>
</natures>
</projectDescription>
To compile the client:
g++ -lxmlrpc++ -lxmlrpc -lxmlrpc_client++ BookClient.cpp -o client
To compile the server:
g++ -lxmlrpc++ -lxmlrpc -lxmlrpc_server_abyss++ BookServer.cpp -o server
To run client:
./client
To run server:
./server
\ No newline at end of file
/*
* Book.cpp
*
* Created on: Apr 24, 2010
* Author: Andrew Dahl
*/
#include "Book.h"
Book::Book(string Title = "", string Publisher = "", string ISBN = "",
int Year = 0, float Price = 0.0, int Stock = 0, string Auth1 = "",
string Auth2 = "", string Auth3 = "", string Auth4 = "")
{
this->title = Title;
this->publisher = Publisher;
this->isbn = ISBN;
if(Year >= 1800)
this->publication_year = Year;
else
this->publication_year = 1800;
if(Price > 0)
this->price = Price;
else
this->price = 0;
if(Stock >= 0)
this->stock = Stock;
else
this->stock = 0;
this->number_of_authors = 0;
if(Auth1 != "")
{
this->author[this->number_of_authors] = Auth1;
this->number_of_authors++;
}
if(Auth2 != "")
{
this->author[this->number_of_authors] = Auth2;
this->number_of_authors++;
}
if(Auth3 != "")
{
this->author[this->number_of_authors] = Auth3;
this->number_of_authors++;
}
if(Auth4 != "")
{
this->author[this->number_of_authors] = Auth4;
this->number_of_authors++;
}
}
void Book::setTitle(string Title)
{
if(Title != "")
this->title = Title;
}
string Book::getTitle() const
{
return this->title;
}
bool Book::isTitle(string Title) const
{
if(this->title.length() != Title.length())
return false;
for (int i = 0; i < Title.length(); i++)
{
if(toupper(this->title[i] != toupper(Title[i])))
return false;
}
return true;
}
bool Book::setStock(int Stock)
{
if(Stock >= 0)
{
this->stock = Stock;
return true;
}
return false;
}
bool Book::addStock(int Delta)
{
if((this->stock + Delta) >= 0)
{
this->stock += Delta;
return true;
}
return false;
}
int Book::getStock() const
{
return this->stock;
}
bool Book::setPublisher(string Publisher)
{
if(Publisher != "")
{
this->publisher = Publisher;
return true;
}
return false;
}
string Book::getPublisher() const
{
return this->publisher;
}
bool Book::setISBN(string ISBN)
{
if(ISBN != "")
{
this->isbn = ISBN;
return true;
}
return false;
}
bool Book::isISBN(const string ISBN) const
{
if(this->isbn == ISBN)
return true;
return false;
}
string Book::getISBN() const
{
return this->isbn;
}
bool Book::setYear(int Year)
{
if(Year >= 1800)
{
this->publication_year = Year;
return true;
}
return false;
}
int Book::getYear() const
{
return this->publication_year;
}
bool Book::setPrice(float Price)
{
if(Price >= 0)
{
this->price = Price;
return true;
}
return false;
}
float Book::getPrice() const
{
return this->price;
}
bool Book::addAuthor(string Auth)
{
if(this->number_of_authors < MAX_AUTH)
{
this->author[this->number_of_authors] = Auth;
this->number_of_authors++;
return true;
}
return false;
}
int Book::getNumberOfAuthors() const
{
return this->number_of_authors;
}
void Book::print(ofstream & outs) const
{
}
bool Book::operator >= (const bookType & rhs) const
{
//TODO: Finish This...
return false;
}
bool Book::operator == (const bookType & rhs) const
{
//TODO: Finish This...
return false;
}
bool Book::operator <= (const bookType & rhs) const
{
//TODO: Finish This...
return false;
}
bool Book::operator < (const bookType & rhs) const
{
//TODO: Finish This...
return false;
}
bool Book::operator != (const bookType & rhs) const
{
//TODO: Finish This...
return false;
}
bool Book::operator > (const bookType & rhs) const
{
//TODO: Finish This...
return false;
}
/*
* Book.h
*
* Created on: Apr 24, 2010
* Author: Andrew Dahl
*/
#ifndef BOOK_H_
#define BOOK_H_
#include <string>
#include <iostream>
#include <fstream>
#include <ctype.h>
using namespace std;
const int MAX_AUTH = 4; // size of author list
class Book {
string title, // book title
author[MAX_AUTH], // list of authors
publisher, // publisher of book
isbn; // book bar code
int number_of_authors, // number of authors in the author list
publication_year, // year of publication
stock; // number of books in stock
float price; // book price
public:
Book(string Title = "", string Publisher = "", string ISBN = "",
int Year = 0, float Price = 0.0, int Stock = 0, string Auth1 = "",
string Auth2 = "", string Auth3 = "", string Auth4 = "");
void setTitle(string Title);
string getTitle() const;
bool isTitle(string Title) const;
bool setStock(int Stock);
bool addStock(int Delta);
int getStock() const;
bool setPublisher(string Publisher);
string getPublisher() const;
bool setISBN(string ISBN);
bool isISBN(const string) const;
string getISBN() const;
bool setYear(int Year);
int getYear() const;
bool setPrice(float Price);
float getPrice() const;
bool addAuthor(string Auth);
int getNumberOfAuthors() const;
void print(ofstream & outs) const;
bool operator >= (const bookType & rhs) const;
bool operator == (const bookType & rhs) const;
bool operator <= (const bookType & rhs) const;
bool operator < (const bookType & rhs) const;
bool operator != (const bookType & rhs) const;
bool operator > (const bookType & rhs) const;
};
#endif /* BOOK_H_ */
//============================================================================
// Name : BookClient.cpp
// Author : Andrew Dahl
// Description : Client for Book Server for testing Book Server for final project in C440
//============================================================================
#include <cstdlib>
#include <string>
#include <iostream>
#include <xmlrpc-c/girerr.hpp>
#include <xmlrpc-c/base.hpp>
#include <xmlrpc-c/client_simple.hpp>
using namespace std;
int
main(int argc, char **) {
if (argc-1 > 0) {
cerr << "This program has no arguments" << endl;
exit(1);
}
try {
string const serverUrl("http://localhost:8080/RPC2");
string const methodName("sample.add");
xmlrpc_c::clientSimple myClient;
xmlrpc_c::value result;
myClient.call(serverUrl, methodName, "ii", &result, 3, 7);
int const sum = xmlrpc_c::value_int(result);
// Assume the method returned an integer; throws error if not
cout << "Result of RPC (sum of 5 and 7): " << sum << endl;
} catch (exception const& e) {
cerr << "Client threw error: " << e.what() << endl;
} catch (...) {
cerr << "Client threw unexpected error." << endl;
}
return 0;
}
//============================================================================
// Name : BookServer.cpp
// Author : Andrew Dahl
// Description : Book Server for final project in C440
//============================================================================
#include <cassert>
#include <stdexcept>
#include <iostream>
#ifdef WIN32
# include <windows.h>
#else
# include <unistd.h>
#endif
#include <xmlrpc-c/base.hpp>
#include <xmlrpc-c/registry.hpp>
#include <xmlrpc-c/server_abyss.hpp>
using namespace std;
#ifdef WIN32
#define SLEEP(seconds) SleepEx(seconds * 1000);
#else
#define SLEEP(seconds) sleep(seconds);
#endif
class sampleAddMethod : public xmlrpc_c::method {
public:
sampleAddMethod() {
// signature and help strings are documentation -- the client
// can query this information with a system.methodSignature and
// system.methodHelp RPC.
this->_signature = "i:ii";
// method's result and two arguments are integers
this->_help = "This method adds two integers together";
}
void
execute(xmlrpc_c::paramList const& paramList,
xmlrpc_c::value * const retvalP) {
int const addend(paramList.getInt(0));
int const adder(paramList.getInt(1));
paramList.verifyEnd(2);
*retvalP = xmlrpc_c::value_int(addend + adder);
// Sometimes, make it look hard (so client can see what it's like
// to do an RPC that takes a while).
if (adder == 1)
SLEEP(2);
}
};
int
main(int const,
const char ** const) {
try {
xmlrpc_c::registry myRegistry;
xmlrpc_c::methodPtr const sampleAddMethodP(new sampleAddMethod);
myRegistry.addMethod("sample.add", sampleAddMethodP);
xmlrpc_c::serverAbyss myAbyssServer(
xmlrpc_c::serverAbyss::constrOpt()
.registryP(&myRegistry)
.portNumber(8080));
myAbyssServer.run();
// xmlrpc_c::serverAbyss.run() never returns
assert(false);
} catch (exception const& e) {
cerr << "Something failed. " << e.what() << endl;
}
return 0;
}
/*#include <iostream>
using namespace std;
int main() {
cout << "!!!Hello World!!!" << endl; // prints !!!Hello World!!!
return 0;
}*/
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment