1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
|
// -*- Mode: C++; tab-width: 2; -*-
// vi: set ts=2:
//
// $Id: client.C,v 1.1.4.1 2007/03/25 22:00:05 oliver Exp $
//
#include <BALL/CONCEPT/client.h>
using namespace std;
namespace BALL
{
Client::InvalidClient::InvalidClient(const char* file, int line)
: Exception::GeneralException(file, line, string("InvalidClient"), string("client not valid!"))
{
}
Client::NoPersistentObject::NoPersistentObject(const char* file, int line)
: Exception::GeneralException(file, line, string("NoPersistentObject"), string("object is not a persistent object!"))
{
}
Client::Client()
: host_(),
port_(20000),
pm_()
{
}
Client::Client(const String& host, int port)
: pm_()
{
connect(host, port);
}
Client::~Client()
{
#ifdef BALL_DEBUG
cout << "Destructing object " << (void *)this
<< " of class " << RTTI::getName<Client>() << endl;
#endif
}
void Client::clear()
{
}
void Client::connect(const String& host, int port)
{
host_ = host;
port_ = port;
}
void Client::insert(Composite &composite)
{
if (!isValid())
{
throw InvalidClient(__FILE__, __LINE__);
}
if (!RTTI::isKindOf<PersistentObject>(&composite))
{
throw NoPersistentObject(__FILE__, __LINE__);
}
TCPIOStream tcp_iostream(host_.c_str(), port_);
tcp_iostream << (Size)COMMAND__SEND_OBJECT << " ";
tcp_iostream << static_cast<LongSize>(reinterpret_cast<PointerSizeUInt>(&composite)) << endl;
pm_.setOstream(tcp_iostream);
composite >> pm_;
tcp_iostream.close();
}
bool Client::isValid() const
{
return (host_ != "" && port_ != 0);
}
void Client::dump(ostream& s, Size depth) const
{
BALL_DUMP_STREAM_PREFIX(s);
BALL_DUMP_DEPTH(s, depth);
BALL_DUMP_HEADER(s, this, this);
BALL_DUMP_DEPTH(s, depth);
s << "host: " << host_ << endl;
BALL_DUMP_DEPTH(s, depth);
s << "port: " << port_ << endl;
BALL_DUMP_STREAM_SUFFIX(s);
}
} // namespace BALL
|