Пример #1
0
/** Run dialog and try to connect.
 * This runs the service chooser dialog and connects to the given service
 * with the attached FawkesNetworkClient. If the connection couldn't be established
 * an error dialog is shown. You should not rely on the connection to be
 * active after calling this method, rather you should use a ConnectionDispatcher
 * to get the "connected" signal.
 */
void
ServiceChooserDialog::run_and_connect()
{
  if (! __client)  throw NullPointerException("FawkesNetworkClient not set");
  if (__client->connected()) throw Exception("Client is already connected");

  if ( run() ) {
    try {
      Glib::ustring name;
      Glib::ustring hostname;
      Glib::ustring ipaddr;
      unsigned short int port;
      get_selected_service(name, hostname, ipaddr, port);
      if ( port == 0 )  port = 1910;

      __client->connect(hostname.c_str(), ipaddr.c_str(), port);
    } catch (Exception &e) {
      Glib::ustring message = *(e.begin());
      Gtk::MessageDialog md(__parent, message, /* markup */ false,
			    Gtk::MESSAGE_ERROR, Gtk::BUTTONS_OK,
			    /* modal */ true);
      md.set_title("Connection failed");
      md.run();
    }
  }
}
Пример #2
0
G_MODULE_EXPORT
void
on_device_treeview_row_activate (GtkMenuItem *menuitem,
                                 gpointer     user_data)
{
        GUPnPServiceProxy         *proxy;
        GUPnPServiceIntrospection *introspection;

        /* See if a service is selected */
        proxy = get_selected_service ();
        if (proxy != NULL) {
                gboolean subscribed;

                subscribed = gupnp_service_proxy_get_subscribed (proxy);
                gupnp_service_proxy_set_subscribed (proxy, !subscribed);
        } else {
                GUPnPServiceActionInfo *action_info;

                /* See if an action is selected */
                action_info = get_selected_action (&proxy, &introspection);
                if (action_info != NULL) {
                        run_action_dialog (action_info,
                                           proxy,
                                           introspection);
                        g_object_unref (introspection);
                }
        }

        if (proxy != NULL)
                g_object_unref (proxy);
}
Пример #3
0
static void
setup_device_popup (GtkWidget *widget)
{
        GUPnPServiceProxy *proxy;

        /* See if a service is selected */
        proxy = get_selected_service ();
        if (proxy != NULL) {
                g_object_set (subscribe_menuitem,
                              "visible",
                              TRUE,
                              "active",
                              gupnp_service_proxy_get_subscribed (proxy),
                              NULL);

                g_object_set (action_menuitem,
                              "visible",
                              FALSE,
                              NULL);
        } else {
                GUPnPServiceActionInfo *action;

                g_object_set (subscribe_menuitem,
                              "visible",
                              FALSE,
                              NULL);

                /* See if an action is selected */
                action = get_selected_action (NULL, NULL);
                g_object_set (action_menuitem,
                              "visible",
                              action != NULL,
                              NULL);
        }

        /* Separator should be visible only if either service or action row is
         * selected
         */
        g_object_set (separator,
                      "visible",
                      (proxy != NULL),
                      NULL);
        if (proxy)
                g_object_unref (proxy);
}
Пример #4
0
/** Get raw address.
 * @param addr upon returns contains the raw representation of the IP address
 * @param addr_size size in bytes of addr, if addr_size is too small for an
 * AF_INET addr an exception is thrown.
 */
void
ServiceChooserDialog::get_raw_address(struct sockaddr *addr, socklen_t addr_size)
{
  if ( addr_size < sizeof(struct sockaddr_in) ) {
    throw Exception("Size of addrlen too small, only %u bytes, but required %zu\n",
		    addr_size, sizeof(struct sockaddr_in));
  }
  Glib::ustring name, hostname, ipaddr;
  unsigned short int port;
  get_selected_service (name, hostname, ipaddr, port);

  if (inet_pton(AF_INET, ipaddr.c_str(), &(((struct sockaddr_in *)addr)->sin_addr)) <= 0) {
    NetworkNameResolver resolver;
    struct sockaddr_in *saddr;
    socklen_t saddr_len;
    if (resolver.resolve_name_blocking(ipaddr.c_str(), (struct sockaddr **)&saddr, &saddr_len)) {
      memcpy(addr, saddr, std::min(saddr_len, addr_size));
    } else {
      throw Exception("Could not lookup hostname '%s' and it is not a valid IP address",
		      ipaddr.c_str());
    }
  }

}