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

This commit is contained in:
2017-04-14 14:15:22 +00:00
parent db1410d918
commit 8cdf50a45f
25 changed files with 175 additions and 64 deletions

View File

@@ -1,5 +1,8 @@
#include "piplatform.h"
#include "pibase.h"
#ifdef WINDOWS
# include <windef.h>
# include <winbase.h>
#endif
#ifndef WINDOWS
int main (int argc, char * argv[]) {
return 0;

View File

@@ -16,7 +16,11 @@
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "pibase.h"
#ifdef WINDOWS
# include <windef.h>
# include <winbase.h>
#endif
#include "piconsole.h"
#include "pipeer.h"
#include "piprotocol.h"

View File

@@ -16,7 +16,11 @@
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "pibase.h"
#ifdef WINDOWS
# include <windef.h>
# include <winbase.h>
#endif
#include "pikbdlistener.h"
#ifndef WINDOWS
# include <termios.h>

View File

@@ -16,7 +16,11 @@
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "pibase.h"
#ifdef WINDOWS
# include <windef.h>
# include <winbase.h>
#endif
#include "piscreen.h"
#ifndef WINDOWS
# include <sys/ioctl.h>

View File

@@ -16,13 +16,17 @@
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "pibase.h"
#ifdef WINDOWS
# include <windef.h>
# include <winbase.h>
#endif
#include "piterminal.h"
# include "pisharedmemory.h"
#ifdef CC_GCC
# include <unistd.h>
#endif
#ifdef WINDOWS
# include "pisharedmemory.h"
# include <windows.h>
# include <wincon.h>
# include <winuser.h>

View File

@@ -95,8 +95,8 @@
#include <stddef.h>
#include <stdlib.h>
#ifdef WINDOWS
# include <windef.h>
# include <winbase.h>
//# include <windef.h>
//# include <winbase.h>
# ifdef CC_VC
# define SHUT_RDWR 2
# pragma comment(lib, "Ws2_32.lib")
@@ -105,11 +105,9 @@
# else
# define SHUT_RDWR SD_BOTH
# endif
typedef int socklen_t;
typedef void(*PINtSetTimerResolution)(ULONG, BOOLEAN, PULONG);
extern long long __pi_perf_freq;
extern PINtSetTimerResolution setTimerResolutionAddr;
inline int random() {return rand();}
typedef int socklen_t;
extern long long __pi_perf_freq;
inline int random() {return rand();}
#endif
#ifdef ANDROID

View File

@@ -16,7 +16,11 @@
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "pibase.h"
#ifdef WINDOWS
# include <windef.h>
# include <winbase.h>
#endif
#include "picout.h"
#include "piconsole.h"
#ifdef WINDOWS

View File

@@ -18,7 +18,12 @@
*/
#include "piincludes.h"
#ifdef WINDOWS
# include <windef.h>
# include <winbase.h>
#endif
#include "piconsole.h"
#include "pitime.h"
#ifndef QNX
# include <clocale>
#else

View File

@@ -19,6 +19,11 @@
#include "piplatform.h"
#include "piinit.h"
#ifdef WINDOWS
# include <windef.h>
# include <winbase.h>
#endif
#include "pitime.h"
#include "pisignals.h"
#include "piobject.h"
#include "pisysteminfo.h"
@@ -26,7 +31,8 @@
#include "piprocess.h"
#ifdef WINDOWS
# include <winsock2.h>
extern FILETIME __pi_ftjan1970;
extern FILETIME __pi_ftjan1970;
extern PINtSetTimerResolution setTimerResolutionAddr;
#else
# include <pwd.h>
# include <sys/utsname.h>
@@ -68,6 +74,12 @@
static locale_t currentLocale_t = 0;
#endif
PRIVATE_DEFINITION_START(PIInit)
#ifdef WINDOWS
HMODULE ntlib;
ULONG prev_res;
#endif
PRIVATE_DEFINITION_END(PIInit)
void __sighandler__(PISignals::Signal s) {
//piCout << Hex << int(s);
@@ -129,9 +141,9 @@ PIInit::PIInit() {
if (__pi_perf_freq == 0) __pi_perf_freq = -1;
// Sleep precision init
ntlib = LoadLibrary("ntdll.dll");
if (ntlib) setTimerResolutionAddr = (PINtSetTimerResolution)GetProcAddress(ntlib, "NtSetTimerResolution");
/*if (setTimerResolution) setTimerResolutionAddr(1, TRUE, &prev_res);*/
PRIVATE->ntlib = LoadLibrary("ntdll.dll");
if (PRIVATE->ntlib) setTimerResolutionAddr = (PINtSetTimerResolution)GetProcAddress(PRIVATE->ntlib, "NtSetTimerResolution");
/*if (setTimerResolution) setTimerResolutionAddr(1, TRUE, &(PRIVATE->prev_res));*/
# endif
//piDebug = true;
# ifdef HAS_LOCALE
@@ -262,9 +274,9 @@ PIInit::~PIInit() {
file_charset = 0;
#ifdef WINDOWS
WSACleanup();
//if (setTimerResolution) setTimerResolutionAddr(prev_res, TRUE, &prev_res);
if (ntlib) FreeLibrary(ntlib);
ntlib = 0;
//if (setTimerResolution) setTimerResolutionAddr(PRIVATE->prev_res, TRUE, &(PRIVATE->prev_res));
if (PRIVATE->ntlib) FreeLibrary(PRIVATE->ntlib);
PRIVATE->ntlib = 0;
#endif
#ifdef MAC_OS
mach_port_deallocate(mach_task_self(), __pi_mac_clock);

View File

@@ -60,10 +60,7 @@ public:
private:
void setFileCharset(const char *charset);
bool fileExists(const PIString & p);
#ifdef WINDOWS
HMODULE ntlib;
ULONG prev_res;
#endif
PRIVATE_DECLARATION
char * file_charset;
};

View File

@@ -16,7 +16,11 @@
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "pibase.h"
#ifdef WINDOWS
# include <windef.h>
# include <winbase.h>
#endif
#include "pitime.h"
#include "pisystemtests.h"
#ifdef WINDOWS

View File

@@ -22,8 +22,11 @@
#ifndef PITIME_H
#define PITIME_H
#include "pistring.h"
#ifdef WINDOWS
# include <windef.h>
typedef void(*PINtSetTimerResolution)(ULONG, BOOLEAN, PULONG);
#endif
//! \brief Sleep for "msecs" milliseconds
@@ -237,6 +240,19 @@ struct PIP_EXPORT PIDateTime {
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;

View File

@@ -16,7 +16,11 @@
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "pibase.h"
#ifdef WINDOWS
# include <windef.h>
# include <winbase.h>
#endif
#include "pidir.h"
//#if !defined(ANDROID)

View File

@@ -16,7 +16,11 @@
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "pibase.h"
#ifdef WINDOWS
# include <windef.h>
# include <winbase.h>
#endif
#include "piethernet.h"
#include "piconfig.h"
#include "pisysteminfo.h"

View File

@@ -16,7 +16,11 @@
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "pibase.h"
#ifdef WINDOWS
# include <windef.h>
# include <winbase.h>
#endif
#include "pifile.h"
#include "pidir.h"
#ifdef WINDOWS
@@ -33,6 +37,7 @@
# define S_IFCHR 0x10
# define S_IFSOCK 0x20
#else
# include <stdio.h>
# include <sys/stat.h>
# include <sys/time.h>
# include <fcntl.h>

View File

@@ -16,7 +16,11 @@
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "pibase.h"
#ifdef WINDOWS
# include <windef.h>
# include <winbase.h>
#endif
#include "piserial.h"
#include "piconfig.h"
#include "pidir.h"

View File

@@ -16,7 +16,11 @@
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "pibase.h"
#ifdef WINDOWS
# include <windef.h>
# include <winbase.h>
#endif
#include "pisharedmemory.h"
#ifdef WINDOWS

View File

@@ -1,3 +1,8 @@
#include "pibase.h"
#ifdef WINDOWS
# include <windef.h>
# include <winbase.h>
#endif
#include "piusb.h"
#include "piconfig.h"

View File

@@ -18,7 +18,10 @@
*/
#include "pilibrary.h"
#ifndef WINDOWS
#ifdef WINDOWS
# include <windef.h>
# include <winbase.h>
#else
# include <dlfcn.h>
#endif

View File

@@ -17,10 +17,13 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "piprocess.h"
#include "pibase.h"
#ifdef WINDOWS
# include <winbase.h>
#else
# include <windef.h>
# include <winbase.h>
#endif
#include "piprocess.h"
#ifndef WINDOWS
# include <sys/wait.h>
# include <csignal>
#endif
@@ -31,12 +34,23 @@
# include <unistd.h>
#endif
PRIVATE_DEFINITION_START(PIProcess)
#ifdef WINDOWS
STARTUPINFOA si;
PROCESS_INFORMATION pi;
#else
pid_t pid;
#endif
PRIVATE_DEFINITION_END(PIProcess)
PIProcess::PIProcess(): PIThread() {
exit_code = -1;
#ifdef WINDOWS
pi.dwProcessId = 0;
PRIVATE->pi.dwProcessId = 0;
#else
pid = 0;
PRIVATE->pid = 0;
#endif
is_exec = false;
g_in = g_out = g_err = false;
@@ -128,7 +142,7 @@ void PIProcess::startProc(bool detached) {
if (!detached) execStarted(str);
#ifndef WINDOWS
int pid_ = fork();
if (!detached) pid = pid_;
if (!detached) PRIVATE->pid = pid_;
if (pid_ == 0) {
#endif
tf_in = tf_out = tf_err = 0;
@@ -141,8 +155,8 @@ void PIProcess::startProc(bool detached) {
if (!wd.isEmpty()) chdir(wd.data());
#endif
#ifdef WINDOWS
GetStartupInfoA(&si);
memset(&pi, 0, sizeof(pi));
GetStartupInfoA(&(PRIVATE->si));
memset(&(PRIVATE->pi), 0, sizeof(PRIVATE->pi));
if(CreateProcessA(0, // No module name (use command line)
a, // Command line
0, // Process handle not inheritable
@@ -151,12 +165,12 @@ void PIProcess::startProc(bool detached) {
detached ? DETACHED_PROCESS/*CREATE_NEW_CONSOLE*/ : 0, // Creation flags
0,//e, // Use environment
wd.isEmpty() ? 0 : wd.data(), // Use working directory
&si, // Pointer to STARTUPINFO structure
&pi)) // Pointer to PROCESS_INFORMATION structure
&(PRIVATE->si), // Pointer to STARTUPINFO structure
&(PRIVATE->pi))) // Pointer to PROCESS_INFORMATION structure
{
if (!detached) WaitForSingleObject(pi.hProcess, INFINITE);
CloseHandle(pi.hThread);
CloseHandle(pi.hProcess);
if (!detached) WaitForSingleObject(PRIVATE->pi.hProcess, INFINITE);
CloseHandle(PRIVATE->pi.hThread);
CloseHandle(PRIVATE->pi.hProcess);
} else
piCoutObj << "\"CreateProcess\" error, " << errorString();
#else
@@ -173,7 +187,7 @@ void PIProcess::startProc(bool detached) {
if (tf_out != 0) fclose(tf_out);
if (tf_err != 0) fclose(tf_err);*/
pid_ = 0;
if (!detached) pid = pid_;
if (!detached) PRIVATE->pid = pid_;
//cout << "wait done" << endl;
}
}
@@ -195,13 +209,13 @@ void PIProcess::startProc(bool detached) {
void PIProcess::terminate() {
#ifdef WINDOWS
if (is_exec)
if (!TerminateProcess(pi.hProcess, 0))
if (!TerminateProcess(PRIVATE->pi.hProcess, 0))
return;
pi.dwProcessId = 0;
PRIVATE->pi.dwProcessId = 0;
#else
if (is_exec)
kill(pid, SIGKILL);
pid = 0;
kill(PRIVATE->pid, SIGKILL);
PRIVATE->pid = 0;
#endif
}
@@ -215,9 +229,9 @@ void PIProcess::execIndependent(const PIString & program, const PIStringList & a
int PIProcess::pID() const {
#ifdef WINDOWS
return pi.dwProcessId;
return PRIVATE->pi.dwProcessId;
#else
return pid;
return PRIVATE->pid;
#endif
}

View File

@@ -95,12 +95,7 @@ private:
PIByteArray out;
PIFile f_in, f_out, f_err;
bool g_in, g_out, g_err, t_in, t_out, t_err;
#ifdef WINDOWS
STARTUPINFOA si;
PROCESS_INFORMATION pi;
#else
pid_t pid;
#endif
PRIVATE_DECLARATION
FILE * tf_in, * tf_out, * tf_err;
int exit_code, sz;
bool is_exec;

View File

@@ -16,7 +16,11 @@
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "pibase.h"
#ifdef WINDOWS
# include <windef.h>
# include <winbase.h>
#endif
#include "pisysteminfo.h"
#include "pidir.h"
#include "pitime.h"

View File

@@ -17,10 +17,15 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "pibase.h"
#ifdef WINDOWS
# include <windef.h>
# include <winbase.h>
#endif
#include "pisystemmonitor.h"
#include "pisysteminfo.h"
#ifdef WINDOWS
# include "tlhelp32.h"
# include <tlhelp32.h>
#endif
#ifdef CC_GCC
# include <unistd.h>

View File

@@ -18,7 +18,10 @@
*/
#include "pimutex.h"
#ifdef WINDOWS
# include <windef.h>
# include <winbase.h>
#endif
/** \class PIMutex
* \brief Mutex

View File

@@ -17,12 +17,18 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "pibase.h"
#ifdef WINDOWS
# include <windef.h>
# include <winbase.h>
#endif
#include "pithread.h"
#include "pisystemtests.h"
#include "piintrospection_proxy.h"
#include <signal.h>
#ifdef WINDOWS
void __PISetTimerResolution() {if (setTimerResolutionAddr == NULL) return; ULONG ret; setTimerResolutionAddr(1, TRUE, &ret);}
extern PINtSetTimerResolution setTimerResolutionAddr;
void __PISetTimerResolution() {if (setTimerResolutionAddr == NULL) return; ULONG ret; setTimerResolutionAddr(1, TRUE, &ret);}
#endif
#ifdef MAC_OS
# include <pthread.h>