move msg to api, update win project to vs2019
This commit is contained in:
parent
b70746cf41
commit
6d05b9899f
|
@ -11,7 +11,7 @@ read -p "Please input:[1-3]:" input
|
|||
|
||||
# build GuiLite.h
|
||||
cd core_include
|
||||
cat api.h cmd_target.h rect.h msg.h resource.h theme.h surface.h display.h word.h bitmap.h wnd.h audio.h > core.h
|
||||
cat api.h cmd_target.h rect.h resource.h theme.h surface.h display.h word.h bitmap.h wnd.h audio.h > core.h
|
||||
mv core.h ../
|
||||
|
||||
cd ../widgets_include
|
||||
|
|
|
@ -9,8 +9,7 @@ INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR})
|
|||
# core
|
||||
FILE(GLOB CORE_SRC core/*.cpp)
|
||||
FILE(GLOB CORE_ADAPTER core/adapter/api_linux.cpp
|
||||
core/adapter/audio_linux.cpp
|
||||
core/adapter/msg_linux.cpp)
|
||||
core/adapter/audio_linux.cpp)
|
||||
# gui
|
||||
FILE(GLOB WIDGETS_SRC widgets/*.cpp)
|
||||
|
||||
|
|
|
@ -36,7 +36,7 @@
|
|||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>{DF7A4FAD-A68D-3E43-9C4B-7DE4EE77F732}</ProjectGuid>
|
||||
<WindowsTargetPlatformVersion>10.0.16299.0</WindowsTargetPlatformVersion>
|
||||
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
|
||||
<Keyword>Win32Proj</Keyword>
|
||||
<Platform>Win32</Platform>
|
||||
<ProjectName>GuiLite</ProjectName>
|
||||
|
@ -46,12 +46,12 @@
|
|||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>StaticLibrary</ConfigurationType>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
<PlatformToolset>v141</PlatformToolset>
|
||||
<PlatformToolset>v142</PlatformToolset>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||
<ConfigurationType>StaticLibrary</ConfigurationType>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
<PlatformToolset>v141</PlatformToolset>
|
||||
<PlatformToolset>v142</PlatformToolset>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>StaticLibrary</ConfigurationType>
|
||||
|
@ -390,7 +390,6 @@
|
|||
<ItemGroup>
|
||||
<ClCompile Include="core\adapter\api_win.cpp" />
|
||||
<ClCompile Include="core\adapter\audio_win.cpp" />
|
||||
<ClCompile Include="core\adapter\msg_win.cpp" />
|
||||
<ClCompile Include="core\bitmap.cpp" />
|
||||
<ClCompile Include="core\cmd_target.cpp" />
|
||||
<ClCompile Include="core\display.cpp" />
|
||||
|
|
|
@ -67,9 +67,6 @@
|
|||
<ClCompile Include="core\adapter\audio_win.cpp">
|
||||
<Filter>core\adapter</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="core\adapter\msg_win.cpp">
|
||||
<Filter>core\adapter</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Filter Include="core">
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
#include "../../core_include/api.h"
|
||||
#include "../../core_include/msg.h"
|
||||
#include <unistd.h>
|
||||
#include <pthread.h>
|
||||
#include <string.h>
|
||||
|
@ -14,6 +13,7 @@
|
|||
#include <errno.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#define MAX_TIMER_CNT 10
|
||||
#define TIMER_UNIT 50//ms
|
||||
|
@ -318,3 +318,68 @@ int build_bmp(const char *filename, unsigned int width, unsigned int height, uns
|
|||
fclose(fp);
|
||||
return 0;
|
||||
}
|
||||
|
||||
c_fifo::c_fifo()
|
||||
{
|
||||
m_head = m_tail = 0;
|
||||
m_read_sem = malloc(sizeof(sem_t));
|
||||
m_write_mutex = malloc(sizeof(pthread_mutex_t));
|
||||
|
||||
sem_init((sem_t*)m_read_sem, 0, 0);
|
||||
pthread_mutex_init((pthread_mutex_t*)m_write_mutex, 0);
|
||||
}
|
||||
|
||||
int c_fifo::read(void* buf, int len)
|
||||
{
|
||||
unsigned char* pbuf = (unsigned char*)buf;
|
||||
int i = 0;
|
||||
while(i < len)
|
||||
{
|
||||
if (m_tail == m_head)
|
||||
{//empty
|
||||
sem_wait((sem_t*)m_read_sem);
|
||||
continue;
|
||||
}
|
||||
*pbuf++ = m_buf[m_head];
|
||||
m_head = (m_head + 1) % FIFO_BUFFER_LEN;
|
||||
i++;
|
||||
}
|
||||
if(i != len)
|
||||
{
|
||||
ASSERT(false);
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
int c_fifo::write(void* buf, int len)
|
||||
{
|
||||
unsigned char* pbuf = (unsigned char*)buf;
|
||||
int i = 0;
|
||||
int tail = m_tail;
|
||||
|
||||
pthread_mutex_lock((pthread_mutex_t*)m_write_mutex);
|
||||
while(i < len)
|
||||
{
|
||||
if ((m_tail + 1) % FIFO_BUFFER_LEN == m_head)
|
||||
{//full, clear data has been written;
|
||||
m_tail = tail;
|
||||
log_out("Warning: fifo full\n");
|
||||
pthread_mutex_unlock((pthread_mutex_t*)m_write_mutex);
|
||||
return 0;
|
||||
}
|
||||
m_buf[m_tail] = *pbuf++;
|
||||
m_tail = (m_tail + 1) % FIFO_BUFFER_LEN;
|
||||
i++;
|
||||
}
|
||||
pthread_mutex_unlock((pthread_mutex_t*)m_write_mutex);
|
||||
|
||||
if(i != len)
|
||||
{
|
||||
ASSERT(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
sem_post((sem_t*)m_read_sem);
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
|
|
@ -75,3 +75,56 @@ int build_bmp(const char *filename, unsigned int width, unsigned int height, uns
|
|||
log_out("Not support now");
|
||||
return 0;
|
||||
}
|
||||
|
||||
c_fifo::c_fifo()
|
||||
{
|
||||
m_head = m_tail = 0;
|
||||
m_read_sem = m_write_mutex = 0;
|
||||
}
|
||||
|
||||
int c_fifo::read(void* buf, int len)
|
||||
{
|
||||
unsigned char* pbuf = (unsigned char*)buf;
|
||||
int i = 0;
|
||||
while(i < len)
|
||||
{
|
||||
if (m_tail == m_head)
|
||||
{//empty
|
||||
continue;
|
||||
}
|
||||
*pbuf++ = m_buf[m_head];
|
||||
m_head = (m_head + 1) % FIFO_BUFFER_LEN;
|
||||
i++;
|
||||
}
|
||||
if(i != len)
|
||||
{
|
||||
ASSERT(false);
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
int c_fifo::write(void* buf, int len)
|
||||
{
|
||||
unsigned char* pbuf = (unsigned char*)buf;
|
||||
int i = 0;
|
||||
int tail = m_tail;
|
||||
|
||||
while(i < len)
|
||||
{
|
||||
if ((m_tail + 1) % FIFO_BUFFER_LEN == m_head)
|
||||
{//full, clear data has been written;
|
||||
m_tail = tail;
|
||||
log_out("Warning: fifo full\n");
|
||||
return 0;
|
||||
}
|
||||
m_buf[m_tail] = *pbuf++;
|
||||
m_tail = (m_tail + 1) % FIFO_BUFFER_LEN;
|
||||
i++;
|
||||
}
|
||||
|
||||
if(i != len)
|
||||
{
|
||||
ASSERT(false);
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
#include "../../core_include/api.h"
|
||||
#include "../../core_include/msg.h"
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
|
@ -325,3 +324,68 @@ int build_bmp(const char *filename, unsigned int width, unsigned int height, uns
|
|||
fclose(fp);
|
||||
return 0;
|
||||
}
|
||||
|
||||
c_fifo::c_fifo()
|
||||
{
|
||||
m_head = m_tail = 0;
|
||||
m_read_sem = CreateSemaphore(0, // default security attributes
|
||||
0, // initial count
|
||||
1, // maximum count
|
||||
0); // unnamed semaphore
|
||||
m_write_mutex = CreateMutex(0, false, 0);
|
||||
}
|
||||
|
||||
int c_fifo::read(void* buf, int len)
|
||||
{
|
||||
unsigned char* pbuf = (unsigned char*)buf;
|
||||
int i = 0;
|
||||
while (i < len)
|
||||
{
|
||||
if (m_tail == m_head)
|
||||
{//empty
|
||||
WaitForSingleObject(m_read_sem, INFINITE);
|
||||
continue;
|
||||
}
|
||||
*pbuf++ = m_buf[m_head];
|
||||
m_head = (m_head + 1) % FIFO_BUFFER_LEN;
|
||||
i++;
|
||||
}
|
||||
if (i != len)
|
||||
{
|
||||
ASSERT(false);
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
int c_fifo::write(void* buf, int len)
|
||||
{
|
||||
unsigned char* pbuf = (unsigned char*)buf;
|
||||
int i = 0;
|
||||
int tail = m_tail;
|
||||
|
||||
WaitForSingleObject(m_write_mutex, INFINITE);
|
||||
while (i < len)
|
||||
{
|
||||
if ((m_tail + 1) % FIFO_BUFFER_LEN == m_head)
|
||||
{//full, clear data has been written;
|
||||
m_tail = tail;
|
||||
log_out("Warning: fifo full\n");
|
||||
ReleaseMutex(m_write_mutex);
|
||||
return 0;
|
||||
}
|
||||
m_buf[m_tail] = *pbuf++;
|
||||
m_tail = (m_tail + 1) % FIFO_BUFFER_LEN;
|
||||
i++;
|
||||
}
|
||||
ReleaseMutex(m_write_mutex);
|
||||
|
||||
if (i != len)
|
||||
{
|
||||
ASSERT(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
ReleaseSemaphore(m_read_sem, 1, 0);
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
#include "../../core_include/api.h"
|
||||
#include "../../core_include/msg.h"
|
||||
#include "../../core_include/audio.h"
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
#include <mmdeviceapi.h>
|
||||
|
||||
#include "../../core_include/api.h"
|
||||
#include "../../core_include/msg.h"
|
||||
#include "../../core_include/audio.h"
|
||||
|
||||
#ifndef AUDCLNT_STREAMFLAGS_AUTOCONVERTPCM
|
||||
|
|
|
@ -1,70 +0,0 @@
|
|||
#include "../../core_include/api.h"
|
||||
#include "../../core_include/msg.h"
|
||||
#include <stdlib.h>
|
||||
#include <pthread.h>
|
||||
#include <semaphore.h>
|
||||
|
||||
c_fifo::c_fifo()
|
||||
{
|
||||
m_head = m_tail = 0;
|
||||
m_read_sem = malloc(sizeof(sem_t));
|
||||
m_write_mutex = malloc(sizeof(pthread_mutex_t));
|
||||
|
||||
sem_init((sem_t*)m_read_sem, 0, 0);
|
||||
pthread_mutex_init((pthread_mutex_t*)m_write_mutex, 0);
|
||||
}
|
||||
|
||||
int c_fifo::read(void* buf, int len)
|
||||
{
|
||||
unsigned char* pbuf = (unsigned char*)buf;
|
||||
int i = 0;
|
||||
while(i < len)
|
||||
{
|
||||
if (m_tail == m_head)
|
||||
{//empty
|
||||
sem_wait((sem_t*)m_read_sem);
|
||||
continue;
|
||||
}
|
||||
*pbuf++ = m_buf[m_head];
|
||||
m_head = (m_head + 1) % FIFO_BUFFER_LEN;
|
||||
i++;
|
||||
}
|
||||
if(i != len)
|
||||
{
|
||||
ASSERT(false);
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
int c_fifo::write(void* buf, int len)
|
||||
{
|
||||
unsigned char* pbuf = (unsigned char*)buf;
|
||||
int i = 0;
|
||||
int tail = m_tail;
|
||||
|
||||
pthread_mutex_lock((pthread_mutex_t*)m_write_mutex);
|
||||
while(i < len)
|
||||
{
|
||||
if ((m_tail + 1) % FIFO_BUFFER_LEN == m_head)
|
||||
{//full, clear data has been written;
|
||||
m_tail = tail;
|
||||
log_out("Warning: fifo full\n");
|
||||
pthread_mutex_unlock((pthread_mutex_t*)m_write_mutex);
|
||||
return 0;
|
||||
}
|
||||
m_buf[m_tail] = *pbuf++;
|
||||
m_tail = (m_tail + 1) % FIFO_BUFFER_LEN;
|
||||
i++;
|
||||
}
|
||||
pthread_mutex_unlock((pthread_mutex_t*)m_write_mutex);
|
||||
|
||||
if(i != len)
|
||||
{
|
||||
ASSERT(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
sem_post((sem_t*)m_read_sem);
|
||||
}
|
||||
return i;
|
||||
}
|
|
@ -1,55 +0,0 @@
|
|||
#include "../../core_include/api.h"
|
||||
#include "../../core_include/msg.h"
|
||||
|
||||
c_fifo::c_fifo()
|
||||
{
|
||||
m_head = m_tail = 0;
|
||||
m_read_sem = m_write_mutex = 0;
|
||||
}
|
||||
|
||||
int c_fifo::read(void* buf, int len)
|
||||
{
|
||||
unsigned char* pbuf = (unsigned char*)buf;
|
||||
int i = 0;
|
||||
while(i < len)
|
||||
{
|
||||
if (m_tail == m_head)
|
||||
{//empty
|
||||
continue;
|
||||
}
|
||||
*pbuf++ = m_buf[m_head];
|
||||
m_head = (m_head + 1) % FIFO_BUFFER_LEN;
|
||||
i++;
|
||||
}
|
||||
if(i != len)
|
||||
{
|
||||
ASSERT(false);
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
int c_fifo::write(void* buf, int len)
|
||||
{
|
||||
unsigned char* pbuf = (unsigned char*)buf;
|
||||
int i = 0;
|
||||
int tail = m_tail;
|
||||
|
||||
while(i < len)
|
||||
{
|
||||
if ((m_tail + 1) % FIFO_BUFFER_LEN == m_head)
|
||||
{//full, clear data has been written;
|
||||
m_tail = tail;
|
||||
log_out("Warning: fifo full\n");
|
||||
return 0;
|
||||
}
|
||||
m_buf[m_tail] = *pbuf++;
|
||||
m_tail = (m_tail + 1) % FIFO_BUFFER_LEN;
|
||||
i++;
|
||||
}
|
||||
|
||||
if(i != len)
|
||||
{
|
||||
ASSERT(false);
|
||||
}
|
||||
return i;
|
||||
}
|
|
@ -1,68 +0,0 @@
|
|||
#include "../../core_include/api.h"
|
||||
#include "../../core_include/msg.h"
|
||||
#include <windows.h>
|
||||
|
||||
c_fifo::c_fifo()
|
||||
{
|
||||
m_head = m_tail = 0;
|
||||
m_read_sem = CreateSemaphore(0, // default security attributes
|
||||
0, // initial count
|
||||
1, // maximum count
|
||||
0); // unnamed semaphore
|
||||
m_write_mutex = CreateMutex(0, false, 0);
|
||||
}
|
||||
|
||||
int c_fifo::read(void* buf, int len)
|
||||
{
|
||||
unsigned char* pbuf = (unsigned char*)buf;
|
||||
int i = 0;
|
||||
while(i < len)
|
||||
{
|
||||
if (m_tail == m_head)
|
||||
{//empty
|
||||
WaitForSingleObject(m_read_sem, INFINITE);
|
||||
continue;
|
||||
}
|
||||
*pbuf++ = m_buf[m_head];
|
||||
m_head = (m_head + 1) % FIFO_BUFFER_LEN;
|
||||
i++;
|
||||
}
|
||||
if(i != len)
|
||||
{
|
||||
ASSERT(false);
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
int c_fifo::write(void* buf, int len)
|
||||
{
|
||||
unsigned char* pbuf = (unsigned char*)buf;
|
||||
int i = 0;
|
||||
int tail = m_tail;
|
||||
|
||||
WaitForSingleObject(m_write_mutex, INFINITE);
|
||||
while(i < len)
|
||||
{
|
||||
if ((m_tail + 1) % FIFO_BUFFER_LEN == m_head)
|
||||
{//full, clear data has been written;
|
||||
m_tail = tail;
|
||||
log_out("Warning: fifo full\n");
|
||||
ReleaseMutex(m_write_mutex);
|
||||
return 0;
|
||||
}
|
||||
m_buf[m_tail] = *pbuf++;
|
||||
m_tail = (m_tail + 1) % FIFO_BUFFER_LEN;
|
||||
i++;
|
||||
}
|
||||
ReleaseMutex(m_write_mutex);
|
||||
|
||||
if(i != len)
|
||||
{
|
||||
ASSERT(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
ReleaseSemaphore(m_read_sem, 1, 0);
|
||||
}
|
||||
return i;
|
||||
}
|
|
@ -1,7 +1,6 @@
|
|||
#include "../core_include/api.h"
|
||||
#include "../core_include/rect.h"
|
||||
#include "../core_include/cmd_target.h"
|
||||
#include "../core_include/msg.h"
|
||||
#include "../core_include/surface.h"
|
||||
#include "../core_include/display.h"
|
||||
|
||||
|
|
|
@ -53,4 +53,19 @@ unsigned int get_cur_thread_id();
|
|||
void create_thread(unsigned long* thread_id, void* attr, void *(*start_routine) (void *), void* arg);
|
||||
void thread_sleep(unsigned int milli_seconds);
|
||||
int build_bmp(const char *filename, unsigned int width, unsigned int height, unsigned char *data);
|
||||
|
||||
#define FIFO_BUFFER_LEN 1024
|
||||
class c_fifo
|
||||
{
|
||||
public:
|
||||
c_fifo();
|
||||
int read(void* buf, int len);
|
||||
int write(void* buf, int len);
|
||||
private:
|
||||
unsigned char m_buf[FIFO_BUFFER_LEN];
|
||||
int m_head;
|
||||
int m_tail;
|
||||
void* m_read_sem;
|
||||
void* m_write_mutex;
|
||||
};
|
||||
#endif
|
||||
|
|
|
@ -1,27 +0,0 @@
|
|||
#ifndef GUILITE_CORE_INCLUDE_MSG_H
|
||||
#define GUILITE_CORE_INCLUDE_MSG_H
|
||||
|
||||
typedef struct
|
||||
{
|
||||
unsigned int dwMsgId;
|
||||
unsigned int dwParam1;
|
||||
unsigned int dwParam2;
|
||||
}MSG_INFO;
|
||||
|
||||
#define FIFO_BUFFER_LEN 1024
|
||||
class c_fifo
|
||||
{
|
||||
public:
|
||||
c_fifo();
|
||||
int read(void* buf, int len);
|
||||
int write(void* buf, int len);
|
||||
|
||||
private:
|
||||
unsigned char m_buf[FIFO_BUFFER_LEN];
|
||||
int m_head;
|
||||
int m_tail;
|
||||
void* m_read_sem;
|
||||
void* m_write_mutex;
|
||||
};
|
||||
|
||||
#endif
|
|
@ -1,5 +1,4 @@
|
|||
#include "../core_include/api.h"
|
||||
#include "../core_include/msg.h"
|
||||
#include "../core_include/rect.h"
|
||||
#include "../core_include/surface.h"
|
||||
#include "../core_include/display.h"
|
||||
|
|
Loading…
Reference in New Issue