git-svn-id: svn://db.shs.com.ru/pip@244 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5
This commit is contained in:
@@ -706,7 +706,7 @@ void PIConfig::parse() {
|
||||
if (!isOpened()) return;
|
||||
_seekToBeginDev();
|
||||
other.clear();
|
||||
lines = centry = 0;
|
||||
lines = 0;
|
||||
while (!_isEndDev()) {
|
||||
other.push_back(PIString());
|
||||
src = str = parseLine(_readLineDev());
|
||||
|
||||
@@ -487,7 +487,6 @@ private:
|
||||
PIString parseLine(PIString v);
|
||||
void parse();
|
||||
|
||||
int centry;
|
||||
bool own_dev, internal;
|
||||
PIVector<PIConfig * > includes, inc_devs;
|
||||
Branch all_includes;
|
||||
|
||||
@@ -790,6 +790,12 @@ void PIConnection::stopAllSenders() {
|
||||
}
|
||||
|
||||
|
||||
void PIConnection::destroy() {
|
||||
stop();
|
||||
removeAllDevices();
|
||||
}
|
||||
|
||||
|
||||
PIDiagnostics * PIConnection::diagnostic(const PIString & full_path_name) const {
|
||||
PIIODevice * dev = deviceByFullPath(full_path_name);
|
||||
if (dev == 0) dev = device_names.value(full_path_name, 0);
|
||||
@@ -1010,6 +1016,7 @@ PIConnection::DevicePool::DeviceData::~DeviceData() {
|
||||
rthread = 0;
|
||||
}
|
||||
if (dev != 0) {
|
||||
dev->close();
|
||||
delete dev;
|
||||
dev = 0;
|
||||
}
|
||||
|
||||
@@ -240,6 +240,7 @@ public:
|
||||
//! Stop all read threads and senders
|
||||
void stop() {stopAllThreadedReads(); stopAllSenders();}
|
||||
|
||||
void destroy();
|
||||
|
||||
//! Returns if there are no devices in this connection
|
||||
bool isEmpty() const {return device_modes.isEmpty();}
|
||||
|
||||
@@ -134,9 +134,9 @@ PIEthernet::PIEthernet(int sock_, PIString ip_port): PIIODevice("", ReadWrite) {
|
||||
|
||||
PIEthernet::~PIEthernet() {
|
||||
//piCoutObj << "~PIEthernet ...";
|
||||
piMonitor.ethernets--;
|
||||
stop();
|
||||
closeDevice();
|
||||
piMonitor.ethernets--;
|
||||
//piCoutObj << "~PIEthernet done";
|
||||
}
|
||||
|
||||
|
||||
@@ -399,10 +399,10 @@ protected:
|
||||
void applyOptInt(int level, int opt, int val);
|
||||
|
||||
PRIVATE_DECLARATION
|
||||
int sock, sock_s, wrote;
|
||||
mutable int port_, port_s, port_c, port_r;
|
||||
int sock, sock_s;
|
||||
mutable int port_, port_s, port_r;
|
||||
bool connected_, connecting_, listen_threaded, server_bounded;
|
||||
mutable PIString ip_, ip_s, ip_c, ip_r;
|
||||
mutable PIString ip_, ip_s, ip_r;
|
||||
PIThread server_thread_;
|
||||
PIMutex clients_mutex;
|
||||
PIVector<PIEthernet * > clients_;
|
||||
|
||||
@@ -88,7 +88,7 @@ public:
|
||||
|
||||
PIFile(const PIFile & other);
|
||||
|
||||
~PIFile() {close();}
|
||||
~PIFile() {closeDevice();}
|
||||
|
||||
//PIFile & operator =(const PIFile & f) {path_ = f.path_; type_ = f.type_; return *this;}
|
||||
|
||||
|
||||
@@ -49,15 +49,15 @@ bool PIFileTransfer::send(PIVector<PIFile::FileInfo> entries) {
|
||||
allEntries.back().dest_path = entries[i].name();
|
||||
if (entries[i].isDir()) {
|
||||
cur_file_string = "scanning ... ";
|
||||
d.setDir(entries[i].path);
|
||||
scan_dir.setDir(entries[i].path);
|
||||
scanning = true;
|
||||
PIVector<PIFile::FileInfo> fls = d.allEntries();
|
||||
PIVector<PIFile::FileInfo> fls = scan_dir.allEntries();
|
||||
scanning = false;
|
||||
d.up();
|
||||
scan_dir.up();
|
||||
//piCout << "files rel to" << d.absolutePath();
|
||||
for (int j = 0; j < fls.size(); j++) {
|
||||
allEntries << PFTFileInfo(fls[j]);
|
||||
allEntries.back().dest_path = d.relative(fls[j].path);
|
||||
allEntries.back().dest_path = scan_dir.relative(fls[j].path);
|
||||
//piCout << " abs path" << fls[j].path;
|
||||
//piCout << " rel path" << allEntries.back().dest_path;
|
||||
}
|
||||
@@ -249,7 +249,7 @@ void PIFileTransfer::receivePart(PIBaseTransfer::Part fi, PIByteArray ba, PIByte
|
||||
|
||||
PIString PIFileTransfer::curFile() const {
|
||||
if (scanning)
|
||||
return cur_file_string + d.scanDir();
|
||||
return cur_file_string + scan_dir.scanDir();
|
||||
return cur_file_string;
|
||||
}
|
||||
|
||||
|
||||
@@ -93,7 +93,7 @@ private:
|
||||
PIDir dir;
|
||||
PIFile work_file;
|
||||
PIByteArray desc;
|
||||
PIDir d;
|
||||
PIDir scan_dir;
|
||||
bool started_, scanning;
|
||||
|
||||
bool sendFiles(const PIVector<PFTFileInfo> &files);
|
||||
|
||||
@@ -40,10 +40,6 @@ PIIOString::PIIOString(const PIString & string) {
|
||||
}
|
||||
|
||||
|
||||
PIIOString::~PIIOString() {
|
||||
}
|
||||
|
||||
|
||||
bool PIIOString::open(PIString * string, PIIODevice::DeviceMode mode_) {
|
||||
str = string;
|
||||
return PIIODevice::open(mode_);
|
||||
|
||||
@@ -37,8 +37,7 @@ public:
|
||||
//! Contructs %PIIOString with \"string\" content only for read
|
||||
PIIOString(const PIString & string);
|
||||
|
||||
~PIIOString();
|
||||
|
||||
~PIIOString() {closeDevice();}
|
||||
|
||||
//! Returns content
|
||||
PIString * string() const {return str;}
|
||||
|
||||
@@ -99,7 +99,7 @@ void PIPacketExtractor::construct() {
|
||||
setDevice(0);
|
||||
setPacketSize(0);
|
||||
setSplitMode(None);
|
||||
allReaded = addSize = curInd = missed = missed_packets = footerInd = 0;
|
||||
missed = missed_packets = footerInd = 0;
|
||||
header_found = false;
|
||||
}
|
||||
|
||||
|
||||
@@ -119,11 +119,6 @@ public:
|
||||
// //! Returns pointer to \a missedPackets() count. Useful for output to PIConsole
|
||||
const ullong * missedPackets_ptr() const {return &missed_packets;}
|
||||
|
||||
|
||||
// //! Returns last successfully validated header as byte array
|
||||
PIByteArray lastHeader() {return mheader;}
|
||||
|
||||
|
||||
//! Directly call \a read() function of child %device
|
||||
int read(void * read_to, int max_size) {if (dev == 0) return -1; return dev->read(read_to, max_size);}
|
||||
|
||||
@@ -172,11 +167,11 @@ private:
|
||||
bool openDevice() {if (dev == 0) return false; return dev->open();}
|
||||
|
||||
PIIODevice * dev;
|
||||
PIByteArray mheader, buffer, sbuffer, tmpbuf, src_header, src_footer, trbuf;
|
||||
PIByteArray buffer, sbuffer, tmpbuf, src_header, src_footer, trbuf;
|
||||
PacketExtractorCheckFunc ret_func_header, ret_func_footer;
|
||||
SplitMode mode_;
|
||||
void * data;
|
||||
int buffer_size, dataSize, packetSize_hf, allReaded, addSize, curInd, footerInd, packetSize_;
|
||||
int buffer_size, dataSize, packetSize_hf, footerInd, packetSize_;
|
||||
double time_;
|
||||
bool header_found;
|
||||
ullong missed, missed_packets;
|
||||
|
||||
@@ -143,13 +143,13 @@ PIPeer::PIPeer(const PIString & n): PIIODevice() {
|
||||
//joinMulticastGroup("239.240.241.242");
|
||||
srand(uint(PISystemTime::current(true).toMicroseconds()));
|
||||
//id_ = self_info.name + "_" + PIString::fromNumber(rand());
|
||||
CONNECTU(&timer, tickEvent, this, timerEvent);
|
||||
CONNECTU(&sync_timer, tickEvent, this, timerEvent);
|
||||
prev_ifaces = PIEthernet::interfaces();
|
||||
no_timer = false;
|
||||
// initNetwork();
|
||||
sendSelfInfo();
|
||||
timer.addDelimiter(5);
|
||||
timer.start(1000);
|
||||
sync_timer.addDelimiter(5);
|
||||
sync_timer.start(1000);
|
||||
}
|
||||
|
||||
|
||||
@@ -162,7 +162,7 @@ PIPeer::~PIPeer() {
|
||||
p._data->dt_out.stop();
|
||||
p._data->t.stop(true);
|
||||
}
|
||||
timer.stop();
|
||||
sync_timer.stop();
|
||||
diag_s.stop();
|
||||
diag_d.stop();
|
||||
destroyEths();
|
||||
|
||||
@@ -92,7 +92,6 @@ public:
|
||||
void init();
|
||||
void destroy();
|
||||
|
||||
PIString nearest_address;
|
||||
int sync, cnt, trace;
|
||||
bool was_update;
|
||||
PISystemTime time;
|
||||
@@ -200,7 +199,7 @@ private:
|
||||
PIVector<PIEthernet * > eths_traffic, eths_mcast, eths_bcast;
|
||||
PIEthernet::InterfaceList prev_ifaces;
|
||||
PIEthernet eth_send, eth_lo;
|
||||
PITimer timer;
|
||||
PITimer sync_timer;
|
||||
PeerInfo self_info;
|
||||
PIVector<PeerInfo> peers;
|
||||
PIMap<PIString, PeerInfo * > peers_map;
|
||||
@@ -208,7 +207,6 @@ private:
|
||||
PIMap<PIString, PIPair<int, PISystemTime> > removed;
|
||||
PIDiagnostics diag_s, diag_d;
|
||||
bool destroyed, no_timer;
|
||||
PIString id_;
|
||||
PIString trust_peer;
|
||||
PIMutex read_buffer_mutex;
|
||||
PIQueue<PIByteArray> read_buffer;
|
||||
|
||||
@@ -176,7 +176,7 @@ public:
|
||||
void * sendData() {return sendDataPtr;}
|
||||
|
||||
PIPacketExtractor * packetExtractor() {return packet_ext;}
|
||||
PIByteArray lastHeader() {return packet_ext->lastHeader();}
|
||||
// PIByteArray lastHeader() {return packet_ext->lastHeader();}
|
||||
|
||||
EVENT0(receiverStarted)
|
||||
EVENT0(receiverStopped)
|
||||
|
||||
@@ -153,6 +153,7 @@ PISerial::PISerial(const PIString & device_, PISerial::Speed speed_, PIFlags<PIS
|
||||
|
||||
|
||||
PISerial::~PISerial() {
|
||||
closeDevice();
|
||||
piMonitor.serials--;
|
||||
}
|
||||
|
||||
@@ -523,8 +524,8 @@ void PISerial::applySettings() {
|
||||
times.ReadIntervalTimeout = block_read ? vtime : MAXDWORD;
|
||||
times.ReadTotalTimeoutConstant = block_read ? 0 : 1;
|
||||
times.ReadTotalTimeoutMultiplier = block_read ? 0 : MAXDWORD;
|
||||
times.WriteTotalTimeoutConstant = 0;
|
||||
times.WriteTotalTimeoutMultiplier = block_write ? 0 : 1;
|
||||
times.WriteTotalTimeoutConstant = 10;
|
||||
times.WriteTotalTimeoutMultiplier = 1;// block_write ? 0 : 1;
|
||||
if (SetCommTimeouts(PRIVATE->hCom, ×) == -1)
|
||||
piCoutObj << "Unable to set timeouts for \"" << path() << "\"";
|
||||
GetCommMask(PRIVATE->hCom, &PRIVATE->mask);
|
||||
@@ -591,8 +592,8 @@ void PISerial::setReadIsBlocking(bool yes) {
|
||||
times.ReadIntervalTimeout = block_read ? vtime : MAXDWORD;
|
||||
times.ReadTotalTimeoutConstant = block_read ? 0 : 1;
|
||||
times.ReadTotalTimeoutMultiplier = block_read ? 0 : MAXDWORD;
|
||||
times.WriteTotalTimeoutConstant = 0;
|
||||
times.WriteTotalTimeoutMultiplier = block_write ? 0 : 1;
|
||||
times.WriteTotalTimeoutConstant = 10;
|
||||
times.WriteTotalTimeoutMultiplier = 1;//block_write ? 0 : 1;
|
||||
if (isOpened()) SetCommTimeouts(PRIVATE->hCom, ×);
|
||||
#else
|
||||
if (isOpened()) fcntl(fd, F_SETFL, yes ? 0 : O_NONBLOCK);
|
||||
@@ -619,7 +620,7 @@ int PISerial::read(void * read_to, int max_size) {
|
||||
|
||||
|
||||
int PISerial::write(const void * data, int max_size, bool wait) {
|
||||
// piCoutObj << "send " << max_size;// << ": " << PIString((char*)data, max_size);
|
||||
piCoutObj << "send " << max_size;// << ": " << PIString((char*)data, max_size);
|
||||
if (fd == -1 || !canWrite()) {
|
||||
//piCoutObj << "Can`t write to uninitialized COM";
|
||||
return -1;
|
||||
@@ -636,9 +637,9 @@ int PISerial::write(const void * data, int max_size, bool wait) {
|
||||
wrote = ::write(fd, data, max_size);
|
||||
if (wait) tcdrain(fd);
|
||||
#endif
|
||||
piCoutObj << "Wrote " << wrote << " bytes in " << path();
|
||||
return (int)wrote;
|
||||
//piCoutObj << "Error while sending";
|
||||
//piCoutObj << "Wrote " << wrote << " bytes in " << path_;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@ PIUSB::PIUSB(ushort vid, ushort pid): PIIODevice("", ReadWrite) {
|
||||
pid_ = pid;
|
||||
intefrace_ = 0;
|
||||
hdev = 0;
|
||||
timeout_r = timeout_w = 0;
|
||||
interface_claimed = -1;
|
||||
setPath(PIString::fromNumber(vid_, 16).expandLeftTo(4, "0") + ":" + PIString::fromNumber(pid_, 16).expandLeftTo(4, "0"));
|
||||
setDeviceNumber(1);
|
||||
|
||||
@@ -32,6 +32,7 @@ class PIP_EXPORT PIUSB: public PIIODevice
|
||||
PIIODEVICE(PIUSB)
|
||||
public:
|
||||
PIUSB(ushort vid = 0, ushort pid = 0);
|
||||
~PIUSB() {closeDevice();}
|
||||
|
||||
struct Endpoint {
|
||||
Endpoint(uchar a = 0, uchar at = 0, ushort mps = 0) {address = a; attributes = at; max_packet_size = mps; parse();}
|
||||
|
||||
Reference in New Issue
Block a user