/// get pointer to logging stream, returns NULL if no logging needed
std::ostream* client_connection::get_logstream(log_level_values level)
{
- if (logstream && level >= log_level)
+ if (logstream && log_level >= level)
return logstream;
+ else
+ return NULL;
}
/// activate logging to the given stream. everything above the given level is logged.
#include <boost/archive/xml_oarchive.hpp>
#include <boost/archive/xml_iarchive.hpp>
#include <boost/serialization/serialization.hpp>
-#include <boost/serialization/export.hpp>
#include "command_client.hxx"
// TODO: exceptions
oa << cc;
+ std::ostream* ostr;
+ if ((ostr=c.get_logstream(fulldebug))!=NULL)
+ {
+ (*ostr) << "sending command, decoded data: " << std::endl;
+ boost::archive::xml_oarchive xo(*ostr);
+ xo << BOOST_SERIALIZATION_NVP(cc);
+ }
+
c.write(ofs.str());
// TODO: fix timeout
// TODO: exceptions
ia >> res;
+
+ if ((ostr=c.get_logstream(fulldebug))!=NULL)
+ {
+ (*ostr) << "received result, decoded data: " << std::endl;
+ boost::archive::xml_oarchive xo(*ostr);
+ xo << BOOST_SERIALIZATION_NVP(res);
+ }
}
}
// TODO: catch
ia >> ccont;
+ std::ostream* ostr;
+ if ((ostr=s.get_logstream(fulldebug))!=NULL)
+ {
+ (*ostr) << "decoded packet data: " << std::endl;
+ boost::archive::xml_oarchive xo(*ostr);
+ xo << BOOST_SERIALIZATION_NVP(ccont);
+ }
+
// TODO: cast to command subclass (template)
command *cmd=ccont.get_command();
// TODO: catch
oa << res;
+ if ((ostr=s.get_logstream(fulldebug))!=NULL)
+ {
+ (*ostr) << "returning result, decoded data: " << std::endl;
+ boost::archive::xml_oarchive xo(*ostr);
+ xo << BOOST_SERIALIZATION_NVP(res);
+ }
+
conn->write(ofs.str());
}
std::ostream* server_connection::get_logstream(log_level_values level)
{
if (my_server != NULL)
- return my_server->get_logstream(level);
+ {
+ std::ostream* ostr=my_server->get_logstream(level);
+ if (ostr != NULL)
+ (*ostr) << "connection " << get_id() << ": ";
+ return ostr;
+ }
+ else
+ return NULL;
}
/// check if timeout is expired, close connection if so
/// get pointer to logging stream, returns NULL if no logging needed
std::ostream* server::get_logstream(log_level_values level)
{
- if (logstream && level >= log_level)
+ if (logstream && log_level >= level)
return logstream;
+ else
+ return NULL;
}
};
if (nbytes > 0)
{
buffer.assign(socket_buffer,nbytes);
- LOGSTREAM(debug,nbytes << " read");
+ LOGSTREAM(debug,nbytes << " bytes read");
}
// more data waiting -> recurse
{
/// possible levels for logging
-enum log_level_values { none=0, error=1, debug=2 };
+enum log_level_values { none=0, error=1, debug=2, fulldebug=3 };
/// possible types of a socket (tcp and unix)
enum socket_type_value { tcp_s, unix_s };
#include <cppunit/ui/text/TestRunner.h>
#include <cppunit/extensions/HelperMacros.h>
-
#include <boost/archive/binary_oarchive.hpp>
#include <boost/archive/binary_iarchive.hpp>
+#include <boost/archive/xml_oarchive.hpp>
+#include <boost/archive/xml_iarchive.hpp>
#include <boost/serialization/serialization.hpp>
#include <container.hxx>
#include <command_server.hxx>
using namespace std;
-using namespace libt2n;
using namespace CppUnit;
string testfunc(const string& str)
return ret;
}
-class testfunc_res : public result
+class testfunc_res : public libt2n::result
{
private:
string res;
template<class Archive>
void serialize(Archive & ar, const unsigned int version)
{
- ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(result);
+ ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(libt2n::result);
ar & BOOST_SERIALIZATION_NVP(res);
}
param=str;
}
- result* operator()()
+ libt2n::result* operator()()
{
return new testfunc_res(testfunc(param));
}
BOOST_CLASS_EXPORT(testfunc_cmd)
BOOST_CLASS_EXPORT(testfunc_res)
+using namespace libt2n;
+
class test_simplecmd : public TestFixture
{
CPPUNIT_TEST_SUITE(test_simplecmd);