I have been reposting same problem years as there are almost thousands of views but zero replies.
I am far from Class, Methods and OOP way that is why I noway understand the algorithm of source.
from header file:
Command.h:
Code: Select all
#define INITDONE_EVENT 4
#define STATECHANGED_EVENT 5
typedef enum L_ERROR
{
L_NO_ERROR = 0, /*!< No errors */
L_CONNECT_ERROR = 1, /*!< The Error of connection */
L_MEMORY_ERROR = 2, /*!< Out of memory */
L_RESOURCES_ERROR = 3, /*!< The Error of the allocating resource IPC */
L_EXIT_ERROR = 7, /*!< The thread terminated */
L_ARG_ERROR = 10, /*!< Wrong function arguments. */
} L_ERROR;
typedef enum L_COMMAND
{
L_CMD_NOP = 0, /*!< empty command */
L_CMD_EXIT = 1, /*!< terminate the thread */
L_CMD_STOP = 2, /*!< stop the mode of waiting for command */
L_CMD_START = 6, /*!< start the mode of waiting for command */
} L_COMMAND;
typedef struct L_HANDLE
{
L_COMMAND command;
void* visual_ptr;
QMutex* image_lock;
}L_HANDLE;
/*Get command to Client thread*/
L_COMMAND getCommand(L_HNDL handle)
/*Send command to the client library thread.*/
void sendCommand(L_HNDL handle, L_COMMAND command );
typedef struct LClient
{
L_HNDL Client;
L_COMMAND (*GetCommand)( L_HNDL Cl );
} LSClient;
__declspec(dllexport) L_ERROR LInit( LClient *cl, L_DEV dev, int num );
__declspec(dllexport) L_ERROR LStart( LClient *cl );
__declspec(dllexport) void LShutDown( LClient* cl );
Command.cpp:
Code: Select all
L_COMMAND getCommand( L_HNDL handle )
{
L_HANDLE* hndl = (L_HANDLE*) handle;
L_COMMAND cmd;
cmd = hndl->command;
hndl->command = L_CMD_NOP;
return cmd;
}
void sendCommand( L_HNDL handle, L_COMMAND command )
{
L_HANDLE* hndl = (L_HANDLE*) handle;
while( hndl->command != L_CMD_NOP )
{
#ifdef _WIN32
SleepEx( 10, TRUE );
#else
usleep( 10000 );
#endif
}
hndl->command = command;
}
void initDone( L_HNDL handle )
{
L_HANDLE* hndl = (L_HANDLE*) handle;
QCustomEvent* event = new QCustomEvent( (QEvent::Type) (QEvent::User + INITDONE_EVENT) );
QApplication::postEvent( (QObject*) hndl->visual_ptr, event );
}
Code: Select all
/* Send start command to lclient */
void mainForm::startSlot()
{
sendCommand( &l_handle, L_CMD_START );
}
/* Send stop command to lclient */
void mainForm::stopSlot()
{
sendCommand( &l_handle, L_CMD_STOP );
}
This is unusual way for me and I can not understand to translate to PB and no hint in the forum.
Will be very glad for any explanation