From 8cdf50a45fcfc03610dda43f7c086f6dcba4ba2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=91=D1=8B=D1=87=D0=BA=D0=BE=D0=B2=20=D0=90=D0=BD=D0=B4?= =?UTF-8?q?=D1=80=D0=B5=D0=B9?= Date: Fri, 14 Apr 2017 14:15:22 +0000 Subject: [PATCH] git-svn-id: svn://db.shs.com.ru/pip@361 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5 --- src/auxiliary/piterminal/main.cpp | 7 ++-- src/console/piconsole.cpp | 6 +++- src/console/pikbdlistener.cpp | 6 +++- src/console/piscreen.cpp | 6 +++- src/console/piterminal.cpp | 8 +++-- src/core/pibase.h | 12 +++---- src/core/picout.cpp | 6 +++- src/core/piincludes.cpp | 5 +++ src/core/piinit.cpp | 26 +++++++++++---- src/core/piinit.h | 5 +-- src/core/pitime.cpp | 6 +++- src/core/pitime.h | 18 ++++++++++- src/io/pidir.cpp | 6 +++- src/io/piethernet.cpp | 6 +++- src/io/pifile.cpp | 7 +++- src/io/piserial.cpp | 6 +++- src/io/pisharedmemory.cpp | 6 +++- src/io/piusb.cpp | 5 +++ src/system/pilibrary.cpp | 5 ++- src/system/piprocess.cpp | 54 +++++++++++++++++++------------ src/system/piprocess.h | 7 +--- src/system/pisysteminfo.cpp | 6 +++- src/system/pisystemmonitor.cpp | 7 +++- src/thread/pimutex.cpp | 5 ++- src/thread/pithread.cpp | 8 ++++- 25 files changed, 175 insertions(+), 64 deletions(-) diff --git a/src/auxiliary/piterminal/main.cpp b/src/auxiliary/piterminal/main.cpp index 7a5a2f35..ce227531 100644 --- a/src/auxiliary/piterminal/main.cpp +++ b/src/auxiliary/piterminal/main.cpp @@ -1,5 +1,8 @@ -#include "piplatform.h" - +#include "pibase.h" +#ifdef WINDOWS +# include +# include +#endif #ifndef WINDOWS int main (int argc, char * argv[]) { return 0; diff --git a/src/console/piconsole.cpp b/src/console/piconsole.cpp index f38c7020..5c36812f 100644 --- a/src/console/piconsole.cpp +++ b/src/console/piconsole.cpp @@ -16,7 +16,11 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ - +#include "pibase.h" +#ifdef WINDOWS +# include +# include +#endif #include "piconsole.h" #include "pipeer.h" #include "piprotocol.h" diff --git a/src/console/pikbdlistener.cpp b/src/console/pikbdlistener.cpp index 276db77b..2f525d02 100644 --- a/src/console/pikbdlistener.cpp +++ b/src/console/pikbdlistener.cpp @@ -16,7 +16,11 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ - +#include "pibase.h" +#ifdef WINDOWS +# include +# include +#endif #include "pikbdlistener.h" #ifndef WINDOWS # include diff --git a/src/console/piscreen.cpp b/src/console/piscreen.cpp index 0793cb78..402eb78c 100644 --- a/src/console/piscreen.cpp +++ b/src/console/piscreen.cpp @@ -16,7 +16,11 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ - +#include "pibase.h" +#ifdef WINDOWS +# include +# include +#endif #include "piscreen.h" #ifndef WINDOWS # include diff --git a/src/console/piterminal.cpp b/src/console/piterminal.cpp index 219ccb54..48d55ac9 100644 --- a/src/console/piterminal.cpp +++ b/src/console/piterminal.cpp @@ -16,13 +16,17 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ - +#include "pibase.h" +#ifdef WINDOWS +# include +# include +#endif #include "piterminal.h" +# include "pisharedmemory.h" #ifdef CC_GCC # include #endif #ifdef WINDOWS -# include "pisharedmemory.h" # include # include # include diff --git a/src/core/pibase.h b/src/core/pibase.h index c985cbdb..5f21bc88 100644 --- a/src/core/pibase.h +++ b/src/core/pibase.h @@ -95,8 +95,8 @@ #include #include #ifdef WINDOWS -# include -# include +//# include +//# include # 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 diff --git a/src/core/picout.cpp b/src/core/picout.cpp index ea748f56..6f301433 100644 --- a/src/core/picout.cpp +++ b/src/core/picout.cpp @@ -16,7 +16,11 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ - +#include "pibase.h" +#ifdef WINDOWS +# include +# include +#endif #include "picout.h" #include "piconsole.h" #ifdef WINDOWS diff --git a/src/core/piincludes.cpp b/src/core/piincludes.cpp index 943a0e99..ffe2d130 100755 --- a/src/core/piincludes.cpp +++ b/src/core/piincludes.cpp @@ -18,7 +18,12 @@ */ #include "piincludes.h" +#ifdef WINDOWS +# include +# include +#endif #include "piconsole.h" +#include "pitime.h" #ifndef QNX # include #else diff --git a/src/core/piinit.cpp b/src/core/piinit.cpp index d5df2292..29ce3657 100644 --- a/src/core/piinit.cpp +++ b/src/core/piinit.cpp @@ -19,6 +19,11 @@ #include "piplatform.h" #include "piinit.h" +#ifdef WINDOWS +# include +# include +#endif +#include "pitime.h" #include "pisignals.h" #include "piobject.h" #include "pisysteminfo.h" @@ -26,7 +31,8 @@ #include "piprocess.h" #ifdef WINDOWS # include - extern FILETIME __pi_ftjan1970; + extern FILETIME __pi_ftjan1970; + extern PINtSetTimerResolution setTimerResolutionAddr; #else # include # include @@ -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); diff --git a/src/core/piinit.h b/src/core/piinit.h index f6a46315..238b3713 100644 --- a/src/core/piinit.h +++ b/src/core/piinit.h @@ -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; }; diff --git a/src/core/pitime.cpp b/src/core/pitime.cpp index fe985565..42cc035b 100755 --- a/src/core/pitime.cpp +++ b/src/core/pitime.cpp @@ -16,7 +16,11 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ - +#include "pibase.h" +#ifdef WINDOWS +# include +# include +#endif #include "pitime.h" #include "pisystemtests.h" #ifdef WINDOWS diff --git a/src/core/pitime.h b/src/core/pitime.h index 57326911..ea6eaa7d 100755 --- a/src/core/pitime.h +++ b/src/core/pitime.h @@ -22,8 +22,11 @@ #ifndef PITIME_H #define PITIME_H - #include "pistring.h" +#ifdef WINDOWS +# include + 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; diff --git a/src/io/pidir.cpp b/src/io/pidir.cpp index 4ed65a0a..576fbbaf 100755 --- a/src/io/pidir.cpp +++ b/src/io/pidir.cpp @@ -16,7 +16,11 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ - +#include "pibase.h" +#ifdef WINDOWS +# include +# include +#endif #include "pidir.h" //#if !defined(ANDROID) diff --git a/src/io/piethernet.cpp b/src/io/piethernet.cpp index 6ccafe5c..39c82717 100755 --- a/src/io/piethernet.cpp +++ b/src/io/piethernet.cpp @@ -16,7 +16,11 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ - +#include "pibase.h" +#ifdef WINDOWS +# include +# include +#endif #include "piethernet.h" #include "piconfig.h" #include "pisysteminfo.h" diff --git a/src/io/pifile.cpp b/src/io/pifile.cpp index d1e8b3b7..205a4a63 100755 --- a/src/io/pifile.cpp +++ b/src/io/pifile.cpp @@ -16,7 +16,11 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ - +#include "pibase.h" +#ifdef WINDOWS +# include +# include +#endif #include "pifile.h" #include "pidir.h" #ifdef WINDOWS @@ -33,6 +37,7 @@ # define S_IFCHR 0x10 # define S_IFSOCK 0x20 #else +# include # include # include # include diff --git a/src/io/piserial.cpp b/src/io/piserial.cpp index 61ece534..dc3daeaa 100755 --- a/src/io/piserial.cpp +++ b/src/io/piserial.cpp @@ -16,7 +16,11 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ - +#include "pibase.h" +#ifdef WINDOWS +# include +# include +#endif #include "piserial.h" #include "piconfig.h" #include "pidir.h" diff --git a/src/io/pisharedmemory.cpp b/src/io/pisharedmemory.cpp index 5b36dca8..a4e7e667 100644 --- a/src/io/pisharedmemory.cpp +++ b/src/io/pisharedmemory.cpp @@ -16,7 +16,11 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ - +#include "pibase.h" +#ifdef WINDOWS +# include +# include +#endif #include "pisharedmemory.h" #ifdef WINDOWS diff --git a/src/io/piusb.cpp b/src/io/piusb.cpp index 5b75a890..62d6d4b6 100755 --- a/src/io/piusb.cpp +++ b/src/io/piusb.cpp @@ -1,3 +1,8 @@ +#include "pibase.h" +#ifdef WINDOWS +# include +# include +#endif #include "piusb.h" #include "piconfig.h" diff --git a/src/system/pilibrary.cpp b/src/system/pilibrary.cpp index 93e99e68..9b15bb48 100644 --- a/src/system/pilibrary.cpp +++ b/src/system/pilibrary.cpp @@ -18,7 +18,10 @@ */ #include "pilibrary.h" -#ifndef WINDOWS +#ifdef WINDOWS +# include +# include +#else # include #endif diff --git a/src/system/piprocess.cpp b/src/system/piprocess.cpp index d444e371..022823d5 100755 --- a/src/system/piprocess.cpp +++ b/src/system/piprocess.cpp @@ -17,10 +17,13 @@ along with this program. If not, see . */ -#include "piprocess.h" +#include "pibase.h" #ifdef WINDOWS -# include -#else +# include +# include +#endif +#include "piprocess.h" +#ifndef WINDOWS # include # include #endif @@ -31,12 +34,23 @@ # include #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 } diff --git a/src/system/piprocess.h b/src/system/piprocess.h index 56ea69e4..eca9d433 100755 --- a/src/system/piprocess.h +++ b/src/system/piprocess.h @@ -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; diff --git a/src/system/pisysteminfo.cpp b/src/system/pisysteminfo.cpp index a9187643..9d74b146 100644 --- a/src/system/pisysteminfo.cpp +++ b/src/system/pisysteminfo.cpp @@ -16,7 +16,11 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ - +#include "pibase.h" +#ifdef WINDOWS +# include +# include +#endif #include "pisysteminfo.h" #include "pidir.h" #include "pitime.h" diff --git a/src/system/pisystemmonitor.cpp b/src/system/pisystemmonitor.cpp index 04e2b749..e3a05e77 100755 --- a/src/system/pisystemmonitor.cpp +++ b/src/system/pisystemmonitor.cpp @@ -17,10 +17,15 @@ along with this program. If not, see . */ +#include "pibase.h" +#ifdef WINDOWS +# include +# include +#endif #include "pisystemmonitor.h" #include "pisysteminfo.h" #ifdef WINDOWS -# include "tlhelp32.h" +# include #endif #ifdef CC_GCC # include diff --git a/src/thread/pimutex.cpp b/src/thread/pimutex.cpp index 5873eb60..0ecccf56 100755 --- a/src/thread/pimutex.cpp +++ b/src/thread/pimutex.cpp @@ -18,7 +18,10 @@ */ #include "pimutex.h" - +#ifdef WINDOWS +# include +# include +#endif /** \class PIMutex * \brief Mutex diff --git a/src/thread/pithread.cpp b/src/thread/pithread.cpp index 6d9e56f3..0a0e4d85 100755 --- a/src/thread/pithread.cpp +++ b/src/thread/pithread.cpp @@ -17,12 +17,18 @@ along with this program. If not, see . */ +#include "pibase.h" +#ifdef WINDOWS +# include +# include +#endif #include "pithread.h" #include "pisystemtests.h" #include "piintrospection_proxy.h" #include #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