add IPC send

This commit is contained in:
Hendrik Schutter 2022-11-24 19:21:24 +01:00
parent ce696f676a
commit b1cc2ac13d
3 changed files with 47 additions and 20 deletions

View File

@ -10,29 +10,33 @@
#include "reHDD.h"
#include <sys/ipc.h>
#include <sys/msg.h>
#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_

View File

@ -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

View File

@ -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!");
}
}