示例#1
0
static int main_loop(int sock) {
    char buf[1000];
    for (;;) {
        //printf("Rx: \"%s\"\n", buf);

        int result = client_rx_line(sock, buf, 999);
        if (result) break;

        char* args;

        //  printf("CMD: \"%s\"\n", buf);

        isolate_verb(buf, &args);

        //printf("ISO: \"%s\"(\"%s\")\n\n", buf, args);

        pingSock = sock;
        if (0 == strcasecmp(buf, "NAME")) {
            handle_name(sock, args);
            continue;
        }

        if (0 == strcasecmp(buf, "NEWGAME")) {
            handle_newgame(sock, args);
            continue;
        }

        if (0 == strcasecmp(buf, "PLAYER")) {
            handle_player(sock, args);
            continue;
        }

        if (0 == strcasecmp(buf, "YOURMOVE")) {
            handle_yourmove(sock, args);
            continue;
        }

        if (0 == strcasecmp(buf, "GAMEOVER")) {
            handle_gameover(sock, args);
            continue;
        }

        if (0 == strcasecmp(buf, "ERROR") || 0 == strcasecmp(buf, "BADPROT")) {
            handle_error(sock, args);
            continue;
        }

        printf("Server error: unknown verb \"%s\"\n", buf);
        return 1;

    }
    return 1;
}
示例#2
0
/**
 * MPRISEntryPoint() routes incoming messages to their respective interface
 * implementation.
 *
 * This function is called during dbus_connection_dispatch()
 */
static DBusHandlerResult
MPRISEntryPoint ( DBusConnection *p_conn, DBusMessage *p_from, void *p_this )
{
    const char *psz_target_interface;
    const char *psz_interface = dbus_message_get_interface( p_from );
    const char *psz_method    = dbus_message_get_member( p_from );

    DBusError error;

    if( psz_interface && strcmp( psz_interface, DBUS_INTERFACE_PROPERTIES ) )
        psz_target_interface = psz_interface;

    else
    {
        dbus_error_init( &error );
        dbus_message_get_args( p_from, &error,
                               DBUS_TYPE_STRING, &psz_target_interface,
                               DBUS_TYPE_INVALID );

        if( dbus_error_is_set( &error ) )
        {
            msg_Err( (vlc_object_t*) p_this, "D-Bus error on %s.%s: %s",
                                             psz_interface, psz_method,
                                             error.message );
            dbus_error_free( &error );
            return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
        }
    }

    msg_Dbg( (vlc_object_t*) p_this, "Routing %s.%s D-Bus method call to %s",
                                     psz_interface, psz_method,
                                     psz_target_interface );

    if( !strcmp( psz_target_interface, DBUS_INTERFACE_INTROSPECTABLE ) )
        return handle_introspect( p_conn, p_from, p_this );

    if( !strcmp( psz_target_interface, DBUS_MPRIS_ROOT_INTERFACE ) )
        return handle_root( p_conn, p_from, p_this );

    if( !strcmp( psz_target_interface, DBUS_MPRIS_PLAYER_INTERFACE ) )
        return handle_player( p_conn, p_from, p_this );

    if( !strcmp( psz_target_interface, DBUS_MPRIS_TRACKLIST_INTERFACE ) )
        return handle_tracklist( p_conn, p_from, p_this );

    return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
}
示例#3
0
void		*handle_client(t_elem *player)
{
  t_player	*data;
  char		buff[256];
  int		len;

  data = player->data;
  player = player->next;
  if ((len = read(data->fd, buff, 255)) > 0)
    {
      buff[len] = 0;
      if (data->state == WAITING)
	handle_waiting_player(data, buff);
      else
	handle_player(data, buff);
    }
  else
    erase_client(data, 1);
  return (player);
}