version 0.5.0_alpha

git-svn-id: svn://db.shs.com.ru/pip@8 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5
This commit is contained in:
2015-03-10 10:13:18 +00:00
parent b1f651ab62
commit c11bc3b3b8
697 changed files with 18150 additions and 18839 deletions

View File

@@ -1,7 +1,7 @@
/*
PIP - Platform Independent Primitives
Geometry
Copyright (C) 2014 Ivan Pelipenko peri4ko@gmail.com
Copyright (C) 2015 Ivan Pelipenko peri4ko@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

View File

@@ -1,7 +1,7 @@
/*
PIP - Platform Independent Primitives
C++ code info structs
Copyright (C) 2014 Ivan Pelipenko peri4ko@gmail.com
Copyright (C) 2015 Ivan Pelipenko peri4ko@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

View File

@@ -4,7 +4,7 @@
/*
PIP - Platform Independent Primitives
C++ code info structs
Copyright (C) 2014 Ivan Pelipenko peri4ko@gmail.com
Copyright (C) 2015 Ivan Pelipenko peri4ko@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -104,7 +104,7 @@ inline PICout operator <<(PICout s, const PICodeInfo::ClassInfo & v) {
}
s << " {\n";
piForeachC (FunctionInfo & i, v.functions) {
s << Tab << i.return_type << " " << i.name << "(";
s << PICoutManipulators::Tab << i.return_type << " " << i.name << "(";
bool fa = true;
piForeachC (TypeInfo & a, i.arguments) {
if (fa) fa = false;
@@ -116,7 +116,7 @@ inline PICout operator <<(PICout s, const PICodeInfo::ClassInfo & v) {
if (!v.functions.isEmpty() && !v.variables.isEmpty())
s << "\n";
piForeachC (TypeInfo & i, v.variables) {
s << Tab << i << ";\n";
s << PICoutManipulators::Tab << i << ";\n";
}
s << "}\n";
s.restoreControl();
@@ -130,7 +130,7 @@ inline PICout operator <<(PICout s, const PICodeInfo::EnumInfo & v) {
bool f = true;
if (f) f = false;
else s << ", ";
s << Tab << i << "\n";
s << PICoutManipulators::Tab << i << "\n";
}
s << "}\n";
s.restoreControl();

View File

@@ -1,7 +1,7 @@
/*
PIP - Platform Independent Primitives
C++ code parser
Copyright (C) 2014 Ivan Pelipenko peri4ko@gmail.com
Copyright (C) 2015 Ivan Pelipenko peri4ko@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -54,7 +54,7 @@ PIString PICodeParser::Macro::expand(PIString args_, bool * ok) const {
PIChar ppc(0), pc(0), nc(0);
if (ind > 1) ppc = ret[ind - 2];
if (ind > 0) pc = ret[ind - 1];
if (ind + an.size_s() < ret.size_s()) nc = ret[ind + an.size_s()];
if (ind + an.size_s() < ret.size_s()) nc = ret.mid(ind + an.size_s(),0)[0];
if (ppc != '#' && pc == '#' && !_isCChar(nc)) { // to chars
ind--;
ret.replace(ind, an.size_s() + 1, "\"" + av + "\"");
@@ -230,7 +230,7 @@ bool PICodeParser::parseFileContent(PIString & fc, bool main) {
while ((ind = pfc.find(d.first, ind + 1)) >= 0) {
PIChar pc(0), nc(0);
if (ind > 0) pc = pfc[ind - 1];
if (ind + d.first.size_s() < pfc.size_s()) nc = pfc[ind + d.first.size_s()];
if (ind + d.first.size_s() < pfc.size_s()) nc = pfc.mid(ind + d.first.size_s(),0)[0];
if (_isCChar(pc) || _isCChar(nc) || nc.isDigit()) continue;
pfc.replace(ind, d.first.size_s(), d.second);
ind -= d.first.size_s() - d.second.size_s();
@@ -242,7 +242,7 @@ bool PICodeParser::parseFileContent(PIString & fc, bool main) {
while ((ind = pfc.find(m.name, ind + 1)) >= 0) {
PIChar pc(0), nc(0);
if (ind > 0) pc = pfc[ind - 1];
if (ind + m.name.size_s() < pfc.size_s()) nc = pfc[ind + m.name.size_s()];
if (ind + m.name.size_s() < pfc.size_s()) nc = pfc.mid(ind + m.name.size_s(),0)[0];
if (_isCChar(pc) || _isCChar(nc) || nc.isDigit()) continue;
PIString ret, range; bool ok(false);
range = pfc.mid(ind + m.name.size_s()).takeRange("(", ")");

View File

@@ -4,7 +4,7 @@
/*
PIP - Platform Independent Primitives
C++ code parser
Copyright (C) 2014 Ivan Pelipenko peri4ko@gmail.com
Copyright (C) 2015 Ivan Pelipenko peri4ko@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

View File

@@ -1,7 +1,7 @@
/*
PIP - Platform Independent Primitives
Generic containers
Copyright (C) 2014 Ivan Pelipenko peri4ko@gmail.com
Copyright (C) 2015 Ivan Pelipenko peri4ko@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

View File

@@ -7,7 +7,7 @@
/*
PIP - Platform Independent Primitives
Generic containers
Copyright (C) 2014 Ivan Pelipenko peri4ko@gmail.com
Copyright (C) 2015 Ivan Pelipenko peri4ko@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -27,6 +27,7 @@
#define PICONTAINERS_H
#include "picout.h"
#include <list>
template<typename Type0, typename Type1>
class PIP_EXPORT PIPair {
@@ -227,9 +228,9 @@ template <typename T> inline _PIForeachC<T> * _PIForeachCastC(_PIForeachBase & c
#endif // DOXYGEN
template<typename Type, typename Allocator = std::allocator<Type> >
class PIP_EXPORT PIList: public list<Type, Allocator> {
class PIP_EXPORT PIList: public std::list<Type, Allocator> {
typedef PIList<Type, Allocator> _CList;
typedef list<Type, Allocator> _stlc;
typedef std::list<Type, Allocator> _stlc;
public:
PIList() {piMonitor.containers++;}
PIList(const Type & value) {piMonitor.containers++; _stlc::resize(1, value);}
@@ -275,10 +276,6 @@ __PICONTAINERS_SIMPLE_TYPE__(ullong)
__PICONTAINERS_SIMPLE_TYPE__(float)
__PICONTAINERS_SIMPLE_TYPE__(double)
__PICONTAINERS_SIMPLE_TYPE__(ldouble)
__PICONTAINERS_SIMPLE_TYPE__(complexi)
__PICONTAINERS_SIMPLE_TYPE__(complexf)
__PICONTAINERS_SIMPLE_TYPE__(complexd)
__PICONTAINERS_SIMPLE_TYPE__(complexld)
#endif

View File

@@ -6,7 +6,7 @@
/*
PIP - Platform Independent Primitives
Dynamic array of any type
Copyright (C) 2014 Ivan Pelipenko peri4ko@gmail.com
Copyright (C) 2015 Ivan Pelipenko peri4ko@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

View File

@@ -6,7 +6,7 @@
/*
PIP - Platform Independent Primitives
Dynamic array of any type
Copyright (C) 2014 Ivan Pelipenko peri4ko@gmail.com
Copyright (C) 2015 Ivan Pelipenko peri4ko@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -226,12 +226,12 @@ public:
}
void dump() {
piCout << "PIMap" << size() << "entries" << NewLine << "content:";
piCout << "PIMap" << size() << "entries" << PICoutManipulators::NewLine << "content:";
for (size_t i = 0; i < pim_content.size(); ++i)
piCout << Tab << i << ":" << pim_content[i];
piCout << PICoutManipulators::Tab << i << ":" << pim_content[i];
piCout << "index:";
for (size_t i = 0; i < pim_index.size(); ++i)
piCout << Tab << i << ":" << pim_index[i].key << "->" << pim_index[i].index;
piCout << PICoutManipulators::Tab << i << ":" << pim_index[i].key << "->" << pim_index[i].index;
}
protected:

View File

@@ -6,7 +6,7 @@
/*
PIP - Platform Independent Primitives
Queue container
Copyright (C) 2014 Ivan Pelipenko peri4ko@gmail.com
Copyright (C) 2015 Ivan Pelipenko peri4ko@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

View File

@@ -6,7 +6,7 @@
/*
PIP - Platform Independent Primitives
Set container
Copyright (C) 2014 Ivan Pelipenko peri4ko@gmail.com
Copyright (C) 2015 Ivan Pelipenko peri4ko@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

View File

@@ -6,7 +6,7 @@
/*
PIP - Platform Independent Primitives
Stack container
Copyright (C) 2014 Ivan Pelipenko peri4ko@gmail.com
Copyright (C) 2015 Ivan Pelipenko peri4ko@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

View File

@@ -6,7 +6,7 @@
/*
PIP - Platform Independent Primitives
Dynamic array of any type
Copyright (C) 2014 Ivan Pelipenko peri4ko@gmail.com
Copyright (C) 2015 Ivan Pelipenko peri4ko@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

View File

@@ -1,7 +1,7 @@
/*
PIP - Platform Independent Primitives
Bit array
Copyright (C) 2014 Ivan Pelipenko peri4ko@gmail.com
Copyright (C) 2015 Ivan Pelipenko peri4ko@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

View File

@@ -1,7 +1,7 @@
/*
PIP - Platform Independent Primitives
Byte array
Copyright (C) 2014 Ivan Pelipenko peri4ko@gmail.com
Copyright (C) 2015 Ivan Pelipenko peri4ko@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -133,7 +133,7 @@ void PIHuffman::calcFrequencies(const PIDeque<uchar> & src) {
if (nodes[i].freq > 0 && i < 255)
{nodes.remove(i + 1, 255 - i); break;}
for (int i = 0; i < nodes.size_s(); ++i)
cout << string((char*)nodes[i].word.data(), 1) << ": " << nodes[i].freq << endl;
std::cout << std::string((char*)nodes[i].word.data(), 1) << ": " << nodes[i].freq << std::endl;
}

View File

@@ -4,7 +4,7 @@
/*
PIP - Platform Independent Primitives
Byte array
Copyright (C) 2014 Ivan Pelipenko peri4ko@gmail.com
Copyright (C) 2015 Ivan Pelipenko peri4ko@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

View File

@@ -4,7 +4,7 @@
/*
PIP - Platform Independent Primitives
Unicode char
Copyright (C) 2014 Ivan Pelipenko peri4ko@gmail.com
Copyright (C) 2015 Ivan Pelipenko peri4ko@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

View File

@@ -1,7 +1,7 @@
/*
PIP - Platform Independent Primitives
Command-Line Parser
Copyright (C) 2014 Ivan Pelipenko peri4ko@gmail.com
Copyright (C) 2015 Ivan Pelipenko peri4ko@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

View File

@@ -4,7 +4,7 @@
/*
PIP - Platform Independent Primitives
Command-Line Parser
Copyright (C) 2014 Ivan Pelipenko peri4ko@gmail.com
Copyright (C) 2015 Ivan Pelipenko peri4ko@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

View File

@@ -4,7 +4,7 @@
/*
PIP - Platform Independent Primitives
Peer - named I/O ethernet node, forming self-organized peering network
Copyright (C) 2014 Ivan Pelipenko peri4ko@gmail.com
Copyright (C) 2015 Ivan Pelipenko peri4ko@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

View File

@@ -1,7 +1,7 @@
/*
PIP - Platform Independent Primitives
Universal output to console class
Copyright (C) 2014 Ivan Pelipenko peri4ko@gmail.com
Copyright (C) 2015 Ivan Pelipenko peri4ko@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -19,6 +19,11 @@
#include "picout.h"
#include "piconsole.h"
#ifdef WINDOWS
# include <windows.h>
# include <wincon.h>
# define COMMON_LVB_UNDERSCORE 0x8000
#endif
/*! \class PICout
* \brief Class for formatted output similar std::cout
@@ -44,29 +49,43 @@
PIMutex __PICout_mutex__;
PIString __PICout_string__;
#ifdef WINDOWS
void * PICout::hOut = 0;
WORD PICout::dattr = 0;
DWORD PICout::smode = 0;
#endif
using namespace PICoutManipulators;
bool PICout::buffer_ = false;
PRIVATE_DEFINITION_START(PICout)
PIStack<PICoutControls> cos_;
#ifdef WINDOWS
static void * hOut;
static WORD dattr;
static DWORD smode;
#endif
PRIVATE_DEFINITION_END(PICout)
#ifdef WINDOWS
void * PICout::__Private__::hOut = 0;
WORD PICout::__Private__::dattr = 0;
DWORD PICout::__Private__::smode = 0;
#endif
PICout::PICout(PIFlags<PICoutControl> controls): fo_(true), cc_(false), fc_(false), cnb_(10), co_(controls) {
#ifdef WINDOWS
if (hOut == 0) {
hOut = GetStdHandle(STD_OUTPUT_HANDLE);
if (__Private__::hOut == 0) {
__Private__::hOut = GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_SCREEN_BUFFER_INFO sbi;
GetConsoleScreenBufferInfo(hOut, &sbi);
dattr = sbi.wAttributes;
GetConsoleScreenBufferInfo(__Private__::hOut, &sbi);
__Private__::dattr = sbi.wAttributes;
}
attr_ = dattr;
attr_ = __Private__::dattr;
#endif
__PICout_mutex__.lock();
}
PICout::PICout(const PICout & other): fo_(other.fo_), cc_(true), fc_(false), cnb_(other.cnb_), attr_(other.attr_), co_(other.co_) {
}
PICout::~PICout() {
if (fc_) applyFormat(PICoutManipulators::Default);
if (cc_) return;
@@ -89,12 +108,12 @@ PICout PICout::operator <<(const PICoutAction v) {
case PICoutManipulators::Backspace:
if (!PICout::buffer_) {
#ifdef WINDOWS
GetConsoleScreenBufferInfo(hOut, &sbi);
GetConsoleScreenBufferInfo(__Private__::hOut, &sbi);
coord = sbi.dwCursorPosition;
coord.X = piMax<int>(0, int(coord.X) - 1);
SetConsoleCursorPosition(hOut, coord);
SetConsoleCursorPosition(__Private__::hOut, coord);
printf(" ");
SetConsoleCursorPosition(hOut, coord);
SetConsoleCursorPosition(__Private__::hOut, coord);
#else
printf("\e[1D \e[1D");
#endif
@@ -103,9 +122,9 @@ PICout PICout::operator <<(const PICoutAction v) {
case PICoutManipulators::ShowCursor:
if (!PICout::buffer_) {
#ifdef WINDOWS
GetConsoleCursorInfo(hOut, &curinfo);
GetConsoleCursorInfo(__Private__::hOut, &curinfo);
curinfo.bVisible = true;
SetConsoleCursorInfo(hOut, &curinfo);
SetConsoleCursorInfo(__Private__::hOut, &curinfo);
#else
printf("\e[?25h");
#endif
@@ -114,9 +133,9 @@ PICout PICout::operator <<(const PICoutAction v) {
case PICoutManipulators::HideCursor:
if (!PICout::buffer_) {
#ifdef WINDOWS
GetConsoleCursorInfo(hOut, &curinfo);
GetConsoleCursorInfo(__Private__::hOut, &curinfo);
curinfo.bVisible = false;
SetConsoleCursorInfo(hOut, &curinfo);
SetConsoleCursorInfo(__Private__::hOut, &curinfo);
#else
printf("\e[?25l");
#endif
@@ -126,13 +145,13 @@ PICout PICout::operator <<(const PICoutAction v) {
if (!PICout::buffer_) {
#ifdef WINDOWS
/// TODO !!!
/*GetConsoleCursorInfo(hOut, &curinfo);
/*GetConsoleCursorInfo(__Private__::hOut, &curinfo);
curinfo.bVisible = false;
SetConsoleCursorInfo(hOut, &curinfo);
SetConsoleCursorInfo(__Private__::hOut, &curinfo);
SetConsoleCursorPosition(hOut, ulcoord);
FillConsoleOutputAttribute(hOut, dattr, width * (height + 1), ulcoord, &written);
FillConsoleOutputCharacter(hOut, ' ', width * (height + 1), ulcoord, &written);*/
SetConsoleCursorPosition(__Private__::hOut, ulcoord);
FillConsoleOutputAttribute(__Private__::hOut, __Private__::dattr, width * (height + 1), ulcoord, &written);
FillConsoleOutputCharacter(__Private__::hOut, ' ', width * (height + 1), ulcoord, &written);*/
#else
printf("\e[H\e[J");
#endif
@@ -152,7 +171,7 @@ PICout PICout::operator <<(const PICoutAction v) {
PICout PICout::operator <<(const char * v) {if (v == '\0') return *this; space(); quote(); PICOUTTOTARGET(v) quote(); return *this;}
PICout PICout::operator <<(const string & v) {space(); quote(); PICOUTTOTARGET(v) quote(); return *this;}
PICout PICout::operator <<(const std::string & v) {space(); quote(); PICOUTTOTARGET(v) quote(); return *this;}
PICout PICout::operator <<(const bool v) {space(); if (v) PICOUTTOTARGET("true") else PICOUTTOTARGET("false") return *this;}
@@ -228,6 +247,22 @@ PICout PICout::operator <<(const PICoutSpecialChar v) {
return *this;
}
PICout & PICout::saveControl() {
PRIVATE->cos_.push(co_);
return *this;
}
PICout & PICout::restoreControl() {
if (!PRIVATE->cos_.isEmpty()) {
co_ = PRIVATE->cos_.top();
PRIVATE->cos_.pop();
}
return *this;
}
#undef PICOUTTOTARGET
#undef PINUMERICCOUT
@@ -285,10 +320,10 @@ void PICout::applyFormat(PICoutFormat f) {
case PICoutManipulators::BackMagenta: attr_ = (attr_ & mask_back) | BACKGROUND_RED | BACKGROUND_BLUE; break;
case PICoutManipulators::BackCyan: attr_ = (attr_ & mask_back) | BACKGROUND_GREEN | BACKGROUND_BLUE; break;
case PICoutManipulators::BackWhite: attr_ = (attr_ & mask_back) | BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE; break;
case PICoutManipulators::Default: attr_ = dattr; break;
case PICoutManipulators::Default: attr_ = __Private__::dattr; break;
default: break;
}
SetConsoleTextAttribute(hOut, attr_);
SetConsoleTextAttribute(__Private__::hOut, attr_);
#else
switch (f) {
case Bin: case Oct: case Dec: case Hex: break;

View File

@@ -4,7 +4,7 @@
/*
PIP - Platform Independent Primitives
Universal output to console class
Copyright (C) 2014 Ivan Pelipenko peri4ko@gmail.com
Copyright (C) 2015 Ivan Pelipenko peri4ko@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -102,25 +102,28 @@ namespace PICoutManipulators {
BackWhite /*! White background */ = 0x2000000,
Default /*! Default format */ = 0x4000000
};
typedef PIFlags<PICoutControl> PICoutControls;
};
using namespace PICoutManipulators;
//using namespace PICoutManipulators;
typedef PIFlags<PICoutControl> PICoutControls;
class PIP_EXPORT PICout {
public:
//! Default constructor with default features (AddSpaces and AddNewLine)
PICout(PIFlags<PICoutControl> controls = AddSpaces | AddNewLine);
explicit PICout(PIFlags<PICoutManipulators::PICoutControl> controls = PICoutManipulators::AddSpaces | PICoutManipulators::AddNewLine);
PICout(const PICout & other);
PICout(const PICout & other): fo_(other.fo_), cc_(true), fc_(false), cnb_(other.cnb_), attr_(other.attr_), co_(other.co_) {;}
~PICout();
//! Output operator for strings with <tt>"const char * "</tt> type
PICout operator <<(const char * v);
//! Output operator for strings with <tt>"std::string"</tt> type
PICout operator <<(const string & v);
PICout operator <<(const std::string & v);
//! Output operator for boolean values
PICout operator <<(const bool v);
@@ -168,65 +171,65 @@ public:
PICout operator <<(const PIObject * v);
//! Output operator for \a PICoutSpecialChar values
PICout operator <<(const PICoutSpecialChar v);
PICout operator <<(const PICoutManipulators::PICoutSpecialChar v);
//! Output operator for \a PIFlags<PICoutFormat> values
PICout operator <<(const PIFlags<PICoutFormat> v) {
if (v[Bin]) cnb_ = 2;
if (v[Oct]) cnb_ = 8;
if (v[Dec]) cnb_ = 10;
if (v[Hex]) cnb_ = 16;
if (v[Bold]) applyFormat(Bold);
if (v[Faint]) applyFormat(Faint);
if (v[Italic]) applyFormat(Italic);
if (v[Underline]) applyFormat(Underline);
if (v[Blink]) applyFormat(Blink);
if (v[Black]) applyFormat(Black);
if (v[Red]) applyFormat(Red);
if (v[Green]) applyFormat(Green);
if (v[Blue]) applyFormat(Blue);
if (v[Yellow]) applyFormat(Yellow);
if (v[Magenta]) applyFormat(Magenta);
if (v[Cyan]) applyFormat(Cyan);
if (v[White]) applyFormat(White);
if (v[BackBlack]) applyFormat(BackBlack);
if (v[BackRed]) applyFormat(BackRed);
if (v[BackGreen]) applyFormat(BackGreen);
if (v[BackBlue]) applyFormat(BackBlue);
if (v[BackYellow]) applyFormat(BackYellow);
if (v[BackMagenta]) applyFormat(BackMagenta);
if (v[BackCyan]) applyFormat(BackCyan);
if (v[BackWhite]) applyFormat(BackWhite);
if (v[Default]) applyFormat(Default);
PICout operator <<(const PIFlags<PICoutManipulators::PICoutFormat> v) {
if (v[PICoutManipulators::Bin]) cnb_ = 2;
if (v[PICoutManipulators::Oct]) cnb_ = 8;
if (v[PICoutManipulators::Dec]) cnb_ = 10;
if (v[PICoutManipulators::Hex]) cnb_ = 16;
if (v[PICoutManipulators::Bold]) applyFormat(PICoutManipulators::Bold);
if (v[PICoutManipulators::Faint]) applyFormat(PICoutManipulators::Faint);
if (v[PICoutManipulators::Italic]) applyFormat(PICoutManipulators::Italic);
if (v[PICoutManipulators::Underline]) applyFormat(PICoutManipulators::Underline);
if (v[PICoutManipulators::Blink]) applyFormat(PICoutManipulators::Blink);
if (v[PICoutManipulators::Black]) applyFormat(PICoutManipulators::Black);
if (v[PICoutManipulators::Red]) applyFormat(PICoutManipulators::Red);
if (v[PICoutManipulators::Green]) applyFormat(PICoutManipulators::Green);
if (v[PICoutManipulators::Blue]) applyFormat(PICoutManipulators::Blue);
if (v[PICoutManipulators::Yellow]) applyFormat(PICoutManipulators::Yellow);
if (v[PICoutManipulators::Magenta]) applyFormat(PICoutManipulators::Magenta);
if (v[PICoutManipulators::Cyan]) applyFormat(PICoutManipulators::Cyan);
if (v[PICoutManipulators::White]) applyFormat(PICoutManipulators::White);
if (v[PICoutManipulators::BackBlack]) applyFormat(PICoutManipulators::BackBlack);
if (v[PICoutManipulators::BackRed]) applyFormat(PICoutManipulators::BackRed);
if (v[PICoutManipulators::BackGreen]) applyFormat(PICoutManipulators::BackGreen);
if (v[PICoutManipulators::BackBlue]) applyFormat(PICoutManipulators::BackBlue);
if (v[PICoutManipulators::BackYellow]) applyFormat(PICoutManipulators::BackYellow);
if (v[PICoutManipulators::BackMagenta]) applyFormat(PICoutManipulators::BackMagenta);
if (v[PICoutManipulators::BackCyan]) applyFormat(PICoutManipulators::BackCyan);
if (v[PICoutManipulators::BackWhite]) applyFormat(PICoutManipulators::BackWhite);
if (v[PICoutManipulators::Default]) applyFormat(PICoutManipulators::Default);
return *this;
}
//! Output operator for \a PICoutFormat values
PICout operator <<(const PICoutFormat v) {
PICout operator <<(const PICoutManipulators::PICoutFormat v) {
switch (v) {
case Bin: cnb_ = 2; break;
case Oct: cnb_ = 8; break;
case Dec: cnb_ = 10; break;
case Hex: cnb_ = 16; break;
case PICoutManipulators::Bin: cnb_ = 2; break;
case PICoutManipulators::Oct: cnb_ = 8; break;
case PICoutManipulators::Dec: cnb_ = 10; break;
case PICoutManipulators::Hex: cnb_ = 16; break;
default: applyFormat(v);
};
return *this;
}
//! Do some action
PICout operator <<(const PICoutAction v);
PICout operator <<(const PICoutManipulators::PICoutAction v);
//! Set control flag "c" is "on" state
PICout & setControl(PICoutControl c, bool on = true) {co_.setFlag(c, on); return *this;}
PICout & setControl(PICoutManipulators::PICoutControl c, bool on = true) {co_.setFlag(c, on); return *this;}
//! Set control flags "c" and if "save" exec \a saveControl()
PICout & setControl(PICoutControls c, bool save = false) {if (save) saveControl(); co_ = c; return *this;}
PICout & setControl(PICoutManipulators::PICoutControls c, bool save = false) {if (save) saveControl(); co_ = c; return *this;}
//! Save control flags to internal stack \sa \a restoreControl()
PICout & saveControl() {cos_.push(co_); return *this;}
PICout & saveControl();
//! Restore control flags from internal stack \sa \a saveControl()
PICout & restoreControl() {if (!cos_.empty()) {co_ = cos_.top(); cos_.pop();} return *this;}
PICout & restoreControl();
/*! \brief Conditional put space character to output
* \details If it is not a first output and control \a AddSpaces is set
@@ -249,18 +252,13 @@ public:
static void clearBuffer();
private:
void applyFormat(PICoutFormat f);
void applyFormat(PICoutManipulators::PICoutFormat f);
static bool buffer_;
PRIVATE_DECLARATION
bool fo_, cc_, fc_;
int cnb_, attr_;
PICoutControls co_;
std::stack<PICoutControls> cos_;
#ifdef WINDOWS
static void * hOut;
static WORD dattr;
static DWORD smode;
#endif
PICoutManipulators::PICoutControls co_;
};
#endif // PICOUT_H

View File

@@ -4,7 +4,7 @@
/*
PIP - Platform Independent Primitives
General flags class
Copyright (C) 2014 Ivan Pelipenko peri4ko@gmail.com
Copyright (C) 2015 Ivan Pelipenko peri4ko@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

View File

@@ -1,7 +1,7 @@
/*
PIP - Platform Independent Primitives
Global includes
Copyright (C) 2014 Ivan Pelipenko peri4ko@gmail.com
Copyright (C) 2015 Ivan Pelipenko peri4ko@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -19,6 +19,18 @@
#include "piincludes.h"
#include "piconsole.h"
#ifndef QNX
# include <clocale>
#else
# include <locale.h>
#endif
#ifdef MAC_OS
//# include <mach/mach_traps.h>
//# include <mach/mach.h>
# include <mach/clock.h>
//# include <crt_externs.h>
#endif
#include <errno.h>
bool piDebug = true;
double piMountInfoRefreshIntervalMs = 10000.;
@@ -53,7 +65,7 @@ PIString errorString() {
char * msg;
int err = GetLastError();
FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, err, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPSTR)&msg, 0, NULL);
return "code " + itos(err) + " - " + string(msg);
return "code " + PIString::fromNumber(err) + " - " + PIString(msg);
#else
int e = errno;
return PIString("code ") + PIString::fromNumber(e) + " - " + PIString(strerror(e));

View File

@@ -1,13 +1,7 @@
/*! \file piincludes.h
* \brief Global includes of PIP
*
* This file include all needed system headers, STL
* and declare many useful macros and functions
*/
/*
PIP - Platform Independent Primitives
Global includes
Copyright (C) 2014 Ivan Pelipenko peri4ko@gmail.com
Minimal PIP includes
Copyright (C) 2015 Ivan Pelipenko peri4ko@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -26,105 +20,36 @@
#ifndef PIINCLUDES_H
#define PIINCLUDES_H
#include "piversion.h"
#include "pibase.h"
#include "piflags.h"
//! Version of PIP in hex - 0x##(Major)##(Minor)##(Revision)
#define PIP_VERSION ((PIP_VERSION_MAJOR << 16) | (PIP_VERSION_MINOR < 8) | PIP_VERSION_REVISION)
#ifdef DOXYGEN
//! Major value of PIP version
# define PIP_VERSION_MAJOR
//! Minor value of PIP version
# define PIP_VERSION_MINOR
//! Revision value of PIP version
# define PIP_VERSION_REVISION
//! Suffix of PIP version
# define PIP_VERSION_SUFFIX
//! Macro is defined when compile-time debug is enabled
# define PIP_DEBUG
//! Macro is defined when host is any Windows
# define WINDOWS
//! Macro is defined when host is QNX
# define QNX
//! Macro is defined when host is FreeBSD
# define FREE_BSD
//! Macro is defined when host is Mac OS
# define MAC_OS
//! Macro is defined when host is Android
# define ANDROID
//! Macro is defined when host is any Linux
# define LINUX
//! Macro is defined when compiler is GCC or MinGW
# define CC_GCC
//! Macro is defined when PIP is decided that host is support language
# define HAS_LOCALE
//! Macro is defined when compiler is Visual Studio
# define CC_VC
//! Macro is defined when compiler is unknown
# define CC_OTHER
//! Macro is defined when PIP use "rt" library for timers implementation
# define PIP_TIMER_RT
//! Define this macro to use STL implementation of containers, else PIP implementation will be used
# define PIP_CONTAINERS_STL
#endif
#include "piplatform.h"
#include "pip_export.h"
#if defined(DOXYGEN) || defined(CC_GCC) || defined(PICODE)
# undef PIP_EXPORT
# define PIP_EXPORT
#endif
#include <iostream>
#ifdef CC_GCC
# include <unistd.h>
#endif
#include <stdarg.h>
#include <stddef.h>
#include <stdlib.h>
#include <cassert>
#include <string.h>
#include <string>
#ifndef QNX
# include <cstdio>
# include <cstdlib>
# include <clocale>
# include <complex>
# include <cmath>
#else
# include <stdio.h>
# include <locale.h>
# include <complex.h>
# include <math.h>
#endif
#include <stdlib.h>
#include <sys/stat.h>
/*#ifdef WINDOWS
# include <io.h>
# include <windows.h>
# include <wincon.h>
#endif*/
#ifdef CC_GCC
# include <unistd.h>
#endif
/*
#include <sys/types.h>
#include <errno.h>
#include <cctype>
#include <ctime>
#include <csignal>
#include <cassert>
#include <cmath>
//#include <signal.h>
#include <typeinfo>
#include <algorithm>
#include <string.h>
#include <string>
#include <vector>
#include <list>
#include <queue>
@@ -135,397 +60,36 @@
#ifdef WINDOWS
# include <conio.h>
# include <io.h>
# include <winsock2.h>
# ifdef CC_VC
# define SHUT_RDWR 2
# pragma comment(lib, "Ws2_32.lib")
# pragma comment(lib, "Iphlpapi.lib")
# pragma comment(lib, "Psapi.lib")
# else
# define SHUT_RDWR SD_BOTH
# endif
# include <windows.h>
# include <wincon.h>
# include <iphlpapi.h>
# include <psapi.h>
typedef int socklen_t;
typedef void(*PINtSetTimerResolution)(ULONG, BOOLEAN, PULONG);
extern FILETIME __pi_ftjan1970;
extern long long __pi_perf_freq;
extern PINtSetTimerResolution setTimerResolutionAddr;
inline long long __PIQueryPerformanceCounter() {LARGE_INTEGER li; QueryPerformanceCounter(&li); return li.QuadPart;}
inline void __PISetTimerResolution() {if (setTimerResolutionAddr == NULL) return; ULONG ret; setTimerResolutionAddr(1, TRUE, &ret);}
#else
# include <netinet/in.h>
# include <arpa/inet.h>
# include <sys/socket.h>
# include <fcntl.h>
# include <sys/ioctl.h>
# include <net/if.h>
# include <sys/utsname.h>
# include <pthread.h>
# ifndef ANDROID
# include <ifaddrs.h>
# endif
#endif
#ifdef ANDROID
# define tcdrain(fd) ioctl(fd, TCSBRK, 1)
inline int wctomb(char * c, wchar_t w) {*c = ((char * )&w)[0]; return 1;}
inline int mbtowc(wchar_t * w, const char * c, size_t) {*w = ((wchar_t * )&c)[0]; return 1;}
#endif
#ifdef MAC_OS
# include <mach/mach_traps.h>
# include <mach/mach.h>
# include <mach/clock.h>
# include <crt_externs.h>
# define environ (*_NSGetEnviron())
typedef long time_t;
extern clock_serv_t __pi_mac_clock;
#endif
#ifdef LINUX
# define environ __environ
#endif
#if !defined(WINDOWS) && !defined(MAC_OS)
//# define PIP_TIMER_RT
#endif
#ifdef FREE_BSD
extern char ** environ;
#endif
#if defined(DOXYGEN) || defined(PICODE)
# undef PIP_EXPORT
# define PIP_EXPORT
# undef DEPRECATED
# define DEPRECATED
#endif
#include "pimonitor.h"
#include "piflags.h"
#endif*/
extern PIMonitor piMonitor;
//! Macro used for infinite loop
#define FOREVER for (;;)
//! Macro used for infinite wait
#define FOREVER_WAIT FOREVER msleep(1);
//! Macro used for infinite wait
#define WAIT_FOREVER FOREVER msleep(1);
using std::cout;
using std::cin;
using std::endl;
using std::flush;
using std::vector;
using std::list;
using std::queue;
using std::deque;
using std::stack;
using std::set;
using std::map;
using std::multimap;
using std::string;
using std::complex;
#ifndef QNX
using std::wstring;
#else
typedef std::basic_string<wchar_t> wstring;
#endif
typedef long long llong;
typedef unsigned char uchar;
typedef unsigned short int ushort;
typedef unsigned int uint;
typedef unsigned long ulong;
typedef unsigned long long ullong;
typedef long double ldouble;
typedef complex<int> complexi;
typedef complex<float> complexf;
typedef complex<double> complexd;
typedef complex<ldouble> complexld;
const complexld complexld_i(0., 1.);
const complexld complexld_0(0.);
const complexld complexld_1(1.);
const complexd complexd_i(0., 1.);
const complexd complexd_0(0.);
const complexd complexd_1(1.);
/*! \brief Templated function for swap two values
* \details Example:\n \snippet piincludes.cpp swap */
template<typename T> inline void piSwap(T & f, T & s) {T t = f; f = s; s = t;}
/*! \brief Templated function for swap two values without "="
* \details Example:\n \snippet piincludes.cpp swapBinary */
template<typename T> inline void piSwapBinary(T & f, T & s) {
static size_t j = (sizeof(T) / sizeof(size_t)), bs = j * sizeof(size_t), bf = sizeof(T);
size_t i = 0;
for (i = 0; i < j; ++i) {
((size_t*)(&f))[i] ^= ((size_t*)(&s))[i];
((size_t*)(&s))[i] ^= ((size_t*)(&f))[i];
((size_t*)(&f))[i] ^= ((size_t*)(&s))[i];
}
for (i = bs; i < bf; ++i) {
((uchar*)(&f))[i] ^= ((uchar*)(&s))[i];
((uchar*)(&s))[i] ^= ((uchar*)(&f))[i];
((uchar*)(&f))[i] ^= ((uchar*)(&s))[i];
}
}
/*! \brief Templated function return round of float falue
* \details Round is the nearest integer value \n
* There are some macros:
* - \c piRoundf for "float"
* - \c piRoundd for "double"
*
* Example:
* \snippet piincludes.cpp round */
template<typename T> inline int piRound(const T & v) {return int(v >= T(0.) ? v + T(0.5) : v - T(0.5));}
/*! \brief Templated function return floor of float falue
* \details Floor is the largest integer that is not greater than value \n
* There are some macros:
* - \c piFloorf for "float"
* - \c piFloord for "double"
*
* Example:
* \snippet piincludes.cpp floor */
template<typename T> inline int piFloor(const T & v) {return v < T(0) ? int(v) - 1 : int(v);}
/*! \brief Templated function return ceil of float falue
* \details Ceil is the smallest integer that is not less than value \n
* There are some macros:
* - \c piCeilf for "float"
* - \c piCeild for "double"
*
* Example:
* \snippet piincludes.cpp ceil */
template<typename T> inline int piCeil(const T & v) {return v < T(0) ? int(v) : int(v) + 1;}
/*! \brief Templated function return absolute of numeric falue
* \details Absolute is the positive or equal 0 value \n
* There are some macros:
* - \c piAbss for "short"
* - \c piAbsi for "int"
* - \c piAbsl for "long"
* - \c piAbsll for "llong"
* - \c piAbsf for "float"
* - \c piAbsd for "double"
*
* Example:
* \snippet piincludes.cpp abs */
template<typename T> inline T piAbs(const T & v) {return (v >= T(0) ? v : -v);}
/*! \brief Templated function return minimum of two values
* \details There are some macros:
* - \c piMins for "short"
* - \c piMini for "int"
* - \c piMinl for "long"
* - \c piMinll for "llong"
* - \c piMinf for "float"
* - \c piMind for "double"
*
* Example:
* \snippet piincludes.cpp min2 */
template<typename T> inline T piMin(const T & f, const T & s) {return ((f > s) ? s : f);}
/*! \brief Templated function return minimum of tree values
* \details There are some macros:
* - \c piMins for "short"
* - \c piMini for "int"
* - \c piMinl for "long"
* - \c piMinll for "llong"
* - \c piMinf for "float"
* - \c piMind for "double"
*
* Example:
* \snippet piincludes.cpp min3 */
template<typename T> inline T piMin(const T & f, const T & s, const T & t) {return ((f < s && f < t) ? f : ((s < t) ? s : t));}
/*! \brief Templated function return maximum of two values
* \details There are some macros:
* - \c piMaxs for "short"
* - \c piMaxi for "int"
* - \c piMaxl for "long"
* - \c piMaxll for "llong"
* - \c piMaxf for "float"
* - \c piMaxd for "double"
*
* Example:
* \snippet piincludes.cpp max2 */
template<typename T> inline T piMax(const T & f, const T & s) {return ((f < s) ? s : f);}
/*! \brief Templated function return maximum of tree values
* \details There are some macros:
* - \c piMaxs for "short"
* - \c piMaxi for "int"
* - \c piMaxl for "long"
* - \c piMaxll for "llong"
* - \c piMaxf for "float"
* - \c piMaxd for "double"
*
* Example:
* \snippet piincludes.cpp max3 */
template<typename T> inline T piMax(const T & f, const T & s, const T & t) {return ((f > s && f > t) ? f : ((s > t) ? s : t));}
/*! \brief Templated function return clamped value
* \details Clamped is the not greater than "max" and not lesser than "min" value \n
* There are some macros:
* - \c piClamps for "short"
* - \c piClampi for "int"
* - \c piClampl for "long"
* - \c piClampll for "llong"
* - \c piClampf for "float"
* - \c piClampd for "double"
*
* Example:
* \snippet piincludes.cpp clamp */
template<typename T> inline T piClamp(const T & v, const T & min, const T & max) {return (v > max ? max : (v < min ? min : v));}
/// Function inverse byte order in memory block
inline void piLetobe(void * data, int size) {
for (int i = 0; i < size / 2; i++)
piSwap<uchar>(((uchar*)data)[size - i - 1], ((uchar*)data)[i]);
}
/// \brief Templated function that inverse byte order of value "v"
template<typename T> inline void piLetobe(T * v) {piLetobe(v, sizeof(T));}
/*! \brief Templated function that returns "v" with inversed byte order
* \details This function used to convert values between little and big endian \n
* There are some macros:
* - \c piLetobes for "ushort"
* - \c piLetobei for "uint"
* - \c piLetobel for "ulong"
* - \c piLetobell for "ullong"
*
* Example:
* \snippet piincludes.cpp letobe */
template<typename T> inline T piLetobe(const T & v) {T tv(v); piLetobe(&tv, sizeof(T)); return tv;}
// specialization
template<> inline ushort piLetobe(const ushort & v) {return (v << 8) | (v >> 8);}
template<> inline uint piLetobe(const uint & v) {return (v >> 24) | ((v >> 8) & 0xFF00) | ((v << 8) & 0xFF0000) | ((v << 24) & 0xFF000000);}
DEPRECATED inline ushort letobe_s(const ushort & v) {return (v << 8) | (v >> 8);}
DEPRECATED inline uint letobe_i(const uint & v) {return (v >> 24) | ((v >> 8) & 0xFF00) | ((v << 8) & 0xFF0000) | ((v << 24) & 0xFF000000);}
#ifdef DOXYGEN
/// \deprecated \brief Use \a piLetobe() instead of this function
ushort letobe_s(ushort v) {return (v << 8) | (v >> 8);}
/// \deprecated \brief Use \a piLetobe() instead of this function
uint letobe_i(uint v) {return (v >> 24) | ((v >> 8) & 0xFF00) | ((v << 8) & 0xFF0000) | ((v << 24) & 0xFF000000);}
#endif
#define piRoundf piRound<float>
#define piRoundd piRound<double>
#define piFloorf piFloor<float>
#define piFloord piFloor<double>
#define piCeilf piCeil<float>
#define piCeild piCeil<double>
#define piAbss piAbs<short>
#define piAbsi piAbs<int>
#define piAbsl piAbs<long>
#define piAbsll piAbs<llong>
#define piAbsf piAbs<float>
#define piAbsd piAbs<double>
#define piMins piMin<short>
#define piMini piMin<int>
#define piMinl piMin<long>
#define piMinll piMin<llong>
#define piMinf piMin<float>
#define piMind piMin<double>
#define piMaxs piMax<short>
#define piMaxi piMax<int>
#define piMaxl piMax<long>
#define piMaxll piMax<llong>
#define piMaxf piMax<float>
#define piMaxd piMax<double>
#define piClamps piClamp<short>
#define piClampi piClamp<int>
#define piClampl piClamp<long>
#define piClampll piClamp<llong>
#define piClampf piClamp<float>
#define piClampd piClamp<double>
#define piLetobes piLetobe<ushort>
#define piLetobei piLetobe<uint>
#define piLetobel piLetobe<ulong>
#define piLetobell piLetobe<ullong>
class PIObject;
class PIMutex;
class PIString;
class PIInit;
//! global variable enabling output to piCout, default is true
extern PIP_EXPORT bool piDebug;
//! global variable that set minimum real update interval
//! for function PIInit::mountInfo(), default is 10000 ms
extern PIP_EXPORT double piMountInfoRefreshIntervalMs;
struct lconv;
extern lconv * currentLocale;
#ifdef WINDOWS
inline int random() {return rand();}
# ifdef CC_VC
inline double round(const double & v) {return floor(v + 0.5);}
# endif
#endif
inline bool atob(const string & str) {return str == "1" ? true : false;}
inline string btos(const bool num) {return num ? "0" : "1";}
inline string itos(const int num) {
char ch[256];
#ifndef CC_VC
sprintf(ch, "%d", num);
#else
sprintf_s(ch, 256, "%d", num);
#endif
return string(ch);}
inline string ltos(const long num) {
char ch[256];
#ifndef CC_VC
sprintf(ch, "%ld", num);
#else
sprintf_s(ch, 256, "%ld", num);
#endif
return string(ch);}
inline string uitos(const uint num) {
char ch[256];
#ifndef CC_VC
sprintf(ch, "%u", num);
#else
sprintf_s(ch, 256, "%u", num);
#endif
return string(ch);}
inline string ultos(const ulong num) {
char ch[256];
#ifndef CC_VC
sprintf(ch, "%lu", num);
#else
sprintf_s(ch, 256, "%lu", num);
#endif
return string(ch);}
inline string ftos(const float num) {
char ch[256];
#ifndef CC_VC
sprintf(ch, "%.8f", num);
#else
sprintf_s(ch, 256, "%.8f", num);
#endif
return string(ch);}
inline string dtos(const double num) {
char ch[256];
#ifndef CC_VC
sprintf(ch, "%.8f", num);
#else
sprintf_s(ch, 256, "%.8f", num);
#endif
return string(ch);}
/*! \fn errorString()
* \brief Return readable error description in format "code <number> - <description>" */
PIString errorString();

View File

@@ -1,7 +1,7 @@
/*
PIP - Platform Independent Primitives
Initialization
Copyright (C) 2014 Ivan Pelipenko peri4ko@gmail.com
Copyright (C) 2015 Ivan Pelipenko peri4ko@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -25,9 +25,32 @@
#include "pidir.h"
#include "piprocess.h"
#ifdef WINDOWS
# include <winsock2.h>
extern FILETIME __pi_ftjan1970;
#else
# include <pwd.h>
# include <sys/utsname.h>
# include <pthread.h>
# include <csignal>
#endif
#ifdef MAC_OS
# include <mach/mach_traps.h>
# include <mach/mach.h>
# include <mach/clock.h>
//# include <crt_externs.h>
extern clock_serv_t __pi_mac_clock;
#endif
/*
#ifdef WINDOWS
# include <conio.h>
# include <io.h>
# include <windows.h>
# include <wincon.h>
#else
# include <fcntl.h>
# include <sys/ioctl.h>
# include <pthread.h>
#endif*/
#ifdef HAS_LOCALE

View File

@@ -6,7 +6,7 @@
/*
PIP - Platform Independent Primitives
Initialization
Copyright (C) 2014 Ivan Pelipenko peri4ko@gmail.com
Copyright (C) 2015 Ivan Pelipenko peri4ko@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

View File

@@ -1,7 +1,7 @@
/*
PIP - Platform Independent Primitives
Object, base class of some PIP classes, provide EVENT -> EVENT_HANDLER mechanism
Copyright (C) 2014 Ivan Pelipenko peri4ko@gmail.com
Copyright (C) 2015 Ivan Pelipenko peri4ko@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -339,26 +339,26 @@ bool PIObject::execute(const PIString & method) {
void PIObject::dump(const PIString & line_prefix) const {
//printf("dump %s \"%s\"\n", className(), name().data());
PICout(AddNewLine) << line_prefix << "class " << className() << " (" << (const void*)this << ", \"" << name() << "\") {";
PICout(AddNewLine) << line_prefix << " properties {";
PICout(AddNewLine) << line_prefix << " count: " << properties_.size_s();
PICout(PICoutManipulators::AddNewLine) << line_prefix << "class " << className() << " (" << (const void*)this << ", \"" << name() << "\") {";
PICout(PICoutManipulators::AddNewLine) << line_prefix << " properties {";
PICout(PICoutManipulators::AddNewLine) << line_prefix << " count: " << properties_.size_s();
//printf("dump %d properties\n", properties_.size());
piForeachC (Property p, properties_)
if (p.first != "name")
PICout(AddNewLine) << line_prefix << " " << p.first << ": " << p.second;
PICout(PICoutManipulators::AddNewLine) << line_prefix << " " << p.first << ": " << p.second;
//printf("dump %d properties ok\n", properties_.size());
PICout(AddNewLine) << line_prefix << " }";
PICout(AddNewLine) << line_prefix << " methodsEH {";
PICout(PICoutManipulators::AddNewLine) << line_prefix << " }";
PICout(PICoutManipulators::AddNewLine) << line_prefix << " methodsEH {";
__EHData & ehd(__eh_data[className()]);
PICout(AddNewLine) << line_prefix << " count: " << ehd.eh_func.size_s();
PICout(PICoutManipulators::AddNewLine) << line_prefix << " count: " << ehd.eh_func.size_s();
//printf("dump %d methods\n", ehd.eh_func.size());
piForeachC (__EHPair & eh, ehd.eh_func) {
PICout(AddNewLine) << line_prefix << " " << eh.second.fullFormat();
PICout(PICoutManipulators::AddNewLine) << line_prefix << " " << eh.second.fullFormat();
}
//printf("dump %d methods ok\n", ehd.eh_func.size());
PICout(AddNewLine) << line_prefix << " }";
PICout(AddNewLine) << line_prefix << " connections {";
PICout(AddNewLine) << line_prefix << " count: " << connections.size_s();
PICout(PICoutManipulators::AddNewLine) << line_prefix << " }";
PICout(PICoutManipulators::AddNewLine) << line_prefix << " connections {";
PICout(PICoutManipulators::AddNewLine) << line_prefix << " count: " << connections.size_s();
//printf("dump %d connections\n",connections.size());
piForeachC (Connection & c, connections) {
PIObject * dst = c.dest_o;
@@ -369,11 +369,11 @@ void PIObject::dump(const PIString & line_prefix) const {
PIString src(c.event);
if (!ef.func_name.isEmpty())
src = ef.func_name + "(" + ef.arguments() + ")";
PICout(AddNewLine) << line_prefix << " " << src << " -> " << dst->className() << " (" << c.dest << ", \"" << dst->name() << "\")::" << hf.func_name;
PICout(PICoutManipulators::AddNewLine) << line_prefix << " " << src << " -> " << dst->className() << " (" << c.dest << ", \"" << dst->name() << "\")::" << hf.func_name;
}
//printf("dump %d connections ok\n",connections.size());
PICout(AddNewLine) << line_prefix << " }";
PICout(AddNewLine) << line_prefix << "}";
PICout(PICoutManipulators::AddNewLine) << line_prefix << " }";
PICout(PICoutManipulators::AddNewLine) << line_prefix << "}";
}
@@ -383,20 +383,20 @@ void dumpApplication() {
//printf("dump application ...\n");
PIDateTime cd = PIDateTime::current();
PISystemInfo * pi = PISystemInfo::instance();
PICout(AddNewLine) << "application {";
PICout(AddNewLine) << " PIP version: " << PIPVersion();
PICout(AddNewLine) << " processors: " << pi->processorsCount;
PICout(AddNewLine) << " hostname: \"" << pi->hostname << "\"";
PICout(AddNewLine) << " user: \"" << pi->user << "\"";
PICout(AddNewLine) << " exec command: \"" << pi->execCommand << "\"";
PICout(AddNewLine) << " started: " << pi->execDateTime.toString();
PICout(AddNewLine) << " uptime, s: " << (cd.toSystemTime() - pi->execDateTime.toSystemTime()).toSeconds();
PICout(AddNewLine) << " PIObjects {";
PICout(AddNewLine) << " count: " << PIObject::objects.size_s();
PICout(PICoutManipulators::AddNewLine) << "application {";
PICout(PICoutManipulators::AddNewLine) << " PIP version: " << PIPVersion();
PICout(PICoutManipulators::AddNewLine) << " processors: " << pi->processorsCount;
PICout(PICoutManipulators::AddNewLine) << " hostname: \"" << pi->hostname << "\"";
PICout(PICoutManipulators::AddNewLine) << " user: \"" << pi->user << "\"";
PICout(PICoutManipulators::AddNewLine) << " exec command: \"" << pi->execCommand << "\"";
PICout(PICoutManipulators::AddNewLine) << " started: " << pi->execDateTime.toString();
PICout(PICoutManipulators::AddNewLine) << " uptime, s: " << (cd.toSystemTime() - pi->execDateTime.toSystemTime()).toSeconds();
PICout(PICoutManipulators::AddNewLine) << " PIObjects {";
PICout(PICoutManipulators::AddNewLine) << " count: " << PIObject::objects.size_s();
piForeachC (PIObject * o, PIObject::objects)
o->dump(" ");
PICout(AddNewLine) << " }";
PICout(AddNewLine) << "}";
PICout(PICoutManipulators::AddNewLine) << " }";
PICout(PICoutManipulators::AddNewLine) << "}";
//printf("dump application done\n");
}

View File

@@ -6,7 +6,7 @@
/*
PIP - Platform Independent Primitives
Object, base class of some PIP classes, provide EVENT -> EVENT_HANDLER mechanism
Copyright (C) 2014 Ivan Pelipenko peri4ko@gmail.com
Copyright (C) 2015 Ivan Pelipenko peri4ko@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

View File

@@ -4,7 +4,7 @@
/*
PIP - Platform Independent Primitives
State machine
Copyright (C) 2014 Ivan Pelipenko peri4ko@gmail.com
Copyright (C) 2015 Ivan Pelipenko peri4ko@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

View File

@@ -1,7 +1,7 @@
/*
PIP - Platform Independent Primitives
String
Copyright (C) 2014 Ivan Pelipenko peri4ko@gmail.com
Copyright (C) 2015 Ivan Pelipenko peri4ko@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -76,6 +76,21 @@ const int PIString::fromBaseN[] = {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1};
#ifndef CC_VC
# define pisprintf(f, v) char ch[256]; memset(ch, 0, 256); sprintf(ch, f, v);
#else
# define pisprintf(f, v) char ch[256]; memset(ch, 0, 256); sprintf_s(ch, 256, f, v);
#endif
PIString PIString::itos(const int num) {pisprintf("%d", num); return PIString(ch);}
PIString PIString::ltos(const long num) {pisprintf("%ld", num); return PIString(ch);}
PIString PIString::uitos(const uint num) {pisprintf("%u", num); return PIString(ch);}
PIString PIString::ultos(const ulong num) {pisprintf("%lu", num); return PIString(ch);}
PIString PIString::ftos(const float num) {pisprintf("%.8f", num); return PIString(ch);}
PIString PIString::dtos(const double num) {pisprintf("%.8f", num); return PIString(ch);}
#undef pisprintf
void PIString::appendFromChars(const char * c, int s) {
int sz;
@@ -640,8 +655,8 @@ const char * PIString::data() const {
}
string PIString::convertToStd() const {
string s;
std::string PIString::convertToStd() const {
std::string s;
uint wc;
uchar tc;
if (size() > 0) {

View File

@@ -6,7 +6,7 @@
/*
PIP - Platform Independent Primitives
String
Copyright (C) 2014 Ivan Pelipenko peri4ko@gmail.com
Copyright (C) 2015 Ivan Pelipenko peri4ko@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -27,7 +27,6 @@
#include "pibytearray.h"
#include "pichar.h"
#include "math.h"
class PIStringList;
@@ -41,7 +40,7 @@ public:
PIString & operator +=(const PIChar & c) {push_back(c); return *this;}
PIString & operator +=(const char * str);
PIString & operator +=(const wchar_t * str);
PIString & operator +=(const string & str) {appendFromChars(str.c_str(), str.length()); return *this;}
PIString & operator +=(const std::string & str) {appendFromChars(str.c_str(), str.length()); return *this;}
PIString & operator +=(const PIByteArray & ba) {appendFromChars((const char * )ba.data(), ba.size_s()); return *this;}
PIString & operator +=(const PIString & str);
#ifdef HAS_LOCALE
@@ -67,7 +66,7 @@ public:
PIString(const wchar_t * str): PIDeque<PIChar>() {/*reserve(256); */piMonitor.strings++; piMonitor.containers--; *this += str;}
//! Contructs string from std::string "str"
PIString(const string & str): PIDeque<PIChar>() {/*reserve(256); */piMonitor.strings++; piMonitor.containers--; *this += str;}
PIString(const std::string & str): PIDeque<PIChar>() {/*reserve(256); */piMonitor.strings++; piMonitor.containers--; *this += str;}
#ifdef HAS_LOCALE
PIString(const wstring & str): PIDeque<PIChar>() {/*reserve(256); */piMonitor.strings++; piMonitor.containers--; *this += str;}
@@ -81,7 +80,7 @@ public:
/*! \brief Contructs string from "len" characters of buffer "str"
* \details Example: \snippet pistring.cpp PIString(char * , int) */
PIString(const char * str, const int len): PIDeque<PIChar>() {/*reserve(256); */piMonitor.strings++; piMonitor.containers--; *this += string(str, len);}
PIString(const char * str, const int len): PIDeque<PIChar>() {/*reserve(256); */piMonitor.strings++; piMonitor.containers--; *this += std::string(str, len);}
/*! \brief Contructs string as sequence of characters "c" of buffer with length "len"
* \details Example: \snippet pistring.cpp PIString(int, char) */
@@ -123,7 +122,7 @@ public:
operator const char*() {return data();}
//! Return std::string representation of string
operator const string() {if (size() == 0) return string(); string s; for (int i = 0; i < length(); ++i) s.push_back(at(i).toAscii()); return s;}
operator const std::string() {if (size() == 0) return std::string(); std::string s; for (int i = 0; i < length(); ++i) s.push_back(at(i).toAscii()); return s;}
//! Return symbol at index "pos"
PIChar operator [](const int pos) const {return at(pos);}
@@ -142,7 +141,7 @@ public:
bool operator ==(const char * str) const {return *this == PIString(str);}
//! Compare operator
bool operator ==(const string & str) const {return *this == PIString(str);}
bool operator ==(const std::string & str) const {return *this == PIString(str);}
//! Compare operator
@@ -156,7 +155,7 @@ public:
bool operator !=(const char * str) const {return *this != PIString(str);}
//! Compare operator
bool operator !=(const string & str) const {return *this != PIString(str);}
bool operator !=(const std::string & str) const {return *this != PIString(str);}
//! Compare operator
@@ -170,7 +169,7 @@ public:
bool operator <(const char * str) const {return *this < PIString(str);}
//! Compare operator
bool operator <(const string & str) const {return *this < PIString(str);}
bool operator <(const std::string & str) const {return *this < PIString(str);}
//! Compare operator
@@ -184,7 +183,7 @@ public:
bool operator >(const char * str) const {return *this > PIString(str);}
//! Compare operator
bool operator >(const string & str) const {return *this > PIString(str);}
bool operator >(const std::string & str) const {return *this > PIString(str);}
//! Compare operator
@@ -198,7 +197,7 @@ public:
bool operator <=(const char * str) const {return *this <= PIString(str);}
//! Compare operator
bool operator <=(const string & str) const {return *this <= PIString(str);}
bool operator <=(const std::string & str) const {return *this <= PIString(str);}
//! Compare operator
@@ -212,7 +211,7 @@ public:
bool operator >=(const char * str) const {return *this >= PIString(str);}
//! Compare operator
bool operator >=(const string & str) const {return *this >= PIString(str);}
bool operator >=(const std::string & str) const {return *this >= PIString(str);}
operator bool() const {return toBool();}
@@ -246,7 +245,7 @@ public:
PIString & operator <<(const wchar_t * str) {*this += str; return *this;}
//! Append std::string "str" at the end of string
PIString & operator <<(const string & str) {*this += str; return *this;}
PIString & operator <<(const std::string & str) {*this += str; return *this;}
/*! \brief Append string representation of "num" at the end of string
* \details Example: \snippet pistring.cpp PIString::<<(int) */
@@ -469,6 +468,7 @@ public:
//! \brief Return \c std::string representation of this string
std::string stdString() const {return convertToStd();}
#ifdef HAS_LOCALE
wstring stdWString() const {return convertToWString();}
#endif
@@ -486,11 +486,15 @@ public:
//! \brief Convert each symbol in copyed string to lower case and return it
PIString toLowerCase() const;
PIString toNativeDecimalPoints() const {
#ifdef HAS_LOCALE
PIString toNativeDecimalPoints() const {PIString s(*this); if (currentLocale == 0) return s; return s.replaceAll(".", currentLocale->decimal_point).replaceAll(",", currentLocale->decimal_point);}
PIString s(*this); if (currentLocale == 0) return s; return s.replaceAll(".", currentLocale->decimal_point).replaceAll(",", currentLocale->decimal_point);
#else
PIString toNativeDecimalPoints() const {return PIString(*this).replaceAll(",", ".");}
return PIString(*this).replaceAll(",", ".");
#endif
}
//! \brief Search substring "str" from symbol at index "start" and return first occur position
@@ -505,10 +509,6 @@ public:
//! \details Example: \snippet pistring.cpp PIString::find
int find(const char * str, const int start = 0) const {return find(PIString(str), start);}
//! \brief Search substring "str" from symbol at index "start" and return first occur position
//! \details Example: \snippet pistring.cpp PIString::find
int find(const string str, const int start = 0) const {return find(PIString(str), start);}
//! \brief Search substring "str" from symbol at index "start" and return last occur position
//! \details Example: \snippet pistring.cpp PIString::findLast
int findLast(const char str, const int start = 0) const;
@@ -521,10 +521,6 @@ public:
//! \details Example: \snippet pistring.cpp PIString::findLast
int findLast(const char * str, const int start = 0) const {return findLast(PIString(str), start);}
//! \brief Search substring "str" from symbol at index "start" and return last occur position
//! \details Example: \snippet pistring.cpp PIString::findLast
int findLast(const string str, const int start = 0) const {return findLast(PIString(str), start);}
//! \brief Search word "word" from symbol at index "start" and return first occur position.
//! \details Example: \snippet pistring.cpp PIString::findWord
int findWord(const PIString & word, const int start = 0) const;
@@ -632,15 +628,15 @@ public:
//! \brief Set string content to numeric representation of "value"
//! \details Example: \snippet pistring.cpp PIString::setFloat
PIString & setNumber(const float value) {clear(); *this += ftos(value); return *this;}
PIString & setNumber(const float value) {clear(); *this += PIString::fromNumber(value); return *this;}
//! \brief Set string content to numeric representation of "value"
//! \details Example: \snippet pistring.cpp PIString::setFloat
PIString & setNumber(const double & value) {clear(); *this += dtos(value); return *this;}
PIString & setNumber(const double & value) {clear(); *this += PIString::fromNumber(value); return *this;}
//! \brief Set string content to numeric representation of "value"
//! \details Example: \snippet pistring.cpp PIString::setFloat
PIString & setNumber(const ldouble & value) {clear(); *this += dtos(value); return *this;}
PIString & setNumber(const ldouble & value) {clear(); *this += PIString::fromNumber(value); return *this;}
//! \brief Set string content to human readable size in B/kB/MB/GB/TB
//! \details Example: \snippet pistring.cpp PIString::setReadableSize
@@ -682,15 +678,15 @@ public:
//! \brief Return string contains numeric representation of "value"
//! \details Example: \snippet pistring.cpp PIString::fromFloat
static PIString fromNumber(const float value) {return PIString(ftos(value));}
static PIString fromNumber(const float value) {return ftos(value);}
//! \brief Return string contains numeric representation of "value"
//! \details Example: \snippet pistring.cpp PIString::fromFloat
static PIString fromNumber(const double & value) {return PIString(dtos(value));}
static PIString fromNumber(const double & value) {return ftos(value);}
//! \brief Return string contains numeric representation of "value"
//! \details Example: \snippet pistring.cpp PIString::fromFloat
static PIString fromNumber(const ldouble & value) {return PIString(dtos(value));}
static PIString fromNumber(const ldouble & value) {return ftos(value);}
//! \brief Return "true" or "false"
static PIString fromBool(const bool value) {return PIString(value ? "true" : "false");}
@@ -706,6 +702,12 @@ private:
static const char toBaseN[];
static const int fromBaseN[];
static PIString itos(const int num);
static PIString ltos(const long num);
static PIString uitos(const uint num);
static PIString ultos(const ulong num);
static PIString ftos(const float num);
static PIString dtos(const double num);
static PIString fromNumberBaseS(const llong value, int base = 10, bool * ok = 0) {
if (value == 0) return PIString("0");
if (base < 2 || base > 40) {if (ok != 0) *ok = false; return PIString();}
@@ -777,7 +779,7 @@ private:
return ret;
}
void appendFromChars(const char * c, int s);
string convertToStd() const;
std::string convertToStd() const;
#ifdef HAS_LOCALE
wstring convertToWString() const {wstring s; for (int i = 0; i < length(); ++i) s.push_back(at(i).toWChar()); return s;}
#endif
@@ -793,7 +795,7 @@ private:
inline std::ostream & operator <<(std::ostream & s, const PIString & v) {for (int i = 0; i < v.length(); ++i) s << v[i]; return s;}
//! \relatesalso PIString \brief Input operator from std::istream (cin)
inline std::istream & operator >>(std::istream & s, PIString & v) {string ss; s >> ss; v << PIString(ss); return s;}
inline std::istream & operator >>(std::istream & s, PIString & v) {std::string ss; s >> ss; v << PIString(ss); return s;}
//! \relatesalso PIString \relatesalso PICout \brief Output operator to PICout
inline PICout operator <<(PICout s, const PIString & v) {s.space(); s.quote(); s.setControl(0, true); for (int i = 0; i < v.length(); ++i) s << v[i]; s.restoreControl(); s.quote(); return s;}
@@ -815,7 +817,7 @@ inline PIString operator +(const PIString & str, const PIString & f) {PIString s
inline PIString operator +(const PIString & f, const char * str) {PIString s(f); s += str; return s;}
//! \relatesalso PIString \brief Return concatenated string
inline PIString operator +(const PIString & f, const string & str) {PIString s(f); s += str; return s;}
inline PIString operator +(const PIString & f, const std::string & str) {PIString s(f); s += str; return s;}
//inline PIString operator +(const char c, const PIString & f) {return PIString(c) + f;}
@@ -823,7 +825,7 @@ inline PIString operator +(const PIString & f, const string & str) {PIString s(f
inline PIString operator +(const char * str, const PIString & f) {return PIString(str) + f;}
//! \relatesalso PIString \brief Return concatenated string
inline PIString operator +(const string & str, const PIString & f) {return PIString(str) + f;}
inline PIString operator +(const std::string & str, const PIString & f) {return PIString(str) + f;}
inline char chrUpr(char c);
inline char chrLwr(char c);
@@ -890,7 +892,7 @@ public:
PIStringList & operator <<(const PIStringList & sl) {piForeachC (PIString & i, sl) push_back(i); return *this;}
//inline PIStringList & operator <<(const char c) {push_back(PIString(c)); return *this;}
PIStringList & operator <<(const char * str) {push_back(PIString(str)); return *this;}
PIStringList & operator <<(const string & str) {push_back(str); return *this;}
PIStringList & operator <<(const std::string & str) {push_back(str); return *this;}
PIStringList & operator <<(const int & num) {push_back(PIString::fromNumber(num)); return *this;}
PIStringList & operator <<(const short & num) {push_back(PIString::fromNumber(num)); return *this;}
PIStringList & operator <<(const long & num) {push_back(PIString::fromNumber(num)); return *this;}

View File

@@ -1,7 +1,7 @@
/*
PIP - Platform Independent Primitives
Timer
Copyright (C) 2014 Ivan Pelipenko peri4ko@gmail.com
Copyright (C) 2015 Ivan Pelipenko peri4ko@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -19,6 +19,17 @@
#include "pitime.h"
#include "pisystemtests.h"
#ifdef WINDOWS
extern FILETIME __pi_ftjan1970;
long long __PIQueryPerformanceCounter() {LARGE_INTEGER li; QueryPerformanceCounter(&li); return li.QuadPart;}
#endif
#ifdef MAC_OS
//# include <mach/mach_traps.h>
//# include <mach/mach.h>
# include <mach/clock.h>
//# include <crt_externs.h>
extern clock_serv_t __pi_mac_clock;
#endif
/*! \class PISystemTime

View File

@@ -4,7 +4,7 @@
/*
PIP - Platform Independent Primitives
Time structs
Copyright (C) 2014 Ivan Pelipenko peri4ko@gmail.com
Copyright (C) 2015 Ivan Pelipenko peri4ko@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -24,7 +24,6 @@
#define PITIME_H
#include <ctime>
#include <csignal>
#include "pistring.h"
#ifdef DOXYGEN

View File

@@ -1,7 +1,7 @@
/*
PIP - Platform Independent Primitives
Variant type
Copyright (C) 2014 Ivan Pelipenko peri4ko@gmail.com
Copyright (C) 2015 Ivan Pelipenko peri4ko@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

View File

@@ -6,7 +6,7 @@
/*
PIP - Platform Independent Primitives
Variant type
Copyright (C) 2014 Ivan Pelipenko peri4ko@gmail.com
Copyright (C) 2015 Ivan Pelipenko peri4ko@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -28,7 +28,7 @@
#include "pistring.h"
#include "pibitarray.h"
#include "pitime.h"
#include "pimath.h"
#include "pimathbase.h"
#define __PIVARIANT_UNION_SIZE__ 32

View File

@@ -1,7 +1,7 @@
/*
PIP - Platform Independent Primitives
Class for write binary data to logfile, and read or playback this data
Copyright (C) 2014 Andrey Bychkov work.a.b@yandex.ru
Copyright (C) 2015 Andrey Bychkov work.a.b@yandex.ru
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

View File

@@ -4,7 +4,7 @@
/*
PIP - Platform Independent Primitives
Class for write binary data to logfile, and read or playback this data
Copyright (C) 2014 Andrey Bychkov work.a.b@yandex.ru
Copyright (C) 2015 Andrey Bychkov work.a.b@yandex.ru
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

View File

@@ -1,7 +1,7 @@
/*
PIP - Platform Independent Primitives
Config parser
Copyright (C) 2014 Ivan Pelipenko peri4ko@gmail.com
Copyright (C) 2015 Ivan Pelipenko peri4ko@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

View File

@@ -4,7 +4,7 @@
/*
PIP - Platform Independent Primitives
Configuration parser and writer
Copyright (C) 2014 Ivan Pelipenko peri4ko@gmail.com
Copyright (C) 2015 Ivan Pelipenko peri4ko@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -29,28 +29,28 @@
Entry & getValue(const PIString & vname, const char * def, bool * exists = 0) {return getValue(vname, PIString(def), exists);} \
Entry & getValue(const PIString & vname, const PIStringList & def, bool * exists = 0) {return getValue(vname, def.join("%|%"), exists);} \
Entry & getValue(const PIString & vname, const bool def, bool * exists = 0) {return getValue(vname, PIString::fromBool(def), exists);} \
Entry & getValue(const PIString & vname, const short def, bool * exists = 0) {return getValue(vname, itos(def), exists);} \
Entry & getValue(const PIString & vname, const int def, bool * exists = 0) {return getValue(vname, itos(def), exists);} \
Entry & getValue(const PIString & vname, const long def, bool * exists = 0) {return getValue(vname, ltos(def), exists);} \
Entry & getValue(const PIString & vname, const uchar def, bool * exists = 0) {return getValue(vname, uitos(def), exists);} \
Entry & getValue(const PIString & vname, const ushort def, bool * exists = 0) {return getValue(vname, uitos(def), exists);} \
Entry & getValue(const PIString & vname, const uint def, bool * exists = 0) {return getValue(vname, uitos(def), exists);} \
Entry & getValue(const PIString & vname, const ulong def, bool * exists = 0) {return getValue(vname, ultos(def), exists);} \
Entry & getValue(const PIString & vname, const float def, bool * exists = 0) {return getValue(vname, ftos(def), exists);} \
Entry & getValue(const PIString & vname, const double def, bool * exists = 0) {return getValue(vname, dtos(def), exists);} \
Entry & getValue(const PIString & vname, const short def, bool * exists = 0) {return getValue(vname, PIString::fromNumber(def), exists);} \
Entry & getValue(const PIString & vname, const int def, bool * exists = 0) {return getValue(vname, PIString::fromNumber(def), exists);} \
Entry & getValue(const PIString & vname, const long def, bool * exists = 0) {return getValue(vname, PIString::fromNumber(def), exists);} \
Entry & getValue(const PIString & vname, const uchar def, bool * exists = 0) {return getValue(vname, PIString::fromNumber(def), exists);} \
Entry & getValue(const PIString & vname, const ushort def, bool * exists = 0) {return getValue(vname, PIString::fromNumber(def), exists);} \
Entry & getValue(const PIString & vname, const uint def, bool * exists = 0) {return getValue(vname, PIString::fromNumber(def), exists);} \
Entry & getValue(const PIString & vname, const ulong def, bool * exists = 0) {return getValue(vname, PIString::fromNumber(def), exists);} \
Entry & getValue(const PIString & vname, const float def, bool * exists = 0) {return getValue(vname, PIString::fromNumber(def), exists);} \
Entry & getValue(const PIString & vname, const double def, bool * exists = 0) {return getValue(vname, PIString::fromNumber(def), exists);} \
\
Entry & getValue(const PIString & vname, const char * def, bool * exists = 0) const {return getValue(vname, PIString(def), exists);} \
Entry & getValue(const PIString & vname, const PIStringList & def, bool * exists = 0) const {return getValue(vname, def.join("%|%"), exists);} \
Entry & getValue(const PIString & vname, const bool def, bool * exists = 0) const {return getValue(vname, PIString::fromBool(def), exists);} \
Entry & getValue(const PIString & vname, const short def, bool * exists = 0) const {return getValue(vname, itos(def), exists);} \
Entry & getValue(const PIString & vname, const int def, bool * exists = 0) const {return getValue(vname, itos(def), exists);} \
Entry & getValue(const PIString & vname, const long def, bool * exists = 0) const {return getValue(vname, ltos(def), exists);} \
Entry & getValue(const PIString & vname, const uchar def, bool * exists = 0) const {return getValue(vname, uitos(def), exists);} \
Entry & getValue(const PIString & vname, const ushort def, bool * exists = 0) const {return getValue(vname, uitos(def), exists);} \
Entry & getValue(const PIString & vname, const uint def, bool * exists = 0) const {return getValue(vname, uitos(def), exists);} \
Entry & getValue(const PIString & vname, const ulong def, bool * exists = 0) const {return getValue(vname, ultos(def), exists);} \
Entry & getValue(const PIString & vname, const float def, bool * exists = 0) const {return getValue(vname, ftos(def), exists);} \
Entry & getValue(const PIString & vname, const double def, bool * exists = 0) const {return getValue(vname, dtos(def), exists);}
Entry & getValue(const PIString & vname, const short def, bool * exists = 0) const {return getValue(vname, PIString::fromNumber(def), exists);} \
Entry & getValue(const PIString & vname, const int def, bool * exists = 0) const {return getValue(vname, PIString::fromNumber(def), exists);} \
Entry & getValue(const PIString & vname, const long def, bool * exists = 0) const {return getValue(vname, PIString::fromNumber(def), exists);} \
Entry & getValue(const PIString & vname, const uchar def, bool * exists = 0) const {return getValue(vname, PIString::fromNumber(def), exists);} \
Entry & getValue(const PIString & vname, const ushort def, bool * exists = 0) const {return getValue(vname, PIString::fromNumber(def), exists);} \
Entry & getValue(const PIString & vname, const uint def, bool * exists = 0) const {return getValue(vname, PIString::fromNumber(def), exists);} \
Entry & getValue(const PIString & vname, const ulong def, bool * exists = 0) const {return getValue(vname, PIString::fromNumber(def), exists);} \
Entry & getValue(const PIString & vname, const float def, bool * exists = 0) const {return getValue(vname, PIString::fromNumber(def), exists);} \
Entry & getValue(const PIString & vname, const double def, bool * exists = 0) const {return getValue(vname, PIString::fromNumber(def), exists);}
class PIP_EXPORT PIConfig
{
@@ -170,37 +170,37 @@ public:
Entry & setValue(const char * value) {setValue(PIString(value)); setType("s"); return *this;}
//! Set value to "value" and returns this. Type is set to "b"
Entry & setValue(const bool value) {setValue(btos(value)); setType("b"); return *this;}
Entry & setValue(const bool value) {setValue(PIString::fromBool(value)); setType("b"); return *this;}
//! Set value to "value" and returns this. Type is set to "s"
Entry & setValue(const char value) {setValue(PIString(1, value)); setType("s"); return *this;}
//! Set value to "value" and returns this. Type is set to "n"
Entry & setValue(const short value) {setValue(itos(value)); setType("n"); return *this;}
Entry & setValue(const short value) {setValue(PIString::fromNumber(value)); setType("n"); return *this;}
//! Set value to "value" and returns this. Type is set to "n"
Entry & setValue(const int value) {setValue(itos(value)); setType("n"); return *this;}
Entry & setValue(const int value) {setValue(PIString::fromNumber(value)); setType("n"); return *this;}
//! Set value to "value" and returns this. Type is set to "n"
Entry & setValue(const long value) {setValue(ltos(value)); setType("n"); return *this;}
Entry & setValue(const long value) {setValue(PIString::fromNumber(value)); setType("n"); return *this;}
//! Set value to "value" and returns this. Type is set to "n"
Entry & setValue(const uchar value) {setValue(uitos(value)); setType("n"); return *this;}
Entry & setValue(const uchar value) {setValue(PIString::fromNumber(value)); setType("n"); return *this;}
//! Set value to "value" and returns this. Type is set to "n"
Entry & setValue(const ushort value) {setValue(uitos(value)); setType("n"); return *this;}
Entry & setValue(const ushort value) {setValue(PIString::fromNumber(value)); setType("n"); return *this;}
//! Set value to "value" and returns this. Type is set to "n"
Entry & setValue(const uint value) {setValue(uitos(value)); setType("n"); return *this;}
Entry & setValue(const uint value) {setValue(PIString::fromNumber(value)); setType("n"); return *this;}
//! Set value to "value" and returns this. Type is set to "n"
Entry & setValue(const ulong value) {setValue(ultos(value)); setType("n"); return *this;}
Entry & setValue(const ulong value) {setValue(PIString::fromNumber(value)); setType("n"); return *this;}
//! Set value to "value" and returns this. Type is set to "f"
Entry & setValue(const float value) {setValue(ftos(value)); setType("f"); return *this;}
Entry & setValue(const float value) {setValue(PIString::fromNumber(value)); setType("f"); return *this;}
//! Set value to "value" and returns this. Type is set to "f"
Entry & setValue(const double value) {setValue(dtos(value)); setType("f"); return *this;}
Entry & setValue(const double value) {setValue(PIString::fromNumber(value)); setType("f"); return *this;}
/** \brief Returns entry with name "vname" and default value "def"
@@ -303,8 +303,8 @@ public:
bool entryExists(const Entry * e, const PIString & name) const;
void buildLine() {_all = _tab + _full_name + " = " + _value + " #" + _type + " " + _comment;}
void clear() {_children.clear(); _name = _value = _type = _comment = _all = PIString(); _line = 0; _parent = 0;}
void coutt(std::ostream & s, const PIString & p) const {PIString nl = p + " "; if (!_value.isEmpty()) s << p << _name << " = " << _value << endl; else cout << p << _name << endl; piForeachC (Entry * i, _children) i->coutt(s, nl);}
void piCoutt(PICout s, const PIString & p) const {PIString nl = p + " "; if (!_value.isEmpty()) s << p << _name << " = " << _value << NewLine; else cout << p << _name << endl; piForeachC (Entry * i, _children) i->piCoutt(s, nl);}
void coutt(std::ostream & s, const PIString & p) const {PIString nl = p + " "; if (!_value.isEmpty()) s << p << _name << " = " << _value << std::endl; else std::cout << p << _name << std::endl; piForeachC (Entry * i, _children) i->coutt(s, nl);}
void piCoutt(PICout s, const PIString & p) const {PIString nl = p + " "; if (!_value.isEmpty()) s << p << _name << " = " << _value << PICoutManipulators::NewLine; else std::cout << p << _name << std::endl; piForeachC (Entry * i, _children) i->piCoutt(s, nl);}
void deleteBranch() {piForeach (Entry * i, _children) {i->deleteBranch(); delete i;}}
static Entry _empty;
@@ -390,34 +390,34 @@ public:
void setValue(const PIString & name, const char * value, bool write = true) {setValue(name, PIString(value), "s", write);}
//! Set top-level entry with name "name" value to "value", type to "b" and if "write" immediate write to file. Add new entry if there is no suitable exists
void setValue(const PIString & name, const bool value, bool write = true) {setValue(name, btos(value), "b", write);}
void setValue(const PIString & name, const bool value, bool write = true) {setValue(name, PIString::fromBool(value), "b", write);}
//! Set top-level entry with name "name" value to "value", type to "n" and if "write" immediate write to file. Add new entry if there is no suitable exists
void setValue(const PIString & name, const short value, bool write = true) {setValue(name, itos(value), "n", write);}
void setValue(const PIString & name, const short value, bool write = true) {setValue(name, PIString::fromNumber(value), "n", write);}
//! Set top-level entry with name "name" value to "value", type to "n" and if "write" immediate write to file. Add new entry if there is no suitable exists
void setValue(const PIString & name, const int value, bool write = true) {setValue(name, itos(value), "n", write);}
void setValue(const PIString & name, const int value, bool write = true) {setValue(name, PIString::fromNumber(value), "n", write);}
//! Set top-level entry with name "name" value to "value", type to "n" and if "write" immediate write to file. Add new entry if there is no suitable exists
void setValue(const PIString & name, const long value, bool write = true) {setValue(name, ltos(value), "n", write);}
void setValue(const PIString & name, const long value, bool write = true) {setValue(name, PIString::fromNumber(value), "n", write);}
//! Set top-level entry with name "name" value to "value", type to "n" and if "write" immediate write to file. Add new entry if there is no suitable exists
void setValue(const PIString & name, const uchar value, bool write = true) {setValue(name, uitos(value), "n", write);}
void setValue(const PIString & name, const uchar value, bool write = true) {setValue(name, PIString::fromNumber(value), "n", write);}
//! Set top-level entry with name "name" value to "value", type to "n" and if "write" immediate write to file. Add new entry if there is no suitable exists
void setValue(const PIString & name, const ushort value, bool write = true) {setValue(name, uitos(value), "n", write);}
void setValue(const PIString & name, const ushort value, bool write = true) {setValue(name, PIString::fromNumber(value), "n", write);}
//! Set top-level entry with name "name" value to "value", type to "n" and if "write" immediate write to file. Add new entry if there is no suitable exists
void setValue(const PIString & name, const uint value, bool write = true) {setValue(name, uitos(value), "n", write);}
void setValue(const PIString & name, const uint value, bool write = true) {setValue(name, PIString::fromNumber(value), "n", write);}
//! Set top-level entry with name "name" value to "value", type to "n" and if "write" immediate write to file. Add new entry if there is no suitable exists
void setValue(const PIString & name, const ulong value, bool write = true) {setValue(name, ultos(value), "n", write);}
void setValue(const PIString & name, const ulong value, bool write = true) {setValue(name, PIString::fromNumber(value), "n", write);}
//! Set top-level entry with name "name" value to "value", type to "f" and if "write" immediate write to file. Add new entry if there is no suitable exists
void setValue(const PIString & name, const float value, bool write = true) {setValue(name, ftos(value), "f", write);}
void setValue(const PIString & name, const float value, bool write = true) {setValue(name, PIString::fromNumber(value), "f", write);}
//! Set top-level entry with name "name" value to "value", type to "f" and if "write" immediate write to file. Add new entry if there is no suitable exists
void setValue(const PIString & name, const double value, bool write = true) {setValue(name, dtos(value), "f", write);}
void setValue(const PIString & name, const double value, bool write = true) {setValue(name, PIString::fromNumber(value), "f", write);}
//! Returns root entry
Entry & rootEntry() {return root;}

View File

@@ -1,7 +1,7 @@
/*
PIP - Platform Independent Primitives
Complex I/O point
Copyright (C) 2014 Ivan Pelipenko peri4ko@gmail.com
Copyright (C) 2015 Ivan Pelipenko peri4ko@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

View File

@@ -4,7 +4,7 @@
/*
PIP - Platform Independent Primitives
Complex I/O point
Copyright (C) 2014 Ivan Pelipenko peri4ko@gmail.com
Copyright (C) 2015 Ivan Pelipenko peri4ko@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

View File

@@ -1,7 +1,7 @@
/*
PIP - Platform Independent Primitives
Speed and quality in/out diagnostics
Copyright (C) 2014 Ivan Pelipenko peri4ko@gmail.com
Copyright (C) 2015 Ivan Pelipenko peri4ko@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

View File

@@ -4,7 +4,7 @@
/*
PIP - Platform Independent Primitives
Speed and quality in/out diagnostics
Copyright (C) 2014 Ivan Pelipenko peri4ko@gmail.com, Bychkov Andrey wapmobil@gmail.com
Copyright (C) 2015 Ivan Pelipenko peri4ko@gmail.com, Bychkov Andrey wapmobil@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

View File

@@ -1,7 +1,7 @@
/*
PIP - Platform Independent Primitives
Directory
Copyright (C) 2014 Ivan Pelipenko peri4ko@gmail.com
Copyright (C) 2015 Ivan Pelipenko peri4ko@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -217,8 +217,13 @@ PIVector<PIFile::FileInfo> PIDir::entries() {
# else
const_cast<char*>(p.data()), 0
# endif
, 0, versionsort);
for (int i = 0; i < cnt; ++i) {
, 0,
# ifdef MAC_OS
alphasort);
# else
versionsort);
# endif
for (int i = 0; i < cnt; ++i) {
l << PIFile::fileInfo(dp + PIString(list[i]->d_name));
delete list[i];
}

View File

@@ -4,7 +4,7 @@
/*
PIP - Platform Independent Primitives
Directory
Copyright (C) 2014 Ivan Pelipenko peri4ko@gmail.com
Copyright (C) 2015 Ivan Pelipenko peri4ko@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

View File

@@ -1,7 +1,7 @@
/*
PIP - Platform Independent Primitives
Ethernet, UDP/TCP Broadcast/Multicast
Copyright (C) 2014 Ivan Pelipenko peri4ko@gmail.com
Copyright (C) 2015 Ivan Pelipenko peri4ko@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -19,16 +19,32 @@
#include "piethernet.h"
#include "piconfig.h"
#include "pisysteminfo.h"
#ifdef QNX
# include <net/if_dl.h>
# include <hw/nicinfo.h>
# include <sys/dcmd_io-net.h>
#endif
#ifdef WINDOWS
# include <io.h>
# include <winsock2.h>
# include <iphlpapi.h>
# include <psapi.h>
# include <ws2tcpip.h>
# define ip_mreqn ip_mreq
# define imr_address imr_interface
#else
# include <fcntl.h>
# include <sys/ioctl.h>
# include <netinet/in.h>
# include <arpa/inet.h>
# include <sys/socket.h>
# include <net/if.h>
# ifndef ANDROID
# include <ifaddrs.h>
# endif
#endif
#include <errno.h>
/** \class PIEthernet
@@ -51,9 +67,23 @@
*
* */
#ifndef WINDOWS
PIString getSockAddr(sockaddr * s) {
return s == 0 ? PIString() : PIString(inet_ntoa(((sockaddr_in*)s)->sin_addr));
}
#endif
REGISTER_DEVICE(PIEthernet);
PRIVATE_DEFINITION_START(PIEthernet)
sockaddr_in addr_;
sockaddr_in saddr_;
sockaddr_in raddr_;
PRIVATE_DEFINITION_END(PIEthernet)
PIEthernet::PIEthernet(): PIIODevice("", ReadWrite) {
construct();
setType(UDP);
@@ -140,11 +170,45 @@ bool PIEthernet::init() {
void PIEthernet::parseAddress(const PIString & ipp, PIString * ip, int * port) {
//piCout << "parse" << ipp;
if (ip != 0) *ip = ipp.left(ipp.find(":"));
if (port != 0) *port = ipp.right(ipp.length() - ipp.find(":") - 1).toInt();
}
PIString PIEthernet::macFromBytes(const PIByteArray & mac) {
PIString r;
for (int i = 0; i < mac.size_s(); ++i) {
r += PIString::fromNumber(mac[i], 16).expandLeftTo(2, '0');
if (i < mac.size_s() - 1) r += ":";
}
return r;
}
PIByteArray PIEthernet::macToBytes(const PIString & mac) {
PIByteArray r;
PIStringList sl = mac.split(":");
piForeachC (PIString & i, sl)
r << uchar(i.toInt(16));
return r;
}
PIString PIEthernet::applyMask(const PIString & ip, const PIString & mask) {
struct in_addr ia;
ia.s_addr = inet_addr(ip.data()) & inet_addr(mask.data());
return PIString(inet_ntoa(ia));
}
PIString PIEthernet::getBroadcast(const PIString & ip, const PIString & mask) {
struct in_addr ia;
ia.s_addr = inet_addr(ip.data()) | ~inet_addr(mask.data());
return PIString(inet_ntoa(ia));
}
bool PIEthernet::openDevice() {
if (connected_) return true;
init();
@@ -154,18 +218,18 @@ bool PIEthernet::openDevice() {
connecting_ = true;
if (type() != UDP || mode() == PIIODevice::WriteOnly)
return true;
memset(&addr_, 0, sizeof(addr_));
addr_.sin_family = AF_INET;
addr_.sin_port = htons(port_);
memset(&PRIVATE->addr_, 0, sizeof(PRIVATE->addr_));
PRIVATE->addr_.sin_family = AF_INET;
PRIVATE->addr_.sin_port = htons(port_);
PIFlags<Parameters> params = parameters();
if (params[PIEthernet::Broadcast]) addr_.sin_addr.s_addr = INADDR_ANY;
else addr_.sin_addr.s_addr = inet_addr(ip_.data());
if (params[PIEthernet::Broadcast]) PRIVATE->addr_.sin_addr.s_addr = INADDR_ANY;
else PRIVATE->addr_.sin_addr.s_addr = inet_addr(ip_.data());
#ifdef QNX
addr_.sin_len = sizeof(addr_);
PRIVATE->addr_.sin_len = sizeof(PRIVATE->addr_);
#endif
//piCout << "bind to" << (params[PIEthernet::Broadcast] ? "255.255.255.255" : ip_) << ":" << port_ << " ...";
int tries = 0;
while ((bind(sock, (sockaddr * )&addr_, sizeof(addr_)) == -1) && (tries < 10)) {
while ((bind(sock, (sockaddr * )&PRIVATE->addr_, sizeof(PRIVATE->addr_)) == -1) && (tries < 10)) {
init();
tries++;
}
@@ -328,16 +392,16 @@ bool PIEthernet::connect() {
connecting_ = true;
return true;
/*if (sock == -1) return false;
memset(&addr_, 0, sizeof(addr_));
memset(addr_, 0, sizeof(*addr_));
parseAddress(path_, &ip_, &port_);
addr_.sin_port = htons(port_);
addr_.sin_addr.s_addr = inet_addr(ip_.data());
addr_.sin_family = AF_INET;
PRIVATE->addr_.sin_port = htons(port_);
PRIVATE->addr_.sin_addr.s_addr = inet_addr(ip_.data());
PRIVATE->addr_.sin_family = AF_INET;
#ifdef QNX
addr_.sin_len = sizeof(addr_);
PRIVATE->addr_.sin_len = sizeof(*addr_);
#endif
//piCoutObj << "connect to " << ip << ":" << port_;
connected_ = (::connect(sock, (sockaddr * )&addr_, sizeof(addr_)) == 0);
connected_ = (::connect(sock, (sockaddr * )addr_, sizeof(*addr_)) == 0);
if (!connected_)
piCoutObj << "Can`t connect to " << ip_ << ":" << port_ << ", " << ethErrorString();
opened_ = connected_;
@@ -363,16 +427,16 @@ bool PIEthernet::listen(bool threaded) {
}
listen_threaded = server_bounded = false;
parseAddress(path(), &ip_, &port_);
memset(&addr_, 0, sizeof(addr_));
addr_.sin_port = htons(port_);
addr_.sin_addr.s_addr = inet_addr(ip_.data());
addr_.sin_family = AF_INET;
memset(&PRIVATE->addr_, 0, sizeof(PRIVATE->addr_));
PRIVATE->addr_.sin_port = htons(port_);
PRIVATE->addr_.sin_addr.s_addr = inet_addr(ip_.data());
PRIVATE->addr_.sin_family = AF_INET;
#ifdef QNX
addr_.sin_len = sizeof(addr_);
PRIVATE->addr_.sin_len = sizeof(*addr_);
#endif
opened_ = false;
int tries = 0;
while ((bind(sock, (sockaddr * )&addr_, sizeof(addr_)) == -1) && (tries < 10)) {
while ((bind(sock, (sockaddr * )&PRIVATE->addr_, sizeof(PRIVATE->addr_)) == -1) && (tries < 10)) {
init();
tries++;
}
@@ -413,16 +477,16 @@ int PIEthernet::read(void * read_to, int max_size) {
return rs;
case TCP_Client:
if (connecting_) {
memset(&addr_, 0, sizeof(addr_));
memset(&PRIVATE->addr_, 0, sizeof(PRIVATE->addr_));
parseAddress(path(), &ip_, &port_);
addr_.sin_port = htons(port_);
addr_.sin_addr.s_addr = inet_addr(ip_.data());
addr_.sin_family = AF_INET;
PRIVATE->addr_.sin_port = htons(port_);
PRIVATE->addr_.sin_addr.s_addr = inet_addr(ip_.data());
PRIVATE->addr_.sin_family = AF_INET;
#ifdef QNX
addr_.sin_len = sizeof(addr_);
PRIVATE->addr_.sin_len = sizeof(PRIVATE->addr_);
#endif
//piCoutObj << "connect to " << ip_ << ":" << port_ << "...";
connected_ = (::connect(sock, (sockaddr * )&addr_, sizeof(addr_)) == 0);
connected_ = (::connect(sock, (sockaddr * )&PRIVATE->addr_, sizeof(PRIVATE->addr_)) == 0);
//piCoutObj << "connect to " << ip_ << ":" << port_ << connected_;
if (!connected_)
piCoutObj << "Can`t connect to " << ip_ << ":" << port_ << ", " << ethErrorString();
@@ -459,12 +523,12 @@ int PIEthernet::read(void * read_to, int max_size) {
if (rs > 0) received(read_to, rs);
return rs;
case UDP:
memset(&raddr_, 0, sizeof(raddr_));
rs = ethRecvfrom(sock, read_to, max_size, 0, (sockaddr*)&raddr_);
memset(&PRIVATE->raddr_, 0, sizeof(PRIVATE->raddr_));
rs = ethRecvfrom(sock, read_to, max_size, 0, (sockaddr*)&PRIVATE->raddr_);
//piCout << "eth" << path() << "read return" << rs << errorString();
if (rs > 0) {
port_r = ntohs(raddr_.sin_port);
ip_r = inet_ntoa(raddr_.sin_addr);
port_r = ntohs(PRIVATE->raddr_.sin_port);
ip_r = inet_ntoa(PRIVATE->raddr_.sin_addr);
//piCout << "received from" << lastReadAddress();
received(read_to, rs);
}
@@ -487,15 +551,15 @@ int PIEthernet::write(const void * data, int max_size) {
int ret = 0;
switch (type()) {
case TCP_SingleTCP:
memset(&addr_, 0, sizeof(addr_));
addr_.sin_port = htons(port_s);
addr_.sin_addr.s_addr = inet_addr(ip_s.data());
addr_.sin_family = AF_INET;
memset(&PRIVATE->addr_, 0, sizeof(PRIVATE->addr_));
PRIVATE->addr_.sin_port = htons(port_s);
PRIVATE->addr_.sin_addr.s_addr = inet_addr(ip_s.data());
PRIVATE->addr_.sin_family = AF_INET;
#ifdef QNX
addr_.sin_len = sizeof(addr_);
PRIVATE->addr_.sin_len = sizeof(*addr_);
#endif
//piCoutObj << "connect SingleTCP" << ip_s << ":" << port_s << "...";
if (::connect(sock, (sockaddr * )&addr_, sizeof(addr_)) != 0) {
if (::connect(sock, (sockaddr * )&PRIVATE->addr_, sizeof(PRIVATE->addr_)) != 0) {
//piCoutObj << "Can`t connect to " << ip_s << ":" << port_s << ", " << ethErrorString();
msleep(1);
return -1;
@@ -507,25 +571,25 @@ int PIEthernet::write(const void * data, int max_size) {
init();
return ret;
case UDP:
saddr_.sin_port = htons(port_s);
/*if (params[PIEthernet::Broadcast]) saddr_.sin_addr.s_addr = INADDR_BROADCAST;
else*/ saddr_.sin_addr.s_addr = inet_addr(ip_s.data());
saddr_.sin_family = AF_INET;
PRIVATE->saddr_.sin_port = htons(port_s);
/*if (params[PIEthernet::Broadcast]) PRIVATE->saddr_.sin_addr.s_addr = INADDR_BROADCAST;
else*/ PRIVATE->saddr_.sin_addr.s_addr = inet_addr(ip_s.data());
PRIVATE->saddr_.sin_family = AF_INET;
//piCout << "[PIEth] write to" << ip_s << ":" << port_s << "socket" << sock_s << max_size << "bytes ...";
return ethSendto(sock_s, data, max_size, 0, (sockaddr * )&saddr_, sizeof(saddr_));
return ethSendto(sock_s, data, max_size, 0, (sockaddr * )&PRIVATE->saddr_, sizeof(PRIVATE->saddr_));
//piCout << "[PIEth] write to" << ip_s << ":" << port_s << "ok";
case TCP_Client:
if (connecting_) {
memset(&addr_, 0, sizeof(addr_));
memset(&PRIVATE->addr_, 0, sizeof(PRIVATE->addr_));
parseAddress(path(), &ip_, &port_);
addr_.sin_port = htons(port_);
addr_.sin_addr.s_addr = inet_addr(ip_.data());
addr_.sin_family = AF_INET;
PRIVATE->addr_.sin_port = htons(port_);
PRIVATE->addr_.sin_addr.s_addr = inet_addr(ip_.data());
PRIVATE->addr_.sin_family = AF_INET;
#ifdef QNX
addr_.sin_len = sizeof(addr_);
PRIVATE->addr_.sin_len = sizeof(*addr_);
#endif
//piCoutObj << "connect to " << ip << ":" << port_;
connected_ = (::connect(sock, (sockaddr * )&addr_, sizeof(addr_)) == 0);
connected_ = (::connect(sock, (sockaddr * )&PRIVATE->addr_, sizeof(PRIVATE->addr_)) == 0);
if (!connected_)
piCoutObj << "Can`t connect to " << ip_ << ":" << port_ << ", " << ethErrorString();
opened_ = connected_;
@@ -892,7 +956,6 @@ int PIEthernet::ethErrorCore() {
#else
return errno;
#endif
}

View File

@@ -4,7 +4,7 @@
/*
PIP - Platform Independent Primitives
Ethernet, UDP/TCP Broadcast/Multicast
Copyright (C) 2014 Ivan Pelipenko peri4ko@gmail.com
Copyright (C) 2015 Ivan Pelipenko peri4ko@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -25,7 +25,8 @@
#include "pitimer.h"
#include "piiodevice.h"
#include "piprocess.h"
class sockaddr;
class PIP_EXPORT PIEthernet: public PIIODevice
{
@@ -34,7 +35,7 @@ class PIP_EXPORT PIEthernet: public PIIODevice
public:
//! Contructs UDP %PIEthernet with empty read address
PIEthernet();
explicit PIEthernet();
//! \brief Type of %PIEthernet
enum PIP_EXPORT Type {
@@ -54,7 +55,7 @@ public:
};
//! Contructs %PIEthernet with type "type", read address "ip_port" and parameters "params"
PIEthernet(Type type, const PIString & ip_port = PIString(), const PIFlags<Parameters> params = 0);
explicit PIEthernet(Type type, const PIString & ip_port = PIString(), const PIFlags<Parameters> params = 0);
virtual ~PIEthernet();
@@ -324,10 +325,10 @@ public:
static PIStringList allAddresses();
static void parseAddress(const PIString & ipp, PIString * ip, int * port);
static PIString macFromBytes(const PIByteArray & mac) {PIString r; for (int i = 0; i < mac.size_s(); ++i) {r += PIString::fromNumber(mac[i], 16).expandLeftTo(2, '0'); if (i < mac.size_s() - 1) r += ":";} return r;}
static PIByteArray macToBytes(const PIString & mac) {PIByteArray r; PIStringList sl = mac.split(":"); piForeachC (PIString & i, sl) r << uchar(i.toInt(16)); return r;}
static PIString applyMask(const PIString & ip, const PIString & mask) {struct in_addr ia; ia.s_addr = inet_addr(ip.data()) & inet_addr(mask.data()); return PIString(inet_ntoa(ia));}
static PIString getBroadcast(const PIString & ip, const PIString & mask) {struct in_addr ia; ia.s_addr = inet_addr(ip.data()) | ~inet_addr(mask.data()); return PIString(inet_ntoa(ia));}
static PIString macFromBytes(const PIByteArray & mac);
static PIByteArray macToBytes(const PIString & mac);
static PIString applyMask(const PIString & ip, const PIString & mask);
static PIString getBroadcast(const PIString & ip, const PIString & mask);
//! \events
//! \{
@@ -369,7 +370,7 @@ public:
//! \}
protected:
PIEthernet(int sock, PIString ip_port);
explicit PIEthernet(int sock, PIString ip_port);
void propertyChanged(const PIString & name);
@@ -388,15 +389,11 @@ protected:
void applyTimeouts();
void applyTimeout(int fd, int opt, double ms);
void applyOptInt(int level, int opt, int val);
#ifndef WINDOWS
static PIString getSockAddr(sockaddr * s) {return s == 0 ? PIString() : PIString(inet_ntoa(((sockaddr_in*)s)->sin_addr));}
#endif
PRIVATE_DECLARATION
int sock, sock_s, wrote;
mutable int port_, port_s, port_c, port_r;
bool connected_, connecting_, listen_threaded, server_bounded;
sockaddr_in addr_, saddr_, raddr_;
mutable PIString ip_, ip_s, ip_c, ip_r;
PIThread server_thread_;
PIVector<PIEthernet * > clients_;

View File

@@ -1,7 +1,7 @@
/*
PIP - Platform Independent Primitives
File
Copyright (C) 2014 Ivan Pelipenko peri4ko@gmail.com
Copyright (C) 2015 Ivan Pelipenko peri4ko@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -32,6 +32,9 @@
# define S_IFBLK 0x08
# define S_IFCHR 0x10
# define S_IFSOCK 0x20
#else
# include <sys/stat.h>
# include <fcntl.h>
#endif
#define S_IFHDN 0x40
#ifdef QNX
@@ -294,10 +297,17 @@ PIFile::FileInfo PIFile::fileInfo(const PIString & path) {
_stat_call_(path.data(), &fs);
int mode = fs.st_mode;
ret.size = fs.st_size;
ret.id_user = fs.st_uid;
ret.id_user = fs.st_uid;
ret.id_group = fs.st_gid;
ret.time_access = PIDateTime::fromSystemTime(PISystemTime(fs.st_atim.tv_sec, fs.st_atim.tv_nsec));
ret.time_modification = PIDateTime::fromSystemTime(PISystemTime(fs.st_mtim.tv_sec, fs.st_mtim.tv_nsec));
#ifdef MAC_OS
# define ATIME st_atimespec
# define MTIME st_ctimespec
#else
# define ATIME st_atim
# define MTIME st_mtim
#endif
ret.time_access = PIDateTime::fromSystemTime(PISystemTime(fs.ATIME.tv_sec, fs.ATIME.tv_nsec));
ret.time_modification = PIDateTime::fromSystemTime(PISystemTime(fs.MTIME.tv_sec, fs.MTIME.tv_nsec));
ret.perm_user = FileInfo::Permissions((mode & S_IRUSR) == S_IRUSR, (mode & S_IWUSR) == S_IWUSR, (mode & S_IXUSR) == S_IXUSR);
ret.perm_group = FileInfo::Permissions((mode & S_IRGRP) == S_IRGRP, (mode & S_IWGRP) == S_IWGRP, (mode & S_IXGRP) == S_IXGRP);
ret.perm_other = FileInfo::Permissions((mode & S_IROTH) == S_IROTH, (mode & S_IWOTH) == S_IWOTH, (mode & S_IXOTH) == S_IXOTH);

View File

@@ -4,7 +4,7 @@
/*
PIP - Platform Independent Primitives
File
Copyright (C) 2014 Ivan Pelipenko peri4ko@gmail.com
Copyright (C) 2015 Ivan Pelipenko peri4ko@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -24,7 +24,7 @@
#define PIFILE_H
#include "piiodevice.h"
#include <cstdio>
class PIP_EXPORT PIFile: public PIIODevice
{
@@ -141,7 +141,7 @@ public:
int precision() const {return prec_;}
//! Set float numbers write precision to "prec_" digits
void setPrecision(int prec) {prec_ = prec; if (prec_ >= 0) prec_str = "." + itos(prec_); else prec_str = "";}
void setPrecision(int prec) {prec_ = prec; if (prec_ >= 0) prec_str = "." + PIString::fromNumber(prec_); else prec_str = "";}
//! Read from file to "read_to" no more than "max_size" and return readed bytes count
@@ -206,9 +206,9 @@ public:
//! Write to file text representation of "v"
PIFile & operator <<(ullong v) {if (canWrite() && fd != 0) ret = fprintf(fd, "%llu", v); return *this;}
//! Write to file text representation of "v" with precision \a precision()
PIFile & operator <<(float v) {if (canWrite() && fd != 0) ret = fprintf(fd, ("%" + prec_str + "f").c_str(), v); return *this;}
PIFile & operator <<(float v) {if (canWrite() && fd != 0) ret = fprintf(fd, ("%" + prec_str + "f").data(), v); return *this;}
//! Write to file text representation of "v" with precision \a precision()
PIFile & operator <<(double v) {if (canWrite() && fd != 0) ret = fprintf(fd, ("%" + prec_str + "lf").c_str(), v); return *this;}
PIFile & operator <<(double v) {if (canWrite() && fd != 0) ret = fprintf(fd, ("%" + prec_str + "lf").data(), v); return *this;}
//! Read from file text representation of "v"
@@ -292,7 +292,7 @@ private:
FILE * fd;
int ret, prec_;
string prec_str;
PIString prec_str;
};
@@ -301,7 +301,7 @@ inline PICout operator <<(PICout s, const PIFile::FileInfo & v) {
s << "FileInfo(\"" << v.path << "\", " << PIString::readableSize(v.size) << ", "
<< v.perm_user.toString() << " " << v.perm_group.toString() << " " << v.perm_other.toString() << ", "
<< v.time_access.toString() << ", " << v.time_modification.toString()
<< ", 0x" << Hex << v.flags << ")";
<< ", 0x" << PICoutManipulators::Hex << v.flags << ")";
s.restoreControl();
return s;
}

View File

@@ -8,7 +8,7 @@ PIFileTransfer::PIFileTransfer(): crc(standardCRC_16()) {
header.version = PIFILETRANSFER_VERSION;
header.session_id = 0;
dir = PIDir::current();
fileinfo_size = sizeof(EntryInfo) + sizeof(PIByteArray) + 100;
fileinfo_size = sizeof(EntryInfo) + sizeof(FilePart) + 100;
min_packet_size = sizeof(PacketHeader) + sizeof(uint) + fileinfo_size;
is_sending = is_receiving = false;
bytes_file_all = bytes_file_cur = bytes_total_all = bytes_total_cur = 0;
@@ -26,16 +26,33 @@ PIFileTransfer::~PIFileTransfer() {
bool PIFileTransfer::send(const PIString & file) {
return sendFiles(PIVector<PIFile::FileInfo>() << PIFile::fileInfo(file));
PIVector<PIFile::FileInfo> ce = dir.entries();
PIFile::FileInfo e;
e.path = "";
for (int i = 0; i < ce.size_s(); i++) {
if (ce[i].path == file) e = ce[i];
}
if (e.path != "") return sendFiles(PIVector<PIFile::FileInfo>() << e);
return false;
}
bool PIFileTransfer::send(PIVector<PIFile::FileInfo> entries) {
PIVector<PIFile::FileInfo> allEntries;
PIVector<PIFile::FileInfo> ce;
PISet<PIString> names;
for (int i = 0; i < entries.size_s(); i++) {
allEntries << entries[i];
ce.clear();
if (entries[i].isDir())
allEntries << PIDir::allEntries(dir.absolutePath() + dir.separator + entries[i].path);
ce = PIDir::allEntries(dir.absolutePath() + dir.separator + entries[i].path);
for (int k = 0; k < ce.size_s(); k++) ce[k].path = entries[i].path + dir.separator + ce[k].path;
ce.push_front(entries[i]);
for (int j = 0; j < ce.size_s(); j++) {
if (names.contains(ce[j].path)) continue;
allEntries << ce[j];
//piCout << ce[j].path;
names << ce[j].path;
}
}
return sendFiles(allEntries);
}
@@ -146,12 +163,6 @@ void PIFileTransfer::received(PIByteArray & ba) {
bool PIFileTransfer::sendFiles(PIVector<PIFile::FileInfo> files) {
PIStringList names;
for(int i=0; i<files.size_s(); i++) {
files[i].path = dir.relative(files[i].path);
if (names.contains(files[i].path)) {files.remove(i); i--;}
else names << files[i].path;
}
// piCoutObj << "prepare to send" << files.size() << "files";
break_ = false;
is_sending = true;
@@ -247,7 +258,7 @@ void PIFileTransfer::buildSession(PIVector<PIFile::FileInfo> files) {
fi.fstart = fs;
fi.fsize = piMinll(fi.entry.size - fs, max_packet_size - min_packet_size);
lfi << fi;
cur_size += fi.fsize + sizeof(PIByteArray);
cur_size += fi.fsize + sizeof(FilePart);
if (fi.part_index != fi.parts) {
session << lfi;
lfi.clear();

View File

@@ -16,6 +16,22 @@ public:
enum ReplyCode {Unknown = 0, Success, Invalid, Break};
enum PacketType {pt_Data = 1, pt_Reply, pt_SendRequest};//, pt_SendResult};
struct EntryInfo {
EntryInfo() {
fstart = fsize = 0;
parts = part_index = 0;
}
PIFile::FileInfo entry;
llong fstart;
llong fsize;
uint parts;
uint part_index;
};
struct FilePart {
uint index;
PIByteArray data;
};
struct PacketHeader {
union {
@@ -34,25 +50,6 @@ public:
}
// uint crc;
};
struct PartHeader {
uint id;
uint total_size;
uint part_start;
uint part_size;
};
struct EntryInfo {
EntryInfo() {
fstart = fsize = 0;
parts = part_index = 0;
}
PIFile::FileInfo entry;
llong fstart;
llong fsize;
uint parts;
uint part_index;
};
//bool send(const PIFile & file);
bool send(const PIString & file);
@@ -126,8 +123,6 @@ private:
inline PIByteArray & operator <<(PIByteArray & s, const PIFileTransfer::PacketHeader & v) {s << v.raw_sig << v.type << v.session_id << v.id; return s;}
inline PIByteArray & operator >>(PIByteArray & s, PIFileTransfer::PacketHeader & v) {s >> v.raw_sig >> v.type >> v.session_id >> v.id; return s;}
inline PIByteArray & operator <<(PIByteArray & s, const PIFileTransfer::PartHeader & v) {s << v.id << v.total_size << v.part_start << v.part_size; return s;}
inline PIByteArray & operator >>(PIByteArray & s, PIFileTransfer::PartHeader & v) {s >> v.id >> v.total_size >> v.part_start >> v.part_size; return s;}
inline PIByteArray & operator <<(PIByteArray & s, const PIFileTransfer::EntryInfo & v) {s << v.entry.path << v.entry.size << v.entry.time_modification << v.entry.time_access << int(v.entry.flags)
<< v.entry.id_user << v.entry.id_group << v.fstart; return s;}

View File

@@ -1,7 +1,7 @@
/*
PIP - Platform Independent Primitives
Abstract input/output device
Copyright (C) 2014 Ivan Pelipenko peri4ko@gmail.com
Copyright (C) 2015 Ivan Pelipenko peri4ko@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

View File

@@ -4,7 +4,7 @@
/*
PIP - Platform Independent Primitives
Abstract input/output device
Copyright (C) 2014 Ivan Pelipenko peri4ko@gmail.com
Copyright (C) 2015 Ivan Pelipenko peri4ko@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

View File

@@ -1,7 +1,7 @@
/*
PIP - Platform Independent Primitives
PIIODevice wrapper around PIString
Copyright (C) 2014 Ivan Pelipenko peri4ko@gmail.com
Copyright (C) 2015 Ivan Pelipenko peri4ko@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

View File

@@ -4,7 +4,7 @@
/*
PIP - Platform Independent Primitives
PIIODevice wrapper around PIString
Copyright (C) 2014 Ivan Pelipenko peri4ko@gmail.com
Copyright (C) 2015 Ivan Pelipenko peri4ko@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

View File

@@ -1,7 +1,7 @@
/*
PIP - Platform Independent Primitives
Multiprotocol
Copyright (C) 2014 Ivan Pelipenko peri4ko@gmail.com
Copyright (C) 2015 Ivan Pelipenko peri4ko@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

View File

@@ -1,7 +1,7 @@
/*
PIP - Platform Independent Primitives
Packets extractor
Copyright (C) 2014 Ivan Pelipenko peri4ko@gmail.com
Copyright (C) 2015 Ivan Pelipenko peri4ko@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

View File

@@ -4,7 +4,7 @@
/*
PIP - Platform Independent Primitives
Packets extractor
Copyright (C) 2014 Ivan Pelipenko peri4ko@gmail.com
Copyright (C) 2015 Ivan Pelipenko peri4ko@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

View File

@@ -1,7 +1,7 @@
/*
PIP - Platform Independent Primitives
Peer - named I/O ethernet node
Copyright (C) 2014 Ivan Pelipenko peri4ko@gmail.com
Copyright (C) 2015 Ivan Pelipenko peri4ko@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -133,7 +133,7 @@ void PIPeer::initMBcasts(PIStringList al) {
PIString nm;
al << _PIPEER_MULTICAST_IP;
piForeachC (PIString & a, al) {
piCout << "mcast try" << a;
//piCout << "mcast try" << a;
ce = new PIEthernet();
ce->setDebug(false);
ce->setName("__S__PIPeer_mcast_eth_" + a);
@@ -156,7 +156,7 @@ void PIPeer::initMBcasts(PIStringList al) {
ce->setSendAddress(PIEthernet::getBroadcast(a, nm), _PIPEER_BROADCAST_PORT);
ce->setReadAddress(a, _PIPEER_BROADCAST_PORT);
//piCout << "mc BC try" << a << nm << ce->sendIP();
piCout << "bcast try" << a << nm;
//piCout << "bcast try" << a << nm;
eths_bcast << ce;
CONNECTU(ce, threadedReadEvent, this, mbcastRead);
ce->startThreadedRead();
@@ -171,7 +171,7 @@ void PIPeer::initMBcasts(PIStringList al) {
eth_lo.setSendIP("127.0.0.1");
CONNECTU(&eth_lo, threadedReadEvent, this, mbcastRead);
eth_lo.startThreadedRead();
piCout << "lo binded to" << eth_lo.readAddress();
//piCout << "lo binded to" << eth_lo.readAddress();
//piCout << "add eth" << ta;
break;
}
@@ -335,55 +335,63 @@ bool PIPeer::mbcastRead(uchar * data, int size) {
ba >> type;
if (type <= 0 || type >= 4) return true;
PeerInfo pi;
const PeerInfo * rpi = 0;
PIVector<PeerInfo> rpeers;
ba >> pi.name;
//piCout << "read type" << type << "from" << pi.name;
if (pi.name == self_info.name) return true;
PIMutexLocker locker(mc_mutex);
diag_s.received(size);
const PeerInfo * rpi = 0;
bool ch = false;
PIVector<PeerInfo> rpeers;
//piCout << "analyz ...";
switch (type) {
case 1: // new peer
//piCout << "new peer packet ...";
if (hasPeer(pi.name)) break;
ba >> pi;
pi.sync = 0;
if (pi.dist == 0) {
pi.addNeighbour(self_info.name);
self_info.addNeighbour(pi.name);
peers_mutex.lock();
if (hasPeer(pi.name)) {
ba >> pi;
pi.sync = 0;
if (pi.dist == 0) {
pi.addNeighbour(self_info.name);
self_info.addNeighbour(pi.name);
}
peers << pi;
findNearestAddresses();
piCoutObj << "new peer \"" << pi.name << "\"" << " dist " << pi.dist;
pi.dist++;
sendSelfInfo();
sendPeerInfo(pi);
peerConnected(pi.name);
peerConnectedEvent(pi.name);
//piCout << "new peer packet ok";
}
peers << pi;
piCoutObj << "new peer \"" << pi.name << "\"" << " dist " << pi.dist;
pi.dist++;
sendSelfInfo();
sendPeerInfo(pi);
findNearestAddresses();
peerConnected(pi.name);
peerConnectedEvent(pi.name);
//piCout << "new peer packet ok";
peers_mutex.unlock();
break;
case 2: // remove peer
//piCout << "remove peer packet ..." << pi.name;
peers_mutex.lock();
rpi = getPeerByName(pi.name);
if (!rpi) break;
dist = rpi->dist;
addToRemoved(*rpi);
removePeer(pi.name);
piCoutObj << "remove peer \"" << pi.name << "\"";
if (dist == 0)
self_info.removeNeighbour(pi.name);
sendPeerRemove(pi.name);
findNearestAddresses();
peerDisconnected(pi.name);
peerDisconnectedEvent(pi.name);
//piCout << "remove peer packet ok";
if (rpi) {
dist = rpi->dist;
addToRemoved(*rpi);
removePeer(pi.name);
piCoutObj << "remove peer \"" << pi.name << "\"";
if (dist == 0)
self_info.removeNeighbour(pi.name);
sendPeerRemove(pi.name);
findNearestAddresses();
peerDisconnected(pi.name);
peerDisconnectedEvent(pi.name);
//piCout << "remove peer packet ok";
}
peers_mutex.unlock();
break;
case 3: // sync peers
//piCout << "sync packet ...";
ba >> pi >> rpeers;
rpeers << pi;
//piCoutObj << "rec sync " << rpeers.size_s() << " peers";
peers_mutex.lock();
piForeach (PeerInfo & rpeer, rpeers) {
//piCout << " to sync " << rpeer.name;
if (rpeer.name == self_info.name) continue;
@@ -416,12 +424,14 @@ bool PIPeer::mbcastRead(uchar * data, int size) {
if (exist || isRemoved(rpeer)) continue;
rpeer.dist++;
peers << rpeer;
findNearestAddresses();
ch = true;
peerConnected(rpeer.name);
peerConnectedEvent(rpeer.name);
}
//piCout << "***";
//piCout << self_info.name << self_info.neighbours;
if (ch)
findNearestAddresses();
piForeach (PeerInfo & i, peers) {
if (i.dist == 0) {
self_info.addNeighbour(i.name);
@@ -429,6 +439,7 @@ bool PIPeer::mbcastRead(uchar * data, int size) {
}
//piCout << i.name << i.neighbours;
}
peers_mutex.unlock();
//piCoutObj << "after sync " << peers.size_s() << " peers";
break;
}
@@ -514,6 +525,7 @@ void PIPeer::syncPeers() {
PIMutexLocker locker(eth_mutex);
PIString pn;
bool change = false;
peers_mutex.lock();
for (uint i = 0; i < peers.size(); ++i) {
PeerInfo & cp(peers[i]);
if (cp.sync > 3 && cp.dist == 0) {
@@ -539,6 +551,7 @@ void PIPeer::syncPeers() {
self_info.time = PISystemTime::current();
PIByteArray ba;
ba << int(3) << self_info.name << self_info << peers;
peers_mutex.unlock();
sendMBcast(ba);
}

View File

@@ -4,7 +4,7 @@
/*
PIP - Platform Independent Primitives
Peer - named I/O ethernet node, forming self-organized peering network
Copyright (C) 2014 Ivan Pelipenko peri4ko@gmail.com
Copyright (C) 2015 Ivan Pelipenko peri4ko@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -162,7 +162,7 @@ private:
PIVector<PIEthernet * > eths_traffic, eths_mcast, eths_bcast;
PIEthernet eth_send, eth_lo;
PITimer timer;
PIMutex mc_mutex, eth_mutex;
PIMutex mc_mutex, eth_mutex, peers_mutex;
PeerInfo self_info;
PIVector<PeerInfo> peers;

View File

@@ -1,7 +1,7 @@
/*
PIP - Platform Independent Primitives
Protocol, input/output channel (COM, UDP)
Copyright (C) 2014 Ivan Pelipenko peri4ko@gmail.com, Bychkov Andrey wapmobil@gmail.com
Copyright (C) 2015 Ivan Pelipenko peri4ko@gmail.com, Bychkov Andrey wapmobil@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

View File

@@ -4,7 +4,7 @@
/*
PIP - Platform Independent Primitives
Protocol, input/output channel (COM, UDP)
Copyright (C) 2014 Ivan Pelipenko peri4ko@gmail.com, Bychkov Andrey wapmobil@gmail.com
Copyright (C) 2015 Ivan Pelipenko peri4ko@gmail.com, Bychkov Andrey wapmobil@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -28,6 +28,7 @@
#include "pipacketextractor.h"
#include "pitimer.h"
#include "piconfig.h"
#include "pifile.h"
#include "math.h"
class PIProtocol;

View File

@@ -1,7 +1,7 @@
/*
PIP - Platform Independent Primitives
COM
Copyright (C) 2014 Ivan Pelipenko peri4ko@gmail.com, Bychkov Andrey wapmobil@gmail.com
Copyright (C) 2015 Ivan Pelipenko peri4ko@gmail.com, Bychkov Andrey wapmobil@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -20,6 +20,72 @@
#include "piserial.h"
#include "piconfig.h"
#include "pidir.h"
#include <errno.h>
#ifdef WINDOWS
# include <winreg.h>
# define TIOCM_LE 1
# define TIOCM_DTR 4
# define TIOCM_RTS 7
# define TIOCM_CTS 8
# define TIOCM_ST 3
# define TIOCM_SR 2
# define TIOCM_CAR 1
# define TIOCM_RNG 9
# define TIOCM_DSR 6
# define B50 50
# define B75 75
# define B110 110
# define B300 300
# define B600 600
# define B1200 1200
# define B2400 2400
# define B4800 4800
# define B9600 9600
# define B14400 14400
# define B19200 19200
# define B38400 38400
# define B57600 57600
# define B115200 115200
# define B128000 128000
# define B256000 256000
# define B1500000 1500000
# define B2000000 2000000
# define B2500000 2500000
# define B3000000 3000000
# define B3500000 3500000
# define B4000000 4000000
#else
# include <termios.h>
# include <fcntl.h>
# include <sys/ioctl.h>
# ifndef B50
# define B50 0000001
# endif
# ifndef B75
# define B75 0000002
# endif
# ifndef B1500000
# define B1500000 0010012
# endif
# ifndef B2000000
# define B2000000 0010013
# endif
# ifndef B2500000
# define B2500000 0010014
# endif
# ifndef B3000000
# define B3000000 0010015
# endif
# ifndef B3500000
# define B3500000 0010016
# endif
# ifndef B4000000
# define B4000000 0010017
# endif
#endif
#ifndef CRTSCTS
# define CRTSCTS 020000000000
#endif
/*! \class PISerial
@@ -35,6 +101,18 @@
REGISTER_DEVICE(PISerial);
PRIVATE_DEFINITION_START(PISerial)
#ifdef WINDOWS
DCB desc, sdesc;
void * hCom;
DWORD readed, mask;
#else
termios desc, sdesc;
uint readed;
#endif
PRIVATE_DEFINITION_END(PISerial)
PISerial::PISerial(): PIIODevice("", ReadWrite) {
_init();
}
@@ -54,15 +132,14 @@ PISerial::~PISerial() {
void PISerial::_init() {
#ifdef WINDOWS
PRIVATE->hCom = 0;
#endif
fd = -1;
piMonitor.serials++;
setPriority(piHigh);
block_read = true;
block_read = block_write = true;
vtime = 1;
#ifdef WINDOWS
block_write = true;
hCom = 0;
#endif
setParameters(0);
setSpeed(S115200);
setDataBitsCount(8);
@@ -122,6 +199,26 @@ bool PISerial::isPin(int number) const {
return false;
}
bool PISerial::setLE(bool on) {return setBit(TIOCM_LE, on, "LE");}
bool PISerial::setDTR(bool on) {return setBit(TIOCM_DTR, on, "DTR");}
bool PISerial::setRTS(bool on) {return setBit(TIOCM_RTS, on, "RTS");}
bool PISerial::setCTS(bool on) {return setBit(TIOCM_CTS, on, "CTS");}
bool PISerial::setST(bool on) {return setBit(TIOCM_ST, on, "ST");}
bool PISerial::setSR(bool on) {return setBit(TIOCM_SR, on, "SR");}
bool PISerial::setCAR(bool on) {return setBit(TIOCM_CAR, on, "CAR");}
bool PISerial::setRNG(bool on) {return setBit(TIOCM_RNG, on, "RNG");}
bool PISerial::setDSR(bool on) {return setBit(TIOCM_DSR, on, "DSR");}
bool PISerial::isLE() const {return isBit(TIOCM_LE, "LE");}
bool PISerial::isDTR() const {return isBit(TIOCM_DTR, "DTR");}
bool PISerial::isRTS() const {return isBit(TIOCM_RTS, "RTS");}
bool PISerial::isCTS() const {return isBit(TIOCM_CTS, "CTS");}
bool PISerial::isST() const {return isBit(TIOCM_ST, "ST");}
bool PISerial::isSR() const {return isBit(TIOCM_SR, "SR");}
bool PISerial::isCAR() const {return isBit(TIOCM_CAR, "CAR");}
bool PISerial::isRNG() const {return isBit(TIOCM_RNG, "RNG");}
bool PISerial::isDSR() const {return isBit(TIOCM_DSR, "DSR");}
bool PISerial::setBit(int bit, bool on, const PIString & bname) {
#ifndef WINDOWS
@@ -158,6 +255,13 @@ bool PISerial::isBit(int bit, const PIString & bname) const {
}
void PISerial::flush() {
#ifndef WINDOWS
if (fd != -1) tcflush(fd, TCIOFLUSH);
#endif
}
bool PISerial::closeDevice() {
if (!isInitialized()) return true;
if (isRunning()) {
@@ -166,12 +270,12 @@ bool PISerial::closeDevice() {
}
if (fd != -1) {
#ifdef WINDOWS
SetCommState(hCom, &sdesc);
SetCommMask(hCom, mask);
CloseHandle(hCom);
hCom = 0;
SetCommState(PRIVATE->hCom, &PRIVATE->sdesc);
SetCommMask(PRIVATE->hCom, PRIVATE->mask);
CloseHandle(PRIVATE->hCom);
PRIVATE->hCom = 0;
#else
tcsetattr(fd, TCSANOW, &sdesc);
tcsetattr(fd, TCSANOW, &PRIVATE->sdesc);
::close(fd);
#endif
fd = -1;
@@ -351,8 +455,8 @@ bool PISerial::openDevice() {
if (isReadable()) {ds |= GENERIC_READ; sm |= FILE_SHARE_READ;}
if (isWriteable()) {ds |= GENERIC_WRITE; sm |= FILE_SHARE_WRITE;}
PIString wp = "//./" + path();
hCom = CreateFileA(wp.data(), ds, sm, 0, OPEN_EXISTING, FILE_ATTRIBUTE_SYSTEM, 0);
if (hCom == INVALID_HANDLE_VALUE) {
PRIVATE->hCom = CreateFileA(wp.data(), ds, sm, 0, OPEN_EXISTING, FILE_ATTRIBUTE_SYSTEM, 0);
if (PRIVATE->hCom == INVALID_HANDLE_VALUE) {
piCoutObj << "Unable to open \"" << path() << "\"";
fd = -1;
return false;
@@ -371,8 +475,8 @@ bool PISerial::openDevice() {
piCoutObj << "Unable to open \"" << path() << "\"";
return false;
}
tcgetattr(fd, &desc);
sdesc = desc;
tcgetattr(fd, &PRIVATE->desc);
PRIVATE->sdesc = PRIVATE->desc;
//piCoutObj << "Initialized " << path_;
#endif
applySettings();
@@ -389,58 +493,58 @@ void PISerial::applySettings() {
times.ReadTotalTimeoutMultiplier = block_read ? 0 : MAXDWORD;
times.WriteTotalTimeoutConstant = 0;
times.WriteTotalTimeoutMultiplier = block_write ? 0 : 1;
if (SetCommTimeouts(hCom, &times) == -1)
if (SetCommTimeouts(PRIVATE->hCom, &times) == -1)
piCoutObj << "Unable to set timeouts for \"" << path() << "\"";
GetCommMask(hCom, &mask);
SetCommMask(hCom, EV_RXCHAR);
GetCommState(hCom, &sdesc);
desc = sdesc;
desc.DCBlength = sizeof(desc);
desc.BaudRate = convertSpeed(outSpeed());
GetCommMask(PRIVATE->hCom, &PRIVATE->mask);
SetCommMask(PRIVATE->hCom, EV_RXCHAR);
GetCommState(PRIVATE->hCom, &PRIVATE->sdesc);
PRIVATE->desc = PRIVATE->sdesc;
PRIVATE->desc.DCBlength = sizeof(PRIVATE->desc);
PRIVATE->desc.BaudRate = convertSpeed(outSpeed());
if (dataBitsCount() >= 5 && dataBitsCount() <= 8)
desc.ByteSize = dataBitsCount();
PRIVATE->desc.ByteSize = dataBitsCount();
else
desc.ByteSize = 8;
PRIVATE->desc.ByteSize = 8;
PIFlags<Parameters> params = parameters();
if (params[PISerial::ParityControl]) {
desc.fParity = 1;
desc.Parity = params[PISerial::ParityOdd] ? 1 : 2;
PRIVATE->desc.fParity = 1;
PRIVATE->desc.Parity = params[PISerial::ParityOdd] ? 1 : 2;
}
desc.StopBits = params[PISerial::TwoStopBits] ? TWOSTOPBITS : ONESTOPBIT;
if (SetCommState(hCom, &desc) == -1) {
PRIVATE->desc.StopBits = params[PISerial::TwoStopBits] ? TWOSTOPBITS : ONESTOPBIT;
if (SetCommState(PRIVATE->hCom, &PRIVATE->desc) == -1) {
piCoutObj << "Unable to set comm state for \"" << path() << "\"";
return;
}
#else
if (fd == -1) return;
tcgetattr(fd, &desc);
desc.c_oflag = desc.c_lflag = desc.c_cflag = 0;
desc.c_iflag = IGNBRK;
desc.c_cflag = CLOCAL | HUPCL;
tcgetattr(fd, &PRIVATE->desc);
PRIVATE->desc.c_oflag = PRIVATE->desc.c_lflag = PRIVATE->desc.c_cflag = 0;
PRIVATE->desc.c_iflag = IGNBRK;
PRIVATE->desc.c_cflag = CLOCAL | HUPCL;
switch (dataBitsCount()) {
case 5: desc.c_cflag |= (CSIZE & CS5); break;
case 6: desc.c_cflag |= (CSIZE & CS6); break;
case 7: desc.c_cflag |= (CSIZE & CS7); break;
case 8: default: desc.c_cflag |= (CSIZE & CS8); break;
case 5: PRIVATE->desc.c_cflag |= (CSIZE & CS5); break;
case 6: PRIVATE->desc.c_cflag |= (CSIZE & CS6); break;
case 7: PRIVATE->desc.c_cflag |= (CSIZE & CS7); break;
case 8: default: PRIVATE->desc.c_cflag |= (CSIZE & CS8); break;
};
if (isReadable()) desc.c_cflag |= CREAD;
if (isReadable()) PRIVATE->desc.c_cflag |= CREAD;
PIFlags<Parameters> params = parameters();
if (params[PISerial::TwoStopBits]) desc.c_cflag |= CSTOPB;
if (params[PISerial::TwoStopBits]) PRIVATE->desc.c_cflag |= CSTOPB;
if (params[PISerial::ParityControl]) {
desc.c_iflag |= INPCK;
desc.c_cflag |= PARENB;
if (params[PISerial::ParityOdd]) desc.c_cflag |= PARODD;
PRIVATE->desc.c_iflag |= INPCK;
PRIVATE->desc.c_cflag |= PARENB;
if (params[PISerial::ParityOdd]) PRIVATE->desc.c_cflag |= PARODD;
}
desc.c_cc[VMIN] = 1;
desc.c_cc[VTIME] = vtime;
PRIVATE->desc.c_cc[VMIN] = 1;
PRIVATE->desc.c_cc[VTIME] = vtime;
cfsetispeed(&desc, convertSpeed(inSpeed()));
cfsetospeed(&desc, convertSpeed(outSpeed()));
cfsetispeed(&PRIVATE->desc, convertSpeed(inSpeed()));
cfsetospeed(&PRIVATE->desc, convertSpeed(outSpeed()));
tcflush(fd, TCIOFLUSH);
fcntl(fd, F_SETFL, block_read ? 0 : O_NONBLOCK);
if(tcsetattr(fd, TCSANOW, &desc) < 0) {
if(tcsetattr(fd, TCSANOW, &PRIVATE->desc) < 0) {
piCoutObj << "Can`t set attributes for \"" << path() << "\"";
return;
}
@@ -457,7 +561,7 @@ void PISerial::setReadIsBlocking(bool yes) {
times.ReadTotalTimeoutMultiplier = block_read ? 0 : MAXDWORD;
times.WriteTotalTimeoutConstant = 0;
times.WriteTotalTimeoutMultiplier = block_write ? 0 : 1;
if (isOpened()) SetCommTimeouts(hCom, &times);
if (isOpened()) SetCommTimeouts(PRIVATE->hCom, &times);
#else
if (isOpened()) fcntl(fd, F_SETFL, yes ? 0 : O_NONBLOCK);
#endif
@@ -472,9 +576,9 @@ void PISerial::setReadIsBlocking(bool yes) {
int PISerial::read(void * read_to, int max_size) {
#ifdef WINDOWS
if (!canRead()) return -1;
WaitCommEvent(hCom, 0, 0);
ReadFile(hCom, read_to, max_size, &readed, 0);
return readed;
WaitCommEvent(PRIVATE->hCom, 0, 0);
ReadFile(PRIVATE->hCom, read_to, max_size, &PRIVATE->readed, 0);
return PRIVATE->readed;
#else
if (!canRead()) return -1;
return ::read(fd, read_to, max_size);
@@ -494,7 +598,7 @@ int PISerial::write(const void * data, int max_size, bool wait) {
setReadIsBlocking(block_read);
}
DWORD wrote;
WriteFile(hCom, data, max_size, &wrote, 0);
WriteFile(PRIVATE->hCom, data, max_size, &wrote, 0);
#else
int wrote;
wrote = ::write(fd, data, max_size);

View File

@@ -4,7 +4,7 @@
/*
PIP - Platform Independent Primitives
COM
Copyright (C) 2014 Ivan Pelipenko peri4ko@gmail.com, Bychkov Andrey wapmobil@gmail.com
Copyright (C) 2015 Ivan Pelipenko peri4ko@gmail.com, Bychkov Andrey wapmobil@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -25,71 +25,6 @@
#include "pitimer.h"
#include "piiodevice.h"
#ifndef WINDOWS
# include <termios.h>
# include <fcntl.h>
# include <sys/ioctl.h>
# ifndef B50
# define B50 0000001
# endif
# ifndef B75
# define B75 0000002
# endif
# ifndef B1500000
# define B1500000 0010012
# endif
# ifndef B2000000
# define B2000000 0010013
# endif
# ifndef B2500000
# define B2500000 0010014
# endif
# ifndef B3000000
# define B3000000 0010015
# endif
# ifndef B3500000
# define B3500000 0010016
# endif
# ifndef B4000000
# define B4000000 0010017
# endif
#else
# define TIOCM_LE 1
# define TIOCM_DTR 4
# define TIOCM_RTS 7
# define TIOCM_CTS 8
# define TIOCM_ST 3
# define TIOCM_SR 2
# define TIOCM_CAR 1
# define TIOCM_RNG 9
# define TIOCM_DSR 6
# define B50 50
# define B75 75
# define B110 110
# define B300 300
# define B600 600
# define B1200 1200
# define B2400 2400
# define B4800 4800
# define B9600 9600
# define B14400 14400
# define B19200 19200
# define B38400 38400
# define B57600 57600
# define B115200 115200
# define B128000 128000
# define B256000 256000
# define B1500000 1500000
# define B2000000 2000000
# define B2500000 2500000
# define B3000000 3000000
# define B3500000 3500000
# define B4000000 4000000
#endif
#ifndef CRTSCTS
# define CRTSCTS 020000000000
#endif
class PIP_EXPORT PISerial: public PIIODevice
{
@@ -97,7 +32,7 @@ class PIP_EXPORT PISerial: public PIIODevice
public:
//! Contructs an empty %PISerial
PISerial();
explicit PISerial();
//! \brief Parameters of PISerial
enum Parameters {
@@ -130,7 +65,7 @@ public:
};
//! Contructs %PISerial with device name "device", speed "speed" and parameters "params"
PISerial(const PIString & device, PISerial::Speed speed = S115200, PIFlags<PISerial::Parameters> params = 0);
explicit PISerial(const PIString & device, PISerial::Speed speed = S115200, PIFlags<PISerial::Parameters> params = 0);
~PISerial();
@@ -174,25 +109,25 @@ public:
//! Returns pin number "number" logic level. Valid numbers range is from 1 to 9
bool isPin(int number) const;
bool setLE(bool on) {return setBit(TIOCM_LE, on, "LE");} // useless function, just formally
bool setDTR(bool on) {return setBit(TIOCM_DTR, on, "DTR");}
bool setRTS(bool on) {return setBit(TIOCM_RTS, on, "RTS");}
bool setCTS(bool on) {return setBit(TIOCM_CTS, on, "CTS");} // useless function, just formally
bool setST(bool on) {return setBit(TIOCM_ST, on, "ST");} // useless function, just formally
bool setSR(bool on) {return setBit(TIOCM_SR, on, "SR");} // useless function, just formally
bool setCAR(bool on) {return setBit(TIOCM_CAR, on, "CAR");} // useless function, just formally
bool setRNG(bool on) {return setBit(TIOCM_RNG, on, "RNG");} // useless function, just formally
bool setDSR(bool on) {return setBit(TIOCM_DSR, on, "DSR");} // useless function, just formally
bool setLE(bool on); // useless function, just formally
bool setDTR(bool on);
bool setRTS(bool on);
bool setCTS(bool on); // useless function, just formally
bool setST(bool on); // useless function, just formally
bool setSR(bool on); // useless function, just formally
bool setCAR(bool on); // useless function, just formally
bool setRNG(bool on); // useless function, just formally
bool setDSR(bool on); // useless function, just formally
bool isLE() const {return isBit(TIOCM_LE, "LE");}
bool isDTR() const {return isBit(TIOCM_DTR, "DTR");}
bool isRTS() const {return isBit(TIOCM_RTS, "RTS");}
bool isCTS() const {return isBit(TIOCM_CTS, "CTS");}
bool isST() const {return isBit(TIOCM_ST, "ST");}
bool isSR() const {return isBit(TIOCM_SR, "SR");}
bool isCAR() const {return isBit(TIOCM_CAR, "CAR");}
bool isRNG() const {return isBit(TIOCM_RNG, "RNG");}
bool isDSR() const {return isBit(TIOCM_DSR, "DSR");}
bool isLE() const;
bool isDTR() const;
bool isRTS() const;
bool isCTS() const;
bool isST() const;
bool isSR() const;
bool isCAR() const;
bool isRNG() const;
bool isDSR() const;
void setVTime(int t) {vtime = t; applySettings();}
@@ -214,11 +149,8 @@ public:
//! Discard all buffered input and output data
void flush() {
#ifndef WINDOWS
if (fd != -1) tcflush(fd, TCIOFLUSH);
#endif
}
void flush();
int read(void * read_to, int max_size);
bool read(void * read_to, int max_size, double timeout_ms);
@@ -292,17 +224,9 @@ protected:
bool openDevice();
bool closeDevice();
#ifdef WINDOWS
DCB desc, sdesc;
void * hCom;
DWORD readed, mask;
bool block_write;
#else
termios desc, sdesc;
uint readed;
#endif
PRIVATE_DECLARATION
int fd, vtime;
bool block_read;
bool block_read, block_write;
PITimeMeasurer tm_;
};

View File

@@ -348,41 +348,41 @@ void PIUSB::flush() {
PICout operator<<(PICout s, const PIUSB::Endpoint & v) {
s.setControl(0, true);
s << NewLine << "{" << NewLine;
s << PICoutManipulators::NewLine << "{" << PICoutManipulators::NewLine;
if (v.isNull())
s << " " << "Null Endpoint";
else {
s << " " << "Address: " << v.address << NewLine;
s << " " << "Attributes: " << v.attributes << NewLine;
s << " " << "Direction: " << (v.direction == PIUSB::Endpoint::Write ? "Write" : "Read") << NewLine;
s << " " << "Address: " << v.address << PICoutManipulators::NewLine;
s << " " << "Attributes: " << v.attributes << PICoutManipulators::NewLine;
s << " " << "Direction: " << (v.direction == PIUSB::Endpoint::Write ? "Write" : "Read") << PICoutManipulators::NewLine;
s << " " << "Transfer Type: ";
switch (v.transfer_type) {
case PIUSB::Endpoint::Control: s << "Control" << NewLine; break;
case PIUSB::Endpoint::Bulk: s << "Bulk" << NewLine; break;
case PIUSB::Endpoint::Interrupt: s << "Interrupt" << NewLine; break;
case PIUSB::Endpoint::Isochronous: s << "Isochronous" << NewLine; break;
case PIUSB::Endpoint::Control: s << "Control" << PICoutManipulators::NewLine; break;
case PIUSB::Endpoint::Bulk: s << "Bulk" << PICoutManipulators::NewLine; break;
case PIUSB::Endpoint::Interrupt: s << "Interrupt" << PICoutManipulators::NewLine; break;
case PIUSB::Endpoint::Isochronous: s << "Isochronous" << PICoutManipulators::NewLine; break;
default: break;
}
if (v.transfer_type == PIUSB::Endpoint::Isochronous) {
s << " " << "Synchronisation Type: ";
switch (v.synchronisation_type) {
case PIUSB::Endpoint::NoSynchonisation: s << "No Synchonisation" << NewLine; break;
case PIUSB::Endpoint::Asynchronous: s << "Asynchronous" << NewLine; break;
case PIUSB::Endpoint::Adaptive: s << "Adaptive" << NewLine; break;
case PIUSB::Endpoint::Synchronous: s << "Synchronous" << NewLine; break;
case PIUSB::Endpoint::NoSynchonisation: s << "No Synchonisation" << PICoutManipulators::NewLine; break;
case PIUSB::Endpoint::Asynchronous: s << "Asynchronous" << PICoutManipulators::NewLine; break;
case PIUSB::Endpoint::Adaptive: s << "Adaptive" << PICoutManipulators::NewLine; break;
case PIUSB::Endpoint::Synchronous: s << "Synchronous" << PICoutManipulators::NewLine; break;
default: break;
}
s << " " << "Usage Type: ";
switch (v.usage_type) {
case PIUSB::Endpoint::DataEndpoint: s << "Data Endpoint" << NewLine; break;
case PIUSB::Endpoint::FeedbackEndpoint: s << "Feedback Endpoint" << NewLine; break;
case PIUSB::Endpoint::ExplicitFeedbackDataEndpoint: s << "Explicit Feedback Data Endpoint" << NewLine; break;
case PIUSB::Endpoint::DataEndpoint: s << "Data Endpoint" << PICoutManipulators::NewLine; break;
case PIUSB::Endpoint::FeedbackEndpoint: s << "Feedback Endpoint" << PICoutManipulators::NewLine; break;
case PIUSB::Endpoint::ExplicitFeedbackDataEndpoint: s << "Explicit Feedback Data Endpoint" << PICoutManipulators::NewLine; break;
default: break;
}
}
s << " " << "Max Packet Size: " << v.max_packet_size << NewLine;
s << " " << "Max Packet Size: " << v.max_packet_size << PICoutManipulators::NewLine;
}
s << "}" << NewLine;
s << "}" << PICoutManipulators::NewLine;
s.restoreControl();
return s;
}

View File

@@ -4,7 +4,7 @@
/*
PIP - Platform Independent Primitives
USB, based on libusb
Copyright (C) 2014 Ivan Pelipenko peri4ko@gmail.com
Copyright (C) 2015 Ivan Pelipenko peri4ko@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

View File

@@ -4,7 +4,7 @@
/*
PIP - Platform Independent Primitives
CRC checksum calculator
Copyright (C) 2014 Ivan Pelipenko peri4ko@gmail.com
Copyright (C) 2015 Ivan Pelipenko peri4ko@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -213,7 +213,7 @@ public:
}
N calculate(const PIByteArray & d) {return calculate(d.data(), d.size());}
N calculate(const char * str) {string s(str); return calculate((void * )s.data(), s.size());}
N calculate(const char * str) {PIByteArray s(PIString(str).toByteArray()); return calculate(s.data(), s.size_s());}
private:
inline N reversed(const N & v) {return v.reversed();}

View File

@@ -1,7 +1,7 @@
/*
PIP - Platform Independent Primitives
Evaluator designed for stream computing
Copyright (C) 2014 Ivan Pelipenko peri4ko@gmail.com
Copyright (C) 2015 Ivan Pelipenko peri4ko@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

View File

@@ -4,7 +4,7 @@
/*
PIP - Platform Independent Primitives
Evaluator designed for stream calculations
Copyright (C) 2014 Ivan Pelipenko peri4ko@gmail.com
Copyright (C) 2015 Ivan Pelipenko peri4ko@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -24,7 +24,7 @@
#define PIEVALUATOR_H
#include "pistring.h"
#include "pimath.h"
#include "pimathbase.h"
typedef complexd (*FuncFunc)(void * , int, complexd * );

View File

@@ -1,7 +1,7 @@
/*
PIP - Platform Independent Primitives
Class for FFT, IFFT and Hilbert transformations
Copyright (C) 2014 Ivan Pelipenko peri4ko@gmail.com, Andrey Bychkov work.a.b@yandex.ru
Copyright (C) 2015 Ivan Pelipenko peri4ko@gmail.com, Andrey Bychkov work.a.b@yandex.ru
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

View File

@@ -4,7 +4,7 @@
/*
PIP - Platform Independent Primitives
Class for FFT, IFFT and Hilbert transformations
Copyright (C) 2014 Ivan Pelipenko peri4ko@gmail.com, Andrey Bychkov work.a.b@yandex.ru
Copyright (C) 2015 Ivan Pelipenko peri4ko@gmail.com, Andrey Bychkov work.a.b@yandex.ru
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

View File

@@ -1,7 +1,7 @@
/*
PIP - Platform Independent Primitives
Basic mathematical functions and defines
Copyright (C) 2014 Ivan Pelipenko peri4ko@gmail.com
Copyright (C) 2015 Ivan Pelipenko peri4ko@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

View File

@@ -4,7 +4,7 @@
/*
PIP - Platform Independent Primitives
Basic mathematical functions and defines
Copyright (C) 2014 Ivan Pelipenko peri4ko@gmail.com
Copyright (C) 2015 Ivan Pelipenko peri4ko@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -32,6 +32,11 @@
# undef PIP_MATH_Y0
# undef PIP_MATH_Y1
# undef PIP_MATH_YN
# include <complex.h>
# include <math.h>
#else
# include <complex>
# include <cmath>
#endif
#ifndef M_LN2
@@ -77,6 +82,25 @@
# define M_LIGHT_SPEED 2.99792458e+8
#endif
using std::complex;
typedef complex<int> complexi;
typedef complex<float> complexf;
typedef complex<double> complexd;
typedef complex<ldouble> complexld;
const complexld complexld_i(0., 1.);
const complexld complexld_0(0.);
const complexld complexld_1(1.);
const complexd complexd_i(0., 1.);
const complexd complexd_0(0.);
const complexd complexd_1(1.);
__PICONTAINERS_SIMPLE_TYPE__(complexi)
__PICONTAINERS_SIMPLE_TYPE__(complexf)
__PICONTAINERS_SIMPLE_TYPE__(complexd)
__PICONTAINERS_SIMPLE_TYPE__(complexld)
const double deg2rad = M_PI_180;
const double rad2deg = M_180_PI;

View File

@@ -4,7 +4,7 @@
/*
PIP - Platform Independent Primitives
PIMathMatrix
Copyright (C) 2014 Ivan Pelipenko peri4ko@gmail.com
Copyright (C) 2015 Ivan Pelipenko peri4ko@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -225,9 +225,9 @@ template<> inline PIMathMatrixT<3u, 3u> PIMathMatrixT<3u, 3u>::scaleY(double fac
template<> inline PIMathMatrixT<3u, 3u> PIMathMatrixT<3u, 3u>::scaleZ(double factor) {PIMathMatrixT<3u, 3u> tm; tm[0][0] = tm[1][1] = 1.; tm[2][2] = factor; return tm;}
template<uint Rows, uint Cols, typename Type>
inline std::ostream & operator <<(std::ostream & s, const PIMathMatrixT<Rows, Cols, Type> & m) {s << '{'; PIMM_FOR_I(r, c) s << m[r][c]; if (c < Cols - 1 || r < Rows - 1) s << ", ";} if (r < Rows - 1) s << endl << ' ';} s << '}'; return s;}
inline std::ostream & operator <<(std::ostream & s, const PIMathMatrixT<Rows, Cols, Type> & m) {s << '{'; PIMM_FOR_I(r, c) s << m[r][c]; if (c < Cols - 1 || r < Rows - 1) s << ", ";} if (r < Rows - 1) s << std::endl << ' ';} s << '}'; return s;}
template<uint Rows, uint Cols, typename Type>
inline PICout operator <<(PICout s, const PIMathMatrixT<Rows, Cols, Type> & m) {s << '{'; PIMM_FOR_I(r, c) s << m[r][c]; if (c < Cols - 1 || r < Rows - 1) s << ", ";} if (r < Rows - 1) s << NewLine << ' ';} s << '}'; return s;}
inline PICout operator <<(PICout s, const PIMathMatrixT<Rows, Cols, Type> & m) {s << '{'; PIMM_FOR_I(r, c) s << m[r][c]; if (c < Cols - 1 || r < Rows - 1) s << ", ";} if (r < Rows - 1) s << PICoutManipulators::NewLine << ' ';} s << '}'; return s;}
/// Multiply matrices {Rows0 x CR} on {CR x Cols1}, result is {Rows0 x Cols1}
template<uint CR, uint Rows0, uint Cols1, typename Type>
@@ -450,9 +450,9 @@ private:
};
template<typename Type>
inline std::ostream & operator <<(std::ostream & s, const PIMathMatrix<Type> & m) {s << '{'; for (uint r = 0; r < m.rows(); ++r) { for (uint c = 0; c < m.cols(); ++c) { s << m[c][r]; if (c < m.cols() - 1 || r < m.rows() - 1) s << ", ";} if (r < m.rows() - 1) s << endl << ' ';} s << '}'; return s;}
inline std::ostream & operator <<(std::ostream & s, const PIMathMatrix<Type> & m) {s << '{'; for (uint r = 0; r < m.rows(); ++r) { for (uint c = 0; c < m.cols(); ++c) { s << m[c][r]; if (c < m.cols() - 1 || r < m.rows() - 1) s << ", ";} if (r < m.rows() - 1) s << std::endl << ' ';} s << '}'; return s;}
template<typename Type>
inline PICout operator <<(PICout s, const PIMathMatrix<Type> & m) {s << '{'; for (uint r = 0; r < m.rows(); ++r) { for (uint c = 0; c < m.cols(); ++c) { s << m[c][r]; if (c < m.cols() - 1 || r < m.rows() - 1) s << ", ";} if (r < m.rows() - 1) s << NewLine << ' ';} s << '}'; return s;}
inline PICout operator <<(PICout s, const PIMathMatrix<Type> & m) {s << '{'; for (uint r = 0; r < m.rows(); ++r) { for (uint c = 0; c < m.cols(); ++c) { s << m[c][r]; if (c < m.cols() - 1 || r < m.rows() - 1) s << ", ";} if (r < m.rows() - 1) s << PICoutManipulators::NewLine << ' ';} s << '}'; return s;}
/// Multiply matrices {CR x Rows0} on {Cols1 x CR}, result is {Cols1 x Rows0}
template<typename Type>

View File

@@ -1,7 +1,7 @@
/*
PIP - Platform Independent Primitives
PIMathSolver
Copyright (C) 2014 Ivan Pelipenko peri4ko@gmail.com
Copyright (C) 2015 Ivan Pelipenko peri4ko@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -98,7 +98,7 @@ void PIMathSolver::fromTF(const TransferFunction & TF) {
a1 /= a0;
b1 /= a0;
d[0] = b1[0]; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> d
d[0] = b1[0]; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> d
for (uint i = 1; i < size + 1; ++i) {
sum = 0.;
for (uint m = 0; m < i; ++m)
@@ -106,7 +106,7 @@ void PIMathSolver::fromTF(const TransferFunction & TF) {
d[i] = b1[i] - sum;
}
for (uint i = 0; i < size - 1; ++i) // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>
for (uint i = 0; i < size - 1; ++i) // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>
for (uint j = 0; j < size; ++j)
A[j][i] = (j == i + 1);
for (uint i = 0; i < size; ++i)

View File

@@ -4,7 +4,7 @@
/*
PIP - Platform Independent Primitives
PIMathSolver
Copyright (C) 2014 Ivan Pelipenko peri4ko@gmail.com
Copyright (C) 2015 Ivan Pelipenko peri4ko@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -27,15 +27,15 @@
/// Differential evaluations
struct TransferFunction { // <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
struct TransferFunction { // <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
PIVector<double> vector_Bm, vector_An;
};
// <20><><EFBFBD><EFBFBD><EFBFBD>, <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>. <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>. <20><>-<2D><><EFBFBD>:
// <09><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
// <09><><EFBFBD><EFBFBD><EFBFBD>-<2D><><EFBFBD><EFBFBD><EFBFBD> 4-<2D><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
// <09><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>-<2D><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>-<2D><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 2, 3, 4 <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
// <20><><EFBFBD><EFBFBD><EFBFBD>, <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>. <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>. <20><>-<2D><><EFBFBD>:
// <09><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
// <09><><EFBFBD><EFBFBD><EFBFBD>-<2D><><EFBFBD><EFBFBD><EFBFBD> 4-<2D><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
// <09><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>-<2D><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>-<2D><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 2, 3, 4 <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
class PIP_EXPORT PIMathSolver
{
public:

View File

@@ -4,7 +4,7 @@
/*
PIP - Platform Independent Primitives
PIMathVector
Copyright (C) 2014 Ivan Pelipenko peri4ko@gmail.com
Copyright (C) 2015 Ivan Pelipenko peri4ko@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

View File

@@ -4,7 +4,7 @@
/*
PIP - Platform Independent Primitives
Class for calculacing math statistic in values array
Copyright (C) 2014 Ivan Pelipenko peri4ko@gmail.com, Andrey Bychkov work.a.b@yandex.ru
Copyright (C) 2015 Ivan Pelipenko peri4ko@gmail.com, Andrey Bychkov work.a.b@yandex.ru
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

View File

@@ -1,7 +1,7 @@
/*
PIP - Platform Independent Primitives
All includes
Copyright (C) 2014 Ivan Pelipenko peri4ko@gmail.com
Copyright (C) 2015 Ivan Pelipenko peri4ko@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -17,23 +17,15 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "pitimer.h"
#include "pivariant.h"
#include "piconsole.h"
#include "picli.h"
#include "pievaluator.h"
#include "pimultiprotocol.h"
#include "picodec.h"
#include "pisignals.h"
#include "piobject.h"
#include "pisystemmonitor.h"
#include "pisysteminfo.h"
#include "pipeer.h"
#include "picrc.h"
#include "pistatemachine.h"
#include "picollection.h"
#include "piserial.h"
#include "pibinarylog.h"
#include "piusb.h"
#include "piiostring.h"
#include "piconnection.h"
#ifndef PIP_H
#define PIP_H
#include "picoremodule.h"
#include "picontainersmodule.h"
#include "piconsolemodule.h"
#include "pithreadmodule.h"
#include "piiomodule.h"
#include "pimathmodule.h"
#include "pisystemmodule.h"
#endif // PIP_H

View File

@@ -1 +1,2 @@
#define __PIP_VERSION_STR__ "0.4.2_alpha"
// This file was generated by PIP CMake, don`t edit it!
#define __PIP_VERSION_STR__ "0.5.0_alpha"

View File

@@ -1,3 +1,22 @@
/*
PIP - Platform Independent Primitives
Platform and compiler macros
Copyright (C) 2015 Ivan Pelipenko peri4ko@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef PIPLATFORM_H
#define PIPLATFORM_H
@@ -46,48 +65,10 @@
#ifdef __GNUC__
# define CC_GCC
# define CC_GCC_VERSION ((__GNUC__ << 8) | __GNUC_MINOR__)
# if CC_GCC_VERSION > 0x025F // > 2.95
# ifdef LINUX
# define HAS_LOCALE
# endif
# pragma GCC diagnostic ignored "-Wpragmas"
# pragma GCC diagnostic ignored "-Wformat"
# pragma GCC diagnostic ignored "-Wformat-extra-args"
# pragma GCC diagnostic ignored "-Wstrict-aliasing"
# pragma GCC diagnostic ignored "-Waggressive-loop-optimizations"
# endif
# ifdef ANDROID
# pragma GCC diagnostic ignored "-Wunused-parameter"
# pragma GCC diagnostic ignored "-Wextra"
# pragma GCC diagnostic ignored "-Wliteral-suffix"
# endif
# define DEPRECATED __attribute__((deprecated))
#elif defined(_MSC_VER)
# define CC_VC
# pragma warning(disable: 4018)
# pragma warning(disable: 4061)
# pragma warning(disable: 4100)
# pragma warning(disable: 4239)
# pragma warning(disable: 4242)
# pragma warning(disable: 4244)
# pragma warning(disable: 4251)
# pragma warning(disable: 4365)
# pragma warning(disable: 4512)
# pragma warning(disable: 4668)
# pragma warning(disable: 4710)
# pragma warning(disable: 4800)
# pragma warning(disable: 4820)
# pragma warning(disable: 4986)
# pragma warning(disable: 4996)
# define DEPRECATED
# ifdef ARCH_BITS_32
typedef long ssize_t;
# else
typedef long long ssize_t;
# endif
#else
# define CC_OTHER
# define DEPRECATED
#endif
#ifdef WINDOWS
@@ -98,4 +79,11 @@
# define typeof __typeof__
#endif
#if defined(DOXYGEN) || defined(CC_GCC) || defined(PICODE)
# undef PIP_EXPORT
# define PIP_EXPORT
# undef DEPRECATED
# define DEPRECATED
#endif
#endif // PIPLATFORM_H

View File

@@ -3,8 +3,8 @@
#define PIVERSION_H
#define PIP_VERSION_MAJOR 0
#define PIP_VERSION_MINOR 4
#define PIP_VERSION_REVISION 2
#define PIP_VERSION_MINOR 5
#define PIP_VERSION_REVISION 0
#define PIP_VERSION_SUFFIX "_alpha"
#endif // PIVERSION_H

View File

@@ -1,7 +1,7 @@
/*
PIP - Platform Independent Primitives
Text codings coder, based on "iconv"
Copyright (C) 2014 Ivan Pelipenko peri4ko@gmail.com
Copyright (C) 2015 Ivan Pelipenko peri4ko@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

View File

@@ -1,7 +1,7 @@
/*
PIP - Platform Independent Primitives
Text codings coder, based on "iconv"
Copyright (C) 2014 Ivan Pelipenko peri4ko@gmail.com
Copyright (C) 2015 Ivan Pelipenko peri4ko@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

View File

@@ -1,7 +1,7 @@
/*
PIP - Platform Independent Primitives
Counter of some PIP types
Copyright (C) 2014 Ivan Pelipenko peri4ko@gmail.com
Copyright (C) 2015 Ivan Pelipenko peri4ko@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

View File

@@ -1,7 +1,7 @@
/*
PIP - Platform Independent Primitives
Counter of some PIP types
Copyright (C) 2014 Ivan Pelipenko peri4ko@gmail.com
Copyright (C) 2015 Ivan Pelipenko peri4ko@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

View File

@@ -1,7 +1,7 @@
/*
PIP - Platform Independent Primitives
Process
Copyright (C) 2014 Ivan Pelipenko peri4ko@gmail.com
Copyright (C) 2015 Ivan Pelipenko peri4ko@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -18,6 +18,15 @@
*/
#include "piprocess.h"
#ifdef WINDOWS
//# include <.h>
#else
# include <sys/wait.h>
# include <csignal>
#endif
#ifdef MAC_OS
# include <crt_externs.h>
#endif
PIProcess::PIProcess(): PIThread() {
@@ -51,9 +60,47 @@ void PIProcess::exec_() {
}
void PIProcess::terminate() {
#ifdef WINDOWS
if (is_exec) if (!TerminateProcess(pi.hProcess, 0)) return; pi.dwProcessId = 0;
#else
if (is_exec) kill(pid, SIGKILL); pid = 0;
#endif
}
int PIProcess::pID() const {
#ifdef WINDOWS
return pi.dwProcessId;
#else
return pid;
#endif
}
int PIProcess::currentPID() {
#ifdef WINDOWS
return GetCurrentProcessId();
#else
return getpid();
#endif
}
PIStringList PIProcess::currentEnvironment() {
PIStringList l;
int i = 0;
while (environ[i] != 0) {
l << environ[i];
++i;
}
return l;
}
void PIProcess::run() {
//cout << "run" << endl;
string str;
PIString str;
/// arguments convertion
as = 0;
#ifdef WINDOWS
@@ -64,17 +111,17 @@ void PIProcess::run() {
memset(a, ' ', as - 1);
as = 0;
for (int i = 0; i < args.size_s(); ++i) {
str = args[i].stdString();
memcpy(&a[as], str.c_str(), str.size());
str = args[i];
memcpy(&a[as], str.data(), str.lengthAscii());
as += str.length() + 1;
}
a[as - 1] = 0;
#else
char * a[args.size_s() + 1];
for (int i = 0; i < args.size_s(); ++i) {
str = args[i].stdString();
str = args[i];
a[i] = new char[str.size() + 1];
memcpy(a[i], str.c_str(), str.size());
memcpy(a[i], str.data(), str.lengthAscii());
a[i][str.size()] = 0;
//cout << a[i] << endl;
}
@@ -83,9 +130,9 @@ void PIProcess::run() {
/// environment convertion
char ** e = new char*[env.size_s() + 1];
for (int i = 0; i < env.size_s(); ++i) {
str = env[i].stdString();
str = env[i];
e[i] = new char[str.size() + 1];
memcpy(e[i], str.c_str(), str.size());
memcpy(e[i], str.data(), str.lengthAscii());
e[i][str.size()] = 0;
//cout << e[i] << endl;
}
@@ -108,9 +155,9 @@ void PIProcess::run() {
}
//f_err.open(PIIODevice::WriteOnly); f_err.close();
str = args.front().stdString();
str = args.front();
is_exec = true;
execStarted(PIString(str));
execStarted(str);
#ifndef WINDOWS
pid = fork();
if (pid == 0) {
@@ -145,7 +192,7 @@ void PIProcess::run() {
#else
//cout << "exec " << tf_in << ", " << tf_out << ", " << tf_err << endl;
if (execve(str.c_str(), a, e) < 0)
if (execve(str.data(), a, e) < 0)
piCoutObj << "\"execve\" error, " << errorString();
} else {
msleep(1);
@@ -158,7 +205,7 @@ void PIProcess::run() {
//cout << "wait done" << endl;
}
#endif
execFinished(PIString(str), exit_code);
execFinished(str, exit_code);
is_exec = false;
for (int i = 0; i < env.size_s(); ++i)
delete e[i];

View File

@@ -4,7 +4,7 @@
/*
PIP - Platform Independent Primitives
Process
Copyright (C) 2014 Ivan Pelipenko peri4ko@gmail.com
Copyright (C) 2015 Ivan Pelipenko peri4ko@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -25,11 +25,6 @@
#include "pithread.h"
#include "pifile.h"
#ifdef WINDOWS
//# include <.h>
#else
# include <sys/wait.h>
#endif
/// events:
/// execStarted(PIString program)
@@ -51,13 +46,7 @@ public:
virtual ~PIProcess();
int exitCode() const {return exit_code;}
int pID() const {
#ifdef WINDOWS
return pi.dwProcessId;
#else
return pid;
#endif
}
int pID() const;
void setGrabInput(bool yes) {g_in = yes;}
void setGrabOutput(bool yes) {g_out = yes;}
@@ -84,27 +73,15 @@ public:
EVENT_HANDLER3(void, exec, const PIString & , program, const PIString & , arg1, const PIString & , arg2) {args.clear(); args << program << arg1 << arg2; exec_();}
EVENT_HANDLER4(void, exec, const PIString & , program, const PIString & , arg1, const PIString & , arg2, const PIString & , arg3) {args.clear(); args << program << arg1 << arg2 << arg3; exec_();}
EVENT_HANDLER2(void, exec, const PIString & , program, const PIStringList & , args_) {args << program << args_; exec_();}
EVENT_HANDLER(void, terminate) {
#ifdef WINDOWS
if (is_exec) if (!TerminateProcess(pi.hProcess, 0)) return; pi.dwProcessId = 0;
#else
if (is_exec) kill(pid, SIGKILL); pid = 0;
#endif
}
EVENT_HANDLER(void, terminate);
EVENT_HANDLER(bool, waitForFinish) {return waitForFinish(60000);}
EVENT_HANDLER1(bool, waitForFinish, int, timeout_msecs) {return PIThread::waitForFinish(timeout_msecs);}
EVENT1(execStarted, PIString, program)
EVENT2(execFinished, PIString, program, int, exit_code)
static PIStringList currentEnvironment() {PIStringList l; int i = 0; while (environ[i] != 0) {l << environ[i]; ++i;} return l;}
static int currentPID() {
#ifdef WINDOWS
return GetCurrentProcessId();
#else
return getpid();
#endif
}
static PIStringList currentEnvironment();
static int currentPID();
private:
virtual void run();

View File

@@ -1,7 +1,7 @@
/*
PIP - Platform Independent Primitives
Signals
Copyright (C) 2014 Ivan Pelipenko peri4ko@gmail.com
Copyright (C) 2015 Ivan Pelipenko peri4ko@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -18,6 +18,11 @@
*/
#include "pisignals.h"
#include <csignal>
#ifdef WINDOWS
# define SIGUSR1 10
# define SIGUSR2 12
#endif
PISignals::SignalEvent PISignals::ret_func;
@@ -47,6 +52,11 @@ void PISignals::grabSignals(PIFlags<PISignals::Signal> signals_) {
}
void PISignals::raiseSignal(PISignals::Signal signal) {
raise(signalCode(signal));
}
int PISignals::signalCode(PISignals::Signal signal) {
switch (signal) {
case PISignals::Interrupt: return SIGINT;

View File

@@ -4,7 +4,7 @@
/*
PIP - Platform Independent Primitives
Signals
Copyright (C) 2014 Ivan Pelipenko peri4ko@gmail.com
Copyright (C) 2015 Ivan Pelipenko peri4ko@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -24,11 +24,6 @@
#define PISIGNALS_H
#include "picontainers.h"
#include <csignal>
#ifdef WINDOWS
# define SIGUSR1 10
# define SIGUSR2 12
#endif
class PIP_EXPORT PISignals
{
@@ -60,7 +55,7 @@ public:
// slot is any function format "void <func>(PISignals::Signal)"
static void setSlot(SignalEvent slot) {ret_func = slot;}
static void grabSignals(PIFlags<PISignals::Signal> signals_);
static void raiseSignal(PISignals::Signal signal) {raise(signalCode(signal));}
static void raiseSignal(PISignals::Signal signal);
private:
PISignals() {ret_func = 0;}

View File

@@ -1,7 +1,7 @@
/*
PIP - Platform Independent Primitives
System information
Copyright (C) 2014 Ivan Pelipenko peri4ko@gmail.com
Copyright (C) 2015 Ivan Pelipenko peri4ko@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

View File

@@ -1,7 +1,7 @@
/*
PIP - Platform Independent Primitives
System information
Copyright (C) 2014 Ivan Pelipenko peri4ko@gmail.com
Copyright (C) 2015 Ivan Pelipenko peri4ko@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

View File

@@ -1,7 +1,7 @@
/*
PIP - Platform Independent Primitives
Process resource monitor
Copyright (C) 2014 Ivan Pelipenko peri4ko@gmail.com
Copyright (C) 2015 Ivan Pelipenko peri4ko@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

View File

@@ -1,7 +1,7 @@
/*
PIP - Platform Independent Primitives
Process resource monitor
Copyright (C) 2014 Ivan Pelipenko peri4ko@gmail.com
Copyright (C) 2015 Ivan Pelipenko peri4ko@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -22,6 +22,9 @@
#include "pithread.h"
#include "piprocess.h"
#ifdef WINDOWS
# include <psapi.h>
#endif
class PIP_EXPORT PISystemMonitor: public PIThread
{

View File

@@ -1,7 +1,7 @@
/*
PIP - Platform Independent Primitives
System tests results (see system_test folder)
Copyright (C) 2014 Ivan Pelipenko peri4ko@gmail.com
Copyright (C) 2015 Ivan Pelipenko peri4ko@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

View File

@@ -1,7 +1,7 @@
/*
PIP - Platform Independent Primitives
System tests results (see system_test folder)
Copyright (C) 2014 Ivan Pelipenko peri4ko@gmail.com
Copyright (C) 2015 Ivan Pelipenko peri4ko@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

View File

@@ -1,7 +1,7 @@
/*
PIP - Platform Independent Primitives
Mutex
Copyright (C) 2014 Ivan Pelipenko peri4ko@gmail.com
Copyright (C) 2015 Ivan Pelipenko peri4ko@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -57,3 +57,30 @@ PIMutex::~PIMutex() {
pthread_mutex_destroy(&mutex);
#endif
}
void PIMutex::lock() {
#ifdef WINDOWS
WaitForSingleObject(mutex, INFINITE);
#else
pthread_mutex_lock(&mutex);
#endif
}
void PIMutex::unlock() {
#ifdef WINDOWS
ReleaseMutex(mutex);
#else
pthread_mutex_unlock(&mutex);
#endif
}
bool PIMutex::tryLock() {
#ifdef WINDOWS
return (WaitForSingleObject(mutex, 0) == WAIT_OBJECT_0);
#else
return (pthread_mutex_trylock(&mutex) == 0);
#endif
}

View File

@@ -4,7 +4,7 @@
/*
PIP - Platform Independent Primitives
Mutex
Copyright (C) 2014 Ivan Pelipenko peri4ko@gmail.com
Copyright (C) 2015 Ivan Pelipenko peri4ko@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -38,36 +38,16 @@ public:
//! \brief Lock mutex
//! \details If mutex is unlocked it set to locked state and returns immediate.
//! If mutex is already locked function blocks until mutex will be unlocked
void lock() {
#ifdef WINDOWS
WaitForSingleObject(mutex, INFINITE);
#else
pthread_mutex_lock(&mutex);
#endif
}
void lock();
//! \brief Unlock mutex
//! \details In any case this function returns immediate
void unlock() {
#ifdef WINDOWS
ReleaseMutex(mutex);
#else
pthread_mutex_unlock(&mutex);
#endif
}
void unlock();
//! \brief Try to lock mutex
//! \details If mutex is unlocked it set to locked state and returns "true" immediate.
//! If mutex is already locked function returns immediate an returns "false"
bool tryLock() {
#ifdef WINDOWS
return (WaitForSingleObject(mutex, 0) == WAIT_OBJECT_0);
#else
return (pthread_mutex_trylock(&mutex) == 0);
#endif
}
bool tryLock();
private:
#ifdef WINDOWS

View File

@@ -1,7 +1,7 @@
/*
PIP - Platform Independent Primitives
Thread
Copyright (C) 2014 Ivan Pelipenko peri4ko@gmail.com
Copyright (C) 2015 Ivan Pelipenko peri4ko@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -19,6 +19,10 @@
#include "pithread.h"
#include "pisystemtests.h"
#include <signal.h>
#ifdef WINDOWS
void __PISetTimerResolution() {if (setTimerResolutionAddr == NULL) return; ULONG ret; setTimerResolutionAddr(1, TRUE, &ret);}
#endif
/*! \class PIThread

Some files were not shown because too many files have changed in this diff Show More