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

This commit is contained in:
2016-08-24 13:12:49 +00:00
parent 3b6a746644
commit 77a48eb270
133 changed files with 304 additions and 225 deletions

View File

@@ -1,7 +1,7 @@
/*
PIP - Platform Independent Primitives
Text codings coder, based on "iconv"
Copyright (C) 2016 Ivan Pelipenko peri4ko@gmail.com
Copyright (C) 2016 Ivan Pelipenko peri4ko@yandex.ru
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
@@ -35,7 +35,7 @@ PIByteArray PICodec::exec_iconv(const PIString & from, const PIString & to, cons
tf.clear();
tf << str;
tf.close();
exec("/usr/bin/iconv", ("-f=" + from), ("-t=" + to), tf.path());
exec("/usr/bin/iconv", PIStringList() << ("-f=" + from) << ("-t=" + to) << tf.path());
waitForFinish();
return readOutput();
}

View File

@@ -1,7 +1,7 @@
/*
PIP - Platform Independent Primitives
Text codings coder, based on "iconv"
Copyright (C) 2016 Ivan Pelipenko peri4ko@gmail.com
Copyright (C) 2016 Ivan Pelipenko peri4ko@yandex.ru
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

View File

@@ -1,7 +1,7 @@
/*
PIP - Platform Independent Primitives
Introspection module
Copyright (C) 2016 Ivan Pelipenko peri4ko@gmail.com
Copyright (C) 2016 Ivan Pelipenko peri4ko@yandex.ru
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

View File

@@ -1,7 +1,7 @@
/*
PIP - Platform Independent Primitives
Introspection module
Copyright (C) 2016 Ivan Pelipenko peri4ko@gmail.com
Copyright (C) 2016 Ivan Pelipenko peri4ko@yandex.ru
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

View File

@@ -1,7 +1,7 @@
/*
PIP - Platform Independent Primitives
Introspection module
Copyright (C) 2016 Ivan Pelipenko peri4ko@gmail.com
Copyright (C) 2016 Ivan Pelipenko peri4ko@yandex.ru
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

View File

@@ -1,7 +1,7 @@
/*
PIP - Platform Independent Primitives
Introspection module
Copyright (C) 2016 Ivan Pelipenko peri4ko@gmail.com
Copyright (C) 2016 Ivan Pelipenko peri4ko@yandex.ru
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

View File

@@ -1,7 +1,7 @@
/*
PIP - Platform Independent Primitives
Dynamic library
Copyright (C) 2016 Ivan Pelipenko peri4ko@gmail.com
Copyright (C) 2016 Ivan Pelipenko peri4ko@yandex.ru
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

View File

@@ -1,7 +1,7 @@
/*
PIP - Platform Independent Primitives
Dynamic library
Copyright (C) 2016 Ivan Pelipenko peri4ko@gmail.com
Copyright (C) 2016 Ivan Pelipenko peri4ko@yandex.ru
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

View File

@@ -1,7 +1,7 @@
/*
PIP - Platform Independent Primitives
Counter of some PIP types
Copyright (C) 2016 Ivan Pelipenko peri4ko@gmail.com
Copyright (C) 2016 Ivan Pelipenko peri4ko@yandex.ru
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

View File

@@ -1,7 +1,7 @@
/*
PIP - Platform Independent Primitives
Counter of some PIP types
Copyright (C) 2016 Ivan Pelipenko peri4ko@gmail.com
Copyright (C) 2016 Ivan Pelipenko peri4ko@yandex.ru
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

View File

@@ -1,7 +1,7 @@
/*
PIP - Platform Independent Primitives
Process
Copyright (C) 2016 Ivan Pelipenko peri4ko@gmail.com
Copyright (C) 2016 Ivan Pelipenko peri4ko@yandex.ru
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
@@ -19,7 +19,7 @@
#include "piprocess.h"
#ifdef WINDOWS
//# include <.h>
# include <winbase.h>
#else
# include <sys/wait.h>
# include <csignal>
@@ -60,62 +60,27 @@ 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() {
void PIProcess::startProc(bool detached) {
//cout << "run" << endl;
PIString str;
/// arguments convertion
as = 0;
int as = 0;
#ifdef WINDOWS
//args.pop_front();
piForeachC (PIString & i, args)
as += i.lengthAscii() + 1;
as += i.lengthAscii() + 3;
char * a = new char[as];
memset(a, ' ', as - 1);
as = 0;
for (int i = 0; i < args.size_s(); ++i) {
str = args[i];
memcpy(&a[as], str.data(), str.lengthAscii());
as += str.length() + 1;
a[as] = '"';
memcpy(&a[as + 1], str.data(), str.lengthAscii());
a[as + str.length() + 1] = '"';
as += str.length() + 3;
}
a[as - 1] = 0;
//piCout << a;
#else
char * a[args.size_s() + 1];
for (int i = 0; i < args.size_s(); ++i) {
@@ -157,10 +122,11 @@ void PIProcess::run() {
str = args.front();
is_exec = true;
execStarted(str);
if (!detached) execStarted(str);
#ifndef WINDOWS
pid = fork();
if (pid == 0) {
int pid_ = fork();
if (!detached) pid = pid_;
if (pid_ == 0) {
#endif
tf_in = tf_out = tf_err = 0;
//cout << "exec " << tf_in << ", " << tf_out << ", " << tf_err << endl;
@@ -179,13 +145,14 @@ void PIProcess::run() {
0, // Process handle not inheritable
0, // Thread handle not inheritable
false, // Set handle inheritance to FALSE
0, // No creation flags
detached ? DETACHED_PROCESS : 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
{
WaitForSingleObject(pi.hProcess, INFINITE);
if (!detached) WaitForSingleObject(pi.hProcess, INFINITE);
CloseHandle(pi.hThread);
CloseHandle(pi.hProcess);
} else
piCoutObj << "\"CreateProcess\" error, " << errorString();
@@ -197,15 +164,18 @@ void PIProcess::run() {
} else {
msleep(1);
//cout << "wait" << endl;
wait(&exit_code);
/*if (tf_in != 0) fclose(tf_in);
if (tf_out != 0) fclose(tf_out);
if (tf_err != 0) fclose(tf_err);*/
pid = 0;
//cout << "wait done" << endl;
if (!detached) {
wait(&exit_code);
/*if (tf_in != 0) fclose(tf_in);
if (tf_out != 0) fclose(tf_out);
if (tf_err != 0) fclose(tf_err);*/
pid_ = 0;
if (!detached) pid = pid_;
//cout << "wait done" << endl;
}
}
#endif
execFinished(str, exit_code);
if (!detached) execFinished(str, exit_code);
is_exec = false;
for (int i = 0; i < env.size_s(); ++i)
delete e[i];
@@ -216,7 +186,56 @@ void PIProcess::run() {
for (int i = 0; i < args.size_s(); ++i)
delete a[i];
#endif
//cout << "end " << tf_in << ", " << tf_out << ", " << tf_err << endl;
}
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
}
void PIProcess::execIndependent(const PIString & program, const PIStringList & args_) {
PIProcess p;
p.args << program << args_;
p.startProc(true);
}
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() {
startProc(false);
}

View File

@@ -4,7 +4,7 @@
/*
PIP - Platform Independent Primitives
Process
Copyright (C) 2016 Ivan Pelipenko peri4ko@gmail.com
Copyright (C) 2016 Ivan Pelipenko peri4ko@yandex.ru
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
@@ -70,8 +70,6 @@ public:
EVENT_HANDLER1(void, exec, const PIString & , program) {args.clear(); args << program; exec_();}
EVENT_HANDLER2(void, exec, const PIString & , program, const PIString & , arg) {args.clear(); args << program << arg; exec_();}
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);
EVENT_HANDLER(bool, waitForFinish) {return waitForFinish(60000);}
@@ -80,12 +78,17 @@ public:
EVENT1(execStarted, PIString, program)
EVENT2(execFinished, PIString, program, int, exit_code)
static void execIndependent(const PIString & program) {execIndependent(program, PIStringList());}
static void execIndependent(const PIString & program, const PIString & arg) {execIndependent(program, PIStringList() << arg);}
static void execIndependent(const PIString & program, const PIStringList & args_);
static PIStringList currentEnvironment();
static int currentPID();
private:
virtual void run();
void exec_();
void startProc(bool detached);
PIStringList args, env;
PIString wd;
@@ -99,7 +102,7 @@ private:
pid_t pid;
#endif
FILE * tf_in, * tf_out, * tf_err;
int exit_code, sz, as;
int exit_code, sz;
bool is_exec;
};

View File

@@ -1,7 +1,7 @@
/*
PIP - Platform Independent Primitives
Signals
Copyright (C) 2016 Ivan Pelipenko peri4ko@gmail.com
Copyright (C) 2016 Ivan Pelipenko peri4ko@yandex.ru
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

View File

@@ -4,7 +4,7 @@
/*
PIP - Platform Independent Primitives
Signals
Copyright (C) 2016 Ivan Pelipenko peri4ko@gmail.com
Copyright (C) 2016 Ivan Pelipenko peri4ko@yandex.ru
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

View File

@@ -1,7 +1,7 @@
/*
PIP - Platform Independent Primitives
System information
Copyright (C) 2016 Ivan Pelipenko peri4ko@gmail.com
Copyright (C) 2016 Ivan Pelipenko peri4ko@yandex.ru
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

View File

@@ -1,7 +1,7 @@
/*
PIP - Platform Independent Primitives
System information
Copyright (C) 2016 Ivan Pelipenko peri4ko@gmail.com
Copyright (C) 2016 Ivan Pelipenko peri4ko@yandex.ru
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

View File

@@ -1,7 +1,7 @@
/*
PIP - Platform Independent Primitives
Module includes
Copyright (C) 2016 Ivan Pelipenko peri4ko@gmail.com
Copyright (C) 2016 Ivan Pelipenko peri4ko@yandex.ru
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

View File

@@ -1,7 +1,7 @@
/*
PIP - Platform Independent Primitives
Process resource monitor
Copyright (C) 2016 Ivan Pelipenko peri4ko@gmail.com
Copyright (C) 2016 Ivan Pelipenko peri4ko@yandex.ru
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

View File

@@ -1,7 +1,7 @@
/*
PIP - Platform Independent Primitives
Process resource monitor
Copyright (C) 2016 Ivan Pelipenko peri4ko@gmail.com
Copyright (C) 2016 Ivan Pelipenko peri4ko@yandex.ru
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

View File

@@ -1,7 +1,7 @@
/*
PIP - Platform Independent Primitives
System tests results (see system_test folder)
Copyright (C) 2016 Ivan Pelipenko peri4ko@gmail.com
Copyright (C) 2016 Ivan Pelipenko peri4ko@yandex.ru
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

View File

@@ -1,7 +1,7 @@
/*
PIP - Platform Independent Primitives
System tests results (see system_test folder)
Copyright (C) 2016 Ivan Pelipenko peri4ko@gmail.com
Copyright (C) 2016 Ivan Pelipenko peri4ko@yandex.ru
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