Updated IPCChannel class to pass a variable number of parameter strings per message (instead of just one).
This commit is contained in:
parent
e33d869f59
commit
4091eccf9b
@ -26,6 +26,7 @@
|
||||
|
||||
//Qt
|
||||
#include <QtGlobal>
|
||||
#include <QStringList>
|
||||
|
||||
namespace MUtils
|
||||
{
|
||||
@ -34,7 +35,8 @@ namespace MUtils
|
||||
class MUTILS_API IPCChannel
|
||||
{
|
||||
public:
|
||||
static const size_t MAX_MESSAGE_LEN = 4096;
|
||||
static const quint32 MAX_PARAM_LEN = 4096;
|
||||
static const quint32 MAX_PARAM_CNT = 4;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
@ -50,8 +52,8 @@ namespace MUtils
|
||||
|
||||
int initialize(void);
|
||||
|
||||
bool send(const quint32 &command, const quint32 &flags, const char *const message);
|
||||
bool read(quint32 &command, quint32 &flags, char *const message, const size_t &buffSize);
|
||||
bool send(const quint32 &command, const quint32 &flags, const QStringList ¶ms = QStringList());
|
||||
bool read(quint32 &command, quint32 &flags, QStringList ¶ms);
|
||||
|
||||
private:
|
||||
IPCChannel(const IPCChannel&) : p(NULL), m_appVersionNo(-1) { throw "Constructor is disabled!"; }
|
||||
|
@ -31,4 +31,4 @@
|
||||
|
||||
#define VER_MUTILS_MAJOR 1
|
||||
#define VER_MUTILS_MINOR_HI 0
|
||||
#define VER_MUTILS_MINOR_LO 0
|
||||
#define VER_MUTILS_MINOR_LO 1
|
||||
|
@ -523,7 +523,7 @@ int MUtils::Internal::selfTest(const char *const buildKey, const bool debug)
|
||||
static const bool MY_DEBUG_FLAG = MUTILS_DEBUG;
|
||||
static const char *const MY_BUILD_KEY = __DATE__"@"__TIME__;
|
||||
|
||||
if(strncmp(buildKey, MY_BUILD_KEY, 14) || (MY_DEBUG_FLAG != debug))
|
||||
if(strncmp(buildKey, MY_BUILD_KEY, 13) || (MY_DEBUG_FLAG != debug))
|
||||
{
|
||||
MUtils::OS::system_message_err(L"MUtils", L"FATAL ERROR: MUtils library version mismatch detected!");
|
||||
MUtils::OS::system_message_wrn(L"MUtils", L"Please re-build the complete solution in order to fix this issue!");
|
||||
|
@ -33,7 +33,7 @@
|
||||
#include <QMutex>
|
||||
#include <QWriteLocker>
|
||||
#include <QCryptographicHash>
|
||||
|
||||
#include <QStringList>
|
||||
//CRT
|
||||
#include <cassert>
|
||||
|
||||
@ -87,11 +87,18 @@ namespace MUtils
|
||||
}
|
||||
ipc_status_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
char values[MUtils::IPCChannel::MAX_PARAM_CNT][MUtils::IPCChannel::MAX_PARAM_LEN];
|
||||
quint32 count;
|
||||
}
|
||||
ipc_msg_data_params_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
quint32 command_id;
|
||||
quint32 flags;
|
||||
char param[MUtils::IPCChannel::MAX_MESSAGE_LEN];
|
||||
ipc_msg_data_params_t params;
|
||||
quint64 timestamp;
|
||||
}
|
||||
ipc_msg_data_t;
|
||||
@ -301,7 +308,7 @@ int MUtils::IPCChannel::initialize(void)
|
||||
// SEND MESSAGE
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
bool MUtils::IPCChannel::send(const quint32 &command, const quint32 &flags, const char *const message)
|
||||
bool MUtils::IPCChannel::send(const quint32 &command, const quint32 &flags, const QStringList ¶ms)
|
||||
{
|
||||
bool success = false;
|
||||
QReadLocker readLock(&p->lock);
|
||||
@ -334,9 +341,14 @@ bool MUtils::IPCChannel::send(const quint32 &command, const quint32 &flags, cons
|
||||
|
||||
ipc_msg.payload.command_id = command;
|
||||
ipc_msg.payload.flags = flags;
|
||||
if(message)
|
||||
if(!params.isEmpty())
|
||||
{
|
||||
strncpy_s(ipc_msg.payload.param, MAX_MESSAGE_LEN, message, _TRUNCATE);
|
||||
const quint32 param_count = qMin(MAX_PARAM_CNT, (quint32)params.count());
|
||||
for(quint32 i = 0; i < param_count; i++)
|
||||
{
|
||||
strncpy_s(ipc_msg.payload.params.values[i], MAX_PARAM_LEN, MUTILS_UTF8(params[i]), _TRUNCATE);
|
||||
}
|
||||
ipc_msg.payload.params.count = param_count;
|
||||
}
|
||||
ipc_msg.payload.timestamp = ptr->status.payload.counter++;
|
||||
UPDATE_CHECKSUM(ipc_msg);
|
||||
@ -376,16 +388,12 @@ bool MUtils::IPCChannel::send(const quint32 &command, const quint32 &flags, cons
|
||||
// READ MESSAGE
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
bool MUtils::IPCChannel::read(quint32 &command, quint32 &flags, char *const message, const size_t &buffSize)
|
||||
bool MUtils::IPCChannel::read(quint32 &command, quint32 &flags, QStringList ¶ms)
|
||||
{
|
||||
bool success = false;
|
||||
QReadLocker readLock(&p->lock);
|
||||
|
||||
command = 0;
|
||||
if(message && (buffSize > 0))
|
||||
{
|
||||
message[0] = '\0';
|
||||
}
|
||||
params.clear();
|
||||
|
||||
if(!p->initialized)
|
||||
{
|
||||
@ -421,7 +429,13 @@ bool MUtils::IPCChannel::read(quint32 &command, quint32 &flags, char *const mess
|
||||
{
|
||||
command = ipc_msg.payload.command_id;
|
||||
flags = ipc_msg.payload.flags;
|
||||
strncpy_s(message, buffSize, ipc_msg.payload.param, _TRUNCATE);
|
||||
const quint32 param_count = qMin(ipc_msg.payload.params.count, MAX_PARAM_CNT);
|
||||
char temp[MAX_PARAM_LEN];
|
||||
for(quint32 i = 0; i < param_count; i++)
|
||||
{
|
||||
strncpy_s(temp, MAX_PARAM_LEN, ipc_msg.payload.params.values[i], _TRUNCATE);
|
||||
params.append(QString::fromUtf8(temp));
|
||||
}
|
||||
success = true;
|
||||
}
|
||||
else
|
||||
|
Loading…
Reference in New Issue
Block a user