1 /***************************************************************************
2 * Copyright (C) 2006 by Gerd v. Egidy *
5 * This library is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU Lesser General Public License version *
7 * 2.1 as published by the Free Software Foundation. *
9 * This library is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU Lesser General Public License for more details. *
14 * You should have received a copy of the GNU Lesser General Public *
15 * License along with this program; if not, write to the *
16 * Free Software Foundation, Inc., *
17 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
18 ***************************************************************************/
23 #include <boost/archive/binary_oarchive.hpp>
24 #include <boost/archive/binary_iarchive.hpp>
25 #include <boost/archive/xml_oarchive.hpp>
26 #include <boost/archive/xml_iarchive.hpp>
27 #include <boost/serialization/serialization.hpp>
29 #include <boost/bind.hpp>
31 #include "command_client.hxx"
42 command_client::command_client(client_connection& _c)
46 c.add_callback(new_connection,bind(&command_client::read_hello, boost::ref(*this)));
51 void command_client::read_hello()
55 while(!c.get_packet(resultpacket))
58 istringstream hello(resultpacket);
63 if (hello.fail() || hello.eof() || string("T2Nv") != chk)
64 throw t2n_version_mismatch("illegal hello received (T2N)");
67 hello >> prot_version;
68 if (hello.fail() || hello.eof() || prot_version != PROTOCOL_VERSION)
69 throw t2n_version_mismatch("not compatible with the server protocol version");
72 if (hello.fail() || hello.eof() || chk[0] != ';')
73 throw t2n_version_mismatch("illegal hello received (1. ;)");
76 if (hello.fail() || hello.eof() || *((int*)chk) != 1)
77 throw t2n_version_mismatch("host byte order not matching");
80 if (hello.fail() || hello.eof() || chk[0] != ';')
81 throw t2n_version_mismatch("illegal hello received (2. ;)");
84 void command_client::send_command(command* cmd, result_container &res)
87 command_container cc(cmd);
88 boost::archive::binary_oarchive oa(ofs);
94 if ((ostr=c.get_logstream(fulldebug))!=NULL)
96 (*ostr) << "sending command, decoded data: " << std::endl;
97 boost::archive::xml_oarchive xo(*ostr);
98 xo << BOOST_SERIALIZATION_NVP(cc);
105 while(!c.get_packet(resultpacket))
108 istringstream ifs(resultpacket);
109 boost::archive::binary_iarchive ia(ifs);
114 if ((ostr=c.get_logstream(fulldebug))!=NULL)
116 (*ostr) << "received result, decoded data: " << std::endl;
117 boost::archive::xml_oarchive xo(*ostr);
118 xo << BOOST_SERIALIZATION_NVP(res);