static void
watch_killer(NautilusDropboxHookserv *hookserv) {
  debug("hook client disconnected");

  hookserv->connected = FALSE;

  g_hook_list_invoke(&(hookserv->ondisconnect_hooklist), FALSE);
  
  /* we basically just have to free the memory allocated in the
     handle_hook_server_init ctx */
  if (hookserv->hhsi.command_name != NULL) {
    g_free(hookserv->hhsi.command_name);
    hookserv->hhsi.command_name = NULL;
  }

  if (hookserv->hhsi.command_args != NULL) {
    g_hash_table_unref(hookserv->hhsi.command_args);
    hookserv->hhsi.command_args = NULL;
  }

  g_io_channel_unref(hookserv->chan);
  hookserv->chan = NULL;
  hookserv->event_source = 0;
  hookserv->socket = 0;

  /* lol we also have to start a new connection */
  try_to_connect(hookserv);
}
Example #2
0
static void
gnc_gconf_general_changed (GConfClient *client,
                           guint cnxn_id,
                           GConfEntry *entry,
                           gpointer data)
{
    const gchar *key, *key_tail;
    GHookList *hook_list;

    g_once(&gcb_init_once, gcb_init, NULL);

    key = gconf_entry_get_key(entry);
    key_tail = strrchr(key, '/');
    if (key_tail != NULL)
    {
        key_tail++;
    }
    if (key_tail == NULL)
    {
        /* Should never happen. */
        g_warning("Malformed key %s:", key);
        return;
    }

    hook_list = g_hash_table_lookup(gcb_callback_hash, key_tail);
    if (hook_list != NULL)
        g_hook_list_marshal(hook_list, TRUE, gcb_call_hook, entry);
    g_hook_list_invoke(gcb_final_hook_list, TRUE);
}
/* The show method */
static void
deskmenu_show (DeskmenuObject *dm_object,
			   Deskmenu *deskmenu,
               GError  **error)
{
	GSList *list = NULL, *iterator = NULL;
	list = dm_object->pin_items;
	g_hook_list_invoke (dm_object->show_hooks, FALSE);
	if (deskmenu->pinnable)
	{
		gtk_menu_set_tearoff_state (GTK_MENU (dm_object->menu), TRUE);
		for (iterator = list; iterator; iterator = iterator->next)
		{
			gtk_widget_show (iterator->data);
			gtk_widget_set_no_show_all (iterator->data, FALSE);
		}
	}
	else {
		gtk_menu_popup(GTK_MENU (dm_object->menu),
		               NULL, NULL, NULL, NULL,
		               0, 0);
		for (iterator = list; iterator; iterator = iterator->next)
		{
			gtk_widget_hide (iterator->data);
			gtk_widget_set_no_show_all (iterator->data, TRUE);
		}
	}
}
static void
cogl_pango_glyph_cache_reorganize_cb (void *user_data)
{
  CoglPangoGlyphCache *cache = user_data;

  g_hook_list_invoke (&cache->reorganize_callbacks, FALSE);
}
static void
command_on_connect(DropboxClient *dc) {
  dc->command_connect_called = TRUE;
  
  if (dc->hook_connect_called) {
    debug("client connection");
    g_hook_list_invoke(&(dc->onconnect_hooklist), FALSE);
    /* reset flags */
    dc->hook_connect_called = dc->command_connect_called = FALSE;
  }
}
static void
hook_on_disconnect(DropboxClient *dc) {
  dc->hook_disconnect_called = TRUE;
  
  if (dc->command_disconnect_called) {
    debug("client disconnect");
    g_hook_list_invoke(&(dc->ondisconnect_hooklist), FALSE);
    /* reset flags */
    dc->hook_disconnect_called = dc->command_disconnect_called = FALSE;
  }
  else {
    dropbox_command_client_force_reconnect(&(dc->dcc));
  }
}
Example #7
0
/**
 * Instantiates all the 
 */
void
TheOneInit(void)
{
    if (gSleepConfig.debug)
    {
        PrintHookLists();
    }

    /** Run common init funcs **/
    GHookList *commonInitFuncs = g_hash_table_lookup(namedInitFuncs, COMMON_INIT_NAME);
    if (commonInitFuncs)
    {
        g_info("\n%s Running common Inits", __FUNCTION__);
        g_hook_list_invoke(commonInitFuncs, FALSE);
    }
}
static gboolean
on_disconnect(DropboxCommandClient *dcc) {
  g_hook_list_invoke(&(dcc->ondisconnect_hooklist), FALSE);
  return FALSE;
}
void prefs_set(const gchar * prefs_name, ...)
{
	va_list ap;
	struct prefs_value * value;
	guint new_guint;
	gboolean new_gboolean;
	const gchar * new_string;

	va_start(ap, prefs_name);

	value = g_hash_table_lookup(prefs_hash, prefs_name);
	if(value) {
		gboolean validated;
		union prefs_value_union value_backup;

		/* backup the current value, if the validator decides the new one is invalid */
		value_backup = value->value;

		/* check if the old value hasn't changed
		 * and if so, set the new value */
		switch(value->type) {
		case PREFS_TYPE_UINT:
			new_guint = va_arg(ap, guint);
			if(value->value.integer!=new_guint)
				value->value.integer = new_guint;
			else
				goto no_change;
			break;
		case PREFS_TYPE_BOOL:
			new_gboolean = va_arg(ap, gboolean);
			if(value->value.boolean!=new_gboolean)
				value->value.boolean = new_gboolean;
			else
				goto no_change;
			break;
		case PREFS_TYPE_STR:
			new_string = va_arg(ap, gchar*);
			if(strcmp(value->value.string, new_string))
				value->value.string = g_strdup(new_string);
			else
				goto no_change;	
			break;
		case PREFS_TYPE_LIST:
			value->value.list = util_list_copy_with_data(
				va_arg(ap, GList *),
				(util_list_data_copy_func_t*)g_strdup);
			break;
		}

		/* invoke validator to check new value */
		validated = value->validator_func != NULL
			? value->validator_func(prefs_name, value->validator_user_data)
			: TRUE;

		if(validated) {
			/* free backup data */
			prefs_free_value(value->type, &value_backup);

			/* notify that we've changed to a new value */
			g_hook_list_invoke(&value->change_hook, FALSE);
			raise_event(EVENT_PREFS_CHANGED, (gpointer)prefs_name, 0);

			/* preferences are not in sync with those on the disk */
			prefs_values_saved = FALSE;
		} else {
			/* restore backup value
			 */
			prefs_free_value(value->type, &value->value);
			value->value = value_backup;
		}
	} else {
Example #10
0
static void
_cogl_atlas_notify_post_reorganize (CoglAtlas *atlas)
{
  g_hook_list_invoke (&atlas->post_reorganize_callbacks, FALSE);
}
static gboolean
on_connect(SkypeCommandClient *dcc) {
  g_hook_list_invoke(&(dcc->onconnect_hooklist), FALSE);
  return FALSE;
}
static gboolean
try_to_connect(NautilusDropboxHookserv *hookserv) {
  /* create socket */
  hookserv->socket = socket(PF_UNIX, SOCK_STREAM, 0);
  
  /* set native non-blocking, for connect timeout */
  {
    unsigned int flags;

    if ((flags = fcntl(hookserv->socket, F_GETFL, 0)) < 0) {
      goto FAIL_CLEANUP;
    }

    if (fcntl(hookserv->socket, F_SETFL, flags | O_NONBLOCK) < 0) {
      goto FAIL_CLEANUP;
    }
  }

  /* connect to server, might fail of course */
  {
    struct sockaddr_un addr;
    socklen_t addr_len;
    
    /* intialize address structure */
    addr.sun_family = AF_UNIX;
    g_snprintf(addr.sun_path,
	       sizeof(addr.sun_path),
	       "%s/.dropbox/iface_socket",
	       g_get_home_dir());
    addr_len = sizeof(addr) - sizeof(addr.sun_path) + strlen(addr.sun_path);

    /* if there was an error we have to try again later */
    if (connect(hookserv->socket, (struct sockaddr *) &addr, addr_len) < 0) {
      if (errno == EINPROGRESS) {
	fd_set writers;
	struct timeval tv = {1, 0};
        FD_ZERO(&writers);
	FD_SET(hookserv->socket, &writers);
	
	/* if nothing was ready after 3 seconds, fail out homie */
	if (select(hookserv->socket+1, NULL, &writers, NULL, &tv) == 0) {
	  goto FAIL_CLEANUP;
	}

	if (connect(hookserv->socket, (struct sockaddr *) &addr, addr_len) < 0) {
	  debug("couldn't connect to hook server after 1 second");
	  goto FAIL_CLEANUP;
	}
      }
      else {
	goto FAIL_CLEANUP;
      }
    }
  }

  /* lol sometimes i write funny codez */
  if (FALSE) {
  FAIL_CLEANUP:
    close(hookserv->socket);
    g_timeout_add_seconds(1, (GSourceFunc) try_to_connect, hookserv);
    return FALSE;
  }

  /* great we connected!, let's create the channel and wait on it */
  hookserv->chan = g_io_channel_unix_new(hookserv->socket);
  g_io_channel_set_line_term(hookserv->chan, "\n", -1);
  g_io_channel_set_close_on_unref(hookserv->chan, TRUE);

  /*debug("create channel"); */

  /* Set non-blocking ;) (again just in case) */
  {
    GIOFlags flags;
    GIOStatus iostat;
    
    flags = g_io_channel_get_flags(hookserv->chan);
    iostat = g_io_channel_set_flags(hookserv->chan, flags | G_IO_FLAG_NONBLOCK,
				    NULL);
    if (iostat == G_IO_STATUS_ERROR) {
      g_io_channel_unref(hookserv->chan);
      g_timeout_add_seconds(1, (GSourceFunc) try_to_connect, hookserv);
      return FALSE;
    }
  }

  /*debug("set non blocking"); */

  /* this is fun, async io watcher */
  hookserv->hhsi.line = 0;
  hookserv->hhsi.command_args = NULL;
  hookserv->hhsi.command_name = NULL;
  hookserv->event_source = 
    g_io_add_watch_full(hookserv->chan, G_PRIORITY_DEFAULT,
			G_IO_IN | G_IO_PRI | G_IO_ERR | G_IO_HUP | G_IO_NVAL,
			(GIOFunc) handle_hook_server_input, hookserv,
			(GDestroyNotify) watch_killer);

  debug("hook client connected");
  hookserv->connected = TRUE;
  g_hook_list_invoke(&(hookserv->onconnect_hooklist), FALSE);

  /*debug("added watch");*/
  return FALSE;
}