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

This commit is contained in:
2015-02-28 18:35:47 +00:00
parent 8e451c891d
commit 13336674eb
154 changed files with 44021 additions and 0 deletions

View File

@@ -0,0 +1,5 @@
add_executable(pip_cmg "main.cpp")
target_link_libraries(pip_cmg pip)
if (DEFINED LIB)
install(TARGETS pip_cmg DESTINATION ${CMAKE_INSTALL_PREFIX}/bin)
endif ()

View File

@@ -0,0 +1,209 @@
# CMAKE generated file: DO NOT EDIT!
# Generated by "Unix Makefiles" Generator, CMake Version 2.8
# Default target executed when no arguments are given to make.
default_target: all
.PHONY : default_target
#=============================================================================
# Special targets provided by cmake.
# Disable implicit rules so canonical targets will work.
.SUFFIXES:
# Remove some rules from gmake that .SUFFIXES does not remove.
SUFFIXES =
.SUFFIXES: .hpux_make_needs_suffix_list
# Suppress display of executed commands.
$(VERBOSE).SILENT:
# A target that is always out of date.
cmake_force:
.PHONY : cmake_force
#=============================================================================
# Set environment variables for the build.
# The shell in which to execute make rules.
SHELL = /bin/sh
# The CMake executable.
CMAKE_COMMAND = /usr/bin/cmake
# The command to remove a file.
RM = /usr/bin/cmake -E remove -f
# Escaping for special characters.
EQUALS = =
# The top-level source directory on which CMake was run.
CMAKE_SOURCE_DIR = /home/andrey/linux_build/libs
# The top-level build directory on which CMake was run.
CMAKE_BINARY_DIR = /home/andrey/linux_build/libs
#=============================================================================
# Targets provided globally by CMake.
# Special rule for the target edit_cache
edit_cache:
@$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Running interactive CMake command-line interface..."
/usr/bin/cmake -i .
.PHONY : edit_cache
# Special rule for the target edit_cache
edit_cache/fast: edit_cache
.PHONY : edit_cache/fast
# Special rule for the target install
install: preinstall
@$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Install the project..."
/usr/bin/cmake -P cmake_install.cmake
.PHONY : install
# Special rule for the target install
install/fast: preinstall/fast
@$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Install the project..."
/usr/bin/cmake -P cmake_install.cmake
.PHONY : install/fast
# Special rule for the target install/local
install/local: preinstall
@$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Installing only the local directory..."
/usr/bin/cmake -DCMAKE_INSTALL_LOCAL_ONLY=1 -P cmake_install.cmake
.PHONY : install/local
# Special rule for the target install/local
install/local/fast: install/local
.PHONY : install/local/fast
# Special rule for the target install/strip
install/strip: preinstall
@$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Installing the project stripped..."
/usr/bin/cmake -DCMAKE_INSTALL_DO_STRIP=1 -P cmake_install.cmake
.PHONY : install/strip
# Special rule for the target install/strip
install/strip/fast: install/strip
.PHONY : install/strip/fast
# Special rule for the target list_install_components
list_install_components:
@$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Available install components are: \"Unspecified\""
.PHONY : list_install_components
# Special rule for the target list_install_components
list_install_components/fast: list_install_components
.PHONY : list_install_components/fast
# Special rule for the target rebuild_cache
rebuild_cache:
@$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Running CMake to regenerate build system..."
/usr/bin/cmake -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR)
.PHONY : rebuild_cache
# Special rule for the target rebuild_cache
rebuild_cache/fast: rebuild_cache
.PHONY : rebuild_cache/fast
# The main all target
all: cmake_check_build_system
cd /home/andrey/linux_build/libs && $(CMAKE_COMMAND) -E cmake_progress_start /home/andrey/linux_build/libs/CMakeFiles /home/andrey/linux_build/libs/pip/utils/code_model_generator/CMakeFiles/progress.marks
cd /home/andrey/linux_build/libs && $(MAKE) -f CMakeFiles/Makefile2 pip/utils/code_model_generator/all
$(CMAKE_COMMAND) -E cmake_progress_start /home/andrey/linux_build/libs/CMakeFiles 0
.PHONY : all
# The main clean target
clean:
cd /home/andrey/linux_build/libs && $(MAKE) -f CMakeFiles/Makefile2 pip/utils/code_model_generator/clean
.PHONY : clean
# The main clean target
clean/fast: clean
.PHONY : clean/fast
# Prepare targets for installation.
preinstall: all
cd /home/andrey/linux_build/libs && $(MAKE) -f CMakeFiles/Makefile2 pip/utils/code_model_generator/preinstall
.PHONY : preinstall
# Prepare targets for installation.
preinstall/fast:
cd /home/andrey/linux_build/libs && $(MAKE) -f CMakeFiles/Makefile2 pip/utils/code_model_generator/preinstall
.PHONY : preinstall/fast
# clear depends
depend:
cd /home/andrey/linux_build/libs && $(CMAKE_COMMAND) -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) --check-build-system CMakeFiles/Makefile.cmake 1
.PHONY : depend
# Convenience name for target.
pip/utils/code_model_generator/CMakeFiles/pip_cmg.dir/rule:
cd /home/andrey/linux_build/libs && $(MAKE) -f CMakeFiles/Makefile2 pip/utils/code_model_generator/CMakeFiles/pip_cmg.dir/rule
.PHONY : pip/utils/code_model_generator/CMakeFiles/pip_cmg.dir/rule
# Convenience name for target.
pip_cmg: pip/utils/code_model_generator/CMakeFiles/pip_cmg.dir/rule
.PHONY : pip_cmg
# fast build rule for target.
pip_cmg/fast:
cd /home/andrey/linux_build/libs && $(MAKE) -f pip/utils/code_model_generator/CMakeFiles/pip_cmg.dir/build.make pip/utils/code_model_generator/CMakeFiles/pip_cmg.dir/build
.PHONY : pip_cmg/fast
main.o: main.cpp.o
.PHONY : main.o
# target to build an object file
main.cpp.o:
cd /home/andrey/linux_build/libs && $(MAKE) -f pip/utils/code_model_generator/CMakeFiles/pip_cmg.dir/build.make pip/utils/code_model_generator/CMakeFiles/pip_cmg.dir/main.cpp.o
.PHONY : main.cpp.o
main.i: main.cpp.i
.PHONY : main.i
# target to preprocess a source file
main.cpp.i:
cd /home/andrey/linux_build/libs && $(MAKE) -f pip/utils/code_model_generator/CMakeFiles/pip_cmg.dir/build.make pip/utils/code_model_generator/CMakeFiles/pip_cmg.dir/main.cpp.i
.PHONY : main.cpp.i
main.s: main.cpp.s
.PHONY : main.s
# target to generate assembly for a file
main.cpp.s:
cd /home/andrey/linux_build/libs && $(MAKE) -f pip/utils/code_model_generator/CMakeFiles/pip_cmg.dir/build.make pip/utils/code_model_generator/CMakeFiles/pip_cmg.dir/main.cpp.s
.PHONY : main.cpp.s
# Help Target
help:
@echo "The following are some of the valid targets for this Makefile:"
@echo "... all (the default if no target is provided)"
@echo "... clean"
@echo "... depend"
@echo "... edit_cache"
@echo "... install"
@echo "... install/local"
@echo "... install/strip"
@echo "... list_install_components"
@echo "... pip_cmg"
@echo "... rebuild_cache"
@echo "... main.o"
@echo "... main.i"
@echo "... main.s"
.PHONY : help
#=============================================================================
# Special targets to cleanup operation of make.
# Special rule to run CMake to check the build system integrity.
# No rule that depends on this can have commands that come from listfiles
# because they might be regenerated.
cmake_check_build_system:
cd /home/andrey/linux_build/libs && $(CMAKE_COMMAND) -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) --check-build-system CMakeFiles/Makefile.cmake 0
.PHONY : cmake_check_build_system

View File

@@ -0,0 +1,60 @@
# Install script for directory: /home/andrey/linux_build/libs/pip/utils/code_model_generator
# Set the install prefix
IF(NOT DEFINED CMAKE_INSTALL_PREFIX)
SET(CMAKE_INSTALL_PREFIX "/usr")
ENDIF(NOT DEFINED CMAKE_INSTALL_PREFIX)
STRING(REGEX REPLACE "/$" "" CMAKE_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}")
# Set the install configuration name.
IF(NOT DEFINED CMAKE_INSTALL_CONFIG_NAME)
IF(BUILD_TYPE)
STRING(REGEX REPLACE "^[^A-Za-z0-9_]+" ""
CMAKE_INSTALL_CONFIG_NAME "${BUILD_TYPE}")
ELSE(BUILD_TYPE)
SET(CMAKE_INSTALL_CONFIG_NAME "Release")
ENDIF(BUILD_TYPE)
MESSAGE(STATUS "Install configuration: \"${CMAKE_INSTALL_CONFIG_NAME}\"")
ENDIF(NOT DEFINED CMAKE_INSTALL_CONFIG_NAME)
# Set the component getting installed.
IF(NOT CMAKE_INSTALL_COMPONENT)
IF(COMPONENT)
MESSAGE(STATUS "Install component: \"${COMPONENT}\"")
SET(CMAKE_INSTALL_COMPONENT "${COMPONENT}")
ELSE(COMPONENT)
SET(CMAKE_INSTALL_COMPONENT)
ENDIF(COMPONENT)
ENDIF(NOT CMAKE_INSTALL_COMPONENT)
# Install shared libraries without execute permission?
IF(NOT DEFINED CMAKE_INSTALL_SO_NO_EXE)
SET(CMAKE_INSTALL_SO_NO_EXE "1")
ENDIF(NOT DEFINED CMAKE_INSTALL_SO_NO_EXE)
IF(NOT CMAKE_INSTALL_COMPONENT OR "${CMAKE_INSTALL_COMPONENT}" STREQUAL "Unspecified")
IF(EXISTS "$ENV{DESTDIR}/usr/bin/pip_cmg" AND
NOT IS_SYMLINK "$ENV{DESTDIR}/usr/bin/pip_cmg")
FILE(RPATH_CHECK
FILE "$ENV{DESTDIR}/usr/bin/pip_cmg"
RPATH "")
ENDIF()
list(APPEND CMAKE_ABSOLUTE_DESTINATION_FILES
"/usr/bin/pip_cmg")
IF (CMAKE_WARN_ON_ABSOLUTE_INSTALL_DESTINATION)
message(WARNING "ABSOLUTE path INSTALL DESTINATION : ${CMAKE_ABSOLUTE_DESTINATION_FILES}")
ENDIF (CMAKE_WARN_ON_ABSOLUTE_INSTALL_DESTINATION)
IF (CMAKE_ERROR_ON_ABSOLUTE_INSTALL_DESTINATION)
message(FATAL_ERROR "ABSOLUTE path INSTALL DESTINATION forbidden (by caller): ${CMAKE_ABSOLUTE_DESTINATION_FILES}")
ENDIF (CMAKE_ERROR_ON_ABSOLUTE_INSTALL_DESTINATION)
FILE(INSTALL DESTINATION "/usr/bin" TYPE EXECUTABLE FILES "/home/andrey/linux_build/libs/pip/utils/code_model_generator/pip_cmg")
IF(EXISTS "$ENV{DESTDIR}/usr/bin/pip_cmg" AND
NOT IS_SYMLINK "$ENV{DESTDIR}/usr/bin/pip_cmg")
FILE(RPATH_REMOVE
FILE "$ENV{DESTDIR}/usr/bin/pip_cmg")
IF(CMAKE_INSTALL_DO_STRIP)
EXECUTE_PROCESS(COMMAND "/usr/bin/strip" "$ENV{DESTDIR}/usr/bin/pip_cmg")
ENDIF(CMAKE_INSTALL_DO_STRIP)
ENDIF()
ENDIF(NOT CMAKE_INSTALL_COMPONENT OR "${CMAKE_INSTALL_COMPONENT}" STREQUAL "Unspecified")

View File

@@ -0,0 +1,263 @@
/*
PIP - Platform Independent Primitives
Code model generator
Copyright (C) 2014 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
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
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 "picli.h"
#include "picodeparser.h"
void usage() {
piCout << Bold << "PIP Code model generator";
piCout << Cyan << "Version" << Bold << PIPVersion() << NewLine;
piCout << Green << Bold << "Usage:" << Default << "\"pip_cmg [-hqPpEs] -o <output_file> [-I<include_dir1>] [-I<include_dir1>] [...] [-D<define1>] [-D<define1>] [...] <file1> [<file2>] [<file3>] [...]\"" << NewLine;
piCout << Green << Bold << "Details:";
piCout << "-h " << Green << "- display this message and exit";
piCout << "-q " << Green << "- quiet, no debug output to console";
piCout << "-P " << Green << "- print list of all parsed files to console before exit";
piCout << "-p " << Green << "- print list of all parsed files without file with \"main\" function to console before exit";
piCout << "-E " << Green << "- write only enums";
piCout << "-s " << Green << "- single file (don`t follow includes)";
piCout << "-o <output_file> " << Green << "- output file for code model without extension (e.g. \"ccm\" - files \"ccm.h\" and \"ccm.cpp\" will be created)";
piCout << "-I<include_dir> " << Green << "- add include dir (e.g. -I.. -I../some_dir -I/usr/include)";
piCout << "-D<define> " << Green << "- add define to preprocessor, define PICODE is always defined (e.g. -DMY_DEFINE will add MY_DEFINE define)";
piCout << "<file> " << Green << "- add file to code model, all includes of this file will be proceed (e.g. \"main.cpp\")";
}
void makeClassInfo(PIFile & f, const PICodeParser::Entity * e) {
f << "\n\tci = new ClassInfo();\n";
f << "\t(*classesInfo)[\"" << e->name << "\"] = ci;\n";
f << "\tci->name = \"" << e->name << "\";\n";
piForeachC (PICodeParser::Entity * p, e->parents)
f << "\tci->parents << \"" << p->name << "\";\n";
piForeachC (PICodeParser::Member & m, e->members) {
f << "\tci->variables << TypeInfo(\"" << m.name << "\", \"" << m.type << "\"";
if (m.attributes != 0) {
bool fir = true;
f << ", ";
if (m.attributes[PICodeParser::Const]) {if (fir) fir = false; else f << " | "; f << "Const";}
if (m.attributes[PICodeParser::Static]) {if (fir) fir = false; else f << " | "; f << "Static";}
if (m.attributes[PICodeParser::Mutable]) {if (fir) fir = false; else f << " | "; f << "Mutable";}
if (m.attributes[PICodeParser::Volatile]) {if (fir) fir = false; else f << " | "; f << "Volatile";}
if (m.attributes[PICodeParser::Inline]) {if (fir) fir = false; else f << " | "; f << "Inline";}
if (m.attributes[PICodeParser::Virtual]) {if (fir) fir = false; else f << " | "; f << "Virtual";}
}
f << ");\n";
}
PIString arg;
piForeachC (PICodeParser::Member & m, e->functions) {
if (e->name.findCWord(m.name) >= 0) continue;
f << "\tci->functions.push_back(FunctionInfo()); fi = &(ci->functions.back());\n";
f << "\tfi->name = \"" << m.name << "\";";
f << " fi->return_type = TypeInfo(\"\", \"" << m.type << "\"";
if (m.attributes[PICodeParser::Const] || m.attributes[PICodeParser::Static]) {
bool fir = true;
f << ", ";
if (m.attributes[PICodeParser::Const]) {if (fir) fir = false; else f << " | "; f << "Const";}
if (m.attributes[PICodeParser::Static]) {if (fir) fir = false; else f << " | "; f << "Static";}
}
f << ");\n";
//piCout << "write func" << m.name;
piForeachC (PIString & a, m.arguments_full) {
//piCout << "write arg" << a;
f << "\tfi->arguments << TypeInfo(";
arg = a;
bool con = false;
arg.prepend(" ");
if (arg.find(" const ") >= 0) {
arg.replaceAll(" const ", " ");
con = true;
}
arg.trim();
int ts = 0;
for (ts = arg.size_s() - 1; ts > 0; --ts)
if (!_isCChar(arg[ts]) && !(arg[ts].isDigit())) break;
f << "\"" << arg.takeRight(arg.size_s() - ts - 1).trim() << "\", ";
f << "\"" << arg.trim() << "\"";
if (con) f << ", Const";
f << ");\n";
}
}
}
void makeEnumInfo(PIFile & f, const PICodeParser::Enum * e) {
if (e->name.isEmpty()) {
f << "\n\tei = (*enumsInfo)[\"\"];\n";
} else {
f << "\n\tei = new EnumInfo();\n";
f << "\t(*enumsInfo)[\"" << e->name << "\"] = ei;\n";
f << "\tei->name = \"" << e->name << "\";\n";
}
piForeachC (PICodeParser::Enumerator & m, e->members)
f << "\tei->members << PICodeInfo::EnumeratorInfo(\"" << m.first << "\", " << m.second << ");\n";
}
void writeModel(PICodeParser & parser, const PIString out, bool only_enums) {
PIVector<const PICodeParser::Entity * > ventities;
PIString defname = out.replaceAll(".", "_").replaceAll("/", "_").toUpperCase() + "_H";
PISet<PIString> inc_files;
piForeachC (PICodeParser::Entity * e, parser.entities)
if (e->name.find("::") < 0 && !e->name.startsWith("_PI"))
inc_files << e->file;
PIFile f(out + ".cpp");
f.clear();
f.open(PIIODevice::WriteOnly);
f << "// Generated by \"PIP Code model generator\" " << PIDateTime::current().toString("dd.MM.yyyy hh:mm:ss\n\n");
f << "#include <string.h>\n#include \"" << out << ".h\"\n\nusing namespace PICodeInfo;\n\n";
if (!only_enums) {
PIVector<PIString> incf = inc_files.toVector();
piForeachC (PIString & i, incf) {
if (i != parser.mainFile())
f << "#include \"" << i << "\"\n";
}
f << "\n";
PIString entry, argtype, rettype, args;
piForeachC (PICodeParser::Entity * e, parser.entities) {
if (e->name.find("::") >= 0 || e->name.startsWith("_PI")) continue;
entry.clear();
entry << "\nPIVariant execFunction(" << e->name << " * object, const char * function, const PIVariant & arg0, const PIVariant & arg1, const PIVariant & arg2, const PIVariant & arg3) {\n";
const PIVector<PICodeParser::Member> & fl(e->functions);
bool efunc = true;
piForeachC (PICodeParser::Member & m, fl) {
if (m.name.startsWith("__stat") || m.attributes[PICodeParser::Static]) continue;
//piCout << e->name << m.name << m.visibility;
args.clear();
rettype = m.type;
if (rettype.startsWith("const") && rettype.endsWith("&"))
rettype.cutLeft(5).cutRight(1).trim();
if (rettype.endsWith("&")) continue;
bool aok = true, ret = (m.type != "void");
if (m.arguments_full.size() > 4 || m.visibility != PICodeParser::Public) continue;
for (int i = 0; i < m.arguments_full.size_s(); ++i) {
if (i > 0) args << ", ";
argtype = m.arguments_type[i];
if (argtype.startsWith("const") && argtype.endsWith("&"))
argtype.cutLeft(5).cutRight(1).trim();
if (argtype.endsWith("&")) {
aok = false;
continue;
}
//entry << "(" << m.arguments_type[i] << ")";
//if (parser.isEnum(m.arguments_type[i])) entry << "(int)";
args << "arg" << i << ".toValue<" << argtype << " >()";
}
if (!aok) continue;
efunc = false;
entry << "\tif (strcmp(function, \"" << m.name << "\") == 0) {";
if (ret) entry << "return PIVariant::fromValue<" << rettype << " >(";
entry << "object->" << m.name << "(" << args << ")";
if (ret) entry << ");";
else entry << "; return PIVariant();";
entry << "}\n";
}
if (efunc) continue;
f << entry << "\tPICout(AddNewLine) << \"Can`t find function \\\"\" << function << \"\\\" in "
<< e->type << " \\\"" << e->name << "\\\"!\";\n\treturn PIVariant();\n}\n";
ventities << e;
}
}
f << "\n\n__ClassInfo_" << defname << "_Initializer__::__ClassInfo_" << defname << "_Initializer__() {\n";
f << "\tif (_inited_) return;\n\t_inited_ = true;\n\n";
if (!only_enums)
f << "\tClassInfo * ci;\n\tTypeInfo * ni;\n\tFunctionInfo * fi;\n";
f << "\tEnumInfo * ei;\n";
f << "\t(*enumsInfo)[\"\"] = new EnumInfo();\n";
if (!only_enums) {
f << "\n\n// Classes\n";
piForeachC (PICodeParser::Entity * e, parser.entities) {
if (e->name.startsWith("_PI")) continue;
makeClassInfo(f, e);
}
}
f << "\n// Enums\n";
piForeachC (PICodeParser::Enum & e, parser.enums)
makeEnumInfo(f, &e);
f << "}\n";
f << "\n\nbool __ClassInfo_" << defname << "_Initializer__::_inited_ = false;\n";
f.close();
f.setPath(out + ".h");
f.clear();
f.open(PIIODevice::WriteOnly);
f << "// Generated by \"PIP Code model generator\" " << PIDateTime::current().toString("dd.MM.yyyy hh:mm:ss\n\n");
f << "#ifndef " << defname << "\n#define " << defname << "\n\n";
f << "#include \"pivariant.h\"\n#include \"picodeinfo.h\"";
if (!only_enums) {
f << "\n\n";
piForeachC (PICodeParser::Entity * e, ventities)
f << e->type << " " << e->name << ";\n";
f << "\n";
piForeachC (PICodeParser::Entity * e, ventities) {
f << "\nPIVariant execFunction(" << e->name << " * object, const char * function, const PIVariant & arg0 = PIVariant(), \
const PIVariant & arg1 = PIVariant(), const PIVariant & arg2 = PIVariant(), const PIVariant & arg3 = PIVariant());";
}
}
f << "\n\n\nclass __ClassInfo_" << defname << "_Initializer__ {\n";
f << "public:\n\t__ClassInfo_" << defname << "_Initializer__();\n\tstatic bool _inited_;\n};\n";
f << "\nstatic __ClassInfo_" << defname << "_Initializer__ __classinfo_" << defname.toLowerCase() << "_initializer__;\n";
f << "\n\n#endif // " << defname << "\n";
f.close();
}
int main(int argc, char * argv[]) {
PICLI cli(argc, argv);
cli.setOptionalArgumentsCount(-1);
cli.addArgument("output", true);
cli.addArgument("help");
cli.addArgument("quiet");
cli.addArgument("Enum");
cli.addArgument("print");
cli.addArgument("Print");
cli.addArgument("single");
if (cli.hasArgument("help") || cli.argumentValue("output").isEmpty() || cli.optionalArguments().isEmpty()) {
usage();
return 0;
}
piDebug = !cli.hasArgument("quiet");
PICodeParser parser;
piForeachC (PIString & a, cli.rawArguments()) {
if (a.startsWith("-I")) parser.includeDirectory(a.mid(2));
if (a.startsWith("-D")) parser.addDefine(a.mid(2), PIString());
}
PIStringList files;
piForeachC (PIString & a, cli.optionalArguments())
if (!a.startsWith("-")) files << a;
piCout << Cyan << Bold << "Parse files" << files << "...";
parser.parseFiles(files, !cli.hasArgument("single"));
piCout << Cyan << Bold << "Parsing done";
piCout << Cyan << Bold << "Writing code model ...";
writeModel(parser, cli.argumentValue("output"), cli.hasArgument("Enum"));
piCout << Cyan << Bold << "Writing done";
if (cli.hasArgument("print") || cli.hasArgument("Print")) {
bool womain = cli.hasArgument("print");
piDebug = true;
PIStringList pf(parser.parsedFiles());
piForeachC (PIString & f, pf) {
if ((womain && (f != parser.mainFile())) || !womain)
piCout << f;
}
}
return 0;
};

View File

@@ -0,0 +1,48 @@
/*
PIP - Platform Independent Primitives
Code model generator
Copyright (C) 2014 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
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
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 "pitimer.h"
#include "test.h"
void event(void * , int d) {
piCout << "tick" << d;
}
PITimer tm;
int main(int argc, char * argv[]) {
//tm.setSlot(event);
//tm.start(200);
/*execFunction(&tm, "setSlot", PIVariant::fromValue<TimerEvent>(event));
execFunction(&tm, "start", 200);
piMSleep(1000);
execFunction(&tm, "addDelimiter", 2);
piMSleep(1000);
execFunction(&tm, "stop");
execFunction(&tm, "stop_");
piMSleep(1000);*/
typedef PIMap<PIString, PICodeInfo::ClassInfo* >::value_type mpair;
piForeachC (mpair & i, *(PICodeInfo::classesInfo))
piCout << *i.second;
piCout << "\n\n";
typedef PIMap<PIString, PICodeInfo::EnumInfo * >::value_type epair;
piForeachC (epair & i, *(PICodeInfo::enumsInfo))
piCout << *i.second;
return 0;
};

Binary file not shown.

Binary file not shown.

File diff suppressed because it is too large Load Diff

100
utils/code_model_generator/test.h Executable file
View File

@@ -0,0 +1,100 @@
// Generated by "PIP Code model generator" 29.04.2014 18:03:05
#ifndef TEST_H
#define TEST_H
#include "pivariant.h"
#include "picodeinfo.h"
class PIMutex;
class PIBitArray;
class PIHuffman;
class PIByteArray;
class PIChar;
class PIString;
class PIStringList;
class PISystemTime;
struct PITime;
struct PIDate;
struct PIDateTime;
class Solver;
class PIFFT;
class PIVariant;
class PIObject;
class PIThread;
class PITimer;
class PIKbdListener;
class PIIODevice;
class PISerial;
class PIFile;
class PIProcess;
class PIEthernet;
class PIPacketExtractor;
class PIConfig;
class PIMultiProtocolBase;
class PIProtocol;
class PIDiagnostics;
class PISystemMonitor;
class PIConsole;
class PICLI;
class PIEvaluatorContent;
class PIEvaluator;
class PIMultiProtocol;
class PIRepeater;
class PICodec;
class PIPeer;
class PIBinaryLog;
class PIUSB;
PIVariant execFunction(PIMutex * object, const char * function, const PIVariant & arg0 = PIVariant(), const PIVariant & arg1 = PIVariant(), const PIVariant & arg2 = PIVariant(), const PIVariant & arg3 = PIVariant());
PIVariant execFunction(PIBitArray * object, const char * function, const PIVariant & arg0 = PIVariant(), const PIVariant & arg1 = PIVariant(), const PIVariant & arg2 = PIVariant(), const PIVariant & arg3 = PIVariant());
PIVariant execFunction(PIHuffman * object, const char * function, const PIVariant & arg0 = PIVariant(), const PIVariant & arg1 = PIVariant(), const PIVariant & arg2 = PIVariant(), const PIVariant & arg3 = PIVariant());
PIVariant execFunction(PIByteArray * object, const char * function, const PIVariant & arg0 = PIVariant(), const PIVariant & arg1 = PIVariant(), const PIVariant & arg2 = PIVariant(), const PIVariant & arg3 = PIVariant());
PIVariant execFunction(PIChar * object, const char * function, const PIVariant & arg0 = PIVariant(), const PIVariant & arg1 = PIVariant(), const PIVariant & arg2 = PIVariant(), const PIVariant & arg3 = PIVariant());
PIVariant execFunction(PIString * object, const char * function, const PIVariant & arg0 = PIVariant(), const PIVariant & arg1 = PIVariant(), const PIVariant & arg2 = PIVariant(), const PIVariant & arg3 = PIVariant());
PIVariant execFunction(PIStringList * object, const char * function, const PIVariant & arg0 = PIVariant(), const PIVariant & arg1 = PIVariant(), const PIVariant & arg2 = PIVariant(), const PIVariant & arg3 = PIVariant());
PIVariant execFunction(PISystemTime * object, const char * function, const PIVariant & arg0 = PIVariant(), const PIVariant & arg1 = PIVariant(), const PIVariant & arg2 = PIVariant(), const PIVariant & arg3 = PIVariant());
PIVariant execFunction(PITime * object, const char * function, const PIVariant & arg0 = PIVariant(), const PIVariant & arg1 = PIVariant(), const PIVariant & arg2 = PIVariant(), const PIVariant & arg3 = PIVariant());
PIVariant execFunction(PIDate * object, const char * function, const PIVariant & arg0 = PIVariant(), const PIVariant & arg1 = PIVariant(), const PIVariant & arg2 = PIVariant(), const PIVariant & arg3 = PIVariant());
PIVariant execFunction(PIDateTime * object, const char * function, const PIVariant & arg0 = PIVariant(), const PIVariant & arg1 = PIVariant(), const PIVariant & arg2 = PIVariant(), const PIVariant & arg3 = PIVariant());
PIVariant execFunction(Solver * object, const char * function, const PIVariant & arg0 = PIVariant(), const PIVariant & arg1 = PIVariant(), const PIVariant & arg2 = PIVariant(), const PIVariant & arg3 = PIVariant());
PIVariant execFunction(PIFFT * object, const char * function, const PIVariant & arg0 = PIVariant(), const PIVariant & arg1 = PIVariant(), const PIVariant & arg2 = PIVariant(), const PIVariant & arg3 = PIVariant());
PIVariant execFunction(PIVariant * object, const char * function, const PIVariant & arg0 = PIVariant(), const PIVariant & arg1 = PIVariant(), const PIVariant & arg2 = PIVariant(), const PIVariant & arg3 = PIVariant());
PIVariant execFunction(PIObject * object, const char * function, const PIVariant & arg0 = PIVariant(), const PIVariant & arg1 = PIVariant(), const PIVariant & arg2 = PIVariant(), const PIVariant & arg3 = PIVariant());
PIVariant execFunction(PIThread * object, const char * function, const PIVariant & arg0 = PIVariant(), const PIVariant & arg1 = PIVariant(), const PIVariant & arg2 = PIVariant(), const PIVariant & arg3 = PIVariant());
PIVariant execFunction(PITimer * object, const char * function, const PIVariant & arg0 = PIVariant(), const PIVariant & arg1 = PIVariant(), const PIVariant & arg2 = PIVariant(), const PIVariant & arg3 = PIVariant());
PIVariant execFunction(PIKbdListener * object, const char * function, const PIVariant & arg0 = PIVariant(), const PIVariant & arg1 = PIVariant(), const PIVariant & arg2 = PIVariant(), const PIVariant & arg3 = PIVariant());
PIVariant execFunction(PIIODevice * object, const char * function, const PIVariant & arg0 = PIVariant(), const PIVariant & arg1 = PIVariant(), const PIVariant & arg2 = PIVariant(), const PIVariant & arg3 = PIVariant());
PIVariant execFunction(PISerial * object, const char * function, const PIVariant & arg0 = PIVariant(), const PIVariant & arg1 = PIVariant(), const PIVariant & arg2 = PIVariant(), const PIVariant & arg3 = PIVariant());
PIVariant execFunction(PIFile * object, const char * function, const PIVariant & arg0 = PIVariant(), const PIVariant & arg1 = PIVariant(), const PIVariant & arg2 = PIVariant(), const PIVariant & arg3 = PIVariant());
PIVariant execFunction(PIProcess * object, const char * function, const PIVariant & arg0 = PIVariant(), const PIVariant & arg1 = PIVariant(), const PIVariant & arg2 = PIVariant(), const PIVariant & arg3 = PIVariant());
PIVariant execFunction(PIEthernet * object, const char * function, const PIVariant & arg0 = PIVariant(), const PIVariant & arg1 = PIVariant(), const PIVariant & arg2 = PIVariant(), const PIVariant & arg3 = PIVariant());
PIVariant execFunction(PIPacketExtractor * object, const char * function, const PIVariant & arg0 = PIVariant(), const PIVariant & arg1 = PIVariant(), const PIVariant & arg2 = PIVariant(), const PIVariant & arg3 = PIVariant());
PIVariant execFunction(PIConfig * object, const char * function, const PIVariant & arg0 = PIVariant(), const PIVariant & arg1 = PIVariant(), const PIVariant & arg2 = PIVariant(), const PIVariant & arg3 = PIVariant());
PIVariant execFunction(PIMultiProtocolBase * object, const char * function, const PIVariant & arg0 = PIVariant(), const PIVariant & arg1 = PIVariant(), const PIVariant & arg2 = PIVariant(), const PIVariant & arg3 = PIVariant());
PIVariant execFunction(PIProtocol * object, const char * function, const PIVariant & arg0 = PIVariant(), const PIVariant & arg1 = PIVariant(), const PIVariant & arg2 = PIVariant(), const PIVariant & arg3 = PIVariant());
PIVariant execFunction(PIDiagnostics * object, const char * function, const PIVariant & arg0 = PIVariant(), const PIVariant & arg1 = PIVariant(), const PIVariant & arg2 = PIVariant(), const PIVariant & arg3 = PIVariant());
PIVariant execFunction(PISystemMonitor * object, const char * function, const PIVariant & arg0 = PIVariant(), const PIVariant & arg1 = PIVariant(), const PIVariant & arg2 = PIVariant(), const PIVariant & arg3 = PIVariant());
PIVariant execFunction(PIConsole * object, const char * function, const PIVariant & arg0 = PIVariant(), const PIVariant & arg1 = PIVariant(), const PIVariant & arg2 = PIVariant(), const PIVariant & arg3 = PIVariant());
PIVariant execFunction(PICLI * object, const char * function, const PIVariant & arg0 = PIVariant(), const PIVariant & arg1 = PIVariant(), const PIVariant & arg2 = PIVariant(), const PIVariant & arg3 = PIVariant());
PIVariant execFunction(PIEvaluatorContent * object, const char * function, const PIVariant & arg0 = PIVariant(), const PIVariant & arg1 = PIVariant(), const PIVariant & arg2 = PIVariant(), const PIVariant & arg3 = PIVariant());
PIVariant execFunction(PIEvaluator * object, const char * function, const PIVariant & arg0 = PIVariant(), const PIVariant & arg1 = PIVariant(), const PIVariant & arg2 = PIVariant(), const PIVariant & arg3 = PIVariant());
PIVariant execFunction(PIMultiProtocol * object, const char * function, const PIVariant & arg0 = PIVariant(), const PIVariant & arg1 = PIVariant(), const PIVariant & arg2 = PIVariant(), const PIVariant & arg3 = PIVariant());
PIVariant execFunction(PIRepeater * object, const char * function, const PIVariant & arg0 = PIVariant(), const PIVariant & arg1 = PIVariant(), const PIVariant & arg2 = PIVariant(), const PIVariant & arg3 = PIVariant());
PIVariant execFunction(PICodec * object, const char * function, const PIVariant & arg0 = PIVariant(), const PIVariant & arg1 = PIVariant(), const PIVariant & arg2 = PIVariant(), const PIVariant & arg3 = PIVariant());
PIVariant execFunction(PIPeer * object, const char * function, const PIVariant & arg0 = PIVariant(), const PIVariant & arg1 = PIVariant(), const PIVariant & arg2 = PIVariant(), const PIVariant & arg3 = PIVariant());
PIVariant execFunction(PIBinaryLog * object, const char * function, const PIVariant & arg0 = PIVariant(), const PIVariant & arg1 = PIVariant(), const PIVariant & arg2 = PIVariant(), const PIVariant & arg3 = PIVariant());
PIVariant execFunction(PIUSB * object, const char * function, const PIVariant & arg0 = PIVariant(), const PIVariant & arg1 = PIVariant(), const PIVariant & arg2 = PIVariant(), const PIVariant & arg3 = PIVariant());
class __ClassInfo_TEST_H_Initializer__ {
public:
__ClassInfo_TEST_H_Initializer__();
static bool _inited_;
};
static __ClassInfo_TEST_H_Initializer__ __classinfo_test_h_initializer__;
#endif // TEST_H

View File

@@ -0,0 +1,5 @@
add_executable(pip_remote_console "main.cpp")
target_link_libraries(pip_remote_console pip)
if (DEFINED LIB)
install(TARGETS pip_remote_console DESTINATION ${CMAKE_INSTALL_PREFIX}/bin)
endif ()

View File

@@ -0,0 +1,209 @@
# CMAKE generated file: DO NOT EDIT!
# Generated by "Unix Makefiles" Generator, CMake Version 2.8
# Default target executed when no arguments are given to make.
default_target: all
.PHONY : default_target
#=============================================================================
# Special targets provided by cmake.
# Disable implicit rules so canonical targets will work.
.SUFFIXES:
# Remove some rules from gmake that .SUFFIXES does not remove.
SUFFIXES =
.SUFFIXES: .hpux_make_needs_suffix_list
# Suppress display of executed commands.
$(VERBOSE).SILENT:
# A target that is always out of date.
cmake_force:
.PHONY : cmake_force
#=============================================================================
# Set environment variables for the build.
# The shell in which to execute make rules.
SHELL = /bin/sh
# The CMake executable.
CMAKE_COMMAND = /usr/bin/cmake
# The command to remove a file.
RM = /usr/bin/cmake -E remove -f
# Escaping for special characters.
EQUALS = =
# The top-level source directory on which CMake was run.
CMAKE_SOURCE_DIR = /home/andrey/linux_build/libs
# The top-level build directory on which CMake was run.
CMAKE_BINARY_DIR = /home/andrey/linux_build/libs
#=============================================================================
# Targets provided globally by CMake.
# Special rule for the target edit_cache
edit_cache:
@$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Running interactive CMake command-line interface..."
/usr/bin/cmake -i .
.PHONY : edit_cache
# Special rule for the target edit_cache
edit_cache/fast: edit_cache
.PHONY : edit_cache/fast
# Special rule for the target install
install: preinstall
@$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Install the project..."
/usr/bin/cmake -P cmake_install.cmake
.PHONY : install
# Special rule for the target install
install/fast: preinstall/fast
@$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Install the project..."
/usr/bin/cmake -P cmake_install.cmake
.PHONY : install/fast
# Special rule for the target install/local
install/local: preinstall
@$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Installing only the local directory..."
/usr/bin/cmake -DCMAKE_INSTALL_LOCAL_ONLY=1 -P cmake_install.cmake
.PHONY : install/local
# Special rule for the target install/local
install/local/fast: install/local
.PHONY : install/local/fast
# Special rule for the target install/strip
install/strip: preinstall
@$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Installing the project stripped..."
/usr/bin/cmake -DCMAKE_INSTALL_DO_STRIP=1 -P cmake_install.cmake
.PHONY : install/strip
# Special rule for the target install/strip
install/strip/fast: install/strip
.PHONY : install/strip/fast
# Special rule for the target list_install_components
list_install_components:
@$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Available install components are: \"Unspecified\""
.PHONY : list_install_components
# Special rule for the target list_install_components
list_install_components/fast: list_install_components
.PHONY : list_install_components/fast
# Special rule for the target rebuild_cache
rebuild_cache:
@$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Running CMake to regenerate build system..."
/usr/bin/cmake -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR)
.PHONY : rebuild_cache
# Special rule for the target rebuild_cache
rebuild_cache/fast: rebuild_cache
.PHONY : rebuild_cache/fast
# The main all target
all: cmake_check_build_system
cd /home/andrey/linux_build/libs && $(CMAKE_COMMAND) -E cmake_progress_start /home/andrey/linux_build/libs/CMakeFiles /home/andrey/linux_build/libs/pip/utils/remote_console/CMakeFiles/progress.marks
cd /home/andrey/linux_build/libs && $(MAKE) -f CMakeFiles/Makefile2 pip/utils/remote_console/all
$(CMAKE_COMMAND) -E cmake_progress_start /home/andrey/linux_build/libs/CMakeFiles 0
.PHONY : all
# The main clean target
clean:
cd /home/andrey/linux_build/libs && $(MAKE) -f CMakeFiles/Makefile2 pip/utils/remote_console/clean
.PHONY : clean
# The main clean target
clean/fast: clean
.PHONY : clean/fast
# Prepare targets for installation.
preinstall: all
cd /home/andrey/linux_build/libs && $(MAKE) -f CMakeFiles/Makefile2 pip/utils/remote_console/preinstall
.PHONY : preinstall
# Prepare targets for installation.
preinstall/fast:
cd /home/andrey/linux_build/libs && $(MAKE) -f CMakeFiles/Makefile2 pip/utils/remote_console/preinstall
.PHONY : preinstall/fast
# clear depends
depend:
cd /home/andrey/linux_build/libs && $(CMAKE_COMMAND) -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) --check-build-system CMakeFiles/Makefile.cmake 1
.PHONY : depend
# Convenience name for target.
pip/utils/remote_console/CMakeFiles/pip_remote_console.dir/rule:
cd /home/andrey/linux_build/libs && $(MAKE) -f CMakeFiles/Makefile2 pip/utils/remote_console/CMakeFiles/pip_remote_console.dir/rule
.PHONY : pip/utils/remote_console/CMakeFiles/pip_remote_console.dir/rule
# Convenience name for target.
pip_remote_console: pip/utils/remote_console/CMakeFiles/pip_remote_console.dir/rule
.PHONY : pip_remote_console
# fast build rule for target.
pip_remote_console/fast:
cd /home/andrey/linux_build/libs && $(MAKE) -f pip/utils/remote_console/CMakeFiles/pip_remote_console.dir/build.make pip/utils/remote_console/CMakeFiles/pip_remote_console.dir/build
.PHONY : pip_remote_console/fast
main.o: main.cpp.o
.PHONY : main.o
# target to build an object file
main.cpp.o:
cd /home/andrey/linux_build/libs && $(MAKE) -f pip/utils/remote_console/CMakeFiles/pip_remote_console.dir/build.make pip/utils/remote_console/CMakeFiles/pip_remote_console.dir/main.cpp.o
.PHONY : main.cpp.o
main.i: main.cpp.i
.PHONY : main.i
# target to preprocess a source file
main.cpp.i:
cd /home/andrey/linux_build/libs && $(MAKE) -f pip/utils/remote_console/CMakeFiles/pip_remote_console.dir/build.make pip/utils/remote_console/CMakeFiles/pip_remote_console.dir/main.cpp.i
.PHONY : main.cpp.i
main.s: main.cpp.s
.PHONY : main.s
# target to generate assembly for a file
main.cpp.s:
cd /home/andrey/linux_build/libs && $(MAKE) -f pip/utils/remote_console/CMakeFiles/pip_remote_console.dir/build.make pip/utils/remote_console/CMakeFiles/pip_remote_console.dir/main.cpp.s
.PHONY : main.cpp.s
# Help Target
help:
@echo "The following are some of the valid targets for this Makefile:"
@echo "... all (the default if no target is provided)"
@echo "... clean"
@echo "... depend"
@echo "... edit_cache"
@echo "... install"
@echo "... install/local"
@echo "... install/strip"
@echo "... list_install_components"
@echo "... pip_remote_console"
@echo "... rebuild_cache"
@echo "... main.o"
@echo "... main.i"
@echo "... main.s"
.PHONY : help
#=============================================================================
# Special targets to cleanup operation of make.
# Special rule to run CMake to check the build system integrity.
# No rule that depends on this can have commands that come from listfiles
# because they might be regenerated.
cmake_check_build_system:
cd /home/andrey/linux_build/libs && $(CMAKE_COMMAND) -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) --check-build-system CMakeFiles/Makefile.cmake 0
.PHONY : cmake_check_build_system

View File

@@ -0,0 +1,60 @@
# Install script for directory: /home/andrey/linux_build/libs/pip/utils/remote_console
# Set the install prefix
IF(NOT DEFINED CMAKE_INSTALL_PREFIX)
SET(CMAKE_INSTALL_PREFIX "/usr")
ENDIF(NOT DEFINED CMAKE_INSTALL_PREFIX)
STRING(REGEX REPLACE "/$" "" CMAKE_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}")
# Set the install configuration name.
IF(NOT DEFINED CMAKE_INSTALL_CONFIG_NAME)
IF(BUILD_TYPE)
STRING(REGEX REPLACE "^[^A-Za-z0-9_]+" ""
CMAKE_INSTALL_CONFIG_NAME "${BUILD_TYPE}")
ELSE(BUILD_TYPE)
SET(CMAKE_INSTALL_CONFIG_NAME "Release")
ENDIF(BUILD_TYPE)
MESSAGE(STATUS "Install configuration: \"${CMAKE_INSTALL_CONFIG_NAME}\"")
ENDIF(NOT DEFINED CMAKE_INSTALL_CONFIG_NAME)
# Set the component getting installed.
IF(NOT CMAKE_INSTALL_COMPONENT)
IF(COMPONENT)
MESSAGE(STATUS "Install component: \"${COMPONENT}\"")
SET(CMAKE_INSTALL_COMPONENT "${COMPONENT}")
ELSE(COMPONENT)
SET(CMAKE_INSTALL_COMPONENT)
ENDIF(COMPONENT)
ENDIF(NOT CMAKE_INSTALL_COMPONENT)
# Install shared libraries without execute permission?
IF(NOT DEFINED CMAKE_INSTALL_SO_NO_EXE)
SET(CMAKE_INSTALL_SO_NO_EXE "1")
ENDIF(NOT DEFINED CMAKE_INSTALL_SO_NO_EXE)
IF(NOT CMAKE_INSTALL_COMPONENT OR "${CMAKE_INSTALL_COMPONENT}" STREQUAL "Unspecified")
IF(EXISTS "$ENV{DESTDIR}/usr/bin/pip_remote_console" AND
NOT IS_SYMLINK "$ENV{DESTDIR}/usr/bin/pip_remote_console")
FILE(RPATH_CHECK
FILE "$ENV{DESTDIR}/usr/bin/pip_remote_console"
RPATH "")
ENDIF()
list(APPEND CMAKE_ABSOLUTE_DESTINATION_FILES
"/usr/bin/pip_remote_console")
IF (CMAKE_WARN_ON_ABSOLUTE_INSTALL_DESTINATION)
message(WARNING "ABSOLUTE path INSTALL DESTINATION : ${CMAKE_ABSOLUTE_DESTINATION_FILES}")
ENDIF (CMAKE_WARN_ON_ABSOLUTE_INSTALL_DESTINATION)
IF (CMAKE_ERROR_ON_ABSOLUTE_INSTALL_DESTINATION)
message(FATAL_ERROR "ABSOLUTE path INSTALL DESTINATION forbidden (by caller): ${CMAKE_ABSOLUTE_DESTINATION_FILES}")
ENDIF (CMAKE_ERROR_ON_ABSOLUTE_INSTALL_DESTINATION)
FILE(INSTALL DESTINATION "/usr/bin" TYPE EXECUTABLE FILES "/home/andrey/linux_build/libs/pip/utils/remote_console/pip_remote_console")
IF(EXISTS "$ENV{DESTDIR}/usr/bin/pip_remote_console" AND
NOT IS_SYMLINK "$ENV{DESTDIR}/usr/bin/pip_remote_console")
FILE(RPATH_REMOVE
FILE "$ENV{DESTDIR}/usr/bin/pip_remote_console")
IF(CMAKE_INSTALL_DO_STRIP)
EXECUTE_PROCESS(COMMAND "/usr/bin/strip" "$ENV{DESTDIR}/usr/bin/pip_remote_console")
ENDIF(CMAKE_INSTALL_DO_STRIP)
ENDIF()
ENDIF(NOT CMAKE_INSTALL_COMPONENT OR "${CMAKE_INSTALL_COMPONENT}" STREQUAL "Unspecified")

64
utils/remote_console/main.cpp Executable file
View File

@@ -0,0 +1,64 @@
/*
PIP - Platform Independent Primitives
Remote console viewer
Copyright (C) 2014 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
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
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 "pip.h"
void key_event(char key, void * );
PIConsole console(false, key_event);
PIStringList as;
bool selected = false;
void key_event(char key, void * ) {
if (key < '1' || key > '9') return;
int ind = key - '1';
if (ind < 0 || ind >= as.size_s()) return;
selected = true;
console.connectToServer(as[ind]);
}
int main(int argc, char * argv[]) {
console.enableExitCapture();
console.listenServers();
while (!PIKbdListener::exiting) {
msleep(200);
if (selected) break;
console.clearScreen();
as = console.availableServers();
if (as.isEmpty()) {
piCout << "No servers are available!";
} else {
piCout << "Select one with numeric key:";
for (int i = 0; i < as.size_s(); ++i)
piCout << (i + 1) << as[i];
}
}
if (!selected) return 0;
//console.clearScreen();
piCout << "Connecting to" << console.selectedServer() << "...";
while (!PIKbdListener::exiting) {
msleep(20);
if (console.isConnected())
break;
}
if (PIKbdListener::exiting)
return 0;
console.start();
console.waitForFinish();
};

Binary file not shown.

Binary file not shown.

View File

@@ -0,0 +1,7 @@
file(GLOB CPPS "*.cpp")
file(GLOB HDRS "*.h")
add_executable(pisd ${CPPS} ${HDRS})
target_link_libraries(pisd pip)
if (DEFINED LIB)
install(TARGETS pisd DESTINATION ${CMAKE_INSTALL_PREFIX}/bin)
endif ()

View File

@@ -0,0 +1,265 @@
# CMAKE generated file: DO NOT EDIT!
# Generated by "MinGW Makefiles" Generator, CMake Version 2.8
# Default target executed when no arguments are given to make.
default_target: all
.PHONY : default_target
#=============================================================================
# Special targets provided by cmake.
# Disable implicit rules so canonical targets will work.
.SUFFIXES:
# Remove some rules from gmake that .SUFFIXES does not remove.
SUFFIXES =
.SUFFIXES: .hpux_make_needs_suffix_list
# Suppress display of executed commands.
$(VERBOSE).SILENT:
# A target that is always out of date.
cmake_force:
.PHONY : cmake_force
#=============================================================================
# Set environment variables for the build.
SHELL = cmd.exe
# The CMake executable.
CMAKE_COMMAND = "C:\Program Files (x86)\CMake 2.8\bin\cmake.exe"
# The command to remove a file.
RM = "C:\Program Files (x86)\CMake 2.8\bin\cmake.exe" -E remove -f
# Escaping for special characters.
EQUALS = =
# The program to use to edit the cache.
CMAKE_EDIT_COMMAND = "C:\Program Files (x86)\CMake 2.8\bin\cmake-gui.exe"
# The top-level source directory on which CMake was run.
CMAKE_SOURCE_DIR = C:\libs
# The top-level build directory on which CMake was run.
CMAKE_BINARY_DIR = C:\libs
#=============================================================================
# Targets provided globally by CMake.
# Special rule for the target edit_cache
edit_cache:
@$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Running CMake cache editor..."
"C:\Program Files (x86)\CMake 2.8\bin\cmake-gui.exe" -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR)
.PHONY : edit_cache
# Special rule for the target edit_cache
edit_cache/fast: edit_cache
.PHONY : edit_cache/fast
# Special rule for the target install
install: preinstall
@$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Install the project..."
"C:\Program Files (x86)\CMake 2.8\bin\cmake.exe" -P cmake_install.cmake
.PHONY : install
# Special rule for the target install
install/fast: preinstall/fast
@$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Install the project..."
"C:\Program Files (x86)\CMake 2.8\bin\cmake.exe" -P cmake_install.cmake
.PHONY : install/fast
# Special rule for the target install/local
install/local: preinstall
@$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Installing only the local directory..."
"C:\Program Files (x86)\CMake 2.8\bin\cmake.exe" -DCMAKE_INSTALL_LOCAL_ONLY=1 -P cmake_install.cmake
.PHONY : install/local
# Special rule for the target install/local
install/local/fast: install/local
.PHONY : install/local/fast
# Special rule for the target install/strip
install/strip: preinstall
@$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Installing the project stripped..."
"C:\Program Files (x86)\CMake 2.8\bin\cmake.exe" -DCMAKE_INSTALL_DO_STRIP=1 -P cmake_install.cmake
.PHONY : install/strip
# Special rule for the target install/strip
install/strip/fast: install/strip
.PHONY : install/strip/fast
# Special rule for the target list_install_components
list_install_components:
@$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Available install components are: \"Unspecified\""
.PHONY : list_install_components
# Special rule for the target list_install_components
list_install_components/fast: list_install_components
.PHONY : list_install_components/fast
# Special rule for the target rebuild_cache
rebuild_cache:
@$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Running CMake to regenerate build system..."
"C:\Program Files (x86)\CMake 2.8\bin\cmake.exe" -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR)
.PHONY : rebuild_cache
# Special rule for the target rebuild_cache
rebuild_cache/fast: rebuild_cache
.PHONY : rebuild_cache/fast
# The main all target
all: cmake_check_build_system
cd /d C:\libs && $(CMAKE_COMMAND) -E cmake_progress_start C:\libs\CMakeFiles C:\libs\pip\utils\system_daemon\CMakeFiles\progress.marks
cd /d C:\libs && $(MAKE) -f CMakeFiles\Makefile2 pip/utils/system_daemon/all
$(CMAKE_COMMAND) -E cmake_progress_start C:\libs\CMakeFiles 0
.PHONY : all
# The main clean target
clean:
cd /d C:\libs && $(MAKE) -f CMakeFiles\Makefile2 pip/utils/system_daemon/clean
.PHONY : clean
# The main clean target
clean/fast: clean
.PHONY : clean/fast
# Prepare targets for installation.
preinstall: all
cd /d C:\libs && $(MAKE) -f CMakeFiles\Makefile2 pip/utils/system_daemon/preinstall
.PHONY : preinstall
# Prepare targets for installation.
preinstall/fast:
cd /d C:\libs && $(MAKE) -f CMakeFiles\Makefile2 pip/utils/system_daemon/preinstall
.PHONY : preinstall/fast
# clear depends
depend:
cd /d C:\libs && $(CMAKE_COMMAND) -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) --check-build-system CMakeFiles\Makefile.cmake 1
.PHONY : depend
# Convenience name for target.
pip/utils/system_daemon/CMakeFiles/pisd.dir/rule:
cd /d C:\libs && $(MAKE) -f CMakeFiles\Makefile2 pip/utils/system_daemon/CMakeFiles/pisd.dir/rule
.PHONY : pip/utils/system_daemon/CMakeFiles/pisd.dir/rule
# Convenience name for target.
pisd: pip/utils/system_daemon/CMakeFiles/pisd.dir/rule
.PHONY : pisd
# fast build rule for target.
pisd/fast:
cd /d C:\libs && $(MAKE) -f pip\utils\system_daemon\CMakeFiles\pisd.dir\build.make pip/utils/system_daemon/CMakeFiles/pisd.dir/build
.PHONY : pisd/fast
daemon.obj: daemon.cpp.obj
.PHONY : daemon.obj
# target to build an object file
daemon.cpp.obj:
cd /d C:\libs && $(MAKE) -f pip\utils\system_daemon\CMakeFiles\pisd.dir\build.make pip/utils/system_daemon/CMakeFiles/pisd.dir/daemon.cpp.obj
.PHONY : daemon.cpp.obj
daemon.i: daemon.cpp.i
.PHONY : daemon.i
# target to preprocess a source file
daemon.cpp.i:
cd /d C:\libs && $(MAKE) -f pip\utils\system_daemon\CMakeFiles\pisd.dir\build.make pip/utils/system_daemon/CMakeFiles/pisd.dir/daemon.cpp.i
.PHONY : daemon.cpp.i
daemon.s: daemon.cpp.s
.PHONY : daemon.s
# target to generate assembly for a file
daemon.cpp.s:
cd /d C:\libs && $(MAKE) -f pip\utils\system_daemon\CMakeFiles\pisd.dir\build.make pip/utils/system_daemon/CMakeFiles/pisd.dir/daemon.cpp.s
.PHONY : daemon.cpp.s
file_manager.obj: file_manager.cpp.obj
.PHONY : file_manager.obj
# target to build an object file
file_manager.cpp.obj:
cd /d C:\libs && $(MAKE) -f pip\utils\system_daemon\CMakeFiles\pisd.dir\build.make pip/utils/system_daemon/CMakeFiles/pisd.dir/file_manager.cpp.obj
.PHONY : file_manager.cpp.obj
file_manager.i: file_manager.cpp.i
.PHONY : file_manager.i
# target to preprocess a source file
file_manager.cpp.i:
cd /d C:\libs && $(MAKE) -f pip\utils\system_daemon\CMakeFiles\pisd.dir\build.make pip/utils/system_daemon/CMakeFiles/pisd.dir/file_manager.cpp.i
.PHONY : file_manager.cpp.i
file_manager.s: file_manager.cpp.s
.PHONY : file_manager.s
# target to generate assembly for a file
file_manager.cpp.s:
cd /d C:\libs && $(MAKE) -f pip\utils\system_daemon\CMakeFiles\pisd.dir\build.make pip/utils/system_daemon/CMakeFiles/pisd.dir/file_manager.cpp.s
.PHONY : file_manager.cpp.s
main.obj: main.cpp.obj
.PHONY : main.obj
# target to build an object file
main.cpp.obj:
cd /d C:\libs && $(MAKE) -f pip\utils\system_daemon\CMakeFiles\pisd.dir\build.make pip/utils/system_daemon/CMakeFiles/pisd.dir/main.cpp.obj
.PHONY : main.cpp.obj
main.i: main.cpp.i
.PHONY : main.i
# target to preprocess a source file
main.cpp.i:
cd /d C:\libs && $(MAKE) -f pip\utils\system_daemon\CMakeFiles\pisd.dir\build.make pip/utils/system_daemon/CMakeFiles/pisd.dir/main.cpp.i
.PHONY : main.cpp.i
main.s: main.cpp.s
.PHONY : main.s
# target to generate assembly for a file
main.cpp.s:
cd /d C:\libs && $(MAKE) -f pip\utils\system_daemon\CMakeFiles\pisd.dir\build.make pip/utils/system_daemon/CMakeFiles/pisd.dir/main.cpp.s
.PHONY : main.cpp.s
# Help Target
help:
@echo The following are some of the valid targets for this Makefile:
@echo ... all (the default if no target is provided)
@echo ... clean
@echo ... depend
@echo ... edit_cache
@echo ... install
@echo ... install/local
@echo ... install/strip
@echo ... list_install_components
@echo ... pisd
@echo ... rebuild_cache
@echo ... daemon.obj
@echo ... daemon.i
@echo ... daemon.s
@echo ... file_manager.obj
@echo ... file_manager.i
@echo ... file_manager.s
@echo ... main.obj
@echo ... main.i
@echo ... main.s
.PHONY : help
#=============================================================================
# Special targets to cleanup operation of make.
# Special rule to run CMake to check the build system integrity.
# No rule that depends on this can have commands that come from listfiles
# because they might be regenerated.
cmake_check_build_system:
cd /d C:\libs && $(CMAKE_COMMAND) -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) --check-build-system CMakeFiles\Makefile.cmake 0
.PHONY : cmake_check_build_system

View File

@@ -0,0 +1,47 @@
# Install script for directory: C:/libs/pip/utils/system_daemon
# Set the install prefix
IF(NOT DEFINED CMAKE_INSTALL_PREFIX)
SET(CMAKE_INSTALL_PREFIX "C:/mingw/x32")
ENDIF(NOT DEFINED CMAKE_INSTALL_PREFIX)
STRING(REGEX REPLACE "/$" "" CMAKE_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}")
# Set the install configuration name.
IF(NOT DEFINED CMAKE_INSTALL_CONFIG_NAME)
IF(BUILD_TYPE)
STRING(REGEX REPLACE "^[^A-Za-z0-9_]+" ""
CMAKE_INSTALL_CONFIG_NAME "${BUILD_TYPE}")
ELSE(BUILD_TYPE)
SET(CMAKE_INSTALL_CONFIG_NAME "Release")
ENDIF(BUILD_TYPE)
MESSAGE(STATUS "Install configuration: \"${CMAKE_INSTALL_CONFIG_NAME}\"")
ENDIF(NOT DEFINED CMAKE_INSTALL_CONFIG_NAME)
# Set the component getting installed.
IF(NOT CMAKE_INSTALL_COMPONENT)
IF(COMPONENT)
MESSAGE(STATUS "Install component: \"${COMPONENT}\"")
SET(CMAKE_INSTALL_COMPONENT "${COMPONENT}")
ELSE(COMPONENT)
SET(CMAKE_INSTALL_COMPONENT)
ENDIF(COMPONENT)
ENDIF(NOT CMAKE_INSTALL_COMPONENT)
IF(NOT CMAKE_INSTALL_COMPONENT OR "${CMAKE_INSTALL_COMPONENT}" STREQUAL "Unspecified")
list(APPEND CMAKE_ABSOLUTE_DESTINATION_FILES
"C:/mingw/x32/bin/pisd.exe")
IF (CMAKE_WARN_ON_ABSOLUTE_INSTALL_DESTINATION)
message(WARNING "ABSOLUTE path INSTALL DESTINATION : ${CMAKE_ABSOLUTE_DESTINATION_FILES}")
ENDIF (CMAKE_WARN_ON_ABSOLUTE_INSTALL_DESTINATION)
IF (CMAKE_ERROR_ON_ABSOLUTE_INSTALL_DESTINATION)
message(FATAL_ERROR "ABSOLUTE path INSTALL DESTINATION forbidden (by caller): ${CMAKE_ABSOLUTE_DESTINATION_FILES}")
ENDIF (CMAKE_ERROR_ON_ABSOLUTE_INSTALL_DESTINATION)
FILE(INSTALL DESTINATION "C:/mingw/x32/bin" TYPE EXECUTABLE FILES "C:/libs/pip/utils/system_daemon/pisd.exe")
IF(EXISTS "$ENV{DESTDIR}/C:/mingw/x32/bin/pisd.exe" AND
NOT IS_SYMLINK "$ENV{DESTDIR}/C:/mingw/x32/bin/pisd.exe")
IF(CMAKE_INSTALL_DO_STRIP)
EXECUTE_PROCESS(COMMAND "C:/mingw/x32/bin/strip.exe" "$ENV{DESTDIR}/C:/mingw/x32/bin/pisd.exe")
ENDIF(CMAKE_INSTALL_DO_STRIP)
ENDIF()
ENDIF(NOT CMAKE_INSTALL_COMPONENT OR "${CMAKE_INSTALL_COMPONENT}" STREQUAL "Unspecified")

View File

@@ -0,0 +1,252 @@
#include "daemon.h"
#include "shared.h"
#include "pisysteminfo.h"
Daemon::Daemon(): PIPeer("_pisd_" + PISystemInfo::instance()->hostname + "_" + PIString(rand() % 100)) {
setName("Daemon");
timer.setName("__S__Daemon_timer");
enabled = false;
mode = offset = cur = height = 0;
CONNECTU(&console, keyPressed, this, keyEvent)
CONNECTU(&timer, tickEvent, this, timerEvent)
timer.addDelimiter(5);
timer.start(200);
}
void Daemon::keyEvent(char key) {
if (!enabled) return;
int num = key - '0';
switch (mode) {
case 0:
if (num >= 0 && num <= 9) {
connectToDaemon(dnames.value(key - '0'));
return;
}
break;
case 1:
if (num >= 0 && num <= 9) {
mode = num + 10;
updateConsole();
return;
}
break;
}
switch (key) {
case PIKbdListener::UpArrow:
/*cur--;
if (cur < 0) cur = 0;
if (cur - offset < 2) offset--;
if (offset < 0) offset = 0;*/
updateConsole();
break;
case PIKbdListener::Space:
/*if (cur < 0 || cur >= files.size_s()) return;
if (selected.contains(files[cur].name)) selected.removeOne(files[cur].name);
else selected << files[cur].name;*/
case PIKbdListener::DownArrow:
/*cur++;
if (cur >= files.size_s()) cur = files.size_s() - 1;
if (cur - offset >= height - 2) offset++;
if (offset >= files.size_s() - height) offset = files.size_s() - height;*/
updateConsole();
break;
case PIKbdListener::Home:
//cur = offset = 0;
updateConsole();
break;
case PIKbdListener::End:
//cur = files.size_s() - 1;
//offset = files.size_s() - height;
updateConsole();
break;
case PIKbdListener::Return:
//if (cur < files.size_s() && cur >= 0) {
//}
break;
case 'A':
updateConsole();
break;
case 'R':
updateConsole();
break;
case PIKbdListener::Esc:
//selected.clear();
//updateConsole();
if (mode == 0)
menuRequest();
else {
if (mode > 1) {
mode = 1;
updateConsole();
} else
disconnect();
}
break;
default: break;
}
}
void Daemon::timerEvent(void * _d, int delim) {
if (!enabled) return;
if (delim == 1) {
if (mode == 0)
updateConsole();
}
if (delim == 5) {
if (conn_name.isEmpty()) return;
PIByteArray ba; ba << int(RequestHostInfo);
send(conn_name, ba);
}
}
PIStringList Daemon::availableDaemons() const {
available_daemons.clear();
piForeachC (PIPeer::PeerInfo & p, allPeers()) {
if (!p.name.startsWith("_pisd_")) continue;
available_daemons << p.name.mid(6);
}
return available_daemons;
}
void Daemon::connectToDaemon(const PIString & dn) {
if (dn.isEmpty()) return;
conn_name = "_pisd_" + dn;
mode = 1;
updateConsole();
}
void Daemon::disconnect() {
conn_name.clear();
mode = 0;
updateConsole();
}
PIString Daemon::connectedDaemon() const {
return conn_name.mid(6);
}
void Daemon::peerDisconnected(const PIString & name) {
if (name == conn_name) {
conn_name.clear();
mode = 0;
}
}
void Daemon::dataReceived(const PIString & from, const PIByteArray & data) {
//if (conn_name != from) return;
if (data.size() < 4) return;
PIByteArray ba(data), rba;
int type; ba >> type;
//piCout << "rec from" << from << type;
switch (type) {
case RequestHostInfo:
makeMyHostInfo();
rba << int(ReplyHostInfo) << info_my;
break;
case ReplyHostInfo:
ba >> info_other;
makeOtherHostInfo();
break;
};
if (!rba.isEmpty()) send(from, rba);
}
void Daemon::makeMyHostInfo() {
info_my.execCommand = PISystemInfo::instance()->execCommand;
info_my.hostname = PISystemInfo::instance()->hostname;
info_my.user = PISystemInfo::instance()->user;
info_my.OS_name = PISystemInfo::instance()->OS_name;
info_my.OS_version = PISystemInfo::instance()->OS_version;
info_my.architecture = PISystemInfo::instance()->architecture;
info_my.execDateTime = PISystemInfo::instance()->execDateTime;
info_my.processorsCount = PISystemInfo::instance()->processorsCount;
info_my.ID = sys_mon.statistic().ID;
info_my.threads = sys_mon.statistic().threads;
info_my.priority = sys_mon.statistic().priority;
info_my.physical_memsize = sys_mon.statistic().physical_memsize;
info_my.share_memsize = sys_mon.statistic().share_memsize;
info_my.cpu_load_system = sys_mon.statistic().cpu_load_system;
info_my.cpu_load_user = sys_mon.statistic().cpu_load_user;
}
void Daemon::makeOtherHostInfo() {
PISystemMonitor::ProcessStats & ps(const_cast<PISystemMonitor::ProcessStats & >(sys_mon_other.statistic()));
ps.ID = info_other.ID;
ps.threads = info_other.threads;
ps.priority = info_other.priority;
ps.physical_memsize = info_other.physical_memsize;
ps.share_memsize = info_other.share_memsize;
ps.cpu_load_system = info_other.cpu_load_system;
ps.cpu_load_user = info_other.cpu_load_user;
sys_mon_other.setStatistic(ps);
}
void Daemon::updateConsole() {
if (!enabled) return;
switch (mode) {
case 0: tabConnect(); break;
case 1: tabFeature(); break;
case RequestHostInfo: tabInfo(); break;
}
}
void Daemon::tabConnectedHeader(int cols) {
console.addString("Connected to: " + connectedDaemon(), 1, PIConsole::BackGreen | PIConsole::Bold);
for (int i = 2; i <= cols; ++i)
console.addString(" ", i, PIConsole::Green | PIConsole::Inverse);
}
void Daemon::tabConnect() {
startTab();
console.addString("Available daemons:");
int num = 0;
dnames.clear();
PIStringList adl = availableDaemons();
piForeachC (PIString & p, adl) {
dnames[num] = p;
console.addString(" " + PIString(num++) + " - " + p);
}
finishTab();
}
void Daemon::tabFeature() {
startTab();
tabConnectedHeader();
console.addString("What do you wish to do with this daemon?");
console.addString(" 0 - show host info");
console.addString(" 1 - file manager");
console.addString(" 2 - execute command");
finishTab();
}
void Daemon::tabInfo() {
startTab(2);
tabConnectedHeader(2);
console.addString("Exec command: " + info_other.execCommand);
console.addString(" Executed on " + info_other.execDateTime.toString());
console.addString(" Hostname: " + info_other.hostname);
console.addString(" Username: " + info_other.user);
console.addString(" OS name: " + info_other.OS_name);
console.addString(" OS version: " + info_other.OS_version);
console.addString("Architecture: " + info_other.architecture);
console.addString(" CPU count: " + PIString::fromNumber(info_other.processorsCount));
console.addVariable("of this process", &sys_mon_other, 2);
finishTab();
}

View File

@@ -0,0 +1,93 @@
#ifndef DAEMON_H
#define DAEMON_H
#include "piconsole.h"
#include "pipeer.h"
extern PIConsole console;
extern PISystemMonitor sys_mon;
class Daemon: public PIPeer {
PIOBJECT(Daemon)
public:
Daemon();
struct HostInfo {
PIString execCommand;
PIString hostname;
PIString user;
PIString OS_name;
PIString OS_version;
PIString architecture;
PIDateTime execDateTime;
int processorsCount;
int ID;
int threads;
int priority;
ulong physical_memsize;
ulong share_memsize;
float cpu_load_system;
float cpu_load_user;
};
void enable() {enabled = true;}
void disable() {enabled = false;}
PIStringList availableDaemons() const;
void connectToDaemon(const PIString & dn);
void disconnect();
PIString connectedDaemon() const;
private:
enum PacketType {
RequestHostInfo = 10,
ReplyHostInfo = 20
};
EVENT_HANDLER1(void, keyEvent, char, key);
EVENT_HANDLER2(void, timerEvent, void * , _d, int, delim);
EVENT(menuRequest);
void peerDisconnected(const PIString & name);
void dataReceived(const PIString & from, const PIByteArray & data);
void makeMyHostInfo();
void makeOtherHostInfo();
void updateConsole();
void tabConnectedHeader(int cols = 1);
void tabConnect();
void tabFeature();
void tabInfo();
mutable PIStringList available_daemons;
PITimer timer;
PIString conn_name;
PIMap<int, PIString> dnames;
PISystemMonitor sys_mon_other;
HostInfo info_my, info_other;
bool enabled;
int mode, offset, cur, height;
};
inline PIByteArray & operator <<(PIByteArray & b, const Daemon::HostInfo & v) {
b << v.execCommand << v.hostname << v.user << v.OS_name
<< v.OS_version << v.architecture << v.execDateTime
<< v.processorsCount << v.ID << v.threads << v.priority
<< v.physical_memsize << v.share_memsize
<< v.cpu_load_system << v.cpu_load_user;
return b;
}
inline PIByteArray & operator >>(PIByteArray & b, Daemon::HostInfo & v) {
b >> v.execCommand >> v.hostname >> v.user >> v.OS_name
>> v.OS_version >> v.architecture >> v.execDateTime
>> v.processorsCount >> v.ID >> v.threads >> v.priority
>> v.physical_memsize >> v.share_memsize
>> v.cpu_load_system >> v.cpu_load_user;
return b;
}
#endif // DAEMON_H

View File

@@ -0,0 +1,182 @@
#include "file_manager.h"
#include "shared.h"
FileManager::FileManager() {
setName("FileManager");
offset = cur = height = 0;
enabled = del_commit = false;
CONNECTU(&console, keyPressed, this, keyEvent)
dir = PIDir::current();
//dir.setDir("/home/peri4/Documents");
dir.setDir("/home/peri4");
updateDir();
}
void FileManager::keyEvent(char key) {
if (!enabled) return;
if (key == 'D') {
if (cur >= files.size_s() || cur < 0) return;
if (del_commit) {
piForeachC (PIString & f, selected) {
PIFile::remove(dir.absolutePath() + PIDir::separator + f);
//piCout << "remove" << (dir.absolutePath() + PIDir::separator + f);
}
selected.clear();
updateDir();
console.clearCustomStatus();
del_commit = false;
} else {
if (selected.isEmpty()) selected << files[cur].path;
console.addCustomStatus("Delete " + PIString(selected.size_s()) + " file, are you sure? D as yes");
del_commit = true;
}
updateConsole();
return;
}
console.clearCustomStatus();
del_commit = false;
PIStringList nsel;
switch (key) {
case PIKbdListener::UpArrow:
cur--;
if (cur < 0) cur = 0;
if (cur - offset < 3) offset--;
if (offset < 0) offset = 0;
updateConsole();
break;
case PIKbdListener::Space:
if (cur < 0 || cur >= files.size_s()) return;
if (selected.contains(files[cur].path)) selected.removeOne(files[cur].path);
else selected << files[cur].path;
case PIKbdListener::DownArrow:
cur++;
if (cur >= files.size_s()) cur = files.size_s() - 1;
if (cur - offset >= height - 3) offset++;
if (offset >= files.size_s() - height) offset = files.size_s() - height;
updateConsole();
//piCout << offset << files.size_s() << height;
break;
case PIKbdListener::Home:
cur = offset = 0;
updateConsole();
break;
case PIKbdListener::End:
cur = files.size_s() - 1;
offset = files.size_s() - height;
updateConsole();
//piCout << offset << files.size_s() << height;
break;
case PIKbdListener::Return:
if (cur < files.size_s() && cur >= 0) {
piCout << files[cur];
if (files[cur].isDir()) {
prev_pos[dir.path()] = cur;
prev_off[dir.path()] = offset;
dir.cd(files[cur].name());
cur = prev_pos.value(dir.path(), 0);
offset = prev_off.value(dir.path(), 0);
selected.clear();
updateDir();
updateConsole();
}
}
break;
case 'A':
selected.clear();
piForeach (PIFile::FileInfo & e, files)
selected << e.path;
updateConsole();
break;
case 'R':
updateDir();
piForeach (PIFile::FileInfo & e, files)
if (selected.contains(e.path))
nsel << e.path;
selected = nsel;
updateConsole();
break;
case PIKbdListener::Esc:
//selected.clear();
//updateConsole();
menuRequest();
break;
default: break;
}
}
void FileManager::updateConsole() {
if (!enabled) return;
startTab(2);
console.addString("File manager", 1, PIConsole::Yellow | PIConsole::Inverse);
console.addString("Path: " + dir.absolutePath(), 1, PIConsole::Green | PIConsole::Inverse | PIConsole::Bold);
console.addString("Name", 1, PIConsole::Green | PIConsole::Inverse | PIConsole::Bold);
console.addString(" ", 2, PIConsole::Yellow | PIConsole::Inverse);
console.addString(" ", 2, PIConsole::Green | PIConsole::Inverse);
console.addString(" ", 2, PIConsole::Green | PIConsole::Inverse);
buildNames();
console.addString("A - select all, D - remove, R - refresh, Esc - exit", 1, PIConsole::Green | PIConsole::Inverse | PIConsole::Bold);
finishTab();
}
void FileManager::buildNames() {
if (!enabled) return;
height = console.windowHeight() - 10;
int is = piClampi(offset, 0, piMaxi(0, files.size_s() - 1)), ie = piClampi(offset + height, 0, files.size_s());
console.addString((is > 0) ? (PIString(" /\\ ").repeat(console.windowWidth() / 8)) : " ", 1, PIConsole::Green | PIConsole::Bold);
console.addString(" ", 2);
PIChar t;
PIConsole::FormatFlags f = 0;
PIString scol;
piCout << cur;
for (int i = is; i < ie; ++i) {
if (files[i].isDir()) {
t = '/';
f = PIConsole::Bold;
scol = " dir";
} else {
if (files[i].perm_user.exec || files[i].perm_group.exec || files[i].perm_other.exec) {
f = PIConsole::Green | PIConsole::Bold;
t = '*';
} else {
t = ' ';
f = 0;
}
scol = PIString::readableSize(files[i].size);
}
if (files[i].isSymbolicLink() && (t != '*')) t = '~';
scol = scol.expandRightTo(9, ' ') + "| " + files[i].time_modification.toString("dd.MM hh:mm:ss") + " | "
+ files[i].perm_user.toString() + " " + files[i].perm_group.toString() + " " + files[i].perm_other.toString();
if (i == cur) f |= PIConsole::BackBlue;
if (selected.contains(files[i].path)) f |= PIConsole::Yellow | PIConsole::Bold;
console.addString(t + files[i].name(), 1, f);
console.addString(scol, 2, f);
}
console.addString((ie < files.size_s()) ? (PIString(" \\/ ").repeat(console.windowWidth() / 8)) : " ", 1, PIConsole::Green | PIConsole::Bold);
console.addString(" ", 2);
}
void FileManager::updateDir() {
if (!enabled) return;
files.clear();
PIVector<PIFile::FileInfo> el = dir.entries(), fl, dl;
for (int i = 0; i < el.size_s(); ++i) {
if (el[i].path == ".") continue;
if (el[i].path == "..") {
dl.push_front(el[i]);
continue;
}
if (el[i].isDir()) dl << el[i];
else fl << el[i];
}
files << dl << fl;
if (cur >= files.size_s()) cur = files.size_s() - 1;
if (offset >= files.size_s() - height) offset = files.size_s() - height;
if (cur < 0) cur = 0;
if (offset < 0) offset = 0;
}

View File

@@ -0,0 +1,33 @@
#ifndef FILE_MANAGER_H
#define FILE_MANAGER_H
#include "piconsole.h"
#include "pidir.h"
extern PIConsole console;
class FileManager: public PIObject {
PIOBJECT(FileManager)
public:
FileManager();
void enable() {enabled = true; updateDir(); updateConsole();}
void disable() {enabled = false;}
private:
EVENT_HANDLER1(void, keyEvent, char, key);
EVENT(menuRequest);
void updateConsole();
void updateDir();
void buildNames();
int offset, cur, height;
bool enabled, del_commit;
PIDir dir;
PIVector<PIFile::FileInfo> files;
PIMap<PIString, int> prev_pos, prev_off;
PIStringList selected;
};
#endif // FILE_MANAGER_H

244
utils/system_daemon/main.cpp Executable file
View File

@@ -0,0 +1,244 @@
/*
PIP - Platform Independent Primitives
Remote console viewer
Copyright (C) 2014 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
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
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 "picli.h"
#include "pisystemmonitor.h"
#include "pisysteminfo.h"
#include "file_manager.h"
#include "daemon.h"
#include "shared.h"
void key_event(char key, void * );
class _Init {
public:
_Init() {srand(PISystemTime::current().toMicroseconds());}
};
_Init _pisd_init;
PIConsole console(false, key_event);
PISystemMonitor sys_mon;
FileManager file_manager;
Daemon daemon_;
int mode = 0, oldmode = -1;
class MenuOperator: public PIObject {
PIOBJECT(MenuOperator)
public:
MenuOperator() {
CONNECTU(&file_manager, menuRequest, this, menuRequest)
CONNECTU(&daemon_, menuRequest, this, menuRequest)
}
EVENT_HANDLER(void, menuRequest) {mode = 0;}
};
MenuOperator menu_operator;
void key_event(char key, void * ) {
if (key == PIKbdListener::Esc) {
;//mode = 0;
} else {
if (mode != 3) {
if (key < '0' || key > '9') return;
mode = key - '0';
}
}
}
void tabMenu() {
startTab();
console.addString("Select with numeric key:");
console.addString(" 0 - this screen");
console.addString(" 1 - show host info");
console.addString(" 2 - local file manager");
console.addString(" 3 - connect to another daemon");
finishTab();
}
void tabInfo() {
startTab();
console.addString("Exec command: " + PISystemInfo::instance()->execCommand);
console.addString(" Executed on " + PISystemInfo::instance()->execDateTime.toString());
console.addString(" Hostname: " + PISystemInfo::instance()->hostname);
console.addString(" Username: " + PISystemInfo::instance()->user);
console.addString(" OS name: " + PISystemInfo::instance()->OS_name);
console.addString(" OS version: " + PISystemInfo::instance()->OS_version);
console.addString("Architecture: " + PISystemInfo::instance()->architecture);
console.addString(" CPU count: " + PIString::fromNumber(PISystemInfo::instance()->processorsCount));
console.addString(" ", 2, PIConsole::Yellow | PIConsole::Inverse);
console.addVariable("of this process", &sys_mon, 2);
finishTab();
}
void tabConnect() {
}
#include <picrc.h>
int main(int argc, char * argv[]) {
/*PICRC<16> crc(0xFF12FF34);
PIByteArray ba(4096);
for (int i = 0; i < ba.size_s(); ++i) ba[i] = i % 256;
PITimeMeasurer tm;
uint_cl<16> ret;
for (int i = 0; i < 1000; ++i) {
ret = crc.calculate(ba);
}*/
/*if (argc < 2) return 0;
PIFile af;
if (!af.open(argv[1], PIIODevice::ReadOnly))
return 0;
piCout << "open" << af.path();
PIByteArray sign, jfif, rsign, rdata;
int phase = 0, pos = 0, asize = af.size();
ushort jct = 0, jcl = 0;
uint ct = 0, cl = 0, cc = 0, tend = 1229278788;
sign << uchar(0x89) << uchar(0x50) << uchar(0x4E) << uchar(0x47) << uchar(0x0D) << uchar(0x0A) << uchar(0x1A) << uchar(0x0A);
jfif << uchar(0x4A) << uchar(0x46) << uchar(0x49) << uchar(0x46);
rsign.resize(sign.size());
PIByteArray nf;
PITimeMeasurer tm;
int cnt = 0, j = 0;
while (!af.isEnd()) {
if (tm.elapsed_m() >= 500) {
tm.reset();
piCout << "readed" << PIString::readableSize(af.pos());
}
if (pos >= asize) break;
switch (phase) {
case 0:
af.seek(pos);
af.read(rsign.data(), rsign.size_s());
if (rsign == sign) {
phase = 1;
nf = rsign;
} else if (rsign.resized(4) == jfif) {
phase = 2;
af.seek(pos - 6);
nf.resize(2);
af.read(nf.data(), nf.size_s());
} else
pos++;
break;
case 1:
af.read(&cl, 4);
af.read(&ct, 4);
rdata.resize(piLetobe(cl));
af.read(rdata.data(), rdata.size_s());
af.read(&cc, 4);
nf.append(&cl, 4);
nf.append(&ct, 4);
nf.append(rdata);
nf.append(&cc, 4);
if (piLetobe(ct) == tend) {
piCout << "found PNG size" << PIString::readableSize(nf.size_s());
PIFile wf("./PNG/" + PIString(cnt++) + ".png");
if (wf.open(PIIODevice::ReadWrite))
wf.write(nf.data(), nf.size());
nf.clear();
phase = 0;
pos = af.pos();
}
break;
case 2:
//jct = 0;
//while (jct != ushort(0xD9FF)) {
// af.read(&jct, 2);
// nf.append(&jct, 2);
//}
//if (++j >= 30) return 0;
af.read(&jct, 2);
nf.append(&jct, 2);
if (jct == ushort(0xD9FF)) {
piCout << "found JPG size" << PIString::readableSize(nf.size_s());
PIFile wf("./PNG/" + PIString(cnt++) + ".jpg");
if (wf.open(PIIODevice::ReadWrite))
wf.write(nf.data(), nf.size());
nf.clear();
phase = 0;
pos = af.pos();
break;
}
af.read(&jcl, 2);
nf.append(&jcl, 2);
if (jct == 0xDAFF) {
jct = 0;
int pp = af.pos();
rdata.resize(1024*1024*3);
af.read(rdata.data(), rdata.size_s());
nf.append(rdata);
//while (jct != ushort(0xFFD9)) {
// af.read(&jct, 2);
// nf.append(&jct, 2);
// //piCout << Hex << jct;
//}
piCout << "found JPG size" << PIString::readableSize(nf.size_s());
PIFile wf("./PNG/" + PIString(cnt++) + ".jpg");
if (wf.open(PIIODevice::ReadWrite))
wf.write(nf.data(), nf.size());
nf.clear();
phase = 0;
pos = pp + 1;
break;
}
//piCout << "length" << piLetobe(jcl);
rdata.resize(piLetobe(jcl) - 2);
af.read(rdata.data(), rdata.size_s());
nf.append(rdata);
break;
};
};
return 0;*/
//piCout << Hex << uint(ret) << tm.elapsed_m();
PICLI cli(argc, argv);
//cli.addArgument("");
sys_mon.startOnSelf();
console.enableExitCapture();
console.setDefaultAlignment(PIConsole::Right);
console.start();
//WAIT_FOR_EXIT
//return 0;
while (!PIKbdListener::exiting) {
if (oldmode != mode) {
file_manager.disable();
daemon_.disable();
oldmode = mode;
switch (mode) {
case 0: /// menu
tabMenu();
break;
case 1: /// host info
tabInfo();
break;
case 2: /// file manager
file_manager.enable();
break;
case 3: /// daemon
daemon_.enable();
break;
}
}
piMSleep(100);
}
return 0;
};

Binary file not shown.

View File

@@ -0,0 +1,22 @@
#include "piconsole.h"
extern PIConsole console;
inline void header(int cols = 1) {
console.addString("PIP System Daemon (PIP " + PIPVersion() + ")", 1, PIConsole::Yellow | PIConsole::Inverse);
for (int i = 2; i <= cols; ++i)
console.addString(" ", i, PIConsole::Yellow | PIConsole::Inverse);
}
inline void startTab(int cols = 1) {
console.pause(true);
console.clearTab(0);
console.lock();
header(cols);
}
inline void finishTab() {
console.unlock();
console.pause(false);
console.update();
}

View File

@@ -0,0 +1,5 @@
add_executable(pip_system_test "main.cpp")
target_link_libraries(pip_system_test pip)
if (DEFINED LIB)
install(TARGETS pip_system_test DESTINATION ${CMAKE_INSTALL_PREFIX}/bin)
endif ()

209
utils/system_test/Makefile Normal file
View File

@@ -0,0 +1,209 @@
# CMAKE generated file: DO NOT EDIT!
# Generated by "Unix Makefiles" Generator, CMake Version 2.8
# Default target executed when no arguments are given to make.
default_target: all
.PHONY : default_target
#=============================================================================
# Special targets provided by cmake.
# Disable implicit rules so canonical targets will work.
.SUFFIXES:
# Remove some rules from gmake that .SUFFIXES does not remove.
SUFFIXES =
.SUFFIXES: .hpux_make_needs_suffix_list
# Suppress display of executed commands.
$(VERBOSE).SILENT:
# A target that is always out of date.
cmake_force:
.PHONY : cmake_force
#=============================================================================
# Set environment variables for the build.
# The shell in which to execute make rules.
SHELL = /bin/sh
# The CMake executable.
CMAKE_COMMAND = /usr/bin/cmake
# The command to remove a file.
RM = /usr/bin/cmake -E remove -f
# Escaping for special characters.
EQUALS = =
# The top-level source directory on which CMake was run.
CMAKE_SOURCE_DIR = /home/andrey/linux_build/libs
# The top-level build directory on which CMake was run.
CMAKE_BINARY_DIR = /home/andrey/linux_build/libs
#=============================================================================
# Targets provided globally by CMake.
# Special rule for the target edit_cache
edit_cache:
@$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Running interactive CMake command-line interface..."
/usr/bin/cmake -i .
.PHONY : edit_cache
# Special rule for the target edit_cache
edit_cache/fast: edit_cache
.PHONY : edit_cache/fast
# Special rule for the target install
install: preinstall
@$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Install the project..."
/usr/bin/cmake -P cmake_install.cmake
.PHONY : install
# Special rule for the target install
install/fast: preinstall/fast
@$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Install the project..."
/usr/bin/cmake -P cmake_install.cmake
.PHONY : install/fast
# Special rule for the target install/local
install/local: preinstall
@$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Installing only the local directory..."
/usr/bin/cmake -DCMAKE_INSTALL_LOCAL_ONLY=1 -P cmake_install.cmake
.PHONY : install/local
# Special rule for the target install/local
install/local/fast: install/local
.PHONY : install/local/fast
# Special rule for the target install/strip
install/strip: preinstall
@$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Installing the project stripped..."
/usr/bin/cmake -DCMAKE_INSTALL_DO_STRIP=1 -P cmake_install.cmake
.PHONY : install/strip
# Special rule for the target install/strip
install/strip/fast: install/strip
.PHONY : install/strip/fast
# Special rule for the target list_install_components
list_install_components:
@$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Available install components are: \"Unspecified\""
.PHONY : list_install_components
# Special rule for the target list_install_components
list_install_components/fast: list_install_components
.PHONY : list_install_components/fast
# Special rule for the target rebuild_cache
rebuild_cache:
@$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Running CMake to regenerate build system..."
/usr/bin/cmake -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR)
.PHONY : rebuild_cache
# Special rule for the target rebuild_cache
rebuild_cache/fast: rebuild_cache
.PHONY : rebuild_cache/fast
# The main all target
all: cmake_check_build_system
cd /home/andrey/linux_build/libs && $(CMAKE_COMMAND) -E cmake_progress_start /home/andrey/linux_build/libs/CMakeFiles /home/andrey/linux_build/libs/pip/utils/system_test/CMakeFiles/progress.marks
cd /home/andrey/linux_build/libs && $(MAKE) -f CMakeFiles/Makefile2 pip/utils/system_test/all
$(CMAKE_COMMAND) -E cmake_progress_start /home/andrey/linux_build/libs/CMakeFiles 0
.PHONY : all
# The main clean target
clean:
cd /home/andrey/linux_build/libs && $(MAKE) -f CMakeFiles/Makefile2 pip/utils/system_test/clean
.PHONY : clean
# The main clean target
clean/fast: clean
.PHONY : clean/fast
# Prepare targets for installation.
preinstall: all
cd /home/andrey/linux_build/libs && $(MAKE) -f CMakeFiles/Makefile2 pip/utils/system_test/preinstall
.PHONY : preinstall
# Prepare targets for installation.
preinstall/fast:
cd /home/andrey/linux_build/libs && $(MAKE) -f CMakeFiles/Makefile2 pip/utils/system_test/preinstall
.PHONY : preinstall/fast
# clear depends
depend:
cd /home/andrey/linux_build/libs && $(CMAKE_COMMAND) -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) --check-build-system CMakeFiles/Makefile.cmake 1
.PHONY : depend
# Convenience name for target.
pip/utils/system_test/CMakeFiles/pip_system_test.dir/rule:
cd /home/andrey/linux_build/libs && $(MAKE) -f CMakeFiles/Makefile2 pip/utils/system_test/CMakeFiles/pip_system_test.dir/rule
.PHONY : pip/utils/system_test/CMakeFiles/pip_system_test.dir/rule
# Convenience name for target.
pip_system_test: pip/utils/system_test/CMakeFiles/pip_system_test.dir/rule
.PHONY : pip_system_test
# fast build rule for target.
pip_system_test/fast:
cd /home/andrey/linux_build/libs && $(MAKE) -f pip/utils/system_test/CMakeFiles/pip_system_test.dir/build.make pip/utils/system_test/CMakeFiles/pip_system_test.dir/build
.PHONY : pip_system_test/fast
main.o: main.cpp.o
.PHONY : main.o
# target to build an object file
main.cpp.o:
cd /home/andrey/linux_build/libs && $(MAKE) -f pip/utils/system_test/CMakeFiles/pip_system_test.dir/build.make pip/utils/system_test/CMakeFiles/pip_system_test.dir/main.cpp.o
.PHONY : main.cpp.o
main.i: main.cpp.i
.PHONY : main.i
# target to preprocess a source file
main.cpp.i:
cd /home/andrey/linux_build/libs && $(MAKE) -f pip/utils/system_test/CMakeFiles/pip_system_test.dir/build.make pip/utils/system_test/CMakeFiles/pip_system_test.dir/main.cpp.i
.PHONY : main.cpp.i
main.s: main.cpp.s
.PHONY : main.s
# target to generate assembly for a file
main.cpp.s:
cd /home/andrey/linux_build/libs && $(MAKE) -f pip/utils/system_test/CMakeFiles/pip_system_test.dir/build.make pip/utils/system_test/CMakeFiles/pip_system_test.dir/main.cpp.s
.PHONY : main.cpp.s
# Help Target
help:
@echo "The following are some of the valid targets for this Makefile:"
@echo "... all (the default if no target is provided)"
@echo "... clean"
@echo "... depend"
@echo "... edit_cache"
@echo "... install"
@echo "... install/local"
@echo "... install/strip"
@echo "... list_install_components"
@echo "... pip_system_test"
@echo "... rebuild_cache"
@echo "... main.o"
@echo "... main.i"
@echo "... main.s"
.PHONY : help
#=============================================================================
# Special targets to cleanup operation of make.
# Special rule to run CMake to check the build system integrity.
# No rule that depends on this can have commands that come from listfiles
# because they might be regenerated.
cmake_check_build_system:
cd /home/andrey/linux_build/libs && $(CMAKE_COMMAND) -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) --check-build-system CMakeFiles/Makefile.cmake 0
.PHONY : cmake_check_build_system

View File

@@ -0,0 +1,60 @@
# Install script for directory: /home/andrey/linux_build/libs/pip/utils/system_test
# Set the install prefix
IF(NOT DEFINED CMAKE_INSTALL_PREFIX)
SET(CMAKE_INSTALL_PREFIX "/usr")
ENDIF(NOT DEFINED CMAKE_INSTALL_PREFIX)
STRING(REGEX REPLACE "/$" "" CMAKE_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}")
# Set the install configuration name.
IF(NOT DEFINED CMAKE_INSTALL_CONFIG_NAME)
IF(BUILD_TYPE)
STRING(REGEX REPLACE "^[^A-Za-z0-9_]+" ""
CMAKE_INSTALL_CONFIG_NAME "${BUILD_TYPE}")
ELSE(BUILD_TYPE)
SET(CMAKE_INSTALL_CONFIG_NAME "Release")
ENDIF(BUILD_TYPE)
MESSAGE(STATUS "Install configuration: \"${CMAKE_INSTALL_CONFIG_NAME}\"")
ENDIF(NOT DEFINED CMAKE_INSTALL_CONFIG_NAME)
# Set the component getting installed.
IF(NOT CMAKE_INSTALL_COMPONENT)
IF(COMPONENT)
MESSAGE(STATUS "Install component: \"${COMPONENT}\"")
SET(CMAKE_INSTALL_COMPONENT "${COMPONENT}")
ELSE(COMPONENT)
SET(CMAKE_INSTALL_COMPONENT)
ENDIF(COMPONENT)
ENDIF(NOT CMAKE_INSTALL_COMPONENT)
# Install shared libraries without execute permission?
IF(NOT DEFINED CMAKE_INSTALL_SO_NO_EXE)
SET(CMAKE_INSTALL_SO_NO_EXE "1")
ENDIF(NOT DEFINED CMAKE_INSTALL_SO_NO_EXE)
IF(NOT CMAKE_INSTALL_COMPONENT OR "${CMAKE_INSTALL_COMPONENT}" STREQUAL "Unspecified")
IF(EXISTS "$ENV{DESTDIR}/usr/bin/pip_system_test" AND
NOT IS_SYMLINK "$ENV{DESTDIR}/usr/bin/pip_system_test")
FILE(RPATH_CHECK
FILE "$ENV{DESTDIR}/usr/bin/pip_system_test"
RPATH "")
ENDIF()
list(APPEND CMAKE_ABSOLUTE_DESTINATION_FILES
"/usr/bin/pip_system_test")
IF (CMAKE_WARN_ON_ABSOLUTE_INSTALL_DESTINATION)
message(WARNING "ABSOLUTE path INSTALL DESTINATION : ${CMAKE_ABSOLUTE_DESTINATION_FILES}")
ENDIF (CMAKE_WARN_ON_ABSOLUTE_INSTALL_DESTINATION)
IF (CMAKE_ERROR_ON_ABSOLUTE_INSTALL_DESTINATION)
message(FATAL_ERROR "ABSOLUTE path INSTALL DESTINATION forbidden (by caller): ${CMAKE_ABSOLUTE_DESTINATION_FILES}")
ENDIF (CMAKE_ERROR_ON_ABSOLUTE_INSTALL_DESTINATION)
FILE(INSTALL DESTINATION "/usr/bin" TYPE EXECUTABLE FILES "/home/andrey/linux_build/libs/pip/utils/system_test/pip_system_test")
IF(EXISTS "$ENV{DESTDIR}/usr/bin/pip_system_test" AND
NOT IS_SYMLINK "$ENV{DESTDIR}/usr/bin/pip_system_test")
FILE(RPATH_REMOVE
FILE "$ENV{DESTDIR}/usr/bin/pip_system_test")
IF(CMAKE_INSTALL_DO_STRIP)
EXECUTE_PROCESS(COMMAND "/usr/bin/strip" "$ENV{DESTDIR}/usr/bin/pip_system_test")
ENDIF(CMAKE_INSTALL_DO_STRIP)
ENDIF()
ENDIF(NOT CMAKE_INSTALL_COMPONENT OR "${CMAKE_INSTALL_COMPONENT}" STREQUAL "Unspecified")

106
utils/system_test/main.cpp Executable file
View File

@@ -0,0 +1,106 @@
/*
PIP - Platform Independent Primitives
System tests program
Copyright (C) 2014 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
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
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 "pip.h"
#include "pisystemtests.h"
int main(int argc, char * argv[]) {
#ifdef WINDOWS
cout << "This program is useless for Windows" << endl;
return 0;
#else
if (getuid() != 0) {
cout << "You should run this program as root!" << endl;
return 0;
}
PIConfig conf(
#ifndef WINDOWS
"/etc/pip.conf"
#else
"pip.conf"
#endif
);
PITimeMeasurer timer, tm;
timespec ts;
long stc = 0;
double st;
llong sts = 0;
clock_getres(CLOCK_REALTIME, &ts);
stc = long(ts.tv_sec) * 1000000000l + long(ts.tv_nsec);
conf.setValue("time_resolution_ns", stc);
cout << "Timer resolution is " << stc << " ns" << endl;
cout << "\"PITimer.elapsed_*\" test ... " << flush;
stc = 0;
ts.tv_sec = 0;
ts.tv_nsec = 1000;
PIVector<double> times;
times.resize(8192);
tm.reset();
PISystemTests::time_elapsed_ns = 0;
while (tm.elapsed_s() < 3.) {
for (int i = 0; i < times.size_s(); ++i) {
timer.reset();
times[i] = timer.elapsed_m();
times[i] = timer.elapsed_s();
times[i] = timer.elapsed_u();
}
st = 0;
for (int i = 0; i < times.size_s(); ++i)
st += times[i];
//cout << times[0] << endl;
//cout << st / times.size_s() / 3. * 1000. << endl;
sts += piRoundd(st / times.size_s() / 3. * 1000.);
//cout << sts << endl;
stc++;
}
sts /= stc;
conf.setValue("time_elapsed_ns", long(sts));
cout << "ok, cost " << sts << " ns, average in " << stc << " series (" << (stc * 3 * times.size_s()) << " executes)" << endl;
cout << "\"usleep\" offset test ... " << flush;
PISystemTests::time_elapsed_ns = sts;
tm.reset();
stc = 0;
sts = 0;
times.resize(128);
while (tm.elapsed_s() < 3.) {
for (int i = 0; i < times.size_s(); ++i) {
timer.reset();
usleep(1000);
times[i] = timer.elapsed_u();
}
st = 0;
for (int i = 0; i < times.size_s(); ++i)
st += times[i] - 1000;
//cout << times[0] << endl;
//cout << st / times.size_s() / 3. * 1000. << endl;
sts += piRoundd(st / times.size_s());
//cout << sts << endl;
stc++;
}
sts /= stc;
conf.setValue("usleep_offset_us", long(sts));
cout << "ok, " << sts << " us, average in " << stc << " series (" << (stc * times.size_s()) << " executes)" << endl;
//WAIT_FOR_EXIT
return 0;
#endif
};

BIN
utils/system_test/pip_system_test Executable file

Binary file not shown.

Binary file not shown.