Ejemplo n.º 1
0
DWORD WINAPI MyThreadProc(LPVOID lpParameter)
{
	MSG msg;
	BOOL bRet;

	printf("MyThreadProc start\n");
	
	bRet = ::PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE);
	printf("Message queue created. %d\n", bRet);

	::SetEvent(hEvent);

	while( (bRet = ::GetMessage( &msg, NULL, 0, 0 )) != 0)
	{ 
		if (bRet == -1)
		{
			// handle the error and possibly exit
			printf("GetMessage error: %d\n", GetLastError());
		}
		else
		{
			processMsg(&msg);
		}
	}

	const char* yesorno = (msg.message == WM_QUIT) ? "yes" : "no";
	printf("MyThreadProc exit. msg.message=%d, WM_QUIT=%s\n", msg.message, yesorno);
	return msg.wParam;
}
Ejemplo n.º 2
0
void tsClient :: startConnection()
{
    while(true) {
        tv.tv_sec = 0;
        tv.tv_usec = SHORT_TIMER*1000; //time expire after short timer expiry
        tvptr = &tv;
        FD_ZERO(&master);
        master = read_fds;
        result = select( fd_max+1, &master, NULL, NULL, tvptr);
        ERROR(result==-1,__FILE__,__LINE__);
        if( FD_ISSET( sockId, & master) ) {
            recvMsg();
            processMsg();
        }
        else if(periodicTimer == true) {
            presentTime += SHORT_TIMER;
            updateNodePos();
            if(presentTime == targetTime) //convert ns timer from sec to millisecond
            {
                //this is NS timer expiry, send update to NS
                makeSendMsg(NS_CONN);
                targetTime += timeInterval;
            } 
            if(presentTime == dsTargetTime)
            {
                //this is dS timer expiry, send update to DS
                makeSendMsg(DS_CONN);
                dsTargetTime += dsTimeInterval;
            }

        }
    }
    close(sockId);
}
Ejemplo n.º 3
0
int main(int argc, char **argv)
{
  if ((GTDragBase = OpenLibrary("gtdrag.library",3)) != 0)
  {
    if (GTD_AddApp("dragtest",GTDA_NewStyle,TRUE,TAG_END))
    {
      if ((scr = LockPubScreen(NULL)) != 0)
      {
        vi = GetVisualInfo(scr,TAG_END);
        fontheight = scr->Font->ta_YSize;
        init();

        if ((win = initWindow()) != 0)
        {
          processMsg();
          CloseWindow(win);
        }
        FreeGadgets(glist);

        cleanup();
        FreeVisualInfo(vi);
        UnlockPubScreen(NULL,scr);
      }
      GTD_RemoveApp();
    }
    CloseLibrary(GTDragBase);
  }
  return 0;
}
Ejemplo n.º 4
0
void IRC::processTick()
{
    uint8_t counter = 0;

    // in case a lot of messages are in the queue processTick() will block the rest of the bot
    // --> leave while after max 5 loops
    while(!IRC::_msgQueue.empty() && counter < 5)
    {
        ircMsg ircMsg = IRC::_msgQueue.front();

#ifdef DEBUG
        std::cerr << "IRC::processTick() ircMsg:" << std::endl;
        std::cerr << " -- session: " << ircMsg.session << std::endl;
        std::cerr << " -- msg: " << ircMsg.msg << std::endl;
        std::cerr << " -- nick: " << ircMsg.nick << std::endl;
#endif

        // auto response
        if(!ircMsg.disableAutoResponse)
            processAutoResponse(ircMsg);

        processMsg(ircMsg);

        // remove item
        IRC::_msgQueue.pop();
        counter++;
    }
}
Ejemplo n.º 5
0
bool AutoResponse::processMsgIrc(std::string& inMsg, std::string& inNick, std::vector<std::string>& out, std::string& ownNick)
{
    if(!_options->enable)
        return false;

    //std::cout << "AutoResponse::processMsgIrc() processing message " << inMsg << std::endl;

    return processMsg(inMsg, Utils::MODULE_IRC, inNick, ownNick, out);
}
Ejemplo n.º 6
0
bool AutoResponse::processMsgRetroShare(rsctrl::chat::ChatMessage& in, std::vector<std::string>& out, std::string& ownNick)
{
    if(!_options->enable)
        return false;

    //std::cout << "AutoResponse::processMsgRetroShare() processing message " << in.msg() << std::endl;

    std::string msg = in.msg();
    return processMsg(msg, Utils::MODULE_RETROSHARE, in.peer_nickname(), ownNick, out);

}
Ejemplo n.º 7
0
 void handleGlobalTimeSync(const ReceivedDataStructure<protocol::GlobalTimeSync>& msg)
 {
     if (msg.getTransferType() == TransferTypeMessageBroadcast)
     {
         processMsg(msg);
     }
     else
     {
         UAVCAN_TRACE("GlobalTimeSyncSlave", "Invalid transfer type %i", int(msg.getTransferType()));
     }
 }
Ejemplo n.º 8
0
void TFHandler::handleMsg(const tf2_msgs::TFMessage& msg)
{
	if(!m_node->live())
		return;

	processMsg(msg);

	m_rawTFLog.push_back(msg);
	trimRawTFLog();

	m_pub_tf.publish(msg);
}
Ejemplo n.º 9
0
void WpaGui::receiveMsgs()
{
    char buf[256];printf("========== WpaGui::receiveMsgs Function.=========\n");
    size_t len;

    while (monitor_conn && wpa_ctrl_pending(monitor_conn) > 0) {
            len = sizeof(buf) - 1;
            if (wpa_ctrl_recv(monitor_conn, buf, &len) == 0) {
                    buf[len] = '\0';printf("======== receiveMsgs:%s \n",buf);
                    processMsg(buf);
            }
    }
}
Ejemplo n.º 10
0
void WpaGui::receiveMsgs()
{
	char buf[256];
	size_t len;

	while (monitor_conn && wpa_ctrl_pending(monitor_conn) > 0) {
		len = sizeof(buf) - 1;
		if (wpa_ctrl_recv(monitor_conn, buf, &len) == 0) {
			buf[len] = '\0';
			processMsg(buf);
		}
	}
}
Ejemplo n.º 11
0
void processMsg(netmgr::ConnectionMgr& mgr)
{
    while(true)
    {
        netmgr::Message* m = mgr.PopMsg(true);
        if (NULL == m)
        {
            LOG_ERROR("popmsg error");
            continue;
        }
        BASE_BLOCK_GUARD(&netmgr::MappedMsgFactory::Destroy, *netmgr::GetGlobalMsgFactory(), m);
        assert(m);
        LOG_DEBUG("recv msg:%s, content:%s", m->GetTypeName().c_str(), m->ToString().c_str());
        std::string msgName = m->GetTypeName();
        if (msgName == "netmgr::LineMessage")
        {
            netmgr::LineMessage* req = dynamic_cast<netmgr::LineMessage*>(m);
            netmgr::LineMessage res;
            processMsg(*req, res);
            int ret = mgr.PushMsg(&res);
            LOG_DEBUG("send msg ret:%d", ret);
        }
        else if (msgName == "AddRequest")
        {
            AddRequest* req = dynamic_cast<AddRequest*>(m);
            AddResult res;
            processMsg(*req, res);
            int ret = mgr.PushMsg(&res);
            LOG_DEBUG("send msg ret:%d", ret);
        }
        else
        {
            LOG_ERROR("recv unknown msg:[%s]", m->GetTypeName().c_str());
        }
    }
}
Ejemplo n.º 12
0
void start_server(int sockfd) {
    struct sockaddr_in addr;
    int n;
    socklen_t addrlen;
    struct chatmsg msg;
    pthread_t th;
    pthread_create(&th, NULL, checklive, NULL);
    while (1) {
        addrlen = sizeof(struct sockaddr_in);
        n = recvfrom(sockfd, (void *)&msg, sizeof(struct chatmsg), 0, (struct sockaddr*)&addr, &addrlen);
        if (msg.msgtype == CHATMSG_CHAT)
            fprintf(stdout, "receved msg from %d: msgid: %d msg: %s", msg.userid, msg.msgid, msg.msgbuf);
        else if (msg.msgtype == CHATMSG_JOIN)
            fprintf(stdout, "%d join the room\n", msg.userid);
        processMsg(sockfd, addr, msg);
    }
}
Ejemplo n.º 13
0
void Thread::readMsg()
{
	ThreadMsg* p;
	if (read(toThreadFdr, &p, sizeof (p)) != sizeof (p))
	{
		perror("Thread::readMessage(): read pipe failed");
		exit(-1);
	}
	processMsg(p);
	char c = 'x';
	int rv = write(fromThreadFdw, &c, 1);
	if (rv != 1)
		perror("Thread::readMessage(): write pipe failed");
	//int c = p->serialNo;
	//int rv = write(fromThreadFdw, &c, sizeof(c));
	//if (rv != sizeof(c))
	//      perror("Thread::readMsg(): write pipe failed");
}
Ejemplo n.º 14
0
int QPacketParse::prcessCommand(const QString &pack, void **result)
{
    switch ( m_packtype )
    {
    case IQ:
        {
            break;
        }
    case Message:
        {
            return processMsg(pack,result);
        }
    default:
        {
            return None;
            break;
        }
    }
}
Ejemplo n.º 15
0
void AtlantikNetwork::slotRead()
{
	if ( socketStatus() != KExtendedSocket::connected )
		return;

	if (canReadLine())
	{
		processMsg(m_textStream->readLine());
		// There might be more data
		QTimer::singleShot(0, this, SLOT(slotRead()));
	}
	else
	{
		// Maximum message size. Messages won't get bigger than 32k anyway, so
		// if we didn't receive a newline by now, we probably won't anyway.
		if (bytesAvailable() > (1024 * 32))
			flush();
	}
}
Ejemplo n.º 16
0
bool Thread::sendMsg(const ThreadMsg* m)
{
	// Changed by Tim. p3.3.17

	if (_running)
	{
		int rv = write(toThreadFdw, &m, sizeof (ThreadMsg*));
		if (rv != sizeof (ThreadMsg*))
		{
			perror("Thread::sendMessage(): write pipe failed");
			return true;
		}

		// wait for sequencer to finish operation
		char c;
		rv = read(fromThreadFdr, &c, 1);
		if (rv != 1)
		{
			perror("Thread::sendMessage(): read pipe failed");
			return true;
		}
		//int c;
		//rv = read(fromThreadFdr, &c, sizeof(c));
		//if (rv != sizeof(c)) {
		//      perror("Thread::sendMessage(): read pipe failed");
		//      return true;
		//      }
	}
	else
	{
		// if thread is not running (during initialization)
		// process commands directly:
		processMsg(m);
	}
	return false;
}
Ejemplo n.º 17
0
static void MAMACALLTYPE
dict_onMsg (mamaSubscription subsc, mamaMsg msg, void *dictionary, void *notUsed)
{
    processMsg( self, msg );
}
Ejemplo n.º 18
0
 bool RunOnce()
 {
     processMsg(*_conMgr);
     return true;
 }
Ejemplo n.º 19
0
    void messageLoop()
      {
          fd_set read_fds;
          fd_set read_fds_back;
          char buf[8192];
          std::memset( &buf, 0, sizeof( char ) * 8192 );

          int in = fileno( stdin );
          FD_ZERO( &read_fds );
          FD_SET( in, &read_fds );
          FD_SET( M_socket.getFD(), &read_fds );
          read_fds_back = read_fds;

#ifdef RCSS_WIN
          int max_fd = 0;
#else
          int max_fd = M_socket.getFD() + 1;
#endif
          while ( 1 )
          {

              read_fds = read_fds_back;
              int ret = ::select( max_fd, &read_fds, NULL, NULL, NULL );
              if ( ret < 0 )
              {
                  perror( "Error selecting input" );
                  break;
              }
              else if ( ret != 0 )
              {
                  // read from stdin
                  if ( FD_ISSET( in, &read_fds ) )
                  {
                      if ( std::fgets( buf, sizeof( buf ), stdin ) != NULL )
                      {
                          size_t len = std::strlen( buf );
                          if ( buf[len-1] == '\n' )
                          {
                              buf[len-1] = '\0';
                              --len;
                          }

                          M_transport->write( buf, len + 1 );
                          M_transport->flush();
                          if ( ! M_transport->good() )
                          {
                              if ( errno != ECONNREFUSED )
                              {
                                  std::cerr << __FILE__ << ": " << __LINE__
                                            << ": Error sending to socket: "
                                            << strerror( errno ) << std::endl
                                            << "msg = [" << buf << "]\n";
                              }
                              M_socket.close();
                          }
                          std::cout << buf << std::endl;
                      }
                  }

                  // read from socket
                  if ( FD_ISSET( M_socket.getFD(), &read_fds ) )
                  {
                      rcss::net::Addr from;
                      int len = M_socket.recv( buf, sizeof( buf ) - 1, from );
                      if ( len == -1
                           && errno != EWOULDBLOCK )
                      {
                          if ( errno != ECONNREFUSED )
                          {
                              std::cerr << __FILE__ << ": " << __LINE__
                                        << ": Error receiving from socket: "
                                        << strerror( errno ) << std::endl;
                          }
                          M_socket.close();
                      }
                      else if ( len > 0 )
                      {
                          M_dest.setPort( from.getPort() );
                          M_socket_buf->setEndPoint( M_dest );
                          processMsg( buf, len );
                      }
                  }
              }
          }
      }
Ejemplo n.º 20
0
void OkayThread::run()
{
	Time currentTime;
	Time writeTime;
	TcpTask_IT it;
	SDWORD kdpfd;
	EpollfdContainer epollFdContainer;
	kdpfd = epoll_create(256);
	assert(-1 != kdpfd);
	m_epollFdContainer.resize(256);
	DWORD countFd = 0;
	bool check = false;
	while(!isFinal())
	{
		this->setRuning();
		currentTime.now();
		if(check)
		{
			check_queue();
			if(!m_taskContainer.empty())
			{
				for(it = m_taskContainer.begin();it != m_taskContainer.end();)
				{
					TcpTask *task = *it;
					if(task->m_mSocket.checkChangeSocket())
					{
						if(task->isFdsrAdd())
						{
							task->delEpoll(kdpfd,EPOLLIN|EPOLLERR|EPOLLPRI);
						}
						task->delEpoll(m_kdpfd,EPOLLIN | EPOLLERR | EPOLLPRI);
						task->m_mSocket.changeSocket(0);
						if(task->isFdsrAdd())
						{
							task->addEpoll(kdpfd,EPOLLIN|EPOLLERR|EPOLLPRI,(void*)task);
						}
						task->addEpoll(m_kdpfd,EPOLLIN|EPOLLOUT|EPOLLERR|EPOLLPRI,(void*)task);
					}
					task->checkSignal(currentTime);
					if(task->isTerminateWait())
					{
						task->Terminate();
					}
					if(task->isTerminate())
					{
						if(task->isFdsrAdd())
						{
							task->delEpoll(kdpfd,EPOLLIN|EPOLLERR|EPOLLPRI);
							countFd--;
						}
						remove(it);
						task->getNextState();
						m_pool->addRecycle(task);
					}
					else
					{	
						if(!task->isFdsrAdd())
						{
							task->addEpoll(kdpfd,EPOLLIN | EPOLLERR | EPOLLPRI,(void*)task);
							task->fdsrAdd();
							countFd++;
							if(countFd > epollFdContainer.size())
							{
								epollFdContainer.resize(countFd + 16);
							}
						}
						++it;
					}
				}
			}
			check = false;
		}
		Thread::msleep(2);
		if(countFd)
		{
			SDWORD retcode = epoll_wait(kdpfd,&epollFdContainer[0],countFd,0);
			if(retcode > 0)
			{
				for(SDWORD index = 0;index < retcode;++index)
				{
					TcpTask *task = (TcpTask*)epollFdContainer[index].data.ptr;
					if(epollFdContainer[index].events & (EPOLLERR|EPOLLPRI))
					{
						task->TerminateError();
						task->Terminate(TcpTask::TM_ACTIVE);
						check = true;
					}
					else
					{
						if(epollFdContainer[index].events & EPOLLIN)
						{
							if(!task->listeningRecv(true))
							{
								task->Terminate(TcpTask::TM_ACTIVE);
								check = true;
							}	
						}
					}
					epollFdContainer[index].events = 0;
				}
			}
		}
		if(check)
		{
			continue;
		}
		if(currentTime.msec() - writeTime.msec() >= (QWORD)(m_pool->s_usleepTime/1000))
		{
			writeTime = currentTime;
			processMsg();
			if(!m_taskContainer.empty())
			{	
				SDWORD retcode = epoll_wait(m_kdpfd,&m_epollFdContainer[0],m_taskCount,0);
				if(retcode > 0)
				{
					for(SDWORD index = 0;index < retcode;index++)
					{	
						TcpTask *task = (TcpTask*)m_epollFdContainer[index].data.ptr;
						if(m_epollFdContainer[index].events & (EPOLLERR|EPOLLPRI))
						{
							task->TerminateError();
							task->Terminate(TcpTask::TM_ACTIVE);
						}
						else
						{
							if(m_epollFdContainer[index].events & EPOLLIN)
							{
								if(!task->listeningRecv(true))
								{
									task->Terminate(TcpTask::TM_ACTIVE);
								}
							}
							if(m_epollFdContainer[index].events & EPOLLOUT)
							{
								if(!task->listeningSend())
								{
									task->Terminate(TcpTask::TM_ACTIVE);
								}
							}
						}
						m_epollFdContainer[index].events = 0;
					}
				}
			}
			check = true;
		}
	}
	for(it = m_taskContainer.begin();it != m_taskContainer.end();)
	{
		TcpTask *task = *it;
		remove(it);
		task->getNextState();
		m_pool->addRecycle(task);
	}
	TEMP_FAILURE_RETRY(::close(m_kdpfd));
}
Ejemplo n.º 21
0
//called in main thread
dove::Nub::SOCKETSTATUS Nub::processAllReachMsg()
{
	dove::Nub::SOCKETSTATUS status;
	while( (status = processMsg()) == STATUS_NORMAL);
	return status;
}
Ejemplo n.º 22
0
void MulticastProcessing::doListenning()
{

	LOG_INFO("MulticastProcessing::doListenning Do listenning");
	// TODO need to reopen socket incase socket is closed
	unsigned int addrlen;
	int nbytes;
	addrlen = sizeof(addr);
//	ofstream myfile;
//	myfile.open ("./google.bin", ios::out | ios::app | ios::binary);

	while (1)
	{

		nbytes = recvfrom(fd, msgbuf, MSGBUFSIZE, 0, (sockaddr *) &addr, &addrlen);
//		cout<<"nbyte "<<nbytes<<endl;
//		myfile << msgbuf<<endl;
//		myfile.flush();
//		myfile.close();
//		exit(0);
		//std::cout<<"received msg size: "<<nbytes<<std::endl;

		if(nbytes < 0)
		{
			  LOG_ERROR("MulticastProcessing > Error while reading soket");
			  sleep(10);
			  continue;
		}
		//google::protobuf::
		if(tollMsg.ParseFromArray(msgbuf, nbytes))//tollMsg.ParseFromString(string(msgbuf))tollMsg.ParseFromArray(msgbuf, nbytes)*/)
		{

//			cout<<tollMsg.staffname()<<endl;
//			  sleep(5);
//			  QString txt = QString::fromUtf8(tollMsg.staffname().c_str());
//			  QImage img("./okImg.jpg");
//			  if(img.width() <= 0)
//				  cout<<"not valid image"<<endl;
//			  QPainter painter;
//				painter.begin(&img);
//
//				painter.setFont(QFont("Arial", 20, QFont::Bold));
//				painter.setPen(QColor(200,200,0));
//				painter.drawText(QPoint(200,200), txt);
//
//				img.save("./draw.jpg");
//				painter.end();

			  MulticastMsg mMsg = MulticastMsg();
			  mMsg.laneid = tollMsg.laneid();
			  mMsg.platenumber = tollMsg.platenumber();
			  mMsg.price = tollMsg.price();
			  mMsg.staffname = (tollMsg.staffname());
			  mMsg.vehicleclass = tollMsg.vehicleclass();
			  mMsg.timestamp = tollMsg.timestamp();
			  mMsg.cameralanip = tollMsg.cameralaneip();
			  //cout<<"ID: "<<tollMsg.laneid()<<" Price:  "<<tollMsg.price()<<" Staff "<< tollMsg.staffname()<<tollMsg.platenumber()<<" vclass "<< tollMsg.vehicleclass()<<" timestamp "<<tollMsg.timestamp()<<" camip "<<tollMsg.cameralaneip()<<endl;
			  processMsg(mMsg);
		  }
		  usleep(50*1000);
	 }
}
void Scanner2d::processMsgData(const uint8_t msg_byte)
{
  uint8_t checksum;

  switch (msg_->parser_state)
  {
  case 0:
    msg_->buffer[0] = msg_byte;
    if (msg_byte == 0xFF)
      msg_->parser_state = 1;
    break;
  case 1:
    msg_->buffer[1] = msg_byte;
    if (msg_byte == 0xFF)
      msg_->parser_state = 2;
    else
      msg_->parser_state = 0;
    break;
  case 2:
    msg_->buffer[2] = msg_byte;
    msg_->msg_type = msg_byte;
    msg_->parser_state = 3;
    break;
  case 3:
    msg_->buffer[3] = msg_byte;
    msg_->payload_length = (msg_byte << 8);
    msg_->parser_state = 4;
    break;
  case 4:
    msg_->buffer[4] = msg_byte;
    msg_->payload_length |= msg_byte;
    ROS_DEBUG("msg_->payload_length: %d", msg_->payload_length);

    if (msg_->payload_length >= SCANNER2D_MSG_LEN_MAX)
    {
      ROS_WARN("Got bad payload length in message from scanner!");
      ROS_WARN("  msg_->payload_length: %d", msg_->payload_length);
      msg_->parser_state = 0;
    }
    else if (msg_->payload_length)
    {
      msg_->payload_byte_count = 0;
      msg_->parser_state = 5;
    }
    else
    {
      msg_->parser_state = 6;
    }
    break;
  case 5:
    msg_->buffer[msg_->payload_byte_count + 5] = msg_byte;
    msg_->payload_byte_count++;
    if (msg_->payload_byte_count + 5 > SCANNER2D_MSG_LEN_MAX)
    {
      ROS_DEBUG("Got bad payload byte count!");
      ROS_DEBUG("  msg_->payload_byte_count: %d", msg_->payload_byte_count);
      msg_->parser_state = 0;
    }
    else if (msg_->payload_byte_count >= msg_->payload_length)
    {
      msg_->parser_state = 6;
    }
    break;
  case 6:
    checksum = calcChecksum(msg_->buffer, msg_->payload_byte_count + 5);
    if (msg_byte == checksum)
    {
      ROS_DEBUG("Got complete message (type: %d)!", msg_->msg_type);
      processMsg();
    }
    else
    {
      ROS_DEBUG("Message (type: %d) checksum failed!", msg_->msg_type);
    }

    msg_->parser_state = 0;
    break;
  default:
    ROS_WARN("Bad parser state!");
    msg_->parser_state = 0;
    break;
  }
}