Go to the documentation of this file.00001
00010 #include "CustomConnection.h"
00011 #include "RingBuffer.h"
00012
00013 using namespace qrk;
00014 using namespace std;
00015
00016
00017 struct CustomConnection::pImpl
00018 {
00019 long baudrate_;
00020 RingBuffer<char> recv_buffer_;
00021 RingBuffer<char> send_buffer_;
00022
00023
00024 pImpl(void) : baudrate_(0)
00025 {
00026 }
00027 };
00028
00029
00030 CustomConnection::CustomConnection(void) : pimpl(new pImpl)
00031 {
00032 }
00033
00034
00035 CustomConnection::~CustomConnection(void)
00036 {
00037 }
00038
00039
00040 const char* CustomConnection::what(void) const
00041 {
00042 return "Not implemented.";
00043 }
00044
00045
00046 bool CustomConnection::connect(const char* device, long baudrate)
00047 {
00048 static_cast<void>(device);
00049 static_cast<void>(baudrate);
00050
00051
00052 return true;
00053 }
00054
00055
00056 void CustomConnection::disconnect(void)
00057 {
00058
00059 }
00060
00061
00062 bool CustomConnection::setBaudrate(long baudrate)
00063 {
00064 pimpl->baudrate_ = baudrate;
00065 return true;
00066 }
00067
00068
00069 long CustomConnection::baudrate(void) const
00070 {
00071 return pimpl->baudrate_;
00072 }
00073
00074
00075 bool CustomConnection::isConnected(void) const
00076 {
00077
00078 return false;
00079 }
00080
00081
00082 int CustomConnection::send(const char* data, size_t count)
00083 {
00084 static_cast<void>(data);
00085 static_cast<void>(count);
00086
00087
00088 return count;
00089 }
00090
00091
00092 int CustomConnection::receive(char* data, size_t count, int timeout)
00093 {
00094 static_cast<void>(timeout);
00095
00096 int n = std::min(pimpl->recv_buffer_.size(), count);
00097 pimpl->recv_buffer_.get(data, n);
00098 return n;
00099 }
00100
00101
00102 size_t CustomConnection::size(void) const
00103 {
00104 return pimpl->recv_buffer_.size();
00105 }
00106
00107
00108 void CustomConnection::flush(void)
00109 {
00110
00111 }
00112
00113
00114 void CustomConnection::clear(void)
00115 {
00116
00117 pimpl->recv_buffer_.clear();
00118 pimpl->send_buffer_.clear();
00119 }
00120
00121
00122 void CustomConnection::ungetc(const char ch)
00123 {
00124 pimpl->recv_buffer_.ungetc(ch);
00125 }
00126
00127
00128 void CustomConnection::setReadData(const char* data, size_t count)
00129 {
00130 pimpl->recv_buffer_.put(data, count);
00131 }
00132
00133
00134 void CustomConnection::setReadData(std::string data)
00135 {
00136 pimpl->recv_buffer_.put(data.c_str(), data.size());
00137 }
00138
00139
00140 void CustomConnection::readSendData(char* data, size_t count)
00141 {
00142 pimpl->send_buffer_.put(data, count);
00143 }