Add Simulator part of ShimLib.
This commit is contained in:
@@ -11,8 +11,12 @@
|
|||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#include <arpa/inet.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/socket.h>
|
||||||
|
#include <string.h>
|
||||||
#endif
|
#endif
|
||||||
|
#include <stdbool.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
typedef void(*error_cb)(const char* msg);
|
typedef void(*error_cb)(const char* msg);
|
||||||
@@ -22,6 +26,7 @@ typedef void(*message_callback)(const char* aMessage,const unsigned int aInfoTyp
|
|||||||
int statusCountFlag = 0;
|
int statusCountFlag = 0;
|
||||||
error_cb innerCallback = NULL;
|
error_cb innerCallback = NULL;
|
||||||
message_callback msgCallback = NULL;
|
message_callback msgCallback = NULL;
|
||||||
|
bool isAutoScan = false;
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
void ThreadFunc(void*);
|
void ThreadFunc(void*);
|
||||||
@@ -29,7 +34,9 @@ HANDLE th;
|
|||||||
HANDLE e1,e2;
|
HANDLE e1,e2;
|
||||||
#else
|
#else
|
||||||
void* ThreadFunc(void*);
|
void* ThreadFunc(void*);
|
||||||
|
void InitSever();
|
||||||
pthread_t th;
|
pthread_t th;
|
||||||
|
pthread_t severThread;
|
||||||
sem_t e1;
|
sem_t e1;
|
||||||
sem_t e2;
|
sem_t e2;
|
||||||
#endif
|
#endif
|
||||||
@@ -46,6 +53,7 @@ int InitLib(error_cb cb)
|
|||||||
sem_init(&e1, 0, 0);
|
sem_init(&e1, 0, 0);
|
||||||
sem_init(&e2, 0, 0);
|
sem_init(&e2, 0, 0);
|
||||||
th = pthread_create(&th, NULL, ThreadFunc, (void*)"");
|
th = pthread_create(&th, NULL, ThreadFunc, (void*)"");
|
||||||
|
severThread = pthread_create(&severThread, NULL, InitSever, (void*)"");
|
||||||
#endif
|
#endif
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -92,42 +100,173 @@ void* ThreadFunc(__attribute__((unused))void* args)
|
|||||||
{
|
{
|
||||||
GetPreviewData();
|
GetPreviewData();
|
||||||
}
|
}
|
||||||
for (int i = 0; i <= 50; ++i) {
|
if (isAutoScan)
|
||||||
if (stop_flag > 0 || status != SCANNING){
|
{
|
||||||
stop_flag = 0;
|
for (int i = 0; i <= 50; ++i)
|
||||||
break;
|
{
|
||||||
}
|
if (stop_flag > 0 || status != SCANNING)
|
||||||
if (i == 20){
|
{
|
||||||
progress = 139;
|
stop_flag = 0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (i == 20)
|
||||||
|
{
|
||||||
|
progress = 139;
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
WaitForSingleObject(e2, INFINITE);
|
WaitForSingleObject(e2, INFINITE);
|
||||||
#else
|
#else
|
||||||
sem_wait(&e2);
|
sem_wait(&e2);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
else if (i > 20 && i < 35)
|
||||||
|
{
|
||||||
|
progress = i * 2 + 100;
|
||||||
|
}
|
||||||
|
else if (i >= 35)
|
||||||
|
{
|
||||||
|
progress = i * 2 + 200;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
progress = i * 2;
|
||||||
|
}
|
||||||
|
if (stop_flag > 0 || status != SCANNING)
|
||||||
|
{
|
||||||
|
stop_flag = 0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
#ifdef _WIN32
|
||||||
|
Sleep(300);
|
||||||
|
#else
|
||||||
|
usleep(300000);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
else if ( i > 20 && i<35){
|
}
|
||||||
progress = i * 2 + 100;
|
else
|
||||||
|
{
|
||||||
|
while (progress < 100)
|
||||||
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
else if(i >= 35){
|
}
|
||||||
progress = i * 2 + 200;
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
progress = i *2;
|
|
||||||
}
|
|
||||||
if (stop_flag > 0 || status != SCANNING){
|
|
||||||
stop_flag = 0;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
#ifdef _WIN32
|
|
||||||
Sleep(300);
|
|
||||||
#else
|
|
||||||
usleep(300000);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
status = READY;
|
status = READY;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
#else
|
||||||
|
void InitSever()
|
||||||
|
{
|
||||||
|
int severFd = socket(AF_INET,SOCK_STREAM,0);
|
||||||
|
if (-1 == severFd)
|
||||||
|
{
|
||||||
|
printf("socket failed");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
struct sockaddr_in severAddr;
|
||||||
|
severAddr.sin_family = AF_INET;
|
||||||
|
severAddr.sin_addr.s_addr = htonl(INADDR_ANY);
|
||||||
|
severAddr.sin_port = htons(8888);
|
||||||
|
if(0> bind(severFd,(struct sockaddr*)&severAddr,sizeof(severAddr)))
|
||||||
|
{
|
||||||
|
printf("bind failed");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(0> listen(severFd,2))
|
||||||
|
{
|
||||||
|
printf("listen failed");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
while (1)
|
||||||
|
{
|
||||||
|
int clientFd;
|
||||||
|
struct sockaddr_in clientAddr;
|
||||||
|
socklen_t clientAddrLen = sizeof(clientAddr);
|
||||||
|
clientFd = accept(severFd, (struct sockaddr*)&clientAddr, &clientAddrLen);
|
||||||
|
if (0 > clientFd)
|
||||||
|
{
|
||||||
|
printf("accept failed\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
printf("accept sucess\n");
|
||||||
|
while (1)
|
||||||
|
{
|
||||||
|
isAutoScan = false;
|
||||||
|
char receiveBuffer[64] = { 0 };
|
||||||
|
int ref = recv(clientFd, receiveBuffer, 64, 0);
|
||||||
|
if (ref > 0)
|
||||||
|
{
|
||||||
|
printf("received %s\n", receiveBuffer);
|
||||||
|
char* data = strtok(receiveBuffer,",");
|
||||||
|
if (!data || strlen(data) != 1)
|
||||||
|
{
|
||||||
|
send(clientFd,"unknow command",sizeof("unknow command"),0);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (data[0] == '0')
|
||||||
|
{
|
||||||
|
char* arg1 = strtok(NULL,",");
|
||||||
|
char* arg2 = strtok(NULL,",");
|
||||||
|
if (!arg1 || !arg2)
|
||||||
|
{
|
||||||
|
send(clientFd,"unknow command",sizeof("unknow command"),0);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
msgCallback(arg1, atoi(arg2));
|
||||||
|
send(clientFd,"msgCallback sucess",sizeof("msgCallback sucess"),0);
|
||||||
|
}
|
||||||
|
else if (data[0] == '1')
|
||||||
|
{
|
||||||
|
char* arg1 = strtok(NULL,",");
|
||||||
|
if (!arg1)
|
||||||
|
{
|
||||||
|
send(clientFd,"unknow command",sizeof("unknow command"),0);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
innerCallback(arg1);
|
||||||
|
send(clientFd,"innerCallback sucess",sizeof("innerCallback sucess"),0);
|
||||||
|
}
|
||||||
|
else if (data[0] == 'p')
|
||||||
|
{
|
||||||
|
char* arg1 = strtok(NULL, ",");
|
||||||
|
if (!arg1)
|
||||||
|
{
|
||||||
|
send(clientFd,"unknow command",sizeof("unknow command"),0);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (status == SCANNING)
|
||||||
|
{
|
||||||
|
progress = atoi(arg1);
|
||||||
|
send(clientFd, "set scan progress sucess", sizeof("set scan progress sucess"), 0);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
send(clientFd, "status is not scaning", sizeof("status is not scaning"), 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (data[0] == 'e')
|
||||||
|
{
|
||||||
|
printf("client closed\n");
|
||||||
|
close(clientFd);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
printf("client closed\n");
|
||||||
|
close(clientFd);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
isAutoScan = true;
|
||||||
|
close(clientFd);
|
||||||
|
}
|
||||||
|
close(severFd);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
int ScanControl(ScanAction actionType) {
|
int ScanControl(ScanAction actionType) {
|
||||||
|
|
||||||
switch (actionType) {
|
switch (actionType) {
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ void ImageSwitch::paintEvent(QPaintEvent*)
|
|||||||
{
|
{
|
||||||
QPainter painter(this);
|
QPainter painter(this);
|
||||||
painter.setRenderHints(QPainter::SmoothPixmapTransform);
|
painter.setRenderHints(QPainter::SmoothPixmapTransform);
|
||||||
QImage img(mIsChecked ? mImgOffFile : mImgOnFile);
|
QImage img(mIsChecked ? mImgOnFile : mImgOffFile);
|
||||||
img = img.scaled(this->size(), Qt::KeepAspectRatio, Qt::SmoothTransformation);
|
img = img.scaled(this->size(), Qt::KeepAspectRatio, Qt::SmoothTransformation);
|
||||||
//按照比例自动居中绘制
|
//按照比例自动居中绘制
|
||||||
int pixX = rect().center().x() - img.width() / 2;
|
int pixX = rect().center().x() - img.width() / 2;
|
||||||
|
|||||||
@@ -359,7 +359,7 @@ void DialogManager::invokeOperationStart(QObject *parent, QObject *msg) {
|
|||||||
if (mOperationMessageDialog->isHidden())
|
if (mOperationMessageDialog->isHidden())
|
||||||
{
|
{
|
||||||
mOperationMessageDialog->showFullScreen();
|
mOperationMessageDialog->showFullScreen();
|
||||||
mOperationMessageDialog->exec();
|
//mOperationMessageDialog->exec();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -382,7 +382,7 @@ void DialogManager::invokeOperationProgress(QObject *parent, QObject *msg) {
|
|||||||
if (mOperationMessageDialog->isHidden())
|
if (mOperationMessageDialog->isHidden())
|
||||||
{
|
{
|
||||||
mOperationMessageDialog->showFullScreen();
|
mOperationMessageDialog->showFullScreen();
|
||||||
mOperationMessageDialog->exec();
|
//mOperationMessageDialog->exec();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user