version 0.5.0_alpha
git-svn-id: svn://db.shs.com.ru/pip@8 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
PIP - Platform Independent Primitives
|
||||
Text codings coder, based on "iconv"
|
||||
Copyright (C) 2014 Ivan Pelipenko peri4ko@gmail.com
|
||||
Copyright (C) 2015 Ivan Pelipenko peri4ko@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
PIP - Platform Independent Primitives
|
||||
Text codings coder, based on "iconv"
|
||||
Copyright (C) 2014 Ivan Pelipenko peri4ko@gmail.com
|
||||
Copyright (C) 2015 Ivan Pelipenko peri4ko@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
PIP - Platform Independent Primitives
|
||||
Counter of some PIP types
|
||||
Copyright (C) 2014 Ivan Pelipenko peri4ko@gmail.com
|
||||
Copyright (C) 2015 Ivan Pelipenko peri4ko@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
PIP - Platform Independent Primitives
|
||||
Counter of some PIP types
|
||||
Copyright (C) 2014 Ivan Pelipenko peri4ko@gmail.com
|
||||
Copyright (C) 2015 Ivan Pelipenko peri4ko@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
PIP - Platform Independent Primitives
|
||||
Process
|
||||
Copyright (C) 2014 Ivan Pelipenko peri4ko@gmail.com
|
||||
Copyright (C) 2015 Ivan Pelipenko peri4ko@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
@@ -18,6 +18,15 @@
|
||||
*/
|
||||
|
||||
#include "piprocess.h"
|
||||
#ifdef WINDOWS
|
||||
//# include <.h>
|
||||
#else
|
||||
# include <sys/wait.h>
|
||||
# include <csignal>
|
||||
#endif
|
||||
#ifdef MAC_OS
|
||||
# include <crt_externs.h>
|
||||
#endif
|
||||
|
||||
|
||||
PIProcess::PIProcess(): PIThread() {
|
||||
@@ -51,9 +60,47 @@ void PIProcess::exec_() {
|
||||
}
|
||||
|
||||
|
||||
void PIProcess::terminate() {
|
||||
#ifdef WINDOWS
|
||||
if (is_exec) if (!TerminateProcess(pi.hProcess, 0)) return; pi.dwProcessId = 0;
|
||||
#else
|
||||
if (is_exec) kill(pid, SIGKILL); pid = 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
int PIProcess::pID() const {
|
||||
#ifdef WINDOWS
|
||||
return pi.dwProcessId;
|
||||
#else
|
||||
return pid;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
int PIProcess::currentPID() {
|
||||
#ifdef WINDOWS
|
||||
return GetCurrentProcessId();
|
||||
#else
|
||||
return getpid();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
PIStringList PIProcess::currentEnvironment() {
|
||||
PIStringList l;
|
||||
int i = 0;
|
||||
while (environ[i] != 0) {
|
||||
l << environ[i];
|
||||
++i;
|
||||
}
|
||||
return l;
|
||||
}
|
||||
|
||||
|
||||
void PIProcess::run() {
|
||||
//cout << "run" << endl;
|
||||
string str;
|
||||
PIString str;
|
||||
/// arguments convertion
|
||||
as = 0;
|
||||
#ifdef WINDOWS
|
||||
@@ -64,17 +111,17 @@ void PIProcess::run() {
|
||||
memset(a, ' ', as - 1);
|
||||
as = 0;
|
||||
for (int i = 0; i < args.size_s(); ++i) {
|
||||
str = args[i].stdString();
|
||||
memcpy(&a[as], str.c_str(), str.size());
|
||||
str = args[i];
|
||||
memcpy(&a[as], str.data(), str.lengthAscii());
|
||||
as += str.length() + 1;
|
||||
}
|
||||
a[as - 1] = 0;
|
||||
#else
|
||||
char * a[args.size_s() + 1];
|
||||
for (int i = 0; i < args.size_s(); ++i) {
|
||||
str = args[i].stdString();
|
||||
str = args[i];
|
||||
a[i] = new char[str.size() + 1];
|
||||
memcpy(a[i], str.c_str(), str.size());
|
||||
memcpy(a[i], str.data(), str.lengthAscii());
|
||||
a[i][str.size()] = 0;
|
||||
//cout << a[i] << endl;
|
||||
}
|
||||
@@ -83,9 +130,9 @@ void PIProcess::run() {
|
||||
/// environment convertion
|
||||
char ** e = new char*[env.size_s() + 1];
|
||||
for (int i = 0; i < env.size_s(); ++i) {
|
||||
str = env[i].stdString();
|
||||
str = env[i];
|
||||
e[i] = new char[str.size() + 1];
|
||||
memcpy(e[i], str.c_str(), str.size());
|
||||
memcpy(e[i], str.data(), str.lengthAscii());
|
||||
e[i][str.size()] = 0;
|
||||
//cout << e[i] << endl;
|
||||
}
|
||||
@@ -108,9 +155,9 @@ void PIProcess::run() {
|
||||
}
|
||||
//f_err.open(PIIODevice::WriteOnly); f_err.close();
|
||||
|
||||
str = args.front().stdString();
|
||||
str = args.front();
|
||||
is_exec = true;
|
||||
execStarted(PIString(str));
|
||||
execStarted(str);
|
||||
#ifndef WINDOWS
|
||||
pid = fork();
|
||||
if (pid == 0) {
|
||||
@@ -145,7 +192,7 @@ void PIProcess::run() {
|
||||
#else
|
||||
|
||||
//cout << "exec " << tf_in << ", " << tf_out << ", " << tf_err << endl;
|
||||
if (execve(str.c_str(), a, e) < 0)
|
||||
if (execve(str.data(), a, e) < 0)
|
||||
piCoutObj << "\"execve\" error, " << errorString();
|
||||
} else {
|
||||
msleep(1);
|
||||
@@ -158,7 +205,7 @@ void PIProcess::run() {
|
||||
//cout << "wait done" << endl;
|
||||
}
|
||||
#endif
|
||||
execFinished(PIString(str), exit_code);
|
||||
execFinished(str, exit_code);
|
||||
is_exec = false;
|
||||
for (int i = 0; i < env.size_s(); ++i)
|
||||
delete e[i];
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
/*
|
||||
PIP - Platform Independent Primitives
|
||||
Process
|
||||
Copyright (C) 2014 Ivan Pelipenko peri4ko@gmail.com
|
||||
Copyright (C) 2015 Ivan Pelipenko peri4ko@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
@@ -25,11 +25,6 @@
|
||||
|
||||
#include "pithread.h"
|
||||
#include "pifile.h"
|
||||
#ifdef WINDOWS
|
||||
//# include <.h>
|
||||
#else
|
||||
# include <sys/wait.h>
|
||||
#endif
|
||||
|
||||
/// events:
|
||||
/// execStarted(PIString program)
|
||||
@@ -51,13 +46,7 @@ public:
|
||||
virtual ~PIProcess();
|
||||
|
||||
int exitCode() const {return exit_code;}
|
||||
int pID() const {
|
||||
#ifdef WINDOWS
|
||||
return pi.dwProcessId;
|
||||
#else
|
||||
return pid;
|
||||
#endif
|
||||
}
|
||||
int pID() const;
|
||||
|
||||
void setGrabInput(bool yes) {g_in = yes;}
|
||||
void setGrabOutput(bool yes) {g_out = yes;}
|
||||
@@ -84,27 +73,15 @@ public:
|
||||
EVENT_HANDLER3(void, exec, const PIString & , program, const PIString & , arg1, const PIString & , arg2) {args.clear(); args << program << arg1 << arg2; exec_();}
|
||||
EVENT_HANDLER4(void, exec, const PIString & , program, const PIString & , arg1, const PIString & , arg2, const PIString & , arg3) {args.clear(); args << program << arg1 << arg2 << arg3; exec_();}
|
||||
EVENT_HANDLER2(void, exec, const PIString & , program, const PIStringList & , args_) {args << program << args_; exec_();}
|
||||
EVENT_HANDLER(void, terminate) {
|
||||
#ifdef WINDOWS
|
||||
if (is_exec) if (!TerminateProcess(pi.hProcess, 0)) return; pi.dwProcessId = 0;
|
||||
#else
|
||||
if (is_exec) kill(pid, SIGKILL); pid = 0;
|
||||
#endif
|
||||
}
|
||||
EVENT_HANDLER(void, terminate);
|
||||
EVENT_HANDLER(bool, waitForFinish) {return waitForFinish(60000);}
|
||||
EVENT_HANDLER1(bool, waitForFinish, int, timeout_msecs) {return PIThread::waitForFinish(timeout_msecs);}
|
||||
|
||||
EVENT1(execStarted, PIString, program)
|
||||
EVENT2(execFinished, PIString, program, int, exit_code)
|
||||
|
||||
static PIStringList currentEnvironment() {PIStringList l; int i = 0; while (environ[i] != 0) {l << environ[i]; ++i;} return l;}
|
||||
static int currentPID() {
|
||||
#ifdef WINDOWS
|
||||
return GetCurrentProcessId();
|
||||
#else
|
||||
return getpid();
|
||||
#endif
|
||||
}
|
||||
static PIStringList currentEnvironment();
|
||||
static int currentPID();
|
||||
|
||||
private:
|
||||
virtual void run();
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
PIP - Platform Independent Primitives
|
||||
Signals
|
||||
Copyright (C) 2014 Ivan Pelipenko peri4ko@gmail.com
|
||||
Copyright (C) 2015 Ivan Pelipenko peri4ko@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
@@ -18,6 +18,11 @@
|
||||
*/
|
||||
|
||||
#include "pisignals.h"
|
||||
#include <csignal>
|
||||
#ifdef WINDOWS
|
||||
# define SIGUSR1 10
|
||||
# define SIGUSR2 12
|
||||
#endif
|
||||
|
||||
PISignals::SignalEvent PISignals::ret_func;
|
||||
|
||||
@@ -47,6 +52,11 @@ void PISignals::grabSignals(PIFlags<PISignals::Signal> signals_) {
|
||||
}
|
||||
|
||||
|
||||
void PISignals::raiseSignal(PISignals::Signal signal) {
|
||||
raise(signalCode(signal));
|
||||
}
|
||||
|
||||
|
||||
int PISignals::signalCode(PISignals::Signal signal) {
|
||||
switch (signal) {
|
||||
case PISignals::Interrupt: return SIGINT;
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
/*
|
||||
PIP - Platform Independent Primitives
|
||||
Signals
|
||||
Copyright (C) 2014 Ivan Pelipenko peri4ko@gmail.com
|
||||
Copyright (C) 2015 Ivan Pelipenko peri4ko@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
@@ -24,11 +24,6 @@
|
||||
#define PISIGNALS_H
|
||||
|
||||
#include "picontainers.h"
|
||||
#include <csignal>
|
||||
#ifdef WINDOWS
|
||||
# define SIGUSR1 10
|
||||
# define SIGUSR2 12
|
||||
#endif
|
||||
|
||||
class PIP_EXPORT PISignals
|
||||
{
|
||||
@@ -60,7 +55,7 @@ public:
|
||||
// slot is any function format "void <func>(PISignals::Signal)"
|
||||
static void setSlot(SignalEvent slot) {ret_func = slot;}
|
||||
static void grabSignals(PIFlags<PISignals::Signal> signals_);
|
||||
static void raiseSignal(PISignals::Signal signal) {raise(signalCode(signal));}
|
||||
static void raiseSignal(PISignals::Signal signal);
|
||||
|
||||
private:
|
||||
PISignals() {ret_func = 0;}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
PIP - Platform Independent Primitives
|
||||
System information
|
||||
Copyright (C) 2014 Ivan Pelipenko peri4ko@gmail.com
|
||||
Copyright (C) 2015 Ivan Pelipenko peri4ko@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
PIP - Platform Independent Primitives
|
||||
System information
|
||||
Copyright (C) 2014 Ivan Pelipenko peri4ko@gmail.com
|
||||
Copyright (C) 2015 Ivan Pelipenko peri4ko@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
PIP - Platform Independent Primitives
|
||||
Process resource monitor
|
||||
Copyright (C) 2014 Ivan Pelipenko peri4ko@gmail.com
|
||||
Copyright (C) 2015 Ivan Pelipenko peri4ko@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
PIP - Platform Independent Primitives
|
||||
Process resource monitor
|
||||
Copyright (C) 2014 Ivan Pelipenko peri4ko@gmail.com
|
||||
Copyright (C) 2015 Ivan Pelipenko peri4ko@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
@@ -22,6 +22,9 @@
|
||||
|
||||
#include "pithread.h"
|
||||
#include "piprocess.h"
|
||||
#ifdef WINDOWS
|
||||
# include <psapi.h>
|
||||
#endif
|
||||
|
||||
class PIP_EXPORT PISystemMonitor: public PIThread
|
||||
{
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
PIP - Platform Independent Primitives
|
||||
System tests results (see system_test folder)
|
||||
Copyright (C) 2014 Ivan Pelipenko peri4ko@gmail.com
|
||||
Copyright (C) 2015 Ivan Pelipenko peri4ko@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
PIP - Platform Independent Primitives
|
||||
System tests results (see system_test folder)
|
||||
Copyright (C) 2014 Ivan Pelipenko peri4ko@gmail.com
|
||||
Copyright (C) 2015 Ivan Pelipenko peri4ko@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
||||
Reference in New Issue
Block a user