diff --git a/1h-1cpp.sh b/1h-1cpp.sh index 9705305..ab7e441 100644 --- a/1h-1cpp.sh +++ b/1h-1cpp.sh @@ -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 diff --git a/CMakeLists.txt b/CMakeLists.txt index 1afb164..4b56569 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) diff --git a/GuiLite.vcxproj b/GuiLite.vcxproj index 00e41e1..0968458 100644 --- a/GuiLite.vcxproj +++ b/GuiLite.vcxproj @@ -36,7 +36,7 @@ {DF7A4FAD-A68D-3E43-9C4B-7DE4EE77F732} - 10.0.16299.0 + 10.0 Win32Proj Win32 GuiLite @@ -46,12 +46,12 @@ StaticLibrary Unicode - v141 + v142 StaticLibrary Unicode - v141 + v142 StaticLibrary @@ -390,7 +390,6 @@ - diff --git a/GuiLite.vcxproj.filters b/GuiLite.vcxproj.filters index 9a0f08d..ca7a913 100644 --- a/GuiLite.vcxproj.filters +++ b/GuiLite.vcxproj.filters @@ -67,9 +67,6 @@ core\adapter - - core\adapter - diff --git a/core/adapter/api_linux.cpp b/core/adapter/api_linux.cpp index 77bca59..f709bb6 100644 --- a/core/adapter/api_linux.cpp +++ b/core/adapter/api_linux.cpp @@ -1,5 +1,4 @@ #include "../../core_include/api.h" -#include "../../core_include/msg.h" #include #include #include @@ -14,6 +13,7 @@ #include #include #include +#include #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; +} diff --git a/core/adapter/api_unknow.cpp b/core/adapter/api_unknow.cpp index 040d795..3c0ccd6 100644 --- a/core/adapter/api_unknow.cpp +++ b/core/adapter/api_unknow.cpp @@ -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; +} diff --git a/core/adapter/api_win.cpp b/core/adapter/api_win.cpp index 5247b30..8731eaa 100644 --- a/core/adapter/api_win.cpp +++ b/core/adapter/api_win.cpp @@ -1,5 +1,4 @@ #include "../../core_include/api.h" -#include "../../core_include/msg.h" #include #include #include @@ -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; +} diff --git a/core/adapter/audio_linux.cpp b/core/adapter/audio_linux.cpp index 3998e8c..eca574a 100644 --- a/core/adapter/audio_linux.cpp +++ b/core/adapter/audio_linux.cpp @@ -1,5 +1,4 @@ #include "../../core_include/api.h" -#include "../../core_include/msg.h" #include "../../core_include/audio.h" #include #include diff --git a/core/adapter/audio_win.cpp b/core/adapter/audio_win.cpp index 77c4945..bb89b89 100644 --- a/core/adapter/audio_win.cpp +++ b/core/adapter/audio_win.cpp @@ -3,7 +3,6 @@ #include #include "../../core_include/api.h" -#include "../../core_include/msg.h" #include "../../core_include/audio.h" #ifndef AUDCLNT_STREAMFLAGS_AUTOCONVERTPCM diff --git a/core/adapter/msg_linux.cpp b/core/adapter/msg_linux.cpp deleted file mode 100644 index c02c34c..0000000 --- a/core/adapter/msg_linux.cpp +++ /dev/null @@ -1,70 +0,0 @@ -#include "../../core_include/api.h" -#include "../../core_include/msg.h" -#include -#include -#include - -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; -} diff --git a/core/adapter/msg_unknow.cpp b/core/adapter/msg_unknow.cpp deleted file mode 100644 index e47db0f..0000000 --- a/core/adapter/msg_unknow.cpp +++ /dev/null @@ -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; -} diff --git a/core/adapter/msg_win.cpp b/core/adapter/msg_win.cpp deleted file mode 100644 index 59598a8..0000000 --- a/core/adapter/msg_win.cpp +++ /dev/null @@ -1,68 +0,0 @@ -#include "../../core_include/api.h" -#include "../../core_include/msg.h" -#include - -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; -} diff --git a/core/display.cpp b/core/display.cpp index 81238ed..dd219c1 100644 --- a/core/display.cpp +++ b/core/display.cpp @@ -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" diff --git a/core_include/api.h b/core_include/api.h index c68f3f4..53cf5c6 100644 --- a/core_include/api.h +++ b/core_include/api.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 diff --git a/core_include/msg.h b/core_include/msg.h deleted file mode 100644 index 1230637..0000000 --- a/core_include/msg.h +++ /dev/null @@ -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 diff --git a/widgets/gesture.cpp b/widgets/gesture.cpp index e1ce8fe..73e08de 100644 --- a/widgets/gesture.cpp +++ b/widgets/gesture.cpp @@ -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"