git-svn-id: svn://db.shs.com.ru/pip@371 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5
This commit is contained in:
@@ -756,8 +756,6 @@ void PIConsole::addVariable(const PIString & name, const PIProtocol * ptr, int c
|
||||
addVariable("Integral Frequency, Hz", ptr->integralFrequency_ptr(), col, format);
|
||||
addVariable("Receive speed", ptr->receiveSpeed_ptr(), col, format);
|
||||
addVariable("Send speed", ptr->sendSpeed_ptr(), col, format);
|
||||
addVariable("Receiver history size", ptr->receiverHistorySize_ptr(), col, format);
|
||||
addVariable("Sender history size", ptr->senderHistorySize_ptr(), col, format);
|
||||
addVariable("Disconnect Timeout, s", ptr->disconnectTimeout_ptr(), col, format);
|
||||
addVariable("Quality", ptr->quality_ptr(), col, format);
|
||||
}
|
||||
|
||||
@@ -127,6 +127,12 @@ PRIVATE_DEFINITION_START(PIKbdListener)
|
||||
#else
|
||||
struct termios sterm, tterm;
|
||||
#endif
|
||||
#ifdef WINDOWS
|
||||
DWORD
|
||||
#else
|
||||
int
|
||||
#endif
|
||||
ret;
|
||||
PRIVATE_DEFINITION_END(PIKbdListener)
|
||||
|
||||
|
||||
@@ -174,7 +180,7 @@ void PIKbdListener::readKeyboard() {
|
||||
memset(rc, 0, 8);
|
||||
#ifdef WINDOWS
|
||||
INPUT_RECORD ir;
|
||||
ReadConsoleInput(PRIVATE->hIn, &ir, 1, &ret);
|
||||
ReadConsoleInput(PRIVATE->hIn, &ir, 1, &(PRIVATE->ret));
|
||||
if (ir.EventType == KEY_EVENT) {
|
||||
KEY_EVENT_RECORD ker = ir.Event.KeyEvent;
|
||||
if (ker.bKeyDown) {
|
||||
@@ -188,35 +194,35 @@ void PIKbdListener::readKeyboard() {
|
||||
if (ker.dwControlKeyState & CAPSLOCK_ON) shift = !shift;
|
||||
//piCout << "key" << int(ker.wVirtualKeyCode) << int(ker.uChar.AsciiChar);
|
||||
switch (ker.wVirtualKeyCode) {
|
||||
case 8: ret = 1; ke.key = Backspace; break;
|
||||
case 33: ret = 1; ke.key = PageUp; break;
|
||||
case 34: ret = 1; ke.key = PageDown; break;
|
||||
case 35: ret = 1; ke.key = End; break;
|
||||
case 36: ret = 1; ke.key = Home; break;
|
||||
case 37: ret = 1; ke.key = LeftArrow; break;
|
||||
case 38: ret = 1; ke.key = UpArrow; break;
|
||||
case 39: ret = 1; ke.key = RightArrow; break;
|
||||
case 40: ret = 1; ke.key = DownArrow; break;
|
||||
case 45: ret = 1; ke.key = Insert; break;
|
||||
case 46: ret = 1; ke.key = Delete; break;
|
||||
case 8: PRIVATE->ret = 1; ke.key = Backspace; break;
|
||||
case 33: PRIVATE->ret = 1; ke.key = PageUp; break;
|
||||
case 34: PRIVATE->ret = 1; ke.key = PageDown; break;
|
||||
case 35: PRIVATE->ret = 1; ke.key = End; break;
|
||||
case 36: PRIVATE->ret = 1; ke.key = Home; break;
|
||||
case 37: PRIVATE->ret = 1; ke.key = LeftArrow; break;
|
||||
case 38: PRIVATE->ret = 1; ke.key = UpArrow; break;
|
||||
case 39: PRIVATE->ret = 1; ke.key = RightArrow; break;
|
||||
case 40: PRIVATE->ret = 1; ke.key = DownArrow; break;
|
||||
case 45: PRIVATE->ret = 1; ke.key = Insert; break;
|
||||
case 46: PRIVATE->ret = 1; ke.key = Delete; break;
|
||||
case '\r':
|
||||
case '\n': ret = 1; ke.key = Return; break;
|
||||
case ' ': ret = 1; ke.key = Space; break;
|
||||
case '\t': ret = 1; ke.key = Tab; break;
|
||||
case 112: ret = 1; ke.key = F1; break;
|
||||
case 113: ret = 1; ke.key = F2; break;
|
||||
case 114: ret = 1; ke.key = F3; break;
|
||||
case 115: ret = 1; ke.key = F4; break;
|
||||
case 116: ret = 1; ke.key = F5; break;
|
||||
case 117: ret = 1; ke.key = F6; break;
|
||||
case 118: ret = 1; ke.key = F7; break;
|
||||
case 119: ret = 1; ke.key = F8; break;
|
||||
case 120: ret = 1; ke.key = F9; break;
|
||||
case 121: ret = 1; ke.key = F10; break;
|
||||
case 122: ret = 1; ke.key = F11; break;
|
||||
case 123: ret = 1; ke.key = F12; break;
|
||||
case '\n': PRIVATE->ret = 1; ke.key = Return; break;
|
||||
case ' ': PRIVATE->ret = 1; ke.key = Space; break;
|
||||
case '\t': PRIVATE->ret = 1; ke.key = Tab; break;
|
||||
case 112: PRIVATE->ret = 1; ke.key = F1; break;
|
||||
case 113: PRIVATE->ret = 1; ke.key = F2; break;
|
||||
case 114: PRIVATE->ret = 1; ke.key = F3; break;
|
||||
case 115: PRIVATE->ret = 1; ke.key = F4; break;
|
||||
case 116: PRIVATE->ret = 1; ke.key = F5; break;
|
||||
case 117: PRIVATE->ret = 1; ke.key = F6; break;
|
||||
case 118: PRIVATE->ret = 1; ke.key = F7; break;
|
||||
case 119: PRIVATE->ret = 1; ke.key = F8; break;
|
||||
case 120: PRIVATE->ret = 1; ke.key = F9; break;
|
||||
case 121: PRIVATE->ret = 1; ke.key = F10; break;
|
||||
case 122: PRIVATE->ret = 1; ke.key = F11; break;
|
||||
case 123: PRIVATE->ret = 1; ke.key = F12; break;
|
||||
default:
|
||||
ret = 1;
|
||||
PRIVATE->ret = 1;
|
||||
rc[0] = 1;
|
||||
{
|
||||
PIChar ch = PIChar::fromConsole(ker.uChar.AsciiChar);
|
||||
@@ -229,28 +235,28 @@ void PIKbdListener::readKeyboard() {
|
||||
} else {piMSleep(10); return;}
|
||||
} else {piMSleep(10); return;}
|
||||
/*if (lc == 0) {
|
||||
ReadConsole(hIn, &rc, 1, &ret, 0);
|
||||
ReadConsole(hIn, &rc, 1, &(PRIVATE->ret), 0);
|
||||
//cout << "read console" << endl;
|
||||
lc = char(rc);
|
||||
}*/
|
||||
/*if (ret < 0 || ret > 3) return;
|
||||
lc = char(((uchar * )&rc)[ret - 1]);
|
||||
for (int i = 0; i < ret; ++i)
|
||||
/*if (PRIVATE->ret < 0 || PRIVATE->ret > 3) return;
|
||||
lc = char(((uchar * )&rc)[PRIVATE->ret - 1]);
|
||||
for (int i = 0; i < PRIVATE->ret; ++i)
|
||||
cout << std::hex << int(((uchar * )&rc)[i]) << ' ';
|
||||
cout << endl << std::hex << rc << endl;*/
|
||||
#else
|
||||
tcsetattr(0, TCSANOW, &PRIVATE->tterm);
|
||||
ret = read(0, rc, 8);
|
||||
PRIVATE->ret = read(0, rc, 8);
|
||||
//piCout << "key" << PIString(rc).replaceAll("\e", "\\e");
|
||||
/*for (int i = 0; i < ret; ++i)
|
||||
/*for (int i = 0; i < PRIVATE->ret; ++i)
|
||||
cout << std::hex << int(((uchar * )&rc)[i]) << ' ';
|
||||
cout << endl;
|
||||
for (int i = 0; i < ret; ++i)
|
||||
for (int i = 0; i < PRIVATE->ret; ++i)
|
||||
cout << "'" << (char)(rc[i]) << "' ";
|
||||
cout << endl;*/
|
||||
if (rc[0] == 0) {piMSleep(10); return;}
|
||||
if (ret < 0 || ret > 7) {piMSleep(10); return;}
|
||||
if (ret == 1) ke.key = PIChar::fromConsole(rc[0]).unicode16Code();
|
||||
if (PRIVATE->ret < 0 || PRIVATE->ret > 7) {piMSleep(10); return;}
|
||||
if (PRIVATE->ret == 1) ke.key = PIChar::fromConsole(rc[0]).unicode16Code();
|
||||
int mod(0);
|
||||
// 2 - shift 1
|
||||
// 3 - alt 2
|
||||
@@ -258,14 +264,14 @@ void PIKbdListener::readKeyboard() {
|
||||
// 5 - ctrl 4
|
||||
// 8 - ctrl+alt+shift 7
|
||||
if (rc[0] == '\e') { // search for Alt
|
||||
if (ret == 2) {
|
||||
if (PRIVATE->ret == 2) {
|
||||
mod = 2;
|
||||
ke.key = PIChar::fromConsole(rc[1]).unicode16Code();
|
||||
} else {// escape-seq
|
||||
if (rc[1] == '\e') { // search for Alt
|
||||
for (int i = 1; i < 7; ++i) rc[i] = rc[i + 1];
|
||||
mod = 2;
|
||||
ret--;
|
||||
PRIVATE->ret--;
|
||||
}
|
||||
if (rc[1] == '[') {
|
||||
for (int i = 2; i < 7; ++i) // search for modifier
|
||||
@@ -273,16 +279,16 @@ void PIKbdListener::readKeyboard() {
|
||||
mod |= rc[i + 1] - '0' - 1;
|
||||
for (int j = i; j < 6; ++j) rc[j] = rc[j + 2];
|
||||
rc[6] = rc[7] = 0;
|
||||
ret -= 2;
|
||||
PRIVATE->ret -= 2;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (ret >= 3 && rc[1] == 'O') { // search for modifier (F1-F4)
|
||||
if (PRIVATE->ret >= 3 && rc[1] == 'O') { // search for modifier (F1-F4)
|
||||
if (rc[2] >= '1' && rc[2] <= '8') {
|
||||
mod |= rc[2] - '0' - 1;
|
||||
for (int j = 2; j < 6; ++j) rc[j] = rc[j + 1];
|
||||
rc[7] = 0;
|
||||
ret--;
|
||||
PRIVATE->ret--;
|
||||
}
|
||||
}
|
||||
for (int i = 0; ; ++i) {
|
||||
@@ -302,20 +308,20 @@ void PIKbdListener::readKeyboard() {
|
||||
//if (mod & 0x8) ke.modifiers |= Meta;
|
||||
}
|
||||
/*cout << "wo mods (" << mod << ")\n";
|
||||
for (int i = 0; i < ret; ++i)
|
||||
for (int i = 0; i < PRIVATE->ret; ++i)
|
||||
cout << "'" << (char)(rc[i]) << "' ";
|
||||
cout << endl;*/
|
||||
}
|
||||
if (ke.key == 0 && ret > 1)
|
||||
if (ke.key == 0 && PRIVATE->ret > 1)
|
||||
ke.key = PIChar(rc).unicode16Code();
|
||||
#endif
|
||||
if ((rc[0] == '\n' || rc[0] == '\r') && ret == 1)
|
||||
if ((rc[0] == '\n' || rc[0] == '\r') && PRIVATE->ret == 1)
|
||||
ke.key = Return;
|
||||
if (exit_enabled && ke.key == exit_key) {
|
||||
PIKbdListener::exiting = true;
|
||||
return;
|
||||
}
|
||||
if (ret > 0) {
|
||||
if (PRIVATE->ret > 0) {
|
||||
keyPressed(ke, kbddata_);
|
||||
if (ret_func != 0) ret_func(ke, kbddata_);
|
||||
}
|
||||
|
||||
@@ -176,12 +176,6 @@ private:
|
||||
#endif
|
||||
|
||||
PRIVATE_DECLARATION
|
||||
#ifdef WINDOWS
|
||||
DWORD
|
||||
#else
|
||||
int
|
||||
#endif
|
||||
ret;
|
||||
KBFunc ret_func;
|
||||
int exit_key;
|
||||
bool exit_enabled, is_active;
|
||||
|
||||
@@ -242,7 +242,7 @@ void PIScreen::SystemConsole::print() {
|
||||
#ifdef WINDOWS
|
||||
#define FOREGROUND_MASK (FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE)
|
||||
#define BACKGROUND_MASK (BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE)
|
||||
WORD PIScreen::SystemConsole::attributes(const PIScreenTypes::Cell & c) {
|
||||
ushort PIScreen::SystemConsole::attributes(const PIScreenTypes::Cell & c) {
|
||||
WORD attr = PRIVATE->dattr;
|
||||
if (c.format.flags & Bold) attr |= FOREGROUND_INTENSITY;
|
||||
else attr &= ~FOREGROUND_INTENSITY;
|
||||
|
||||
@@ -118,7 +118,7 @@ private:
|
||||
void newLine();
|
||||
void hideCursor();
|
||||
void showCursor();
|
||||
WORD attributes(const PIScreenTypes::Cell & c);
|
||||
ushort attributes(const PIScreenTypes::Cell & c);
|
||||
#else
|
||||
void toUpperLeft() {printf("\e[H");}
|
||||
void moveTo(int x = 0, int y = 0) {printf("\e[%d;%dH", y + 1, x + 1);}
|
||||
|
||||
@@ -35,6 +35,7 @@
|
||||
#endif
|
||||
#include <malloc.h>
|
||||
#include <string.h>
|
||||
#include <new>
|
||||
#ifndef PIP_MEMALIGN_BYTES
|
||||
# define PIP_MEMALIGN_BYTES (sizeof(void*)*4)
|
||||
#endif
|
||||
|
||||
@@ -21,12 +21,12 @@
|
||||
#include "piconsole.h"
|
||||
#include "pibytearray.h"
|
||||
#include "pistack.h"
|
||||
#include "pistring_std.h"
|
||||
#ifdef WINDOWS
|
||||
# include <windows.h>
|
||||
# include <wincon.h>
|
||||
# define COMMON_LVB_UNDERSCORE 0x8000
|
||||
#endif
|
||||
#include <iostream>
|
||||
|
||||
/*! \class PICout
|
||||
* \brief Class for formatted output similar std::cout
|
||||
@@ -195,7 +195,7 @@ PICout PICout::operator <<(const PICoutAction v) {
|
||||
|
||||
PICout PICout::operator <<(const char * v) {if (v[0] == '\0') return *this; 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 std::string & v) {space(); quote(); if (PICout::buffer_) __PICout_string__ << StdString2PIString(v); else std::cout << (v); quote(); return *this;}
|
||||
|
||||
PICout PICout::operator <<(const bool v) {space(); if (v) PICOUTTOTARGET("true") else PICOUTTOTARGET("false") return *this;}
|
||||
|
||||
|
||||
@@ -18,10 +18,7 @@
|
||||
*/
|
||||
|
||||
#include "piincludes.h"
|
||||
#ifdef WINDOWS
|
||||
# include <windef.h>
|
||||
# include <winbase.h>
|
||||
#endif
|
||||
#include "piincludes_p.h"
|
||||
#include "piconsole.h"
|
||||
#include "pitime.h"
|
||||
#ifndef QNX
|
||||
|
||||
@@ -18,14 +18,19 @@
|
||||
*/
|
||||
#ifndef PIINCLUDES_P_H
|
||||
#define PIINCLUDES_P_H
|
||||
|
||||
|
||||
#include "pibase.h"
|
||||
#ifdef WINDOWS
|
||||
# include <windef.h>
|
||||
# include <winbase.h>
|
||||
typedef void(*PINtSetTimerResolution)(ULONG, BOOLEAN, PULONG);
|
||||
#endif
|
||||
#ifdef CC_GCC
|
||||
# include <unistd.h>
|
||||
#endif
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
|
||||
|
||||
#endif // PIINCLUDES_P_H
|
||||
|
||||
@@ -56,7 +56,6 @@ handler A: event to event
|
||||
|
||||
|
||||
PIVector<PIObject * > PIObject::objects;
|
||||
PIMutex PIObject::__eh_mutex;
|
||||
PIMap<PIString, PIObject::__EHData> PIObject::__eh_data;
|
||||
|
||||
|
||||
@@ -147,7 +146,7 @@ PIStringList PIObject::events() {
|
||||
*/
|
||||
|
||||
PIStringList PIObject::methodsEH() {
|
||||
PIMutexLocker ml(__eh_mutex);
|
||||
PIMutexLocker ml(__eh_mutex());
|
||||
PIStringList ret;
|
||||
__EHData & ehd(__eh_data[className()]);
|
||||
piForeachC (__EHPair & eh, ehd.eh_func)
|
||||
@@ -157,7 +156,7 @@ PIStringList PIObject::methodsEH() {
|
||||
|
||||
|
||||
bool PIObject::isMethodEHContains(const PIString & name) const {
|
||||
PIMutexLocker ml(__eh_mutex);
|
||||
PIMutexLocker ml(__eh_mutex());
|
||||
__EHData & ehd(__eh_data[className()]);
|
||||
piForeachC (__EHPair & eh, ehd.eh_func)
|
||||
if (eh.second.func_name == name)
|
||||
@@ -167,7 +166,7 @@ bool PIObject::isMethodEHContains(const PIString & name) const {
|
||||
|
||||
|
||||
PIString PIObject::methodEHArguments(const PIString & name) const {
|
||||
PIMutexLocker ml(__eh_mutex);
|
||||
PIMutexLocker ml(__eh_mutex());
|
||||
__EHData & ehd(__eh_data[className()]);
|
||||
piForeachC (__EHPair & eh, ehd.eh_func)
|
||||
if (eh.second.func_name == name)
|
||||
@@ -177,7 +176,7 @@ PIString PIObject::methodEHArguments(const PIString & name) const {
|
||||
|
||||
|
||||
PIString PIObject::methodEHFullFormat(const PIString & name) const {
|
||||
PIMutexLocker ml(__eh_mutex);
|
||||
PIMutexLocker ml(__eh_mutex());
|
||||
__EHData & ehd(__eh_data[className()]);
|
||||
piForeachC (__EHPair & eh, ehd.eh_func)
|
||||
if (eh.second.func_name == name)
|
||||
@@ -202,7 +201,7 @@ PIVector<PIObject::__EHFunc> PIObject::findEH(const PIString & name) const {
|
||||
|
||||
|
||||
PIObject::__EHFunc PIObject::methodEH(const void * addr) const {
|
||||
PIMutexLocker ml(__eh_mutex);
|
||||
PIMutexLocker ml(__eh_mutex());
|
||||
return __eh_data[className()].eh_func.value(addr);
|
||||
}
|
||||
|
||||
@@ -233,7 +232,7 @@ bool PIObject::piConnectU(PIObject * src, const PIString & ename, PIObject * des
|
||||
piCout << "[piConnectU] \"" << ename << "\" -> \"" << hname << "\" error: destination object is not PIObject! (" << loc << ")";
|
||||
return false;
|
||||
}
|
||||
PIMutexLocker ml(__eh_mutex);
|
||||
PIMutexLocker ml(__eh_mutex());
|
||||
PIMutexLocker mls(src->mutex_connect);
|
||||
PIMutexLocker mld(dest_o->mutex_connect, src != dest_o);
|
||||
PIVector<__EHFunc> m_src = src->findEH(ename), m_dest = dest_o->findEH(hname);
|
||||
@@ -352,6 +351,12 @@ void PIObject::updateConnectors() {
|
||||
}
|
||||
|
||||
|
||||
PIMutex & PIObject::__eh_mutex() {
|
||||
static PIMutex ret;
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
PIString PIObject::simplifyType(const char * a) {
|
||||
PIString ret = PIStringAscii(a).trim();
|
||||
int white = -1;
|
||||
|
||||
@@ -196,7 +196,7 @@
|
||||
__##name##_ParentInitializer__() { \
|
||||
PIString pn(name::__classNameS()); \
|
||||
if (pn.isEmpty()) return; \
|
||||
PIMutexLocker ml(__eh_mutex); \
|
||||
PIMutexLocker ml(__eh_mutex()); \
|
||||
if (__eh_data.contains(__classNameS())) return; \
|
||||
__eh_data[pn]; \
|
||||
__eh_data[__classNameS()]; \
|
||||
@@ -218,7 +218,7 @@
|
||||
class __##name##0_Initializer__ { \
|
||||
public: \
|
||||
__##name##0_Initializer__() { \
|
||||
PIMutexLocker ml(__eh_mutex); \
|
||||
PIMutexLocker ml(__eh_mutex()); \
|
||||
__EHData & eh(__eh_data[__classNameS()]); \
|
||||
void * fp = (void*)(ret(*)(void*))__stat_eh_##name##__; \
|
||||
if (eh.eh_set[fp]) return; \
|
||||
@@ -236,7 +236,7 @@
|
||||
class __##name##1##n0##_Initializer__ { \
|
||||
public: \
|
||||
__##name##1##n0##_Initializer__() { \
|
||||
PIMutexLocker ml(__eh_mutex); \
|
||||
PIMutexLocker ml(__eh_mutex()); \
|
||||
__EHData & eh(__eh_data[__classNameS()]); \
|
||||
void * fp = (void*)(ret(*)(void*, a0))__stat_eh_##name##__; \
|
||||
if (eh.eh_set[fp]) return; \
|
||||
@@ -256,7 +256,7 @@
|
||||
class __##name##2##n0##n1##_Initializer__ { \
|
||||
public: \
|
||||
__##name##2##n0##n1##_Initializer__() { \
|
||||
PIMutexLocker ml(__eh_mutex); \
|
||||
PIMutexLocker ml(__eh_mutex()); \
|
||||
__EHData & eh(__eh_data[__classNameS()]); \
|
||||
void * fp = (void*)(ret(*)(void*, a0, a1))__stat_eh_##name##__; \
|
||||
if (eh.eh_set[fp]) return; \
|
||||
@@ -276,7 +276,7 @@
|
||||
class __##name##3##n0##n1##n2##_Initializer__ { \
|
||||
public: \
|
||||
__##name##3##n0##n1##n2##_Initializer__() { \
|
||||
PIMutexLocker ml(__eh_mutex); \
|
||||
PIMutexLocker ml(__eh_mutex()); \
|
||||
__EHData & eh(__eh_data[__classNameS()]); \
|
||||
void * fp = (void*)(ret(*)(void*, a0, a1, a2))__stat_eh_##name##__; \
|
||||
if (eh.eh_set[fp]) return; \
|
||||
@@ -296,7 +296,7 @@
|
||||
class __##name##4##n0##n1##n2##n3##_Initializer__ { \
|
||||
public: \
|
||||
__##name##4##n0##n1##n2##n3##_Initializer__() { \
|
||||
PIMutexLocker ml(__eh_mutex); \
|
||||
PIMutexLocker ml(__eh_mutex()); \
|
||||
__EHData & eh(__eh_data[__classNameS()]); \
|
||||
void * fp = (void*)(ret(*)(void*, a0, a1, a2, a3))__stat_eh_##name##__; \
|
||||
if (eh.eh_set[fp]) return; \
|
||||
@@ -665,7 +665,7 @@ public:
|
||||
return i;
|
||||
}
|
||||
return 0;
|
||||
};
|
||||
}
|
||||
|
||||
bool isPIObject() const {return isPIObject(this);}
|
||||
bool execute(const PIString & method);
|
||||
@@ -675,6 +675,8 @@ public:
|
||||
static bool execute(void * o, const PIString & method) {return ((PIObject*)o)->execute(method);}
|
||||
static PIString simplifyType(const char * a);
|
||||
|
||||
static PIMutex & __eh_mutex();
|
||||
|
||||
struct __EHFunc {
|
||||
__EHFunc(): addr(0) {;}
|
||||
bool isNull() const {return addr == 0;}
|
||||
@@ -693,7 +695,6 @@ public:
|
||||
};
|
||||
typedef PIPair<const void * , __EHFunc> __EHPair;
|
||||
static PIMap<PIString, __EHData> __eh_data;
|
||||
static PIMutex __eh_mutex;
|
||||
|
||||
protected:
|
||||
|
||||
@@ -739,7 +740,7 @@ private:
|
||||
PIVector<__EHFunc> findEH(const PIString & name) const;
|
||||
__EHFunc methodEH(const void * addr) const;
|
||||
void updateConnectors();
|
||||
|
||||
|
||||
PIVector<Connection> connections;
|
||||
typedef PIPair<PIString, PIVariant> Property;
|
||||
PIMap<PIString, PIVariant> properties_;
|
||||
|
||||
@@ -356,32 +356,11 @@ PIString & PIString::operator +=(const wchar_t * str) {
|
||||
}
|
||||
|
||||
|
||||
#ifdef HAS_LOCALE
|
||||
PIString & PIString::operator +=(const wstring & str) {
|
||||
uint l = str.size();
|
||||
for (uint i = 0; i < l; ++i) push_back(str[i]);
|
||||
return *this;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
PIString & PIString::operator +=(const PIString & str) {
|
||||
//uint l = str.size();
|
||||
*((PIDeque<PIChar>*)this) << *((PIDeque<PIChar>*)&str);
|
||||
return *this;
|
||||
}
|
||||
|
||||
/*
|
||||
#ifdef WINDOWS
|
||||
PIString & PIString::operator +=(const WCHAR * str) {
|
||||
int l = 0;
|
||||
while (str[l] != 0) ++l;
|
||||
for (int i = 0; i < l; ++i)
|
||||
push_back(str[i]);
|
||||
return *this;
|
||||
}
|
||||
#endif
|
||||
*/
|
||||
|
||||
bool PIString::operator ==(const PIString & str) const {
|
||||
uint l = str.size();
|
||||
@@ -429,12 +408,6 @@ bool PIString::operator >(const PIString & str) const {
|
||||
}
|
||||
|
||||
|
||||
PIString &PIString::operator +=(const std::string & str) {
|
||||
appendFromChars(str.c_str(), str.length());
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
PIString PIString::mid(const int start, const int len) const {
|
||||
//PIString str;
|
||||
int s = start, l = len;
|
||||
@@ -844,39 +817,6 @@ PIString PIString::toLowerCase() const {
|
||||
}
|
||||
|
||||
|
||||
std::string PIString::convertToStd() const {
|
||||
std::string s;
|
||||
uint wc;
|
||||
uchar tc;
|
||||
if (size() > 0) {
|
||||
for (int i = 0; i < length(); ++i) {
|
||||
wc = uint(at(i).unicode16Code());
|
||||
while (tc = wc & 0xFF, tc) {
|
||||
s.push_back(char(tc));
|
||||
wc >>= 8;
|
||||
}
|
||||
/*if (at(i).isAscii())
|
||||
s.push_back(at(i).toAscii());
|
||||
else {
|
||||
s.push_back(at(i).toCharPtr()[0]);
|
||||
s.push_back(at(i).toCharPtr()[1]);
|
||||
}*/
|
||||
}
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
#ifdef HAS_LOCALE
|
||||
std::wstring PIString::convertToWString() const {
|
||||
std::wstring s;
|
||||
for (int i = 0; i < length(); ++i)
|
||||
s.push_back(at(i).toWChar());
|
||||
return s;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
char PIString::toChar() const {
|
||||
PIString s(toNativeDecimalPoints());
|
||||
char v;
|
||||
@@ -884,6 +824,21 @@ char PIString::toChar() const {
|
||||
return v;
|
||||
}
|
||||
|
||||
|
||||
float PIString::toFloat() const {
|
||||
return (float)atof(toNativeDecimalPoints().data());
|
||||
}
|
||||
|
||||
|
||||
double PIString::toDouble() const {
|
||||
return atof(toNativeDecimalPoints().data());
|
||||
}
|
||||
|
||||
|
||||
ldouble PIString::toLDouble() const {
|
||||
return atof(toNativeDecimalPoints().data());
|
||||
}
|
||||
|
||||
/*
|
||||
short PIString::toShort() const {
|
||||
PIString s(trimmed().toLowerCase().toNativeDecimalPoints());
|
||||
@@ -1002,13 +957,3 @@ PIStringList& PIStringList::removeDuplicates() {
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
std::ostream &operator <<(std::ostream & s, const PIStringList & v) {
|
||||
s << "{";
|
||||
for (uint i = 0; i < v.size(); ++i) {
|
||||
s << "\"" << v[i] << "\"";
|
||||
if (i < v.size() - 1) s << ", ";
|
||||
}
|
||||
s << "}";
|
||||
return s;
|
||||
}
|
||||
|
||||
@@ -27,10 +27,7 @@
|
||||
|
||||
#include "pibytearray.h"
|
||||
#define PIStringAscii PIString::fromAscii
|
||||
#include <string>
|
||||
#ifdef QNX
|
||||
typedef std::basic_string<wchar_t> wstring;
|
||||
#endif
|
||||
|
||||
|
||||
class PIStringList;
|
||||
|
||||
@@ -45,12 +42,8 @@ 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 std::string & str);
|
||||
PIString & operator +=(const PIByteArray & ba) {appendFromChars((const char * )ba.data(), ba.size_s()); return *this;}
|
||||
PIString & operator +=(const PIString & str);
|
||||
#ifdef HAS_LOCALE
|
||||
PIString & operator +=(const std::wstring & str);
|
||||
#endif
|
||||
|
||||
//PIString(const char c) {*this += c;}
|
||||
PIString(const PIString & o): PIDeque<PIChar>() {/*reserve(4); */piMonitor.strings++; piMonitor.containers--; *this += o;}
|
||||
@@ -69,13 +62,6 @@ public:
|
||||
* \details "str" should be null-terminated\n
|
||||
* Example: \snippet pistring.cpp PIString(wchar_t * ) */
|
||||
PIString(const wchar_t * str): PIDeque<PIChar>() {/*reserve(4); */piMonitor.strings++; piMonitor.containers--; *this += str;}
|
||||
|
||||
//! Contructs string from std::string "str"
|
||||
PIString(const std::string & str): PIDeque<PIChar>() {/*reserve(4); */piMonitor.strings++; piMonitor.containers--; *this += str;}
|
||||
|
||||
#ifdef HAS_LOCALE
|
||||
PIString(const wstring & str): PIDeque<PIChar>() {/*reserve(4); */piMonitor.strings++; piMonitor.containers--; *this += str;}
|
||||
#endif
|
||||
|
||||
//! Contructs string from byte array "ba"
|
||||
PIString(const PIByteArray & ba): PIDeque<PIChar>() {/*reserve(4); */piMonitor.strings++; piMonitor.containers--; *this += ba;}
|
||||
@@ -94,14 +80,8 @@ public:
|
||||
/*! \brief Contructs string as sequence of symbols "c" of buffer with length "len"
|
||||
* \details Example: \snippet pistring.cpp PIString(int, PIChar) */
|
||||
PIString(const int len, const PIChar & c): PIDeque<PIChar>() {/*reserve(4); */piMonitor.strings++; piMonitor.containers--; for (int i = 0; i < len; ++i) push_back(c);}
|
||||
/*
|
||||
#ifdef WINDOWS
|
||||
PIString(const WCHAR * str): PIDeque<PIChar>() {piMonitor.strings++; piMonitor.containers--; *this += str;}
|
||||
PIString & operator +=(const WCHAR * str);
|
||||
PIString & operator <<(const WCHAR * str) {*this += str; return *this;}
|
||||
#endif
|
||||
*/
|
||||
|
||||
|
||||
|
||||
PIString(const short & value): PIDeque<PIChar>() {/*reserve(4); */piMonitor.strings++; piMonitor.containers--; *this = fromNumber(value);}
|
||||
PIString(const ushort & value): PIDeque<PIChar>() {/*reserve(4); */piMonitor.strings++; piMonitor.containers--; *this = fromNumber(value);}
|
||||
PIString(const int & value): PIDeque<PIChar>() {/*reserve(4); */piMonitor.strings++; piMonitor.containers--; *this = fromNumber(value);}
|
||||
@@ -125,9 +105,6 @@ public:
|
||||
* or execution \a data() or \a toByteArray().\n
|
||||
* Example: \snippet pistring.cpp PIString::char* */
|
||||
operator const char*() {return data();}
|
||||
|
||||
//! Return std::string representation of string
|
||||
//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);}
|
||||
@@ -145,10 +122,6 @@ public:
|
||||
//! Compare operator
|
||||
bool operator ==(const char * str) const {return *this == PIString(str);}
|
||||
|
||||
//! Compare operator
|
||||
bool operator ==(const std::string & str) const {return *this == PIString(str);}
|
||||
|
||||
|
||||
//! Compare operator
|
||||
bool operator !=(const PIString & str) const;
|
||||
|
||||
@@ -159,10 +132,6 @@ public:
|
||||
//! Compare operator
|
||||
bool operator !=(const char * str) const {return *this != PIString(str);}
|
||||
|
||||
//! Compare operator
|
||||
bool operator !=(const std::string & str) const {return *this != PIString(str);}
|
||||
|
||||
|
||||
//! Compare operator
|
||||
bool operator <(const PIString & str) const;
|
||||
|
||||
@@ -173,10 +142,6 @@ public:
|
||||
//! Compare operator
|
||||
bool operator <(const char * str) const {return *this < PIString(str);}
|
||||
|
||||
//! Compare operator
|
||||
bool operator <(const std::string & str) const {return *this < PIString(str);}
|
||||
|
||||
|
||||
//! Compare operator
|
||||
bool operator >(const PIString & str) const;
|
||||
|
||||
@@ -187,10 +152,6 @@ public:
|
||||
//! Compare operator
|
||||
bool operator >(const char * str) const {return *this > PIString(str);}
|
||||
|
||||
//! Compare operator
|
||||
bool operator >(const std::string & str) const {return *this > PIString(str);}
|
||||
|
||||
|
||||
//! Compare operator
|
||||
bool operator <=(const PIString & str) const {return !(*this > str);}
|
||||
|
||||
@@ -201,10 +162,6 @@ public:
|
||||
//! Compare operator
|
||||
bool operator <=(const char * str) const {return *this <= PIString(str);}
|
||||
|
||||
//! Compare operator
|
||||
bool operator <=(const std::string & str) const {return *this <= PIString(str);}
|
||||
|
||||
|
||||
//! Compare operator
|
||||
bool operator >=(const PIString & str) const {return !(*this < str);}
|
||||
|
||||
@@ -215,9 +172,6 @@ public:
|
||||
//! Compare operator
|
||||
bool operator >=(const char * str) const {return *this >= PIString(str);}
|
||||
|
||||
//! Compare operator
|
||||
bool operator >=(const std::string & str) const {return *this >= PIString(str);}
|
||||
|
||||
|
||||
operator bool() const {return toBool();}
|
||||
operator short() const {return toShort();}
|
||||
@@ -248,9 +202,6 @@ public:
|
||||
/*! \brief Append \c wchar_t c-string "str" at the end of string
|
||||
* \details Example: \snippet pistring.cpp PIString::<<(wchar_t * ) */
|
||||
PIString & operator <<(const wchar_t * str) {*this += str; return *this;}
|
||||
|
||||
//! Append std::string "str" at the end of string
|
||||
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) */
|
||||
@@ -497,12 +448,6 @@ public:
|
||||
* execution of this function.\n */
|
||||
const char * dataAscii() const;
|
||||
|
||||
//! \brief Return \c std::string representation of this string
|
||||
std::string stdString() const {return convertToStd();}
|
||||
|
||||
#ifdef HAS_LOCALE
|
||||
wstring stdWString() const {return convertToWString();}
|
||||
#endif
|
||||
|
||||
//! \brief Return \a PIByteArray contains \a data() of this string without terminating null-char
|
||||
PIByteArray toByteArray() const {buildData(); return data_.resized(data_.size_s() - 1);}
|
||||
@@ -619,15 +564,15 @@ public:
|
||||
|
||||
//! \brief Return \c float numeric value of string
|
||||
//! \details Example: \snippet pistring.cpp PIString::toFloat
|
||||
float toFloat() const {return (float)atof(toNativeDecimalPoints().data());}
|
||||
float toFloat() const;
|
||||
|
||||
//! \brief Return \c double numeric value of string
|
||||
//! \details Example: \snippet pistring.cpp PIString::toFloat
|
||||
double toDouble() const {return atof(toNativeDecimalPoints().data());}
|
||||
double toDouble() const;
|
||||
|
||||
//! \brief Return \c ldouble numeric value of string
|
||||
//! \details Example: \snippet pistring.cpp PIString::toFloat
|
||||
ldouble toLDouble() const {return atof(toNativeDecimalPoints().data());}
|
||||
ldouble toLDouble() const;
|
||||
|
||||
//inline PIString & setNumber(const char value) {clear(); *this += itos(value); return *this;}
|
||||
|
||||
@@ -838,24 +783,10 @@ private:
|
||||
void appendFromChars(const char * c, int s, const char * cp = 0);
|
||||
void buildData(const char * cp = 0) const;
|
||||
void trimsubstr(int &st, int &fn) const;
|
||||
std::string convertToStd() const;
|
||||
#ifdef HAS_LOCALE
|
||||
std::wstring convertToWString() const;
|
||||
#endif
|
||||
|
||||
mutable PIByteArray data_;
|
||||
//string std_string;
|
||||
//wstring std_wstring;
|
||||
|
||||
};
|
||||
|
||||
|
||||
//! \relatesalso PIString \brief Output operator to std::ostream (cout)
|
||||
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) {std::string ss; s >> ss; v << PIString(ss); return s;}
|
||||
|
||||
//! \relatesalso PIString \relatesalso PICout \brief Output operator to PICout
|
||||
PICout operator <<(PICout s, const PIString & v);
|
||||
|
||||
@@ -875,17 +806,11 @@ inline PIString operator +(const PIString & str, const PIString & f) {PIString s
|
||||
//! \relatesalso PIString \brief Return concatenated string
|
||||
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 std::string & str) {PIString s(f); s += str; return s;}
|
||||
|
||||
//inline PIString operator +(const char c, const PIString & f) {return PIString(c) + f;}
|
||||
|
||||
//! \relatesalso PIString \brief Return concatenated string
|
||||
inline PIString operator +(const char * str, const PIString & f) {return PIString(str) + f;}
|
||||
|
||||
//! \relatesalso PIString \brief Return concatenated string
|
||||
inline PIString operator +(const std::string & str, const PIString & f) {return PIString(str) + f;}
|
||||
|
||||
inline char chrUpr(char c);
|
||||
inline char chrLwr(char c);
|
||||
|
||||
@@ -951,7 +876,6 @@ 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 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;}
|
||||
@@ -967,10 +891,6 @@ inline PIByteArray & operator <<(PIByteArray & s, const PIStringList & v) {s <<
|
||||
//! \relatesalso PIStringList \relatesalso PIByteArray \brief Input operator from PIByteArray
|
||||
inline PIByteArray & operator >>(PIByteArray & s, PIStringList & v) {int sz; s >> sz; v.resize(sz); for (int i = 0; i < sz; ++i) s >> v[i]; return s;}
|
||||
|
||||
|
||||
//! \relatesalso PIStringList \brief Output operator to std::ostream (cout)
|
||||
std::ostream & operator <<(std::ostream & s, const PIStringList & v);
|
||||
|
||||
//! \relatesalso PIStringList \relatesalso PICout \brief Output operator to PICout
|
||||
inline PICout operator <<(PICout s, const PIStringList & v) {s.space(); s.setControl(0, true); s << "{"; for (uint i = 0; i < v.size(); ++i) {s << "\"" << v[i] << "\""; if (i < v.size() - 1) s << ", ";} s << "}"; s.restoreControl(); return s;}
|
||||
|
||||
|
||||
81
src/core/pistring_std.h
Normal file
81
src/core/pistring_std.h
Normal file
@@ -0,0 +1,81 @@
|
||||
#ifndef PISTRING2STD_H
|
||||
#define PISTRING2STD_H
|
||||
#include <string>
|
||||
#ifdef QNX
|
||||
typedef std::basic_string<wchar_t> wstring;
|
||||
#endif
|
||||
|
||||
#include "pistring.h"
|
||||
|
||||
|
||||
inline std::string PIString2StdString(const PIString & v) {
|
||||
std::string s;
|
||||
uint wc;
|
||||
uchar tc;
|
||||
if (v.size() > 0) {
|
||||
for (int i = 0; i < v.length(); ++i) {
|
||||
wc = uint(v.at(i).unicode16Code());
|
||||
while (tc = wc & 0xFF, tc) {
|
||||
s.push_back(char(tc));
|
||||
wc >>= 8;
|
||||
}
|
||||
/*if (at(i).isAscii())
|
||||
s.push_back(at(i).toAscii());
|
||||
else {
|
||||
s.push_back(at(i).toCharPtr()[0]);
|
||||
s.push_back(at(i).toCharPtr()[1]);
|
||||
}*/
|
||||
}
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
inline PIString StdString2PIString(const std::string & v) {
|
||||
return PIString(v.c_str(), v.length());
|
||||
}
|
||||
|
||||
#ifdef HAS_LOCALE
|
||||
inline std::wstring PIString2StdWString(const PIString & v) {
|
||||
std::wstring s;
|
||||
for (int i = 0; i < v.length(); ++i)
|
||||
s.push_back(v.at(i).toWChar());
|
||||
return s;
|
||||
}
|
||||
|
||||
inline PIString StdWString2PIString(const std::wstring & v) {
|
||||
PIString s;
|
||||
uint l = v.size();
|
||||
for (uint i = 0; i < l; ++i) s.push_back(v[i]);
|
||||
return s;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
//! \relatesalso PIString \brief Return concatenated string
|
||||
inline PIString operator +(const PIString & f, const std::string & str) {PIString s(f); s += StdString2PIString(str); return s;}
|
||||
|
||||
//! \relatesalso PIString \brief Return concatenated string
|
||||
inline PIString operator +(const std::string & str, const PIString & f) {return StdString2PIString(str) + f;}
|
||||
|
||||
|
||||
//! \relatesalso PIString \brief Output operator to std::ostream (cout)
|
||||
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) {std::string ss; s >> ss; v = StdString2PIString(ss); return s;}
|
||||
|
||||
|
||||
//! \relatesalso PIStringList \brief Output operator to std::ostream (cout)
|
||||
inline std::ostream & operator <<(std::ostream & s, const PIStringList & v) {
|
||||
s << PIChar("{");
|
||||
for (uint i = 0; i < v.size(); ++i) {
|
||||
s << PIChar("\"") << v[i] << PIChar("\"");
|
||||
if (i < v.size() - 1) s << PIStringAscii(", ");
|
||||
}
|
||||
s << PIChar("}");
|
||||
return s;
|
||||
}
|
||||
|
||||
#endif // PISTRING2STD_H
|
||||
@@ -205,15 +205,6 @@ PIDateTime PIDateTime::current() {
|
||||
}
|
||||
|
||||
|
||||
#ifdef WINDOWS
|
||||
PISystemTime::PISystemTime(const FILETIME & t) {
|
||||
ullong lt = ullong(t.dwHighDateTime) * 0x100000000U + ullong(t.dwLowDateTime);
|
||||
seconds = lt / 10000000U;
|
||||
nanoseconds = (lt % 10000000U) * 100U;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
PISystemTime PISystemTime::abs() const {
|
||||
if (seconds < 0)
|
||||
return PISystemTime(piAbsl(seconds) - 1, 1000000000l - piAbsl(nanoseconds));
|
||||
@@ -312,56 +303,6 @@ PIString PIDateTime::toString(const PIString & format) const {
|
||||
}
|
||||
|
||||
|
||||
#ifdef WINDOWS
|
||||
PIDateTime::PIDateTime(SYSTEMTIME t) {
|
||||
year = t.wYear;
|
||||
month = t.wMonth;
|
||||
day = t.wDay;
|
||||
hours = t.wHour;
|
||||
minutes = t.wMinute;
|
||||
seconds = t.wSecond;
|
||||
milliseconds = t.wMilliseconds;
|
||||
}
|
||||
|
||||
|
||||
PIDateTime::PIDateTime(FILETIME t) {
|
||||
FILETIME lt;
|
||||
SYSTEMTIME st;
|
||||
FileTimeToLocalFileTime(&t, <);
|
||||
FileTimeToSystemTime(<, &st);
|
||||
year = st.wYear;
|
||||
month = st.wMonth;
|
||||
day = st.wDay;
|
||||
hours = st.wHour;
|
||||
minutes = st.wMinute;
|
||||
seconds = st.wSecond;
|
||||
milliseconds = st.wMilliseconds;
|
||||
}
|
||||
|
||||
|
||||
SYSTEMTIME PIDateTime::toSYSTEMTIME() const {
|
||||
SYSTEMTIME st;
|
||||
st.wYear = year;
|
||||
st.wMonth = month;
|
||||
st.wDay = day;
|
||||
st.wHour = hours;
|
||||
st.wMinute = minutes;
|
||||
st.wSecond = seconds;
|
||||
st.wMilliseconds = milliseconds;
|
||||
return st;
|
||||
}
|
||||
|
||||
|
||||
FILETIME PIDateTime::toFILETIME() const {
|
||||
FILETIME lt, ret;
|
||||
SYSTEMTIME st = toSYSTEMTIME();
|
||||
SystemTimeToFileTime(&st, <);
|
||||
LocalFileTimeToFileTime(<, &ret);
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
time_t PIDateTime::toSecondSinceEpoch() const {
|
||||
tm pt;
|
||||
memset(&pt, 0, sizeof(pt));
|
||||
|
||||
@@ -22,11 +22,9 @@
|
||||
|
||||
#ifndef PITIME_H
|
||||
#define PITIME_H
|
||||
|
||||
|
||||
#include "pistring.h"
|
||||
#ifdef WINDOWS
|
||||
# include <minwindef.h>
|
||||
typedef void(*PINtSetTimerResolution)(ULONG, BOOLEAN, PULONG);
|
||||
#endif
|
||||
|
||||
|
||||
//! \brief Sleep for "msecs" milliseconds
|
||||
@@ -63,10 +61,6 @@ public:
|
||||
//! Contructs system time from another
|
||||
PISystemTime(const PISystemTime & t) {seconds = t.seconds; nanoseconds = t.nanoseconds;}
|
||||
|
||||
#ifdef WINDOWS
|
||||
PISystemTime(const FILETIME & t);
|
||||
#endif
|
||||
|
||||
//! Returns stored system time value in seconds
|
||||
double toSeconds() const {return double(seconds) + nanoseconds / 1.e+9;}
|
||||
|
||||
@@ -239,25 +233,6 @@ struct PIP_EXPORT PIDateTime {
|
||||
PIDateTime(const PITime & time) {year = month = day = 0; hours = time.hours; minutes = time.minutes; seconds = time.seconds; milliseconds = time.milliseconds;}
|
||||
PIDateTime(const PIDate & date) {year = date.year; month = date.month; day = date.day; hours = minutes = seconds = milliseconds = 0;}
|
||||
PIDateTime(const PIDate & date, const PITime & time) {year = date.year; month = date.month; day = date.day; hours = time.hours; minutes = time.minutes; seconds = time.seconds; milliseconds = time.milliseconds;}
|
||||
#ifdef WINDOWS
|
||||
#ifndef _SYSTEMTIME_
|
||||
#define _SYSTEMTIME_
|
||||
typedef struct _SYSTEMTIME {
|
||||
WORD wYear;
|
||||
WORD wMonth;
|
||||
WORD wDayOfWeek;
|
||||
WORD wDay;
|
||||
WORD wHour;
|
||||
WORD wMinute;
|
||||
WORD wSecond;
|
||||
WORD wMilliseconds;
|
||||
} SYSTEMTIME, *PSYSTEMTIME, *LPSYSTEMTIME;
|
||||
#endif
|
||||
PIDateTime(SYSTEMTIME t);
|
||||
PIDateTime(FILETIME t);
|
||||
SYSTEMTIME toSYSTEMTIME() const;
|
||||
FILETIME toFILETIME() const;
|
||||
#endif
|
||||
int year;
|
||||
int month;
|
||||
int day;
|
||||
@@ -298,17 +273,6 @@ PICout operator <<(PICout s, const PIDateTime & v);
|
||||
|
||||
|
||||
|
||||
DEPRECATED inline PITime currentTime() {return PITime::current();} // obsolete, use PITime::current() instead
|
||||
DEPRECATED inline PIDate currentDate() {return PIDate::current();} // obsolete, use PIDate::current() instead
|
||||
DEPRECATED inline PIDateTime currentDateTime() {return PIDateTime::current();} // obsolete, use PIDateTime::current() instead
|
||||
|
||||
//! \brief Returns current system time \deprecated Use \a PISystemTime::current() instead
|
||||
DEPRECATED inline PISystemTime currentSystemTime() {return PISystemTime::current();} // obsolete, use PISystemTime::current() instead
|
||||
DEPRECATED PIP_EXPORT PIString time2string(const PITime & time, const PIString & format = "h:mm:ss"); // obsolete, use PITime.toString() instead
|
||||
DEPRECATED PIP_EXPORT PIString date2string(const PIDate & date, const PIString & format = "d.MM.yyyy"); // obsolete, use PITime.toString() instead
|
||||
DEPRECATED PIP_EXPORT PIString datetime2string(const PIDateTime & datetime, const PIString & format = "h:mm:ss d.MM.yyyy"); // obsolete, use PIDateTime.toString() instead
|
||||
|
||||
|
||||
class PITimeMeasurer {
|
||||
public:
|
||||
PITimeMeasurer();
|
||||
|
||||
69
src/core/pitime_win.h
Normal file
69
src/core/pitime_win.h
Normal file
@@ -0,0 +1,69 @@
|
||||
#ifndef PITIME_WIN_H
|
||||
#define PITIME_WIN_H
|
||||
|
||||
#include "pibase.h"
|
||||
#ifdef WINDOWS
|
||||
|
||||
#include "pitime.h"
|
||||
#include <windows.h>
|
||||
|
||||
|
||||
//inline PISystemTime SYSTEMTIME2PISystemTime(SYSTEMTIME &t) {
|
||||
// PISystemTime st;
|
||||
|
||||
//}
|
||||
|
||||
inline PISystemTime FILETIME2PISystemTime(const FILETIME &t) {
|
||||
PISystemTime st;
|
||||
ullong lt = ullong(t.dwHighDateTime) * 0x100000000U + ullong(t.dwLowDateTime);
|
||||
st.seconds = lt / 10000000U;
|
||||
st.nanoseconds = (lt % 10000000U) * 100U;
|
||||
return st;
|
||||
}
|
||||
|
||||
|
||||
|
||||
inline PIDateTime SYSTEMTIME2PIDateTime(const SYSTEMTIME &t) {
|
||||
PIDateTime dt;
|
||||
dt.year = t.wYear;
|
||||
dt.month = t.wMonth;
|
||||
dt.day = t.wDay;
|
||||
dt.hours = t.wHour;
|
||||
dt.minutes = t.wMinute;
|
||||
dt.seconds = t.wSecond;
|
||||
dt.milliseconds = t.wMilliseconds;
|
||||
return dt;
|
||||
}
|
||||
|
||||
inline PIDateTime FILETIME2PIDateTime(const FILETIME &t) {
|
||||
FILETIME lt;
|
||||
SYSTEMTIME st;
|
||||
FileTimeToLocalFileTime(&t, <);
|
||||
FileTimeToSystemTime(<, &st);
|
||||
return SYSTEMTIME2PIDateTime(st);
|
||||
}
|
||||
|
||||
inline SYSTEMTIME PIDateTime2SYSTEMTIME(const PIDateTime &dt) {
|
||||
SYSTEMTIME st;
|
||||
st.wYear = dt.year;
|
||||
st.wMonth = dt.month;
|
||||
st.wDay = dt.day;
|
||||
st.wHour = dt.hours;
|
||||
st.wMinute = dt.minutes;
|
||||
st.wSecond = dt.seconds;
|
||||
st.wMilliseconds = dt.milliseconds;
|
||||
return st;
|
||||
}
|
||||
|
||||
inline FILETIME PIDateTime2FILETIME(const PIDateTime &dt) {
|
||||
FILETIME lt, ret;
|
||||
SYSTEMTIME st = PIDateTime2SYSTEMTIME(dt);
|
||||
SystemTimeToFileTime(&st, <);
|
||||
LocalFileTimeToFileTime(<, &ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endif // WINDOWS
|
||||
#endif // PITIME_WIN_H
|
||||
@@ -17,10 +17,11 @@
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
#include "piconfig.h"
|
||||
#include "pifile.h"
|
||||
#include "piiostring.h"
|
||||
#include <iostream>
|
||||
#include "pistring_std.h"
|
||||
|
||||
/*! \class PIConfig
|
||||
* \brief Configuration file
|
||||
@@ -812,3 +813,15 @@ void PIConfig::parse() {
|
||||
setEntryDelim(&root, delim);
|
||||
buildFullNames(&root);
|
||||
}
|
||||
|
||||
|
||||
std::ostream &operator <<(std::ostream & s, const PIConfig::Entry & v) {
|
||||
s << v.value();
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
std::ostream &operator <<(std::ostream & s, const PIConfig::Branch & v) {
|
||||
v.coutt(s, "");
|
||||
return s;
|
||||
}
|
||||
|
||||
@@ -500,8 +500,8 @@ private:
|
||||
};
|
||||
|
||||
|
||||
inline std::ostream & operator <<(std::ostream & s, const PIConfig::Branch & v) {v.coutt(s, ""); return s;}
|
||||
inline std::ostream & operator <<(std::ostream & s, const PIConfig::Entry & v) {s << v.value(); return s;}
|
||||
std::ostream & operator <<(std::ostream & s, const PIConfig::Branch & v);
|
||||
std::ostream & operator <<(std::ostream & s, const PIConfig::Entry & v);
|
||||
inline PICout operator <<(PICout s, const PIConfig::Branch & v) {s.setControl(0, true); v.piCoutt(s, ""); s.restoreControl(); return s;}
|
||||
inline PICout operator <<(PICout s, const PIConfig::Entry & v) {s << v.value(); return s;}
|
||||
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
#include "piincludes_p.h"
|
||||
#include "pifile.h"
|
||||
#include "pidir.h"
|
||||
#include "pitime_win.h"
|
||||
#ifdef WINDOWS
|
||||
# undef S_IFDIR
|
||||
# undef S_IFREG
|
||||
@@ -378,15 +379,6 @@ int PIFile::writeDevice(const void * data, int max_size) {
|
||||
}
|
||||
|
||||
|
||||
PIFile & PIFile::writeToBinLog(ushort id, const void * data, int size) { /// DEPRECATED
|
||||
if (!isWriteable() || fd == 0) return *this;
|
||||
writeBinary(id).writeBinary((ushort)size);
|
||||
write(data, size);
|
||||
flush();
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
PIFile &PIFile::operator <<(const PIString & v) {
|
||||
if (canWrite() && fd != 0)
|
||||
*this << v.toCharset(defaultCharset());
|
||||
@@ -454,8 +446,8 @@ PIFile::FileInfo PIFile::fileInfo(const PIString & path) {
|
||||
ret.perm_user = FileInfo::Permissions(true, (attr & FILE_ATTRIBUTE_READONLY) != FILE_ATTRIBUTE_READONLY, ext == "bat" || ext == "exe");
|
||||
ret.perm_group = ret.perm_other = ret.perm_user;
|
||||
ret.size = filesize.QuadPart;
|
||||
ret.time_access = PIDateTime(fi.ftLastAccessTime);
|
||||
ret.time_modification = PIDateTime(fi.ftLastWriteTime);
|
||||
ret.time_access = FILETIME2PIDateTime(fi.ftLastAccessTime);
|
||||
ret.time_modification = FILETIME2PIDateTime(fi.ftLastWriteTime);
|
||||
/*PIByteArray sec;
|
||||
DWORD sec_n(0);
|
||||
//SECURITY_DESCRIPTOR sec;
|
||||
@@ -539,7 +531,7 @@ bool PIFile::applyFileInfo(const PIString & path, const PIFile::FileInfo & info)
|
||||
hFile = CreateFile(path.data(), GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, 0, OPEN_EXISTING, 0, 0);
|
||||
}
|
||||
if (!hFile) return false;
|
||||
FILETIME atime = info.time_access.toFILETIME(), mtime = info.time_modification.toFILETIME();
|
||||
FILETIME atime = PIDateTime2FILETIME(info.time_access), mtime = PIDateTime2FILETIME(info.time_modification);
|
||||
if (SetFileTime(hFile, 0, &atime, &mtime) == 0) {
|
||||
piCout << "[PIFile] applyFileInfo: \"SetFileTime\" error:" << errorString();
|
||||
return false;
|
||||
|
||||
@@ -152,9 +152,6 @@ public:
|
||||
void setPrecision(int prec);
|
||||
|
||||
|
||||
PIFile & writeToBinLog(ushort id, const void * data, int size); /// DEPRECATED
|
||||
|
||||
|
||||
//! Write to file binary content of "v"
|
||||
PIFile & writeBinary(const char v) {write(&v, sizeof(v)); return *this;}
|
||||
//! Write to file binary content of "v"
|
||||
|
||||
@@ -66,21 +66,6 @@ PIProtocol::PIProtocol(const PIString & config, const PIString & name_, void * r
|
||||
|
||||
|
||||
PIProtocol::~PIProtocol() {
|
||||
//cout << "prot " << protName << " delete\n";
|
||||
if (history_write_rec) {
|
||||
if (history_file_rec.isEmpty()) {
|
||||
history_file_rec.close();
|
||||
history_file_rec.remove();
|
||||
}
|
||||
history_file_rec.close();
|
||||
}
|
||||
if (history_write_send) {
|
||||
if (history_file_send.isEmpty()) {
|
||||
history_file_send.close();
|
||||
history_file_send.remove();
|
||||
}
|
||||
history_file_send.close();
|
||||
}
|
||||
delete diagTimer;
|
||||
delete sendTimer;
|
||||
delete secTimer;
|
||||
@@ -96,7 +81,7 @@ void PIProtocol::init() {
|
||||
packet_ext->setThreadedReadSlot(receiveEvent);
|
||||
packet_ext->setHeaderCheckSlot(headerValidateEvent);
|
||||
packet_ext->setName("__S__PIProtocol::packet_ext");
|
||||
work = new_mp_prot = history_write_rec = history_write_send = false;
|
||||
work = new_mp_prot = false;
|
||||
eth = 0;
|
||||
ser = 0;
|
||||
ret_func = 0;
|
||||
@@ -120,9 +105,6 @@ void PIProtocol::init() {
|
||||
type_rec = type_send = PIProtocol::None;
|
||||
devSenderState = devReceiverState = "Unknown";
|
||||
devSenderName = devReceiverName = "no device";
|
||||
history_rsize_rec = history_rsize_send = "no file";
|
||||
history_file_rec.setName("__S__PIProtocol::history_file_rec");
|
||||
history_file_send.setName("__S__PIProtocol::history_file_send");
|
||||
secTimer->start(1000.);
|
||||
/*addEvent("receiver started");
|
||||
addEvent("receiver stopped");
|
||||
@@ -265,27 +247,6 @@ void PIProtocol::init_sender(PIConfig::Entry & b, PIConfig::Entry & sb, const PI
|
||||
if (sendDataSize_ == 0)
|
||||
piCoutObj << "Warning: null send data size!";*/
|
||||
}
|
||||
history_write_send = sb.getValue("writeHistory", false, &ok);
|
||||
bool ghist = b.getValue("writeHistory", false, &gok);
|
||||
if (ok || gok) {
|
||||
if (gok && !ok) history_write_send = ghist;
|
||||
if (gok && ok && (history_write_send != ghist)) {
|
||||
piCoutObj << "Ambiguous sender history in \"" << config << "\"!";
|
||||
devSenderState = "Config error";
|
||||
return;
|
||||
}
|
||||
if (history_write_send) {
|
||||
history_path_send = sb.getValue("historyFile", "./history_" + protName + "_send_" +
|
||||
PIDate::current().toString("__dd_mm_yyyy_") +
|
||||
PITime::current().toString("_hh_mm_ss_")).value();
|
||||
history_id_send = sb.getValue("historyID", 0, &ok);
|
||||
if (!ok) {
|
||||
history_id_send = ushort(protName.toByteArray().checksumPlain32()) + 1;
|
||||
piCoutObj << "Warning: no sender history ID defined, write with ID = " << history_id_send;
|
||||
}
|
||||
history_file_send.open(history_path_send, PIIODevice::WriteOnly);
|
||||
}
|
||||
}
|
||||
freq = sb.getValue("frequency", -1.f, &ok);
|
||||
gfreq = b.getValue("frequency", -1.f, &gok);
|
||||
if (gok && !ok) freq = gfreq;
|
||||
@@ -440,27 +401,6 @@ void PIProtocol::init_receiver(PIConfig::Entry & b, PIConfig::Entry & rb, const
|
||||
return;
|
||||
}
|
||||
}
|
||||
history_write_rec = rb.getValue("writeHistory", false, &ok);
|
||||
bool ghist = b.getValue("writeHistory", false, &gok);
|
||||
if (ok || gok) {
|
||||
if (gok && !ok) history_write_rec = ghist;
|
||||
if (gok && ok && (history_write_rec != ghist)) {
|
||||
piCoutObj << "Ambiguous receiver history in \"" << config << "\"!";
|
||||
devReceiverState = "Config error";
|
||||
return;
|
||||
}
|
||||
if (history_write_rec) {
|
||||
history_path_rec = rb.getValue("historyFile", "./history_" + protName + "_rec_" +
|
||||
PIDate::current().toString("__dd_mm_yyyy_") +
|
||||
PITime::current().toString("_hh_mm_ss_")).value();
|
||||
history_id_rec = rb.getValue("historyID", 0, &ok);
|
||||
if (!ok) {
|
||||
history_id_rec = ushort(protName.toByteArray().checksumPlain32());
|
||||
piCoutObj << "Warning: no receiver history ID defined, write with ID = " << history_id_rec;
|
||||
}
|
||||
history_file_rec.open(history_path_rec, PIIODevice::WriteOnly);
|
||||
}
|
||||
}
|
||||
freq = rb.getValue("frequency", -1.f, &ok);
|
||||
gfreq = b.getValue("frequency", -1.f, &gok);
|
||||
if (gok && !ok) freq = gfreq;
|
||||
@@ -625,10 +565,6 @@ bool PIProtocol::receiveEvent(void * t, uchar * data, int size) {
|
||||
p->work = true;
|
||||
//p->lock();
|
||||
if (p->validate()) {
|
||||
if (p->history_write_rec) {
|
||||
p->history_file_rec.writeToBinLog(p->history_id_rec, data, size);
|
||||
p->history_rsize_rec.setReadableSize(p->history_file_rec.pos());
|
||||
}
|
||||
p->received(true);
|
||||
//p->unlock();
|
||||
p->ifreq = p->diag_tm.elapsed_m();
|
||||
@@ -747,10 +683,6 @@ void PIProtocol::send(const void * data, int size, bool direct) {
|
||||
if (data == 0 || size == 0) return;
|
||||
if (!aboutSend()) return;
|
||||
}
|
||||
if (history_write_send) {
|
||||
history_file_send.writeToBinLog(history_id_send, data, size);
|
||||
history_rsize_send.setReadableSize(history_file_send.pos());
|
||||
}
|
||||
if (type_send == PIProtocol::Serial)
|
||||
if (ser->send(data, size)) {
|
||||
send_count++;
|
||||
@@ -772,10 +704,6 @@ void PIProtocol::send() {
|
||||
//unlock();
|
||||
if (!aboutSend()) return;
|
||||
if (sendDataPtr == 0 || sendDataSize == 0) return;
|
||||
if (history_write_send) {
|
||||
history_file_send.writeToBinLog(history_id_send, sendDataPtr, sendDataSize);
|
||||
history_rsize_send.setReadableSize(history_file_send.pos());
|
||||
}
|
||||
if (type_send == PIProtocol::Serial)
|
||||
if (ser->send(sendDataPtr, sendDataSize)) {
|
||||
send_count++;
|
||||
|
||||
@@ -162,14 +162,6 @@ public:
|
||||
const PIString * receiveSpeed_ptr() const {return &speedIn;}
|
||||
PIString sendSpeed() const {return speedOut;}
|
||||
const PIString * sendSpeed_ptr() const {return &speedOut;}
|
||||
PIString receiverHistorySize() const {return history_rsize_rec;}
|
||||
const PIString * receiverHistorySize_ptr() const {return &history_rsize_rec;}
|
||||
PIString senderHistorySize() const {return history_rsize_send;}
|
||||
const PIString * senderHistorySize_ptr() const {return &history_rsize_send;}
|
||||
bool writeReceiverHistory() const {return history_write_rec;}
|
||||
const bool * writeReceiverHistory_ptr() const {return &history_write_rec;}
|
||||
bool writeSenderHistory() const {return history_write_send;}
|
||||
const bool * writeSenderHistory_ptr() const {return &history_write_send;}
|
||||
|
||||
void * receiveData() {return dataPtr;}
|
||||
void * sendData() {return sendDataPtr;}
|
||||
@@ -235,10 +227,7 @@ private:
|
||||
PIDeque<float> last_freq;
|
||||
PIDeque<char> last_packets;
|
||||
PIString protName, devReceiverName, devReceiverState, devSenderName, devSenderState, speedIn, speedOut;
|
||||
PIString history_path_rec, history_path_send, history_rsize_rec, history_rsize_send;
|
||||
PIFile history_file_rec, history_file_send;
|
||||
ushort history_id_rec, history_id_send;
|
||||
bool work, new_mp_prot, history_write_rec, history_write_send;
|
||||
bool work, new_mp_prot;
|
||||
float exp_freq, send_freq, ifreq, immediate_freq, integral_freq, timeout_;
|
||||
int packets[2], pckt_cnt, pckt_cnt_max;
|
||||
char cur_pckt;
|
||||
|
||||
@@ -36,96 +36,76 @@
|
||||
#endif
|
||||
|
||||
|
||||
/// with align
|
||||
template <typename T>
|
||||
class PIFFTW_Private
|
||||
{
|
||||
public:
|
||||
explicit PIFFTW_Private() {
|
||||
plan = 0;
|
||||
p_in = p_out = 0;
|
||||
p_inr = 0;
|
||||
#ifdef PIP_FFTW
|
||||
// fftwf_m
|
||||
#else
|
||||
#ifndef PIP_FFTW
|
||||
piCout << "[PIFFTW]" << "Warning: PIFFTW is disabled, to enable install libfftw3-dev library and build pip with -DFFTW=1";
|
||||
#endif
|
||||
p_makeThreadSafe();
|
||||
}
|
||||
~PIFFTW_Private() {
|
||||
p_destroyPlan(plan);
|
||||
delVec(p_in);
|
||||
delVec(p_out);
|
||||
delVec(p_inr);
|
||||
}
|
||||
~PIFFTW_Private() {p_destroyPlan(plan);}
|
||||
|
||||
const PIVector<complex<T> > & calcFFT(const PIVector<complex<T> > & in) {
|
||||
if (prepare != PlanParams(in.size(), fo_complex)) {
|
||||
newVec(p_in, in.size());
|
||||
newVec(p_out, in.size());
|
||||
p_out.resize(in.size());
|
||||
piCout << "[PIFFTW]" << "creating plan";
|
||||
p_createPlan_c2c_1d(plan, in.size(), p_in, p_out, FFTW_FORWARD, FFTW_ESTIMATE);
|
||||
v_out.resize(in.size());
|
||||
p_createPlan_c2c_1d(plan, in.size(), in.data(), p_out.data(), FFTW_FORWARD, FFTW_ESTIMATE | FFTW_UNALIGNED);
|
||||
prepare = PlanParams(in.size(), fo_complex);
|
||||
}
|
||||
memcpy(p_in, in.data(), sizeof(complex<T>) * in.size());
|
||||
p_executePlan(plan);
|
||||
memcpy(v_out.data(), p_out, sizeof(complex<T>) * v_out.size());
|
||||
return v_out;
|
||||
p_executePlan_c2c(plan, in.data(), p_out.data());
|
||||
return p_out;
|
||||
}
|
||||
const PIVector<complex<T> > & calcFFT(const PIVector<T> & in) {
|
||||
if (prepare != PlanParams(in.size(), fo_real)) {
|
||||
newVec(p_inr, in.size());
|
||||
newVec(p_out, in.size());
|
||||
p_out.resize(in.size());
|
||||
piCout << "[PIFFTW]" << "creating plan";
|
||||
p_createPlan_r2c_1d(plan, in.size(), p_inr, p_out, FFTW_ESTIMATE);
|
||||
v_out.resize(in.size());
|
||||
p_createPlan_r2c_1d(plan, in.size(), in.data(), p_out.data(), FFTW_ESTIMATE | FFTW_UNALIGNED);
|
||||
prepare = PlanParams(in.size(), fo_real);
|
||||
}
|
||||
memcpy(p_inr, in.data(), sizeof(T) * in.size());
|
||||
p_executePlan(plan);
|
||||
memcpy(v_out.data(), p_out, sizeof(complex<T>) * v_out.size());
|
||||
return v_out;
|
||||
p_executePlan_r2c(plan, in.data(), p_out.data());
|
||||
return p_out;
|
||||
}
|
||||
const PIVector<complex<T> > & calcFFTinverse(const PIVector<complex<T> > & in) {
|
||||
if (prepare != PlanParams(in.size(), fo_inverse)) {
|
||||
newVec(p_in, in.size());
|
||||
newVec(p_out, in.size());
|
||||
p_out.resize(in.size());
|
||||
piCout << "[PIFFTW]" << "creating plan";
|
||||
p_createPlan_c2c_1d(plan, in.size(), p_in, p_out, FFTW_BACKWARD, FFTW_ESTIMATE);
|
||||
v_out.resize(in.size());
|
||||
p_createPlan_c2c_1d(plan, in.size(), in.data(), p_out.data(), FFTW_BACKWARD, FFTW_ESTIMATE | FFTW_UNALIGNED);
|
||||
prepare = PlanParams(in.size(), fo_inverse);
|
||||
}
|
||||
memcpy(p_in, in.data(), sizeof(complex<T>) * in.size());
|
||||
p_executePlan(plan);
|
||||
memcpy(v_out.data(), p_out, sizeof(complex<T>) * v_out.size());
|
||||
return v_out;
|
||||
p_executePlan_c2c(plan, in.data(), p_out.data());
|
||||
return p_out;
|
||||
}
|
||||
|
||||
enum FFT_Operation {fo_real, fo_complex, fo_inverse};
|
||||
|
||||
void preparePlan(int size, int op) {
|
||||
p_inr.clear();
|
||||
p_in.clear();
|
||||
p_out.clear();
|
||||
switch ((FFT_Operation)op) {
|
||||
case fo_real:
|
||||
newVec(p_inr, size);
|
||||
newVec(p_out, size);
|
||||
p_createPlan_r2c_1d(plan, size, p_inr, p_out, FFTW_MEASURE);
|
||||
p_inr.resize(size);
|
||||
p_out.resize(size);
|
||||
p_createPlan_r2c_1d(plan, size, p_inr.data(), p_out.data(), FFTW_MEASURE | FFTW_UNALIGNED);
|
||||
break;
|
||||
case fo_complex:
|
||||
newVec(p_in, size);
|
||||
newVec(p_out, size);
|
||||
p_createPlan_c2c_1d(plan, size, p_in, p_out, FFTW_FORWARD, FFTW_MEASURE);
|
||||
p_in.resize(size);
|
||||
p_out.resize(size);
|
||||
p_createPlan_c2c_1d(plan, size, p_in.data(), p_out.data(), FFTW_FORWARD, FFTW_MEASURE | FFTW_UNALIGNED);
|
||||
break;
|
||||
case fo_inverse:
|
||||
newVec(p_in, size);
|
||||
newVec(p_out, size);
|
||||
p_createPlan_c2c_1d(plan, size, p_in, p_out, FFTW_BACKWARD, FFTW_MEASURE);
|
||||
p_in.resize(size);
|
||||
p_out.resize(size);
|
||||
p_createPlan_c2c_1d(plan, size, p_in.data(), p_out.data(), FFTW_BACKWARD, FFTW_MEASURE | FFTW_UNALIGNED);
|
||||
break;
|
||||
default:
|
||||
size = 0;
|
||||
break;
|
||||
}
|
||||
v_out.resize(size);
|
||||
prepare = PlanParams(size, (FFT_Operation)op);
|
||||
}
|
||||
|
||||
@@ -136,10 +116,6 @@ public:
|
||||
inline void p_executePlan_r2c(void * plan, const void * in, void * out) {}
|
||||
inline void p_destroyPlan(void *& plan) {}
|
||||
inline void p_makeThreadSafe() {}
|
||||
template <typename VT>
|
||||
inline void newVec(VT *& v, int size) {delVec(v); v = (VT*)amalloc(sizeof(VT) * size);}
|
||||
template <typename VT>
|
||||
inline void delVec(VT *& v) {if (v) afree(v); v = 0;}
|
||||
|
||||
struct PlanParams {
|
||||
PlanParams() {size = 0; op = fo_complex;}
|
||||
@@ -151,9 +127,9 @@ public:
|
||||
FFT_Operation op;
|
||||
};
|
||||
|
||||
complex<T> * p_in, * p_out;
|
||||
T * p_inr;
|
||||
PIVector<complex<T> > v_out;
|
||||
PIVector<complex<T> > p_in;
|
||||
PIVector<T> p_inr;
|
||||
PIVector<complex<T> > p_out;
|
||||
void * plan;
|
||||
PlanParams prepare;
|
||||
};
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
#define PIP_VERSION_MAJOR 0
|
||||
#define PIP_VERSION_MINOR 9
|
||||
#define PIP_VERSION_REVISION 2
|
||||
#define PIP_VERSION_SUFFIX ""
|
||||
#define PIP_VERSION_REVISION 4
|
||||
#define PIP_VERSION_SUFFIX "alpha"
|
||||
|
||||
#endif // PIVERSION_H
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
#include "piincludes_p.h"
|
||||
#include "pisystemmonitor.h"
|
||||
#include "pisysteminfo.h"
|
||||
#include "pitime_win.h"
|
||||
#ifdef WINDOWS
|
||||
# include <psapi.h>
|
||||
# include <tlhelp32.h>
|
||||
@@ -179,7 +180,8 @@ void PISystemMonitor::run() {
|
||||
FILETIME ft0, ft1, ft_kernel, ft_user;
|
||||
double el_s = PRIVATE->tm.elapsed_s() * cpu_count / 100.;
|
||||
if (GetProcessTimes(PRIVATE->hProc, &ft0, &ft1, &ft_kernel, &ft_user) != 0) {
|
||||
PISystemTime tm_kernel_c(ft_kernel), tm_user_c(ft_user);
|
||||
PISystemTime tm_kernel_c = FILETIME2PISystemTime(ft_kernel);
|
||||
PISystemTime tm_user_c = FILETIME2PISystemTime(ft_user);
|
||||
if (cycle < 0) {
|
||||
PRIVATE->tm_kernel = tm_kernel_c;
|
||||
PRIVATE->tm_user = tm_user_c;
|
||||
|
||||
@@ -35,10 +35,7 @@
|
||||
* */
|
||||
|
||||
#include "pimutex.h"
|
||||
#ifdef WINDOWS
|
||||
# include <windef.h>
|
||||
# include <winbase.h>
|
||||
#endif
|
||||
#include "piincludes_p.h"
|
||||
#ifdef BLACKBERRY
|
||||
# include <pthread.h>
|
||||
#endif
|
||||
@@ -55,6 +52,9 @@ PRIVATE_DEFINITION_END(PIMutex)
|
||||
|
||||
|
||||
PIMutex::PIMutex(): inited_(false) {
|
||||
#ifdef WINDOWS
|
||||
PRIVATE->mutex = 0;
|
||||
#endif
|
||||
init();
|
||||
}
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
extern PINtSetTimerResolution setTimerResolutionAddr;
|
||||
void __PISetTimerResolution() {if (setTimerResolutionAddr == NULL) return; ULONG ret; setTimerResolutionAddr(1, TRUE, &ret);}
|
||||
#endif
|
||||
#ifdef MAC_OS
|
||||
#if defined(MAC_OS) || defined(BLACKBERRY)
|
||||
# include <pthread.h>
|
||||
#endif
|
||||
|
||||
@@ -80,10 +80,20 @@ end();
|
||||
*/
|
||||
|
||||
|
||||
PRIVATE_DEFINITION_START(PIThread)
|
||||
#ifndef WINDOWS
|
||||
pthread_t thread;
|
||||
sched_param sparam;
|
||||
#else
|
||||
void * thread;
|
||||
#endif
|
||||
PRIVATE_DEFINITION_END(PIThread)
|
||||
|
||||
|
||||
PIThread::PIThread(void * data, ThreadFunc func, bool startNow, int timer_delay): PIObject() {
|
||||
piMonitor.threads++;
|
||||
tid_ = -1;
|
||||
thread = 0;
|
||||
PRIVATE->thread = 0;
|
||||
data_ = data;
|
||||
ret_func = func;
|
||||
terminating = running_ = lockRun = false;
|
||||
@@ -96,7 +106,7 @@ PIThread::PIThread(void * data, ThreadFunc func, bool startNow, int timer_delay)
|
||||
PIThread::PIThread(bool startNow, int timer_delay): PIObject() {
|
||||
piMonitor.threads++;
|
||||
tid_ = -1;
|
||||
thread = 0;
|
||||
PRIVATE->thread = 0;
|
||||
ret_func = 0;
|
||||
terminating = running_ = lockRun = false;
|
||||
priority_ = piNormal;
|
||||
@@ -107,16 +117,16 @@ PIThread::PIThread(bool startNow, int timer_delay): PIObject() {
|
||||
|
||||
PIThread::~PIThread() {
|
||||
piMonitor.threads--;
|
||||
if (!running_ || thread == 0) return;
|
||||
if (!running_ || PRIVATE->thread == 0) return;
|
||||
#ifndef WINDOWS
|
||||
# ifdef ANDROID
|
||||
pthread_kill(thread, SIGTERM);
|
||||
pthread_kill(PRIVATE->thread, SIGTERM);
|
||||
# else
|
||||
pthread_cancel(thread);
|
||||
pthread_cancel(PRIVATE->thread);
|
||||
# endif
|
||||
#else
|
||||
TerminateThread(thread, 0);
|
||||
CloseHandle(thread);
|
||||
TerminateThread(PRIVATE->thread, 0);
|
||||
CloseHandle(PRIVATE->thread);
|
||||
#endif
|
||||
terminating = running_ = false;
|
||||
}
|
||||
@@ -130,29 +140,29 @@ bool PIThread::start(int timer_delay) {
|
||||
pthread_attr_t attr;
|
||||
pthread_attr_init(&attr);
|
||||
# ifndef ANDROID
|
||||
//pthread_attr_setschedparam(&attr, &sparam);
|
||||
//pthread_attr_setschedparam(&attr, &(PRIVATE->sparam));
|
||||
# endif
|
||||
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
|
||||
int ret = pthread_create(&thread, &attr, thread_function, this);
|
||||
//piCout << "pthread_create" << thread;
|
||||
int ret = pthread_create(&PRIVATE->thread, &attr, thread_function, this);
|
||||
//piCout << "pthread_create" << PRIVATE->thread;
|
||||
pthread_attr_destroy(&attr);
|
||||
if (ret == 0) {
|
||||
# ifdef MAC_OS
|
||||
pthread_threadid_np(thread, (__uint64_t*)&tid_);
|
||||
pthread_threadid_np(PRIVATE->thread, (__uint64_t*)&tid_);
|
||||
# else
|
||||
tid_ = thread;
|
||||
tid_ = PRIVATE->thread;
|
||||
# endif
|
||||
#else
|
||||
if (thread != 0) CloseHandle(thread);
|
||||
thread = (void *)_beginthreadex(0, 0, thread_function, this, 0, 0);
|
||||
// thread = CreateThread(0, 0, (LPTHREAD_START_ROUTINE)thread_function, this, 0, 0);
|
||||
if (thread != 0) {
|
||||
if (PRIVATE->thread != 0) CloseHandle(PRIVATE->thread);
|
||||
PRIVATE->thread = (void *)_beginthreadex(0, 0, thread_function, this, 0, 0);
|
||||
// PRIVATE->thread = CreateThread(0, 0, (LPTHREAD_START_ROUTINE)thread_function, this, 0, 0);
|
||||
if (PRIVATE->thread != 0) {
|
||||
#endif
|
||||
setPriority(priority_);
|
||||
running_ = true;
|
||||
return true;
|
||||
} else {
|
||||
thread = 0;
|
||||
PRIVATE->thread = 0;
|
||||
piCoutObj << "Error: Can`t start new thread:" << errorString();
|
||||
}
|
||||
return false;
|
||||
@@ -166,29 +176,29 @@ bool PIThread::startOnce() {
|
||||
pthread_attr_t attr;
|
||||
pthread_attr_init(&attr);
|
||||
# ifndef ANDROID
|
||||
//pthread_attr_setschedparam(&attr, &sparam);
|
||||
//pthread_attr_setschedparam(&attr, &(PRIVATE->sparam));
|
||||
# endif
|
||||
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
|
||||
int ret = pthread_create(&thread, &attr, thread_function_once, this);
|
||||
//piCout << "pthread_create" << thread;
|
||||
int ret = pthread_create(&(PRIVATE->thread), &attr, thread_function_once, this);
|
||||
//piCout << "pthread_create" << PRIVATE->thread;
|
||||
pthread_attr_destroy(&attr);
|
||||
if (ret == 0) {
|
||||
# ifdef MAC_OS
|
||||
pthread_threadid_np(thread, (__uint64_t*)&tid_);
|
||||
pthread_threadid_np(PRIVATE->thread, (__uint64_t*)&tid_);
|
||||
# else
|
||||
tid_ = thread;
|
||||
tid_ = PRIVATE->thread;
|
||||
# endif
|
||||
#else
|
||||
if (thread != 0) CloseHandle(thread);
|
||||
thread = (void *)_beginthreadex(0, 0, thread_function_once, this, 0, 0);
|
||||
if (PRIVATE->thread != 0) CloseHandle(PRIVATE->thread);
|
||||
PRIVATE->thread = (void *)_beginthreadex(0, 0, thread_function_once, this, 0, 0);
|
||||
// thread = CreateThread(0, 0, (LPTHREAD_START_ROUTINE)thread_function_once, this, 0, 0);
|
||||
if (thread != 0) {
|
||||
if (PRIVATE->thread != 0) {
|
||||
#endif
|
||||
setPriority(priority_);
|
||||
running_ = true;
|
||||
return true;
|
||||
} else {
|
||||
thread = 0;
|
||||
PRIVATE->thread = 0;
|
||||
piCoutObj << "Error: Can`t start new thread:" << errorString();
|
||||
}
|
||||
return false;
|
||||
@@ -196,25 +206,25 @@ bool PIThread::startOnce() {
|
||||
|
||||
|
||||
void PIThread::terminate() {
|
||||
if (thread == 0) return;
|
||||
if (PRIVATE->thread == 0) return;
|
||||
PIINTROSPECTION_UNREGISTER_THREAD(tid());
|
||||
terminating = running_ = false;
|
||||
tid_ = -1;
|
||||
//piCout << "terminate" << thread;
|
||||
#ifndef WINDOWS
|
||||
# ifdef ANDROID
|
||||
pthread_kill(thread, SIGTERM);
|
||||
pthread_kill(PRIVATE->thread, SIGTERM);
|
||||
# else
|
||||
//pthread_kill(thread, SIGKILL);
|
||||
//pthread_kill(PRIVATE->thread, SIGKILL);
|
||||
//void * ret(0);
|
||||
pthread_cancel(thread);
|
||||
//pthread_join(thread, &ret);
|
||||
pthread_cancel(PRIVATE->thread);
|
||||
//pthread_join(PRIVATE->thread, &ret);
|
||||
# endif
|
||||
#else
|
||||
TerminateThread(thread, 0);
|
||||
CloseHandle(thread);
|
||||
TerminateThread(PRIVATE->thread, 0);
|
||||
CloseHandle(PRIVATE->thread);
|
||||
#endif
|
||||
thread = 0;
|
||||
PRIVATE->thread = 0;
|
||||
end();
|
||||
}
|
||||
|
||||
@@ -265,11 +275,11 @@ __THREAD_FUNC__ PIThread::thread_function(void * t) {
|
||||
ct.terminating = ct.running_ = false;
|
||||
ct.tid_ = -1;
|
||||
//cout << "thread " << t << " exiting ... " << endl;
|
||||
//piCout << "pthread_exit" << ct.thread;
|
||||
//piCout << "pthread_exit" << ct.PRIVATE->thread;
|
||||
PIINTROSPECTION_UNREGISTER_THREAD(ct.tid());
|
||||
#ifndef WINDOWS
|
||||
pthread_detach(ct.thread);
|
||||
ct.thread = 0;
|
||||
pthread_detach(ct.PRIVATE->thread);
|
||||
ct.PRIVATE->thread = 0;
|
||||
#endif
|
||||
#ifndef WINDOWS
|
||||
pthread_exit(0);
|
||||
@@ -307,11 +317,11 @@ __THREAD_FUNC__ PIThread::thread_function_once(void * t) {
|
||||
ct.terminating = ct.running_ = false;
|
||||
ct.tid_ = -1;
|
||||
//cout << "thread " << t << " exiting ... " << endl;
|
||||
//piCout << "pthread_exit" << ct.thread;
|
||||
//piCout << "pthread_exit" << ct.PRIVATE->thread;
|
||||
PIINTROSPECTION_UNREGISTER_THREAD(ct.tid());
|
||||
#ifndef WINDOWS
|
||||
pthread_detach(ct.thread);
|
||||
ct.thread = 0;
|
||||
pthread_detach(ct.PRIVATE->thread);
|
||||
ct.PRIVATE->thread = 0;
|
||||
#endif
|
||||
#ifndef WINDOWS
|
||||
pthread_exit(0);
|
||||
@@ -355,22 +365,22 @@ int PIThread::priority2System(PIThread::Priority p) {
|
||||
void PIThread::setPriority(PIThread::Priority prior) {
|
||||
priority_ = prior;
|
||||
#ifndef WINDOWS
|
||||
if (!running_ || (thread == 0)) return;
|
||||
//piCout << "setPriority" << thread;
|
||||
if (!running_ || (PRIVATE->thread == 0)) return;
|
||||
//piCout << "setPriority" << PRIVATE->thread;
|
||||
policy_ = 0;
|
||||
memset(&sparam, 0, sizeof(sparam));
|
||||
pthread_getschedparam(thread, &policy_, &sparam);
|
||||
sparam.
|
||||
memset(&(PRIVATE->sparam), 0, sizeof(PRIVATE->sparam));
|
||||
pthread_getschedparam(PRIVATE->thread, &policy_, &(PRIVATE->sparam));
|
||||
PRIVATE->sparam.
|
||||
# ifndef LINUX
|
||||
sched_priority
|
||||
# else
|
||||
__sched_priority
|
||||
# endif
|
||||
= priority2System(priority_);
|
||||
pthread_setschedparam(thread, policy_, &sparam);
|
||||
pthread_setschedparam(PRIVATE->thread, policy_, &(PRIVATE->sparam));
|
||||
#else
|
||||
if (!running_ || (thread == 0)) return;
|
||||
SetThreadPriority(thread, priority2System(priority_));
|
||||
if (!running_ || (PRIVATE->thread == 0)) return;
|
||||
SetThreadPriority(PRIVATE->thread, priority2System(priority_));
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -28,9 +28,6 @@
|
||||
#include "piinit.h"
|
||||
#include "pimutex.h"
|
||||
#include "piobject.h"
|
||||
#ifdef BLACKBERRY
|
||||
# include <pthread.h>
|
||||
#endif
|
||||
#ifdef WINDOWS
|
||||
# define __THREAD_FUNC__ uint __stdcall
|
||||
#else
|
||||
@@ -207,13 +204,7 @@ protected:
|
||||
PITimeMeasurer tmf_, tms_, tmr_;
|
||||
PIThread::Priority priority_;
|
||||
ThreadFunc ret_func;
|
||||
#ifndef WINDOWS
|
||||
pthread_t thread;
|
||||
sched_param sparam;
|
||||
#else
|
||||
void * thread;
|
||||
#endif
|
||||
|
||||
PRIVATE_DECLARATION
|
||||
};
|
||||
|
||||
#endif // PITHREAD_H
|
||||
|
||||
@@ -23,5 +23,7 @@
|
||||
#include "pimutex.h"
|
||||
#include "pithread.h"
|
||||
#include "pitimer.h"
|
||||
#include "pipipelinethread.h"
|
||||
#include "pigrabberbase.h"
|
||||
|
||||
#endif // PITHREADMODULE_H
|
||||
|
||||
Reference in New Issue
Block a user