Exemple #1
0
void command(uint8_t byte) {
	wait_signal();
	outb(0x64, 0xd4);
	wait_signal();
	outb(0x60, byte);
	while ((inb(0x64) & 0x21) == 0x21 && inb(0x60) != 0xfa); // ACK
}
Exemple #2
0
int main(int argc, char **argv) {
#if USE_IRQ
	uint8_t status;
#else
	bool first;
#endif

	command(0xa8);  // enable aux. PS2
	command(0xf6);  // load default config
	command(0xf4);  // enable mouse
	command(0xf3);  // set sample rate:
	outb(0x60, 10); // 10 samples per second

#if USE_IRQ
	wait_signal();
	outb(0x64, 0x20);
	status = inb(0x60);
	status &= ~0x20; // enable mouse clock
	status |= 0x02;  // enable IRQ12
	wait_signal();
	outb(0x64, 0x60);
	wait_signal();
	outb(0x60, status);
	wait_signal();
#endif

	rdi_init();

	mouse = rdi_file_cons(robject_new_index(), ACCS_READ | ACCS_EVENT);

#if USE_IRQ
	rdi_set_irq(12, mouse_irq);
#endif

	fs_plink("/dev/mouse", RP_CONS(getpid(), mouse->index), NULL);
	msendb(RP_CONS(getppid(), 0), ACTION_CHILD);

#if USE_IRQ
	_done();
#else
	while (1) {
		first = true;
		while ((inb(0x64) & 0x21) != 0x21) {
			if (first) {
				send_event_delta(dx, dy);
				send_event_button(buttons);
				dx = dy = 0;
			}
			first = false;
			sleep();
		}

		read_byte();
	}
#endif
	
	return 0;
}
Exemple #3
0
void *routine_N(void *)
{
    wait_signal(cond, mutex);
    if (!free_P) wait_signal(wait_P, mutex_P);
    if (!free_K) wait_signal(wait_K, mutex_K);

    //for(int i = 0; i < CYCLE_COUNT * 2; i++)
    {
        sem_wait(&tSemaphore);
        strcat(result_str, "N");
        printf("N");
        sem_post(&tSemaphore);
        //QTest::qSleep(SLEEPING_TIME);
        //usleep(SLEEPING_TIME);
    }

    return NULL;
}
Exemple #4
0
void *routine_M(void *)
{
    wait_signal(cond, mutex);
    if (!free_H) wait_signal(wait_H, mutex_H);
    if (!free_F) wait_signal(wait_F, mutex_F);

    //for(int i = 0; i < CYCLE_COUNT * 3; i++)
    {
        sem_wait(&tSemaphore);
        strcat(result_str, "M");
        printf("M");
        sem_post(&tSemaphore);
        //QTest::qSleep(SLEEPING_TIME);
        //usleep(SLEEPING_TIME);
    }

    return NULL;
}
Exemple #5
0
void *routine_G(void *)
{
    wait_signal(cond, mutex);
    wait_signal(wait_E, mutex_E);

    //for(int i = 0; i < CYCLE_COUNT + 5; i++)
    {
        sem_wait(&tSemaphore);
        strcat(result_str, "G");
        printf("G");
        sem_post(&tSemaphore);
        //QTest::qSleep(SLEEPING_TIME);
        //usleep(SLEEPING_TIME);
    }
    //sleep(1);
    wakeup_all_threads(wait_G, mutex_G);
    return NULL;
}
Exemple #6
0
void *routine_E(void *)
{
    wait_signal(cond, mutex);
    wait_signal(wait_B, mutex);

    //for(int i = 0; i < CYCLE_COUNT * 2; i++)
    {
        pthread_mutex_lock(&tMutex);
        printf("E");
        strcat(result_str, "E");
        pthread_mutex_unlock(&tMutex);
        //QTest::qSleep(SLEEPING_TIME);
        //usleep(SLEEPING_TIME);
    }
    //sleep(1);
    wakeup_all_threads(wait_E, mutex_E);
    return NULL;
}
Exemple #7
0
void *routine_F(void *)
{
    wait_signal(cond, mutex);
    wait_signal(wait_D, mutex_D);

    //for(int i = 0; i < CYCLE_COUNT * 2; i++)
    {
        sem_wait(&tSemaphore);
        strcat(result_str, "F");
        printf("F");
        sem_post(&tSemaphore);
        //QTest::qSleep(SLEEPING_TIME);
        //usleep(SLEEPING_TIME);
    }
    //sleep(1);
    free_F = true;
    wakeup_all_threads(wait_F, mutex_F);
    return NULL;
}
Exemple #8
0
/* ========================================================================================== */
void *routine_A(void *)
{
    wait_signal(cond, mutex);
    //for(int i = 0; i < CYCLE_COUNT; i++)
    {
        printf("A");
        strcat(result_str, "A");
        //QTest::qSleep(SLEEPING_TIME);
        //usleep(SLEEPING_TIME);
    }

    Sleep(1);
    wakeup_all_threads(wait_A, mutex_A);
    return NULL;
}
int main(int argc, char** argv) {
   try {
      std::string config_file( (argc>1)?argv[1]:DEFAULT_CONFIG_FILE );


      dictionary * ini = NULL;

      if ( (ini=iniparser_load(config_file.c_str())) == NULL ) {
         Log::crit("cannot parse the config file: %s\n", config_file.c_str());
         throw GenericError("cannot parse the config file %s", config_file.c_str());
      }

      int use_ipc = iniparser_getboolean(ini, "INTERMEDIATE_BROKER:use_ipc", -1);

      if(use_ipc) {
         Log::notice("No se lanzan los message_broker, use_ipc=true en archivo de configuracion %s", config_file.c_str());
         return 0;
      }

      Log::notice("Launch message_broker_server, read configuration from %s", config_file.c_str());

      strcpy(working_dir, iniparser_getstring(ini, "INTERMEDIATE_BROKER:working_dir", NULL));
      strcpy(port, iniparser_getstring(ini, "INTERMEDIATE_BROKER:port", NULL));
      strcpy(log_path, iniparser_getstring(ini, "INTERMEDIATE_BROKER:log_path", NULL));
      strcpy(persist_path, iniparser_getstring(ini, "INTERMEDIATE_BROKER:persist_path", NULL));

      Process process_server("./../local_broker/message_broker_server", args_message_broker);
      sleep(1);
      ApiComunicacionAeropuerto api_comm( ApiConfiguracion::get_wkdir(config_file.c_str()).c_str(), config_file.c_str(), true);


      Log::notice("Done, waiting for a SIGINT or a SIGTERM signal.");
      wait_signal();

      Log::notice("Signal recieved. Shutdown...");
      process_server.send_signal(SIGTERM);
      process_server.send_signal(SIGKILL);


   } catch (const std::exception &e) {
      Log::crit("%s", e.what());
   }
   catch (...) {
      Log::crit("Critical error. Unknow exception at the end of the 'main' function.");
   }

   return 0;
}
Exemple #10
0
static int
run(LWMsgPeer* server)
{
    LWMsgStatus status = LWMSG_STATUS_SUCCESS;
    int ret = 0;
    int done = 0;
    int sig = 0;

    block_signals();

    /* Begin listening for calls */
    status = lwmsg_peer_start_listen(server);
    if (status)
    {
        goto error;
    }

    while (!done)
    {
        sig = wait_signal();

        switch (sig)
        {
        case SIGINT:
        case SIGTERM:
            done = 1;
            break;
        default:
            break;
        }
    }

    /* Stop listening */
    status = lwmsg_peer_stop_listen(server);
    if (status)
    {
        goto error;
    }
    
error:

    if (status != LWMSG_STATUS_SUCCESS)
    {
        ret = -1;
    }

    return ret;
}
Exemple #11
0
struct multi_tcp *
multi_tcp_init(int maxevents, int *maxclients)
{
    struct multi_tcp *mtcp;
    const int extra_events = BASE_N_EVENTS;

    ASSERT(maxevents >= 1);
    ASSERT(maxclients);

    ALLOC_OBJ_CLEAR(mtcp, struct multi_tcp);
    mtcp->maxevents = maxevents + extra_events;
    mtcp->es = event_set_init(&mtcp->maxevents, 0);
    wait_signal(mtcp->es, MTCP_SIG);
    ALLOC_ARRAY(mtcp->esr, struct event_set_return, mtcp->maxevents);
    *maxclients = max_int(min_int(mtcp->maxevents - extra_events, *maxclients), 1);
    msg(D_MULTI_LOW, "MULTI: TCP INIT maxclients=%d maxevents=%d", *maxclients, mtcp->maxevents);
    return mtcp;
}
Exemple #12
0
void
io_wait_dowork (struct context *c, const unsigned int flags)
{
  unsigned int socket = 0;
  unsigned int tuntap = 0;
  struct event_set_return esr[4];

  /* These shifts all depend on EVENT_READ and EVENT_WRITE */
  static int socket_shift = 0;     /* depends on SOCKET_READ and SOCKET_WRITE */
  static int tun_shift = 2;        /* depends on TUN_READ and TUN_WRITE */
  static int err_shift = 4;        /* depends on ES_ERROR */
#ifdef ENABLE_MANAGEMENT
  static int management_shift = 6; /* depends on MANAGEMENT_READ and MANAGEMENT_WRITE */
#endif

  /*
   * Decide what kind of events we want to wait for.
   */
  event_reset (c->c2.event_set);

  /*
   * On win32 we use the keyboard or an event object as a source
   * of asynchronous signals.
   */
  if (flags & IOW_WAIT_SIGNAL)
    wait_signal (c->c2.event_set, (void*)&err_shift);

  /*
   * If outgoing data (for TCP/UDP port) pending, wait for ready-to-send
   * status from TCP/UDP port. Otherwise, wait for incoming data on
   * TUN/TAP device.
   */
  if (flags & IOW_TO_LINK)
    {
      if (flags & IOW_SHAPER)
	{
	  /*
	   * If sending this packet would put us over our traffic shaping
	   * quota, don't send -- instead compute the delay we must wait
	   * until it will be OK to send the packet.
	   */
#ifdef ENABLE_FEATURE_SHAPER
	  int delay = 0;

	  /* set traffic shaping delay in microseconds */
	  if (c->options.shaper)
	    delay = max_int (delay, shaper_delay (&c->c2.shaper));
	  
	  if (delay < 1000)
	    {
	      socket |= EVENT_WRITE;
	    }
	  else
	    {
	      shaper_soonest_event (&c->c2.timeval, delay);
	    }
#else /* ENABLE_FEATURE_SHAPER */
	  socket |= EVENT_WRITE;
#endif /* ENABLE_FEATURE_SHAPER */
	}
      else
	{
	  socket |= EVENT_WRITE;
	}
    }
  else if (!((flags & IOW_FRAG) && TO_LINK_FRAG (c)))
    {
      if (flags & IOW_READ_TUN)
	tuntap |= EVENT_READ;
    }

  /*
   * If outgoing data (for TUN/TAP device) pending, wait for ready-to-send status
   * from device.  Otherwise, wait for incoming data on TCP/UDP port.
   */
  if (flags & IOW_TO_TUN)
    {
      tuntap |= EVENT_WRITE;
    }
  else
    {
      if (flags & IOW_READ_LINK)
	socket |= EVENT_READ;
    }

  /*
   * outgoing bcast buffer waiting to be sent?
   */
  if (flags & IOW_MBUF)
    socket |= EVENT_WRITE;

  /*
   * Force wait on TUN input, even if also waiting on TCP/UDP output
   */
  if (flags & IOW_READ_TUN_FORCE)
    tuntap |= EVENT_READ;

  /*
   * Configure event wait based on socket, tuntap flags.
   */
  socket_set (c->c2.link_socket, c->c2.event_set, socket, (void*)&socket_shift, NULL);
  tun_set (c->c1.tuntap, c->c2.event_set, tuntap, (void*)&tun_shift, NULL);

#ifdef ENABLE_MANAGEMENT
  if (management)
    management_socket_set (management, c->c2.event_set, (void*)&management_shift, NULL);
#endif

  /*
   * Possible scenarios:
   *  (1) tcp/udp port has data available to read
   *  (2) tcp/udp port is ready to accept more data to write
   *  (3) tun dev has data available to read
   *  (4) tun dev is ready to accept more data to write
   *  (5) we received a signal (handler sets signal_received)
   *  (6) timeout (tv) expired
   */

  c->c2.event_set_status = ES_ERROR;

  if (!c->sig->signal_received)
    {
      if (!(flags & IOW_CHECK_RESIDUAL) || !socket_read_residual (c->c2.link_socket))
	{
	  int status;

#ifdef ENABLE_DEBUG
	  if (check_debug_level (D_EVENT_WAIT))
	    show_wait_status (c);
#endif

	  /*
	   * Wait for something to happen.
	   */
	  status = event_wait (c->c2.event_set, &c->c2.timeval, esr, SIZE(esr));

	  check_status (status, "event_wait", NULL, NULL);

	  if (status > 0)
	    {
	      int i;
	      c->c2.event_set_status = 0;
	      for (i = 0; i < status; ++i)
		{
		  const struct event_set_return *e = &esr[i];
		  c->c2.event_set_status |= ((e->rwflags & 3) << *((int*)e->arg));
		}
	    }
	  else if (status == 0)
	    {
	      c->c2.event_set_status = ES_TIMEOUT;
	    }
	}
      else
	{
	  c->c2.event_set_status = SOCKET_READ;
	}
    }

  /* 'now' should always be a reasonably up-to-date timestamp */
  update_time ();

  /* set signal_received if a signal was received */
  if (c->c2.event_set_status & ES_ERROR)
    get_signal (&c->sig->signal_received);

  dmsg (D_EVENT_WAIT, "I/O WAIT status=0x%04x", c->c2.event_set_status);
}