3.10.2013 - PIPeer release, PIConsole now can work as server and remote client. Remote console test program in directory "remote_console"

This commit is contained in:
peri4
2013-10-03 16:04:02 +04:00
parent 9111640ca8
commit 4b90f2818e
56 changed files with 6422 additions and 673 deletions

View File

@@ -27,7 +27,7 @@
#define PIINCLUDES_H
//! Version of PIP in hex - 0x##(Major)##(Minor)##(Revision)
#define PIP_VERSION 0x000304
#define PIP_VERSION 0x000306
//! Major value of PIP version
#define PIP_VERSION_MAJOR (PIP_VERSION & 0xFF0000) >> 16
@@ -78,16 +78,16 @@
#endif
#if WIN32 || WIN64 || _WIN32 || _WIN64 || __WIN32__ || __WIN64__
#if defined(WIN32) || defined(WIN64) || defined(_WIN32) || defined(_WIN64) || defined(__WIN32__) || defined(__WIN64__)
# define WINDOWS
#endif
#if __QNX__ || __QNXNTO__
#if defined(__QNX__) || defined(__QNXNTO__)
# define QNX
#endif
#if __FreeBSD__
#ifdef __FreeBSD__
# define FREE_BSD
#endif
#if __APPLE__ || __MACH__
#if defined(__APPLE__) || defined(__MACH__)
# define MAC_OS
#endif
#ifndef WINDOWS
@@ -99,7 +99,7 @@
# endif
# endif
#endif
#if __GNUC__
#ifdef __GNUC__
# define CC_GCC
# define CC_GCC_VERSION ((__GNUC__ << 8) | __GNUC_MINOR__)
# if CC_GCC_VERSION > 0x025F // > 2.95
@@ -107,8 +107,25 @@
# define HAS_LOCALE
# endif
# endif
#elif _MSC_VER
# pragma GCC diagnostic ignored "-Wformat"
# pragma GCC diagnostic ignored "-Wformat-extra-args"
# pragma GCC diagnostic ignored "-Wstrict-aliasing"
#elif defined(_MSC_VER)
# define CC_VC
# 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)
#else
# define CC_OTHER
#endif
@@ -168,7 +185,7 @@
#include <set>
#include <map>
#ifdef WINDOWS
typedef int socklen_t;
typedef int socklen_t;
# include <conio.h>
# include <io.h>
# include <winsock2.h>
@@ -189,6 +206,7 @@ typedef int socklen_t;
# include <fcntl.h>
# include <sys/ioctl.h>
# include <net/if.h>
# include <ifaddrs.h>
#endif
#ifdef MAC_OS
# include <mach/mach_traps.h>
@@ -196,8 +214,8 @@ typedef int socklen_t;
# include <mach/clock.h>
# include <crt_externs.h>
# define environ (*_NSGetEnviron())
typedef long time_t;
extern clock_serv_t __pi_mac_clock;
typedef long time_t;
extern clock_serv_t __pi_mac_clock;
#endif
#ifndef QNX
# ifndef WINDOWS
@@ -212,7 +230,7 @@ extern clock_serv_t __pi_mac_clock;
# define PIP_TIMER_RT
#endif
#ifdef FREE_BSD
extern char ** environ;
extern char ** environ;
#endif
#include "pimonitor.h"
@@ -405,7 +423,7 @@ template<typename T> inline T piClamp(const T & v, const T & min, const T & max)
extern bool isPIInit;
//! global variable enabling output to piCout
extern bool piDebug;
extern PIP_EXPORT bool piDebug;
extern string ifconfigPath;
@@ -656,6 +674,9 @@ private:
//! Macro used for conditional (piDebug) output to PICout
#define piCout if (piDebug) PICout()
//! Macro used for conditional (piDebug and PIObject::debug()) output to PICout for subclasses of PIObject
#define piCoutObj if (piDebug && debug_) PICout()
class PIMutex;
extern PIMutex __PICout_mutex__;
@@ -664,25 +685,58 @@ namespace PICoutManipulators {
//! \brief Enum contains special characters
enum PIP_EXPORT PICoutSpecialChar {
Null /*! Null-character, '\\0' */,
NewLine /*! New line character, '\\n' */,
Tab /*! Tab character, '\\t' */,
Esc /*! Escape character, '\\e' */,
Quote /*! Quote character, '"' */
Null /*! Null-character, '\\0' */,
NewLine /*! New line character, '\\n' */,
Tab /*! Tab character, '\\t' */,
Esc /*! Escape character, '\\e' */,
Quote /*! Quote character, '"' */
};
//! \brief Enum contains immediate action
enum PIP_EXPORT PICoutAction {
Flush /*! Flush the output */
Flush /*! Flush the output */,
Backspace /*! Remove last symbol */,
ShowCursor /*! Show cursor */,
HideCursor /*! Hide cursor */
};
//! \brief Enum contains control of PICout
enum PIP_EXPORT PICoutControl {
AddNone /*! No controls */ = 0x0,
AddSpaces /*! Spaces will be appear after each output */ = 0x1,
AddNewLine /*! New line will be appear after all output */ = 0x2,
AddQuotes /*! Each string will be quoted */ = 0x4,
AddAll /*! All controls */ = 0xFFFFFFFF
AddNone /*! No controls */ = 0x0,
AddSpaces /*! Spaces will be appear after each output */ = 0x1,
AddNewLine /*! New line will be appear after all output */ = 0x2,
AddQuotes /*! Each string will be quoted */ = 0x4,
AddAll /*! All controls */ = 0xFFFFFFFF
};
//! \brief Enum contains output format
enum PIP_EXPORT PICoutFormat {
Bin /*! Binary representation of integers */ = 0x01,
Oct /*! Octal representation of integers */ = 0x02,
Dec /*! Decimal representation of integers */ = 0x04,
Hex /*! Hexadecimal representation of integers */ = 0x08,
Bold /*! Bold */ = 0x10,
Faint /*! */ = 0x20,
Italic /*! */ = 0x40,
Underline /*! Underline */ = 0x80,
Blink /*! Blink */ = 0x100,
Black /*! Black font */ = 0x400,
Red /*! Red font */ = 0x800,
Green /*! Green font */ = 0x1000,
Blue /*! Blue font */ = 0x2000,
Yellow /*! Yellow font */ = 0x4000,
Magenta /*! Magenta font */ = 0x8000,
Cyan /*! Cyan font */ = 0x10000,
White /*! White font */ = 0x20000,
BackBlack /*! Black background */ = 0x40000,
BackRed /*! Red background */ = 0x80000,
BackGreen /*! Green background */ = 0x100000,
BackBlue /*! Blue background */ = 0x200000,
BackYellow /*! Yellow background */ = 0x400000,
BackMagenta /*! Magenta background */ = 0x800000,
BackCyan /*! Cyan background */ = 0x1000000,
BackWhite /*! White background */ = 0x2000000,
Default /*! Default format */ = 0x4000000,
};
};
@@ -695,7 +749,7 @@ public:
//! Default constructor with default features
PICout(PIFlags<PICoutControl> controls = AddSpaces | AddNewLine);
PICout(const PICout & other): fo_(other.fo_), cc_(true), co_(other.co_) {;}
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
@@ -711,89 +765,141 @@ public:
PICout operator <<(const char v) {space(); std::cout << v; return *this;}
//! Output operator for <tt>"unsigned char"</tt> values
PICout operator <<(const uchar v) {space(); std::cout << ushort(v); return *this;}
PICout operator <<(const uchar v);
//! Output operator for <tt>"short"</tt> values
PICout operator <<(const short v) {space(); std::cout << v; return *this;}
PICout operator <<(const short v);
//! Output operator for <tt>"unsigned short"</tt> values
PICout operator <<(const ushort v) {space(); std::cout << v; return *this;}
PICout operator <<(const ushort v);
//! Output operator for <tt>"int"</tt> values
PICout operator <<(const int v) {space(); std::cout << v; return *this;}
PICout operator <<(const int v);
//! Output operator for <tt>"unsigned int"</tt> values
PICout operator <<(const uint v) {space(); std::cout << v; return *this;}
PICout operator <<(const uint v);
//! Output operator for <tt>"long"</tt> values
PICout operator <<(const long v) {space(); std::cout << v; return *this;}
PICout operator <<(const long v);
//! Output operator for <tt>"unsigned long"</tt> values
PICout operator <<(const ulong v) {space(); std::cout << v; return *this;}
PICout operator <<(const ulong v);
//! Output operator for <tt>"long long"</tt> values
PICout operator <<(const llong v) {space(); std::cout << v; return *this;}
PICout operator <<(const llong v);
//! Output operator for <tt>"unsigned long long"</tt> values
PICout operator <<(const ullong v) {space(); std::cout << v; return *this;}
PICout operator <<(const ullong v);
//! Output operator for <tt>"float"</tt> values
PICout operator <<(const float v) {space(); std::cout << v; return *this;}
PICout operator <<(const float v);
//! Output operator for <tt>"double"</tt> values
PICout operator <<(const double v) {space(); std::cout << v; return *this;}
PICout operator <<(const double v);
//! Output operator for \a PICoutSpecialChar values
PICout operator <<(const PICoutSpecialChar v) {
switch (v) {
case Null: std::cout << char(0);
case NewLine: std::cout << '\n';
case Tab: std::cout << '\t';
case Esc: std::cout << '\e';
case Quote: std::cout << '"';
case Null: std::cout << char(0); break;
case NewLine: std::cout << '\n'; fo_ = true; break;
case Tab: std::cout << '\t'; break;
case Esc:
#ifdef CC_VC
std::cout << char(27);
#else
std::cout << '\e';
#endif
break;
case Quote: std::cout << '"'; break;
};
return *this;
}
//! 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);
return *this;
}
//! Output operator for \a PICoutFormat values
PICout operator <<(const PICoutFormat v) {
switch (v) {
case Bin: cnb_ = 2; break;
case Oct: cnb_ = 8; break;
case Dec: cnb_ = 10; break;
case Hex: cnb_ = 16; break;
default: applyFormat(v);
};
return *this;
}
//! Do some action
PICout operator <<(const PICoutAction v) {
switch (v) {
case Flush: std::cout << std::flush;
};
return *this;
}
PICout operator <<(const PICoutAction v);
//! Set control flag "c" is "on" state
void setControl(PICoutControl c, bool on = true) {co_.setFlag(c, on);}
PICout & setControl(PICoutControl c, bool on = true) {co_.setFlag(c, on); return *this;}
//! Set control flags "c" and if "save" exec \a saveControl()
void setControl(PICoutControls c, bool save = false) {if (save) saveControl(); co_ = c;}
//! Set control flags "c" and if "save" exec \a saveControl()
PICout & setControl(PICoutControls c, bool save = false) {if (save) saveControl(); co_ = c; return *this;}
//! Save control flags to internal stack \sa \a restoreControl()
void saveControl() {cos_.push(co_);}
PICout & saveControl() {cos_.push(co_); return *this;}
//! Restore control flags from internal stack \sa \a saveControl()
void restoreControl() {if (!cos_.empty()) {co_ = cos_.top(); cos_.pop();}}
PICout & restoreControl() {if (!cos_.empty()) {co_ = cos_.top(); cos_.pop();} return *this;}
/*! \brief Conditional put space character to output
* \details If it is not a first output and control \a AddSpaces is set
* space character is put \sa \a quote(), \a newLine() */
inline void space() {if (!fo_ && co_[AddSpaces]) std::cout << ' '; fo_ = false;}
inline PICout & space() {if (!fo_ && co_[AddSpaces]) std::cout << ' '; fo_ = false; return *this;}
/*! \brief Conditional put quote character to output
* \details If control \a AddQuotes is set
* quote character is put \sa \a space(), \a newLine() */
inline void quote() {if (co_[AddQuotes]) std::cout << '"'; fo_ = false;}
inline PICout & quote() {if (co_[AddQuotes]) std::cout << '"'; fo_ = false; return *this;}
/*! \brief Conditional put new line character to output
* \details If control \a AddNewLine is set
* new line character is put \sa \a space(), \a quote() */
inline void newLine() {if (co_[AddNewLine]) std::cout << std::endl; fo_ = false;}
inline PICout & newLine() {if (co_[AddNewLine]) std::cout << std::endl; fo_ = false; return *this;}
private:
bool fo_, cc_;
void applyFormat(PICoutFormat f);
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
};
#endif // PIINCLUDES_H