void CommunicationClient::doWork() { run(); //_isRunning = true; // moved to init while(_isRunning) { QMutexLocker locker(_waitMutex); // _waitForDataCondition->wait(_waitMutex); try { if(!onImageReceived.empty()) { Container::Images::Image image; getImage(image, true); if(image.frameIndexSize() > 0 && image.width() != 0 && image.height() != 0) { onImageReceived(image); } } } catch(const std::exception& ex) { D_OUT2(__FUNCTION__, ex.what()); _isRunning = false; } catch (...) {} QThread::msleep(10); } }
void CommunicationClientDetector::handleMessage( Core::Communication::Message message ) { D_OUT2(__FUNCTION__, "HandleMessage:"); unsigned int messagetype =0; memcpy(&messagetype, message.body(), 4); std::cout << std::hex << messagetype << std::dec << std::endl; if(messagetype == (unsigned int)Core::Communication::MessageType::Hello) { sendHello(); } }
int token_write(token* my_token, int type, const void* source) { D_OUT2("Writing to [%08x] token, type = %d\n", my_token, type); int c = 0; int str_len = 0; double temp = 0; switch (type) { case TKN_OP: c = *((int*)source); D_OUT1("Got [%c]", c); VERIFY1((c != '+' && c != '-' && c != '*' && c != '/'), TOKEN_BAD, "TOKEN_WRITE(): Expected +-//*, got [%c]", c); TOKEN_BURN(TKN_OP, int); break; case TKN_COMP: c = *((int*)source); D_OUT1("Got [%d] code", c); VERIFY1( (!(c >= CMP_B && c <= CMP_NE)), TOKEN_BAD, "TOKEN_WRITE(): got [%d]", c); TOKEN_BURN(TKN_COMP, int); break; case TKN_ID: str_len = strlen((char*)source); VERIFY1(str_len > MAXLINE, TOKEN_BAD, "TOKEN_WRITE(): got too big identificator \n%50s", (char*)source); D_OUT1("Got [%s]", (char*)source); VERIFY1(token_word_is_valid((char*)source) == 0, TOKEN_BAD, "TOKEN_WRITE(): got invalid identificator only [-_A-Za-z] allowed, '_' can't be first, got [%s]", (char*)source); VERIFY1(token_word_is_key ((char*)source) != 0, TOKEN_BAD, "TOKEN_WRITE(): inputted identificator is key word, got [%s]", (char*)source); my_token -> type = type; my_token -> value = calloc(str_len + 2, sizeof(char)); assert(my_token -> value); strcpy((char*)my_token -> value, (char*)source); break; case TKN_NUM: D_OUT1("Got [%lg]", *((double*)source)); TOKEN_BURN(TKN_NUM, double); break; case TKN_SEP: c = *((char*)(source)); D_OUT1("Got [%c]", c); VERIFY1((c!= ',' && c != ';' && c != '(' && c != ')' && c != '{' && c != '}'), TOKEN_BAD, "TOKEN_WRITE(): Expected ;{}(), got [%c]", c); TOKEN_BURN(TKN_SEP, int); break; case TKN_ASSGN: c = *((int*)source); D_OUT1("Got [%d] code", c); VERIFY1( (!(ASSGN <= c && c <= ASSGN_DIV)), TOKEN_BAD, "TOKEN_WRITE(): input assign code is wrong [%d]", c); TOKEN_BURN(TKN_ASSGN, int); break; case TKN_STR: str_len = strlen((char*)source); VERIFY1(str_len > MAXLINE, TOKEN_BAD, "TOKEN_WRITE(): got too big string \n%50s", (char*)source); D_OUT1("Got [%s]", (char*)source); my_token -> type = type; my_token -> value = calloc(str_len + 2, sizeof(char)); assert(my_token -> value); strcpy((char*)my_token -> value, (char*)source); break; case TKN_END: c = *((int*)source); D_OUT1("Got [%d]", c); VERIFY1(c != 0, TOKEN_BAD, "TOKEN_WRITE(): strange end [%c]", *(char*)source); TOKEN_BURN(TKN_END, int); break; case TKN_KEY: c = *((int*)source); D_OUT1("Got [%d] code", c);my_token -> type = type; VERIFY1( (!(WORD_if <= c && c <= WORD_print_val)), TOKEN_BAD, "TOKEN_WRITE(): input key code is wrong [%d]", c); TOKEN_BURN(TKN_KEY, int); break; default: VERIFY1(true, TOKEN_BAD, "Invalid type of token type, got [%d]", type); break; } D_OUT("Token written successfully"); return TOKEN_OK; }