PhoenixInkscape  2.0.0
Generate multiple png files with svg inkscape files
phoenix_system.cpp
Go to the documentation of this file.
1 /***************************************
2  Auteur : Pierre Aubert
3  Mail : pierre.aubert@lapp.in2p3.fr
4  Licence : CeCILL-C
5 ****************************************/
6 
7 #include <stdio.h>
8 #include <ctime>
9 #include "unistd.h"
10 #include <sys/ioctl.h>
11 
12 #include "PPath.h"
13 #include "phoenix_system.h"
14 
16 
19 PString phoenix_popen(const PString & command){
20  if(command == ""){return "";}
21  FILE * fp = popen(command.c_str(), "r");
22  if(fp == NULL){return "";}
23  PString resultCommand(phoenix_getFileContent(fp));
24  pclose(fp);
25  return resultCommand;
26 }
27 
29 
33 int phoenix_popen(PString & executionLog, const PString & command){
34  executionLog = "";
35  if(command == ""){return -1;}
36  FILE * fp = popen(command.c_str(), "r");
37  if(fp == NULL){return -1;}
38  executionLog = phoenix_getFileContent(fp);
39  return pclose(fp);
40 }
41 
42 
44 
49 bool phoenix_popen(const PPath & executionLogFile, const PString & command, bool onlyLogOnFail){
50  PString executionLog("");
51  bool b(phoenix_popen(executionLog, command) == 0);
52  if((onlyLogOnFail && !b) || !onlyLogOnFail){
53  executionLogFile.saveFileContent(executionLog);
54  }
55  return b;
56 }
57 
59 
62  return clock();
63 }
64 
66 
69  std::chrono::time_point<std::chrono::steady_clock> now = std::chrono::steady_clock::now();
70  auto duration = now.time_since_epoch();
71  auto nanoseconds = std::chrono::duration_cast<std::chrono::nanoseconds>(duration);
72  return nanoseconds.count();
73 
74 
75 // return std::chrono::steady_clock::to_time_t(PhoenixClock::now());
76 
77 // return std::chrono::system_clock::to_time_t((std::chrono::time_point<std::chrono::system_clock>)PhoenixClock::now());
78 
79  //This compiles, but it does not have the precision I want
80 // return std::chrono::system_clock::to_time_t(std::chrono::system_clock::now());
81 }
82 
84 
87  return ((double)phoenix_getClock())/((double)CLOCKS_PER_SEC);
88 }
89 
91 
93 time_t phoenix_getTime(){
94  return std::time(0);
95 }
96 
98 
101  std::time_t currentTime = phoenix_getTime();
102  std::tm* now_tm = std::gmtime(&currentTime);
103  char buf[42];
104  std::strftime(buf, 42, "%Y/%m/%d : %X", now_tm);
105  return buf;
106 }
107 
109 
112  std::time_t currentTime = phoenix_getTime();
113  std::tm* now_tm = std::gmtime(&currentTime);
114  char buf[42];
115  std::strftime(buf, 42, "%Y/%m/%d-%X", now_tm);
116  return buf;
117 }
118 
120 
123  std::string str("");
124  str.resize(1024lu);
125  getlogin_r((char*)str.data(), str.size() - 1lu);
126  return str;
127 }
128 
129 
131 
133 short unsigned int phoenix_getNbColTerminal(){
134  struct winsize w;
135  ioctl(0, TIOCGWINSZ, &w);
136  return w.ws_col;
137 }
138 
140 
142 short unsigned int phoenix_getNbRowTerminal(){
143  struct winsize w;
144  ioctl(0, TIOCGWINSZ, &w);
145  return w.ws_row;
146 }
147 
148 
PString phoenix_getFileContent(FILE *fp)
Get the content of a file.
Definition: PPath.cpp:28
Path of a directory or a file.
Definition: PPath.h:17
bool saveFileContent(const PString &content) const
Save a PString in a file.
Definition: PPath.cpp:395
Extends the std::string.
Definition: PString.h:16
PString phoenix_getDateCompact()
Get the current date.
time_t phoenix_getTime()
Get the current time of the program.
double phoenix_getClockSec()
Get current time.
short unsigned int phoenix_getNbRowTerminal()
Get the number of rows of the terminal.
short unsigned int phoenix_getNbColTerminal()
Get the number of columns of the terminal.
time_t phoenix_getClockNs()
Get current time in nanosecond since the starting of the CPU (steady_clock)
time_t phoenix_getClock()
Get current time.
PString phoenix_getDate()
Get the current date.
PString phoenix_popen(const PString &command)
Execute the given command and returns the output of this command.
PString phoenix_whoami()
Get the name of the current user.