OSDN Git Service

Added support for Visual Studio 2017.9 (v15.9.16).
[mutilities/MUtilities.git] / src / IPCChannel.cpp
index eeb8819..1192e68 100644 (file)
@@ -1,6 +1,6 @@
 ///////////////////////////////////////////////////////////////////////////////
 // MuldeR's Utilities for Qt
-// Copyright (C) 2004-2015 LoRd_MuldeR <MuldeR2@GMX.de>
+// Copyright (C) 2004-2019 LoRd_MuldeR <MuldeR2@GMX.de>
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
@@ -152,7 +152,7 @@ namespace MUtils
                friend class IPCChannel;
 
        protected:
-               volatile bool initialized;
+               QAtomicInt initialized;
                QScopedPointer<QSharedMemory> sharedmem;
                QScopedPointer<QSystemSemaphore> semaphore_rd;
                QScopedPointer<QSystemSemaphore> semaphore_wr;
@@ -172,7 +172,6 @@ MUtils::IPCChannel::IPCChannel(const QString &applicationId, const quint32 &appV
        m_appVersionNo(appVersionNo),
        m_headerStr(QCryptographicHash::hash(MAKE_ID(applicationId, appVersionNo, channelId, "header").toLatin1(), QCryptographicHash::Sha1).toHex())
 {
-       p->initialized = false;
        if(m_headerStr.length() != Internal::HDR_LEN)
        {
                MUTILS_THROW("Invalid header length has been detected!");
@@ -181,7 +180,7 @@ MUtils::IPCChannel::IPCChannel(const QString &applicationId, const quint32 &appV
 
 MUtils::IPCChannel::~IPCChannel(void)
 {
-       if(p->initialized)
+       if(MUTILS_BOOLIFY(p->initialized))
        {
                if(p->sharedmem->isAttached())
                {
@@ -200,7 +199,7 @@ int MUtils::IPCChannel::initialize(void)
 {
        QWriteLocker writeLock(&p->lock);
        
-       if(p->initialized)
+       if(MUTILS_BOOLIFY(p->initialized))
        {
                return RET_ALREADY_INITIALIZED;
        }
@@ -258,7 +257,7 @@ int MUtils::IPCChannel::initialize(void)
                                qWarning("Failed to access shared memory: %s", MUTILS_UTF8(errorMessage));
                                return RET_FAILURE;
                        }
-                       p->initialized = true;
+                       p->initialized.ref();
                        return RET_SUCCESS_SLAVE;
                }
                else
@@ -300,7 +299,7 @@ int MUtils::IPCChannel::initialize(void)
        //qDebug("IPC KEY #2: %s", MUTILS_UTF8(p->semaphore_rd->key()));
        //qDebug("IPC KEY #3: %s", MUTILS_UTF8(p->semaphore_wr->key()));
 
-       p->initialized = true;
+       p->initialized.ref();
        return RET_SUCCESS_MASTER;
 }
 
@@ -346,7 +345,7 @@ bool MUtils::IPCChannel::send(const quint32 &command, const quint32 &flags, cons
                                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);
+                                       strncpy_s(ipc_msg.payload.params.values[i], MAX_PARAM_LEN, MUTILS_UTF8(params[i].trimmed()), _TRUNCATE);
                                }
                                ipc_msg.payload.params.count = param_count;
                        }