├── doc └── zlib.txt ├── lib ├── 3rdparty │ └── 3rdparty.zip ├── LICENSE ├── headers │ ├── core │ │ ├── arch │ │ │ ├── amd │ │ │ │ └── sys_info │ │ │ │ │ └── sys_info_amd.h │ │ │ └── intel │ │ │ │ └── sys_info │ │ │ │ └── sys_info_intel.h │ │ ├── crypto │ │ │ └── crypto_aes.h │ │ ├── linux │ │ │ └── udev.h │ │ ├── logger │ │ │ ├── logger_dummy.h │ │ │ ├── logger_file.h │ │ │ ├── logger_network.h │ │ │ └── logger_qdebug.h │ │ └── windows │ │ │ └── win_wmi.h │ ├── cryptography │ │ └── cryptography_engine.h │ └── globalization │ │ └── info_structs.h ├── include │ └── pcore │ │ ├── config.h │ │ ├── core │ │ ├── bit_operations.h │ │ ├── cachefx │ │ │ └── lru_cache.h │ │ ├── compressor.h │ │ ├── exception.h │ │ ├── hr.h │ │ ├── logger.h │ │ ├── profiler.h │ │ └── system_information.h │ │ ├── cryptography │ │ ├── aes.h │ │ ├── des.h │ │ └── rsa.h │ │ ├── def │ │ ├── arch.h │ │ ├── compiler.h │ │ ├── const.h │ │ ├── def_gcc.h │ │ ├── def_msvc.h │ │ ├── limits.h │ │ └── os.h │ │ ├── globalization │ │ ├── date_parser.h │ │ ├── hijri_calendar.h │ │ ├── locale.h │ │ └── persian_calendar.h │ │ ├── globals.h │ │ ├── math │ │ └── random.h │ │ ├── pcore.h │ │ ├── pcore_def.h │ │ └── root.h ├── lib.pro └── source │ ├── core │ ├── compressor.cpp │ ├── globals.cpp │ ├── hr.cpp │ ├── linux │ │ └── udev.cpp │ ├── logger.cpp │ ├── logger │ │ ├── logger_file.cpp │ │ ├── logger_network.cpp │ │ └── logger_qdebug.cpp │ ├── profiler.cpp │ ├── system_info │ │ ├── sys_info_amd.cpp │ │ ├── sys_info_global.cpp │ │ ├── sys_info_intel.cpp │ │ ├── sys_info_linux.cpp │ │ └── sys_info_win.cpp │ └── windows │ │ └── win_wmi.cpp │ ├── cryptography │ ├── aes.cpp │ ├── cryptography_engine.cpp │ ├── des.cpp │ └── rsa.cpp │ ├── globalization │ ├── date_parser.cpp │ ├── hijri_calendar.cpp │ ├── locale.cpp │ └── persian_calendar.cpp │ ├── math │ └── random.cpp │ └── root.cpp ├── pcore.pro └── test ├── common.pri ├── test.pro ├── test_cache ├── main.cpp └── test_cache.pro ├── test_calendars ├── main.cpp └── test_calendars.pro ├── test_compressor ├── lore.txt ├── main.cpp └── test_compressor.pro ├── test_crypto ├── main.cpp └── test_crypto.pro ├── test_logger ├── main.cpp └── test_logger.pro ├── test_profiler ├── main.cpp └── test_profiler.pro └── test_system_info ├── main.cpp ├── mainwindow.cpp ├── mainwindow.h ├── mainwindow.ui └── test_system_info.pro /doc/zlib.txt: -------------------------------------------------------------------------------- 1 | Compile zlib for x64: 2 | 3 | Go to command prompt and then: 4 | 5 | 6 | cd C:\Users\xxxxxxxxxxxx\Downloads\zlib-1.2.8 7 | "C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\vcvarsall.bat" x86_amd64 8 | nmake -f win32/Makefile.msc AS=ml64 LOC="-DASMV -DASMINF -I." OBJA="inffasx64.obj gvmat64.obj inffas8664.obj" -------------------------------------------------------------------------------- /lib/3rdparty/3rdparty.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pswin/pcore/5b714a35380e1d61f5cf9dc436ccdcc3e3e407bd/lib/3rdparty/3rdparty.zip -------------------------------------------------------------------------------- /lib/headers/core/arch/amd/sys_info/sys_info_amd.h: -------------------------------------------------------------------------------- 1 | //############################################################################## 2 | //# title: System informatio fro AMD's processors 3 | //# c-date: Apr-22-2016 4 | //# author: Pouya Shahinfar (Pswin) - pswinpo@gmail.com 5 | //############################################################################## 6 | 7 | #ifndef _PCORE_ARCH_AMD_SYS_INFO_H 8 | #define _PCORE_ARCH_AMD_SYS_INFO_H 9 | 10 | #include 11 | #include 12 | #include "include/pcore/pcore_def.h" 13 | 14 | #if PCORE_ARCH_FAMILY == PCORE_ARCH_FAMILY_X86 15 | 16 | //===================================== 17 | // structs 18 | //===================================== 19 | 20 | struct AMDCPUIDInformation 21 | { 22 | quint8 stepping; 23 | quint8 model; 24 | quint8 family; 25 | quint8 extended_model; 26 | quint8 extended_family; 27 | 28 | quint8 logical_processor_count; 29 | quint8 brand_id; 30 | quint16 brand_id_ex; 31 | 32 | quint32 cache_l1_size; 33 | quint32 cache_l1_size_data; 34 | quint32 cache_l1_size_instruction; 35 | quint32 cache_l2_size; 36 | quint32 cache_l3_size; 37 | 38 | 39 | 40 | QStringList extensions; 41 | }; 42 | 43 | 44 | //===================================== 45 | // functions 46 | //===================================== 47 | 48 | /*! 49 | * \brief Executes CPUID and return CPUID's information about processor 50 | */ 51 | AMDCPUIDInformation get_amd_cpuid_info( void ); 52 | 53 | 54 | #endif // PCORE_ARCH_FAMILY_X86 55 | #endif // _PCORE_ARCH_AMD_SYS_INFO_H 56 | 57 | -------------------------------------------------------------------------------- /lib/headers/core/arch/intel/sys_info/sys_info_intel.h: -------------------------------------------------------------------------------- 1 | //############################################################################## 2 | //# title: System informatio fro Intel's processors 3 | //# c-date: Apr-21-2016 4 | //# author: Pouya Shahinfar (Pswin) - pswinpo@gmail.com 5 | //############################################################################## 6 | 7 | #ifndef _PCORE_ARCH_INTEL_SYS_INFO_H 8 | #define _PCORE_ARCH_INTEL_SYS_INFO_H 9 | 10 | #include 11 | #include 12 | #include "include/pcore/pcore_def.h" 13 | 14 | #if PCORE_ARCH_FAMILY == PCORE_ARCH_FAMILY_X86 15 | 16 | //===================================== 17 | // structs 18 | //===================================== 19 | 20 | struct IntelCPUIDInformation 21 | { 22 | quint16 stepping; 23 | quint16 model; 24 | quint16 family; 25 | quint16 processor_type; 26 | quint16 extended_model; 27 | quint16 extended_family; 28 | QString serial; 29 | QString signature; 30 | quint16 brand_id; 31 | QStringList extensions; 32 | }; 33 | 34 | 35 | //===================================== 36 | // functions 37 | //===================================== 38 | 39 | /*! 40 | * \brief Retrieves micro-architecture name from signature of intel processors 41 | * \param _signature: signature of processor 42 | * \return Processor's micro-architecure name 43 | */ 44 | QString intel_get_arch_name( quint32 _signature ); 45 | 46 | /*! 47 | * \brief Executes CPUID and return CPUID's information about processor 48 | */ 49 | IntelCPUIDInformation get_intel_cpuid_info( void ); 50 | 51 | 52 | #endif // PCORE_ARCH_FAMILY_X86 53 | #endif // INTEL_SYS_INFO_H 54 | -------------------------------------------------------------------------------- /lib/headers/core/crypto/crypto_aes.h: -------------------------------------------------------------------------------- 1 | //############################################################################## 2 | //# title: AES 3 | //# c-date: Oct-26-2014 4 | //# author: Pouya Shahinfar (Pswin) - pswinpo@gmail.com 5 | //############################################################################## 6 | 7 | #ifndef _DGE_AES_H 8 | #define _DGE_AES_H 9 | 10 | #if 1 11 | # define AES_ENC_PREKEYED /* AES encryption with a precomputed key schedule */ 12 | #endif 13 | #if 1 14 | # define AES_DEC_PREKEYED /* AES decryption with a precomputed key schedule */ 15 | #endif 16 | #if 1 17 | # define AES_ENC_128_OTFK /* AES encryption with 'on the fly' 128 bit keying */ 18 | #endif 19 | #if 1 20 | # define AES_DEC_128_OTFK /* AES decryption with 'on the fly' 128 bit keying */ 21 | #endif 22 | #if 1 23 | # define AES_ENC_256_OTFK /* AES encryption with 'on the fly' 256 bit keying */ 24 | #endif 25 | #if 1 26 | # define AES_DEC_256_OTFK /* AES decryption with 'on the fly' 256 bit keying */ 27 | #endif 28 | 29 | #define N_ROW 4 30 | #define N_COL 4 31 | #define N_BLOCK (N_ROW * N_COL) 32 | #define N_MAX_ROUNDS 14 33 | 34 | typedef unsigned char uint_8t; 35 | 36 | typedef uint_8t return_type; 37 | 38 | /* Warning: The key length for 256 bit keys overflows a byte 39 | (see comment below) 40 | */ 41 | 42 | typedef uint_8t length_type; 43 | 44 | typedef struct 45 | { 46 | uint_8t ksch[(N_MAX_ROUNDS + 1) * N_BLOCK]; 47 | uint_8t rnd; 48 | } aes_context; 49 | 50 | /* The following calls are for a precomputed key schedule 51 | 52 | NOTE: If the length_type used for the key length is an 53 | unsigned 8-bit character, a key length of 256 bits must 54 | be entered as a length in bytes (valid inputs are hence 55 | 128, 192, 16, 24 and 32). 56 | */ 57 | 58 | #if defined( AES_ENC_PREKEYED ) || defined( AES_DEC_PREKEYED ) 59 | 60 | return_type aes_set_key(const unsigned char key[], 61 | length_type keylen, 62 | aes_context ctx[1]); 63 | #endif 64 | 65 | #if defined( AES_ENC_PREKEYED ) 66 | 67 | return_type aes_encrypt(const unsigned char in[N_BLOCK], 68 | unsigned char out[N_BLOCK], 69 | const aes_context ctx[1]); 70 | 71 | return_type aes_cbc_encrypt(const unsigned char *in, 72 | unsigned char *out, 73 | int n_block, 74 | unsigned char iv[N_BLOCK], 75 | const aes_context ctx[1]); 76 | #endif 77 | 78 | #if defined( AES_DEC_PREKEYED ) 79 | 80 | return_type aes_decrypt(const unsigned char in[N_BLOCK], 81 | unsigned char out[N_BLOCK], 82 | const aes_context ctx[1]); 83 | 84 | return_type aes_cbc_decrypt(const unsigned char *in, 85 | unsigned char *out, 86 | int n_block, 87 | unsigned char iv[N_BLOCK], 88 | const aes_context ctx[1]); 89 | #endif 90 | 91 | /* The following calls are for 'on the fly' keying. In this case the 92 | encryption and decryption keys are different. 93 | 94 | The encryption subroutines take a key in an array of bytes in 95 | key[L] where L is 16, 24 or 32 bytes for key lengths of 128, 96 | 192, and 256 bits respectively. They then encrypts the input 97 | data, in[] with this key and put the reult in the output array 98 | out[]. In addition, the second key array, o_key[L], is used 99 | to output the key that is needed by the decryption subroutine 100 | to reverse the encryption operation. The two key arrays can 101 | be the same array but in this case the original key will be 102 | overwritten. 103 | 104 | In the same way, the decryption subroutines output keys that 105 | can be used to reverse their effect when used for encryption. 106 | 107 | Only 128 and 256 bit keys are supported in these 'on the fly' 108 | modes. 109 | */ 110 | 111 | #if defined( AES_ENC_128_OTFK ) 112 | void aes_encrypt_128(const unsigned char in[N_BLOCK], 113 | unsigned char out[N_BLOCK], 114 | const unsigned char key[N_BLOCK], 115 | uint_8t o_key[N_BLOCK]); 116 | #endif 117 | 118 | #if defined( AES_DEC_128_OTFK ) 119 | void aes_decrypt_128(const unsigned char in[N_BLOCK], 120 | unsigned char out[N_BLOCK], 121 | const unsigned char key[N_BLOCK], 122 | unsigned char o_key[N_BLOCK]); 123 | #endif 124 | 125 | #if defined( AES_ENC_256_OTFK ) 126 | void aes_encrypt_256(const unsigned char in[N_BLOCK], 127 | unsigned char out[N_BLOCK], 128 | const unsigned char key[2 * N_BLOCK], 129 | unsigned char o_key[2 * N_BLOCK]); 130 | #endif 131 | 132 | #if defined( AES_DEC_256_OTFK ) 133 | void aes_decrypt_256(const unsigned char in[N_BLOCK], 134 | unsigned char out[N_BLOCK], 135 | const unsigned char key[2 * N_BLOCK], 136 | unsigned char o_key[2 * N_BLOCK]); 137 | #endif 138 | 139 | 140 | #endif // _DGE_AES_H -------------------------------------------------------------------------------- /lib/headers/core/linux/udev.h: -------------------------------------------------------------------------------- 1 | //############################################################################## 2 | //# title: An interface for dealing with Udev 3 | //# c-date: May-20-2016 4 | //# author: Pouya Shahinfar (Pswin) - pswinpo@gmail.com 5 | //############################################################################## 6 | 7 | 8 | #ifndef _PCORE_LINUX_UDEV_H 9 | #define _PCORE_LINUX_UDEV_H 10 | 11 | #include "include/pcore/pcore_def.h" 12 | 13 | #if PCORE_OS == PCORE_OS_LINUX 14 | 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | namespace PCore 21 | { 22 | namespace core 23 | { 24 | class Udev 25 | { 26 | //===================================== 27 | // public classes 28 | //===================================== 29 | public: 30 | 31 | class UdevDevice 32 | { 33 | //----------------- 34 | // public methods 35 | //----------------- 36 | public: 37 | 38 | /*! 39 | * \brief Constructor 40 | * \param _udev: Pointer to the udev. 41 | * \param _device: Pointer to the device. 42 | */ 43 | UdevDevice( udev *_udev, udev_device* _device ); 44 | 45 | 46 | /*! 47 | * \brief Copy constructor 48 | */ 49 | UdevDevice( const UdevDevice& _dev ); 50 | 51 | /*! 52 | * \brief Move constructor 53 | */ 54 | UdevDevice( UdevDevice&& _dev ); 55 | 56 | /*! 57 | * \brief Returns a propertie's value by specified name. 58 | * \param _name: name of the property. 59 | * \return Value's of property. 60 | */ 61 | QString getProperty( const char* _name ) const; 62 | 63 | 64 | /*! 65 | * \brief Returns a system attributes's value by specified name. 66 | * \param _name: name of the system attribute. 67 | * \return Value's of system attribute. 68 | */ 69 | QString getSystemAttribute( const char* _name ) const; 70 | 71 | 72 | /*! 73 | * \brief Returns name of the device. 74 | * \return name of device. 75 | */ 76 | QString getNode( void ) const; 77 | 78 | 79 | /*! 80 | * \brief Returns path of the device. 81 | * \return name of the path. 82 | */ 83 | QString getPath( void ) const; 84 | 85 | 86 | /*! 87 | * \brief Returns type of the device. 88 | * \return type of the device 89 | */ 90 | QString getType( void ) const; 91 | 92 | 93 | /*! 94 | * \brief Returns system name of device. 95 | * \return system name of device. 96 | */ 97 | QString getSystemName( void ) const; 98 | 99 | 100 | /*! 101 | * \brief Returns parent node. 102 | * \return Parent node. 103 | */ 104 | UdevDevice getParent( void ) const; 105 | 106 | 107 | /*! 108 | * \brief Return a parent by specified subsystem and device type. 109 | * \param _sub_system: name of subsystem. 110 | * \param _dev_type: device type; 111 | * \return 112 | */ 113 | UdevDevice getParentBySubsystemAndDevType( 114 | const char* _sub_system, 115 | const char* _dev_type ); 116 | 117 | 118 | /*! 119 | * \brief Retrieves all subsystems, specified by subsystem. 120 | * \param _name: name of subsystem. 121 | * \return All subsystems specified by name. 122 | */ 123 | QList getSubSystems( const char* _name ) const; 124 | 125 | 126 | /*! 127 | * \brief return first child subsystem, specified by name. 128 | * \param _name: name of subsystem. 129 | * \return first chid subsystem 130 | */ 131 | UdevDevice getChildSubsystem( const char* _name ) const; 132 | 133 | 134 | /*! 135 | * \brief Returns true if current device is null. 136 | * \return Returns true if current device is null. 137 | */ 138 | bool isNull( void ) const { return m_pDevice == nullptr; } 139 | 140 | /*! 141 | * \brief release this device 142 | */ 143 | void release( void ); 144 | 145 | 146 | //----------------- 147 | // private members 148 | //----------------- 149 | private: 150 | //! pointer to the device 151 | udev_device* m_pDevice = nullptr; 152 | //! pointer to the udev 153 | struct udev* m_pUdev = nullptr; 154 | //! refrence count 155 | quint32 m_pRefrences = 1; 156 | 157 | }; // UdevDevice 158 | 159 | 160 | //===================================== 161 | // public methods 162 | //===================================== 163 | public: 164 | 165 | //! constructor 166 | Udev( ); 167 | 168 | //! destructor 169 | ~Udev( ); 170 | 171 | 172 | /*! 173 | * \brief Add a subsystem for matching in scans. 174 | * \param _sub_system 175 | */ 176 | void addMatchSubsystem( const char* _sub_system ); 177 | 178 | 179 | /*! 180 | * \brief Add a property for matching scans. 181 | * \param _property_name: name of the property. 182 | * \param _property_value: value of the property. 183 | */ 184 | void addMatchProperty ( 185 | const char* _property_name, 186 | const char* _property_value 187 | ); 188 | 189 | /*! 190 | * \brief Add a class filter 191 | * \param _name: name of class 192 | */ 193 | void addMatchClass( const char* _name ); 194 | 195 | 196 | /*! 197 | * \brief Scan devices by specified filters. 198 | * \return a list of devices which are mached with specified filters. 199 | */ 200 | QList scan( void ); 201 | 202 | 203 | //===================================== 204 | // private members 205 | //===================================== 206 | private: 207 | //! Pointer to the udev. 208 | struct udev* m_pUdev = nullptr; 209 | //! Pointer to the udev_enumerate. 210 | struct udev_enumerate* m_pEnumerate = nullptr; 211 | 212 | }; // Udev 213 | } // Core 214 | } // PCore 215 | #endif // PCORE_OS_LINUX 216 | #endif // _PCORE_LINUX_UDEV_H 217 | 218 | -------------------------------------------------------------------------------- /lib/headers/core/logger/logger_dummy.h: -------------------------------------------------------------------------------- 1 | //############################################################################## 2 | //# title: Dummy logger 3 | //# c-date: Feb-02-2016 4 | //# author: Pouya Shahinfar (Pswin) - pswinpo@gmail.com 5 | //############################################################################## 6 | 7 | #ifndef _PCORE_LOGGER_DUMMY_H 8 | #define _PCORE_LOGGER_DUMMY_H 9 | 10 | #include "include/pcore/core/logger.h" 11 | 12 | 13 | //============================================================================== 14 | // Dummy Logger 15 | //============================================================================== 16 | 17 | namespace PCore 18 | { 19 | namespace core 20 | { 21 | class DummyLogger : public PCore::core::LoggerInterface 22 | { 23 | //===================================== 24 | // Metadata 25 | //===================================== 26 | Q_OBJECT 27 | 28 | Q_CLASSINFO( "author", "Pouya Shahinfar" ) 29 | Q_CLASSINFO( "version", "1.0.0" ) 30 | 31 | 32 | //===================================== 33 | // public mthods 34 | //===================================== 35 | public: 36 | /*! 37 | * \brief Constructor 38 | * \param _parent: Pointer to the parent 39 | */ 40 | DummyLogger( QObject* _parent = nullptr ) 41 | : LoggerInterface( Type::Dummy, _parent ){} 42 | 43 | /*! 44 | * \brief Logs a message 45 | * \param _msg: message 46 | */ 47 | virtual void logMessage( const LogMessage& _msg ) override {} 48 | 49 | }; // DummyLogger 50 | } // core 51 | } // PCore 52 | 53 | 54 | //============================================================================== 55 | // typedefs 56 | //============================================================================== 57 | 58 | #if PCORE_CONFIG_USE_TYPEDEF == PCORE_ENABLE 59 | using PDummyLogger = PCore::core::DummyLogger; 60 | #endif 61 | 62 | #endif // _PCORE_LOGGER_DUMMY_H 63 | 64 | -------------------------------------------------------------------------------- /lib/headers/core/logger/logger_file.h: -------------------------------------------------------------------------------- 1 | //############################################################################## 2 | //# title: File logger interface 3 | //# c-date: Feb-29-2016 4 | //# author: Pouya Shahinfar (Pswin) - pswinpo@gmail.com 5 | //############################################################################## 6 | 7 | #ifndef _PCORE_LOGGER_FILE_H 8 | #define _PCORE_LOGGER_FILE_H 9 | 10 | #include "include/pcore/core/logger.h" 11 | #include 12 | #include 13 | #include 14 | 15 | //============================================================================== 16 | // FileLogger 17 | //============================================================================== 18 | 19 | namespace PCore 20 | { 21 | namespace core 22 | { 23 | class FileLogger : public LoggerInterface 24 | { 25 | //===================================== 26 | // Metadata 27 | //===================================== 28 | Q_OBJECT 29 | 30 | Q_CLASSINFO( "author", "Pouya Shahinfar" ) 31 | Q_CLASSINFO( "version", "1.0.0" ) 32 | 33 | Q_PROPERTY(QString filename READ getFilename WRITE setFile ) 34 | Q_PROPERTY(bool is_open READ isOpen ) 35 | 36 | 37 | //===================================== 38 | // public methods 39 | //===================================== 40 | public: 41 | //! constructor 42 | FileLogger ( QObject* _parent ); 43 | 44 | //! destructor 45 | ~FileLogger(); 46 | 47 | //! logMessage 48 | virtual void logMessage( const LogMessage& _msg ) override; 49 | 50 | /*! 51 | * \brief returns output flie's name 52 | * \return output files name 53 | */ 54 | QString getFilename( void ) const { return m_sFilename; } 55 | 56 | 57 | /*! 58 | * \brief Sets output file 59 | * \param _filename: filename of output file 60 | */ 61 | void setFile( const QString& _filename ); 62 | 63 | 64 | /*! 65 | * \brief returns true if log file is open 66 | */ 67 | bool isOpen( void ) const; 68 | 69 | 70 | /*! 71 | * \brief Clear content of the file 72 | */ 73 | Q_INVOKABLE void clearContent( void ); 74 | 75 | 76 | //===================================== 77 | // private members 78 | //===================================== 79 | private: 80 | //! pointer to the file class instance 81 | QFile* m_pFile = nullptr; 82 | 83 | //! text stream 84 | QTextStream m_TextStream; 85 | 86 | //! name of file 87 | QString m_sFilename = "pcore.log"; 88 | }; // FileLogger 89 | } // core 90 | } // PCore 91 | 92 | 93 | //============================================================================== 94 | // typedefs 95 | //============================================================================== 96 | 97 | #if PCORE_CONFIG_USE_TYPEDEF == PCORE_ENABLE 98 | using PFileLogger = PCore::core::FileLogger; 99 | #endif 100 | 101 | 102 | #endif // _PCORE_LOGGER_FILE_H 103 | 104 | -------------------------------------------------------------------------------- /lib/headers/core/logger/logger_network.h: -------------------------------------------------------------------------------- 1 | //############################################################################## 2 | //# title: Network based logger 3 | //# c-date: Apr-11-2016 4 | //# author: Pouya Shahinfar (Pswin) - pswinpo@gmail.com 5 | //############################################################################## 6 | 7 | #ifndef _PCORE_LOGGER_NETWORK_H 8 | #define _PCORE_LOGGER_NETWORK_H 9 | 10 | #include "include/pcore/pcore_def.h" 11 | #include "include/pcore/core/logger.h" 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | 18 | /*! Doc: 19 | * NetworkLogger is a logger that sends messages throught network by using 20 | * TCP-socket connection. the main advantage of this logger is you can trace 21 | * your log messages on a remote computer or see them on local computer while 22 | * application is running. 23 | * 24 | * Note: 25 | * IF there is not a valid TCP connection, the logger will ignore the messages. 26 | */ 27 | 28 | 29 | //============================================================================== 30 | // NetworkLogger 31 | //============================================================================== 32 | 33 | 34 | namespace PCore 35 | { 36 | namespace core 37 | { 38 | class NetworkLogger : public PCore::core::LoggerInterface 39 | { 40 | //===================================== 41 | // metadata 42 | //===================================== 43 | Q_OBJECT 44 | 45 | //! info 46 | Q_CLASSINFO( "author", "Pouya Shahinfar" ) 47 | Q_CLASSINFO( "version", "1.0.0" ) 48 | 49 | //! properties 50 | Q_PROPERTY( port_t port READ getPort WRITE setPort ) 51 | Q_PROPERTY( QHostAddress host READ getHost WRITE setHost ) 52 | Q_PROPERTY( bool is_connected READ isConnected ) 53 | 54 | 55 | //===================================== 56 | // Typedes 57 | //===================================== 58 | public: 59 | 60 | //! Port number type 61 | using port_t = quint16; 62 | 63 | 64 | //===================================== 65 | // Public methods 66 | //===================================== 67 | public: 68 | 69 | /*! 70 | * \brief Default constructor 71 | * \param _host: Host address 72 | * \param _port_number: Port 73 | * \param _parent: Parent object 74 | */ 75 | NetworkLogger( const QHostAddress _host = PCORE_CONFIG_LOGGER_NETWORK_DEFAULT_HOST, 76 | const port_t _port = PCORE_CONFIG_LOGGER_NETWORK_DEFAULT_PORT, 77 | QObject* _parent = nullptr 78 | ); 79 | 80 | 81 | /*! 82 | * Destructor 83 | */ 84 | ~NetworkLogger(); 85 | 86 | 87 | /*! 88 | * \brief Connect logger to the host. 89 | * \return True if connection was successful or false in case of failture. 90 | */ 91 | bool connect( void ); 92 | 93 | 94 | /*! 95 | * \brief Returns true if it is connected to the server. 96 | * \return True if it is connected to the server. 97 | */ 98 | bool isConnected( void ) const; 99 | 100 | 101 | 102 | /*! 103 | * \brief Sets port number. if connection is open, it will close 104 | * that and opens a new one. 105 | * \param _port Port. 106 | * \return True if a new connection is created or port number is setted. 107 | */ 108 | bool setPort( port_t _port ); 109 | 110 | 111 | /*! 112 | * \brief Returns port number 113 | * \return Port number 114 | */ 115 | port_t getPort( void ) const { return m_Port; } 116 | 117 | 118 | /*! 119 | * \brief Sets host address. if connection is open, it will close 120 | * that and opens a new one. 121 | * \param _port Port. 122 | * \return True if a new connection is created or host address is setted. 123 | */ 124 | bool setHost( const QHostAddress& _host_addr ); 125 | 126 | 127 | /*! 128 | * \brief Returns address of host 129 | * \return Address of host 130 | */ 131 | QHostAddress getHost( void ) const { return m_HostAddress; } 132 | 133 | 134 | //! logMessage 135 | virtual void logMessage( const LogMessage &_msg ) override; 136 | 137 | 138 | //===================================== 139 | // private members and methods 140 | //===================================== 141 | private: 142 | //! pointer to the socket instance 143 | QTcpSocket* m_pSocket = nullptr; 144 | 145 | //! port 146 | port_t m_Port = PCORE_CONFIG_LOGGER_NETWORK_DEFAULT_PORT; 147 | 148 | //! host 149 | QHostAddress m_HostAddress = PCORE_CONFIG_LOGGER_NETWORK_DEFAULT_HOST; 150 | 151 | //! lock for multithread protection 152 | QMutex m_Lock; 153 | 154 | }; // NetworkLogger 155 | } // core 156 | } // PCore 157 | 158 | 159 | //============================================================================== 160 | // typedefs 161 | //============================================================================== 162 | 163 | #if PCORE_CONFIG_USE_TYPEDEF == PCORE_ENABLE 164 | using PNetworkLogger = PCore::core::NetworkLogger; 165 | #endif 166 | 167 | 168 | 169 | #endif // _PCORE_LOGGER_NETWORK_H 170 | 171 | -------------------------------------------------------------------------------- /lib/headers/core/logger/logger_qdebug.h: -------------------------------------------------------------------------------- 1 | //############################################################################## 2 | //# title: QDebug logger interface 3 | //# c-date: Feb-28-2016 4 | //# author: Pouya Shahinfar (Pswin) - pswinpo@gmail.com 5 | //############################################################################## 6 | 7 | #ifndef _PCORE_LOGGER_QDEBUG_H 8 | #define _PCORE_LOGGER_QDEBUG_H 9 | 10 | #include "include/pcore/core/logger.h" 11 | 12 | 13 | //============================================================================== 14 | // LoggerQDebug 15 | //============================================================================== 16 | namespace PCore 17 | { 18 | namespace core 19 | { 20 | class QDebugLogger : public LoggerInterface 21 | { 22 | //===================================== 23 | // Metadata 24 | //===================================== 25 | Q_OBJECT 26 | 27 | Q_CLASSINFO( "author", "Pouya Shahinfar" ) 28 | Q_CLASSINFO( "version", "1.0.0" ) 29 | 30 | //===================================== 31 | // public mthods 32 | //===================================== 33 | public: 34 | 35 | //! constructor 36 | QDebugLogger ( QObject* _parent ); 37 | 38 | //! logMessage 39 | virtual void logMessage( const LogMessage& _msg ) override; 40 | }; // LoggerQDebug 41 | } // core 42 | } // PCore 43 | 44 | 45 | //============================================================================== 46 | // typedefs 47 | //============================================================================== 48 | 49 | #if PCORE_CONFIG_USE_TYPEDEF == PCORE_ENABLE 50 | using PQDebugLogger = PCore::core::QDebugLogger; 51 | #endif 52 | 53 | 54 | #endif // _PCORE_LOGGER_QDEBUG_H 55 | 56 | -------------------------------------------------------------------------------- /lib/headers/core/windows/win_wmi.h: -------------------------------------------------------------------------------- 1 | //############################################################################## 2 | //# title: an interface for facilitating use of MS Windows's WMI 3 | //# c-date: Apr-17-2016 4 | //# author: Pouya Shahinfar (Pswin) - pswinpo@gmail.com 5 | //############################################################################## 6 | 7 | 8 | #ifndef _PCORE_WIN_WMI_H 9 | #define _PCORE_WIN_WMI_H 10 | 11 | #include "include/pcore/pcore_def.h" 12 | 13 | #if PCORE_OS == PCORE_OS_WINDOWS 14 | 15 | 16 | //============================================================================== 17 | // headers 18 | //============================================================================== 19 | 20 | #ifndef _WIN32_DCOM 21 | #define _WIN32_DCOM 22 | #endif 23 | 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | 32 | 33 | //============================================================================== 34 | // classes 35 | //============================================================================== 36 | 37 | namespace PCore 38 | { 39 | namespace core 40 | { 41 | namespace windows 42 | { 43 | class WMI 44 | { 45 | //===================================== 46 | // public members 47 | //===================================== 48 | public: 49 | //! constructor 50 | WMI(); 51 | 52 | /*! 53 | * \brief Execute a query and return true if it was successful. 54 | * \param _str: The query which must be executed. 55 | * \return True if execution of query was successful. 56 | */ 57 | bool executeQuery(const QString& _query ); 58 | 59 | /*! 60 | * \brief Select all item from specified data source 61 | * by _data_source. 62 | * \param _data_source: Name of data source. 63 | * \return true if execution was successful. 64 | */ 65 | bool selectAll(const QString& _data_source ); 66 | 67 | /*! 68 | * \brief it will go to the next row of data if it was avilable. 69 | * \return True if a new raw is abvilable. 70 | */ 71 | bool nextItem( void ); 72 | 73 | 74 | /*! 75 | * \brief return a string which is in current row and 76 | * specified column. 77 | * \param _col_name: Name of column or class member. 78 | * \param _sucsess: specifies getting value was successful or not. 79 | * \return 80 | */ 81 | QString getString( 82 | const QString& _col_name, 83 | bool* _sucsess = nullptr 84 | ); 85 | 86 | /*! 87 | * \brief return a quint32 which is in current row and 88 | * specified column. 89 | * \param _col_name: Name of column or class member. 90 | * \param _sucsess: specifies getting value was successful or not. 91 | * \return 92 | */ 93 | quint32 getInt( 94 | const QString& _col_name, 95 | bool* _sucsess = nullptr 96 | ); 97 | 98 | /*! 99 | * \brief return a quint16 which is in current row and 100 | * specified column. 101 | * \param _col_name: Name of column or class member. 102 | * \param _sucsess: specifies getting value was successful or not. 103 | * \return 104 | */ 105 | quint16 getShortInt( 106 | const QString& _col_name, 107 | bool* _sucsess = nullptr 108 | ); 109 | 110 | /*! 111 | * \brief return a quint64 which is in current row and 112 | * specified column. 113 | * \param _col_name: Name of column or class member. 114 | * \param _sucsess: specifies getting value was successful or not. 115 | * \return 116 | */ 117 | quint64 getLongInt( 118 | const QString& _col_name, 119 | bool* _sucsess = nullptr 120 | ); 121 | 122 | 123 | /*! 124 | * \brief return a double which is in current row and 125 | * specified column. 126 | * \param _col_name: Name of column or class member. 127 | * \param _sucsess: specifies getting value was successful or not. 128 | * \return 129 | */ 130 | double getDouble( 131 | const QString& _col_name, 132 | bool* _sucsess = nullptr 133 | ); 134 | 135 | /*! 136 | * \brief return an arrays of ints which is in current row and 137 | * specified column. 138 | * \param _col_name: Name of column or class member. 139 | * \param _sucsess: specifies getting value was successful or not. 140 | * \return 141 | */ 142 | QList getIntArray( 143 | const QString& _col_name, 144 | bool* _sucsess = nullptr 145 | ); 146 | 147 | 148 | /*! 149 | * \brief return an arrays of strings which is in current row and 150 | * specified column. 151 | * \param _col_name: Name of column or class member. 152 | * \param _sucsess: specifies getting value was successful or not. 153 | * \return 154 | */ 155 | QList getStringArray( 156 | const QString& _col_name, 157 | bool* _sucsess = nullptr 158 | ); 159 | 160 | 161 | //===================================== 162 | // private members 163 | //===================================== 164 | private: 165 | 166 | //! pointer to the iterator 167 | CComPtr< IEnumWbemClassObject > m_pIterator; 168 | 169 | //! pointer to the serice instance 170 | CComPtr< IWbemServices > m_pService; 171 | 172 | //! pointer to the locator 173 | CComPtr< IWbemLocator > m_pLocator; 174 | 175 | //! current row 176 | IWbemClassObject* m_pCurrentRow; 177 | 178 | //! is initialized? 179 | bool m_bInitialized = false; 180 | }; // WMI 181 | } // windows 182 | } // core 183 | } // PCore 184 | 185 | #endif // _PCORE_OS_WINDOWS 186 | #endif // _PCORE_WIN_COM_H 187 | 188 | -------------------------------------------------------------------------------- /lib/headers/cryptography/cryptography_engine.h: -------------------------------------------------------------------------------- 1 | //############################################################################## 2 | //# title: Cryptography engine 3 | //# c-date: Jun-10-2016 4 | //# author: Pouya Shahinfar (Pswin) - pswinpo@gmail.com 5 | //############################################################################## 6 | 7 | #ifndef _PCORE_CRYPTOGRAPHY_ENGINE_H 8 | #define _PCORE_CRYPTOGRAPHY_ENGINE_H 9 | 10 | namespace PCore 11 | { 12 | namespace cryptography 13 | { 14 | class CryptographyEngine 15 | { 16 | public: 17 | 18 | /*! 19 | * \brief Initialize engine. 20 | * \return Return true if initialization procedure was successful. 21 | */ 22 | static bool init( void ); 23 | 24 | 25 | /*! 26 | * \brief Release allocated resources. 27 | * \return Return true if procedure was successful. 28 | */ 29 | static bool shutdown( void ); 30 | }; 31 | } // cryptography 32 | } // PCORE 33 | 34 | 35 | #endif // _PCORE_CRYPTOGRAPHY_ENGINE_H 36 | -------------------------------------------------------------------------------- /lib/headers/globalization/info_structs.h: -------------------------------------------------------------------------------- 1 | //############################################################################## 2 | //# title: Inforamtion classes that is needed of globalization are provided here 3 | //# c-date: Jun-06-2016 4 | //# author: Pouya Shahnfar (Pswin) - pswinpo@gmail.com 5 | //############################################################################## 6 | 7 | #ifndef _PCORE_INFO_STRUCTS_H 8 | #define _PCORE_INFO_STRUCTS_H 9 | 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | 16 | namespace PCore 17 | { 18 | namespace globalization 19 | { 20 | 21 | //====================================================================== 22 | // Country 23 | //====================================================================== 24 | struct CountryInfo 25 | { 26 | QString name; //! Latin name of the country. 27 | QString nameNative; //! Native name of the counry. 28 | QString alpha2; //! ISO 3166-1 alpha-2 code. 29 | QString alpha3; //! ISO 3166-1 alpha-3 code. 30 | QString nationality; //! Nationality 31 | QString currency; //! ISO 4217:2015 based currency code. 32 | QList languages; //! A list of languages. 33 | QList currencies; //! A list of currencies. 34 | QList timeZones; //! A list of timezones 35 | }; // CountryInfo 36 | 37 | 38 | //====================================================================== 39 | // Language 40 | //====================================================================== 41 | struct Language 42 | { 43 | QString code; //! ISO 639-1 based code of the language 44 | QString name; //! Name of the language 45 | QString name_native;//! Native name of the language 46 | QStringList is_macro; //! is it a macro language or not? 47 | }; 48 | 49 | 50 | //================================================================== 51 | // Currency 52 | //================================================================== 53 | struct Currency 54 | { 55 | QString code; //! ISO 4217:2015 based code of currency. 56 | QString symbol; //! Symbol of the currency 57 | QString name; //! Name of the currency 58 | QString name_native;//! Native name of the currency 59 | }; 60 | 61 | 62 | //================================================================== 63 | // DateSystem 64 | //================================================================== 65 | struct DateSystem 66 | { 67 | QString m_sName; //! Name of the calander 68 | QString m_sNameNative; //! Native name of the calander 69 | QString m_sCountry; //! Country code in ISO 3166 70 | QStringList m_Months; //! Months name 71 | QStringList m_MonthsNative; //! Native months name 72 | QStringList m_Days; //! Days name 73 | QStringList m_DaysNative; //! Native Days name 74 | }; 75 | 76 | } // Globalization 77 | } // PCore 78 | 79 | #endif // _PCORE_INFO_STRUCTS_H 80 | -------------------------------------------------------------------------------- /lib/include/pcore/config.h: -------------------------------------------------------------------------------- 1 | //############################################################################# 2 | //# title: compile-time configurations 3 | //# c-date: Jan-01-2016 4 | //# author: Pouya Shahinfar (Pswin) - pswinpo@gmail.com 5 | //############################################################################# 6 | 7 | #ifndef _PCORE_CONFIG_H 8 | #define _PCORE_CONFIG_H 9 | 10 | #include "def/const.h" 11 | 12 | 13 | /*===================================== 14 | General 15 | =====================================*/ 16 | 17 | /* Setting file: 18 | * All settings that is needed for initializing PCore are stroed in setting 19 | * file. This macro defines the default setting file which is used for some 20 | * arguments default value in functions such as Root::init. 21 | */ 22 | #define PCORE_CONFIG_DEFAULT_SETTING_FILE "setting.ini" 23 | 24 | 25 | 26 | /* Typedefs: 27 | * PCore's classes are separated by using namespaces to pervent confilicts with 28 | * other libraries. Nevertheless, you might found it difficult to use namespaces 29 | * in your code for diffrent reasons. Therefore, a typedef of them in Qt-like 30 | * nameing convention are provided to facilitate coding and making you code 31 | * seems more legible. This feature is enabled by default, but if you do not 32 | * find it convenient, or you find confilicts in you code, you can easily 33 | * disable them by changing following macros's value to the PCORE_DISABLE. 34 | */ 35 | #define PCORE_CONFIG_USE_TYPEDEF PCORE_ENABLE 36 | 37 | 38 | /* SIMD: 39 | * PCore uses SIMD instructions for enabling faster mathematical operations. 40 | * But, due to this instructions are highly depended on the architecture of CPU. 41 | * by default they are disabled. Nevertheless, If you were sure your destination 42 | * platform support SIMD (SSE for x86, NOVA fro ARM, etc.) you can easily enbale 43 | * this feature by changing following macro's value to PCORE_ENABLE. 44 | */ 45 | #define PCORE_CONFIG_SIMD PCORE_DISABLE 46 | 47 | 48 | /* Compiler Warnings 49 | * Microsoft Visual Studio tends to produce some warnings during compiling 50 | * progress which might not be harmful or essential. So, by disabling them you 51 | * will have more clear compile output. Nevertheless, if you are intrested in 52 | * them or you want check them, just change the value of this macro PCORE_ENABLE. 53 | */ 54 | #define PCORE_CONFIG_WARNINGS PCORE_DISABLE 55 | 56 | 57 | 58 | /* Throw error 59 | * If you enable this macro must functoin in case of failture will throw an 60 | * error. Although PCore has a mechanism for controlling and reporting errors, 61 | * yet this system could help you to pass errors to the upper layers. 62 | */ 63 | #define PCORE_CONFIG_THROW_ERROR PCORE_DISABLE 64 | 65 | 66 | 67 | /* Locale and language: 68 | * Default locale and language which is used by the PCore 69 | */ 70 | 71 | #define PCORE_CONFIG_DEFAULT_LANGUAGE QLocale::English 72 | #define PCORE_CONFIG_DEFAULT_COUNTRY QLocale::UnitedStates 73 | 74 | 75 | /*===================================== 76 | Cache Frameword 77 | =====================================*/ 78 | 79 | 80 | /* Default cache size: 81 | * This is value specifies default value for maximum cache size. 82 | */ 83 | #define PCORE_CONFIG_DEFAULT_CACHE_SIZE PCORE_1MB 84 | 85 | 86 | /* This macro controls emission of signals in the cache class. 87 | */ 88 | #define PCORE_CONFIG_CACHE_EMIT_SIGNAL PCORE_DISABLE; 89 | 90 | 91 | /*===================================== 92 | Logger 93 | =====================================*/ 94 | 95 | /* 96 | * In case of absence of setting file a default logger will be used. By default 97 | * this logger is bond to Qt Application output but you can change it by 98 | * modifying this macro. 99 | */ 100 | #define PCORE_DEFAULT_LOGGER PCore::Core::LoggerInterface::Type::QDebug 101 | 102 | /* 103 | * Enabling or disabling diffrent loggers in debuging mode. 104 | */ 105 | #define PCORE_CONFIG_LOG_CRITICAL_DEBUG PCORE_ENABLE 106 | #define PCORE_CONFIG_LOG_ERROR_DEBUG PCORE_ENABLE 107 | #define PCORE_CONFIG_LOG_WARNING_DEBUG PCORE_ENABLE 108 | #define PCORE_CONFIG_LOG_INFO_DEBUG PCORE_ENABLE 109 | #define PCORE_CONFIG_LOG_TRACE_DEBUG PCORE_DISABLE 110 | 111 | /* 112 | * Enabling or disabling diffrent loggers in release mode. 113 | */ 114 | #define PCORE_CONFIG_LOG_CRITICAL_RELEASE PCORE_ENABLE 115 | #define PCORE_CONFIG_LOG_ERROR_RELEASE PCORE_ENABLE 116 | #define PCORE_CONFIG_LOG_WARNING_RELEASE PCORE_ENABLE 117 | #define PCORE_CONFIG_LOG_INFO_RELEASE PCORE_ENABLE 118 | #define PCORE_CONFIG_LOG_TRACE_RELEASE PCORE_DISABLE 119 | 120 | /* 121 | * This configuration is for tracing methods execution in case of absence of 122 | * debugger or whenever you find it more convenient. You should bare that in 123 | * mind, the type of the Function Logger is Trace, therefore, by disabling 124 | * trace logger it will not work. 125 | */ 126 | #define PCORE_CONFIG_LOG_TRACE_FUNCTION_START PCORE_DISABLE 127 | 128 | 129 | /* 130 | * This macros define network logger's default TCP-port and host address. 131 | */ 132 | #define PCORE_CONFIG_LOGGER_NETWORK_DEFAULT_PORT 3306 133 | #define PCORE_CONFIG_LOGGER_NETWORK_DEFAULT_HOST QHostAddress::LocalHost 134 | #define PCORE_CONFIG_LOGGER_NETWORK_DEFAULT_WAIT_TIME 30000 // 30 sec 135 | 136 | 137 | /*===================================== 138 | Date and time 139 | =====================================*/ 140 | 141 | #define PCORE_CONFIG_DATE_PERSIAN_DEFAULT_FORMAT "yyyy/mm/dd" 142 | #define PCORE_CONFIG_DATE_HIJRI_DEFAULT_FORMAT "yyyy/mm/dd" 143 | 144 | #endif // _PCORE_CONFIG_H 145 | -------------------------------------------------------------------------------- /lib/include/pcore/core/bit_operations.h: -------------------------------------------------------------------------------- 1 | //############################################################################## 2 | //# title: Bit wise operations 3 | //# c-date: Apr-20-2016 4 | //# author: Pouya Shahinfar 5 | //############################################################################## 6 | 7 | #ifndef _PCORE_BIT_OPERATIONS_H 8 | #define _PCORE_BIT_OPERATIONS_H 9 | 10 | 11 | /* \brif Make a mak at specified position with given length. 12 | * \param __pos: Start position. 13 | * \param __len: Length of mask. 14 | */ 15 | #define PCORE_BIT_MASK( __pos, __len ) (((1 << (__len)) - 1) << (__pos)) 16 | 17 | 18 | /* 19 | * \birf Check if a bit is setted or not 20 | * \param val: Variable that must be checked. 21 | * \param pos: position that must be checked 22 | */ 23 | #define PCORE_BIT_CHECK( __var, __pos ) ((bool)(( __var >> __pos ) & 1)) 24 | 25 | 26 | /* 27 | * \brif Sets specified bit. 28 | * \param __var: Varable. 29 | * \pram __pos: Bit position. 30 | */ 31 | #define PCORE_BIT_SET( __var, __pos ) \ 32 | ((__var) = ((__var) & ( 1 >> __pos))) 33 | 34 | 35 | /* 36 | * \brif Unsets specified bit from given variable. 37 | * \param __var: Varable. 38 | * \pram __pos: Bit position. 39 | */ 40 | #define PCORE_BIT_UNSET( __var, __pos ) \ 41 | ((__var) = ((__var) & ~( 1 >> __pos))) 42 | 43 | 44 | /* 45 | * \brif Reads specified bits from _pos with length _size 46 | * \param __var: Varable that must be readed from. 47 | * \pram __pos: Start position. 48 | * \param __len: Length. 49 | */ 50 | #define PCORE_BIT_READ( __var, __pos, __len ) \ 51 | ( __var & PCORE_BIT_MASK(__pos,__len) ) 52 | 53 | /* 54 | * \brif Writes given value in specified bits of given variable. 55 | * \param __var: Varable that must be writed to. 56 | * \pram __pos: Start position. 57 | * \param __len: Length. 58 | * \param __val: value that have to be writed in specified bits of __var. 59 | */ 60 | #define PCORE_BIT_WRITE( __var, __pos, __len, __val ) \ 61 | ( __var = ( __val << __pos ) | \ 62 | (~PCORE_BIT_MASK(__pos,__len) & __var) ) 63 | 64 | 65 | #endif // _PCORE_BIT_OPERATIONS_H 66 | 67 | -------------------------------------------------------------------------------- /lib/include/pcore/core/cachefx/lru_cache.h: -------------------------------------------------------------------------------- 1 | //############################################################################## 2 | //# title: LRU ( Last Recently Used) based cache. 3 | //# c-date: Jun-21-2016 4 | //# author: Pouya Shahinfar (Pswin) - pswinpo@gmail.com 5 | //############################################################################## 6 | 7 | 8 | #ifndef _PCORE_LRU_CACHE_H 9 | #define _PCORE_LRU_CACHE_H 10 | 11 | //============================================================================== 12 | // includes 13 | //============================================================================== 14 | 15 | #include "../../pcore_def.h" 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | //============================================================================== 26 | // code 27 | //============================================================================== 28 | 29 | namespace PCore 30 | { 31 | namespace core 32 | { 33 | namespace cachefx 34 | { 35 | template< typename KEY, typename T > 36 | class LRUCache 37 | { 38 | //===================================== 39 | // Typedefs 40 | //===================================== 41 | public: 42 | 43 | #if PCORE_ARCH_WORD_SIZE == 64 44 | using cost_t = quint64; 45 | #elif PCORE_ARCH_WORD_SIZE == 32 46 | using cost_t = quint32; 47 | #else 48 | #warning "Undefined word size for the cache system; 64-bit has used." 49 | using cost_t = quint64; 50 | #endif 51 | 52 | //===================================== 53 | // Structs 54 | //===================================== 55 | private: 56 | 57 | /*! 58 | * \brief Cache node. 59 | */ 60 | struct Node 61 | { 62 | Node* previous = nullptr; //! Previous node. 63 | Node* next = nullptr; //! Next node. 64 | cost_t cost = 0; //! Cost of the node. 65 | KEY key; //! Key 66 | QSharedPointer value ; //! Value of the node. 67 | }; 68 | 69 | 70 | //===================================== 71 | // public methods 72 | //===================================== 73 | public: 74 | 75 | 76 | /*! 77 | * \brief Constructor. 78 | * \param _max_cost: Maximim cost (size) of the cahce. 79 | */ 80 | explicit LRUCache(cost_t _max_cost = PCORE_CONFIG_DEFAULT_CACHE_SIZE ) 81 | { 82 | m_uMaxCost = _max_cost; 83 | } 84 | 85 | 86 | /*! 87 | * \brief Destructor. 88 | */ 89 | ~LRUCache( ) 90 | { 91 | clear(); 92 | } 93 | 94 | 95 | /*! 96 | * \brief Returns the object associated with key key, or nullptr 97 | * if the key does not exist in the cache. 98 | */ 99 | QSharedPointer get( const KEY& _key ) 100 | { 101 | QReadLocker lock( &m_Lock ); 102 | if ( m_Items.find( _key ) != m_Items.end() ) 103 | { 104 | Node* n = m_Items[ _key ]; 105 | if ( m_pFirst != nullptr ) m_pFirst->previous = n; 106 | if ( m_pLast == n ) 107 | { 108 | m_pLast = n->previous; 109 | m_pLast->next = nullptr; 110 | } 111 | 112 | n->next = m_pFirst; 113 | m_pFirst = n; 114 | n->previous = nullptr; 115 | 116 | return n->value; 117 | } 118 | 119 | return QSharedPointer( nullptr ); 120 | } 121 | 122 | 123 | /*! 124 | * \brief Inserts an item to the cache. 125 | * \param _key: Key of the item. 126 | * \param _val: Item's itself. 127 | * \param _cost: Cost of the item. 128 | * \return Returns true if inserting new item was successful; 129 | * otherwise returns false. 130 | */ 131 | bool insert( const KEY& _key, const T& _val, cost_t _cost = 1 ) 132 | { 133 | QWriteLocker lock( &m_Lock ); 134 | 135 | Node* n = nullptr; 136 | bool update = false; 137 | 138 | // cost (size) of the item is more than maximum cost 139 | if ( _cost > m_uMaxCost ) 140 | { 141 | return false; 142 | } 143 | 144 | if ( m_Items.find( _key) != m_Items.end() ) 145 | { 146 | n = m_Items[_key]; 147 | n->previous->next = n->next; 148 | n->next->previous = n->previous; 149 | m_uUsedCost -= n->cost; 150 | update = true; 151 | } 152 | 153 | // create free space for the new item 154 | if ( (_cost + m_uUsedCost) > m_uMaxCost ) 155 | { 156 | trim( _cost ); 157 | } 158 | 159 | if ( update == false ) 160 | { 161 | n = new Node(); 162 | } 163 | 164 | n->cost = _cost; 165 | n->next = m_pFirst; 166 | n->key = _key; 167 | n->previous = nullptr; 168 | n->value = QSharedPointer( new T( _val ) ); 169 | 170 | if ( m_pFirst != nullptr ) 171 | { 172 | m_pFirst->previous = n; 173 | } 174 | else 175 | { 176 | m_pLast = n; 177 | } 178 | 179 | m_pFirst = n; 180 | m_uUsedCost += _cost; 181 | m_Items[ _key ] = n; 182 | 183 | 184 | return true; 185 | } // insert 186 | 187 | 188 | /*! 189 | * \brief Rermoves specified item by given key from the cache. 190 | * \param _key: Key of the item. 191 | * \return Returns true if removing key was successful 192 | */ 193 | bool remove( const KEY& _key ) 194 | { 195 | QWriteLocker lock( &m_Lock ); 196 | 197 | auto it = m_Items.find( _key ); 198 | if ( _key == m_Items.end() ) return false; 199 | 200 | Node* n = it.value(); 201 | if ( n->next != nullptr ) n->next->previous = n->previous; 202 | if ( n->previous != nullptr ) n->previous->next = n->next; 203 | m_uUsedCost -= n->cost; 204 | 205 | m_Items.remove( _key ); 206 | delete n; 207 | 208 | return true; 209 | } // remove 210 | 211 | 212 | /*! 213 | * \brief Removes all items from the cache. 214 | */ 215 | void clear( void ) 216 | { 217 | QWriteLocker lock( &m_Lock ); 218 | 219 | m_Items.clear(); 220 | 221 | Node* n = m_pFirst; 222 | Node* m; 223 | while ( n != nullptr ) 224 | { 225 | m = n->next; 226 | delete n; 227 | n = m; 228 | } 229 | } // clear 230 | 231 | 232 | /*! 233 | * \brief Returns true if the cache is empty; otherwise, returns false. 234 | */ 235 | bool isEmpty( void ) 236 | { 237 | QReadLocker lock( &m_Lock ); 238 | return m_Items.size() == 0; 239 | } 240 | 241 | 242 | /*! 243 | * \brief Returns the number of the cached items. 244 | */ 245 | int size( void ) 246 | { 247 | QReadLocker lock( &m_Lock ); 248 | return m_Items.size(); 249 | } 250 | 251 | 252 | /*! 253 | * \brief Return maximum cost (size) of the cache. 254 | */ 255 | cost_t maxCost( void ) 256 | { 257 | QReadLocker lock( &m_Lock ); 258 | return m_uMaxCost; 259 | } 260 | 261 | 262 | /*! 263 | * \brief Sets maximum cost (Size) of the cache 264 | * \param _max_cost: new maximum cost; 265 | */ 266 | void setMaxCost( cost_t _max_cost ) 267 | { 268 | QWriteLocker lock( &m_Lock ); 269 | m_uMaxCost = _max_cost; 270 | } 271 | 272 | 273 | /*! 274 | * \brief Returns used size of the cache. 275 | */ 276 | cost_t usedCost( void ) 277 | { 278 | QReadLocker lock( &m_Lock ); 279 | return m_uUsedCost; 280 | } 281 | 282 | 283 | /*! 284 | * \brief This function is for testing only 285 | */ 286 | void printCacheOrder( ) 287 | { 288 | Node* n = m_pFirst; 289 | int i = 0; 290 | while ( n != nullptr ) 291 | { 292 | qDebug() << i++ << n->key << *n->value; 293 | n = n->next; 294 | } 295 | } 296 | 297 | //===================================== 298 | // private members 299 | //===================================== 300 | private: 301 | 302 | //! Fist node (The most recently used node). 303 | Node* m_pFirst = nullptr; 304 | 305 | //! Last node (The less recently used node). 306 | Node* m_pLast = nullptr; 307 | 308 | //! Maximum cost (size) of the cache. 309 | cost_t m_uMaxCost = PCORE_CONFIG_DEFAULT_CACHE_SIZE; 310 | 311 | //! Total used size of the cache. 312 | cost_t m_uUsedCost = 0; 313 | 314 | //! items 315 | QHash m_Items; 316 | 317 | //! Reader-Writer lock 318 | QReadWriteLock m_Lock; 319 | 320 | 321 | //===================================== 322 | // private methods 323 | //===================================== 324 | private: 325 | 326 | void trim ( cost_t _cost ) 327 | { 328 | cost_t cost = 0; 329 | while ( m_pLast != nullptr ) 330 | { 331 | if ( cost >= _cost ) return; 332 | 333 | m_Items.remove( m_pLast->key ); 334 | cost += m_pLast->cost; 335 | m_uUsedCost -= m_pLast->cost; 336 | Node* n = m_pLast->previous; 337 | delete m_pLast; 338 | m_pLast = n; 339 | if ( m_pLast != nullptr ) m_pLast->next = nullptr; 340 | } 341 | } 342 | 343 | }; // LRUCache 344 | } // cachefx 345 | } // core 346 | } // PCore 347 | 348 | 349 | //============================================================================== 350 | // Typedefs 351 | //============================================================================== 352 | 353 | #if PCORE_CONFIG_USE_TYPEDEF == PCORE_ENABLE 354 | template< class KEY, class T> 355 | using PLRUCache = PCore::core::cachefx::LRUCache; 356 | #endif 357 | 358 | 359 | 360 | #endif // _PCORE_LRU_CACHE_H 361 | -------------------------------------------------------------------------------- /lib/include/pcore/core/compressor.h: -------------------------------------------------------------------------------- 1 | //############################################################################## 2 | //# title: Compressor and uncompressor 3 | //# c-date: Apr-13-2016 4 | //# author: Pouya Shahinfar 5 | //############################################################################## 6 | 7 | #ifndef _PCORE_COMPRESSOR_H 8 | #define _PCORE_COMPRESSOR_H 9 | 10 | #include "../pcore_def.h" 11 | #include 12 | #include 13 | 14 | namespace PCore 15 | { 16 | namespace core 17 | { 18 | class PCORE_API Compressor 19 | { 20 | 21 | public: 22 | 23 | /*! For the first phase, PCore only support following formats. But 24 | * we intended to extend them. 25 | */ 26 | enum class Format 27 | { 28 | RawDeflate, //! Raw deflate format 29 | Zlib, //! Zlib 30 | GZip, //! GZip 31 | Default //! Default format 32 | }; 33 | 34 | 35 | /*! 36 | * \brief Compression level. 37 | */ 38 | enum class Level 39 | { 40 | BestSpeed, 41 | BestCompression, 42 | Default 43 | }; 44 | 45 | public: 46 | 47 | /*! 48 | * \brief Compress given byte array and return it. 49 | * \param _byte_ar: Input byte array. 50 | * \param _format: Method of compression 51 | * \return compressed byte array. 52 | */ 53 | static QByteArray compress( 54 | const QByteArray& _in, 55 | Format _format = Format::RawDeflate, 56 | Level _level = Level::Default 57 | ); 58 | 59 | 60 | /*! 61 | * \brief Compress a single file. 62 | * \param _in_filename: Input file name. 63 | * \param _out_filename: Output file name. 64 | * \param _format: Method of compression. 65 | * \return True if compression progress was successful. 66 | */ 67 | static bool compressFile( 68 | const QString& _in_filename, 69 | const QString& _out_filename, 70 | Format _format = Format::RawDeflate, 71 | Level _level = Level::Default 72 | ); 73 | 74 | 75 | /*! 76 | * \brief Decompress given byte array and return it. 77 | * \param _in: Input byte array. 78 | * \param _format: Method of decompression 79 | * \return 80 | */ 81 | static QByteArray decompress( 82 | const QByteArray& _in, 83 | Format _format = Format::RawDeflate 84 | ); 85 | 86 | 87 | /*! 88 | * \brief Decompress a single file. 89 | * \param _in_filename: Input file name. 90 | * \param _out_filename: Output file name. 91 | * \param _format: Method of decompression. 92 | * \return True if decompression progress was successful. 93 | */ 94 | static bool decompressFile( 95 | const QString& _in_filename, 96 | const QString& _out_filename, 97 | Format _format = Format::Default 98 | ); 99 | 100 | }; // Compressor 101 | } // core 102 | } // PCore 103 | 104 | 105 | //============================================================================== 106 | // typedefs 107 | //============================================================================== 108 | 109 | #if PCORE_CONFIG_USE_TYPEDEF == PCORE_ENABLE 110 | using PCompressor = PCore::core::Compressor; 111 | #endif 112 | 113 | 114 | #endif // _PCORE_COMPRESSOR_H 115 | 116 | -------------------------------------------------------------------------------- /lib/include/pcore/core/exception.h: -------------------------------------------------------------------------------- 1 | //############################################################################## 2 | //# title: PCore exception system 3 | //# c-date: Apr-15-2016 4 | //# author: Pouya Shahinfar (Pswin) - pswinpo@gmail.com 5 | //############################################################################## 6 | 7 | #ifndef _PCORE_EXCEPTION_H 8 | #define _PCORE_EXCEPTION_H 9 | 10 | #include "../pcore_def.h" 11 | #include "../config.h" 12 | 13 | #if PCORE_CONFIG_THROW_ERROR == PCORE_ENABLE 14 | #define PCORE_THROW_EXCEPTION( __type, __desc ) throw ( __type(__desc) ); 15 | #else 16 | #define PCORE_THROW_EXCEPTION( __type, __desc) PCORE_NOOP(''); 17 | #endif 18 | 19 | #endif // _PCORE_EXCEPTION_H 20 | 21 | -------------------------------------------------------------------------------- /lib/include/pcore/core/hr.h: -------------------------------------------------------------------------------- 1 | //############################################################################## 2 | //# title: This class provides some methods which by using them more human 3 | //# readable data could be provided 4 | //# c-date: Jun-16-2016 5 | //# author: Pouya Shahinfar (Pswin) - pswinpo@gmail.com 6 | //############################################################################## 7 | 8 | #ifndef _PCORE_HUMAN_READABLE_H 9 | #define _PCORE_HUMAN_READABLE_H 10 | 11 | #include "../pcore_def.h" 12 | #include "../config.h" 13 | class QString; 14 | 15 | namespace PCore 16 | { 17 | namespace core 18 | { 19 | class PCORE_API HumanReadable 20 | { 21 | public: 22 | /*! 23 | * \brief Converts bytes to KB, MB, etc. 24 | * \param _byte: Bytes. 25 | * \param _fraction: Precision of fraction part. 26 | */ 27 | static QString byteToString( quint64 _bytes, 28 | int _fraction = 2 29 | ); 30 | 31 | 32 | /*! 33 | * \brief Converts Hertx to MHz , GHz and etc. 34 | * \param _freq: Frequance in Hertz. 35 | * \param _fraction: Precision of fraction part 36 | */ 37 | static QString freqToString( quint64 _freq, 38 | int _fraction = 2); 39 | 40 | }; 41 | } // core 42 | } // PCore 43 | 44 | #endif // _PCORE_HUMAN_READABLE_H 45 | -------------------------------------------------------------------------------- /lib/include/pcore/core/profiler.h: -------------------------------------------------------------------------------- 1 | //############################################################################## 2 | //# title: Profiling Tool 3 | //# c-date: Apr-08-2016 4 | //# author: Pouya Shahinfar (Pswin) - pswinpo@gmail.com 5 | //############################################################################## 6 | 7 | #ifndef _PCORE_PROFILER_H 8 | #define _PCORE_PROFILER_H 9 | 10 | #include "../pcore_def.h" 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | 17 | //===================================== 18 | // Macros 19 | //===================================== 20 | 21 | #define PCORE_PROFILE_FUNCTION( ) \ 22 | PCore::core::Profiler ___profiler( PCORE_FILE_NAME + "::" + PCORE_FUNC_NAME );\ 23 | ___profiler.start(); 24 | 25 | 26 | #define PCORE_PROFILE_BLOCK_START( ___var, ___name ) \ 27 | PCore::core::Profiler ___var( ___name ); ___var.start(); 28 | 29 | 30 | #define PCORE_PROFILE_BLOCK_END( ___var )\ 31 | ___var.stop(); 32 | 33 | 34 | //===================================== 35 | // Classes 36 | //===================================== 37 | 38 | namespace PCore 39 | { 40 | namespace core 41 | { 42 | //===================================== 43 | // Profiler 44 | //===================================== 45 | class PCORE_API Profiler 46 | { 47 | public: 48 | 49 | /*! 50 | * \brief Default constructor 51 | * \param _name: Name of profiler 52 | */ 53 | Profiler ( const QString& _name ); 54 | 55 | 56 | //! destructor 57 | ~Profiler( ); 58 | 59 | 60 | /*! 61 | * \brief Returns name of profiler. 62 | * \return Returns name of profiler. 63 | */ 64 | QString getName( void ) const { return m_sName; } 65 | 66 | 67 | /*! 68 | * \brief Start profiling. 69 | */ 70 | void start( void ); 71 | 72 | 73 | /*! 74 | * \brief Stop profiling. 75 | */ 76 | quint64 stop( void ); 77 | 78 | private: 79 | //! name of profiler 80 | QString m_sName; 81 | }; // Profiler 82 | 83 | 84 | 85 | //====================================================================== 86 | // ProfileManager 87 | //====================================================================== 88 | class PCORE_API ProfileManager : QObject 89 | { 90 | //===================================== 91 | // metadata 92 | //===================================== 93 | Q_OBJECT 94 | Q_CLASSINFO( "author", "Pouya Shahinfar" ) 95 | Q_CLASSINFO( "version", "1.0.0" ) 96 | 97 | 98 | public: 99 | //===================================== 100 | // Profile 101 | //===================================== 102 | struct Profile 103 | { 104 | QString name; //! name of profile 105 | quint64 call_num = 0; //! call number 106 | quint64 total_time = 0; //! total time 107 | quint64 max_time = 0; //! maximum time 108 | quint64 min_time = -1; //! minimum time 109 | bool is_started = false; //! is started? 110 | quint64 last_time = 0; //! last time 111 | quint32 pending_count = 0; //! pending call cout for reverse functions or multithread use 112 | QMutex lock; //! lock for protecting structure in multithread use 113 | }; 114 | 115 | 116 | //===================================== 117 | // typedefs 118 | //===================================== 119 | public: 120 | using ProfileMap = QMap; 121 | 122 | 123 | //===================================== 124 | // public methods 125 | //===================================== 126 | public: 127 | 128 | //! default constructor 129 | explicit ProfileManager( QObject* _parent = nullptr ); 130 | 131 | /*! 132 | * \brief Start a profile by given name. 133 | * \param _name: Name of the profile. 134 | */ 135 | void startProfile( const QString& _name ); 136 | 137 | /*! 138 | * \brief Stops a profile by given name. 139 | * \param _name: Name of profile. 140 | * \return Number of miliseconds that elapsed from start. 141 | */ 142 | quint64 stopProfile( const QString& _name ); 143 | 144 | /*! 145 | * \brief Returns all profiles. 146 | * \return All profiles. 147 | */ 148 | ProfileMap getProfiles( void ) const; 149 | 150 | /*! 151 | * \brief Print all profiles to the specified file. 152 | * \param _filename: destionation file. 153 | */ 154 | bool printToFile( const QString& _filename ); 155 | 156 | 157 | //===================================== 158 | // private members 159 | //===================================== 160 | private: 161 | //! list of profiles 162 | ProfileMap m_Map; 163 | 164 | //! lock for map 165 | QMutex m_MapLock; 166 | }; // ProfileManager 167 | } // core 168 | } // PCore 169 | 170 | 171 | #endif // _PCORE_PROFILER_H 172 | 173 | -------------------------------------------------------------------------------- /lib/include/pcore/cryptography/aes.h: -------------------------------------------------------------------------------- 1 | //############################################################################## 2 | //# title: AES 3 | //# c-date: Jun-09-2016 4 | //# author: Pouya Shahinfar (Pswin) - pswinpo@gmail.com 5 | //############################################################################## 6 | 7 | #ifndef _PCORE_CRYPTO_AES_H 8 | #define _PCORE_CRYPTO_AES_H 9 | 10 | #include "../pcore_def.h" 11 | #include "../globals.h" 12 | #include 13 | 14 | namespace PCore 15 | { 16 | namespace cryptography 17 | { 18 | class PCORE_API AES : public QObject 19 | { 20 | //===================================== 21 | // Metadata 22 | //===================================== 23 | 24 | Q_OBJECT 25 | Q_CLASSINFO( "author", "Pouya Shahinfar" ) 26 | Q_CLASSINFO( "version", "1.0.0" ) 27 | 28 | 29 | //===================================== 30 | // enums 31 | //===================================== 32 | public: 33 | 34 | /*! 35 | * Block size 36 | */ 37 | enum class BlockSize 38 | { 39 | _128 = 128, 40 | _192 = 192, 41 | _256 = 256, 42 | 43 | }; 44 | 45 | 46 | //===================================== 47 | // Public methods 48 | //===================================== 49 | public: 50 | 51 | /*! 52 | * \brief Constructs an AES object. 53 | * \param _init_vec: Initialization vector. 54 | * \param _salt: Salt. 55 | * \param _block_size: Size of the blocks. 56 | */ 57 | AES( const QByteArray _init_vec = QByteArray(), 58 | const QByteArray _salt = QByteArray(), 59 | BlockSize _block_size = BlockSize::_128, 60 | QObject* _parent = nullptr 61 | ); 62 | 63 | 64 | /*! 65 | * \brief Sets pass phrase (Password). 66 | * \param _pass: Pass phrase (Password). 67 | */ 68 | void setPass( const QByteArray& _pass ); 69 | 70 | 71 | 72 | /*! 73 | * \brief Sets IV (Initialization Vector). 74 | */ 75 | void setIV( const QByteArray& _iv ); 76 | 77 | 78 | /*! 79 | * \brief Returns IV (Initialization Vector). 80 | */ 81 | QByteArray getIV( void ) const; 82 | 83 | 84 | /*! 85 | * \brief Sets size of blocks. 86 | */ 87 | void setBlockSize( BlockSize _block_size ); 88 | 89 | 90 | /*! 91 | * \brief Returns block size. 92 | */ 93 | BlockSize getBlockSize( void ) const; 94 | 95 | 96 | /*! 97 | * \brief Sets salt. 98 | */ 99 | void setSalt( const QByteArray& _salt ); 100 | 101 | 102 | /*! 103 | * \brief Returns salt. 104 | */ 105 | QByteArray getSalt( void ) const; 106 | 107 | 108 | /*! 109 | * \brief Encrypts given data, and returns it. 110 | * \param _data: Data that should be encrypted. 111 | * \param _attach_salt: if it is true, Salt will be attached 112 | * to the encryped data. 113 | * \return Retruns encrypted data. 114 | */ 115 | QByteArray encrypt( const QByteArray& _data , 116 | bool _attach_salt = true 117 | ); 118 | 119 | 120 | 121 | /*! 122 | * \brief Decrypts given data, and returns it. 123 | * \param _data: Data that should be decrypted. 124 | * \return Retruns decrypted data. 125 | */ 126 | QByteArray decrypt( const QByteArray& _data ); 127 | 128 | 129 | //===================================== 130 | // static methods 131 | //===================================== 132 | public: 133 | 134 | /*! 135 | * \brief Encrypts given data with specified params, and returns it. 136 | * \param _pass: Pass phrase (Password). 137 | * \param _data: Data that should be encrypted. 138 | * \param _iv: Initialization vector. 139 | * \param _block_size: Size of the blocks. 140 | * \return Encrypted data. 141 | */ 142 | static QByteArray encryptEX( const QByteArray& _pass, 143 | const QByteArray& _data, 144 | QByteArray& _iv = NullQByteArray, 145 | QByteArray& _salt = NullQByteArray, 146 | BlockSize _block_size = BlockSize::_128, 147 | bool _attach_salt = true 148 | ); 149 | 150 | 151 | /*! 152 | * \brief Decrypts given data with specified params, and returns it. 153 | * \param _pass: Pass phrase (Password). 154 | * \param _data: Data that should be decrypted. 155 | * \param _iv: Initialization vector. 156 | * \param _block_size: Size of the blocks. 157 | * \return decrypted data. 158 | */ 159 | static QByteArray decryptEX( const QByteArray& _pass, 160 | const QByteArray& _data, 161 | QByteArray& _iv = NullQByteArray, 162 | const QByteArray& _salt = NullQByteArray, 163 | BlockSize _block_size = BlockSize::_128 164 | ); 165 | 166 | 167 | //===================================== 168 | // private members 169 | //===================================== 170 | private: 171 | 172 | QByteArray m_Pass; //! Pass phrase (Password). 173 | QByteArray m_IV; //! Initialization vector. 174 | BlockSize m_eBlockSize;//! Size of the blocks. 175 | QByteArray m_Salt; //! Salt. 176 | 177 | 178 | //! checks inputs 179 | bool checkInput( void ); 180 | }; 181 | } // cryptography 182 | } // PCore 183 | 184 | 185 | //============================================================================== 186 | // typedefs 187 | //============================================================================== 188 | 189 | #if PCORE_CONFIG_USE_TYPEDEF == PCORE_ENABLE 190 | using PAES = PCore::cryptography::AES; 191 | #endif 192 | 193 | #endif // _PCORE_CRYPTO_AES_H 194 | -------------------------------------------------------------------------------- /lib/include/pcore/cryptography/des.h: -------------------------------------------------------------------------------- 1 | //############################################################################## 2 | //# title: DES 3 | //# c-date: Jun-10-2016 4 | //# author: Pouya Shahinfar (Pswin) - pswinpo@gmail.com 5 | //############################################################################## 6 | 7 | 8 | #ifndef _PCORE_CRYPTO_DES_H 9 | #define _PCORE_CRYPTO_DES_H 10 | 11 | #include "../pcore_def.h" 12 | #include 13 | class QByteArray; 14 | 15 | namespace PCore 16 | { 17 | namespace cryptography 18 | { 19 | class PCORE_API DES: public QObject 20 | { 21 | //===================================== 22 | // Metadata 23 | //===================================== 24 | 25 | Q_OBJECT 26 | Q_CLASSINFO( "author", "Pouya Shahinfar" ) 27 | Q_CLASSINFO( "version", "1.0.0" ) 28 | 29 | 30 | //===================================== 31 | // Public methods 32 | //===================================== 33 | public: 34 | 35 | /*! 36 | * \brief Constructor 37 | */ 38 | DES( QObject* _parent = nullptr ); 39 | 40 | 41 | /*! 42 | * \brief Sets pass phrase (Password) 43 | */ 44 | void setPass( const QByteArray& _pass ); 45 | 46 | 47 | /*! 48 | * \brief Returns pass phrase. 49 | */ 50 | QByteArray getPass( void ) const; 51 | 52 | 53 | /*! 54 | * \brief Sets initialization vector. 55 | */ 56 | void setIV( const QByteArray& _iv ); 57 | 58 | 59 | /*! 60 | * \brief Returns initialization. 61 | */ 62 | QByteArray getIV( void ) const; 63 | 64 | 65 | /*! 66 | * \brief Encrypts given data, and returns it. 67 | * \param _data: Data that should be encrypted. 68 | * \return Retruns encrypted data. 69 | */ 70 | QByteArray encrypt( const QByteArray& _data ); 71 | 72 | 73 | /*! 74 | * \brief Decrypts given data, and returns it. 75 | * \param _data: Data that should be decrypted. 76 | * \return Retruns decrypted data. 77 | */ 78 | QByteArray decrypt( const QByteArray& _data ); 79 | 80 | 81 | //===================================== 82 | // Static members 83 | //===================================== 84 | public: 85 | 86 | /*! 87 | * \brief Encrypts given _data by specified _pass, and returns it. 88 | * \param _pass: Pass phrase (Password). 89 | * \param _iv: Initialization vector. 90 | * \param _data: Data that should be encrypted. 91 | * \return Encrypted _data with specified password. 92 | */ 93 | static QByteArray encryptEX( const QByteArray& _pass, 94 | QByteArray& _iv, 95 | const QByteArray& _data ); 96 | 97 | 98 | /*! 99 | * \brief Decrypts given _data by specified _pass, and returns it. 100 | * \param _pass: Pass phrase (Password) 101 | * \param _iv: Initialization vector. 102 | * \param _data: Data that should be decrypted. 103 | * \return Decrypted _data with specified password. 104 | */ 105 | static QByteArray decryptEX( const QByteArray& _pass, 106 | const QByteArray& _iv, 107 | const QByteArray& _data ); 108 | 109 | 110 | //===================================== 111 | // private members 112 | //===================================== 113 | public: 114 | QByteArray m_Pass; //! Pass phrase. 115 | QByteArray m_IV; //! Initialization vector. 116 | 117 | }; // DES 118 | } // cryptography 119 | } // PCore 120 | 121 | 122 | //============================================================================== 123 | // typedefs 124 | //============================================================================== 125 | 126 | #if PCORE_CONFIG_USE_TYPEDEF == PCORE_ENABLE 127 | using PDES = PCore::cryptography::DES; 128 | #endif 129 | 130 | 131 | #endif // _PCORE_CRYPTO_DES_H 132 | -------------------------------------------------------------------------------- /lib/include/pcore/cryptography/rsa.h: -------------------------------------------------------------------------------- 1 | //############################################################################## 2 | //# title: RSA (Rivest-Shamir-Adleman) 3 | //# c-date: Jun-09-2016 4 | //# author: Pouya Shahinfar (Pswin) - pswinpo@gmail.com 5 | //############################################################################## 6 | 7 | #ifndef _PCORE_CRYPTO_RSA_H 8 | #define _PCORE_CRYPTO_RSA_H 9 | 10 | #include "../pcore_def.h" 11 | #include 12 | class QByteArray; 13 | 14 | namespace PCore 15 | { 16 | namespace cryptography 17 | { 18 | //====================================================================== 19 | // RSA Class 20 | //====================================================================== 21 | class PCORE_API Rsa : public QObject 22 | { 23 | //===================================== 24 | // Metadata 25 | //===================================== 26 | 27 | Q_OBJECT 28 | Q_CLASSINFO( "author", "Pouya Shahinfar" ) 29 | Q_CLASSINFO( "version", "1.0.0" ) 30 | 31 | 32 | //===================================== 33 | // enums 34 | //===================================== 35 | public: 36 | 37 | /*! 38 | * Paddings 39 | */ 40 | enum class Padding 41 | { 42 | PKCS1 = 1, 43 | SSL_V23 = 2, 44 | NO_PADDING = 3, 45 | PKCS1_OAEP = 4, 46 | X931 = 5 47 | }; 48 | 49 | 50 | //===================================== 51 | // Public methods 52 | //===================================== 53 | public: 54 | 55 | /*! 56 | * \brief Constructs a RSA object. 57 | * \param _generate_keys: Generates private and public keys. 58 | */ 59 | Rsa( bool _generate_keys = true, QObject* _parent = nullptr ); 60 | 61 | 62 | /*! 63 | * \brief Copy constructor. 64 | */ 65 | Rsa( const Rsa& _obj ); 66 | 67 | 68 | /*! 69 | * \brief Move constructor. 70 | */ 71 | Rsa( Rsa&& _obj ); 72 | 73 | 74 | /*! 75 | *\brief Destrcutor. 76 | */ 77 | ~Rsa( ); 78 | 79 | 80 | /*! 81 | * \brief Encrypts given byte array by using public key, and returns it. 82 | * \param _byte_array: Array that should be encrypted. 83 | * \param _padding: Padding. 84 | * \return Returns encrypted byte array by public key. 85 | */ 86 | QByteArray encrypt( const QByteArray& _byte_array, 87 | Padding _padding = Padding::PKCS1 88 | ); 89 | 90 | 91 | /*! 92 | * \brief Decrypts given byte array by using private key, and returns it. 93 | * \param _byte_array: Array that should be decrypted; 94 | * \return Returns decrypted byte array by public key. 95 | */ 96 | QByteArray decrypt( const QByteArray& _byte_array, 97 | Padding _padding = Padding::PKCS1 ); 98 | 99 | 100 | /*! 101 | * \brief Sets the public key. 102 | * \param _public_key: Public Key. 103 | */ 104 | bool setPublicKey( const QByteArray& _public_key ); 105 | 106 | 107 | /*! 108 | * \brief Returns seted public key. 109 | */ 110 | QByteArray getPublicKey( void ) const; 111 | 112 | 113 | /*! 114 | * \brief Sets the private key. 115 | * \param _public_key: Private Key. 116 | */ 117 | bool setPrivateKey( const QByteArray& _private_key ); 118 | 119 | 120 | /*! 121 | * \brief Returns seted public key. 122 | */ 123 | QByteArray getPrivateKey( void ) const; 124 | 125 | 126 | //===================================== 127 | // Static methods 128 | //===================================== 129 | public: 130 | 131 | /*! 132 | * \brief Generates a random private key, and returns it. 133 | * \param _len: Length of the key. 134 | * \return Returns generated private key. 135 | */ 136 | static QByteArray generatePrivateKey( int _len = PCORE_1KB ); 137 | 138 | /*! 139 | * \brief Generates a public key from given private key, and returns it. 140 | * \param _private_key: Input private key. 141 | * \return Returns generated public key from given private key. 142 | */ 143 | static QByteArray generatePublicKey( const QByteArray& _private_key ); 144 | 145 | 146 | //===================================== 147 | // Private members 148 | //===================================== 149 | private: 150 | 151 | QByteArray m_PublicKey; //! Public Key. 152 | QByteArray m_PrivateKey; //! Private Key. 153 | 154 | void* m_pPrvKey = nullptr; //! Pointer to private key instance. 155 | void* m_pPubKey = nullptr; //! pointer to public key instance. 156 | 157 | }; // RSA 158 | } // Cryptography 159 | } // PCore 160 | 161 | 162 | //============================================================================== 163 | // typedefs 164 | //============================================================================== 165 | 166 | #if PCORE_CONFIG_USE_TYPEDEF == PCORE_ENABLE 167 | using PRSA = PCore::cryptography::Rsa; 168 | #endif 169 | 170 | 171 | #endif // _PCORE_CRYPTO_RSA_H 172 | 173 | -------------------------------------------------------------------------------- /lib/include/pcore/def/arch.h: -------------------------------------------------------------------------------- 1 | //############################################################################## 2 | //# title: CPU Architecture 3 | //# c-date: Apr-02-2014 4 | //# author: Pouya Shahinfar (Pswin) - pswinpo@gmail.com 5 | //############################################################################## 6 | 7 | #include 8 | 9 | /* 10 | * As default useful macros provided, but for saftey and making them more 11 | * robust, Qt based macros added. 12 | */ 13 | 14 | #ifndef _PCORE_ARCH_H 15 | #define _PCORE_ARCH_H 16 | 17 | //===================================== 18 | // Arch list 19 | //===================================== 20 | 21 | #define PCORE_ARCH_X86_32 1 //! X86 22 | #define PCORE_ARCH_X86_64 3 //! X86-64 23 | #define PCORE_ARCH_ARM_32 4 //! ARM 32-bit 24 | #define PCORE_ARCH_ARM_64 4 //! ARM 64-bit 25 | #define PCORE_ARCH_UNKNOWN 99 //! Unknown architecture 26 | 27 | #define PCORE_ARCH_FAMILY_X86 1 //! All processors in X86 family 28 | #define PCORE_ARCH_FAMILY_ARM 2 //! All processors in ARM family 29 | #define PCORE_ARCH_FAMILY_UNKOWN 99 //! Unknown family 30 | 31 | //===================================== 32 | // Big endian or little endian 33 | //===================================== 34 | 35 | #define PCORE_ARCH_BIG_ENDIAN 1 36 | #define PCORE_ARCH_LITTLE_ENDIAN 2 37 | 38 | #if Q_BYTE_ORDER == Q_BIG_ENDIAN 39 | #define PCORE_ARCH_ENDIAN PCORE_ARCH_BIG_ENDIAN 40 | #else 41 | #define PCORE_ARCH_ENDIAN PCORE_ARCH_LITTLE_ENDIAN 42 | #endif 43 | 44 | //===================================== 45 | // 46 | //===================================== 47 | #if defined ( i386 ) || defined ( __i386 ) || defined ( __i386__ ) || \ 48 | defined ( __i486__ ) || defined ( __i586__ ) || defined ( __i686__ ) || \ 49 | defined ( _M_IX86 ) || defined ( _X86_ ) || defined (Q_PROCESSOR_X86_32) 50 | #define PCORE_ARCH PCORE_ARCH_I386 51 | #define PCORE_ARCH_WORD_SIZE 32 52 | #define PCORE_ARCH_FAMILY PCORE_ARCH_FAMILY_X86 53 | #elif defined ( __amd64__ ) || defined ( __amd64 ) || defined ( __x86_64__ ) ||\ 54 | defined ( __x86_64 ) || defined ( _M_X64 ) || defined ( _M_AMD64 ) || \ 55 | defined ( _M_IA64 ) || defined ( __ia64__ ) || defined ( _IA64 ) || \ 56 | defined ( __IA64__ ) || defined ( __itanium__ ) || defined ( _M_IA64 ) || \ 57 | defined ( _M_AMD64 ) || defined ( Q_PROCESSOR_X86_64 ) 58 | #define PCORE_ARCH PCORE_ARCH_X86_64 59 | #define PCORE_ARCH_WORD_SIZE 64 60 | #define PCORE_ARCH_FAMILY PCORE_ARCH_FAMILY_X86 61 | #elif defined ( __aarch64__ ) 62 | #define PCORE_ARCH PCORE_ARCH_ARM_64 63 | #define PCORE_ARCH_WORD_SIZE 64 64 | #elif defined ( __arm__ ) || defined ( __thumb__ ) || defined ( _M_ARM ) ||\ 65 | defined ( _M_ARMT ) || defined ( Q_PROCESSOR_ARM ) 66 | #define PCORE_ARCH PCORE_ARCH_ARM_32 67 | #define PCORE_ARCH_WORD_SIZE 32 68 | #define PCORE_ARCH_FAMILY PCORE_ARCH_FAMILY_ARM 69 | #else 70 | #define PCORE_ARCH PCORE_ARCH_UNKNOWN 71 | #error "Compiling PCore failed, Unknown architecture" 72 | #endif 73 | 74 | #endif // _PCORE_ARCH_H 75 | -------------------------------------------------------------------------------- /lib/include/pcore/def/compiler.h: -------------------------------------------------------------------------------- 1 | //############################################################################## 2 | //# title: Compiler detection and version 3 | //# c-date: Apr-02-2014 4 | //# author: Pouya Shahinfar (Pswin) - pswinpo@gmail.com 5 | //############################################################################## 6 | 7 | #ifndef _PCORE_COMPILER_H 8 | #define _PCORE_COMPILER_H 9 | 10 | #include 11 | 12 | #define PCORE_COMPILER_MSVC 1 // Microsoft Visual C++ 13 | #define PCORE_COMPILER_GCC 2 // GNU C/C++ compilers 14 | #define PCORE_COMPILER_INTEL 3 // Intel C/C++ compiler 15 | #define PCORE_COMPILER_UNKNOWN 99 // Unknown compiler 16 | 17 | 18 | #if defined ( __GNUC__ ) || defined ( Q_CC_GNU ) 19 | #define PCORE_COMPILER PCORE_COMPILER_GCC 20 | #elif defined ( _MSC_VER ) || defined ( Q_CC_MSVC ) 21 | #define PCORE_COMPILER PCORE_COMPILER_MSVC 22 | #elif defined ( __INTEL_COMPILER ) || defined ( Q_CC_INTEL ) 23 | #define PCORE_COMPILER PCORE_COMPILER_INTEL 24 | #else 25 | #error "Compiling PCore failed, Unknown compiler." 26 | #endif 27 | 28 | #endif // _PCORE_COMPILER_H 29 | -------------------------------------------------------------------------------- /lib/include/pcore/def/const.h: -------------------------------------------------------------------------------- 1 | //############################################################################## 2 | //# title: Constants 3 | //# c-date: Apr-02-2014 4 | //# author: Pouya Shahinfar (Pswin) - pswinpo@gmail.com 5 | //############################################################################## 6 | 7 | 8 | #ifndef _PCORE_CONST_H 9 | #define _PCORE_CONST_H 10 | 11 | //======================================= 12 | // general 13 | //======================================= 14 | 15 | #define PCORE_ENABLE ( 1 ) 16 | #define PCORE_DISABLE ( 2 ) 17 | 18 | #define PCORE_TRUE ( 1 ) 19 | #define PCORE_FALSE ( 0 ) 20 | 21 | 22 | //======================================= 23 | // bytes and sizes 24 | //======================================= 25 | 26 | #define PCORE_1KB ( 0x400 ) 27 | #define PCORE_4KB ( 0x1000 ) 28 | #define PCORE_1MB ( 0x100000 ) 29 | #define PCORE_1GB ( 0x40000000 ) 30 | #define PCORE_1TB ( 0x10000000000 ) 31 | 32 | 33 | //======================================= 34 | // Frequance 35 | //======================================= 36 | 37 | #define PCORE_1HZ ( 1 ) 38 | #define PCORE_1KHZ ( 1000 ) 39 | #define PCORE_1MHZ ( 1000000 ) 40 | #define PCORE_1GHZ ( 1000000000 ) 41 | #define PCORE_1THZ ( 1000000000000 ) 42 | 43 | #endif // _PCORE_CONST_H 44 | -------------------------------------------------------------------------------- /lib/include/pcore/def/def_gcc.h: -------------------------------------------------------------------------------- 1 | //############################################################################## 2 | //# title: macros, predefinations for gcc 3 | //# c-date: Apr-01-2014 4 | //# author: Pouya Shahinfar (Pswin) - pswinpo@gmail.com 5 | //############################################################################## 6 | 7 | #ifndef _PCORE_GCC_COMPILER_H 8 | #define _PCORE_GCC_COMPILER_H 9 | 10 | #include "../config.h" 11 | #include "arch.h" 12 | #include "compiler.h" 13 | 14 | #if PCORE_COMPILER == PCORE_COMPILER_GCC 15 | 16 | //======================================= 17 | // version info and version control 18 | //======================================= 19 | 20 | /*! converting format of version to VVRRPP 21 | V = Version 22 | R = Reversion 23 | P = Patch level 24 | */ 25 | 26 | #if defined(__GNUC_PATCHLEVEL__) 27 | #define PCORE_COMPILER_VERSION (__GNUC__ * 10000 \ 28 | + __GNUC_MINOR__ * 100 \ 29 | + __GNUC_PATCHLEVEL__) 30 | #else 31 | #define PCORE_COMPILER_VERSION (__GNUC__ * 10000 \ 32 | + __GNUC_MINOR__ * 100) 33 | #endif 34 | 35 | //! Versions 36 | #define PCORE_GCC_4_4 40400 37 | #define PCORE_GCC_4_5 40500 38 | #define PCORE_GCC_4_6 40600 39 | #define PCORE_GCC_4_7 40700 40 | #define PCORE_GCC_4_8 40800 41 | 42 | 43 | //! Checking for CPP11 (Cpp0x) support 44 | #if PCORE_COMPILER_VERSION >= PCORE_GCC_4_6 45 | #define PCORE_COMPILER_SUPPORT_CPP11_NULLPTR PCORE_TRUE 46 | #endif 47 | 48 | #if PCORE_COMPILER_VERSION >= PCORE_GCC_4_7 49 | #define PCORE_COMPILER_SUPPORT_CPP11_ALIAS PCORE_TRUE 50 | #endif 51 | 52 | /*! Version control 53 | PCORE use some C++11 (C++0x) features like as template alias that supported 54 | in g++ 4.7 55 | */ 56 | #if PCORE_COMPILER_VERSION < PCORE_GCC_4_7 57 | #error "Error: Compiling failed, PCORE at least need G++ 4.7 ." 58 | #endif 59 | 60 | //======================================= 61 | // sizes 62 | //======================================= 63 | 64 | #define PCORE_SIZE_CHAR 1 65 | #define PCORE_SIZE_SHORT 2 66 | #define PCORE_SIZE_INT 4 67 | #define PCORE_SIZE_LONG 4 68 | #define PCORE_SIZE_FLOAT 4 69 | #define PCORE_SIZE_DOUBLE 8 70 | 71 | 72 | #if PCORE_ARCH_BIT == 32 73 | #define PCORE_POINTER_SIZE 4 74 | #elif PCORE_ARCH_BIT == 64 75 | #define PCORE_POINTER_SIZE 8 76 | #endif 77 | 78 | //======================================= 79 | // type defination 80 | //======================================= 81 | 82 | /* 83 | namespace PCORE 84 | { 85 | //! type based definitions 86 | typedef unsigned char byte_t; 87 | typedef unsigned char uchar_t; 88 | typedef unsigned short ushort_t; 89 | typedef unsigned int uint_t; 90 | typedef unsigned long ulong_t; 91 | 92 | //! size based type definitions 93 | typedef unsigned char u8_t; 94 | typedef unsigned short u16_t; 95 | typedef unsigned int u32_t; 96 | typedef unsigned long long u64_t; 97 | 98 | typedef unsigned char s8_t; 99 | typedef unsigned short s16_t; 100 | typedef unsigned int s32_t; 101 | typedef unsigned long long s64_t; 102 | 103 | //! pointers 104 | typedef void* ptr_t; 105 | 106 | #if PCORE_POINTER_SIZE == 8 107 | typedef unsigned long long size_t; 108 | #else 109 | typedef unsigned int size_t; 110 | #endif 111 | 112 | } // Pcore 113 | */ 114 | 115 | //======================================= 116 | // macros 117 | //======================================= 118 | 119 | #define PCORE_INLINE inline //! inline function 120 | #define PCORE_FORCE_INLINE __inline __attribute__ ((always_inline)) //! force to inline 121 | #define PCORE_NO_INLINE __attribute__ ((noinline)) //! 122 | #define PCORE_NAKED_FUNC void __attribute__ ((naked)) //! naked function ( without epilouge and prologue ) 123 | 124 | #if PCORE_CONFIG_SIMD == PCORE_ENABLE 125 | #define PCORE_ALIGN __attribute__ ((aligned (16))) 126 | #else 127 | #define PCORE_ALIGN 128 | #endif 129 | 130 | 131 | //======================================= 132 | // DLL import export 133 | //======================================= 134 | 135 | #ifdef PCORE_EXPORT 136 | //#define PCORE_API __attribute__ ((visibility("default"))) PCORE_ALIGN 137 | #define PCORE_API Q_DECL_EXPORT 138 | #else 139 | //#define PCORE_API __attribute__ ((visibility("default"))) PCORE_ALIGN 140 | #define PCORE_API Q_DECL_IMPORT 141 | #endif 142 | 143 | #endif // PCORE_COMPILER == PCORE_COMPILER_GCC 144 | #endif // _PCORE_GCC_COMPILER_H 145 | -------------------------------------------------------------------------------- /lib/include/pcore/def/def_msvc.h: -------------------------------------------------------------------------------- 1 | //############################################################################## 2 | //# title: macros, predefinitions 3 | //# c-date: Jan-01-2014 4 | //# author: Pouya Shahinfar (Pswin) - pswinpo@gmail.com 5 | //############################################################################## 6 | 7 | #ifndef _PCORE_MSVC_COMPILER_H 8 | #define _PCORE_MSVC_COMPILER_H 9 | 10 | #include "../config.h" 11 | #include "arch.h" 12 | #include "compiler.h" 13 | 14 | #if PCORE_COMPILER == PCORE_COMPILER_MSVC 15 | 16 | //======================================= 17 | // disabling libc 18 | //======================================= 19 | 20 | #if PCORE_CONFIG_MEM_OVERRID_NEW_DELETE == PCORE_ENABLE 21 | #pragma comment(linker, "/nodefaultlib:libc.lib") 22 | #pragma comment(linker, "/nodefaultlib:libcd.lib") 23 | #endif 24 | 25 | //======================================= 26 | // version info and version control 27 | //======================================= 28 | 29 | // version names 30 | #define PCORE_MSVC_VER_1 800 31 | #define PCORE_MSVC_VER_3 900 32 | #define PCORE_MSVC_VER_4 1000 33 | #define PCORE_MSVC_VER_4_2 1020 34 | #define PCORE_MSVC_VER_5 1100 35 | #define PCORE_MSVC_VER_6 1200 36 | #define PCORE_MSVC_VER_7 1300 37 | #define PCORE_MSVC_VER_7_1 1310 //! 2003 38 | #define PCORE_MSVC_VER_8 1400 //! 2005 39 | #define PCORE_MSVC_VER_9 1500 //! 2008 40 | #define PCORE_MSVC_VER_10 1600 //! 2010 41 | #define PCORE_MSVC_VER_11 1700 //! 2012 42 | #define PCORE_MSVC_VER_12 1800 //! 2013 43 | #define PCORE_MSVC_VER_14 1900 //! 2015 44 | 45 | #define PCORE_MSVC_VER_2003 PCORE_MSVC_VER_7_1 46 | #define PCORE_MSVC_VER_2005 PCORE_MSVC_VER_8 47 | #define PCORE_MSVC_VER_2008 PCORE_MSVC_VER_9 48 | #define PCORE_MSVC_VER_2010 PCORE_MSVC_VER_10 49 | #define PCORE_MSVC_VER_2012 PCORE_MSVC_VER_11 50 | #define PCORE_MSVC_VER_2013 PCORE_MSVC_VER_12 51 | #define PCORE_MSVC_VER_2015 PCORE_MSVC_VER_14 52 | 53 | //! compiler version 54 | #define PCORE_COMPILER_VERSION _MSC_VER 55 | 56 | #if PCORE_COMPILER_VERSION < PCORE_MSVC_VER_2013 57 | #error "compiling PCORE failed, PCORE at least need Microsoft Visual studio 2012 for compiling" 58 | #endif 59 | 60 | #if PCORE_COMPILER_VERSION >= PCORE_MSVC_VER_2013 61 | #define PCORE_COMPILER_SUPPORT_CPP11_ALIAS PCORE_ENABLE 62 | #endif 63 | 64 | //======================================= 65 | // sizes 66 | //======================================= 67 | 68 | #define PCORE_SIZE_CHAR 1 69 | #define PCORE_SIZE_SHORT 2 70 | #define PCORE_SIZE_INT 4 71 | #define PCORE_SIZE_LONG 4 72 | #define PCORE_SIZE_FLOAT 4 73 | #define PCORE_SIZE_DOUBLE 8 74 | 75 | 76 | #if PCORE_ARCH_WORD_SIZE == 32 77 | #define PCORE_SIZE_POINTER 4 78 | #elif PCORE_ARCH_WORD_SIZE == 64 79 | #define PCORE_SIZE_POINTER 8 80 | #endif 81 | 82 | //======================================= 83 | // type definition 84 | //======================================= 85 | /* 86 | namespace PCORE 87 | { 88 | //! type based definitions 89 | typedef unsigned char byte_t; 90 | typedef unsigned char uchar_t; 91 | typedef unsigned short ushort_t; 92 | typedef unsigned int uint_t; 93 | typedef unsigned long ulong_t; 94 | 95 | //! size based type definitions 96 | typedef unsigned __int8 u8_t; 97 | typedef unsigned __int16 u16_t; 98 | typedef unsigned __int32 u32_t; 99 | typedef unsigned __int64 u64_t; 100 | 101 | typedef unsigned __int8 s8_t; 102 | typedef unsigned __int16 s16_t; 103 | typedef unsigned __int32 s32_t; 104 | typedef unsigned __int64 s64_t; 105 | 106 | //! pointers 107 | typedef void* ptr_t; 108 | 109 | #if PCORE_SIZE_POINTER == 8 110 | typedef u64_t size_t; 111 | #else 112 | typedef u32_t size_t; 113 | #endif 114 | 115 | } // Pcore 116 | */ 117 | 118 | //======================================= 119 | // warnings 120 | //======================================= 121 | 122 | #if PCORE_CONFIG_WARNINGS == PCORE_DISABLE 123 | #pragma warning(disable : 4049) 124 | #pragma warning(disable : 4996) // _CRT_SECURE_NO_WARNING 125 | #pragma warning(disable : 4244) // conversion to float, possible loss of data 126 | #pragma warning(disable : 4699) // creating precompiled header 127 | #pragma warning(disable : 4200) // Zero-length array item at end of structure, a VC-specific extension 128 | #pragma warning(disable : 4100) // unreferenced formal parameter 129 | #pragma warning(disable : 4514) // unreferenced inline function has been removed 130 | #pragma warning(disable : 4201) // nonstandard extension used : nameless struct/union 131 | #pragma warning(disable : 4710) // inline function not expanded 132 | #pragma warning(disable : 4714) // __forceinline function not expanded 133 | #pragma warning(disable : 4702) // unreachable code in inline expanded function 134 | #pragma warning(disable : 4711) // function selected for automatic inlining 135 | #pragma warning(disable : 4127) // Conditional expression is constant 136 | #pragma warning(disable : 4512) // assignment operator could not be generated 137 | #pragma warning(disable : 4245) // conversion from 'enum ' to 'unsigned long', signed/unsigned mismatch 138 | #pragma warning(disable : 4389) // signed/unsigned mismatch 139 | #pragma warning(disable : 4251) // needs to have dll-interface to be used by clients of class 140 | #pragma warning(disable : 4275) // non dll-interface class used as base for dll-interface class 141 | #pragma warning(disable : 4511) // copy constructor could not be generated 142 | #pragma warning(disable : 4284) // return type is not a UDT or reference to a UDT 143 | #pragma warning(disable : 4355) // this used in base initializer list 144 | #pragma warning(disable : 4291) // typedef-name '' used as synonym for class-name '' 145 | #pragma warning(disable : 4324) // structure was padded due to __declspec(align()) 146 | #pragma warning(disable : 4996) // 'function': was declared deprecated 147 | #pragma warning(disable : 4800) // 'function': was declared deprecated 148 | #endif 149 | 150 | 151 | //======================================= 152 | // macros 153 | //======================================= 154 | 155 | #define PCORE_INLINE inline //! inline function 156 | #define PCORE_FORCE_INLINE __forceinline //! force to inline 157 | #define PCORE_NO_INLINE __declspec(noinline) //! 158 | #define PCORE_NAKED_FUNC void _declspec(naked) //! naked function ( without epilouge and prologue ) 159 | 160 | #if PCORE_CONFIG_SIMD == PCORE_ENABLE 161 | #define PCORE_ALIGN __declspec(align(16)) 162 | #else 163 | #define PCORE_ALIGN 164 | #endif 165 | 166 | 167 | //======================================= 168 | // DLL import export 169 | //======================================= 170 | 171 | #ifdef PCORE_EXPORT 172 | //#define PCORE_API __declspec( dllexport ) 173 | #define PCORE_API Q_DECL_EXPORT 174 | #else 175 | // #define PCORE_API __declspec( dllimport ) 176 | #define PCORE_API Q_DECL_IMPORT 177 | #endif 178 | 179 | #endif // PCORE_COMPILER == PCORE_COMPILER_MSVC 180 | #endif // _PCORE_MSVC_COMPILER_H 181 | -------------------------------------------------------------------------------- /lib/include/pcore/def/limits.h: -------------------------------------------------------------------------------- 1 | //############################################################################## 2 | //# title: limits 3 | //# c-date: Oct-19-2014 4 | //# author: Pouya Shahinfar (Pswin) - pswinpo@gmail.com 5 | //############################################################################## 6 | 7 | 8 | #ifndef _PCORE_LIMITS_H 9 | #define _PCORE_LIMITS_H 10 | 11 | #include 12 | 13 | //===================================== 14 | // constants 15 | //===================================== 16 | 17 | //! numerical types 18 | #define PCORE_UINT_MAX ( UINT_MAX ) //! maximum unsigned int 19 | #define PCORE_UINT_MIN ( 0x0 ) //! minimum unsigned int 20 | #define PCORE_INT_MAX ( INT_MAX ) //! maximum singed int 21 | #define PCORE_INT_MIN ( INT_MIN ) //! minimum signed int 22 | #define PCORE_USHORT_MAX ( USHRT_MAX ) //! maximum unsigned short 23 | #define PCORE_USHORT_MIN ( 0x0 ) //! minimum unsigned short 24 | #define PCORE_SHORT_MAX ( SHRT_MAX ) //! maximum signed short 25 | #define PCORE_SHORT_MIN ( SHRT_MIN ) //! minimum signed int 26 | #define PCORE_ULONG_MAX ( ULONG_MAX ) //! maximum unsigned long 27 | #define PCORE_ULONG_MIN ( 0x0 ) //! minimum unsigned long 28 | #define PCORE_LONG_MAX ( LONG_MAX ) //! maximum signed long 29 | #define PCORE_LONG_MIN ( LONG_MIN ) //! minimum signed long 30 | #define PCORE_U_LONG_LONG_MAX ( ULLONG_MAX ) //! maximum unsigned long long 31 | #define PCORE_U_LONG_LONG_MIN ( 0x0 ) //! minimum unsigned long long 32 | #define PCORE_LONG_LONG_MAX ( LLONG_MAX ) //! maximum signed long long 33 | #define PCORE_LONG_LONG_MIN ( LLONG_MIN ) //! minimum signed long long 34 | 35 | //! bitwise types 36 | #define PCORE_U64_MAX ( 0xffffffffffffffff ) 37 | #define PCORE_U32_MAX ( 0xffffffff ) 38 | #define PCORE_U16_MAX ( 0xffff ) 39 | #define PCORE_U8_MAX ( 0xff ) 40 | 41 | 42 | #endif // _PCORE_LIMITS_H 43 | -------------------------------------------------------------------------------- /lib/include/pcore/def/os.h: -------------------------------------------------------------------------------- 1 | //############################################################################## 2 | //# title: CPU Architecture 3 | //# c-date: Apr-02-2014 4 | //# author: Pouya Shahinfar (Pswin) - pswinpo@gmail.com 5 | //############################################################################## 6 | 7 | #ifndef _PCORE_OS_H 8 | #define _PCORE_OS_H 9 | 10 | #include 11 | 12 | //===================================== 13 | // OS list 14 | //===================================== 15 | 16 | #define PCORE_OS_WINDOWS 1 //! Microsoft Windows 17 | #define PCORE_OS_LINUX 2 //! Linux 18 | #define PCORE_OS_MAC 3 //! OS X 19 | #define PCORE_OS_UNKNOWN 99 //! Unknown OS 20 | 21 | 22 | //===================================== 23 | // detection 24 | //===================================== 25 | 26 | #if defined ( _WIN32 ) || defined ( _WIN64 ) || defined ( __WIN32__ ) || \ 27 | defined ( Q_OS_WIN ) 28 | #define PCORE_OS PCORE_OS_WINDOWS 29 | #elif defined ( __linux__ ) || defined ( __gnu_linux__ ) ||\ 30 | defined ( Q_OS_LINUX) 31 | #define PCORE_OS PCORE_OS_LINUX 32 | #elif defined( __APPLE__ ) && defined( __MACH__ ) || defined( Q_OS_OSX ) 33 | #define PCORE_OS PCORE_OS_MAC 34 | #else 35 | #define PCORE_OS PCORE_OS_UNKNOWN 36 | #error "Compiling Pcore failed, Unknown OS" 37 | #endif 38 | 39 | #endif // _PCORE_OS_H 40 | -------------------------------------------------------------------------------- /lib/include/pcore/globalization/date_parser.h: -------------------------------------------------------------------------------- 1 | //############################################################################# 2 | //# title: This class is for parsing a string date using given format 3 | //# c-date: May-27-2016 4 | //# author: Pouya Shahinfar (Pswin) - pswinpo@gmail.com 5 | //############################################################################# 6 | 7 | #ifndef _PCORE_DATE_PARSER_H 8 | #define _PCORE_DATE_PARSER_H 9 | 10 | 11 | //============================================================================== 12 | // Include 13 | //============================================================================== 14 | 15 | #include "../pcore_def.h" 16 | #include 17 | #include 18 | #include 19 | 20 | 21 | //============================================================================== 22 | // DateParser 23 | //============================================================================== 24 | 25 | namespace PCore 26 | { 27 | namespace globalization 28 | { 29 | class PCORE_API DateParser 30 | { 31 | //===================================== 32 | // public structs 33 | //===================================== 34 | public: 35 | 36 | //! date 37 | struct Date 38 | { 39 | int year = 0; 40 | int month = 0; 41 | int day = 0; 42 | int week_day= 0; 43 | bool valid = false; 44 | }; 45 | 46 | 47 | //===================================== 48 | // public methods 49 | //===================================== 50 | public: 51 | 52 | //! default constructor 53 | DateParser( ){} 54 | 55 | /*! 56 | * \brief Constructor. 57 | * \param _lang: Language. 58 | * \param _country: Countery. 59 | * \param _script: Script. 60 | */ 61 | DateParser( QLocale::Language _lang, 62 | QLocale::Country _country = QLocale::AnyCountry, 63 | QLocale::Script _script = QLocale::AnyScript 64 | ); 65 | 66 | 67 | /*! 68 | * \brief Sets format of the date. 69 | */ 70 | void setFormat( const QString& _format ); 71 | 72 | 73 | /*! 74 | * \brief Sets input and out put format for parsing. 75 | * \param _lang: Language 76 | * \param _country: Country 77 | * \param _script: Script 78 | */ 79 | void setLocale( QLocale::Language _lang, 80 | QLocale::Country _country = QLocale::AnyCountry, 81 | QLocale::Script _script = QLocale::AnyScript 82 | ); 83 | 84 | 85 | /*! 86 | * \brief Returns the format of the date. 87 | */ 88 | QString format( void ) const { return m_sFormat; } 89 | QString getFormat( void ) const { return m_sFormat; } 90 | 91 | 92 | /*! 93 | * \brief Parse the given date in string, and return it. 94 | */ 95 | DateParser::Date parseFromString( const QString& _date ); 96 | 97 | 98 | /*! 99 | * \brief Converts given date to a string. 100 | * \param _year: Year. 101 | * \param _month: Month. 102 | * \param _day: Day. 103 | * \param _day_of_week: day number in the week 104 | * \return 105 | */ 106 | QString toString( int _year, int _month, int _day , int _day_of_week ); 107 | 108 | 109 | //===================================== 110 | // private classes 111 | //===================================== 112 | public: 113 | 114 | class Node 115 | { 116 | //----------------- 117 | // public enums 118 | //----------------- 119 | public: 120 | 121 | /*! 122 | * \brief Type of the node 123 | */ 124 | enum Type 125 | { 126 | //! year 127 | Year = 0, 128 | YearLong = 1, 129 | //! month 130 | Month = 2, 131 | MonthLeadingZero = 3, 132 | MonthNameAbbreviated= 4, 133 | MonthNameFull = 5, 134 | //! Day 135 | Day = 6, 136 | DayLeadingZero = 7, 137 | DayNameAbbreviated = 8, 138 | DayNameFull = 9, 139 | //! sperator 140 | Sperator 141 | }; // Type 142 | 143 | 144 | //----------------- 145 | // public methods 146 | //----------------- 147 | public: 148 | 149 | /*! 150 | * \brief Default constructor 151 | */ 152 | Node( ) {} 153 | 154 | 155 | /*! 156 | * \brief Constructor 157 | * \param Type of the node. 158 | * \param _value Value of the node 159 | */ 160 | Node( Node::Type _type, 161 | const QString& _value = nullptr ); 162 | 163 | 164 | /*! 165 | * \brief Sets node's type. 166 | * \param _type Type of the node 167 | */ 168 | void setType( Node::Type _type ){ m_eType = _type; } 169 | 170 | 171 | /*! 172 | * \brief Sets value of the node. 173 | * \param _str: Value in string. 174 | */ 175 | void setValue( const QString& _str ) { m_sValue = _str; } 176 | 177 | 178 | /*! 179 | * \brief Returns type of the node 180 | */ 181 | Node::Type getType( void ) const { return m_eType; } 182 | Node::Type type( void ) const { return m_eType; } 183 | 184 | 185 | /*! 186 | * \brief Retuns value of the node. 187 | */ 188 | QString value( void ) const { return m_sValue; } 189 | QString getValue( void ) const { return m_sValue; } 190 | 191 | 192 | //----------------- 193 | // private members 194 | //----------------- 195 | private: 196 | QString m_sValue; //! Value in String 197 | Type m_eType; //! Type of node 198 | }; 199 | 200 | //===================================== 201 | // private members 202 | //===================================== 203 | private: 204 | 205 | //! format of date 206 | QString m_sFormat; 207 | 208 | //! a list of node 209 | QList m_Nodes; 210 | 211 | //! Local information 212 | QLocale::Language m_eLanguage = QLocale::AnyLanguage; 213 | QLocale::Country m_eCountry = QLocale::AnyCountry; 214 | QLocale::Script m_eScript = QLocale::AnyScript; 215 | }; 216 | } // globalization 217 | } // PCore 218 | 219 | 220 | //============================================================================== 221 | // typedefs 222 | //============================================================================== 223 | 224 | #if PCORE_CONFIG_USE_TYPEDEF == PCORE_ENABLE 225 | using PDateParser = PCore::globalization::DateParser; 226 | #endif 227 | 228 | 229 | #endif // _PCORE_DATE_PARSER_H 230 | -------------------------------------------------------------------------------- /lib/include/pcore/globalization/locale.h: -------------------------------------------------------------------------------- 1 | //############################################################################## 2 | //# title: This is a helper class for localization 3 | //# c-date: Jun-04-2016 4 | //# author: Pouya Shahinfar (Pswin) - pswinpo@gmail.com 5 | //############################################################################## 6 | 7 | 8 | #ifndef _PCORE_LOCAL_INFO_H 9 | #define _PCORE_LOCAL_INFO_H 10 | 11 | 12 | //============================================================================== 13 | // Include 14 | //============================================================================== 15 | 16 | #include "../pcore_def.h" 17 | #include 18 | 19 | /* 20 | * Development of this class is postponed to the future 21 | */ 22 | 23 | class QString; 24 | class QStringList; 25 | 26 | 27 | //============================================================================== 28 | // LocalInfo 29 | //============================================================================== 30 | 31 | namespace PCore 32 | { 33 | namespace globalization 34 | { 35 | class PCORE_API Locale 36 | { 37 | 38 | //================================================================== 39 | // Country 40 | //================================================================== 41 | public: 42 | class PCORE_API Country 43 | { 44 | public: 45 | 46 | /*! 47 | * \brief Returns name of the country 48 | */ 49 | QString getName( void ) const; 50 | QString name( void ) const; 51 | 52 | 53 | /*! 54 | * \brief Returns native name of the country 55 | */ 56 | QString getNativeName( void ) const; 57 | QString nativeName( void ) const; 58 | 59 | 60 | /*! 61 | * \brief Returns calendar system of the country. 62 | */ 63 | QString getCalendarSystem( void ) const; 64 | QString calendarSystem( void ) const; 65 | 66 | 67 | /*! 68 | * \brief Returns a list of country's languages 69 | */ 70 | QStringList getLanguages( void ) const; 71 | QStringList languages( void ) const; 72 | 73 | 74 | /*! 75 | * \brief Returns a list of country's currencies. 76 | */ 77 | QStringList getCurrencies( void ) const; 78 | QStringList currencies( void ) const; 79 | 80 | 81 | /*! 82 | * \brief Returns nationality of the country. 83 | */ 84 | QString getNationality( void ) const; 85 | QString nationality( void ) const; 86 | 87 | 88 | /*! 89 | * \brief Returns ISO 3166-1 alpha-2 code of the country. 90 | */ 91 | QString getAlpha2Code( void ) const; 92 | QString alpha2Code( void ) const; 93 | 94 | 95 | /*! 96 | * \brief Returns ISO 3166-1 alpha-3 code of the country. 97 | */ 98 | QString getAlpha3Code( void ) const; 99 | QString alpha3Code( void ) const; 100 | 101 | 102 | private: 103 | //! Alpha 3 based code 104 | QString m_Alpha3Code; 105 | 106 | }; // country 107 | 108 | 109 | 110 | //================================================================== 111 | // Calendar 112 | //================================================================== 113 | public: 114 | class PCORE_API Calendar 115 | { 116 | public: 117 | 118 | /*! 119 | * \brief Type of calendars 120 | */ 121 | enum class Type 122 | { 123 | PersianIran = 0, //! Iranian calendar (Jalali). 124 | PersianAfghanistan = 1, //! Afghanistan's calendar. 125 | Hijri = 2, //! Hijri Calendar. 126 | Gregorian = 3, //! Gregorian 127 | Invalid = -1 128 | }; 129 | 130 | 131 | /*! 132 | * \brief Days of week 133 | */ 134 | enum class Day 135 | { 136 | Saturday = 0, 137 | Sunday = 1, 138 | Monday = 2, 139 | Tuesday = 3, 140 | Wednesday = 4, 141 | Thursday = 5, 142 | Friday = 6 143 | }; 144 | 145 | 146 | public: 147 | 148 | /*! 149 | * \brief Constructs a calendar object by specified type. 150 | * \param _type 151 | */ 152 | explicit Calendar( Type _type ); 153 | 154 | 155 | /*! 156 | * \brief Constructs a calendar object by specified type. 157 | * \param _type 158 | */ 159 | explicit Calendar( ); 160 | 161 | 162 | /*! 163 | * \brief Returns name of the country 164 | */ 165 | QString getName( void ) const; 166 | QString name( void ) const; 167 | 168 | 169 | /*! 170 | * \brief Returns native name of the country 171 | */ 172 | QString getNativeName( void ) const; 173 | QString nativeName( void ) const; 174 | 175 | 176 | /*! 177 | * \brief Returns day name in English from given day number. 178 | * \param _day: Day number. 179 | */ 180 | QString getDayName( int _day ) const; 181 | QString dayName( int _day ) const; 182 | 183 | 184 | /*! 185 | * \brief Returns short from of the day name in English. 186 | * \param _day: Day number. 187 | */ 188 | QString getDayNameShort( int _day ) const; 189 | QString dayNameShort( int _day ) const; 190 | 191 | 192 | /*! 193 | * \brief Returns short from of the day name in native language 194 | * \param _day: Day number. 195 | */ 196 | QString getDayNameShortNative( int _day ) const; 197 | QString dayNameShortNative( int _day ) const; 198 | 199 | 200 | /*! 201 | * \brief Returns day name in native language from given day number. 202 | * \param _day: Day number. 203 | */ 204 | QString getDayNameNative( int _day ) const; 205 | QString dayNameNative( int _day ) const; 206 | 207 | 208 | /*! 209 | * \brief Returns month name in english from given month number. 210 | * \param _month: month number. 211 | */ 212 | QString getMonthName( int _month ) const; 213 | QString monthName( int _month ) const; 214 | 215 | 216 | /*! 217 | * \brief Returns month name in native language from given month number. 218 | * \param _month: month number. 219 | */ 220 | QString getMonthNameNative( int _month ) const; 221 | QString monthNameNative( int _month ) const; 222 | 223 | 224 | /*! 225 | * \brief Returns month name in short format by given month 226 | * number in english language. 227 | * \param _month: month number. 228 | */ 229 | QString getMonthNameShort( int _month ) const; 230 | QString monthNameShort( int _month ) const; 231 | 232 | 233 | /*! 234 | * \brief Returns month name in short format by given month 235 | * number in native language. 236 | * \param _month: month number. 237 | */ 238 | QString getMonthNameShortNative( int _month ) const; 239 | QString monthNameShortNative( int _month ) const; 240 | 241 | 242 | /*! 243 | * \brief Returns day number by its name, or returns -1 in case 244 | * failure. 245 | * \param _name: name of the day. 246 | */ 247 | int getDayNumberByName( const QString& _name ) const; 248 | int dayNumberByName( const QString& _name ) const ; 249 | 250 | 251 | /*! 252 | * \brief Returns month number by its name, or returns -1 in case 253 | * failure. 254 | * \param _name: name of the month. 255 | */ 256 | int getMonthNumberByName( const QString& _name ) const; 257 | int monthNumberByName( const QString& _name ) const; 258 | 259 | 260 | /*! 261 | * \brief Returns start day of the week 262 | */ 263 | Calendar::Day getStartDay( void ) const; 264 | Calendar::Day startDay( void ) const; 265 | 266 | 267 | /*! 268 | * \brief Returns type of the calendar. 269 | */ 270 | Type getType( void ) const { return m_eType; } 271 | Type type( void ) const { return m_eType; } 272 | 273 | 274 | /*! 275 | * \brief Sets calendar type. 276 | */ 277 | void setType( Calendar::Type _type ){ m_eType = _type; } 278 | 279 | 280 | private: 281 | //! Type of the calendar 282 | Calendar::Type m_eType = Type::Invalid; 283 | 284 | }; // calendar 285 | 286 | 287 | //================================================================== 288 | // static mthods 289 | //================================================================== 290 | public: 291 | 292 | /*! 293 | * \brief Initialize local information. 294 | */ 295 | static bool init( void ); 296 | 297 | 298 | /*! 299 | * \brief Release allocated memory and resources 300 | */ 301 | static bool shutdown( void ); 302 | 303 | 304 | /*! 305 | * \brief Returns specified contry by its alpha-2 code 306 | * \param _code: ISO 3166-1 alpha-2 code. 307 | */ 308 | static Country getContryByAlpha2Code( const QString& _code ); 309 | 310 | 311 | /*! 312 | * \brief Returns calndar by its name 313 | * \param _type 314 | */ 315 | static Calendar getCalendar( Calendar::Type _type ); 316 | 317 | }; 318 | } // globalization 319 | } // PCore 320 | 321 | 322 | //============================================================================== 323 | // typedefs 324 | //============================================================================== 325 | 326 | #if PCORE_CONFIG_USE_TYPEDEF == PCORE_ENABLE 327 | using PLocale = PCore::globalization::Locale; 328 | #endif 329 | 330 | #endif // _PCORE_LOCAL_INFO_H 331 | -------------------------------------------------------------------------------- /lib/include/pcore/globals.h: -------------------------------------------------------------------------------- 1 | //############################################################################## 2 | //# title: Global variables 3 | //# c-date: Feb-28-2016 4 | //# author: Pouya Shahinfar (Pswin) - pswinpo@gmail.com 5 | //############################################################################## 6 | 7 | /* 8 | * Diffrent frameworks use diffrent approaches for accessing singleton classes. 9 | * Although, At first sight, using things such as singleton design pattern 10 | * might look convenient, yet in PCore global variables are used. We suppose 11 | * Since in the singlton design pattern for every access to the class's instace 12 | * a static mthod is called, the performace of application tend to be decreased. 13 | * Therefore, using global varibales would be more appropriate. 14 | * 15 | * Almost all of the this varibales are initialized in Root::init. Hence this 16 | * method should be called before using other classes of PCore; Otherwise, your 17 | * application are likely to crash. 18 | */ 19 | 20 | #ifndef _PCORE_GLOBALS 21 | #define _PCORE_GLOBALS 22 | 23 | #include "pcore_def.h" 24 | 25 | namespace PCore 26 | { 27 | namespace core 28 | { 29 | class Logger; 30 | class ProfileManager; 31 | } // Logger 32 | 33 | class Root; 34 | } // PCore 35 | 36 | class QByteArray; 37 | 38 | 39 | //===================================== 40 | // Global variables 41 | //===================================== 42 | 43 | PCORE_EXTERN( PCore::core::Logger*, pLogger ) 44 | PCORE_EXTERN( PCore::core::ProfileManager*, pProfileManager ) 45 | PCORE_EXTERN( PCore::Root*, pRoot ) 46 | 47 | 48 | //===================================== 49 | // static variables 50 | //===================================== 51 | 52 | PCORE_EXTERN( QByteArray, NullQByteArray ) 53 | 54 | #endif // _PCORE_GLOBALS 55 | 56 | -------------------------------------------------------------------------------- /lib/include/pcore/math/random.h: -------------------------------------------------------------------------------- 1 | //############################################################################## 2 | //# title: Random number of data generation 3 | //# c-date: Jun-10-2016 4 | //# author: Pouya Shahinfar (Pswin) - pswinpo@gmail.com 5 | //############################################################################## 6 | 7 | #ifndef _PCORE_MATH_RANDOM_H 8 | #define _PCORE_MATH_RANDOM_H 9 | 10 | #include "../pcore_def.h" 11 | class QByteArray; 12 | 13 | namespace PCore 14 | { 15 | namespace math 16 | { 17 | class PCORE_API Random 18 | { 19 | //===================================== 20 | // Static members 21 | //===================================== 22 | public: 23 | 24 | /*! 25 | * \brief Generates an array of random bytes in given size. 26 | * \param _size: Size of array. 27 | * \return An array of random bytes in given size. 28 | */ 29 | static QByteArray randomByteArray( quint32 _size ); 30 | }; 31 | } // math 32 | } // PCore 33 | 34 | 35 | //============================================================================== 36 | // typedefs 37 | //============================================================================== 38 | 39 | #if PCORE_CONFIG_USE_TYPEDEF == PCORE_ENABLE 40 | using PRandom = PCore::math::Random; 41 | #endif 42 | 43 | #endif // _PCORE_MATH_RANDOM_H 44 | -------------------------------------------------------------------------------- /lib/include/pcore/pcore.h: -------------------------------------------------------------------------------- 1 | //############################################################################## 2 | //# PCore 3 | //# Written by: Pouya Shahinfar (Pswin) 4 | //# http://www.pswin.ir 5 | //############################################################################## 6 | 7 | /* 8 | * PCore is a library for creating applications based on Qt framework and 9 | * PS-Technologies. This library include several class for faciliating 10 | * application development, and creating an integrate interface for application 11 | * that are developed by Pouya Shahinfar (Pswin). 12 | */ 13 | #ifndef _PCORE_H 14 | #define _PCORE_H 15 | 16 | 17 | //===================================== 18 | // root 19 | //===================================== 20 | 21 | #include "root.h" 22 | 23 | 24 | //===================================== 25 | // core 26 | //===================================== 27 | 28 | #include "core/logger.h" 29 | #include "core/profiler.h" 30 | #include "core/exception.h" 31 | #include "core/compressor.h" 32 | #include "core/system_information.h" 33 | #include "core/hr.h" 34 | 35 | 36 | //===================================== 37 | // cahce framework 38 | //===================================== 39 | 40 | #include "core/cachefx/lru_cache.h" 41 | 42 | 43 | //===================================== 44 | // globalization 45 | //===================================== 46 | 47 | #include "globalization/locale.h" 48 | #include "globalization/date_parser.h" 49 | #include "globalization/persian_calendar.h" 50 | #include "globalization/hijri_calendar.h" 51 | 52 | 53 | //===================================== 54 | // cryptography 55 | //===================================== 56 | 57 | #include "cryptography/rsa.h" 58 | #include "cryptography/aes.h" 59 | #include "cryptography/des.h" 60 | 61 | 62 | //===================================== 63 | // math 64 | //===================================== 65 | 66 | #include "math/random.h" 67 | 68 | 69 | 70 | #endif // _PCORE_H 71 | -------------------------------------------------------------------------------- /lib/include/pcore/pcore_def.h: -------------------------------------------------------------------------------- 1 | //############################################################################## 2 | //# title: macros, predefinitions 3 | //# c-date: Jan-01-2014 4 | //# author: Pouya Shahinfar (Pswin) - pswinpo@gmail.com 5 | //############################################################################## 6 | 7 | 8 | #ifndef _PCORE_DEF_H 9 | #define _PCORE_DEF_H 10 | 11 | //======================================== 12 | // includes 13 | //======================================== 14 | 15 | #include "config.h" 16 | #include "def/const.h" 17 | #include "def/compiler.h" 18 | #include "def/arch.h" 19 | #include "def/os.h" 20 | #include "def/limits.h" 21 | 22 | 23 | //======================================== 24 | // Version Information 25 | //======================================== 26 | 27 | #define PCORE_VERSION_MAJOR 1 28 | #define PCORE_VERSION_MINOR 0 29 | #define PCORE_VERSION_PATCH 0 30 | #define PCORE_VERSION_SUFFIX "" 31 | #define PCORE_VERSION_NAME "1.0.0" 32 | 33 | #define PCORE_VERSION ((PCORE_VERSION_MAJOR << 16) | \ 34 | (PCORE_VERSION_MINOR << 8) | PCORE_VERSION_PATCH) 35 | 36 | 37 | //======================================== 38 | // Compiler specific include 39 | //======================================== 40 | 41 | #if PCORE_COMPILER == PCORE_COMPILER_MSVC 42 | #include "def/def_msvc.h" 43 | #elif PCORE_COMPILER == PCORE_COMPILER_GCC 44 | #include "def/def_gcc.h" 45 | #elif PCORE_COMPILER == PCORE_COMPILER_INTEL 46 | #include "def/def_intel.h" 47 | #else 48 | #error "asasas" 49 | #endif 50 | 51 | 52 | //========================================== 53 | // macros 54 | //========================================== 55 | 56 | #if defined ( _DEBUG ) || defined ( DEBUG ) || defined ( PCORE_DEBUG ) 57 | #define PCORE_DEBUG_MODE PCORE_ENABLE 58 | #else 59 | #define PCORE_DEBUG_MODE PCORE_DISABLE 60 | #endif 61 | 62 | // string convector for constants 63 | #define PCORE_CHAR_STRING(__str) #__str 64 | 65 | // line number and file name 66 | #define PCORE_LINE_NUMBER __LINE__ 67 | #define PCORE_LINE_NUMBER_STR QString ( PCORE_CHAR_STRING( __LINE__ ) ) 68 | #define PCORE_FILE_NAME QString( __FILE__ ) 69 | #define PCORE_FUNC_NAME QString( __FUNCTION__ ) 70 | 71 | // extern 72 | #define PCORE_EXTERN( __type, __var ) extern "C" { PCORE_API extern __type __var; } 73 | 74 | // noop 75 | #define PCORE_NOOP(__assert_expr) 76 | 77 | // new line 78 | #define PCORE_NEW_LINE "\r\n" 79 | 80 | #endif // _PCORE_DEF_H 81 | -------------------------------------------------------------------------------- /lib/include/pcore/root.h: -------------------------------------------------------------------------------- 1 | //############################################################################## 2 | //# title: Root class, use this class for initializing whole system 3 | //# c-date: April-04-2016 4 | //# author: Pouya Shahinfar (Pswin) - pswinpo@gmail.com 5 | //############################################################################## 6 | 7 | #ifndef _PCORE_ROOT 8 | #define _PCORE_ROOT 9 | 10 | //============================================================================== 11 | // Includes 12 | //============================================================================== 13 | 14 | #include "pcore_def.h" 15 | #include "globals.h" 16 | #include "config.h" 17 | #include 18 | #include 19 | 20 | 21 | //============================================================================== 22 | // Defines 23 | //============================================================================== 24 | 25 | class QVersionNumber; 26 | 27 | 28 | //============================================================================== 29 | // Macros 30 | //============================================================================== 31 | 32 | #define PCORE_INIT( ) pRoot = new PCore::Root(); pRoot->init(); 33 | 34 | 35 | //============================================================================== 36 | // Root 37 | //============================================================================== 38 | namespace PCore 39 | { 40 | class PCORE_API Root : public QObject 41 | { 42 | Q_OBJECT 43 | 44 | public: 45 | 46 | //! default constructor 47 | explicit Root( QObject* _parent = nullptr ); 48 | 49 | 50 | /*! 51 | * \brief initialize the core (Engine) 52 | * \param _setting_file: Setting file name and path 53 | * \return true if initialization was successful 54 | */ 55 | bool init( const QString& _setting_file 56 | = PCORE_CONFIG_DEFAULT_SETTING_FILE ); 57 | 58 | 59 | /*! 60 | * \brief Shutdowns PCore and release resources 61 | * \return Returns true if procedure was successful. 62 | */ 63 | bool shutdown( void ); 64 | 65 | 66 | #if QT_VERSION >= QT_VERSION_CHECK(5,6,0) 67 | /*! 68 | * \brief Returns version number of PCore. 69 | * \return Version number of PCore. 70 | */ 71 | QVersionNumber getVersionNumber( void ) const; 72 | #endif // Qt 5.6 73 | 74 | /*! 75 | * \brief Returns version of PCore in string. 76 | * \return Version of PCore in string. 77 | */ 78 | QString getVersionString( void ) const; 79 | }; // Root 80 | } // PCore 81 | 82 | 83 | //============================================================================== 84 | // typedefs 85 | //============================================================================== 86 | 87 | #if PCORE_CONFIG_USE_TYPEDEF == PCORE_ENABLE 88 | using PRoot = PCore::Root; 89 | #endif 90 | 91 | 92 | #endif // _PCORE_ROOT 93 | 94 | -------------------------------------------------------------------------------- /lib/lib.pro: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | # PCore Library 3 | # By Pouya Shahinfar 4 | # pswinpo@gmail.com 5 | ################################################################################ 6 | 7 | 8 | #=============================================================================== 9 | # Internal libs 10 | #=============================================================================== 11 | 12 | QT += network xml 13 | QT -= gui 14 | 15 | 16 | #=============================================================================== 17 | # Configs 18 | #=============================================================================== 19 | 20 | CONFIG += C++11 21 | 22 | 23 | #=============================================================================== 24 | # Target 25 | #=============================================================================== 26 | 27 | TARGET = pcore 28 | TEMPLATE = lib 29 | 30 | DESTDIR = $$PWD/../bin/ 31 | 32 | 33 | unix { 34 | target.path = /usr/lib 35 | INSTALLS += target 36 | } 37 | 38 | 39 | #=============================================================================== 40 | # Defines 41 | #=============================================================================== 42 | 43 | DEFINES += PCORE_EXPORT 44 | 45 | 46 | #=============================================================================== 47 | # Include path 48 | #=============================================================================== 49 | 50 | INCLUDEPATH += ../ 51 | 52 | 53 | #=============================================================================== 54 | # Source/Header files 55 | #=============================================================================== 56 | 57 | SOURCES += \ 58 | source/core/globals.cpp \ 59 | source/core/logger.cpp \ 60 | source/root.cpp \ 61 | source/core/logger/logger_file.cpp \ 62 | source/core/logger/logger_qdebug.cpp \ 63 | source/core/profiler.cpp \ 64 | source/core/logger/logger_network.cpp \ 65 | source/core/compressor.cpp \ 66 | source/core/windows/win_wmi.cpp \ 67 | source/core/system_info/sys_info_intel.cpp \ 68 | source/core/system_info/sys_info_amd.cpp \ 69 | source/core/system_info/sys_info_win.cpp \ 70 | source/core/system_info/sys_info_linux.cpp \ 71 | source/core/system_info/sys_info_global.cpp \ 72 | source/core/linux/udev.cpp \ 73 | source/globalization/persian_calendar.cpp \ 74 | source/globalization/date_parser.cpp \ 75 | source/globalization/locale.cpp \ 76 | source/globalization/hijri_calendar.cpp \ 77 | source/cryptography/rsa.cpp \ 78 | source/cryptography/cryptography_engine.cpp \ 79 | source/math/random.cpp \ 80 | source/cryptography/aes.cpp \ 81 | source/cryptography/des.cpp \ 82 | source/core/hr.cpp 83 | 84 | HEADERS +=\ 85 | include/pcore/pcore.h \ 86 | include/pcore/def/arch.h \ 87 | include/pcore/def/compiler.h \ 88 | include/pcore/def/const.h \ 89 | include/pcore/def/def_gcc.h \ 90 | include/pcore/def/def_msvc.h \ 91 | include/pcore/def/limits.h \ 92 | include/pcore/def/os.h \ 93 | include/pcore/config.h \ 94 | include/pcore/pcore_def.h \ 95 | include/pcore/core/logger.h \ 96 | include/pcore/globals.h \ 97 | include/pcore/root.h \ 98 | include/pcore/core/profiler.h \ 99 | headers/core/logger/logger_network.h \ 100 | headers/core/logger/logger_dummy.h \ 101 | headers/core/logger/logger_file.h \ 102 | headers/core/logger/logger_qdebug.h \ 103 | include/pcore/core/compressor.h \ 104 | include/pcore/core/exception.h \ 105 | include/pcore/core/system_information.h \ 106 | headers/core/windows/win_wmi.h \ 107 | include/pcore/core/bit_operations.h \ 108 | headers/core/arch/intel/sys_info/sys_info_intel.h \ 109 | headers/core/arch/amd/sys_info/sys_info_amd.h \ 110 | headers/core/linux/udev.h \ 111 | include/pcore/globalization/persian_calendar.h \ 112 | include/pcore/globalization/date_parser.h \ 113 | headers/globalization/info_structs.h \ 114 | include/pcore/globalization/locale.h \ 115 | include/pcore/globalization/hijri_calendar.h \ 116 | include/pcore/cryptography/rsa.h \ 117 | headers/cryptography/cryptography_engine.h \ 118 | include/pcore/cryptography/aes.h \ 119 | include/pcore/math/random.h \ 120 | include/pcore/cryptography/des.h \ 121 | include/pcore/core/hr.h \ 122 | include/pcore/core/cachefx/lru_cache.h 123 | 124 | 125 | 126 | DISTFILES += \ 127 | plan.txt 128 | 129 | 130 | #=============================================================================== 131 | # Libs 132 | #=============================================================================== 133 | 134 | #-------------------------------------- 135 | # zlib 136 | #-------------------------------------- 137 | 138 | win32:contains( QMAKE_HOST.arch, x86_64 ) { 139 | LIBS += -L$$PWD/3rdparty/zlib/bin_x64 -lzdll 140 | } else:win32 { 141 | LIBS += -L$$PWD/3rdparty/zlib/bin_x86 -lzdll 142 | } else:unix { 143 | LIBS += -lz 144 | } 145 | 146 | win32: { 147 | INCLUDEPATH += $$PWD/3rdparty/zlib/include 148 | DEPENDPATH += $$PWD/3rdparty/zlib/include 149 | } 150 | 151 | 152 | #-------------------------------------- 153 | # openssl 154 | #-------------------------------------- 155 | 156 | 157 | win32:contains( QMAKE_HOST.arch, x86_64 ) { 158 | LIBS += -L$$PWD/3rdparty/openssl/bin_x64 -llibeay32MD -lssleay32MD 159 | } else:win32 { 160 | LIBS += -L$$PWD/3rdparty/openssl/bin_x86 -llibeay32MD -lssleay32MD 161 | } else:unix { 162 | LIBS += -lssl -lcrypto 163 | } 164 | 165 | win32:contains( QMAKE_HOST.arch, x86_64 ) { 166 | INCLUDEPATH += $$PWD/3rdparty/openssl/include64 167 | DEPENDPATH += $$PWD/3rdparty/openssl/include64 168 | } else:win32 { 169 | INCLUDEPATH += $$PWD/3rdparty/openssl/include 170 | DEPENDPATH += $$PWD/3rdparty/openssl/include 171 | } 172 | 173 | 174 | #-------------------------------------- 175 | # 7-Zip 176 | #-------------------------------------- 177 | 178 | 179 | 180 | #-------------------------------------- 181 | # Windows COM 182 | #-------------------------------------- 183 | 184 | win32: LIBS+= -lwbemuuid -lcomsupp 185 | 186 | 187 | #-------------------------------------- 188 | # udev 189 | #-------------------------------------- 190 | 191 | unix: { 192 | LIBS += -ludev 193 | } 194 | 195 | RESOURCES += 196 | 197 | -------------------------------------------------------------------------------- /lib/source/core/compressor.cpp: -------------------------------------------------------------------------------- 1 | //############################################################################## 2 | //# c-date: Apr-13-2016 3 | //# author: Pouya Shahinfar 4 | //############################################################################## 5 | 6 | #include "include/pcore/core/compressor.h" 7 | #include "include/pcore/core/logger.h" 8 | #include "include/pcore/core/exception.h" 9 | #include 10 | #include 11 | 12 | 13 | #define MOD_GZIP_ZLIB_WINDOWSIZE 15 14 | #define MOD_GZIP_ZLIB_CFACTOR 9 15 | #define MOD_GZIP_ZLIB_BSIZE 8096 16 | 17 | namespace PCore 18 | { 19 | namespace core 20 | { 21 | //! compress 22 | QByteArray Compressor::compress(const QByteArray& _in, 23 | Compressor::Format _format, 24 | Level _level 25 | ) 26 | { 27 | z_stream zs; 28 | memset(&zs, 0, sizeof(zs)); 29 | 30 | int compression_level = Z_DEFAULT_COMPRESSION; 31 | 32 | switch ( _level ) 33 | { 34 | case Level::BestCompression: 35 | compression_level = Z_BEST_COMPRESSION; 36 | break; 37 | case Level::BestSpeed: 38 | compression_level = Z_BEST_SPEED; 39 | break; 40 | default: 41 | compression_level = Z_DEFAULT_COMPRESSION; 42 | } 43 | 44 | 45 | int ret; 46 | switch ( _format ) 47 | { 48 | case Format::RawDeflate: 49 | ret = deflateInit( &zs, compression_level ); 50 | break; 51 | case Format::GZip: 52 | ret = deflateInit2( &zs, compression_level, 53 | Z_DEFLATED, 54 | MOD_GZIP_ZLIB_WINDOWSIZE + 16, 55 | MOD_GZIP_ZLIB_CFACTOR, 56 | Z_DEFAULT_STRATEGY); 57 | break; 58 | default: 59 | ret = deflateInit( &zs, compression_level ); 60 | 61 | } 62 | if ( ret != Z_OK ) 63 | { 64 | PCORE_LOG_ERROR( "Initializing compression structure failed." ); 65 | PCORE_THROW_EXCEPTION( std::runtime_error, "Initializing compression structure failed." ); 66 | return QByteArray(); 67 | } 68 | zs.next_in = (Bytef*)_in.data(); 69 | zs.avail_in = _in.size(); 70 | 71 | char out_buf[ 32 * PCORE_1KB ]; 72 | QByteArray out; 73 | 74 | // retrieve the compressed bytes blockwise 75 | do { 76 | zs.next_out = reinterpret_cast( out_buf ); 77 | zs.avail_out = sizeof( out_buf ); 78 | 79 | ret = deflate( &zs, Z_FINISH ); 80 | 81 | if ( (uLong)out.size() < zs.total_out ) 82 | { 83 | out.append( out_buf, zs.total_out - out.size() ); 84 | } 85 | } while ( ret == Z_OK ); 86 | 87 | deflateEnd( &zs ); 88 | 89 | if ( ret != Z_STREAM_END ) 90 | { 91 | QString msg = "Exception during decompression: " + 92 | QString::number(ret) + ", " + QString( zs.msg ); 93 | PCORE_LOG_ERROR( msg ); 94 | PCORE_THROW_EXCEPTION( std::runtime_error, msg.toStdString() ); 95 | return QByteArray(); 96 | } 97 | 98 | return out; 99 | } 100 | 101 | //! compressFile 102 | bool Compressor::compressFile( 103 | const QString& _in_filename, 104 | const QString& _out_filename, 105 | Compressor::Format _format, 106 | Level _level 107 | ) 108 | { 109 | QFile input_file( _in_filename ); 110 | 111 | if ( input_file.open( QFile::ReadOnly ) == false ) 112 | { 113 | QString msg = "Error in opening file: '" + _in_filename + "'."; 114 | PCORE_LOG_ERROR( msg ); 115 | PCORE_THROW_EXCEPTION( std::runtime_error, msg.toStdString() ); 116 | return false; 117 | } 118 | 119 | QByteArray ar_in = input_file.readAll(); 120 | input_file.close(); 121 | 122 | QByteArray ar_out; 123 | try 124 | { 125 | ar_out = compress( ar_in, _format, _level ); 126 | } 127 | catch ( ... ) 128 | { 129 | QString msg = "Error in compressing file: '" + _in_filename + "'."; 130 | PCORE_LOG_ERROR( msg ); 131 | PCORE_THROW_EXCEPTION( std::runtime_error, msg.toStdString() ); 132 | return false; 133 | } 134 | 135 | if ( ar_out.isEmpty() == true ) 136 | { 137 | QString msg = "Error in compressing file: '" + _in_filename + "'."; 138 | PCORE_LOG_ERROR( msg ); 139 | PCORE_THROW_EXCEPTION( std::runtime_error, msg.toStdString() ); 140 | return false; 141 | } 142 | 143 | QFile out_file( _out_filename ); 144 | 145 | if ( out_file.open( QFile::WriteOnly) == false ) 146 | { 147 | QString msg = "Error in opening file: '" + _in_filename + "'."; 148 | PCORE_LOG_ERROR( msg ); 149 | PCORE_THROW_EXCEPTION( std::runtime_error, msg.toStdString() ); 150 | return false; 151 | } 152 | 153 | out_file.write( ar_out ); 154 | out_file.flush(); 155 | out_file.close(); 156 | 157 | return true; 158 | } // compress 159 | 160 | 161 | //! decompress 162 | QByteArray Compressor::decompress( 163 | const QByteArray& _in, 164 | Compressor::Format _format 165 | ) 166 | { 167 | z_stream zs; 168 | 169 | memset( &zs, 0, sizeof(zs) ); 170 | 171 | 172 | int ret; 173 | switch ( _format ) 174 | { 175 | case Format::RawDeflate: 176 | ret = inflateInit( &zs ); 177 | break; 178 | case Format::GZip: 179 | ret = inflateInit2( &zs, MOD_GZIP_ZLIB_WINDOWSIZE + 16 ); 180 | break; 181 | default: 182 | ret = inflateInit( &zs ); 183 | } 184 | 185 | if ( ret != Z_OK ) 186 | { 187 | PCORE_LOG_ERROR( "Initializing decompression structure failed." ); 188 | PCORE_THROW_EXCEPTION( std::runtime_error, "Initializing decompression structure failed." ); 189 | return QByteArray(); 190 | } 191 | 192 | zs.next_in = (Bytef*)_in.data(); 193 | zs.avail_in = _in.size(); 194 | 195 | char out_buf[ 32 * PCORE_1KB ]; 196 | QByteArray out; 197 | 198 | 199 | // get the decompressed bytes blockwise using repeated calls to inflate 200 | do 201 | { 202 | zs.next_out = reinterpret_cast( out_buf ); 203 | zs.avail_out = sizeof( out_buf ); 204 | 205 | ret = inflate( &zs, 0 ); 206 | 207 | if ( (uLong)out.size() < zs.total_out ) 208 | { 209 | out.append( out_buf, zs.total_out - out.size() ); 210 | } 211 | } while ( ret == Z_OK ); 212 | 213 | inflateEnd( &zs ); 214 | 215 | if ( ret != Z_STREAM_END ) 216 | { 217 | QString msg = "Exception during decompression: "+ 218 | QString::number( ret ) + ", " + QString( zs.msg ); 219 | PCORE_LOG_ERROR( msg ); 220 | PCORE_THROW_EXCEPTION( std::runtime_error, msg.toStdString() ); 221 | return QByteArray(); 222 | } 223 | 224 | return out; 225 | } // decompress 226 | 227 | bool Compressor::decompressFile( 228 | const QString& _in_filename, 229 | const QString& _out_filename, 230 | Compressor::Format _format 231 | ) 232 | { 233 | QFile input_file( _in_filename ); 234 | 235 | if ( input_file.open( QFile::ReadOnly ) == false ) 236 | { 237 | QString msg = "Error in opening file: '" + _in_filename + "'."; 238 | PCORE_LOG_ERROR( msg ); 239 | PCORE_THROW_EXCEPTION( std::runtime_error, msg.toStdString() ); 240 | return false; 241 | } 242 | 243 | QByteArray ar_in = input_file.readAll(); 244 | input_file.close(); 245 | 246 | QByteArray ar_out; 247 | try 248 | { 249 | ar_out = decompress( ar_in, _format ); 250 | } 251 | catch ( ... ) 252 | { 253 | QString msg = "Error in decompressing file: '" + _in_filename + "'."; 254 | PCORE_LOG_ERROR( msg ); 255 | PCORE_THROW_EXCEPTION( std::runtime_error, msg.toStdString() ); 256 | return false; 257 | } 258 | 259 | if ( ar_out.isEmpty() == true ) 260 | { 261 | QString msg = "Error in decompressing file: '" + _in_filename + "'."; 262 | PCORE_LOG_ERROR( msg ); 263 | PCORE_THROW_EXCEPTION( std::runtime_error, msg.toStdString() ); 264 | return false; 265 | } 266 | 267 | QFile out_file( _out_filename ); 268 | 269 | if ( out_file.open( QFile::WriteOnly) == false ) 270 | { 271 | QString msg = "Error in opening file: '" + _in_filename + "'."; 272 | PCORE_LOG_ERROR( msg ); 273 | PCORE_THROW_EXCEPTION( std::runtime_error, msg.toStdString() ); 274 | return false; 275 | } 276 | 277 | out_file.write( ar_out ); 278 | out_file.flush(); 279 | out_file.close(); 280 | 281 | return true; 282 | } // decompressFile 283 | } // decompress 284 | 285 | 286 | 287 | // Core 288 | } // PCore 289 | 290 | -------------------------------------------------------------------------------- /lib/source/core/globals.cpp: -------------------------------------------------------------------------------- 1 | //############################################################################## 2 | //# c-date: Feb-28-2016 3 | //# author: Pouya Shahinfar (Pswin) - pswinpo@gmail.com 4 | //############################################################################## 5 | 6 | 7 | #include "include/pcore/globals.h" 8 | #include "include/pcore/core/logger.h" 9 | #include "include/pcore/core/profiler.h" 10 | #include "include/pcore/root.h" 11 | 12 | PCore::core::Logger* pLogger = nullptr; 13 | PCore::core::ProfileManager* pProfileManager = nullptr; 14 | PCore::Root* pRoot = nullptr; 15 | 16 | -------------------------------------------------------------------------------- /lib/source/core/hr.cpp: -------------------------------------------------------------------------------- 1 | //############################################################################## 2 | //# 3 | //# 4 | //############################################################################## 5 | 6 | 7 | #include "include/pcore/core/hr.h" 8 | #include 9 | 10 | 11 | namespace PCore 12 | { 13 | namespace core 14 | { 15 | 16 | //! byteToString 17 | QString HumanReadable::byteToString( quint64 _bytes, int _fraction ) 18 | { 19 | if ( _bytes / PCORE_1TB >= 1 ) 20 | return QString::number( _bytes / (double)PCORE_1TB, 'f', _fraction ) + " TB"; 21 | else if ( _bytes / PCORE_1GB >= 1 ) 22 | return QString::number( _bytes / (double)PCORE_1GB, 'f', _fraction ) + " GB"; 23 | else if ( _bytes / PCORE_1MB >= 1 ) 24 | return QString::number( _bytes / (double)PCORE_1MB, 'f', _fraction ) + " MB"; 25 | else if ( _bytes / PCORE_1KB >= 1 ) 26 | return QString::number( _bytes / (double)PCORE_1KB, 'f', _fraction ) + " KB"; 27 | else 28 | return QString::number( _bytes ); 29 | } // byteToString 30 | 31 | 32 | //! freqToString 33 | QString HumanReadable::freqToString( quint64 _freq, int _fraction ) 34 | { 35 | if ( _freq / PCORE_1THZ >= 1 ) 36 | return QString::number( _freq / (double)PCORE_1THZ, 'f', _fraction ) + " THz"; 37 | else if ( _freq / PCORE_1GHZ >= 1 ) 38 | return QString::number( _freq / (double)PCORE_1GHZ, 'f', _fraction ) + " GHz"; 39 | else if ( _freq / PCORE_1MHZ >= 1 ) 40 | return QString::number( _freq / (double)PCORE_1MHZ, 'f', _fraction ) + " MHz"; 41 | else if ( _freq / PCORE_1KHZ >= 1 ) 42 | return QString::number( _freq / (double)PCORE_1KHZ, 'f', _fraction ) + " KHz"; 43 | else 44 | return QString::number( _freq ); 45 | } 46 | 47 | } // core 48 | } // PCore 49 | 50 | -------------------------------------------------------------------------------- /lib/source/core/linux/udev.cpp: -------------------------------------------------------------------------------- 1 | //############################################################################## 2 | //# title: An interface for dealing with Udev 3 | //# c-date: May-20-2016 4 | //# author: Pouya Shahinfar (Pswin) - pswinpo@gmail.com 5 | //############################################################################## 6 | 7 | #include "headers/core/linux/udev.h" 8 | 9 | #if PCORE_OS == PCORE_OS_LINUX 10 | 11 | namespace PCore 12 | { 13 | namespace core 14 | { 15 | //====================================================================== 16 | // Device 17 | //====================================================================== 18 | 19 | //! constructor 20 | Udev::UdevDevice::UdevDevice( udev *_udev , udev_device *_device ) 21 | { 22 | m_pUdev = _udev; 23 | m_pDevice = _device; 24 | 25 | } 26 | 27 | //! Copy constructor 28 | Udev::UdevDevice::UdevDevice(const Udev::UdevDevice &_dev) 29 | { 30 | m_pDevice = _dev.m_pDevice; 31 | m_pUdev = _dev.m_pUdev; 32 | } 33 | 34 | //! move constructor 35 | Udev::UdevDevice::UdevDevice( Udev::UdevDevice &&_dev ) 36 | { 37 | m_pDevice = _dev.m_pDevice; 38 | _dev.m_pDevice = nullptr; 39 | m_pUdev = _dev.m_pUdev; 40 | } 41 | 42 | //! getProperty 43 | QString Udev::UdevDevice::getProperty( const char *_name ) const 44 | { 45 | if ( m_pDevice == nullptr ) return nullptr; 46 | return QString(udev_device_get_property_value( m_pDevice, _name )).trimmed(); 47 | 48 | } 49 | 50 | //! getSystemAttribute 51 | QString Udev::UdevDevice::getSystemAttribute( const char *_name ) const 52 | { 53 | if ( m_pDevice == nullptr ) return nullptr; 54 | return QString(udev_device_get_sysattr_value( m_pDevice, _name )).trimmed(); 55 | } 56 | 57 | //! getNode 58 | QString Udev::UdevDevice::getNode() const 59 | { 60 | if ( m_pDevice == nullptr ) return nullptr; 61 | return udev_device_get_devnode( m_pDevice ); 62 | } 63 | 64 | //! getPath 65 | QString Udev::UdevDevice::getPath() const 66 | { 67 | if ( m_pDevice == nullptr ) return nullptr; 68 | return udev_device_get_devpath( m_pDevice ); 69 | } 70 | 71 | 72 | //! getType 73 | QString Udev::UdevDevice::getType() const 74 | { 75 | if ( m_pDevice == nullptr ) return nullptr; 76 | return udev_device_get_devtype( m_pDevice ); 77 | } 78 | 79 | 80 | //! getSystemName 81 | QString Udev::UdevDevice::getSystemName() const 82 | { 83 | if ( m_pDevice == nullptr ) return nullptr; 84 | return udev_device_get_sysname( m_pDevice ); 85 | } 86 | 87 | 88 | //! getParent 89 | Udev::UdevDevice Udev::UdevDevice::getParent() const 90 | { 91 | if ( m_pDevice == nullptr ) return UdevDevice( m_pUdev, nullptr ); 92 | return UdevDevice( m_pUdev, udev_device_get_parent( m_pDevice ) ); 93 | } 94 | 95 | 96 | //! getParentBySubsystemAndDevType 97 | Udev::UdevDevice Udev::UdevDevice::getParentBySubsystemAndDevType( 98 | const char *_sub_system, 99 | const char *_dev_type) 100 | { 101 | if ( m_pDevice == nullptr ) return UdevDevice( m_pUdev, nullptr ); 102 | return UdevDevice ( m_pUdev, 103 | udev_device_get_parent_with_subsystem_devtype 104 | ( m_pDevice, _sub_system, _dev_type ) ); 105 | } 106 | 107 | 108 | //! getSubsystems 109 | QList Udev::UdevDevice::getSubSystems( 110 | const char *_name ) const 111 | { 112 | QList children; 113 | 114 | udev_enumerate *enumerate = udev_enumerate_new( m_pUdev ); 115 | 116 | udev_enumerate_add_match_parent( enumerate, m_pDevice ); 117 | udev_enumerate_add_match_subsystem( enumerate, _name ); 118 | udev_enumerate_scan_devices( enumerate ); 119 | 120 | udev_list_entry *devices = udev_enumerate_get_list_entry( enumerate ); 121 | udev_list_entry *entry; 122 | 123 | udev_list_entry_foreach( entry, devices ) 124 | { 125 | const char *path = udev_list_entry_get_name(entry); 126 | children.push_back( UdevDevice( m_pUdev, 127 | udev_device_new_from_syspath( m_pUdev, path ) ) ); 128 | } 129 | 130 | udev_enumerate_unref(enumerate); 131 | return children; 132 | } 133 | 134 | //! getChildSubsystem 135 | Udev::UdevDevice Udev::UdevDevice::getChildSubsystem 136 | (const char *_name) const 137 | { 138 | udev_enumerate *enumerate = udev_enumerate_new( m_pUdev ); 139 | 140 | if ( enumerate == nullptr ) return UdevDevice( m_pUdev, nullptr); 141 | 142 | udev_enumerate_add_match_parent( enumerate, m_pDevice ); 143 | udev_enumerate_add_match_subsystem( enumerate, _name ); 144 | udev_enumerate_scan_devices( enumerate ); 145 | 146 | udev_list_entry *devices = udev_enumerate_get_list_entry( enumerate ); 147 | udev_list_entry *entry; 148 | 149 | udev_device* dev = nullptr; 150 | udev_list_entry_foreach( entry, devices ) 151 | { 152 | const char *path = udev_list_entry_get_name(entry); 153 | dev = udev_device_new_from_syspath( m_pUdev, path ); 154 | break; 155 | } 156 | 157 | udev_enumerate_unref(enumerate); 158 | return UdevDevice( m_pUdev, dev); 159 | } 160 | 161 | //! release 162 | void Udev::UdevDevice::release() 163 | { 164 | if ( m_pDevice == nullptr ) return; 165 | udev_device_unref( m_pDevice ); 166 | m_pDevice = nullptr; 167 | } 168 | 169 | 170 | //====================================================================== 171 | // Device 172 | //====================================================================== 173 | 174 | //! constructor 175 | Udev::Udev() 176 | { 177 | m_pUdev = udev_new(); 178 | 179 | if ( m_pUdev != nullptr ) 180 | { 181 | m_pEnumerate = udev_enumerate_new( m_pUdev ); 182 | } 183 | } 184 | 185 | 186 | //! destructor 187 | Udev::~Udev() 188 | { 189 | if ( m_pUdev != nullptr ) 190 | { 191 | udev_unref( m_pUdev ); 192 | } 193 | 194 | if ( m_pEnumerate != nullptr) 195 | { 196 | udev_enumerate_unref( m_pEnumerate ); 197 | } 198 | } 199 | 200 | //! addMatchSubsystem 201 | void Udev::addMatchSubsystem( const char *_sub_system ) 202 | { 203 | if ( m_pEnumerate == nullptr ) return; 204 | 205 | udev_enumerate_add_match_subsystem( m_pEnumerate, _sub_system ); 206 | } 207 | 208 | //! addMatchProperty 209 | void Udev::addMatchProperty( 210 | const char *_property_name, 211 | const char *_property_value 212 | ) 213 | { 214 | 215 | if ( m_pEnumerate == nullptr ) return; 216 | 217 | udev_enumerate_add_match_property( m_pEnumerate, 218 | _property_name, 219 | _property_value ); 220 | } 221 | 222 | //! addMatchClass 223 | void Udev::addMatchClass( const char *_name ) 224 | { 225 | if ( m_pEnumerate == nullptr ) return; 226 | 227 | udev_enumerate_add_match_subsystem( m_pEnumerate, _name ); 228 | } 229 | 230 | 231 | //! scan 232 | QList Udev::scan() 233 | { 234 | QList list; 235 | if ( m_pEnumerate == nullptr ) return list; 236 | 237 | udev_enumerate_scan_devices( m_pEnumerate ); 238 | 239 | udev_list_entry *devices = 240 | udev_enumerate_get_list_entry( m_pEnumerate ); 241 | 242 | udev_list_entry *entry; 243 | udev_list_entry_foreach(entry, devices) 244 | { 245 | const char* path = udev_list_entry_get_name( entry ); 246 | udev_device* dev = udev_device_new_from_syspath( m_pUdev, path); 247 | list.push_back( Udev::UdevDevice( m_pUdev, dev ) ); 248 | } 249 | 250 | return list; 251 | } 252 | 253 | 254 | 255 | 256 | } // core 257 | } // PCore 258 | 259 | #endif // PCORE_OS_LINUX 260 | 261 | -------------------------------------------------------------------------------- /lib/source/core/logger/logger_file.cpp: -------------------------------------------------------------------------------- 1 | //############################################################################## 2 | //# title: File logger interface 3 | //# c-date: Feb-29-2016 4 | //# author: Pouya Shahinfar (Pswin) - pswinpo@gmail.com 5 | //############################################################################## 6 | 7 | #include "headers/core/logger/logger_file.h" 8 | #include 9 | #include 10 | 11 | //============================================================================== 12 | // FileLogger 13 | //============================================================================== 14 | 15 | #define __PCORE_LOGGER_FILE_HELPER( __type, __msg ) \ 16 | m_TextStream << __type << ": " << QDateTime::currentDateTime().toString() << " | " << __msg.getMessage() << " | " ; \ 17 | for ( quint32 i = 0; i < __msg.getParamCount(); i++ )\ 18 | {\ 19 | auto it = __msg.getParamByIndex(i);\ 20 | m_TextStream << it.key() << ": '" << it.value().toString() << "', ";\ 21 | }\ 22 | m_TextStream << "\r\n"; 23 | 24 | 25 | namespace PCore 26 | { 27 | namespace core 28 | { 29 | 30 | //===================================== 31 | // constructor 32 | //===================================== 33 | FileLogger::FileLogger( QObject* _parent ) 34 | : LoggerInterface( Type::File, _parent ) 35 | { 36 | try 37 | { 38 | m_pFile = new QFile( m_sFilename, this ); 39 | 40 | if ( m_pFile->open( QFile::OpenModeFlag::Append | 41 | QFile::OpenModeFlag::Text ) == false ) 42 | { 43 | qDebug() << "File logger error in opening file: " << m_sFilename; 44 | return; 45 | } 46 | 47 | m_TextStream.setDevice( m_pFile ); 48 | } 49 | catch ( ... ) 50 | { 51 | qDebug() << "File logger error in opening file: " << m_sFilename; 52 | } 53 | } 54 | 55 | 56 | //===================================== 57 | // destructor 58 | //===================================== 59 | FileLogger::~FileLogger() 60 | { 61 | if ( m_pFile != nullptr ) 62 | { 63 | if ( m_pFile->isOpen() == true ) 64 | { 65 | m_pFile->close(); 66 | } 67 | } 68 | } 69 | 70 | 71 | //===================================== 72 | // logMessage 73 | //===================================== 74 | void FileLogger::logMessage( const LogMessage& _msg ) 75 | { 76 | switch ( _msg.getType() ) 77 | { 78 | case LogMessage::Type::Critical: 79 | __PCORE_LOGGER_FILE_HELPER( "Critical", _msg ); 80 | break; 81 | case LogMessage::Type::Error: 82 | __PCORE_LOGGER_FILE_HELPER( "Error", _msg ); 83 | break; 84 | case LogMessage::Type::Information: 85 | __PCORE_LOGGER_FILE_HELPER( "Information", _msg ); 86 | break; 87 | case LogMessage::Type::Warning: 88 | __PCORE_LOGGER_FILE_HELPER( "Warning", _msg ); 89 | break; 90 | case LogMessage::Type::Trace: 91 | __PCORE_LOGGER_FILE_HELPER( "Trace", _msg ); 92 | break; 93 | } 94 | m_TextStream.flush(); 95 | } // logMessage 96 | 97 | 98 | //===================================== 99 | // setFile 100 | //===================================== 101 | void FileLogger::setFile( const QString& _filename ) 102 | { 103 | try 104 | { 105 | m_sFilename = _filename; 106 | 107 | if ( m_pFile->isOpen() ) 108 | { 109 | m_pFile->close(); 110 | } 111 | 112 | m_pFile->setFileName( m_sFilename ); 113 | if ( m_pFile->open( QFile::OpenModeFlag::Append | 114 | QFile::OpenModeFlag::Text ) == false ) 115 | { 116 | qDebug() << "File logger error in opening file: " << m_sFilename; 117 | } 118 | } 119 | catch ( ... ) 120 | { 121 | qDebug() << "File logger error in opening file: " << m_sFilename; 122 | } 123 | } 124 | 125 | 126 | //===================================== 127 | // isOpen 128 | //===================================== 129 | bool FileLogger::isOpen() const 130 | { 131 | if ( m_pFile == nullptr ) return false; 132 | return m_pFile->isOpen(); 133 | } 134 | 135 | //===================================== 136 | // clearContent 137 | //===================================== 138 | void FileLogger::clearContent() 139 | { 140 | m_pFile->resize( 0 ); 141 | } 142 | 143 | } // core 144 | } // PCore 145 | -------------------------------------------------------------------------------- /lib/source/core/logger/logger_network.cpp: -------------------------------------------------------------------------------- 1 | //############################################################################## 2 | //# title: Network based logger 3 | //# c-date: Apr-11-2016 4 | //# author: Pouya Shahinfar (Pswin) - pswinpo@gmail.com 5 | //############################################################################## 6 | 7 | #include "headers/core/logger/logger_network.h" 8 | #include 9 | 10 | namespace PCore 11 | { 12 | namespace core 13 | { 14 | //! Constructor 15 | NetworkLogger::NetworkLogger( const QHostAddress _host, 16 | const port_t _port , QObject* _parent ) 17 | : LoggerInterface( LoggerInterface::Type::Network, _parent ) 18 | { 19 | m_HostAddress = _host; 20 | m_Port = _port; 21 | } // constructor 22 | 23 | 24 | //! Destructor 25 | NetworkLogger::~NetworkLogger() 26 | { 27 | if ( m_pSocket != nullptr ) 28 | { 29 | if ( m_pSocket->isOpen() == true ) 30 | { 31 | m_pSocket->disconnect(); 32 | } 33 | } 34 | } // destructor 35 | 36 | 37 | //! connect 38 | bool NetworkLogger::connect( void ) 39 | { 40 | if ( m_pSocket == nullptr ) 41 | { 42 | m_pSocket = new QTcpSocket(); 43 | } 44 | else 45 | { 46 | if ( m_pSocket->isOpen() == true ) 47 | { 48 | m_pSocket->close(); 49 | } 50 | } 51 | 52 | m_pSocket->connectToHost( m_HostAddress, m_Port ); 53 | 54 | if ( m_pSocket->waitForConnected( 55 | PCORE_CONFIG_LOGGER_NETWORK_DEFAULT_WAIT_TIME ) == false ) 56 | { 57 | PCORE_LOG_CORE_ERROR("NetworkLogger: connection to host :'" + 58 | m_HostAddress.toString() + "'' on port" + 59 | QString::number( m_Port ) + " Failed." 60 | ); 61 | return false; 62 | } 63 | 64 | return true; 65 | } // connect 66 | 67 | 68 | //! isConnected 69 | bool NetworkLogger::isConnected() const 70 | { 71 | if ( m_pSocket == nullptr ) return false; 72 | return m_pSocket->isOpen(); 73 | } 74 | 75 | 76 | //! setPort 77 | bool NetworkLogger::setPort( NetworkLogger::port_t _port ) 78 | { 79 | m_Port = _port; 80 | if ( isConnected() == true ) 81 | { 82 | return connect( ); 83 | } 84 | return true; 85 | 86 | } 87 | 88 | //! setHost 89 | bool NetworkLogger::setHost( const QHostAddress& _host_addr ) 90 | { 91 | m_HostAddress = _host_addr; 92 | if ( isConnected() == true ) 93 | { 94 | return connect( ); 95 | } 96 | return true; 97 | } 98 | 99 | //! logMessage 100 | void NetworkLogger::logMessage( const LogMessage& _msg ) 101 | { 102 | if ( m_pSocket == nullptr ) return; 103 | if ( m_pSocket->isOpen() == false ) return; 104 | QByteArray ar; 105 | QDataStream st( &ar, QIODevice::ReadWrite); 106 | 107 | st << (int)st.byteOrder() << (int)_msg.getType() << 108 | QVariant(_msg.getMessage()) << _msg.getParamCount(); 109 | 110 | 111 | for ( quint32 i = 0; i < _msg.getParamCount(); i++ ) 112 | { 113 | LogMessage::ParamMapConstIterator it = _msg.getParamByIndex( i ); 114 | st << QVariant(it.key()) << it.value(); 115 | } 116 | 117 | m_pSocket->write( ar ); 118 | m_pSocket->flush(); 119 | 120 | } // connect 121 | 122 | } // Core 123 | } // PCore 124 | 125 | -------------------------------------------------------------------------------- /lib/source/core/logger/logger_qdebug.cpp: -------------------------------------------------------------------------------- 1 | //############################################################################## 2 | //# c-date: Feb-28-2016 3 | //# author: Pouya Shahinfar (Pswin) - pswinpo@gmail.com 4 | //############################################################################## 5 | 6 | #include "headers/core/logger/logger_qdebug.h" 7 | #include 8 | 9 | 10 | #define PCORE_LOG_MESSAGE_FORMAT( __type, __msg ) \ 11 | qDebug() << __type << ": " << __msg.getMessage(); \ 12 | for ( quint32 i = 0; i < __msg.getParamCount() ; i++ ) \ 13 | { \ 14 | qDebug() << "\t\t* " << __msg.getParamByIndex( i ).key() << ": "<< __msg.getParamByIndex( i ).value().toString() ;\ 15 | } 16 | 17 | namespace PCore 18 | { 19 | namespace core 20 | { 21 | //===================================== 22 | // constructor 23 | //===================================== 24 | QDebugLogger::QDebugLogger( QObject *_parent ) 25 | : LoggerInterface( Type::QDebug, _parent ) 26 | { 27 | 28 | } 29 | 30 | //===================================== 31 | // logMessage 32 | //===================================== 33 | void QDebugLogger::logMessage( const LogMessage& _msg ) 34 | { 35 | switch ( _msg.getType() ) 36 | { 37 | case LogMessage::Type::Critical: 38 | PCORE_LOG_MESSAGE_FORMAT( "Critical", _msg ); 39 | break; 40 | case LogMessage::Type::Error: 41 | PCORE_LOG_MESSAGE_FORMAT( "Error", _msg ); 42 | break; 43 | case LogMessage::Type::Information: 44 | PCORE_LOG_MESSAGE_FORMAT( "Information", _msg ); 45 | break; 46 | case LogMessage::Type::Trace: 47 | PCORE_LOG_MESSAGE_FORMAT( "Trace", _msg ); 48 | break; 49 | case LogMessage::Type::Warning: 50 | PCORE_LOG_MESSAGE_FORMAT( "Warning", _msg ); 51 | break; 52 | default: 53 | break; 54 | } 55 | } 56 | 57 | 58 | 59 | 60 | } // core 61 | } // PCore 62 | -------------------------------------------------------------------------------- /lib/source/core/profiler.cpp: -------------------------------------------------------------------------------- 1 | //############################################################################## 2 | //# c-date: Apr-08-2016 3 | //# author: Pouya Shahinfar (Pswin) - pswinpo@gmail.com 4 | //############################################################################## 5 | 6 | 7 | #include "include/pcore/core/profiler.h" 8 | #include "include/pcore/core/logger.h" 9 | #include "include/pcore/globals.h" 10 | #include 11 | #include 12 | #include 13 | 14 | 15 | 16 | namespace PCore 17 | { 18 | namespace core 19 | { 20 | //====================================================================== 21 | // Profiler 22 | //====================================================================== 23 | 24 | //! constructor 25 | Profiler::Profiler( const QString& _name ) 26 | { 27 | PCORE_LOG_TRACE_FUNC_START(); 28 | m_sName = _name; 29 | } 30 | 31 | //! destructor 32 | Profiler::~Profiler() 33 | { 34 | PCORE_LOG_TRACE_FUNC_START(); 35 | pProfileManager->stopProfile( m_sName ); 36 | } 37 | 38 | //! start 39 | void Profiler::start() 40 | { 41 | PCORE_LOG_TRACE_FUNC_START(); 42 | pProfileManager->startProfile( m_sName ); 43 | } 44 | 45 | //! stop 46 | quint64 Profiler::stop( void ) 47 | { 48 | PCORE_LOG_TRACE_FUNC_START(); 49 | return pProfileManager->stopProfile( m_sName ); 50 | } 51 | 52 | 53 | //====================================================================== 54 | // ProfileManager 55 | //====================================================================== 56 | 57 | //! constructor 58 | ProfileManager::ProfileManager( QObject* _parent ) 59 | : QObject ( _parent ) 60 | { 61 | 62 | } 63 | 64 | //! startProfile 65 | void ProfileManager::startProfile( const QString& _name ) 66 | { 67 | PCORE_LOG_TRACE_FUNC_START(); 68 | 69 | auto it = m_Map.find( _name ); 70 | 71 | 72 | if ( it != m_Map.end() ) 73 | { 74 | it.value()->lock.lock(); 75 | it.value()->call_num++; 76 | it.value()->pending_count++; 77 | 78 | if ( it.value()->is_started != true ) 79 | { 80 | // optimize: it could be replaced by more accurate function 81 | it.value()->last_time = QDateTime::currentMSecsSinceEpoch(); 82 | } 83 | 84 | it.value()->is_started = true; 85 | it.value()->lock.unlock(); 86 | } 87 | else 88 | { 89 | m_MapLock.lock(); 90 | Profile* p = new Profile(); 91 | p->name = _name; 92 | p->call_num = 1; 93 | p->pending_count =1; 94 | p->last_time = QDateTime::currentMSecsSinceEpoch(); 95 | m_Map[_name] = p; 96 | m_MapLock.unlock(); 97 | } 98 | } 99 | 100 | //! stopProfile 101 | quint64 ProfileManager::stopProfile( const QString& _name ) 102 | { 103 | PCORE_LOG_TRACE_FUNC_START(); 104 | 105 | auto it = m_Map.find( _name ); 106 | 107 | if ( it == m_Map.end() ) return 0; 108 | 109 | Profile* p = it.value(); 110 | 111 | p->lock.lock(); 112 | p->pending_count--; 113 | 114 | quint64 elapsed_time = \ 115 | QDateTime::currentMSecsSinceEpoch() - p->last_time; 116 | 117 | if ( it.value()->pending_count == 0 ) 118 | { 119 | 120 | p->total_time += elapsed_time; 121 | p->is_started = false; 122 | 123 | if ( elapsed_time > p->max_time ) p->max_time = elapsed_time; 124 | if ( elapsed_time < p->min_time ) p->min_time = elapsed_time; 125 | } 126 | 127 | it.value()->lock.unlock(); 128 | 129 | return elapsed_time; 130 | } 131 | 132 | 133 | //! getProfiles 134 | ProfileManager::ProfileMap ProfileManager::getProfiles() const 135 | { 136 | PCORE_LOG_TRACE_FUNC_START(); 137 | return m_Map; 138 | } 139 | 140 | 141 | //! printToFile 142 | bool ProfileManager::printToFile( const QString& _filename ) 143 | { 144 | PCORE_LOG_TRACE_FUNC_START(); 145 | try 146 | { 147 | m_MapLock.lock(); 148 | QFile f( _filename ); 149 | 150 | if ( f.open(QFile::WriteOnly ) == false ) 151 | { 152 | PCORE_LOG_ERROR( "Saving profiles to '"+_filename+"' failed." ); 153 | m_MapLock.unlock(); 154 | return false; 155 | } 156 | 157 | QTextStream st(&f); 158 | 159 | st << "name, call num, total time, max time, min time" << 160 | PCORE_NEW_LINE; 161 | 162 | for ( auto it : m_Map ) 163 | { 164 | st << it->name << ", " << it->call_num << ", " << \ 165 | it->total_time << ", " << it->max_time << ", " << \ 166 | it->min_time << PCORE_NEW_LINE; 167 | } 168 | 169 | st.flush(); 170 | f.close(); 171 | 172 | m_MapLock.unlock(); 173 | 174 | } 175 | catch( ... ) 176 | { 177 | PCORE_LOG_ERROR( "Unexpected Error in saving profiles in " + _filename ); 178 | m_MapLock.unlock(); 179 | return false; 180 | } 181 | 182 | return true; 183 | } 184 | 185 | 186 | } // core 187 | } // PCore 188 | 189 | -------------------------------------------------------------------------------- /lib/source/core/system_info/sys_info_amd.cpp: -------------------------------------------------------------------------------- 1 | //############################################################################## 2 | //# title: System informatio fro AMD's processors 3 | //# c-date: Apr-22-2016 4 | //# author: Pouya Shahinfar (Pswin) - pswinpo@gmail.com 5 | //############################################################################## 6 | 7 | #include "headers/core/arch/amd/sys_info/sys_info_amd.h" 8 | 9 | #if PCORE_ARCH_FAMILY == PCORE_ARCH_FAMILY_X86 && \ 10 | PCORE_OS == PCORE_OS_WINDOWS 11 | 12 | #include 13 | #include 14 | 15 | //============================================================================== 16 | // macros 17 | //============================================================================== 18 | 19 | #define _HELPER_CHECK_AND_ADD( __ar, __val, __pos, __name ) \ 20 | if ( PCORE_BIT_CHECK( __val, __pos ) == true ) \ 21 | {__ar.push_back( __name );} 22 | 23 | 24 | //============================================================================== 25 | // functions 26 | //============================================================================== 27 | 28 | //! get_amd_cpuid_info 29 | AMDCPUIDInformation get_amd_cpuid_info( void ) 30 | { 31 | 32 | quint32 regs[4]; 33 | AMDCPUIDInformation info; 34 | 35 | __cpuid( (int *)regs, (int)1 ); 36 | 37 | 38 | 39 | //-------------------------------- 40 | // Feature Identifiers 41 | //-------------------------------- 42 | 43 | // brand id for older processors of Intel 44 | info.brand_id = PCORE_BIT_READ( regs[1], 0, 8 ); 45 | 46 | // signature details 47 | info.stepping = (quint16)PCORE_BIT_READ( regs[0], 0, 4 ); 48 | info.model = (quint16)PCORE_BIT_READ( regs[0], 4, 4 ); 49 | info.family = (quint16)PCORE_BIT_READ( regs[0], 8, 4 ); 50 | info.extended_model = (quint16)PCORE_BIT_READ( regs[0], 16, 4 ); 51 | info.extended_family= (quint16)PCORE_BIT_READ( regs[0], 20, 8 ); 52 | 53 | // reading extensions 54 | // EDX 55 | _HELPER_CHECK_AND_ADD( info.extensions, regs[3], 0, "fpu" ); 56 | _HELPER_CHECK_AND_ADD( info.extensions, regs[3], 1, "vme" ); 57 | _HELPER_CHECK_AND_ADD( info.extensions, regs[3], 2, "de" ); 58 | _HELPER_CHECK_AND_ADD( info.extensions, regs[3], 3, "pse" ); 59 | _HELPER_CHECK_AND_ADD( info.extensions, regs[3], 4, "tsc" ); 60 | _HELPER_CHECK_AND_ADD( info.extensions, regs[3], 5, "msr" ); 61 | _HELPER_CHECK_AND_ADD( info.extensions, regs[3], 6, "pae" ); 62 | _HELPER_CHECK_AND_ADD( info.extensions, regs[3], 7, "mce" ); 63 | _HELPER_CHECK_AND_ADD( info.extensions, regs[3], 8, "cx8" ); 64 | _HELPER_CHECK_AND_ADD( info.extensions, regs[3], 9, "apic" ); 65 | _HELPER_CHECK_AND_ADD( info.extensions, regs[3], 11, "sep" ); 66 | _HELPER_CHECK_AND_ADD( info.extensions, regs[3], 12, "mtrr" ); 67 | _HELPER_CHECK_AND_ADD( info.extensions, regs[3], 13, "pge" ); 68 | _HELPER_CHECK_AND_ADD( info.extensions, regs[3], 14, "mca" ); 69 | _HELPER_CHECK_AND_ADD( info.extensions, regs[3], 15, "cmov" ); 70 | _HELPER_CHECK_AND_ADD( info.extensions, regs[3], 16, "pat" ); 71 | _HELPER_CHECK_AND_ADD( info.extensions, regs[3], 17, "pse-36" ); 72 | //_HELPER_CHECK_AND_ADD( info.extensions, regs[3], 18, "psn" ); 73 | _HELPER_CHECK_AND_ADD( info.extensions, regs[3], 19, "clfsh" ); 74 | //_HELPER_CHECK_AND_ADD( info.extensions, regs[3], 21, "ds" ); 75 | //_HELPER_CHECK_AND_ADD( info.extensions, regs[3], 22, "acpi" ); 76 | _HELPER_CHECK_AND_ADD( info.extensions, regs[3], 23, "mmx" ); 77 | _HELPER_CHECK_AND_ADD( info.extensions, regs[3], 24, "fxsr" ); 78 | _HELPER_CHECK_AND_ADD( info.extensions, regs[3], 25, "sse" ); 79 | _HELPER_CHECK_AND_ADD( info.extensions, regs[3], 26, "sse2" ); 80 | //_HELPER_CHECK_AND_ADD( info.extensions, regs[3], 27, "ss" ); 81 | _HELPER_CHECK_AND_ADD( info.extensions, regs[3], 28, "htt" ); 82 | //_HELPER_CHECK_AND_ADD( info.extensions, regs[3], 29, "tm" ); 83 | //_HELPER_CHECK_AND_ADD( info.extensions, regs[3], 30, "ia64" ); 84 | //_HELPER_CHECK_AND_ADD( info.extensions, regs[3], 31, "pbe" ); 85 | 86 | // ECX 87 | _HELPER_CHECK_AND_ADD( info.extensions, regs[2], 0, "sse3" ); 88 | _HELPER_CHECK_AND_ADD( info.extensions, regs[2], 1, "pclmulqdq" ); 89 | //_HELPER_CHECK_AND_ADD( info.extensions, regs[2], 2, "dtes64" ); 90 | _HELPER_CHECK_AND_ADD( info.extensions, regs[2], 3, "monitor" ); 91 | //_HELPER_CHECK_AND_ADD( info.extensions, regs[2], 4, "ds-cpl" ); 92 | //_HELPER_CHECK_AND_ADD( info.extensions, regs[2], 5, "vmx" ); 93 | //_HELPER_CHECK_AND_ADD( info.extensions, regs[2], 6, "smx" ); 94 | //_HELPER_CHECK_AND_ADD( info.extensions, regs[2], 7, "est" ); 95 | //_HELPER_CHECK_AND_ADD( info.extensions, regs[2], 8, "tm2" ); 96 | _HELPER_CHECK_AND_ADD( info.extensions, regs[2], 9, "ssse3" ); 97 | //_HELPER_CHECK_AND_ADD( info.extensions, regs[2], 10, "cnxt-id" ); 98 | //_HELPER_CHECK_AND_ADD( info.extensions, regs[2], 11, "sdbg" ); 99 | _HELPER_CHECK_AND_ADD( info.extensions, regs[2], 12, "fma" ); 100 | _HELPER_CHECK_AND_ADD( info.extensions, regs[2], 13, "cx16" ); 101 | //_HELPER_CHECK_AND_ADD( info.extensions, regs[2], 14, "xtpr" ); 102 | //_HELPER_CHECK_AND_ADD( info.extensions, regs[2], 15, "pdcm" ); 103 | //_HELPER_CHECK_AND_ADD( info.extensions, regs[2], 17, "pcid" ); 104 | //_HELPER_CHECK_AND_ADD( info.extensions, regs[2], 18, "dca" ); 105 | _HELPER_CHECK_AND_ADD( info.extensions, regs[2], 19, "sse4.1" ); 106 | _HELPER_CHECK_AND_ADD( info.extensions, regs[2], 20, "sse4.2" ); 107 | //_HELPER_CHECK_AND_ADD( info.extensions, regs[2], 21, "x2apic" ); 108 | //_HELPER_CHECK_AND_ADD( info.extensions, regs[2], 22, "movbe" ); 109 | _HELPER_CHECK_AND_ADD( info.extensions, regs[2], 23, "popcnt" ); 110 | //_HELPER_CHECK_AND_ADD( info.extensions, regs[2], 24, "tsc-deadline" ); 111 | _HELPER_CHECK_AND_ADD( info.extensions, regs[2], 25, "aes" ); 112 | _HELPER_CHECK_AND_ADD( info.extensions, regs[2], 26, "xsave" ); 113 | _HELPER_CHECK_AND_ADD( info.extensions, regs[2], 27, "osxsave" ); 114 | _HELPER_CHECK_AND_ADD( info.extensions, regs[2], 28, "avx" ); 115 | _HELPER_CHECK_AND_ADD( info.extensions, regs[2], 29, "f16c" ); 116 | //_HELPER_CHECK_AND_ADD( info.extensions, regs[2], 30, "rdrnd" ); 117 | _HELPER_CHECK_AND_ADD( info.extensions, regs[2], 31, "hypervisor" ); 118 | 119 | 120 | //-------------------------------- 121 | // Extended Feature Identifiers 122 | //-------------------------------- 123 | 124 | __cpuid( (int *)regs, 0x80000001 ); 125 | 126 | info.brand_id_ex = PCORE_BIT_READ( regs[1], 0 , 16 ); 127 | 128 | // ECX 129 | _HELPER_CHECK_AND_ADD( info.extensions, regs[2], 0, "LahfSahf" ); 130 | _HELPER_CHECK_AND_ADD( info.extensions, regs[2], 1, "CmpLegacy" ); 131 | _HELPER_CHECK_AND_ADD( info.extensions, regs[2], 2, "SVM" ); 132 | _HELPER_CHECK_AND_ADD( info.extensions, regs[2], 3, "ExtApicSpace" ); 133 | _HELPER_CHECK_AND_ADD( info.extensions, regs[2], 4, "AltMovCr8" ); 134 | _HELPER_CHECK_AND_ADD( info.extensions, regs[2], 5, "ABM" ); 135 | _HELPER_CHECK_AND_ADD( info.extensions, regs[2], 6, "SSE4A" ); 136 | _HELPER_CHECK_AND_ADD( info.extensions, regs[2], 7, "MisAlignSse" ); 137 | _HELPER_CHECK_AND_ADD( info.extensions, regs[2], 8, "3DNowPrefetch" ); 138 | _HELPER_CHECK_AND_ADD( info.extensions, regs[2], 9, "OSVW" ); 139 | _HELPER_CHECK_AND_ADD( info.extensions, regs[2], 10, "IBS" ); 140 | _HELPER_CHECK_AND_ADD( info.extensions, regs[2], 11, "XOP" ); 141 | _HELPER_CHECK_AND_ADD( info.extensions, regs[2], 12, "SKINIT" ); 142 | _HELPER_CHECK_AND_ADD( info.extensions, regs[2], 13, "WDT" ); 143 | _HELPER_CHECK_AND_ADD( info.extensions, regs[2], 15, "LWP" ); 144 | _HELPER_CHECK_AND_ADD( info.extensions, regs[2], 16, "FMA4" ); 145 | _HELPER_CHECK_AND_ADD( info.extensions, regs[2], 19, "NodeId" ); 146 | _HELPER_CHECK_AND_ADD( info.extensions, regs[2], 21, "TBM" ); 147 | _HELPER_CHECK_AND_ADD( info.extensions, regs[2], 22, "TopologyExtensions" ); 148 | 149 | // EDX 150 | _HELPER_CHECK_AND_ADD( info.extensions, regs[3], 11, "SysCallSysRet" ); 151 | _HELPER_CHECK_AND_ADD( info.extensions, regs[3], 20, "NX" ); 152 | _HELPER_CHECK_AND_ADD( info.extensions, regs[3], 22, "MmxExt" ); 153 | _HELPER_CHECK_AND_ADD( info.extensions, regs[3], 25, "FFXSR" ); 154 | _HELPER_CHECK_AND_ADD( info.extensions, regs[3], 26, "Page1GB" ); 155 | _HELPER_CHECK_AND_ADD( info.extensions, regs[3], 27, "RDTSCP" ); 156 | _HELPER_CHECK_AND_ADD( info.extensions, regs[3], 29, "LM" ); 157 | _HELPER_CHECK_AND_ADD( info.extensions, regs[3], 30, "3DNowExt" ); 158 | _HELPER_CHECK_AND_ADD( info.extensions, regs[3], 31, "3DNow" ); 159 | 160 | 161 | //-------------------------------- 162 | // Cache and TLB 163 | //-------------------------------- 164 | 165 | // L1 166 | __cpuid( (int *)regs, 0x80000005 ); 167 | 168 | info.cache_l1_size_data = PCORE_BIT_READ( regs[2], 24, 8 ) * 1024; 169 | info.cache_l1_size_instruction = PCORE_BIT_READ( regs[3], 24, 8 ) * 1024; 170 | info.cache_l1_size = info.cache_l1_size_instruction + info.cache_l1_size_data; 171 | 172 | 173 | // L2. L3 174 | __cpuid( (int *)regs, 0x80000006 ); 175 | 176 | info.cache_l2_size = PCORE_BIT_READ( regs[2], 16, 16 ); 177 | info.cache_l3_size = PCORE_BIT_READ(regs[3], 18, 14 ) * 512; 178 | 179 | return info; 180 | 181 | } // get_cpuid_info 182 | 183 | 184 | 185 | #endif // PCORE_ARCH_FAMILY_X86 && PCORE_OS_WINDOWS 186 | 187 | -------------------------------------------------------------------------------- /lib/source/core/system_info/sys_info_global.cpp: -------------------------------------------------------------------------------- 1 | //############################################################################## 2 | //# title: Global methods for system info 3 | //# c-date: May-19-2016 4 | //# author: Pouya Shahinfar (Pswin) - pswinpo@gmail.com 5 | //############################################################################## 6 | 7 | #include "include/pcore/core/system_information.h" 8 | 9 | 10 | namespace PCore 11 | { 12 | namespace core 13 | { 14 | 15 | //====================================================================== 16 | // Processor 17 | //====================================================================== 18 | 19 | //! Processor::Architecture 20 | QString SystemInformation::Processor::getString( 21 | SystemInformation::Processor::Architecture _arch ) 22 | { 23 | switch ( _arch ) 24 | { 25 | case SystemInformation::Processor::Architecture::X86: 26 | return "X86"; 27 | case SystemInformation::Processor::Architecture::X86_64: 28 | return "X86-64"; 29 | case SystemInformation::Processor::Architecture::ARM: 30 | return "ARM"; 31 | case SystemInformation::Processor::Architecture::ARM_64: 32 | return "64-bit ARM"; 33 | case SystemInformation::Processor::Architecture::MIPS: 34 | return "MIPS"; 35 | case SystemInformation::Processor::Architecture::MIPS_64: 36 | return "64-bit MIPS"; 37 | case SystemInformation::Processor::Architecture::PowerPC: 38 | return "PowerPC"; 39 | case SystemInformation::Processor::Architecture::PowerPC_64: 40 | return "64-bit PowerPC"; 41 | case SystemInformation::Processor::Architecture::SPARC: 42 | return "SPARC"; 43 | case SystemInformation::Processor::Architecture::SPARC_64: 44 | return "64-bit SPARC"; 45 | case SystemInformation::Processor::Architecture::Other: 46 | case SystemInformation::Processor::Architecture::Unkown: 47 | default: 48 | return "Unkonown"; 49 | } 50 | } // Processor::Architecture 51 | 52 | 53 | //! Processor::PowerMode 54 | QString SystemInformation::Processor::getString( 55 | SystemInformation::Processor::PowerMode _mode) 56 | { 57 | switch ( _mode ) 58 | { 59 | case SystemInformation::Processor::PowerMode::Preformance: 60 | return "Performance"; 61 | case SystemInformation::Processor::PowerMode::Powersave: 62 | return "Powersave"; 63 | case SystemInformation::Processor::PowerMode::Unkown: 64 | default: 65 | return "Unkown"; 66 | } 67 | } // Processor::PowerMode 68 | 69 | 70 | //====================================================================== 71 | // Storage 72 | //====================================================================== 73 | 74 | //! getString ( Storage::Interface ) 75 | QString SystemInformation::Storage::getString( 76 | SystemInformation::Storage::Interface _interface ) 77 | { 78 | switch ( _interface ) 79 | { 80 | case SystemInformation::Storage::Interface::HDC: 81 | return "HDC"; 82 | case SystemInformation::Storage::Interface::ATA: 83 | return "IDE"; 84 | case SystemInformation::Storage::Interface::SATA: 85 | return "SATA"; 86 | case SystemInformation::Storage::Interface::SCSI: 87 | return "SCSI"; 88 | case SystemInformation::Storage::Interface::USB: 89 | return "USB"; 90 | case SystemInformation::Storage::Interface::_1394: 91 | return "1394"; 92 | case SystemInformation::Storage::Interface::Unknown: 93 | default: 94 | return "Unknown"; 95 | } 96 | } // getString( Storage::Interface ) 97 | 98 | //! getString ( Storage::Type ) 99 | QString SystemInformation::Storage::getString( 100 | SystemInformation::Storage::Type _type) 101 | { 102 | switch ( _type ) 103 | { 104 | case SystemInformation::Storage::Type::ExternalDisk: 105 | return "External hard disk"; 106 | case SystemInformation::Storage::Type::FixedDisk: 107 | return "Fixed hard disk"; 108 | case SystemInformation::Storage::Type::FlashDisk: 109 | return "USB flash drive"; 110 | case SystemInformation::Storage::Type::Floppy: 111 | return "Floppy disk"; 112 | case SystemInformation::Storage::Type::Tape: 113 | return "Tape"; 114 | case SystemInformation::Storage::Type::RemovableMedia: 115 | return "Removable media"; 116 | case SystemInformation::Storage::Type::Unknown: 117 | default: 118 | return "Unkown"; 119 | } 120 | } // getString( Storage::Type ) 121 | 122 | } // Core 123 | } // PCore 124 | 125 | -------------------------------------------------------------------------------- /lib/source/core/system_info/sys_info_intel.cpp: -------------------------------------------------------------------------------- 1 | //############################################################################## 2 | //# c-date: Apr-21-2016 3 | //# author: Pouya Shahinfar (Pswin) - pswinpo@gmail.com 4 | //############################################################################## 5 | 6 | #include "headers/core/arch/intel/sys_info/sys_info_intel.h" 7 | #include "include/pcore/pcore_def.h" 8 | 9 | #if ( PCORE_ARCH_FAMILY == PCORE_ARCH_FAMILY_X86 ) \ 10 | && ( PCORE_OS == PCORE_OS_WINDOWS) 11 | 12 | #include 13 | #include 14 | 15 | 16 | //============================================================================== 17 | // macros 18 | //============================================================================== 19 | 20 | #define _HELPER_CHECK_AND_ADD( __ar, __val, __pos, __name ) \ 21 | if ( PCORE_BIT_CHECK( __val, __pos ) == true ) \ 22 | {__ar.push_back( __name );} 23 | 24 | 25 | //============================================================================== 26 | // functions 27 | //============================================================================== 28 | 29 | //! intel_get_arch_name 30 | QString intel_get_arch_name( quint32 _signature ) 31 | { 32 | PCORE_BIT_WRITE( _signature, 0, 4 , 0 ); 33 | 34 | switch ( _signature ) 35 | { 36 | case 0x306A0: 37 | return "IvyBridge"; 38 | case 0x206A0: 39 | case 0x206D0: 40 | return "SandyBridge"; 41 | case 0x20650: 42 | case 0x206C0: 43 | case 0x206F0: 44 | return "Westmere"; 45 | case 0x106E0: 46 | case 0x106A0: 47 | case 0x206E0: 48 | return "Nehalem"; 49 | case 0x10670: 50 | case 0x106D0: 51 | return "Penryn"; 52 | case 0x006F0: 53 | case 0x10660: 54 | return "Merom"; 55 | case 0x00660: 56 | return "Presler"; 57 | case 0x00630: 58 | case 0x00640: 59 | return "Prescott"; 60 | case 0x006D0: 61 | return "Dothan"; 62 | case 0x03660: 63 | case 0x02660: 64 | case 0x016C0: 65 | return "Atom™"; 66 | default: 67 | return ""; 68 | } 69 | } // intel_get_brand_name 70 | 71 | 72 | /*! 73 | * \brief Executes CPUID and return CPUID's information about processor 74 | */ 75 | IntelCPUIDInformation get_intel_cpuid_info( void ) 76 | { 77 | 78 | quint32 regs[4]; 79 | IntelCPUIDInformation info; 80 | 81 | __cpuid( (int *)regs, (int)1 ); 82 | 83 | // brand id for older processors of Intel 84 | info.brand_id = PCORE_BIT_READ( regs[1], 0, 8 ); 85 | 86 | // signature details 87 | info.stepping = (quint16)PCORE_BIT_READ( regs[0], 0, 4 ); 88 | info.model = (quint16)PCORE_BIT_READ( regs[0], 4, 4 ); 89 | info.family = (quint16)PCORE_BIT_READ( regs[0], 8, 4 ); 90 | info.processor_type = (quint16)PCORE_BIT_READ( regs[0], 12, 2 ); 91 | info.extended_model = (quint16)PCORE_BIT_READ( regs[0], 16, 4 ); 92 | info.extended_family= (quint16)PCORE_BIT_READ( regs[0], 20, 8 ); 93 | 94 | // signature 95 | info.signature = QString::number( regs[0], 16 ); 96 | 97 | // reading extensions 98 | 99 | // EDX 100 | _HELPER_CHECK_AND_ADD( info.extensions, regs[3], 0, "fpu" ); 101 | _HELPER_CHECK_AND_ADD( info.extensions, regs[3], 1, "vme" ); 102 | _HELPER_CHECK_AND_ADD( info.extensions, regs[3], 2, "de" ); 103 | _HELPER_CHECK_AND_ADD( info.extensions, regs[3], 3, "pse" ); 104 | _HELPER_CHECK_AND_ADD( info.extensions, regs[3], 4, "tsc" ); 105 | _HELPER_CHECK_AND_ADD( info.extensions, regs[3], 5, "msr" ); 106 | _HELPER_CHECK_AND_ADD( info.extensions, regs[3], 6, "pae" ); 107 | _HELPER_CHECK_AND_ADD( info.extensions, regs[3], 7, "mce" ); 108 | _HELPER_CHECK_AND_ADD( info.extensions, regs[3], 8, "cx8" ); 109 | _HELPER_CHECK_AND_ADD( info.extensions, regs[3], 9, "apic" ); 110 | _HELPER_CHECK_AND_ADD( info.extensions, regs[3], 11, "sep" ); 111 | _HELPER_CHECK_AND_ADD( info.extensions, regs[3], 12, "mtrr" ); 112 | _HELPER_CHECK_AND_ADD( info.extensions, regs[3], 13, "pge" ); 113 | _HELPER_CHECK_AND_ADD( info.extensions, regs[3], 14, "mca" ); 114 | _HELPER_CHECK_AND_ADD( info.extensions, regs[3], 15, "cmov" ); 115 | _HELPER_CHECK_AND_ADD( info.extensions, regs[3], 16, "pat" ); 116 | _HELPER_CHECK_AND_ADD( info.extensions, regs[3], 17, "pse-36" ); 117 | _HELPER_CHECK_AND_ADD( info.extensions, regs[3], 18, "psn" ); 118 | _HELPER_CHECK_AND_ADD( info.extensions, regs[3], 19, "clfsh" ); 119 | _HELPER_CHECK_AND_ADD( info.extensions, regs[3], 21, "ds" ); 120 | _HELPER_CHECK_AND_ADD( info.extensions, regs[3], 22, "acpi" ); 121 | _HELPER_CHECK_AND_ADD( info.extensions, regs[3], 23, "mmx" ); 122 | _HELPER_CHECK_AND_ADD( info.extensions, regs[3], 24, "fxsr" ); 123 | _HELPER_CHECK_AND_ADD( info.extensions, regs[3], 25, "sse" ); 124 | _HELPER_CHECK_AND_ADD( info.extensions, regs[3], 26, "sse2" ); 125 | _HELPER_CHECK_AND_ADD( info.extensions, regs[3], 27, "ss" ); 126 | _HELPER_CHECK_AND_ADD( info.extensions, regs[3], 28, "htt" ); 127 | _HELPER_CHECK_AND_ADD( info.extensions, regs[3], 29, "tm" ); 128 | _HELPER_CHECK_AND_ADD( info.extensions, regs[3], 30, "ia64" ); 129 | _HELPER_CHECK_AND_ADD( info.extensions, regs[3], 31, "pbe" ); 130 | 131 | // ECX 132 | _HELPER_CHECK_AND_ADD( info.extensions, regs[2], 0, "sse3" ); 133 | _HELPER_CHECK_AND_ADD( info.extensions, regs[2], 1, "pclmulqdq" ); 134 | _HELPER_CHECK_AND_ADD( info.extensions, regs[2], 2, "dtes64" ); 135 | _HELPER_CHECK_AND_ADD( info.extensions, regs[2], 3, "monitor" ); 136 | _HELPER_CHECK_AND_ADD( info.extensions, regs[2], 4, "ds-cpl" ); 137 | _HELPER_CHECK_AND_ADD( info.extensions, regs[2], 5, "vmx" ); 138 | _HELPER_CHECK_AND_ADD( info.extensions, regs[2], 6, "smx" ); 139 | _HELPER_CHECK_AND_ADD( info.extensions, regs[2], 7, "est" ); 140 | _HELPER_CHECK_AND_ADD( info.extensions, regs[2], 8, "tm2" ); 141 | _HELPER_CHECK_AND_ADD( info.extensions, regs[2], 9, "ssse3" ); 142 | _HELPER_CHECK_AND_ADD( info.extensions, regs[2], 10, "cnxt-id" ); 143 | _HELPER_CHECK_AND_ADD( info.extensions, regs[2], 11, "sdbg" ); 144 | _HELPER_CHECK_AND_ADD( info.extensions, regs[2], 12, "fma" ); 145 | _HELPER_CHECK_AND_ADD( info.extensions, regs[2], 13, "cx16" ); 146 | _HELPER_CHECK_AND_ADD( info.extensions, regs[2], 14, "xtpr" ); 147 | _HELPER_CHECK_AND_ADD( info.extensions, regs[2], 15, "pdcm" ); 148 | _HELPER_CHECK_AND_ADD( info.extensions, regs[2], 17, "pcid" ); 149 | _HELPER_CHECK_AND_ADD( info.extensions, regs[2], 18, "dca" ); 150 | _HELPER_CHECK_AND_ADD( info.extensions, regs[2], 19, "sse4.1" ); 151 | _HELPER_CHECK_AND_ADD( info.extensions, regs[2], 20, "sse4.2" ); 152 | _HELPER_CHECK_AND_ADD( info.extensions, regs[2], 21, "x2apic" ); 153 | _HELPER_CHECK_AND_ADD( info.extensions, regs[2], 22, "movbe" ); 154 | _HELPER_CHECK_AND_ADD( info.extensions, regs[2], 23, "popcnt" ); 155 | _HELPER_CHECK_AND_ADD( info.extensions, regs[2], 24, "tsc-deadline" ); 156 | _HELPER_CHECK_AND_ADD( info.extensions, regs[2], 25, "aes" ); 157 | _HELPER_CHECK_AND_ADD( info.extensions, regs[2], 26, "xsave" ); 158 | _HELPER_CHECK_AND_ADD( info.extensions, regs[2], 27, "osxsave" ); 159 | _HELPER_CHECK_AND_ADD( info.extensions, regs[2], 28, "avx" ); 160 | _HELPER_CHECK_AND_ADD( info.extensions, regs[2], 29, "f16c" ); 161 | _HELPER_CHECK_AND_ADD( info.extensions, regs[2], 30, "rdrnd" ); 162 | _HELPER_CHECK_AND_ADD( info.extensions, regs[2], 31, "hypervisor" ); 163 | 164 | return info; 165 | 166 | } // get_cpuid_info 167 | 168 | #endif // PCORE_ARCH_FAMILY_X86 && PCORE_OS_WINDOWS 169 | 170 | -------------------------------------------------------------------------------- /lib/source/cryptography/cryptography_engine.cpp: -------------------------------------------------------------------------------- 1 | 2 | 3 | #include "headers/cryptography/cryptography_engine.h" 4 | #include 5 | #include 6 | #include 7 | 8 | namespace PCore 9 | { 10 | namespace cryptography 11 | { 12 | 13 | // init 14 | bool CryptographyEngine::init( void ) 15 | { 16 | /* Initialise the library */ 17 | ERR_load_CRYPTO_strings(); 18 | OpenSSL_add_all_algorithms(); 19 | OPENSSL_config( NULL ); 20 | 21 | return true; 22 | } 23 | 24 | // shutdown 25 | bool CryptographyEngine::shutdown() 26 | { 27 | EVP_cleanup(); 28 | ERR_free_strings(); 29 | 30 | return true; 31 | } 32 | 33 | } // cryptography 34 | } // PCore 35 | 36 | -------------------------------------------------------------------------------- /lib/source/cryptography/des.cpp: -------------------------------------------------------------------------------- 1 | //############################################################################## 2 | //# c-date: Jun-09-2016 3 | //# author: Pouya Shahinfar (Pswin) - pswinpo@gmail.com 4 | //############################################################################## 5 | 6 | 7 | //============================================================================== 8 | // includes 9 | //============================================================================== 10 | 11 | #include "include/pcore/cryptography/des.h" 12 | #include "include/pcore/core/logger.h" 13 | #include "include/pcore/math/random.h" 14 | #include 15 | #include 16 | 17 | 18 | //============================================================================== 19 | // macros 20 | //============================================================================== 21 | 22 | //! Block size 23 | #define PCORE_DES_BLOCK_SIZE 8 24 | 25 | //! helper macro for calculating block size 26 | #define _PCORE_HELPER_TO_BLOCK(__size,__block_size )\ 27 | (((__size+__block_size)/__block_size) * __block_size ) 28 | 29 | 30 | //============================================================================== 31 | // code 32 | //============================================================================== 33 | 34 | namespace PCore 35 | { 36 | namespace cryptography 37 | { 38 | 39 | //! constructor 40 | DES::DES( QObject* _parent ) : 41 | QObject( _parent ) 42 | { 43 | 44 | } 45 | 46 | 47 | //! setPass 48 | void DES::setPass( const QByteArray& _pass ) 49 | { 50 | m_Pass = _pass; 51 | } 52 | 53 | 54 | //! getPass 55 | QByteArray DES::getPass() const 56 | { 57 | return m_Pass; 58 | } 59 | 60 | 61 | //! setIV 62 | void DES::setIV(const QByteArray& _iv) 63 | { 64 | m_IV = _iv; 65 | } 66 | 67 | //! getIV 68 | QByteArray DES::getIV( void ) const 69 | { 70 | return m_IV; 71 | } 72 | 73 | 74 | //! encrypt 75 | QByteArray DES::encrypt( const QByteArray& _data ) 76 | { 77 | return DES::encryptEX( m_Pass, m_IV, _data ); 78 | } 79 | 80 | 81 | //! decrypt 82 | QByteArray DES::decrypt(const QByteArray& _data) 83 | { 84 | return DES::decryptEX( m_Pass, m_IV, _data ); 85 | } 86 | 87 | 88 | //====================================================================== 89 | // Static mthods 90 | //====================================================================== 91 | 92 | //! encryptEX 93 | QByteArray DES::encryptEX( const QByteArray& _pass, 94 | QByteArray& _iv, 95 | const QByteArray& _data ) 96 | { 97 | if ( _pass.length() < 8 ) 98 | { 99 | PCORE_LOG_ERROR( "DES failed.Key must be at least 8 characters." ); 100 | return QByteArray(); 101 | } 102 | 103 | 104 | if ( _iv.isEmpty() == true ) 105 | { 106 | _iv = math::Random::randomByteArray( PCORE_DES_BLOCK_SIZE ); 107 | 108 | } 109 | else 110 | { 111 | if ( _iv.size() != PCORE_DES_BLOCK_SIZE ) 112 | { 113 | PCORE_LOG_ERROR( "DES failed. IVEC must be at least 8 characters." ); 114 | return QByteArray(); 115 | } 116 | } 117 | 118 | // ivec 119 | DES_cblock iv; 120 | memcpy( iv, _iv.constData(), PCORE_DES_BLOCK_SIZE ); 121 | 122 | 123 | DES_cblock key_2; 124 | DES_key_schedule schedule; 125 | int out_len = _PCORE_HELPER_TO_BLOCK( _data.size(), PCORE_DES_BLOCK_SIZE ) ; 126 | unsigned char *out = new unsigned char[ _data.size() ]; 127 | memset( out, 0, out_len ); 128 | 129 | 130 | // Prepare the key 131 | memcpy( key_2, _pass.constData() , PCORE_DES_BLOCK_SIZE ); 132 | DES_set_odd_parity( &key_2 ); 133 | if ( DES_set_key_checked( &key_2, &schedule ) != 0 ) 134 | { 135 | PCORE_LOG_ERROR( "DES failed; cannot set key." ); 136 | return QByteArray(); 137 | } 138 | 139 | // Encryption 140 | DES_ncbc_encrypt( (unsigned char*)_data.constData(), out, 141 | _data.size() , &schedule, &iv, DES_ENCRYPT ); 142 | 143 | QByteArray ar( (const char*)out, out_len ); 144 | delete[] out; 145 | return ar; 146 | } // encryptEX 147 | 148 | 149 | //! decryptEX 150 | QByteArray DES::decryptEX( const QByteArray& _pass, 151 | const QByteArray& _iv, 152 | const QByteArray& _data ) 153 | { 154 | if ( _pass.length() < 8 ) 155 | { 156 | PCORE_LOG_ERROR( "DES failed.Key must be at least 8 characters." ); 157 | return QByteArray(); 158 | } 159 | 160 | if ( _iv.size() != PCORE_DES_BLOCK_SIZE ) 161 | { 162 | PCORE_LOG_ERROR( "DES failed.IVEC must be at least 8 characters." ); 163 | return QByteArray(); 164 | } 165 | 166 | // ivec 167 | DES_cblock iv; 168 | memcpy( iv, _iv.constData(), PCORE_DES_BLOCK_SIZE ); 169 | 170 | 171 | DES_cblock key_2; 172 | DES_key_schedule schedule; 173 | int out_len = _PCORE_HELPER_TO_BLOCK( _data.size(), PCORE_DES_BLOCK_SIZE ) ; 174 | unsigned char *out = new unsigned char[ out_len ]; 175 | memset( out, 0, out_len ); 176 | 177 | // Prepare the key 178 | memcpy( key_2, _pass.data() , PCORE_DES_BLOCK_SIZE ); 179 | DES_set_odd_parity( &key_2 ); 180 | if ( DES_set_key_checked( &key_2, &schedule ) != 0 ) 181 | { 182 | PCORE_LOG_ERROR( "DES failed. Cannot set key." ); 183 | return QByteArray(); 184 | } 185 | 186 | // Decryption 187 | DES_ncbc_encrypt( (unsigned char *)_data.constData(), out, _data.size(), 188 | &schedule, &iv, DES_DECRYPT ); 189 | 190 | QByteArray ar( (const char*)out ); 191 | delete[] out; 192 | return ar; 193 | } // decryptEX 194 | 195 | } // cryptography 196 | } // PCore 197 | 198 | -------------------------------------------------------------------------------- /lib/source/cryptography/rsa.cpp: -------------------------------------------------------------------------------- 1 | //############################################################################## 2 | //# c-date: Jun-09-2016 3 | //# author: Pouya Shahinfar (Pswin) - pswinpo@gmail.com 4 | //############################################################################## 5 | 6 | #include "include/pcore/cryptography/rsa.h" 7 | #include "include/pcore/core/logger.h" 8 | #include 9 | #include 10 | #include 11 | 12 | namespace PCore 13 | { 14 | namespace cryptography 15 | { 16 | //! constructor 17 | Rsa::Rsa( bool _generate_keys, QObject* _parent ) : 18 | QObject( _parent ) 19 | { 20 | if ( _generate_keys ) 21 | { 22 | if ( setPrivateKey( Rsa::generatePrivateKey( ) ) == true ) 23 | { 24 | setPublicKey( Rsa::generatePublicKey(getPrivateKey()) ); 25 | } 26 | 27 | } 28 | } //! constructor 29 | 30 | 31 | //! copy constructor 32 | Rsa::Rsa( const Rsa& _obj ) 33 | { 34 | if ( _obj.getPrivateKey().isEmpty() == false ) 35 | { 36 | setPrivateKey( _obj.getPrivateKey() ); 37 | } 38 | 39 | if ( _obj.getPublicKey().isEmpty() == false ) 40 | { 41 | setPublicKey( _obj.getPublicKey() ); 42 | } 43 | } // copy constructor 44 | 45 | 46 | //! move-constructor 47 | Rsa::Rsa( Rsa&& _obj ) 48 | { 49 | m_PrivateKey = _obj.m_PrivateKey; 50 | m_pPrvKey = _obj.m_pPrvKey; 51 | _obj.m_pPrvKey = nullptr; 52 | 53 | m_PublicKey = _obj.m_PublicKey; 54 | m_pPubKey = _obj.m_pPubKey; 55 | _obj.m_pPubKey = nullptr; 56 | } 57 | 58 | 59 | //! destructor 60 | Rsa::~Rsa() 61 | { 62 | if ( m_pPrvKey != nullptr ) 63 | { 64 | RSA_free( (RSA*)m_pPrvKey ); 65 | } 66 | 67 | if ( m_pPubKey != nullptr ) 68 | { 69 | RSA_free( (RSA*)m_pPubKey ); 70 | } 71 | } 72 | 73 | 74 | //! encrypt 75 | QByteArray Rsa::encrypt( const QByteArray& _byte_array , 76 | Padding _padding 77 | ) 78 | { 79 | if ( m_pPubKey == nullptr ) 80 | { 81 | PCORE_LOG_ERROR( "Public key is not seted, encryption failed." ); 82 | return QByteArray(); 83 | } 84 | 85 | if ( _byte_array.isNull() == true ) 86 | { 87 | PCORE_LOG_ERROR( "Input array for encryption is null." ); 88 | return QByteArray(); 89 | } 90 | 91 | int rsa_len = RSA_size( (RSA*)m_pPubKey ); 92 | 93 | unsigned char* out = new unsigned char[ rsa_len ]; 94 | 95 | int ret = RSA_public_encrypt( 96 | _byte_array.size(), 97 | (const unsigned char*)_byte_array.constData(), 98 | out, (RSA*)m_pPubKey, 99 | (int)_padding ); 100 | 101 | if ( ret == -1 ) 102 | { 103 | PCORE_LOG_ERROR( "Encryption failed for an unkown error." ); 104 | return QByteArray(); 105 | } 106 | 107 | QByteArray ar( (const char*)out, ret ); 108 | delete[] out; 109 | 110 | return ar; 111 | } // encrypt 112 | 113 | 114 | //! decrypt 115 | QByteArray Rsa::decrypt( const QByteArray& _byte_array , 116 | Padding _padding 117 | ) 118 | { 119 | if ( m_pPrvKey == nullptr ) 120 | { 121 | PCORE_LOG_ERROR( "Private key is not seted, decryption failed." ); 122 | return QByteArray(); 123 | } 124 | 125 | if ( _byte_array.isEmpty() == true ) 126 | { 127 | PCORE_LOG_ERROR( "Input array for decryption is empty." ); 128 | return QByteArray(); 129 | } 130 | 131 | int rsa_len = RSA_size( (RSA*)m_pPrvKey ); 132 | 133 | unsigned char* out = new unsigned char[ rsa_len ]; 134 | 135 | int ret = RSA_private_decrypt( 136 | _byte_array.size(), 137 | (const unsigned char*)_byte_array.constData(), 138 | out, (RSA*)m_pPrvKey, 139 | (int)_padding ); 140 | 141 | if ( ret == -1 ) 142 | { 143 | PCORE_LOG_ERROR( "Decryption failed for an unkown error." ); 144 | return QByteArray(); 145 | } 146 | 147 | QByteArray ar( (const char*)out, ret ); 148 | delete[] out; 149 | 150 | return ar; 151 | } // decrypt 152 | 153 | 154 | //! setPublicKey 155 | bool Rsa::setPublicKey( const QByteArray& _public_key ) 156 | { 157 | if ( _public_key.isEmpty() == true ) 158 | { 159 | PCORE_LOG_ERROR( "Loading public key failed, input array is empty." ); 160 | return false; 161 | } 162 | 163 | BIO* bio = BIO_new_mem_buf( (void*)_public_key.constData() , -1 ); 164 | 165 | if ( bio == nullptr ) 166 | { 167 | PCORE_LOG_ERROR( "Loading public key failed." ); 168 | return false; 169 | } 170 | 171 | BIO_set_flags( bio, BIO_FLAGS_BASE64_NO_NL ); 172 | m_pPubKey= PEM_read_bio_RSAPublicKey( bio, NULL, NULL, NULL ); 173 | 174 | if( m_pPubKey == nullptr ) 175 | { 176 | PCORE_LOG_ERROR( "Loading public key failed." ); 177 | BIO_free( bio ); 178 | return false; 179 | } 180 | 181 | m_PublicKey = _public_key; 182 | BIO_free( bio ); 183 | 184 | return true; 185 | } // setPublicKey 186 | 187 | 188 | //! getPublicKey 189 | QByteArray Rsa::getPublicKey() const 190 | { 191 | return m_PublicKey; 192 | } 193 | 194 | 195 | //! setPrivateKey 196 | bool Rsa::setPrivateKey( const QByteArray& _private_key ) 197 | { 198 | if ( _private_key.isEmpty() == true ) 199 | { 200 | PCORE_LOG_ERROR( "Loading private key failed, input array is empty." ); 201 | return false; 202 | } 203 | 204 | BIO* bio = BIO_new_mem_buf((void*)_private_key.constData(), -1); 205 | BIO_set_flags(bio, BIO_FLAGS_BASE64_NO_NL); 206 | 207 | m_pPrvKey = (void*)PEM_read_bio_RSAPrivateKey( bio, NULL, NULL, NULL ); 208 | 209 | if( m_pPrvKey == nullptr ) 210 | { 211 | PCORE_LOG_ERROR( "Loading private key failed." ); 212 | return false; 213 | } 214 | 215 | m_PrivateKey = _private_key; 216 | 217 | BIO_free(bio); 218 | 219 | return true; 220 | } // setPrivateKey 221 | 222 | 223 | //! getPrivateKey 224 | QByteArray Rsa::getPrivateKey( void ) const 225 | { 226 | return m_PrivateKey; 227 | } 228 | 229 | 230 | //! generatePrivateKey 231 | QByteArray Rsa::generatePrivateKey( int _len ) 232 | { 233 | // generating key 234 | BIGNUM* bne = BN_new(); 235 | int ret = BN_set_word( bne, RSA_F4 ); 236 | if( ret != 1 ) 237 | { 238 | PCORE_LOG_ERROR( "Private key creation has failed." ); 239 | return QByteArray(); 240 | } 241 | 242 | auto rsa = RSA_new(); 243 | ret = RSA_generate_key_ex( rsa, _len, bne, NULL ); 244 | 245 | if ( ret != 1 ) 246 | { 247 | PCORE_LOG_ERROR( "Private key creation has failed." ); 248 | BN_free( bne ); 249 | return QByteArray(); 250 | } 251 | 252 | 253 | // reading key 254 | BIO *bio = BIO_new( BIO_s_mem() ); 255 | 256 | if ( bio == nullptr ) 257 | { 258 | PCORE_LOG_ERROR( "Private key creation has failed." ); 259 | RSA_free( rsa ); 260 | BN_free ( bne ); 261 | return QByteArray(); 262 | } 263 | 264 | PEM_write_bio_RSAPrivateKey( bio, rsa, NULL, NULL, 0, NULL, NULL ); 265 | int key_len = BIO_pending( bio ); 266 | char* key = new char[ key_len ]; 267 | BIO_read( bio, key, key_len ); 268 | QByteArray ar( key, key_len ); 269 | 270 | 271 | // releasing resources 272 | BIO_free_all( bio ); 273 | RSA_free( rsa ); 274 | BN_free ( bne ); 275 | delete[] key; 276 | 277 | return ar; 278 | } // generatePrivateKey 279 | 280 | 281 | //! generatePublicKey 282 | QByteArray Rsa::generatePublicKey( const QByteArray& _private_key ) 283 | { 284 | // reading private key 285 | BIO *bio = BIO_new_mem_buf( (void*)_private_key.constData(), -1 ); 286 | 287 | if ( bio == nullptr ) 288 | { 289 | PCORE_LOG_ERROR( "Generating public key has failed." ); 290 | return QByteArray(); 291 | } 292 | 293 | BIO_set_flags(bio, BIO_FLAGS_BASE64_NO_NL); 294 | RSA* rsa = PEM_read_bio_RSAPrivateKey( bio, NULL, NULL, NULL ); 295 | 296 | 297 | if ( rsa == nullptr ) 298 | { 299 | PCORE_LOG_ERROR( "Generating public key has failed." ); 300 | BIO_free_all( bio ); 301 | return QByteArray(); 302 | } 303 | 304 | 305 | // generating public key 306 | BIO* bio_out = BIO_new( BIO_s_mem() ); 307 | 308 | if ( bio_out == nullptr ) 309 | { 310 | PCORE_LOG_ERROR( "Generating public key has failed." ); 311 | BIO_free_all( bio ); 312 | RSA_free( rsa ); 313 | return QByteArray(); 314 | } 315 | 316 | PEM_write_bio_RSAPublicKey( bio_out, rsa ); 317 | int key_len = BIO_pending( bio_out ); 318 | char* key = new char[ key_len ]; 319 | BIO_read( bio_out, key, key_len ); 320 | QByteArray ar( key, key_len ); 321 | 322 | 323 | // releasing resources 324 | BIO_free_all( bio ); 325 | BIO_free_all( bio_out ); 326 | RSA_free( rsa ); 327 | delete[] key; 328 | 329 | return ar; 330 | } // generatePublicKey 331 | 332 | } // cryptography 333 | } // PCore 334 | -------------------------------------------------------------------------------- /lib/source/math/random.cpp: -------------------------------------------------------------------------------- 1 | //############################################################################## 2 | //# c-date: Jun-10-2016 3 | //# author: Pouya Shahinfar (Pswin) - pswinpo@gmail.com 4 | //############################################################################## 5 | 6 | 7 | //============================================================================== 8 | // includes 9 | //============================================================================== 10 | 11 | #include 12 | #include 13 | #include "include/pcore/math/random.h" 14 | 15 | 16 | //============================================================================== 17 | // random 18 | //============================================================================== 19 | namespace PCore 20 | { 21 | namespace math 22 | { 23 | 24 | //! randomByteArray 25 | QByteArray Random::randomByteArray( quint32 _size ) 26 | { 27 | unsigned char* arr = new unsigned char[ _size ]; 28 | RAND_bytes(arr,_size); 29 | 30 | QByteArray out( (char*)arr, _size ); 31 | delete[] arr; 32 | return out; 33 | } 34 | 35 | } // math 36 | } // PCore 37 | 38 | -------------------------------------------------------------------------------- /lib/source/root.cpp: -------------------------------------------------------------------------------- 1 | //############################################################################## 2 | //# c-date: April-04-2016 3 | //# author: Pouya Shahinfar (Pswin) - pswinpo@gmail.com 4 | //############################################################################## 5 | 6 | 7 | //============================================================================== 8 | // includes 9 | //============================================================================== 10 | #include "include/pcore/root.h" 11 | #include "include/pcore/globals.h" 12 | #include "include/pcore/core/logger.h" 13 | #include "include/pcore/core/profiler.h" 14 | #include "headers/cryptography/cryptography_engine.h" 15 | #include 16 | 17 | #if QT_VERSION >= QT_VERSION_CHECK(5,6,0) 18 | #include 19 | #endif 20 | 21 | 22 | //============================================================================== 23 | // static members 24 | //============================================================================== 25 | 26 | static QByteArray NullQByteArray = QByteArray(); 27 | 28 | 29 | //============================================================================== 30 | // codes 31 | //============================================================================== 32 | namespace PCore 33 | { 34 | 35 | //! constructor 36 | Root::Root( QObject* _parent ) 37 | : QObject( _parent ) 38 | { 39 | pRoot = this; 40 | } 41 | 42 | //! init 43 | bool Root::init( const QString& _setting_file ) 44 | { 45 | // creating an instance of logger 46 | pLogger = new PCore::core::Logger( _setting_file, this ); 47 | 48 | PCORE_LOG_TRACE( "Root::init called." ); 49 | 50 | 51 | if ( PCore::cryptography::CryptographyEngine::init() == false ) 52 | { 53 | PCORE_LOG_ERROR( "Initializing cryptography engine failed." ); 54 | } 55 | 56 | // creating an instance of profile manager 57 | pProfileManager = new PCore::core::ProfileManager( this ); 58 | 59 | 60 | PCORE_LOG_INFO( "PCore started successfully." ); 61 | return true; 62 | } 63 | 64 | 65 | //! shutdown 66 | bool Root::shutdown() 67 | { 68 | if ( PCore::cryptography::CryptographyEngine::shutdown() == false ) 69 | { 70 | PCORE_LOG_ERROR( "Shutdowning cryptography engine failed." ); 71 | } 72 | 73 | return true; 74 | } 75 | 76 | 77 | //! getVersionString 78 | QString Root::getVersionString() const 79 | { 80 | return PCORE_VERSION_NAME; 81 | } 82 | 83 | #if QT_VERSION >= QT_VERSION_CHECK(5,6,0) 84 | //! getVersionNumber 85 | QVersionNumber Root::getVersionNumber( void ) const 86 | { 87 | return QVersionNumber( PCORE_VERSION_MAJOR, 88 | PCORE_VERSION_MINOR, 89 | PCORE_VERSION_PATCH 90 | ); 91 | } 92 | #endif // QT 5.6 93 | 94 | } // PCore 95 | 96 | -------------------------------------------------------------------------------- /pcore.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = subdirs 2 | 3 | SUBDIRS += lib 4 | SUBDIRS += test 5 | 6 | test.depends = lib 7 | -------------------------------------------------------------------------------- /test/common.pri: -------------------------------------------------------------------------------- 1 | 2 | PRJDIR = $$PWD/.. 3 | LIBS += -L$$PRJDIR/bin/ 4 | INCLUDEPATH += $$PRJDIR/lib/include/ 5 | DESTDIR = $$PRJDIR/bin/ 6 | 7 | CONFIG += c++11 8 | 9 | LIBS += -lpcore 10 | -------------------------------------------------------------------------------- /test/test.pro: -------------------------------------------------------------------------------- 1 | 2 | TEMPLATE = subdirs 3 | 4 | SUBDIRS += test_logger \ 5 | test_profiler \ 6 | test_compressor \ 7 | test_system_info \ 8 | test_crypto \ 9 | test_calendars\ 10 | test_cache 11 | -------------------------------------------------------------------------------- /test/test_cache/main.cpp: -------------------------------------------------------------------------------- 1 | //############################################################################## 2 | //# title: Cache 3 | //# c-date: Jun-27-2016 4 | //# author: Pouya Shahinfar (Pswin) - pswinpo@gmail.com 5 | //############################################################################## 6 | 7 | 8 | #include 9 | #include 10 | 11 | 12 | using namespace PCore::core::cachefx; 13 | 14 | 15 | int main() 16 | { 17 | 18 | // initializing PCore 19 | PCORE_INIT(); 20 | 21 | 22 | //===================================== 23 | // LRU Cache 24 | //===================================== 25 | 26 | qDebug() << "-------------------------------------"; 27 | qDebug() << "LRU Cache"; 28 | qDebug() << "-------------------------------------\n"; 29 | 30 | 31 | LRUCache lru_cache( 10 ); 32 | 33 | lru_cache.setMaxCost( 3 ); // Just 3 items in the cache 34 | lru_cache.insert( "Item1", "I am Item #1" ); 35 | lru_cache.insert( "Item2", "I am Item #2" ); 36 | lru_cache.insert( "Item3", "I am Item #3" ); 37 | lru_cache.insert( "Item4", "I am Item #4" ); // Item1 will be removed. 38 | 39 | 40 | /* always check the given results from the cahce. there is not any guarantee 41 | * for existence of the requested element (or item). 42 | */ 43 | auto it = lru_cache.get( "Item1"); 44 | if ( it != nullptr ) 45 | { 46 | qDebug() << "Item 1:" << lru_cache.get("Item1"); 47 | } 48 | else 49 | { 50 | qDebug() << "Item 1 have removed from the cache."; 51 | } 52 | 53 | qDebug() << "Item 2:" << *lru_cache.get( "Item2" ); 54 | 55 | 56 | /* printCacheOrder is a helper method for debuging. you can use it for 57 | * observeing items (elements) in the cache. 58 | */ 59 | lru_cache.printCacheOrder(); 60 | 61 | return 0; 62 | } 63 | 64 | -------------------------------------------------------------------------------- /test/test_cache/test_cache.pro: -------------------------------------------------------------------------------- 1 | QT += core 2 | QT -= gui 3 | 4 | CONFIG += c++11 5 | 6 | TARGET = test_cache 7 | CONFIG += console 8 | CONFIG -= app_bundle 9 | 10 | TEMPLATE = app 11 | 12 | SOURCES += main.cpp 13 | 14 | include(../common.pri) 15 | 16 | -------------------------------------------------------------------------------- /test/test_calendars/main.cpp: -------------------------------------------------------------------------------- 1 | //############################################################################## 2 | //# title: Test for calendars in globalization 3 | //# c-date: May-25-2016 4 | //# author: Pouya Shahinfar (Pswin) - pswinpo@gmail.com 5 | //############################################################################## 6 | 7 | 8 | #include 9 | #include 10 | 11 | 12 | using namespace PCore::core; 13 | using namespace PCore::globalization; 14 | 15 | int main() 16 | { 17 | 18 | // initializing PCore 19 | PCORE_INIT(); 20 | 21 | 22 | //===================================== 23 | // Persian Calendar 24 | //===================================== 25 | 26 | qDebug() << "-------------------------------------"; 27 | qDebug() << "Persian calendar (Jalali)"; 28 | qDebug() << "-------------------------------------\n"; 29 | 30 | qDebug() << "From string: " 31 | << PersianCalendar::fromString( "یکشنبه 12 مرداد 1396", 32 | "DDDD DD MMMM yyyy" ); 33 | 34 | qDebug() << "Formated (MM-DD-yy):" 35 | << PersianCalendar( 1395, 11, 2 ).toString( "MM-DD-yy" ); 36 | 37 | /* 38 | * Start day of Persian calendar is 22nd March 622 A.D in Gregorian calendar. 39 | */ 40 | qDebug() << "Start Date: " 41 | << PersianCalendar::fromQDate( QDate( 622,3,22 ) ) 42 | << QDate( 622,3, 22 ); 43 | 44 | 45 | qDebug() << "Today: " 46 | << PersianCalendar::currentDate( ); 47 | 48 | 49 | 50 | //===================================== 51 | // Hijri Calendar 52 | //===================================== 53 | 54 | qDebug() << "\n\n\n-------------------------------------"; 55 | qDebug() << "Hijri calendar "; 56 | qDebug() << "-------------------------------------\n"; 57 | 58 | qDebug() << "From string: " 59 | << HijriCalendar::fromString( "12 رَمَضان 1437", 60 | "DD MMMM yyyy" ); 61 | 62 | qDebug() << "Formated (MM-DD-yy):" 63 | << HijriCalendar( 1422, 11, 2 ).toString( "MM-DD-yy" ); 64 | 65 | 66 | /* 67 | * Start day of Hijri Calendar is 19th June 622 A.D in Gregorian 68 | * calendar or 16th June 622 A.D in Julian Calander. 69 | */ 70 | qDebug() << "Start Date: " 71 | << HijriCalendar::fromQDate( QDate( 622,7,19 ) ) 72 | << QDate( 622,7,19 ); 73 | 74 | qDebug() << "Today: " 75 | << HijriCalendar::currentDate( ); 76 | 77 | 78 | return 0; 79 | } 80 | 81 | -------------------------------------------------------------------------------- /test/test_calendars/test_calendars.pro: -------------------------------------------------------------------------------- 1 | QT += core 2 | QT -= gui 3 | 4 | CONFIG += c++11 5 | 6 | TARGET = test_calendars 7 | CONFIG += console 8 | CONFIG -= app_bundle 9 | 10 | TEMPLATE = app 11 | 12 | SOURCES += main.cpp 13 | 14 | include(../common.pri) 15 | 16 | -------------------------------------------------------------------------------- /test/test_compressor/lore.txt: -------------------------------------------------------------------------------- 1 | Lorem ipsum dolor sit amet, at duo elitr delicata, eum in unum putent denique, nobis utamur indoctum in has. In mei case civibus, no adhuc equidem contentiones vis. Ad sit mucius facete. Adhuc omnesque pericula et usu. 2 | 3 | Te sed quaeque detracto tractatos, labores nostrum adolescens pri an. Sea id modus inermis. In dolorum veritus eam, inciderint complectitur eu per. Facete voluptua usu no, malis perfecto no pri. Duo in verterem vituperata, his in case etiam soleat, nam eripuit constituam cu. 4 | 5 | Ne vis omnis consequuntur, ei usu lorem invidunt sensibus, eu euismod comprehensam eam. Nibh dicant conceptam cu sit, facer expetendis est eu. Sit ad illud constituam referrentur, in eum sanctus dolorum. In vis justo iuvaret intellegebat. 6 | 7 | Aeque erroribus instructior usu ne, cu vim alia detraxit. Ut sale legimus mei, debet possit pertinacia ea mei. Unum posse graecis cu duo. Modus everti oporteat cum cu, eam virtute postulant te. 8 | 9 | An vim prompta indoctum. Ea aeque electram his, eos aperiri adipiscing id, sea summo percipitur ea. Cu duis facer usu, expetenda pertinacia in sit. Esse labitur gubergren at vel, ex qui melius omittantur. Ut ludus utinam offendit cum. -------------------------------------------------------------------------------- /test/test_compressor/main.cpp: -------------------------------------------------------------------------------- 1 | //############################################################################## 2 | //# title: Test for Compressor class 3 | //# c-date: Apr-17-2016 4 | //# author: Pouya Shahinfar (Pswin) - pswinpo@gmail.com 5 | //############################################################################## 6 | 7 | 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | using namespace PCore::core; 15 | 16 | int main() 17 | { 18 | 19 | /* Note: 20 | * For executing this sample you need to copy lore.txt from directory of 21 | * sample to the bin directory. 22 | */ 23 | 24 | // initializing PCore 25 | PCORE_INIT(); 26 | 27 | 28 | 29 | 30 | // reading from file 31 | QFile f( "lore.txt" ); 32 | if ( f.open( QFile::ReadOnly ) == false ) 33 | { 34 | PCORE_LOG_ERROR( "Cannot open 'lore.txt'" ); 35 | return -1; 36 | } 37 | QByteArray ar = f.readAll(); 38 | f.close(); 39 | 40 | 41 | // compressing using Deflate algorithm 42 | QByteArray res_deflate = Compressor::compress( ar, 43 | Compressor::Format::RawDeflate, 44 | Compressor::Level::BestCompression 45 | ); 46 | // compressing in GZip format 47 | QByteArray res_gzip = Compressor::compress( ar, 48 | Compressor::Format::GZip, 49 | Compressor::Level::BestCompression 50 | ); 51 | 52 | 53 | qDebug()<< "Original size: " << ar.size(); 54 | qDebug()<< "Compresed with Defalte:" << res_deflate.size(); 55 | qDebug()<< "Compresed with GZip: " << res_gzip.size(); 56 | 57 | 58 | return 0; 59 | } 60 | 61 | -------------------------------------------------------------------------------- /test/test_compressor/test_compressor.pro: -------------------------------------------------------------------------------- 1 | QT += core 2 | QT -= gui 3 | 4 | CONFIG += c++11 5 | 6 | TARGET = test_compressor 7 | CONFIG += console 8 | CONFIG -= app_bundle 9 | 10 | TEMPLATE = app 11 | 12 | SOURCES += main.cpp 13 | 14 | include(../common.pri) 15 | 16 | -------------------------------------------------------------------------------- /test/test_crypto/main.cpp: -------------------------------------------------------------------------------- 1 | //############################################################################## 2 | //# title: Test for Crypto 3 | //# c-date: May-25-2016 4 | //# author: Pouya Shahinfar (Pswin) - pswinpo@gmail.com 5 | //############################################################################## 6 | 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | using namespace PCore::core; 14 | using namespace PCore::cryptography; 15 | 16 | 17 | void print_hex( const QByteArray& _ar ) 18 | { 19 | const unsigned char * p = (const unsigned char*)_ar.constData(); 20 | 21 | if ( _ar.isNull() == true ) 22 | { 23 | printf("NULL"); 24 | } 25 | else 26 | { 27 | for (int i = 0; i < _ar.size(); ++i ) 28 | printf( "%02X ", *p++ ); 29 | } 30 | printf("\n"); 31 | } 32 | 33 | 34 | int main() 35 | { 36 | 37 | // initializing PCore 38 | PCORE_INIT(); 39 | 40 | 41 | //===================================== 42 | // AES 43 | //===================================== 44 | 45 | printf("\n=====================================\n"); 46 | printf("AES\n"); 47 | printf("=====================================\n"); 48 | 49 | 50 | AES aes; 51 | aes.setPass( "123" ); 52 | 53 | // encrypt 54 | auto out = aes.encrypt( "Hello world!" ); 55 | printf( "Encrypted: " ); 56 | print_hex( out ); 57 | printf( "IV: " ); 58 | print_hex( aes.getIV() ); 59 | 60 | // decrypt 61 | out = aes.decrypt( out ); 62 | printf( "Decrypted: %s\n\n", out.data() ); 63 | 64 | 65 | //===================================== 66 | // DES 67 | //===================================== 68 | 69 | printf("\n=====================================\n"); 70 | printf("DES\n"); 71 | printf("=====================================\n"); 72 | 73 | 74 | DES des; 75 | des.setPass( "password" ); // key must be at least 8 char for DES 76 | 77 | out = des.encrypt( "Hallo welt!" ); 78 | printf( "Encrypted: " ); 79 | print_hex( out.data() ); 80 | printf( "IV: " ); 81 | print_hex( des.getIV() ); 82 | 83 | // decrypt 84 | out = des.decrypt( out ); 85 | printf( "Decrypted: %s\n\n", out.data() ); 86 | 87 | 88 | 89 | //===================================== 90 | // RSA 91 | //===================================== 92 | 93 | printf("\n=====================================\n"); 94 | printf("RSA\n"); 95 | printf("=====================================\n"); 96 | 97 | Rsa rsa; 98 | 99 | out = rsa.encrypt( "Salam donya!" ); 100 | printf( "Encrypted: " ); 101 | print_hex( out.data() ); 102 | printf( "\n" ); 103 | 104 | out = rsa.decrypt( out ); 105 | qDebug() << "Encrypted: " << out; 106 | 107 | return 0; 108 | } 109 | 110 | -------------------------------------------------------------------------------- /test/test_crypto/test_crypto.pro: -------------------------------------------------------------------------------- 1 | QT += core 2 | QT -= gui 3 | 4 | CONFIG += c++11 5 | 6 | TARGET = test_crypto 7 | CONFIG += console 8 | CONFIG -= app_bundle 9 | 10 | TEMPLATE = app 11 | 12 | SOURCES += main.cpp 13 | 14 | include(../common.pri) 15 | 16 | -------------------------------------------------------------------------------- /test/test_logger/main.cpp: -------------------------------------------------------------------------------- 1 | //############################################################################## 2 | //# title: Logger test 3 | //# c-date: Apr-15-2016 4 | //# author: Pouya Shahinfar (Pswin) - pswinpo@gmail.com 5 | //############################################################################## 6 | 7 | #include 8 | #include 9 | 10 | using namespace PCore::core; 11 | 12 | int main() 13 | { 14 | 15 | // initializing PCore 16 | PCORE_INIT(); 17 | 18 | 19 | //===================================== 20 | // Loging using macros 21 | //===================================== 22 | 23 | // critical 24 | PCORE_LOG_CRITICAL( "This is a critical message." ); 25 | 26 | // Error 27 | PCORE_LOG_ERROR( "This is an error message." ); 28 | 29 | // Warning 30 | PCORE_LOG_WARNING( "This is a warning message." ); 31 | 32 | // Info 33 | PCORE_LOG_INFO( "This is an info message." ); 34 | 35 | // Trace 36 | PCORE_LOG_TRACE( "This is a trace message." ); 37 | 38 | 39 | //===================================== 40 | // Loging by creating a log message 41 | //===================================== 42 | 43 | /* 44 | * if you intend to send additional parameters with you log message, you 45 | * should create LogMessage manually. 46 | */ 47 | 48 | // creating log message 49 | LogMessage msg; 50 | msg.setMessage( "This is a custom message" ); 51 | msg.setParam( "param 1", 12 ); 52 | msg.setParam( "param 2", "hi" ); 53 | msg.setType( LogMessage::Type::Error ); 54 | 55 | // loging it 56 | pLogger->log( msg ); 57 | 58 | 59 | //===================================== 60 | // getting logger information 61 | //===================================== 62 | 63 | auto logger = pLogger->getLogger( LogMessage::Type::Error ); 64 | 65 | qDebug() << "Type:" << logger->property( "type" ); 66 | qDebug() << "Filename:" << logger->property( "filename" ); 67 | 68 | 69 | //===================================== 70 | // changing logger file 71 | //===================================== 72 | 73 | logger->setProperty( "filename", "pcore2.log" ); 74 | PCORE_LOG_ERROR( "Log test in new file." ); 75 | 76 | return 0; 77 | } 78 | 79 | 80 | -------------------------------------------------------------------------------- /test/test_logger/test_logger.pro: -------------------------------------------------------------------------------- 1 | QT += core network 2 | QT -= gui 3 | CONFIG += console 4 | 5 | TARGET = test_logger 6 | TEMPLATE = app 7 | 8 | include(../common.pri) 9 | 10 | 11 | SOURCES += \ 12 | main.cpp 13 | -------------------------------------------------------------------------------- /test/test_profiler/main.cpp: -------------------------------------------------------------------------------- 1 | //############################################################################## 2 | //# title: Test for profiler 3 | //# c-date: Apr-16-2016 4 | //# author: Pouya Shahinfar (Pswin) - pswinpo@gmail.com 5 | //############################################################################## 6 | 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | //===================================== 13 | // foo 14 | //===================================== 15 | void foo() 16 | { 17 | // profiling this function 18 | PCORE_PROFILE_FUNCTION(); 19 | 20 | double res = 0; 21 | for ( int i = 0; i < 999999999; i++ ) 22 | { 23 | res = res + sqrt( i ); 24 | } 25 | std::cout << res << std::endl; 26 | } 27 | 28 | 29 | //===================================== 30 | // bar 31 | //===================================== 32 | 33 | double bar( int i ) 34 | { 35 | return sqrtf(i); 36 | } 37 | 38 | 39 | //===================================== 40 | // zoo 41 | //===================================== 42 | 43 | double zoo( int i ) 44 | { 45 | PCORE_PROFILE_FUNCTION(); 46 | return sqrtf(i); 47 | } 48 | 49 | 50 | 51 | //===================================== 52 | // main 53 | //===================================== 54 | int main(int argc, char *argv[]) 55 | { 56 | // initialize pcore 57 | PCORE_INIT(); 58 | 59 | 60 | // calling foo 61 | foo(); 62 | 63 | 64 | // profiling a block 65 | PCORE_PROFILE_BLOCK_START( _bar, "bar" ); 66 | double res = 0; 67 | for ( int i = 0; i < 999999999; i++ ) 68 | { 69 | res += bar( i ); 70 | } 71 | PCORE_PROFILE_BLOCK_END( _bar ); 72 | 73 | 74 | // counting call number 75 | for ( int i = 0; i < 1000; i++ ) 76 | { 77 | res += zoo( i ); 78 | } 79 | 80 | 81 | // saving profiles to a file 82 | pProfileManager->printToFile( "benchmark.txt" ); 83 | 84 | 85 | return 0; 86 | } 87 | -------------------------------------------------------------------------------- /test/test_profiler/test_profiler.pro: -------------------------------------------------------------------------------- 1 | QT += core 2 | QT -= gui 3 | 4 | CONFIG += c++11 5 | 6 | TARGET = test_profiler 7 | CONFIG += console 8 | CONFIG -= app_bundle 9 | 10 | include(../common.pri) 11 | 12 | TEMPLATE = app 13 | 14 | SOURCES += main.cpp 15 | -------------------------------------------------------------------------------- /test/test_system_info/main.cpp: -------------------------------------------------------------------------------- 1 | #include "mainwindow.h" 2 | #include 3 | #include 4 | 5 | 6 | int main(int argc, char *argv[]) 7 | { 8 | PCORE_INIT(); 9 | 10 | QApplication a(argc, argv); 11 | MainWindow w; 12 | w.show(); 13 | 14 | return a.exec(); 15 | } 16 | -------------------------------------------------------------------------------- /test/test_system_info/mainwindow.h: -------------------------------------------------------------------------------- 1 | #ifndef MAINWINDOW_H 2 | #define MAINWINDOW_H 3 | 4 | #include 5 | 6 | namespace Ui { 7 | class MainWindow; 8 | } 9 | 10 | class MainWindow : public QMainWindow 11 | { 12 | Q_OBJECT 13 | 14 | public: 15 | explicit MainWindow(QWidget *parent = 0); 16 | ~MainWindow(); 17 | 18 | private: 19 | //! fills process table 20 | void fillProcessTable( void ); 21 | 22 | //! fills video controller's table 23 | void fillVideoControllerTable( void ); 24 | 25 | //! fills storages table 26 | void fillStorageTable( void ); 27 | 28 | //! monitros 29 | void fillMonitors( void ); 30 | 31 | //! sound cards 32 | void fillSoundCards( void ); 33 | 34 | private: 35 | Ui::MainWindow *ui; 36 | }; 37 | 38 | #endif // MAINWINDOW_H 39 | -------------------------------------------------------------------------------- /test/test_system_info/mainwindow.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | MainWindow 4 | 5 | 6 | 7 | 0 8 | 0 9 | 490 10 | 571 11 | 12 | 13 | 14 | MainWindow 15 | 16 | 17 | 18 | 19 | 20 | 21 | 0 22 | 23 | 24 | 25 | Processor 26 | 27 | 28 | 29 | 30 | 31 | 32 | 401 33 | 0 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | Video Controllers 43 | 44 | 45 | 46 | 47 | 48 | 49 | 401 50 | 0 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | Storages 60 | 61 | 62 | 63 | 64 | 65 | 66 | 401 67 | 0 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | Monitors 77 | 78 | 79 | 80 | 81 | 82 | 83 | 401 84 | 0 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | Sound Cards 94 | 95 | 96 | 97 | 98 | 99 | 100 | 401 101 | 0 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | -------------------------------------------------------------------------------- /test/test_system_info/test_system_info.pro: -------------------------------------------------------------------------------- 1 | #------------------------------------------------- 2 | # 3 | # Project created by QtCreator 2016-04-18T18:35:57 4 | # 5 | #------------------------------------------------- 6 | 7 | QT += core gui 8 | 9 | greaterThan(QT_MAJOR_VERSION, 4): QT += widgets 10 | 11 | TARGET = test_system_info 12 | TEMPLATE = app 13 | 14 | 15 | SOURCES += main.cpp\ 16 | mainwindow.cpp 17 | 18 | HEADERS += mainwindow.h 19 | 20 | FORMS += mainwindow.ui 21 | 22 | include(../common.pri) 23 | --------------------------------------------------------------------------------