HotplugWatcher_GUI::HotplugWatcher_GUI(QWidget *parent) :
	QWidget(parent)
{
	QVBoxLayout *vbl = new QVBoxLayout(this);
	setLayout(vbl);

	state = new QLabel(this);
	button = new QPushButton(tr("Start"), this);
	detail_button = new QToolButton(this);
	detail_button->setText(tr("Detail"));
	detail_button->setCheckable(true);
	detail_button->setChecked(true);
	msg_view = new QTextBrowser(this);
	msg_view->setLineWrapMode(QTextEdit::NoWrap);

	QHBoxLayout *hbl = new QHBoxLayout(this);
	hbl->addWidget(button);
	hbl->addWidget(detail_button);

	vbl->addWidget(state);
	vbl->addLayout(hbl);
	vbl->addWidget(msg_view);

	tray = new QSystemTrayIcon(this);
	tray->show();

	watcher = new QDeviceWatcher;
	watcher->appendEventReceiver(this);
	connect(watcher, SIGNAL(deviceAdded(QString)), this, SLOT(slotDeviceAdded(QString)), Qt::DirectConnection);
	connect(watcher, SIGNAL(deviceChanged(QString)), this, SLOT(slotDeviceChanged(QString)), Qt::DirectConnection);
	connect(watcher, SIGNAL(deviceRemoved(QString)), this, SLOT(slotDeviceRemoved(QString)), Qt::DirectConnection);

	connect(button, SIGNAL(clicked()), SLOT(toggleWatch()));
	connect(detail_button, SIGNAL(toggled(bool)), SLOT(showDetail(bool)));
}
void ObjectPropertiesView::itemDoubleClicked(QTreeWidgetItem *item, int column)
{
    if (item->type() == PropertiesViewItem::ClassType)
        return;

    if (column == 0)
        toggleWatch(item);
    else if (column == 1)
        m_tree->editItem(item, column);
}
示例#3
0
void main(int argc, char* argv[])
{
	bool singleClock = false;

	genAGCStates();
	MON::displayAGC();

	while(1)
	{
		// NOTE: assumes that the display is always pointing to the start of
		// a new line at the top of this loop!

	    // Clock the AGC, but between clocks, poll the keyboard
	    // for front-panel input by the user. This uses a Microsoft function;
    	// substitute some other non-blocking function to access the keyboard
    	// if you're porting this to a different platform.

		cout << "> "; cout.flush();  // display prompt

		while( !_kbhit() )
		{
			if(MON::FCLK || singleClock)
			{
					// This is a performance enhancement. If the AGC is running,
					// don't check the keyboard or simulator display every simulation
					// cycle, because that slows the simulator down too much.
				int genStateCntr = 100;
				do {
				    CLK::clkAGC(); 
					singleClock = false;

				    genAGCStates();
				    genStateCntr--;

						// This needs more work. It doesn't always stop at the
						// right location and sometimes stops at the instruction
						// afterwards, too.
					if(breakpointEnab && breakpoint == MBF::getEffectiveAddress())
					{
						MON::RUN = 0;
					}

						// Halt right after the instruction that changes a watched
						// memory location.
					if(watchEnab)
					{
						unsigned newWatchValue = MBF::readMemory(watchAddr);
						if(newWatchValue != oldWatchValue)
						{
							MON::RUN = 0;
						}
						oldWatchValue = newWatchValue;
					}


				} while (MON::FCLK && MON::RUN && genStateCntr > 0);

				updateAGCDisplay();

			}
			// for convenience, clear the single step switch on TP1; in the
			// hardware AGC, this happens when the switch is released
			if(MON::STEP && TPG::register_SG.read() == TP1) MON::STEP = 0;
		}
        char key = _getch();

	    // Keyboard controls for front-panel:
		switch(key)
		{
			// AGC controls
            // simulator controls

		case 'q': cout << "QUIT..." << endl; exit(0);
		case 'm': showMenu(); break;

		case 'd': 
			genAGCStates(); 
			MON::displayAGC(); 
			break; // update display

		case 'l': loadMemory(); break;
		case 'e': examineMemory(); break;

		case 'f':
			showSourceCode();
			break;

		case ']': 
			incrCntr(); 
			//genAGCStates();
			//displayAGC(EVERY_CYCLE);
			break;

		case '[': 
			decrCntr(); 
			//genAGCStates();
			//displayAGC(EVERY_CYCLE);
			break;

		case 'i': 
			interrupt(); 
			//genAGCStates();
			//displayAGC(EVERY_CYCLE);
			break;

		case 'z':
			//SCL::F17 = (SCL::F17 + 1) % 2; 
			genAGCStates();
			MON::displayAGC();
			break;

		case 'x':
			//SCL::F13 = (SCL::F13 + 1) % 2; 
			genAGCStates();
			MON::displayAGC();
			break;

		case 'r': 
			MON::RUN = (MON::RUN + 1) % 2; 
			genAGCStates();
			if(!MON::FCLK) MON::displayAGC();
			break;	

		case 's': 
			MON::STEP = (MON::STEP + 1) % 2; 
			genAGCStates();
			if(!MON::FCLK) MON::displayAGC();
			break;	

		case 'a': 
			MON::SA = (MON::SA + 1) % 2; 
			genAGCStates();
			MON::displayAGC();
			break;
			
		case 'n': 
			MON::INST = (MON::INST + 1) % 2; 
			genAGCStates();
			MON::displayAGC();
			break;	

		case 'p': 
			MON::PURST = (MON::PURST + 1) % 2;
			genAGCStates();
			MON::displayAGC();
			break;	

		case 'b':
			toggleBreakpoint();
			break;

		case 'y':
			toggleWatch();
			break;

		// DSKY:
		case '0': KBD::keypress(KEYIN_0); break;
		case '1': KBD::keypress(KEYIN_1); break;
		case '2': KBD::keypress(KEYIN_2); break;
		case '3': KBD::keypress(KEYIN_3); break;
		case '4': KBD::keypress(KEYIN_4); break;
		case '5': KBD::keypress(KEYIN_5); break;
		case '6': KBD::keypress(KEYIN_6); break;
		case '7': KBD::keypress(KEYIN_7); break;
		case '8': KBD::keypress(KEYIN_8); break;
		case '9': KBD::keypress(KEYIN_9); break;
		case '+': KBD::keypress(KEYIN_PLUS); break;
		case '-': KBD::keypress(KEYIN_MINUS); break;
		case '.': KBD::keypress(KEYIN_CLEAR); break;
		case '/': KBD::keypress(KEYIN_VERB); break;
		case '*': KBD::keypress(KEYIN_NOUN); break;
		case 'g': KBD::keypress(KEYIN_KEY_RELEASE); break;
		case 'h': KBD::keypress(KEYIN_ERROR_RESET); break;
		case 'j': KBD::keypress(KEYIN_ENTER); break;

		case '\0': // must be a function key
			key = _getch();
			switch(key)
			{
			case 0x3b: // F1: single clock pulse (when system clock off)
				singleClock = true; break;
		    case 0x3c: // F2: manual clock (FCLK=0)
				MON::FCLK = 0; genAGCStates(); MON::displayAGC(); break;
		    case 0x3e: // F4: fast clock (FCLK=1)
				MON::FCLK = 1; genAGCStates(); MON::displayAGC(); break;
			default: cout << "function key: " << key << "=" << hex << (int) key << dec << endl;
			}
			break;

		//default: cout << "??" << endl;
		default: cout << key << "=" << hex << (int) key << dec << endl;
		}
    }
}
void ObjectPropertiesView::removeWatch()
{
    toggleWatch(m_clickedItem);
}
示例#5
0
void stepNetwork(void)
{
   int i, k, pi, pi2, nbytes, newfd;
   char remoteIP[INET6_ADDRSTRLEN];
   struct sockaddr_storage remoteaddr;
   socklen_t addrlen;
   struct timeval tv;

   if(getDeathMessage(sendbuf))
   {
      for(k = 0; k < conf.maxPlayers; ++k)
      {
         if(connection[k].socket && !connection[k].bot)
         {
            snd(connection[k].socket, "\r\n");
            snd(connection[k].socket, sendbuf);
            snd(connection[k].socket, "\r\n> ");
         }
      }
   }
   
   tv.tv_sec = 0;
   tv.tv_usec = 1;
   readfds = master;
   if(select(fdmax + 1, &readfds, NULL, NULL, &tv) == -1)
   {
      print_error("select");
      exit(5);
   }

   for(i = 0; i <= fdmax; ++i)
   {
      if(FD_ISSET(i, &readfds))
      {
         if(i == listener)
         {
            addrlen = sizeof remoteaddr;
            newfd = accept(listener, (struct sockaddr *)&remoteaddr, &addrlen);
            if(newfd == -1)
            {
               print_error("accept");
            }
            else
            {
               getnameinfo((struct sockaddr *)&remoteaddr, addrlen, remoteIP, sizeof remoteIP, NULL, 0, NI_NUMERICHOST | NI_NUMERICSERV);
               for(k = 0; k < conf.maxPlayers; ++k)
               {
                  if(connection[k].socket == 0)
                  {
                     connection[k].socket = newfd;
                     strncpy(connection[k].remoteIP,remoteIP,INET6_ADDRSTRLEN);
                     playerJoin(k);
                     updateName(k, "Anonymous");
                     allSendPlayerPos(k);
                     break;
                  }
               }
               if(k == conf.maxPlayers)
               {
                  close(newfd);
                  printf("new connection from %s on socket %d refused: max connections\n", remoteIP, newfd);
               }
               else
               {
                  FD_SET(newfd, &master);
                  if(newfd > fdmax)
                  {
                     fdmax = newfd;
                  }
                  printf("new connection from %s on socket %d accepted\n", remoteIP, newfd);
                  snd(newfd, WELCOME);
               }
            }
         }
         else
         {
            if((nbytes = recv(i, buf, sizeof buf, 0)) <= 0)
            {
               if(nbytes == 0)
               {
                  printf("socket %d hung up\n", i);
               }
               else
               {
                  print_error("recv");
               }
               for(k = 0; k < conf.maxPlayers; ++k)
               {
                  if(connection[k].socket == i)
                  {
                     connection[k].socket = 0;
                     connection[k].echo = 0;
                     connection[k].bot = 0;
                     playerLeave(k);
                     allSendPlayerLeave(k);
                     break;
                  }
               }   
               close(i);
               FD_CLR(i, &master);
            }
            else
            {
               pi = -1;
               for(k = 0; k < conf.maxPlayers; ++k)
               {
                  if(connection[k].socket == i)
                  {
                     pi = k;
                     break;
                  }
               }   
               for(k = 0; k < nbytes && pi >= 0; ++k)
               {
                  unsigned char c = buf[k];
                  if(c != '\r' && c != '\n')
                  {
                     if(isprint(c) && connection[pi].msgbufindex < 128 - 2)
                     {
                        connection[pi].msgbuf[connection[pi].msgbufindex++] = c;
                     }
                  }
                  else
                  {
                     if(connection[pi].msgbufindex == 0)
                     {
                        continue;
                     }
                     connection[pi].msgbuf[connection[pi].msgbufindex] = '\0';
                     connection[pi].msgbuf[connection[pi].msgbufindex + 1] = '\0';
                     connection[pi].msgbufindex = 0;
                     if(connection[pi].echo)
                     {
                        snd(i, connection[pi].msgbuf);
                        snd(i, "\r\n");
                     }
                     if(!overdrive)printf("%16s (%d): \"%s\"\n", getPlayer(pi)->name, pi, connection[pi].msgbuf);
                     switch(connection[pi].msgbuf[0])
                     {
                        case 'n':
                        {
                           updateName(pi, connection[pi].msgbuf + 2);
                           break;
                        }
                        case 't':
                        {
			  if(is_from_localhost(connection[pi])) {
                           tankEnergy(atoi(connection[pi].msgbuf + 2));
			  }
                          break;
                        }
                        case 'v':
                        {
                           updateVelocity(pi, atof(connection[pi].msgbuf + 2));
                           break;
                        }
			case 'w':
			{
			   toggleWatch(pi);
			   break;
			}
                        case 'z':
                        {
                           updateZoom(atof(connection[pi].msgbuf + 2));
                           break;
                        }
			case 'T':
			{
			  if(is_from_localhost(connection[pi])) {
		            double throttle = atof(connection[pi].msgbuf + 2);
			    conf.throttle.tv_sec= throttle;
			    conf.throttle.tv_nsec=(throttle - conf.throttle.tv_sec) * 1000000000;
			  }
			  break;
			}
			case 'D':
			{
			  if(is_from_localhost(connection[pi])) {
			    conf.debug = atoi(connection[pi].msgbuf + 2);
			  }
			  break;
			}
                        case 'c':
                        {
                           clearTraces(pi);
                           break;
                        }
                        case 'o':
                        {
			   if(is_from_localhost(connection[pi])) {
                             overdrive = !overdrive;
			   }
                           break;
                        }
                        case 'b':
                        {
                           connection[pi].bot = !connection[pi].bot;
                           if(connection[pi].bot)
                           {
                              sendOwnId(i, pi);
                              for(pi2 = 0; pi2 < conf.maxPlayers; ++pi2)
                              {
                                 if(connection[pi2].socket)
                                 {
                                    sendPlayerPos(i, pi2);
                                 }
                              }
                           }
                           break;
                        }
                        case 'f':
                        {
                           toggleFps();
                           break;
                        }
                        case 'i':
                        {
                           if(strcmp("init", connection[pi].msgbuf) == 0)
                           {
                              reinitialize();
                           }
                           break;
                        }
                        case 'x':
                        {
                           if(strcmp("xit", connection[pi].msgbuf) == 0)
                           {
                              exit(0);
                           }
                           break;
                        }
                        case 'e':
                        {
                           connection[pi].echo = !connection[pi].echo;
                           break;
                        }
                        case 'r':
                        {
                           validateOld(pi);
                           break;
                        }
                        default:
                        {
                           updateAngle(pi, atof(connection[pi].msgbuf));
                           break;
                        }
                     }

                     if(!connection[pi].bot)
                     {
                        snd(i, "> ");
                     }
                  }
               }
            }
         }
      }
   }
   for(k = 0; k < conf.maxPlayers; ++k)
   {
      if(getPlayer(k)->active && getPlayer(k)->timeoutcnt > 2)
      {
         connection[k].echo = 0;
         playerLeave(k);
         close(connection[k].socket);
         FD_CLR(connection[k].socket, &master);
         connection[k].socket = 0;
         connection[k].bot = 0;
         allSendPlayerLeave(k);
     }
   }   
}