Skip to content

Commit

Permalink
Fixed semaphore handle for windows
Browse files Browse the repository at this point in the history
  • Loading branch information
grodansparadis committed Jan 10, 2025
1 parent eec8bc3 commit cc5aa59
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
// $Revision: 1.3 $
/////////////////////////////////////////////////////////////////////////////

#if !defined(AFX_CANALDIAGNOSTICDOC_H__73D0D1F3_987B_4A42_ADD5_AE5718C9D792__INCLUDED_)
#define AFX_CANALDIAGNOSTICDOC_H__73D0D1F3_987B_4A42_ADD5_AE5718C9D792__INCLUDED_
#if !defined(CANALDIAGNOSTICDOC_H__73D0D1F3_987B_4A42_ADD5_AE5718C9D792__INCLUDED_)
#define CANALDIAGNOSTICDOC_H__73D0D1F3_987B_4A42_ADD5_AE5718C9D792__INCLUDED_

#if _MSC_VER > 1000
#pragma once
Expand Down Expand Up @@ -152,7 +152,5 @@ class CCanalDiagnosticDoc : public CDocument

/////////////////////////////////////////////////////////////////////////////

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_CANALDIAGNOSTICDOC_H__73D0D1F3_987B_4A42_ADD5_AE5718C9D792__INCLUDED_)
#endif // !defined(CANALDIAGNOSTICDOC_H__73D0D1F3_987B_4A42_ADD5_AE5718C9D792__INCLUDED_)
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
//
// This file is part of the CANAL (https://www.vscp.org)
//
// Copyright (C) 2000-2025 Ake Hedman, eurosource, <[email protected]>
// Copyright (C) 2000-2025 Ake Hedman, D of Scandinavia, <[email protected]>
//
// This file is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
//
// This file is part of the CANAL (https://www.vscp.org)
//
// Copyright (C) 2000-2025 Ake Hedman, eurosource, <[email protected]>
// Copyright (C) 2000-2025 Ake Hedman, D of Scandinavia, <[email protected]>
//
// This file is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
Expand Down
12 changes: 12 additions & 0 deletions contrib/samples/samples/win32/mfc/README
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
VSCP Simple Button
==================
Application that show how to build a small Visual C++ application that send events through
the daemon interface.


VSCP Simple Lamp
================
Application that show how to build a small Visual C++ application that receive events through
the daemon interface.


CanalDiagnostic
===============
This was the first general message hadnling app for CANAL and was written using MFC.
Expand Down
2 changes: 2 additions & 0 deletions contrib/samples/samples/win32/mfc/loggerwnd/loggerwnd.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,7 @@ class CLoggerWndApp : public CWinApp

/////////////////////////////////////////////////////////////////////////////

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(LOGGERWND_H__B38025D1_B5E4_4E4F_91E3_2AA787075D4C__INCLUDED_)
2 changes: 1 addition & 1 deletion src/vscp/common/vscp-bootdevice-pic1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -757,7 +757,7 @@ CBootDevice_PIC1::writeFirmwareSector(uint8_t *paddr)

// Put data into frame
for (int i = 0; i < 8; i++) {
msg.data[i + offset] = paddr[i];
msg.data[i] = paddr[i];
m_checksum += paddr[i];
};

Expand Down
18 changes: 12 additions & 6 deletions src/vscp/common/vscp-client-canal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,12 @@ vscpClientCanal::vscpClientCanal()
pthread_mutex_init(&m_mutexif, NULL);
pthread_mutex_init(&m_mutexReceiveQueue, NULL);

// sem_init(&m_semSendQueue, 0, 0);
// sem_init(&m_semSendQueue, 0, 0);
#ifdef WIN32
m_semReceiveQueue = CreateSemaphore(NULL, 0, 0x7fffffff, NULL);
#else
sem_init(&m_semReceiveQueue, 0, 0);
#endif

// pthread_mutex_init(&m_mutexSendQueue, NULL);
pthread_mutex_init(&m_mutexReceiveQueue, NULL);
Expand All @@ -85,16 +89,20 @@ vscpClientCanal::~vscpClientCanal()
{
disconnect();

#ifdef WIN32
CloseHandle(m_semReceiveQueue);
#else
sem_destroy(&m_semReceiveQueue);
#endif

pthread_mutex_destroy(&m_mutexif);
pthread_mutex_destroy(&m_mutexReceiveQueue);

// Clear the input queue (if needed)
while (m_receiveQueue.size()) {
vscpEvent *pev = m_receiveQueue.front();
m_receiveQueue.pop_front();
vscp_deleteEvent(pev);
vscpEvent *pev = m_receiveQueue.front();
m_receiveQueue.pop_front();
vscp_deleteEvent(pev);
}

spdlog::trace("CANAL CLIENT: destructor vscp_client_canal object.");
Expand Down Expand Up @@ -660,8 +668,6 @@ workerThread(void *pObj)

// while (cnt) {



if (CANAL_ERROR_SUCCESS == pClient->m_canalif.CanalBlockingReceive(&msg, 100)) {

spdlog::trace("CANAL CLIENT: workthread. Event received");
Expand Down
14 changes: 11 additions & 3 deletions src/vscp/common/vscp-client-tcp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,11 @@ vscpClientTcp::vscpClientTcp()
vscp_clearVSCPFilter(&m_filterIn); // Accept all events
vscp_clearVSCPFilter(&m_filterOut); // Send all events

#ifdef WIN32
m_semReceiveQueue = CreateSemaphore(NULL, 0, 0x7fffffff, NULL);
#else
sem_init(&m_semReceiveQueue, 0, 0);
#endif

pthread_mutex_init(&m_mutexTcpIpObject, NULL);
pthread_mutex_init(&m_mutexReceiveQueue, NULL);
Expand All @@ -67,16 +71,20 @@ vscpClientTcp::~vscpClientTcp()
// Just to be sure
disconnect();

#ifdef WIN32
CloseHandle(m_semReceiveQueue);
#else
sem_destroy(&m_semReceiveQueue);
#endif

pthread_mutex_destroy(&m_mutexTcpIpObject);
pthread_mutex_destroy(&m_mutexReceiveQueue);

// Clear the input queue (if needed)
while (m_receiveList.size()) {
vscpEvent *pev = m_receiveList.front();
m_receiveList.pop_front();
vscp_deleteEvent(pev);
vscpEvent *pev = m_receiveList.front();
m_receiveList.pop_front();
vscp_deleteEvent(pev);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/vscp/common/vscpremotetcpif.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -743,7 +743,7 @@ VscpRemoteTcpIf::doCmdReceiveEx(vscpEventEx *pEventEx)
}

if (!m_inputStrArray.size()) {
return VSCP_ERROR_ERROR;
return VSCP_ERROR_RCV_EMPTY;
}

vscpEvent *pEvent = new vscpEvent;
Expand Down

0 comments on commit cc5aa59

Please sign in to comment.