git-svn-id: svn://db.shs.com.ru/pip@244 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5

This commit is contained in:
2016-08-31 09:36:22 +00:00
parent 414f328a8c
commit ca21d1b8f0
19 changed files with 39 additions and 41 deletions

View File

@@ -706,7 +706,7 @@ void PIConfig::parse() {
if (!isOpened()) return; if (!isOpened()) return;
_seekToBeginDev(); _seekToBeginDev();
other.clear(); other.clear();
lines = centry = 0; lines = 0;
while (!_isEndDev()) { while (!_isEndDev()) {
other.push_back(PIString()); other.push_back(PIString());
src = str = parseLine(_readLineDev()); src = str = parseLine(_readLineDev());

View File

@@ -487,7 +487,6 @@ private:
PIString parseLine(PIString v); PIString parseLine(PIString v);
void parse(); void parse();
int centry;
bool own_dev, internal; bool own_dev, internal;
PIVector<PIConfig * > includes, inc_devs; PIVector<PIConfig * > includes, inc_devs;
Branch all_includes; Branch all_includes;

View File

@@ -790,6 +790,12 @@ void PIConnection::stopAllSenders() {
} }
void PIConnection::destroy() {
stop();
removeAllDevices();
}
PIDiagnostics * PIConnection::diagnostic(const PIString & full_path_name) const { PIDiagnostics * PIConnection::diagnostic(const PIString & full_path_name) const {
PIIODevice * dev = deviceByFullPath(full_path_name); PIIODevice * dev = deviceByFullPath(full_path_name);
if (dev == 0) dev = device_names.value(full_path_name, 0); if (dev == 0) dev = device_names.value(full_path_name, 0);
@@ -1010,6 +1016,7 @@ PIConnection::DevicePool::DeviceData::~DeviceData() {
rthread = 0; rthread = 0;
} }
if (dev != 0) { if (dev != 0) {
dev->close();
delete dev; delete dev;
dev = 0; dev = 0;
} }

View File

@@ -240,6 +240,7 @@ public:
//! Stop all read threads and senders //! Stop all read threads and senders
void stop() {stopAllThreadedReads(); stopAllSenders();} void stop() {stopAllThreadedReads(); stopAllSenders();}
void destroy();
//! Returns if there are no devices in this connection //! Returns if there are no devices in this connection
bool isEmpty() const {return device_modes.isEmpty();} bool isEmpty() const {return device_modes.isEmpty();}

View File

@@ -134,9 +134,9 @@ PIEthernet::PIEthernet(int sock_, PIString ip_port): PIIODevice("", ReadWrite) {
PIEthernet::~PIEthernet() { PIEthernet::~PIEthernet() {
//piCoutObj << "~PIEthernet ..."; //piCoutObj << "~PIEthernet ...";
piMonitor.ethernets--;
stop(); stop();
closeDevice(); closeDevice();
piMonitor.ethernets--;
//piCoutObj << "~PIEthernet done"; //piCoutObj << "~PIEthernet done";
} }

View File

@@ -399,10 +399,10 @@ protected:
void applyOptInt(int level, int opt, int val); void applyOptInt(int level, int opt, int val);
PRIVATE_DECLARATION PRIVATE_DECLARATION
int sock, sock_s, wrote; int sock, sock_s;
mutable int port_, port_s, port_c, port_r; mutable int port_, port_s, port_r;
bool connected_, connecting_, listen_threaded, server_bounded; 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_; PIThread server_thread_;
PIMutex clients_mutex; PIMutex clients_mutex;
PIVector<PIEthernet * > clients_; PIVector<PIEthernet * > clients_;

View File

@@ -88,7 +88,7 @@ public:
PIFile(const PIFile & other); PIFile(const PIFile & other);
~PIFile() {close();} ~PIFile() {closeDevice();}
//PIFile & operator =(const PIFile & f) {path_ = f.path_; type_ = f.type_; return *this;} //PIFile & operator =(const PIFile & f) {path_ = f.path_; type_ = f.type_; return *this;}

View File

@@ -49,15 +49,15 @@ bool PIFileTransfer::send(PIVector<PIFile::FileInfo> entries) {
allEntries.back().dest_path = entries[i].name(); allEntries.back().dest_path = entries[i].name();
if (entries[i].isDir()) { if (entries[i].isDir()) {
cur_file_string = "scanning ... "; cur_file_string = "scanning ... ";
d.setDir(entries[i].path); scan_dir.setDir(entries[i].path);
scanning = true; scanning = true;
PIVector<PIFile::FileInfo> fls = d.allEntries(); PIVector<PIFile::FileInfo> fls = scan_dir.allEntries();
scanning = false; scanning = false;
d.up(); scan_dir.up();
//piCout << "files rel to" << d.absolutePath(); //piCout << "files rel to" << d.absolutePath();
for (int j = 0; j < fls.size(); j++) { for (int j = 0; j < fls.size(); j++) {
allEntries << PFTFileInfo(fls[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 << " abs path" << fls[j].path;
//piCout << " rel path" << allEntries.back().dest_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 { PIString PIFileTransfer::curFile() const {
if (scanning) if (scanning)
return cur_file_string + d.scanDir(); return cur_file_string + scan_dir.scanDir();
return cur_file_string; return cur_file_string;
} }

View File

@@ -93,7 +93,7 @@ private:
PIDir dir; PIDir dir;
PIFile work_file; PIFile work_file;
PIByteArray desc; PIByteArray desc;
PIDir d; PIDir scan_dir;
bool started_, scanning; bool started_, scanning;
bool sendFiles(const PIVector<PFTFileInfo> &files); bool sendFiles(const PIVector<PFTFileInfo> &files);

View File

@@ -40,10 +40,6 @@ PIIOString::PIIOString(const PIString & string) {
} }
PIIOString::~PIIOString() {
}
bool PIIOString::open(PIString * string, PIIODevice::DeviceMode mode_) { bool PIIOString::open(PIString * string, PIIODevice::DeviceMode mode_) {
str = string; str = string;
return PIIODevice::open(mode_); return PIIODevice::open(mode_);

View File

@@ -37,8 +37,7 @@ public:
//! Contructs %PIIOString with \"string\" content only for read //! Contructs %PIIOString with \"string\" content only for read
PIIOString(const PIString & string); PIIOString(const PIString & string);
~PIIOString(); ~PIIOString() {closeDevice();}
//! Returns content //! Returns content
PIString * string() const {return str;} PIString * string() const {return str;}

View File

@@ -99,7 +99,7 @@ void PIPacketExtractor::construct() {
setDevice(0); setDevice(0);
setPacketSize(0); setPacketSize(0);
setSplitMode(None); setSplitMode(None);
allReaded = addSize = curInd = missed = missed_packets = footerInd = 0; missed = missed_packets = footerInd = 0;
header_found = false; header_found = false;
} }

View File

@@ -118,11 +118,6 @@ public:
// //! Returns pointer to \a missedPackets() count. Useful for output to PIConsole // //! Returns pointer to \a missedPackets() count. Useful for output to PIConsole
const ullong * missedPackets_ptr() const {return &missed_packets;} 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 //! 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);} 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();} bool openDevice() {if (dev == 0) return false; return dev->open();}
PIIODevice * dev; 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; PacketExtractorCheckFunc ret_func_header, ret_func_footer;
SplitMode mode_; SplitMode mode_;
void * data; void * data;
int buffer_size, dataSize, packetSize_hf, allReaded, addSize, curInd, footerInd, packetSize_; int buffer_size, dataSize, packetSize_hf, footerInd, packetSize_;
double time_; double time_;
bool header_found; bool header_found;
ullong missed, missed_packets; ullong missed, missed_packets;

View File

@@ -143,13 +143,13 @@ PIPeer::PIPeer(const PIString & n): PIIODevice() {
//joinMulticastGroup("239.240.241.242"); //joinMulticastGroup("239.240.241.242");
srand(uint(PISystemTime::current(true).toMicroseconds())); srand(uint(PISystemTime::current(true).toMicroseconds()));
//id_ = self_info.name + "_" + PIString::fromNumber(rand()); //id_ = self_info.name + "_" + PIString::fromNumber(rand());
CONNECTU(&timer, tickEvent, this, timerEvent); CONNECTU(&sync_timer, tickEvent, this, timerEvent);
prev_ifaces = PIEthernet::interfaces(); prev_ifaces = PIEthernet::interfaces();
no_timer = false; no_timer = false;
// initNetwork(); // initNetwork();
sendSelfInfo(); sendSelfInfo();
timer.addDelimiter(5); sync_timer.addDelimiter(5);
timer.start(1000); sync_timer.start(1000);
} }
@@ -162,7 +162,7 @@ PIPeer::~PIPeer() {
p._data->dt_out.stop(); p._data->dt_out.stop();
p._data->t.stop(true); p._data->t.stop(true);
} }
timer.stop(); sync_timer.stop();
diag_s.stop(); diag_s.stop();
diag_d.stop(); diag_d.stop();
destroyEths(); destroyEths();

View File

@@ -92,7 +92,6 @@ public:
void init(); void init();
void destroy(); void destroy();
PIString nearest_address;
int sync, cnt, trace; int sync, cnt, trace;
bool was_update; bool was_update;
PISystemTime time; PISystemTime time;
@@ -200,7 +199,7 @@ private:
PIVector<PIEthernet * > eths_traffic, eths_mcast, eths_bcast; PIVector<PIEthernet * > eths_traffic, eths_mcast, eths_bcast;
PIEthernet::InterfaceList prev_ifaces; PIEthernet::InterfaceList prev_ifaces;
PIEthernet eth_send, eth_lo; PIEthernet eth_send, eth_lo;
PITimer timer; PITimer sync_timer;
PeerInfo self_info; PeerInfo self_info;
PIVector<PeerInfo> peers; PIVector<PeerInfo> peers;
PIMap<PIString, PeerInfo * > peers_map; PIMap<PIString, PeerInfo * > peers_map;
@@ -208,7 +207,6 @@ private:
PIMap<PIString, PIPair<int, PISystemTime> > removed; PIMap<PIString, PIPair<int, PISystemTime> > removed;
PIDiagnostics diag_s, diag_d; PIDiagnostics diag_s, diag_d;
bool destroyed, no_timer; bool destroyed, no_timer;
PIString id_;
PIString trust_peer; PIString trust_peer;
PIMutex read_buffer_mutex; PIMutex read_buffer_mutex;
PIQueue<PIByteArray> read_buffer; PIQueue<PIByteArray> read_buffer;

View File

@@ -176,7 +176,7 @@ public:
void * sendData() {return sendDataPtr;} void * sendData() {return sendDataPtr;}
PIPacketExtractor * packetExtractor() {return packet_ext;} PIPacketExtractor * packetExtractor() {return packet_ext;}
PIByteArray lastHeader() {return packet_ext->lastHeader();} // PIByteArray lastHeader() {return packet_ext->lastHeader();}
EVENT0(receiverStarted) EVENT0(receiverStarted)
EVENT0(receiverStopped) EVENT0(receiverStopped)

View File

@@ -153,6 +153,7 @@ PISerial::PISerial(const PIString & device_, PISerial::Speed speed_, PIFlags<PIS
PISerial::~PISerial() { PISerial::~PISerial() {
closeDevice();
piMonitor.serials--; piMonitor.serials--;
} }
@@ -523,8 +524,8 @@ void PISerial::applySettings() {
times.ReadIntervalTimeout = block_read ? vtime : MAXDWORD; times.ReadIntervalTimeout = block_read ? vtime : MAXDWORD;
times.ReadTotalTimeoutConstant = block_read ? 0 : 1; times.ReadTotalTimeoutConstant = block_read ? 0 : 1;
times.ReadTotalTimeoutMultiplier = block_read ? 0 : MAXDWORD; times.ReadTotalTimeoutMultiplier = block_read ? 0 : MAXDWORD;
times.WriteTotalTimeoutConstant = 0; times.WriteTotalTimeoutConstant = 10;
times.WriteTotalTimeoutMultiplier = block_write ? 0 : 1; times.WriteTotalTimeoutMultiplier = 1;// block_write ? 0 : 1;
if (SetCommTimeouts(PRIVATE->hCom, &times) == -1) if (SetCommTimeouts(PRIVATE->hCom, &times) == -1)
piCoutObj << "Unable to set timeouts for \"" << path() << "\""; piCoutObj << "Unable to set timeouts for \"" << path() << "\"";
GetCommMask(PRIVATE->hCom, &PRIVATE->mask); GetCommMask(PRIVATE->hCom, &PRIVATE->mask);
@@ -591,8 +592,8 @@ void PISerial::setReadIsBlocking(bool yes) {
times.ReadIntervalTimeout = block_read ? vtime : MAXDWORD; times.ReadIntervalTimeout = block_read ? vtime : MAXDWORD;
times.ReadTotalTimeoutConstant = block_read ? 0 : 1; times.ReadTotalTimeoutConstant = block_read ? 0 : 1;
times.ReadTotalTimeoutMultiplier = block_read ? 0 : MAXDWORD; times.ReadTotalTimeoutMultiplier = block_read ? 0 : MAXDWORD;
times.WriteTotalTimeoutConstant = 0; times.WriteTotalTimeoutConstant = 10;
times.WriteTotalTimeoutMultiplier = block_write ? 0 : 1; times.WriteTotalTimeoutMultiplier = 1;//block_write ? 0 : 1;
if (isOpened()) SetCommTimeouts(PRIVATE->hCom, &times); if (isOpened()) SetCommTimeouts(PRIVATE->hCom, &times);
#else #else
if (isOpened()) fcntl(fd, F_SETFL, yes ? 0 : O_NONBLOCK); 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) { 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()) { if (fd == -1 || !canWrite()) {
//piCoutObj << "Can`t write to uninitialized COM"; //piCoutObj << "Can`t write to uninitialized COM";
return -1; return -1;
@@ -636,9 +637,9 @@ int PISerial::write(const void * data, int max_size, bool wait) {
wrote = ::write(fd, data, max_size); wrote = ::write(fd, data, max_size);
if (wait) tcdrain(fd); if (wait) tcdrain(fd);
#endif #endif
piCoutObj << "Wrote " << wrote << " bytes in " << path();
return (int)wrote; return (int)wrote;
//piCoutObj << "Error while sending"; //piCoutObj << "Error while sending";
//piCoutObj << "Wrote " << wrote << " bytes in " << path_;
} }

View File

@@ -17,6 +17,7 @@ PIUSB::PIUSB(ushort vid, ushort pid): PIIODevice("", ReadWrite) {
pid_ = pid; pid_ = pid;
intefrace_ = 0; intefrace_ = 0;
hdev = 0; hdev = 0;
timeout_r = timeout_w = 0;
interface_claimed = -1; interface_claimed = -1;
setPath(PIString::fromNumber(vid_, 16).expandLeftTo(4, "0") + ":" + PIString::fromNumber(pid_, 16).expandLeftTo(4, "0")); setPath(PIString::fromNumber(vid_, 16).expandLeftTo(4, "0") + ":" + PIString::fromNumber(pid_, 16).expandLeftTo(4, "0"));
setDeviceNumber(1); setDeviceNumber(1);

View File

@@ -32,6 +32,7 @@ class PIP_EXPORT PIUSB: public PIIODevice
PIIODEVICE(PIUSB) PIIODEVICE(PIUSB)
public: public:
PIUSB(ushort vid = 0, ushort pid = 0); PIUSB(ushort vid = 0, ushort pid = 0);
~PIUSB() {closeDevice();}
struct Endpoint { struct Endpoint {
Endpoint(uchar a = 0, uchar at = 0, ushort mps = 0) {address = a; attributes = at; max_packet_size = mps; parse();} Endpoint(uchar a = 0, uchar at = 0, ushort mps = 0) {address = a; attributes = at; max_packet_size = mps; parse();}