Go to the documentation of this file.00001
00010 #include "RecordConnection.h"
00011 #include "Connection.h"
00012 #include <fstream>
00013 #include <string>
00014
00015 using namespace qrk;
00016 using namespace std;
00017
00018
00019 struct RecordConnection::pImpl
00020 {
00021 string error_message_;
00022 Connection* connection_;
00023 ofstream send_fout_;
00024 ofstream receive_fout_;
00025
00026
00027 pImpl(Connection* connection,
00028 const char* send_save_file, const char* receive_save_file)
00029 : error_message_("no error."), connection_(connection)
00030 {
00031 send_fout_.open(send_save_file);
00032 receive_fout_.open(receive_save_file);
00033 }
00034 };
00035
00036
00037 RecordConnection::RecordConnection(Connection* connection,
00038 const char* send_save_file,
00039 const char* receive_save_file)
00040 : pimpl(new pImpl(connection, send_save_file, receive_save_file))
00041 {
00042 }
00043
00044
00045 RecordConnection::~RecordConnection(void)
00046 {
00047 }
00048
00049
00050 const char* RecordConnection::what(void) const
00051 {
00052 return pimpl->error_message_.c_str();
00053 }
00054
00055
00056 bool RecordConnection::connect(const char* device, long baudrate)
00057 {
00058 return pimpl->connection_->connect(device, baudrate);
00059 }
00060
00061
00062 void RecordConnection::disconnect(void)
00063 {
00064 pimpl->connection_->disconnect();
00065 }
00066
00067
00068 bool RecordConnection::setBaudrate(long baudrate)
00069 {
00070 return pimpl->connection_->setBaudrate(baudrate);
00071 }
00072
00073
00074 long RecordConnection::baudrate(void) const
00075 {
00076 return pimpl->connection_->baudrate();
00077 }
00078
00079
00080 bool RecordConnection::isConnected(void) const
00081 {
00082 return pimpl->connection_->isConnected();
00083 }
00084
00085
00086 int RecordConnection::send(const char* data, size_t count)
00087 {
00088 int n = pimpl->connection_->send(data, count);
00089 if (n > 0) {
00090 pimpl->send_fout_.write(data, n);
00091 }
00092 return n;
00093 }
00094
00095
00096 int RecordConnection::receive(char* data, size_t count, int timeout)
00097 {
00098 int n = pimpl->connection_->receive(data, count, timeout);
00099 if (n > 0) {
00100 pimpl->receive_fout_.write(data, n);
00101 }
00102 return n;
00103 }
00104
00105
00106 size_t RecordConnection::size(void) const
00107 {
00108 return pimpl->connection_->size();
00109 }
00110
00111
00112 void RecordConnection::flush(void)
00113 {
00114 pimpl->connection_->flush();
00115 }
00116
00117
00118 void RecordConnection::clear(void)
00119 {
00120 pimpl->connection_->clear();
00121 }
00122
00123
00124 void RecordConnection::ungetc(const char ch)
00125 {
00126 pimpl->connection_->ungetc(ch);
00127 }