Commit 2586f1dfa0efc66798af7d9a48f57f5dd8a8d309

Authored by Eric Menezes Noronha
2 parents 73c8bddb 5145564d
Exists in master

Merge branch 'master' of https://github.com/lightbase/cacic-agente

Conflicts:
	cacic-teste/testcacic.cpp
	src/cacic_computer.cpp
cacic-teste/testcacic.cpp
... ... @@ -88,15 +88,14 @@ void CTestCacic::testInterfaceDeRede(){
88 88  
89 89 void CTestCacic::testpegarOS(){
90 90 //basta que seja um retorno válido, não precisa validar todos.
91   - qDebug() << OCacicComp.getOs();
92   - QVERIFY(OCacicComp.getOs() != -1 );
  91 + QVERIFY(OCacicComp.getOs().getIdSo() != -1 );
93 92 }
94 93  
95 94 void CTestCacic::testConsole()
96 95 {
97 96 ConsoleObject console;
98 97  
99   - QVERIFY(console("echo teste").toStdString() == "teste");
  98 + QVERIFY(console("echo teste").toStdString() == "teste\n");
100 99 }
101 100  
102 101 void CTestCacic::testPegarUsu(){
... ...
src/cacic_computer.cpp
... ... @@ -2,7 +2,7 @@
2 2  
3 3 CACIC_Computer::CACIC_Computer()
4 4 {
5   - os = pegarOS();
  5 + operatingSystem = OperatingSystem();
6 6 networkInterface = networkInterfacesRunning();
7 7 usuario = pegarUsu();
8 8 }
... ... @@ -66,31 +66,6 @@ QJsonObject CACIC_Computer::toJsonObject()
66 66 }
67 67  
68 68  
69   -/*pegarOS
70   - * @return: int;
71   - * retorna um id referente a versão do SO.
72   - * 48 = Windows XP
73   - * 128 = Windows Vista
74   - * 144 = Windows 7
75   - * 160 = Windows 8
76   - * 176 = Windows 8.1
77   - * 200 = Linux
78   - * 0 = unkown
79   - */
80   -int CACIC_Computer::pegarOS(){
81   -#if defined (Q_OS_WIN)
82   - return QSysInfo::WindowsVersion;
83   -#elif defined(Q_OS_MAC)
84   - return MAC;
85   -#elif defined (Q_OS_LINUX)
86   -
87   - //TODO: extrair info de distro do "cat /etc/*release"
88   - return LINUX_ARCH;
89   -#else
90   - return -1;
91   -#endif
92   -}
93   -
94 69 /*
95 70 * PegarUsu()
96 71 * @return: std::string;
... ... @@ -112,9 +87,9 @@ std::string CACIC_Computer::pegarUsu(){
112 87 /*
113 88 * getters/setters
114 89 */
115   -int CACIC_Computer::getOs() const
  90 +OperatingSystem CACIC_Computer::getOs() const
116 91 {
117   - return os;
  92 + return operatingSystem;
118 93 }
119 94  
120 95 std::string CACIC_Computer::getUser() const {
... ...
src/cacic_computer.h
... ... @@ -8,40 +8,26 @@
8 8 #include <QtNetwork/QtNetwork>
9 9 #include <QSysInfo>
10 10  
11   -#include <stdio.h>
12   -#include <unistd.h>
13   -#include <sys/types.h>
  11 +#include <operatingsystem.h>
14 12  
15 13 class CACIC_Computer
16 14 {
17 15 public:
18 16 CACIC_Computer();
19 17  
20   - int getOs() const;
  18 + OperatingSystem getOs() const;
21 19 std::string getUser() const;
22 20 QList<QVariantMap> getNetworkInterface() const;
23 21 QList<QVariantMap> networkInterfacesRunning();
24 22 QJsonObject toJsonObject();
25 23  
26   - enum OsList {
27   - WIN_XP,
28   - WIN_VISTA,
29   - WIN_7,
30   - WIN_8,
31   - WIN_8_1,
32   - MAC,
33   - LINUX_DEBIAN,
34   - LINUX_UBUNTU,
35   - LINUX_ARCH
36   - };
37   - static const enum OsList OsList;
38   -
39 24 private:
  25 +
  26 + OperatingSystem operatingSystem;
40 27 int pegarOS();
41 28 std::string pegarUsu();
42 29  
43 30 QList<QVariantMap> networkInterface;
44   - int os;
45 31 std::string usuario;
46 32  
47 33 };
... ...
src/console.h
... ... @@ -2,16 +2,31 @@
2 2 #define CONSOLE_H
3 3  
4 4 #include <QDebug>
  5 +#include <QProcess>
5 6 #include <QString>
  7 +#include <QSysInfo>
6 8  
7 9 class ConsoleObject:public std::unary_function<std::string,QString>
8 10 {
9 11  
10 12 public:
11   - QString operator() (std::string)
  13 +
  14 +#if defined(Q_OS_LINUX)
  15 + QString operator() (std::string input)
12 16 {
13   - return "";
  17 + QProcess* process = new QProcess();
  18 +
  19 + QStringList options;
  20 + options << "-c" << QString::fromStdString(input);
  21 + process->start("/bin/sh", options);
  22 + process->waitForFinished();
  23 + QString output = process->readAll();
  24 +// qDebug() << output;
  25 +
  26 + delete process;
  27 + return output;
14 28 }
  29 +#endif
15 30 };
16 31  
17 32 #endif // CONSOLE_H
... ...
src/operatingsystem.cpp 0 → 100644
... ... @@ -0,0 +1,35 @@
  1 +#include "operatingsystem.h"
  2 +
  3 +/*pegarOS
  4 + * @return: int;
  5 + * retorna um id referente a versão do SO.
  6 + * 48 = Windows XP
  7 + * 128 = Windows Vista
  8 + * 144 = Windows 7
  9 + * 160 = Windows 8
  10 + * 176 = Windows 8.1
  11 + * 200 = Linux
  12 + */
  13 +int OperatingSystem::pegarOS(){
  14 +#if defined (Q_OS_WIN)
  15 + return QSysInfo::WindowsVersion;
  16 +#elif defined (Q_OS_LINUX)
  17 + return LINUX_ARCH;
  18 +#else
  19 + return 0;
  20 +#endif
  21 +}
  22 +
  23 +int OperatingSystem::getIdSo() const
  24 +{
  25 + return idSo;
  26 +}
  27 +
  28 +void OperatingSystem::setIdSo(int value)
  29 +{
  30 + idSo = value;
  31 +}
  32 +
  33 +OperatingSystem::OperatingSystem()
  34 +{
  35 +}
... ...
src/operatingsystem.h 0 → 100644
... ... @@ -0,0 +1,28 @@
  1 +#ifndef OPERATINGSYSTEM_H
  2 +#define OPERATINGSYSTEM_H
  3 +
  4 +#include <QtCore>
  5 +#include <QSysInfo>
  6 +
  7 +class OperatingSystem
  8 +{
  9 +private:
  10 + int idSo;
  11 +
  12 + int pegarOS();
  13 +public:
  14 + OperatingSystem();
  15 +
  16 + enum OsList {
  17 + MAC,
  18 + LINUX_DEBIAN,
  19 + LINUX_UBUNTU,
  20 + LINUX_ARCH
  21 + };
  22 + static const enum OsList OsList;
  23 +
  24 + int getIdSo() const;
  25 + void setIdSo(int value);
  26 +};
  27 +
  28 +#endif // OPERATINGSYSTEM_H
... ...