Beispiel #1
0
void handle_events(OUTPUT_WINDOW *window) {
    short int mx, my, button, keystate, dummy;
    unsigned short int key;
    short int breturn;
    short int top_wind;           /* Top window handle */
    short int type = 0, out = 0;
    short int time_remaining = 1000;
    short int base_clip[4];                    
    short messages[16];

    while (out != 1) {
        type = 0;
        while (!(type & MU_KEYBD) && !(type & MU_MESAG) && 
               !(type & MU_BUTTON) && !(type & MU_TIMER)) {

            type = evnt_multi(
                (MU_KEYBD | MU_MESAG | MU_BUTTON | MU_TIMER), 0x182, 3, 3,
                0, 0, 0, 0, 0,
                0, 0, 0, 0, 0, 
                messages, time_remaining, &mx, &my,
                &button, &keystate, &key, &breturn);
        }

        /*wind_get(win_handle, WF_TOP, &top_wind, &dummy, &dummy, &dummy);
        if (top_wind != win_handle) {
            if (game_state == ACTIVE) game_state == FROZEN;
        }

        // Base clip region is the screen
        base_clip[0] = base_clip[1] = 0;
        base_clip[2] = SCw - 1;
        base_clip[3] = SCh - 1;
        vs_clip(handle, 1, base_clip);*/

        wind_update(BEG_UPDATE);

        if (type & MU_KEYBD) {
            switch(key) {
                case 0x011B:    /* Esc Pause Game */
                    out = 1;
                    break;
                default:
                    break;
            }
            type &= ~MU_KEYBD;
        }

        if (type & MU_MESAG) {
            out = message_handler(messages, window);
            type &= ~MU_MESAG;
        }

        wind_update(END_UPDATE);
    }
    return;
}
Beispiel #2
0
void its_entry(void *ptr)
{
    uint32_t signals = 0;
    psa_msg_t msg = {0};

    while (1) {
#if defined(TARGET_MBED_SPM)
        signals = psa_wait_any(PSA_BLOCK);
#else
        signals = psa_wait(ITS_WAIT_ANY_SID_MSK, PSA_BLOCK);
#endif

        // KVStore initiation:
        // - Must be done after the psa_wait_any() call since only now we know OS initialization is done
        // - Repeating calls has no effect
        int kv_status = kv_init_storage_config();
        if (kv_status != MBED_SUCCESS) {
            SPM_PANIC("KVStore initiation failed with status %d!", kv_status);
        }

        if ((signals & PSA_ITS_SET_MSK) != 0) {
            psa_get(PSA_ITS_SET_MSK, &msg);
            message_handler(&msg, storage_set);
        }
        if ((signals & PSA_ITS_GET_MSK) != 0) {
            psa_get(PSA_ITS_GET_MSK, &msg);
            message_handler(&msg, storage_get);
        }
        if ((signals & PSA_ITS_INFO_MSK) != 0) {
            psa_get(PSA_ITS_INFO_MSK, &msg);
            message_handler(&msg, storage_info);
        }
        if ((signals & PSA_ITS_REMOVE_MSK) != 0) {
            psa_get(PSA_ITS_REMOVE_MSK, &msg);
            message_handler(&msg, storage_remove);
        }
        if ((signals & PSA_ITS_RESET_MSK) != 0) {
            psa_get(PSA_ITS_RESET_MSK, &msg);
            message_handler(&msg, storage_reset);
        }

    }
}
inline void rawsocket_connection::receive_message_body_handler(
        const boost::system::error_code& error_code, size_t bytes_transferred)
{
    if (error_code) {
        handle_system_error(error_code);
        return;
    }

    const auto& message_handler = get_message_handler();
    assert(message_handler);
    message_handler(shared_from_this(), m_message_buffer.data(), bytes_transferred);

    async_receive();
}
Beispiel #4
0
/* run procthread */
void procthread_run(void *arg)
{
    PROCTHREAD *pth = (PROCTHREAD *)arg;

    if(pth)
    {
        pth->running_status = 1;
        while(pth->running_status)
        {
            if(QTOTAL(pth->message_queue) > 0)
                message_handler(pth->message_queue, pth->logger);
            usleep(pth->usec_sleep);
        }
    }
#ifdef HAVE_PTHREAD
    pthread_exit(NULL);
#endif
}
Beispiel #5
0
void nl80211::receive_handler(const boost::system::error_code& ec, size_t rbytes)
{
	if (ec) {
		_event_handler(ec, event());
		return;
	}

	for (netlink::message_iterator mit(_buffer, rbytes); mit; ++mit) {
		if (mit.type() == netlink::message::error) {
			int error = mit.error();
			if (error) {
				boost::system::error_code err(error, boost::system::system_category());
				_event_handler(err, event());
			}

		} else if (mit.type() == _family) {
			genetlink::message msg(mit.get());

			if (msg)
				message_handler(msg);
			else
				std::cerr << "warning: invalid nl80211 message"
				             "{\n"
				             "    method : opmip::linux::nl80211::event_handler()\n"
				             "    nltype : " << uint(msg.type()) <<
				             "}\n";

		} else {
			std::cerr << "warning: unexpected netlink message type\n"
			             "{\n"
			             "    method : opmip::linux::nl80211::event_handler()\n"
			             "    nltype : " << uint(mit.type()) <<
			             "}\n";
		}
	}

	_gnl.async_receive(boost::asio::buffer(_buffer), boost::bind(&nl80211::receive_handler, this, _1, _2));
}
Beispiel #6
0
/* --------------------------< Listening >--------------------------------- */
int listenSocket(int* listen_port)
{
  int listen_socket;
  struct sockaddr_in server_addr;
  const int       optVal = 1;
  const socklen_t optLen = sizeof(optVal);
  /* criar socket do servidor */
  if ((listen_socket = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0)
  {
    perror("impossível criar socket: erro na função socket()\n");
    exit(1);
  }
  /* estrutura que contém o endereço IP */
  bzero((char *) &server_addr, sizeof(server_addr));
  server_addr.sin_family = AF_INET;
  server_addr.sin_addr.s_addr = htonl(INADDR_ANY);
  server_addr.sin_port = htons(*listen_port);
  setsockopt(listen_socket, SOL_SOCKET, SO_REUSEADDR, (void*) &optVal, optLen);
  /* associa o socket à ringport */
  while(bind(listen_socket, (struct sockaddr *) &server_addr, sizeof(server_addr)) < 0)
  {
    message_handler(DEBUG_MODE,13,NULL,NULL,(*listen_port));    
    (*listen_port)++;
    server_addr.sin_port = htons(*listen_port);
  }
  printf("port - %d\n", *listen_port);
  /* socket do servidor a escutar pedidos */
  if (listen(listen_socket, MAX_PENDING) < 0) { // fila de espera de escuta pela parte da socket do servidor é de 128 clientes, valor definido pelo MAX_PENDING
    perror("impossível criar socket: erro na função listen()\n");
    exit(1);
  }
  /*
  char buffer[128];
  gethostname(buffer,128);
  printf("%s\n", buffer);
  */
  return listen_socket; // função devolve o file descriptor da socket do servidor
}
      std::shared_ptr<t_message>
      client_exchange(const std::shared_ptr<const google::protobuf::Message> &req,
                      const boost::optional<messages::MessageType> & resp_type = boost::none,
                      const boost::optional<std::vector<messages::MessageType>> & resp_types = boost::none,
                      const boost::optional<messages::MessageType*> & resp_type_ptr = boost::none,
                      bool open_session = false)
      {
        // Require strictly protocol buffers response in the template.
        BOOST_STATIC_ASSERT(boost::is_base_of<google::protobuf::Message, t_message>::value);
        const bool accepting_base = boost::is_same<google::protobuf::Message, t_message>::value;
        if (resp_types && !accepting_base){
          throw std::invalid_argument("Cannot specify list of accepted types and not using generic response");
        }

        // Determine type of expected message response
        const messages::MessageType required_type = accepting_base ? messages::MessageType_Success :
                  (resp_type ? resp_type.get() : MessageMapper::get_message_wire_number<t_message>());

        // Open session if required
        if (open_session){
          try {
            m_transport->open();
          } catch (const std::exception& e) {
            std::throw_with_nested(exc::SessionException("Could not open session"));
          }
        }

        // Scoped session closer
        BOOST_SCOPE_EXIT_ALL(&, this) {
          if (open_session){
            this->get_transport()->close();
          }
        };

        // Write/read the request
        CHECK_AND_ASSERT_THROW_MES(req, "Request is null");
        auto msg_resp = call_raw(req.get());

        bool processed = false;
        do {
          processed = message_handler(msg_resp);
        } while(processed);

        // Response section
        if (resp_type_ptr){
          *(resp_type_ptr.get()) = msg_resp.m_type;
        }

        if (msg_resp.m_type == messages::MessageType_Failure) {
          throw_failure_exception(dynamic_cast<messages::common::Failure *>(msg_resp.m_msg.get()));

        } else if (!accepting_base && msg_resp.m_type == required_type) {
          return message_ptr_retype<t_message>(msg_resp.m_msg);

        } else if (accepting_base && (!resp_types ||
                     std::find(resp_types.get().begin(), resp_types.get().end(), msg_resp.m_type) != resp_types.get().end())) {
            return message_ptr_retype<t_message>(msg_resp.m_msg);

        } else {
          throw exc::UnexpectedMessageException(msg_resp.m_type, msg_resp.m_msg);
        }
      }
Beispiel #8
0
int affixd_thread(void *startup)
{
	int			ret = 0;
	struct pollfd		fds[2];
	__u8			msg[HCI_MAX_MSG_SIZE];
	__u8			event[HCI_MAX_EVENT_SIZE];

	DBFENTER;
	daemonize("affixd");
	allow_signal(SIGTERM);
	allow_signal(SIGUSR1);

	/*  Open HCI manager */
	fds[0].fd = hci_open_mgr();
	if (fds[0].fd < 0) {
		ret = fds[0].fd;
		fds[1].fd = -1;
		goto exit;
	}
	fds[0].events = POLLIN;
	
	fds[1].fd = hci_open_event();
	if (fds[1].fd < 0) {
		ret = fds[1].fd;
		goto exit;
	}
	fds[1].events = POLLIN;

	up(&exit_sema);
	
	hci_event_mask(fds[1].fd, ALL_EVENTS_MASK &
			~(COMMAND_COMPLETE_MASK | COMMAND_STATUS_MASK |
			  NUMBER_OF_COMPLETE_PACKETS_MASK | FLUSH_OCCURRED_MASK));
	module_put(THIS_MODULE);
	module_put(THIS_MODULE);
	module_put(THIS_MODULE);
	module_put(THIS_MODULE);
	for (;;) {
		ret = hci_poll(fds, 2, -1);
		if (ret > 0) {/* we have something */
			if ((fds[0].revents | fds[1].revents) & (POLLERR | POLLHUP | POLLNVAL))
				break;
			if (fds[1].revents) {
				if (fds[1].revents & POLLIN) { /* HCI event */
					int	devnum;
					hci_recv_event_any(fds[1].fd, &devnum, event, sizeof(event));
					event_handler((void*)event, devnum);
				}
			}
			if (fds[0].revents) {
				if (fds[0].revents & POLLIN) {/* MSG */
					btsys_recv(fds[0].fd, msg, sizeof(msg), 0);
					message_handler((void*)(msg+1));
				}
			}
		}
		if (signal_pending(current)) {
			DBPRT("Got a signal!!!\n");
//			if (sigismember(&current->pending.signal, SIGUSR1)) {
//				sigdelset(&current->pending.signal, SIGUSR1);
//			}
			flush_signals(current);	// flush pending signals
			spin_lock_irq(&current->sighand->siglock);
			recalc_sigpending();
			spin_unlock_irq(&current->sighand->siglock);
			if (mgr_exit)
				break;
		}
	}
	//try_module_get(THIS_MODULE);
	//try_module_get(THIS_MODULE);
	//try_module_get(THIS_MODULE);
	//try_module_get(THIS_MODULE);
exit:
	if (fds[0].fd >= 0)
		hci_close(fds[0].fd);
	if (fds[1].fd >= 0)
		hci_close(fds[1].fd);
	mgr_exit = ret;
	up(&exit_sema);
	DBFEXIT;
	return ret;
}
Beispiel #9
0
int main (int argc, char **argv)
{

    int opt;
    char *configfile = "hosts";
    JRB hosts, node, node2;
    Host *host, *join, *me;
    int nhosts;
    int i, j;
    Message *m;
    char dest[160];
    char msg[256];
    Key tmp;
    ChimeraHost ch;
    double start;

    while ((opt = getopt (argc, argv, OPTSTR)) != EOF)
	{
	    switch ((char) opt)
		{
		case 'f':
		    configfile = optarg;
		    break;
		default:
		    fprintf (stderr, "invalid option %c\n", (char) opt);
		    fprintf (stderr, "usage: %s\n", USAGE);
		    exit (1);
		}
	}

    sem = sema_create (0);
    state = (ChimeraState *) malloc (sizeof (ChimeraState));

    me = (Host *) malloc (sizeof (Host));
    me->name = "localhost";
    me->port = 11110;
    me->hnp = "localhost:11110";

    hosts = read_hosts (configfile, &nhosts);

    state->log = log_init ();
    log_direct (state->log, LOG_ERROR, stderr);
    log_direct (state->log, LOG_WARN, stderr);

    key_init ();
    state->message = message_init (state, 11110);
    message_handler (state, 21, hello, 1);
    message_handler (state, 22, fwd, 1);
    message_handler (state, 23, del, 1);
    message_handler (state, 24, NULL, 1);

    srand (time (NULL));

/* This part runs bighost in different hosts */

    announced = 0;
    jrb_traverse (node, hosts)
    {
	if (announced == 0)
	    {
		join = NULL;
	    }
	else
	    {
		i = (rand () % announced) + 1;
		jrb_traverse (node2, hosts)
		{
		    i--;
		    if (i == 0)
			break;
		}
		join = (Host *) node2->val.v;
	    }
	host = (Host *) node->val.v;

	start_host (host, join);
	dsleep (0.1);
    }
Beispiel #10
0
void  main()

{
   int   message[8], flag;
   char  string[6];

   gl_apid = appl_init();

   if (! _app) {
        menu_register (gl_apid, "  Super Server");
        evnt_timer (1000, 0);
      }

   if (! rsrc_load ("IND.RSC")) {
        form_alert (1, "[1][ |   Cannot find IND.RSC !   ][ Cancel ]");
        terminate();   return;
      }

   get_path();

   if (initialise_windows (4, ICONIFY) == 0) {
        leave_windows();   rsrc_free();   terminate();
        return;
      }

   if (get_version (string) > 0) {
        form_alert (1, 
                "[1][ |   STiK is not loaded,    | |      or corrupted !][ Cancel ]");
        leave_windows();   rsrc_free();   terminate();
        return;
      }
   change_freestring (START, ST_VERS,  -1, string, 5);
   change_freestring (START, SS_VERS,  -1, version, 5);

   set_api_struct();

   if (init_modules() == 0) {
        leave_windows();   rsrc_free();   terminate();
        return;
      }
   set_callbacks (CB_EVENT, (FUNC) check_modules, (FUNC) 0L);

   init_configs();

   graf_mouse (ARROW, NULL);

   if (_app) {
        do_some_work();
        while (! exit_inetd) {
             evnt_mesag (message);
             message_handler (message);
             while ((flag = operate_events()) >= 0);
             if (flag == -4)
                  exit_inetd = TRUE;
           }
      }
     else {
        FOREVER {
             evnt_mesag (message);
             message_handler (message);
           }
      }

   if (strings)   Mfree (strings);

   terminate_modules();

   leave_windows();

   rsrc_free();

   appl_exit();
 }