randomizw
android port git-svn-id: svn://db.shs.com.ru/pip@39 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5
This commit is contained in:
@@ -21,6 +21,7 @@
|
|||||||
#ifndef WINDOWS
|
#ifndef WINDOWS
|
||||||
# include <sys/ioctl.h>
|
# include <sys/ioctl.h>
|
||||||
# include <fcntl.h>
|
# include <fcntl.h>
|
||||||
|
# include <termios.h>
|
||||||
#else
|
#else
|
||||||
# include <wincon.h>
|
# include <wincon.h>
|
||||||
# ifndef COMMON_LVB_UNDERSCORE
|
# ifndef COMMON_LVB_UNDERSCORE
|
||||||
|
|||||||
@@ -111,8 +111,8 @@
|
|||||||
|
|
||||||
#ifdef ANDROID
|
#ifdef ANDROID
|
||||||
# define tcdrain(fd) ioctl(fd, TCSBRK, 1)
|
# define tcdrain(fd) ioctl(fd, TCSBRK, 1)
|
||||||
inline int wctomb(char * c, wchar_t w) {*c = ((char * )&w)[0]; return 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;}
|
//inline int mbtowc(wchar_t * w, const char * c, size_t) {*w = ((wchar_t * )&c)[0]; return 1;}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef MAC_OS
|
#ifdef MAC_OS
|
||||||
|
|||||||
@@ -158,8 +158,9 @@ PIInit::PIInit() {
|
|||||||
sinfo->user = ps->pw_name;
|
sinfo->user = ps->pw_name;
|
||||||
else {
|
else {
|
||||||
memset(cbuff, 0, 1024);
|
memset(cbuff, 0, 1024);
|
||||||
if (getlogin_r(cbuff, 1023) == 0)
|
char * l = getlogin();
|
||||||
sinfo->user = cbuff;
|
if (l)
|
||||||
|
sinfo->user = l;
|
||||||
}
|
}
|
||||||
struct utsname uns;
|
struct utsname uns;
|
||||||
if (uname(&uns) == 0) {
|
if (uname(&uns) == 0) {
|
||||||
|
|||||||
@@ -81,6 +81,9 @@ const int PIString::fromBaseN[] = {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -
|
|||||||
#else
|
#else
|
||||||
# define pisprintf(f, v) char ch[256]; memset(ch, 0, 256); sprintf_s(ch, 256, f, v);
|
# define pisprintf(f, v) char ch[256]; memset(ch, 0, 256); sprintf_s(ch, 256, f, v);
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef ANDROID
|
||||||
|
int wctomb(char * c, wchar_t w) {*c = ((char * )&w)[0]; return 1;}
|
||||||
|
#endif
|
||||||
|
|
||||||
PIString PIString::itos(const int num) {pisprintf("%d", num); return PIString(ch);}
|
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::ltos(const long num) {pisprintf("%ld", num); return PIString(ch);}
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ const PIChar PIDir::separator = '/';
|
|||||||
#endif
|
#endif
|
||||||
#ifndef WINDOWS
|
#ifndef WINDOWS
|
||||||
# ifdef ANDROID
|
# ifdef ANDROID
|
||||||
# include <sys/dirent.h>
|
# include <dirent.h>
|
||||||
# else
|
# else
|
||||||
# include <sys/dir.h>
|
# include <sys/dir.h>
|
||||||
# endif
|
# endif
|
||||||
@@ -219,7 +219,7 @@ PIVector<PIFile::FileInfo> PIDir::entries() {
|
|||||||
const_cast<char*>(p.data()), 0
|
const_cast<char*>(p.data()), 0
|
||||||
# endif
|
# endif
|
||||||
, 0,
|
, 0,
|
||||||
# ifdef MAC_OS
|
# if defined(MAC_OS) || defined(ANDROID)
|
||||||
alphasort);
|
alphasort);
|
||||||
# else
|
# else
|
||||||
versionsort);
|
versionsort);
|
||||||
|
|||||||
@@ -454,7 +454,7 @@ bool PIEthernet::listen(bool threaded) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//#include <QDebug>
|
||||||
int PIEthernet::read(void * read_to, int max_size) {
|
int PIEthernet::read(void * read_to, int max_size) {
|
||||||
//cout << "read " << sock << endl;
|
//cout << "read " << sock << endl;
|
||||||
if (sock == -1) init();
|
if (sock == -1) init();
|
||||||
@@ -486,8 +486,10 @@ int PIEthernet::read(void * read_to, int max_size) {
|
|||||||
PRIVATE->addr_.sin_len = sizeof(PRIVATE->addr_);
|
PRIVATE->addr_.sin_len = sizeof(PRIVATE->addr_);
|
||||||
#endif
|
#endif
|
||||||
//piCoutObj << "connect to " << ip_ << ":" << port_ << "...";
|
//piCoutObj << "connect to " << ip_ << ":" << port_ << "...";
|
||||||
connected_ = (::connect(sock, (sockaddr * )&PRIVATE->addr_, sizeof(PRIVATE->addr_)) == 0);
|
//qDebug() << "connect to " << ip_.data() << ":" << port_ << sock << PRIVATE->addr_.sin_addr.s_addr << "...";
|
||||||
|
connected_ = (::connect(sock, (sockaddr * )&(PRIVATE->addr_), sizeof(PRIVATE->addr_)) == 0);
|
||||||
//piCoutObj << "connect to " << ip_ << ":" << port_ << connected_;
|
//piCoutObj << "connect to " << ip_ << ":" << port_ << connected_;
|
||||||
|
//qDebug() << "connect to " << ip_.data() << ":" << port_ << connected_;
|
||||||
if (!connected_)
|
if (!connected_)
|
||||||
piCoutObj << "Can`t connect to " << ip_ << ":" << port_ << ", " << ethErrorString();
|
piCoutObj << "Can`t connect to " << ip_ << ":" << port_ << ", " << ethErrorString();
|
||||||
opened_ = connected_;
|
opened_ = connected_;
|
||||||
@@ -497,13 +499,16 @@ int PIEthernet::read(void * read_to, int max_size) {
|
|||||||
} else
|
} else
|
||||||
piMSleep(10);
|
piMSleep(10);
|
||||||
//piCout << "connected to" << path();
|
//piCout << "connected to" << path();
|
||||||
|
//qDebug() << "connected to" << path().data();
|
||||||
}
|
}
|
||||||
if (!connected_) return -1;
|
if (!connected_) return -1;
|
||||||
errorClear();
|
errorClear();
|
||||||
rs = ethRecv(sock, read_to, max_size);
|
rs = ethRecv(sock, read_to, max_size);
|
||||||
//piCoutObj << "readed" << rs;
|
//piCoutObj << "readed" << rs;
|
||||||
|
//qDebug() << "readed" << rs;
|
||||||
if (rs <= 0) {
|
if (rs <= 0) {
|
||||||
lerr = ethErrorCore();
|
lerr = ethErrorCore();
|
||||||
|
//qDebug() << "readed error" << errorString().data();
|
||||||
#ifdef WINDOWS
|
#ifdef WINDOWS
|
||||||
if (lerr == WSAEWOULDBLOCK || /*lerr == NO_ERROR ||*/ lerr == WSAETIMEDOUT) {
|
if (lerr == WSAEWOULDBLOCK || /*lerr == NO_ERROR ||*/ lerr == WSAETIMEDOUT) {
|
||||||
#else
|
#else
|
||||||
@@ -521,6 +526,7 @@ int PIEthernet::read(void * read_to, int max_size) {
|
|||||||
//piCoutObj << "eth" << ip_ << "disconnected";
|
//piCoutObj << "eth" << ip_ << "disconnected";
|
||||||
}
|
}
|
||||||
if (rs > 0) received(read_to, rs);
|
if (rs > 0) received(read_to, rs);
|
||||||
|
//qDebug() << "return from read" << rs;
|
||||||
return rs;
|
return rs;
|
||||||
case UDP:
|
case UDP:
|
||||||
memset(&PRIVATE->raddr_, 0, sizeof(PRIVATE->raddr_));
|
memset(&PRIVATE->raddr_, 0, sizeof(PRIVATE->raddr_));
|
||||||
|
|||||||
@@ -322,6 +322,10 @@ PIFile::FileInfo PIFile::fileInfo(const PIString & path) {
|
|||||||
ret.size = fs.st_size;
|
ret.size = fs.st_size;
|
||||||
ret.id_user = fs.st_uid;
|
ret.id_user = fs.st_uid;
|
||||||
ret.id_group = fs.st_gid;
|
ret.id_group = fs.st_gid;
|
||||||
|
#ifdef ANDROID
|
||||||
|
ret.time_access = PIDateTime::fromSystemTime(PISystemTime(fs.st_atime, fs.st_atime_nsec));
|
||||||
|
ret.time_modification = PIDateTime::fromSystemTime(PISystemTime(fs.st_mtime, fs.st_mtime_nsec));
|
||||||
|
#else
|
||||||
# ifdef MAC_OS
|
# ifdef MAC_OS
|
||||||
# define ATIME st_atimespec
|
# define ATIME st_atimespec
|
||||||
# define MTIME st_ctimespec
|
# define MTIME st_ctimespec
|
||||||
@@ -331,6 +335,7 @@ PIFile::FileInfo PIFile::fileInfo(const PIString & path) {
|
|||||||
# endif
|
# endif
|
||||||
ret.time_access = PIDateTime::fromSystemTime(PISystemTime(fs.ATIME.tv_sec, fs.ATIME.tv_nsec));
|
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.time_modification = PIDateTime::fromSystemTime(PISystemTime(fs.MTIME.tv_sec, fs.MTIME.tv_nsec));
|
||||||
|
#endif
|
||||||
ret.perm_user = FileInfo::Permissions((mode & S_IRUSR) == S_IRUSR, (mode & S_IWUSR) == S_IWUSR, (mode & S_IXUSR) == S_IXUSR);
|
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_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);
|
ret.perm_other = FileInfo::Permissions((mode & S_IROTH) == S_IROTH, (mode & S_IWOTH) == S_IWOTH, (mode & S_IXOTH) == S_IXOTH);
|
||||||
|
|||||||
@@ -18,6 +18,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "pimathbase.h"
|
#include "pimathbase.h"
|
||||||
|
#include "pitime.h"
|
||||||
|
|
||||||
|
|
||||||
double piJ0(const double & v) {
|
double piJ0(const double & v) {
|
||||||
@@ -450,6 +451,11 @@ double piYn(int n, const double & v) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void randomize() {
|
||||||
|
srand(PISystemTime::current(true).nanoseconds);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
double randomn(double dv, double sv) {
|
double randomn(double dv, double sv) {
|
||||||
static bool agen = false;
|
static bool agen = false;
|
||||||
double s = 2., v0 = 0., v1 = 0.;
|
double s = 2., v0 = 0., v1 = 0.;
|
||||||
|
|||||||
@@ -140,6 +140,8 @@ inline double toDeg(double rad) {return rad * M_180_PI;}
|
|||||||
template<typename T>
|
template<typename T>
|
||||||
inline PICout operator <<(PICout s, const complex<T> & v) {s.space(); s.setControl(0, true); s << "(" << v.real() << "; " << v.imag() << ")"; s.restoreControl(); return s;}
|
inline PICout operator <<(PICout s, const complex<T> & v) {s.space(); s.setControl(0, true); s << "(" << v.real() << "; " << v.imag() << ")"; s.restoreControl(); return s;}
|
||||||
|
|
||||||
|
void randomize();
|
||||||
|
|
||||||
// [-1 ; 1]
|
// [-1 ; 1]
|
||||||
inline double randomd() {return (double)random() / RAND_MAX * 2. - 1.;}
|
inline double randomd() {return (double)random() / RAND_MAX * 2. - 1.;}
|
||||||
// [-1 ; 1] normal
|
// [-1 ; 1] normal
|
||||||
|
|||||||
@@ -101,7 +101,7 @@ void PILibrary::getLastError() {
|
|||||||
#ifdef WINDOWS
|
#ifdef WINDOWS
|
||||||
liberror = errorString();
|
liberror = errorString();
|
||||||
#else
|
#else
|
||||||
char * e = dlerror();
|
const char * e = dlerror();
|
||||||
if (e) liberror = e;
|
if (e) liberror = e;
|
||||||
else liberror.clear();
|
else liberror.clear();
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user