mirror of
https://github.com/ShaYmez/P25Clients.git
synced 2024-11-24 05:08:38 -05:00
Code cleanups.
This commit is contained in:
parent
db80247ab0
commit
f58bf29080
@ -22,6 +22,7 @@
|
|||||||
#include "DMRLookup.h"
|
#include "DMRLookup.h"
|
||||||
#include "Network.h"
|
#include "Network.h"
|
||||||
#include "Version.h"
|
#include "Version.h"
|
||||||
|
#include "Thread.h"
|
||||||
#include "Speech.h"
|
#include "Speech.h"
|
||||||
#include "Log.h"
|
#include "Log.h"
|
||||||
|
|
||||||
@ -350,13 +351,8 @@ void CP25Gateway::run()
|
|||||||
lostTimer.stop();
|
lostTimer.stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ms < 5U) {
|
if (ms < 5U)
|
||||||
#if defined(_WIN32) || defined(_WIN64)
|
CThread::sleep(5U);
|
||||||
::Sleep(5UL); // 5ms
|
|
||||||
#else
|
|
||||||
::usleep(5000); // 5ms
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
delete speech;
|
delete speech;
|
||||||
|
@ -4,7 +4,7 @@ CFLAGS = -g -O3 -Wall -std=c++0x
|
|||||||
LIBS =
|
LIBS =
|
||||||
LDFLAGS = -g
|
LDFLAGS = -g
|
||||||
|
|
||||||
OBJECTS = Log.o Network.o P25Parrot.o Parrot.o StopWatch.o Timer.o UDPSocket.o Utils.o
|
OBJECTS = Log.o Network.o P25Parrot.o Parrot.o StopWatch.o Thread.o Timer.o UDPSocket.o Utils.o
|
||||||
|
|
||||||
all: P25Parrot
|
all: P25Parrot
|
||||||
|
|
||||||
|
@ -4,7 +4,7 @@ CFLAGS = -g -O3 -Wall -std=c++0x
|
|||||||
LIBS = -lsocket
|
LIBS = -lsocket
|
||||||
LDFLAGS = -g
|
LDFLAGS = -g
|
||||||
|
|
||||||
OBJECTS = Log.o Network.o P25Parrot.o Parrot.o StopWatch.o Timer.o UDPSocket.o Utils.o
|
OBJECTS = Log.o Network.o P25Parrot.o Parrot.o StopWatch.o Thread.o Timer.o UDPSocket.o Utils.o
|
||||||
|
|
||||||
all: P25Parrot
|
all: P25Parrot
|
||||||
|
|
||||||
|
@ -21,6 +21,7 @@
|
|||||||
#include "Parrot.h"
|
#include "Parrot.h"
|
||||||
#include "Network.h"
|
#include "Network.h"
|
||||||
#include "Version.h"
|
#include "Version.h"
|
||||||
|
#include "Thread.h"
|
||||||
#include "Timer.h"
|
#include "Timer.h"
|
||||||
#include "Log.h"
|
#include "Log.h"
|
||||||
|
|
||||||
@ -148,13 +149,8 @@ void CP25Parrot::run()
|
|||||||
parrot.end();
|
parrot.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ms < 5U) {
|
if (ms < 5U)
|
||||||
#if defined(_WIN32) || defined(_WIN64)
|
CThread::sleep(5U);
|
||||||
::Sleep(5UL); // 5ms
|
|
||||||
#else
|
|
||||||
::usleep(5000); // 5ms
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
network.close();
|
network.close();
|
||||||
|
@ -152,6 +152,7 @@
|
|||||||
<ClInclude Include="Parrot.h" />
|
<ClInclude Include="Parrot.h" />
|
||||||
<ClInclude Include="RingBuffer.h" />
|
<ClInclude Include="RingBuffer.h" />
|
||||||
<ClInclude Include="StopWatch.h" />
|
<ClInclude Include="StopWatch.h" />
|
||||||
|
<ClInclude Include="Thread.h" />
|
||||||
<ClInclude Include="Timer.h" />
|
<ClInclude Include="Timer.h" />
|
||||||
<ClInclude Include="UDPSocket.h" />
|
<ClInclude Include="UDPSocket.h" />
|
||||||
<ClInclude Include="Utils.h" />
|
<ClInclude Include="Utils.h" />
|
||||||
@ -163,6 +164,7 @@
|
|||||||
<ClCompile Include="P25Parrot.cpp" />
|
<ClCompile Include="P25Parrot.cpp" />
|
||||||
<ClCompile Include="Parrot.cpp" />
|
<ClCompile Include="Parrot.cpp" />
|
||||||
<ClCompile Include="StopWatch.cpp" />
|
<ClCompile Include="StopWatch.cpp" />
|
||||||
|
<ClCompile Include="Thread.cpp" />
|
||||||
<ClCompile Include="Timer.cpp" />
|
<ClCompile Include="Timer.cpp" />
|
||||||
<ClCompile Include="UDPSocket.cpp" />
|
<ClCompile Include="UDPSocket.cpp" />
|
||||||
<ClCompile Include="Utils.cpp" />
|
<ClCompile Include="Utils.cpp" />
|
||||||
|
@ -41,6 +41,9 @@
|
|||||||
<ClInclude Include="Log.h">
|
<ClInclude Include="Log.h">
|
||||||
<Filter>Header Files</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
<ClInclude Include="Thread.h">
|
||||||
|
<Filter>Header Files</Filter>
|
||||||
|
</ClInclude>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClCompile Include="Network.cpp">
|
<ClCompile Include="Network.cpp">
|
||||||
@ -67,5 +70,8 @@
|
|||||||
<ClCompile Include="Log.cpp">
|
<ClCompile Include="Log.cpp">
|
||||||
<Filter>Source Files</Filter>
|
<Filter>Source Files</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="Thread.cpp">
|
||||||
|
<Filter>Source Files</Filter>
|
||||||
|
</ClCompile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
101
P25Parrot/Thread.cpp
Normal file
101
P25Parrot/Thread.cpp
Normal file
@ -0,0 +1,101 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2015,2016 by Jonathan Naylor G4KLX
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "Thread.h"
|
||||||
|
|
||||||
|
#if defined(_WIN32) || defined(_WIN64)
|
||||||
|
|
||||||
|
CThread::CThread() :
|
||||||
|
m_handle()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
CThread::~CThread()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CThread::run()
|
||||||
|
{
|
||||||
|
m_handle = ::CreateThread(NULL, 0, &helper, this, 0, NULL);
|
||||||
|
|
||||||
|
return m_handle != NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void CThread::wait()
|
||||||
|
{
|
||||||
|
::WaitForSingleObject(m_handle, INFINITE);
|
||||||
|
|
||||||
|
::CloseHandle(m_handle);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
DWORD CThread::helper(LPVOID arg)
|
||||||
|
{
|
||||||
|
CThread* p = (CThread*)arg;
|
||||||
|
|
||||||
|
p->entry();
|
||||||
|
|
||||||
|
return 0UL;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CThread::sleep(unsigned int ms)
|
||||||
|
{
|
||||||
|
::Sleep(ms);
|
||||||
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
CThread::CThread() :
|
||||||
|
m_thread()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
CThread::~CThread()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CThread::run()
|
||||||
|
{
|
||||||
|
return ::pthread_create(&m_thread, NULL, helper, this) == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void CThread::wait()
|
||||||
|
{
|
||||||
|
::pthread_join(m_thread, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void* CThread::helper(void* arg)
|
||||||
|
{
|
||||||
|
CThread* p = (CThread*)arg;
|
||||||
|
|
||||||
|
p->entry();
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CThread::sleep(unsigned int ms)
|
||||||
|
{
|
||||||
|
::usleep(ms * 1000);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
56
P25Parrot/Thread.h
Normal file
56
P25Parrot/Thread.h
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2015,2016 by Jonathan Naylor G4KLX
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#if !defined(THREAD_H)
|
||||||
|
#define THREAD_H
|
||||||
|
|
||||||
|
#if defined(_WIN32) || defined(_WIN64)
|
||||||
|
#include <windows.h>
|
||||||
|
#else
|
||||||
|
#include <pthread.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
class CThread
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
CThread();
|
||||||
|
virtual ~CThread();
|
||||||
|
|
||||||
|
virtual bool run();
|
||||||
|
|
||||||
|
virtual void entry() = 0;
|
||||||
|
|
||||||
|
virtual void wait();
|
||||||
|
|
||||||
|
static void sleep(unsigned int ms);
|
||||||
|
|
||||||
|
private:
|
||||||
|
#if defined(_WIN32) || defined(_WIN64)
|
||||||
|
HANDLE m_handle;
|
||||||
|
#else
|
||||||
|
pthread_t m_thread;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(_WIN32) || defined(_WIN64)
|
||||||
|
static DWORD __stdcall helper(LPVOID arg);
|
||||||
|
#else
|
||||||
|
static void* helper(void* arg);
|
||||||
|
#endif
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
Loading…
Reference in New Issue
Block a user