From b1cc2ac13da393c7351ec00c2ef9e12e87e85f03 Mon Sep 17 00:00:00 2001 From: localhorst Date: Thu, 24 Nov 2022 19:21:24 +0100 Subject: [PATCH] add IPC send --- include/printer.h | 37 +++++++++++++++++++++---------------- include/shred.h | 2 +- src/printer.cpp | 28 +++++++++++++++++++++++++--- 3 files changed, 47 insertions(+), 20 deletions(-) diff --git a/include/printer.h b/include/printer.h index 7e1271c..9685cae 100644 --- a/include/printer.h +++ b/include/printer.h @@ -10,29 +10,33 @@ #include "reHDD.h" +#include +#include + #define STR_BUFFER_SIZE 64U +#define IPC_MSG_QUEUE_KEY 0x1B11193C0 typedef struct -{ -char caDriveIndex[STR_BUFFER_SIZE]; -char caDriveHours[STR_BUFFER_SIZE]; -char caDriveCycles[STR_BUFFER_SIZE]; -char caDriveErrors[STR_BUFFER_SIZE]; -char caDriveShredTimestamp[STR_BUFFER_SIZE]; -char caDriveShredDuration[STR_BUFFER_SIZE]; -char caDriveCapacity[STR_BUFFER_SIZE]; -char caDriveState[STR_BUFFER_SIZE]; -char caDriveModelFamiliy[STR_BUFFER_SIZE]; -char caDriveModelName[STR_BUFFER_SIZE]; -char caDriveSerialnumber[STR_BUFFER_SIZE]; -char caDriveReHddVersion[STR_BUFFER_SIZE]; +{ + char caDriveIndex[STR_BUFFER_SIZE]; + char caDriveHours[STR_BUFFER_SIZE]; + char caDriveCycles[STR_BUFFER_SIZE]; + char caDriveErrors[STR_BUFFER_SIZE]; + char caDriveShredTimestamp[STR_BUFFER_SIZE]; + char caDriveShredDuration[STR_BUFFER_SIZE]; + char caDriveCapacity[STR_BUFFER_SIZE]; + char caDriveState[STR_BUFFER_SIZE]; + char caDriveModelFamiliy[STR_BUFFER_SIZE]; + char caDriveModelName[STR_BUFFER_SIZE]; + char caDriveSerialnumber[STR_BUFFER_SIZE]; + char caDriveReHddVersion[STR_BUFFER_SIZE]; } t_driveData; typedef struct { - long msg_queue_type; - t_driveData driveData; + long msg_queue_type; + t_driveData driveData; } t_msgQueueData; @@ -47,9 +51,10 @@ public: private: static bool instanceFlag; static Printer *single; + int msqid; Printer(); ~Printer(); - + }; #endif // PRINTER_H_ \ No newline at end of file diff --git a/include/shred.h b/include/shred.h index c423d36..3da43bb 100644 --- a/include/shred.h +++ b/include/shred.h @@ -21,7 +21,7 @@ #define CHUNK_SIZE 1024*1024*32 //amount of bytes that are overwritten at once --> 32MB #define TFNG_DATA_SIZE CHUNK_SIZE //amount of bytes used by tfng -//#define DEMO_DRIVE_SIZE 1024*1024*256L // 256MB +#define DEMO_DRIVE_SIZE 1024*1024*256L // 256MB //#define DEMO_DRIVE_SIZE 1024*1024*1024L // 1GB //#define DEMO_DRIVE_SIZE 5*1024*1024*1024L // 5GB //#define DEMO_DRIVE_SIZE 1024*1024*1024*10L // 10GB diff --git a/src/printer.cpp b/src/printer.cpp index a0aa839..3a94acb 100644 --- a/src/printer.cpp +++ b/src/printer.cpp @@ -7,7 +7,6 @@ #include "../include/reHDD.h" - bool Printer::instanceFlag = false; Printer* Printer::single = NULL; @@ -19,7 +18,10 @@ Printer* Printer::single = NULL; */ Printer::Printer() { - + if (-1 == (this->msqid = msgget((key_t)IPC_MSG_QUEUE_KEY, IPC_CREAT | 0666))) + { + Logger::logThis()->error("Printer: Create mgs queue failed!"); + } } /** @@ -35,8 +37,28 @@ Printer::~Printer() * \brief send data to msg queue * \return void */ -void Printer::print(){ +void Printer::print() +{ + t_msgQueueData msgQueueData; + msgQueueData.msg_queue_type = 1; + sprintf(msgQueueData.driveData.caDriveIndex, "%i",42); + sprintf(msgQueueData.driveData.caDriveState, "shredded"); + sprintf(msgQueueData.driveData.caDriveModelFamiliy, "Toshiba 2.5\\ HDD MK..65GSSX"); + sprintf(msgQueueData.driveData.caDriveModelName, "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"); + sprintf(msgQueueData.driveData.caDriveCapacity, "%li",343597383680); //343597383680 + sprintf(msgQueueData.driveData.caDriveSerialnumber, "YG6742U56UDRL123"); + sprintf(msgQueueData.driveData.caDriveHours, "%i",7074); + sprintf(msgQueueData.driveData.caDriveCycles, "%i",4792); + sprintf(msgQueueData.driveData.caDriveErrors, "%i",1); + sprintf(msgQueueData.driveData.caDriveShredTimestamp, "%i",1647937421); + sprintf(msgQueueData.driveData.caDriveShredDuration, "%i",81718); + sprintf(msgQueueData.driveData.caDriveReHddVersion, "bV0.2.2"); + + if (-1 == msgsnd(this->msqid, &msgQueueData, sizeof(t_msgQueueData) - sizeof(long), 0)) + { + Logger::logThis()->error("Printer: Send mgs queue failed!"); + } }