コード例 #1
0
ファイル: gmenuexporter.c プロジェクト: xchataqua/glib
static void
g_menu_exporter_menu_items_changed (GMenuModel *model,
                                    gint        position,
                                    gint        removed,
                                    gint        added,
                                    gpointer    user_data)
{
  GMenuExporterMenu *menu = user_data;
  GSequenceIter *point;
  gint i;

  g_assert (menu->model == model);
  g_assert (menu->item_links != NULL);
  g_assert (position + removed <= g_sequence_get_length (menu->item_links));

  point = g_sequence_get_iter_at_pos (menu->item_links, position + removed);
  g_sequence_remove_range (g_sequence_get_iter_at_pos (menu->item_links, position), point);

  for (i = position; i < position + added; i++)
    g_sequence_insert_before (point, g_menu_exporter_menu_create_links (menu, i));

  if (g_menu_exporter_group_is_subscribed (menu->group))
    {
      GVariantBuilder builder;

      g_variant_builder_init (&builder, G_VARIANT_TYPE ("(uuuuaa{sv})"));
      g_variant_builder_add (&builder, "u", g_menu_exporter_group_get_id (menu->group));
      g_variant_builder_add (&builder, "u", menu->id);
      g_variant_builder_add (&builder, "u", position);
      g_variant_builder_add (&builder, "u", removed);

      g_variant_builder_open (&builder, G_VARIANT_TYPE ("aa{sv}"));
      for (i = position; i < position + added; i++)
        g_variant_builder_add_value (&builder, g_menu_exporter_menu_describe_item (menu, i));
      g_variant_builder_close (&builder);

      g_menu_exporter_report (g_menu_exporter_group_get_exporter (menu->group), g_variant_builder_end (&builder));
    }
}
コード例 #2
0
ファイル: gmenuexporter.c プロジェクト: xchataqua/glib
static void
g_menu_exporter_group_subscribe (GMenuExporterGroup *group,
                                 GVariantBuilder    *builder)
{
  GHashTableIter iter;
  gpointer key, val;

  if (!group->prepared)
    {
      GMenuExporterMenu *menu;

      /* set this first, so that any menus created during the
       * preparation of the first menu also end up in the prepared
       * state.
       * */
      group->prepared = TRUE;

      menu = g_hash_table_lookup (group->menus, 0);
      g_menu_exporter_menu_prepare (menu);
    }

  group->subscribed++;

  g_hash_table_iter_init (&iter, group->menus);
  while (g_hash_table_iter_next (&iter, &key, &val))
    {
      guint id = GPOINTER_TO_INT (key);
      GMenuExporterMenu *menu = val;

      if (g_sequence_get_length (menu->item_links))
        {
          g_variant_builder_open (builder, G_VARIANT_TYPE ("(uuaa{sv})"));
          g_variant_builder_add (builder, "u", group->id);
          g_variant_builder_add (builder, "u", id);
          g_variant_builder_add_value (builder, g_menu_exporter_menu_list (menu));
          g_variant_builder_close (builder);
        }
    }
}
コード例 #3
0
ファイル: dbus_js_convert.c プロジェクト: CannedFish/dde
GVariant* js_to_dbus(JSContextRef ctx, const JSValueRef jsvalue, const GVariantType* sig, JSValueRef *exception)
{
    if (g_variant_type_is_array(sig)) {
        GVariantBuilder builder;
        g_variant_builder_init(&builder, sig);
        JSPropertyNameArrayRef array = JSObjectCopyPropertyNames(ctx, (JSObjectRef)jsvalue);

        const GVariantType* child_sig = g_variant_type_element(sig);

        if (g_variant_type_is_dict_entry(child_sig)) {

            const GVariantType* key_sig = g_variant_type_first(child_sig);
            const GVariantType* value_sig = g_variant_type_next(key_sig);
            for (size_t i=0; i < JSPropertyNameArrayGetCount(array); i++) {
                if (filter_function_child(ctx, jsvalue, i)) continue;

                g_variant_builder_open(&builder, child_sig);
                JSValueRef key = JSValueMakeString(ctx, JSPropertyNameArrayGetNameAtIndex(array, i));
                JSValueRef value = JSObjectGetPropertyAtIndex(ctx, (JSObjectRef)jsvalue, i, NULL);
                g_variant_builder_add_value(&builder, js_to_dbus(ctx, key, key_sig, exception));
                g_variant_builder_add_value(&builder, js_to_dbus(ctx, value, value_sig, exception));
                g_variant_builder_close(&builder);
            }
            return g_variant_builder_end(&builder);

	} else {
	    GVariantBuilder builder;
	    g_variant_builder_init(&builder, sig);
	    JSPropertyNameArrayRef array = JSObjectCopyPropertyNames(ctx, (JSObjectRef)jsvalue);
	    const GVariantType* child_sig = g_variant_type_element(sig);
	    for (size_t i=0; i < JSPropertyNameArrayGetCount(array); i++) {
		if (filter_array_child(ctx, array, i)) continue;
		g_variant_builder_add_value(&builder, js_to_dbus(ctx, JSObjectGetPropertyAtIndex(ctx, (JSObjectRef)jsvalue, i, NULL), child_sig, exception));
	    }
	    JSPropertyNameArrayRelease(array);
	    return g_variant_builder_end(&builder);
	}
    } else if (g_variant_type_is_tuple(sig)) {
	    GVariantBuilder builder;
	    g_variant_builder_init(&builder, sig);
	    JSPropertyNameArrayRef array = JSObjectCopyPropertyNames(ctx, (JSObjectRef)jsvalue);
	    const GVariantType* current_sig = g_variant_type_first(sig);
            for (size_t i=0; i < JSPropertyNameArrayGetCount(array); i++) {
                if (filter_array_child(ctx, array, i)) continue;
                g_variant_builder_add_value(&builder, js_to_dbus(ctx, JSObjectGetPropertyAtIndex(ctx, (JSObjectRef)jsvalue, i, NULL), current_sig, exception));
		current_sig = g_variant_type_next(current_sig);
            }
            JSPropertyNameArrayRelease(array);
            return g_variant_builder_end(&builder);
    } else {
        switch (g_variant_type_peek_string(sig)[0]) {
            case 'y':
                return g_variant_new_byte(JSValueToNumber(ctx, jsvalue, exception));
            case 'n':
                return g_variant_new_int16(JSValueToNumber(ctx, jsvalue, exception));
            case 'q':
                return g_variant_new_uint16(JSValueToNumber(ctx, jsvalue, exception));
            case 'i':
                return g_variant_new_int32(JSValueToNumber(ctx, jsvalue, exception));
            case 'u':
                return g_variant_new_uint32(JSValueToNumber(ctx, jsvalue, exception));
            case 'x':
                return g_variant_new_int64(JSValueToNumber(ctx, jsvalue, exception));
            case 't':
                return g_variant_new_uint64(JSValueToNumber(ctx, jsvalue, exception));
            case 'd':
                return g_variant_new_double(JSValueToNumber(ctx, jsvalue, exception));
            case 'h':
                return g_variant_new_handle(JSValueToNumber(ctx, jsvalue, exception));
            case 'b':
                return g_variant_new_boolean(JSValueToBoolean(ctx, jsvalue));
            case 's':
                {
                    char* v = jsvalue_to_cstr(ctx, jsvalue);
                    GVariant* r = g_variant_new_string(v);
                    g_free(v);
                    return r;
                }
            case 'v':
                {
                    //TODO:
                    /*g_variant_new_variant()*/
                    g_assert_not_reached();
                }
        }
    }
    g_assert_not_reached();
}
コード例 #4
0
ファイル: ev-application.c プロジェクト: avasha/atril
static void
method_call_cb (GDBusConnection       *connection,
                const gchar           *sender,
                const gchar           *object_path,
                const gchar           *interface_name,
                const gchar           *method_name,
                GVariant              *parameters,
                GDBusMethodInvocation *invocation,
                gpointer               user_data)
{
        EvApplication   *application = EV_APPLICATION (user_data);
	GList           *windows, *l;
        guint            timestamp;
        GVariantIter    *iter;
        const gchar     *key;
        GVariant        *value;
        GdkDisplay      *display = NULL;
        int              screen_number = 0;
	EvLinkDest      *dest = NULL;
	EvWindowRunMode  mode = EV_WINDOW_MODE_NORMAL;
	const gchar     *search_string = NULL;
	GdkScreen       *screen = NULL;

	if (g_strcmp0 (method_name, "Reload") == 0) {
		g_variant_get (parameters, "(a{sv}u)", &iter, &timestamp);

		while (g_variant_iter_loop (iter, "{&sv}", &key, &value)) {
			if (strcmp (key, "display") == 0 && g_variant_classify (value) == G_VARIANT_CLASS_STRING) {
				display = ev_display_open_if_needed (g_variant_get_string (value, NULL));
			} else if (strcmp (key, "screen") == 0 && g_variant_classify (value) == G_VARIANT_CLASS_STRING) {
				screen_number = g_variant_get_int32 (value);
			} else if (strcmp (key, "mode") == 0 && g_variant_classify (value) == G_VARIANT_CLASS_UINT32) {
			mode = g_variant_get_uint32 (value);
			} else if (strcmp (key, "page-label") == 0 && g_variant_classify (value) == G_VARIANT_CLASS_STRING) {
				dest = ev_link_dest_new_page_label (g_variant_get_string (value, NULL));
			} else if (strcmp (key, "find-string") == 0 && g_variant_classify (value) == G_VARIANT_CLASS_STRING) {
				search_string = g_variant_get_string (value, NULL);
			}
		}
		g_variant_iter_free (iter);

		if (display != NULL &&
		    screen_number >= 0 &&
		    screen_number < gdk_display_get_n_screens (display))
			screen = gdk_display_get_screen (display, screen_number);
		else
			screen = gdk_screen_get_default ();

		windows = ev_application_get_windows (application);
		for (l = windows; l != NULL; l = g_list_next (l)) {
			EvWindow *ev_window = EV_WINDOW (l->data);

			ev_application_open_uri_in_window (application, application->uri,
							   ev_window,
							   screen, dest, mode,
							   search_string,
							   timestamp);
		}
		g_list_free (windows);

		if (dest)
			g_object_unref (dest);

		g_dbus_method_invocation_return_value (invocation, g_variant_new ("()"));
	} else if (g_strcmp0 (method_name, "GetWindowList") == 0) {
		GList          *windows = ev_application_get_windows (application);
		GVariantBuilder builder;
		GList	       *l;

		g_variant_builder_init (&builder, G_VARIANT_TYPE ("(ao)"));
		g_variant_builder_open (&builder, G_VARIANT_TYPE ("ao"));

		for (l = windows; l; l = g_list_next (l)) {
			EvWindow *window = (EvWindow *)l->data;

			g_variant_builder_add (&builder, "o", ev_window_get_dbus_object_path (window));
		}

		g_variant_builder_close (&builder);
		g_list_free (windows);

		g_dbus_method_invocation_return_value (invocation, g_variant_builder_end (&builder));
	}
}
コード例 #5
0
static void
handle_method_call (GDBusConnection       *connection,
		    const char            *sender,
		    const char            *object_path,
		    const char            *interface_name,
		    const char            *method_name,
		    GVariant              *parameters,
		    GDBusMethodInvocation *invocation,
		    gpointer               user_data)
{
	update_registered_commands_capabilities ();

	if (g_strcmp0 (method_name, "GetSupportedTypes") == 0) {
		char *action;
		int  *supported_types = NULL;

		g_variant_get (parameters, "(s)", &action);

		if (g_strcmp0 (action, "create") == 0) {
			supported_types = save_type;
		}
		else if (g_strcmp0 (action, "create_single_file") == 0) {
			supported_types = single_file_save_type;
		}
		else if (g_strcmp0 (action, "extract") == 0) {
			supported_types = open_type;
		}

		if (supported_types == NULL) {
			g_dbus_method_invocation_return_error (invocation,
							       G_IO_ERROR,
							       G_IO_ERROR_INVALID_ARGUMENT,
							       "Action not valid %s, valid values are: create, create_single_file, extract",
							       action);
		}
		else {
			GVariantBuilder builder;
			int             i;

			g_variant_builder_init (&builder, G_VARIANT_TYPE ("(aa{ss})"));
			g_variant_builder_open (&builder, G_VARIANT_TYPE ("aa{ss}"));
			for (i = 0; supported_types[i] != -1; i++) {
				g_variant_builder_open (&builder, G_VARIANT_TYPE ("a{ss}"));
				g_variant_builder_add (&builder, "{ss}",
						       "mime-type",
						       mime_type_desc[supported_types[i]].mime_type);
				g_variant_builder_add (&builder, "{ss}",
						       "default-extension",
						       mime_type_desc[supported_types[i]].default_ext);
				g_variant_builder_add (&builder, "{ss}",
						       "description",
						       _(mime_type_desc[supported_types[i]].name));
				g_variant_builder_close (&builder);
			}
			g_variant_builder_close (&builder);

			g_dbus_method_invocation_return_value (invocation, g_variant_builder_end (&builder));
		}

		g_free (action);
	}
	else if (g_strcmp0 (method_name, "AddToArchive") == 0) {
		char       *archive;
		char      **files;
		gboolean    use_progress_dialog;
		int         i;
		GList      *file_list = NULL;
		GtkWidget  *window;

		g_variant_get (parameters, "(s^asb)", &archive, &files, &use_progress_dialog);

		for (i = 0; files[i] != NULL; i++)
			file_list = g_list_prepend (file_list, files[i]);
		file_list = g_list_reverse (file_list);

		window = fr_window_new ();
		fr_window_use_progress_dialog (FR_WINDOW (window), use_progress_dialog);

		g_signal_connect (window, "progress", G_CALLBACK (window_progress_cb), connection);
		g_signal_connect (window, "ready", G_CALLBACK (window_ready_cb), invocation);

		fr_window_new_batch (FR_WINDOW (window));
		fr_window_set_batch__add (FR_WINDOW (window), archive, file_list);
		fr_window_append_batch_action (FR_WINDOW (window), FR_BATCH_ACTION_QUIT, NULL, NULL);
		fr_window_start_batch (FR_WINDOW (window));

		g_free (archive);

		gtk_main ();
	}
	else if (g_strcmp0 (method_name, "Compress") == 0) {
		char      **files;
		char       *destination;
		gboolean    use_progress_dialog;
		int         i;
		GList      *file_list = NULL;
		GtkWidget  *window;

		g_variant_get (parameters, "(^assb)", &files, &destination, &use_progress_dialog);

		for (i = 0; files[i] != NULL; i++)
			file_list = g_list_prepend (file_list, files[i]);
		file_list = g_list_reverse (file_list);

		if ((destination == NULL) || (strcmp (destination, "") == 0))
			destination = remove_level_from_path (file_list->data);

		window = fr_window_new ();
		fr_window_use_progress_dialog (FR_WINDOW (window), use_progress_dialog);
		fr_window_set_default_dir (FR_WINDOW (window), destination, TRUE);

		g_signal_connect (window, "progress", G_CALLBACK (window_progress_cb), connection);
		g_signal_connect (window, "ready", G_CALLBACK (window_ready_cb), invocation);

		fr_window_new_batch (FR_WINDOW (window));
		fr_window_set_batch__add (FR_WINDOW (window), NULL, file_list);
		fr_window_append_batch_action (FR_WINDOW (window), FR_BATCH_ACTION_QUIT, NULL, NULL);
		fr_window_start_batch (FR_WINDOW (window));

		g_free (destination);

		gtk_main ();
	}
	else if (g_strcmp0 (method_name, "Extract") == 0) {
		char      *archive;
		char      *destination;
		gboolean   use_progress_dialog;
		GtkWidget *window;

		g_variant_get (parameters, "(ssb)", &archive, &destination, &use_progress_dialog);

		window = fr_window_new ();
		fr_window_use_progress_dialog (FR_WINDOW (window), use_progress_dialog);
		if ((destination != NULL) & (strcmp (destination, "") != 0))
			fr_window_set_default_dir (FR_WINDOW (window), destination, TRUE);

		g_signal_connect (window, "progress", G_CALLBACK (window_progress_cb), connection);
		g_signal_connect (window, "ready", G_CALLBACK (window_ready_cb), invocation);

		fr_window_new_batch (FR_WINDOW (window));
		fr_window_set_batch__extract (FR_WINDOW (window), archive, destination);
		fr_window_append_batch_action (FR_WINDOW (window), FR_BATCH_ACTION_QUIT, NULL, NULL);
		fr_window_start_batch (FR_WINDOW (window));

		g_free (destination);
		g_free (archive);

		gtk_main ();
	}
	else if (g_strcmp0 (method_name, "ExtractHere") == 0) {
		char      *archive;
		gboolean   use_progress_dialog;
		GtkWidget *window;

		g_variant_get (parameters, "(sb)", &archive, &use_progress_dialog);

		window = fr_window_new ();
		fr_window_use_progress_dialog (FR_WINDOW (window), use_progress_dialog);

		g_signal_connect (window, "progress", G_CALLBACK (window_progress_cb), connection);
		g_signal_connect (window, "ready", G_CALLBACK (window_ready_cb), invocation);

		fr_window_new_batch (FR_WINDOW (window));
		fr_window_set_batch__extract_here (FR_WINDOW (window), archive);
		fr_window_append_batch_action (FR_WINDOW (window), FR_BATCH_ACTION_QUIT, NULL, NULL);
		fr_window_start_batch (FR_WINDOW (window));

		g_free (archive);

		gtk_main ();
	}
}
コード例 #6
0
ファイル: ev-application.c プロジェクト: avasha/atril
static void
on_register_uri_cb (GObject      *source_object,
		    GAsyncResult *res,
		    gpointer      user_data)
{
	GDBusConnection   *connection = G_DBUS_CONNECTION (source_object);
	EvRegisterDocData *data = (EvRegisterDocData *)user_data;
	EvApplication     *application = EV_APP;
	GVariant          *value;
	const gchar       *owner;
	GVariantBuilder    builder;
	GError            *error = NULL;

	value = g_dbus_connection_call_finish (connection, res, &error);
	if (!value) {
		g_warning ("Error registering document: %s\n", error->message);
		g_error_free (error);

		_ev_application_open_uri_at_dest (application,
						  data->uri,
						  data->screen,
						  data->dest,
						  data->mode,
						  data->search_string,
						  data->timestamp);
		ev_register_doc_data_free (data);

		return;
	}

	g_variant_get (value, "(&s)", &owner);

	/* This means that the document wasn't already registered; go
         * ahead with opening it.
         */
	if (owner[0] == '\0') {
                g_variant_unref (value);

		application->doc_registered = TRUE;

		_ev_application_open_uri_at_dest (application,
						  data->uri,
						  data->screen,
						  data->dest,
						  data->mode,
						  data->search_string,
						  data->timestamp);
		ev_register_doc_data_free (data);

                return;
        }

	/* Already registered */
	g_variant_builder_init (&builder, G_VARIANT_TYPE ("(a{sv}u)"));
        g_variant_builder_open (&builder, G_VARIANT_TYPE ("a{sv}"));
        g_variant_builder_add (&builder, "{sv}",
                               "display",
                               g_variant_new_string (gdk_display_get_name (gdk_screen_get_display (data->screen))));
        g_variant_builder_add (&builder, "{sv}",
                               "screen",
                               g_variant_new_int32 (gdk_screen_get_number (data->screen)));
	if (data->dest) {
                g_variant_builder_add (&builder, "{sv}",
                                       "page-label",
                                       g_variant_new_string (ev_link_dest_get_page_label (data->dest)));
	}
	if (data->search_string) {
                g_variant_builder_add (&builder, "{sv}",
                                       "find-string",
                                       g_variant_new_string (data->search_string));
	}
	if (data->mode != EV_WINDOW_MODE_NORMAL) {
                g_variant_builder_add (&builder, "{sv}",
                                       "mode",
                                       g_variant_new_uint32 (data->mode));
	}
        g_variant_builder_close (&builder);

        g_variant_builder_add (&builder, "u", data->timestamp);

        g_dbus_connection_call (connection,
				owner,
				APPLICATION_DBUS_OBJECT_PATH,
				APPLICATION_DBUS_INTERFACE,
				"Reload",
				g_variant_builder_end (&builder),
				NULL,
				G_DBUS_CALL_FLAGS_NONE,
				-1,
				NULL,
				on_reload_cb,
				NULL);
	g_variant_unref (value);
	ev_register_doc_data_free (data);
}
コード例 #7
0
ファイル: test-glib.c プロジェクト: larsu/c-variant
static void test_generate(const char *type, CVariant **cvp, GVariant **gvp) {
        GVariantBuilder *builder;
        CVariantVarg varg;
        CVariant *cv, *child;
        GVariant *gv, *gvc;
        uint64_t val_64;
        size_t n;
        char *s;
        int r, c;

        n = strlen(type);

        r = c_variant_new(&cv, type, n);
        assert(r >= 0);

        /* wrap as tuple as GVariantBuilder cannot deal with basic types */
        s = alloca(n + 2);
        s[0] = '(';
        memcpy(s + 1, type, n);
        s[n + 1] = ')';
        s[n + 2] = 0;
        builder = g_variant_builder_new(G_VARIANT_TYPE(s));

        for (c = c_variant_varg_init(&varg, type, strlen(type));
             c;
             c = c_variant_varg_next(&varg)) {
                val_64 = rand();
                val_64 <<= 32;
                val_64 |= rand();

                switch (c) {
                case -1:
                        c_variant_end(cv, NULL);
                        g_variant_builder_close(builder);
                        break;
                case C_VARIANT_VARIANT:
                        c_variant_new(&child, "u", 1);
                        c_variant_write(child, "u", (uint32_t)val_64);
                        c_variant_seal(child);
                        c_variant_write(cv, "v", child);
                        c_variant_free(child);
                        g_variant_builder_add(builder, "v",
                                              g_variant_new("u", (uint32_t)val_64));
                        break;
                case C_VARIANT_MAYBE:
                        c_variant_begin(cv, "m");
                        c_variant_varg_enter_bound(&varg, cv, val_64 & 1);

                        s = TEST_VARG_TYPE(&varg, "m", "");
                        g_variant_builder_open(builder, G_VARIANT_TYPE(s));
                        free(s);
                        break;
                case C_VARIANT_ARRAY:
                        c_variant_begin(cv, "a");
                        c_variant_varg_enter_bound(&varg, cv, val_64 & 0xf);

                        s = TEST_VARG_TYPE(&varg, "a", "");
                        g_variant_builder_open(builder, G_VARIANT_TYPE(s));
                        free(s);
                        break;
                case C_VARIANT_TUPLE_OPEN:
                        c_variant_begin(cv, "(");
                        c_variant_varg_enter_unbound(&varg, cv, ')');

                        s = TEST_VARG_TYPE(&varg, "(", ")");
                        g_variant_builder_open(builder, G_VARIANT_TYPE(s));
                        free(s);
                        break;
                case C_VARIANT_PAIR_OPEN:
                        c_variant_begin(cv, "{");
                        c_variant_varg_enter_unbound(&varg, cv, '}');

                        s = TEST_VARG_TYPE(&varg, "{", "}");
                        g_variant_builder_open(builder, G_VARIANT_TYPE(s));
                        free(s);
                        break;
                case C_VARIANT_INT64:
                        c_variant_write(cv, "x", val_64);
                        g_variant_builder_add(builder, "x", val_64);
                        break;
                case C_VARIANT_UINT64:
                        c_variant_write(cv, "t", val_64);
                        g_variant_builder_add(builder, "t", val_64);
                        break;
                case C_VARIANT_DOUBLE:
                        c_variant_write(cv, "d", *(double *)&val_64);
                        g_variant_builder_add(builder, "d", *(double *)&val_64);
                        break;
                case C_VARIANT_INT32:
                        c_variant_write(cv, "i", (uint32_t)val_64);
                        g_variant_builder_add(builder, "i", (uint32_t)val_64);
                        break;
                case C_VARIANT_UINT32:
                        c_variant_write(cv, "u", (uint32_t)val_64);
                        g_variant_builder_add(builder, "u", (uint32_t)val_64);
                        break;
                case C_VARIANT_HANDLE:
                        c_variant_write(cv, "h", (uint32_t)val_64);
                        g_variant_builder_add(builder, "h", (uint32_t)val_64);
                        break;
                case C_VARIANT_INT16:
                        c_variant_write(cv, "n", (int)val_64);
                        g_variant_builder_add(builder, "n", (int)val_64);
                        break;
                case C_VARIANT_UINT16:
                        c_variant_write(cv, "q", (int)val_64);
                        g_variant_builder_add(builder, "q", (int)val_64);
                        break;
                case C_VARIANT_BOOL:
                        c_variant_write(cv, "b", !!val_64);
                        g_variant_builder_add(builder, "b", !!val_64);
                        break;
                case C_VARIANT_BYTE:
                        c_variant_write(cv, "y", (int)val_64);
                        g_variant_builder_add(builder, "y", (int)val_64);
                        break;
                case C_VARIANT_STRING:
                        c_variant_write(cv, "s", "foobar");
                        g_variant_builder_add(builder, "s", "foobar");
                        break;
                case C_VARIANT_PATH:
                        c_variant_write(cv, "o", "/foo/bar");
                        g_variant_builder_add(builder, "o", "/foo/bar");
                        break;
                case C_VARIANT_SIGNATURE:
                        c_variant_write(cv, "g", "bison");
                        g_variant_builder_add(builder, "g", "bison");
                        break;
                default:
                        assert(0);
                        break;
                }
        }

        r = c_variant_seal(cv);
        assert(r >= 0);

        gv = g_variant_builder_end(builder);
        gvc = g_variant_get_child_value(gv, 0);
        g_variant_unref(gv);
        g_variant_builder_unref(builder);

        *cvp = cv;
        *gvp = gvc;
}
コード例 #8
0
gboolean dbus_plugin_call_response(struct custom_data *ctx, UserRequest *ur, struct dbus_request_info *dbus_info, enum tcore_response_command command, unsigned int data_len, const void *data)
{
	int i = 0;
	GSList *co_list;
	CoreObject *co_call;
	char *modem_name = NULL;
	TcorePlugin *p = NULL;

	modem_name = tcore_user_request_get_modem_name(ur);
	if (!modem_name)
		return FALSE;

	p = tcore_server_find_plugin(ctx->server, modem_name);
	free(modem_name);
	if (!p)
		return FALSE;

	co_list = tcore_plugin_get_core_objects_bytype(p, CORE_OBJECT_TYPE_NETWORK);
	if (!co_list) {
		return FALSE;
	}

	co_call = (CoreObject *)co_list->data;
	g_slist_free(co_list);

	if (!co_call) {
		return FALSE;
	}

	switch (command) {
		case TRESP_CALL_DIAL: {
			struct tresp_call_dial *resp = (struct tresp_call_dial*)data;

			dbg("receive TRESP_CALL_DIAL");
			dbg("resp->err : [%d]", resp->err);

			telephony_call_complete_dial(dbus_info->interface_object, dbus_info->invocation, resp->err);
		} break;

		case TRESP_CALL_ANSWER: {
			struct tresp_call_answer *resp = (struct tresp_call_answer*)data;

			dbg("receive TRESP_CALL_ANSWER");
			dbg("resp->err : [%d]", resp->err);
			dbg("resp->id : [%d]", resp->id);

			telephony_call_complete_answer(dbus_info->interface_object, dbus_info->invocation, resp->err, resp->id );

		} break;

		case TRESP_CALL_END: {
			struct tresp_call_end *resp = (struct tresp_call_end*)data;

			dbg("receive TRESP_CALL_END");
			dbg("resp->err : [%d]", resp->err);
			dbg("resp->id : [%d]", resp->err);
			dbg("resp->type : [%d]", resp->type);

			telephony_call_complete_end(dbus_info->interface_object, dbus_info->invocation, resp->err, resp->id, resp->type );

		} break;

		case TRESP_CALL_HOLD: {
			struct tresp_call_hold *resp = (struct tresp_call_hold*)data;

			dbg("receive TRESP_CALL_HOLD");
			dbg("resp->err : [%d]", resp->err);
			dbg("resp->id : [%d]", resp->id);

			telephony_call_complete_hold(dbus_info->interface_object, dbus_info->invocation, resp->err, resp->id );

		} break;

		case TRESP_CALL_ACTIVE: {
			struct tresp_call_active *resp = (struct tresp_call_active*)data;

			dbg("receive TRESP_CALL_ACTIVE");
			dbg("resp->err : [%d]", resp->err);
			dbg("resp->id : [%d]", resp->id);

			telephony_call_complete_active(dbus_info->interface_object, dbus_info->invocation, resp->err, resp->id );

		} break;

		case TRESP_CALL_SWAP: {
			struct tresp_call_swap *resp = (struct tresp_call_swap*)data;

			dbg("receive TRESP_CALL_SWAP");
			dbg("resp->err : [%d]", resp->err);
			dbg("resp->id : [%d]", resp->id);

			telephony_call_complete_swap(dbus_info->interface_object, dbus_info->invocation, resp->err, resp->id );

		} break;

		case TRESP_CALL_JOIN: {
			struct tresp_call_join *resp = (struct tresp_call_join*)data;

			dbg("receive TRESP_CALL_JOIN");
			dbg("resp->err : [%d]", resp->err);
			dbg("resp->id : [%d]", resp->id);

			telephony_call_complete_join(dbus_info->interface_object, dbus_info->invocation, resp->err, resp->id );

		} break;


		case TRESP_CALL_SPLIT: {
			struct tresp_call_split *resp = (struct tresp_call_split*)data;

			dbg("receive TRESP_CALL_SPLIT");
			dbg("resp->err : [%d]", resp->err);
			dbg("resp->id : [%d]", resp->id);

			telephony_call_complete_split(dbus_info->interface_object, dbus_info->invocation, resp->err, resp->id );

		} break;

		case TRESP_CALL_DEFLECT: {
			struct tresp_call_deflect *resp = (struct tresp_call_deflect*)data;

			dbg("receive TRESP_CALL_DEFLECT");
			dbg("resp->err : [%d]", resp->err);
			dbg("resp->id : [%d]", resp->id);

			telephony_call_complete_deflect(dbus_info->interface_object, dbus_info->invocation, resp->err );

		} break;

		case TRESP_CALL_TRANSFER: {
			struct tresp_call_transfer *resp = (struct tresp_call_transfer*)data;

			dbg("receive TRESP_CALL_TRANSFER");
			dbg("resp->err : [%d]", resp->err);
			dbg("resp->id : [%d]", resp->id);

			telephony_call_complete_transfer(dbus_info->interface_object, dbus_info->invocation, resp->err, resp->id );

		} break;

		case TRESP_CALL_SEND_DTMF: {
			struct tresp_call_dtmf *resp = (struct tresp_call_dtmf*)data;

			dbg("receive TRESP_CALL_SEND_DTMF");
			dbg("resp->err : [%d]", resp->err);

			telephony_call_complete_dtmf(dbus_info->interface_object, dbus_info->invocation, resp->err);
		} break;

		case TRESP_CALL_SET_SOUND_PATH: {
			struct tresp_call_sound_set_path *resp = (struct tresp_call_sound_set_path*)data;

			dbg("receive TRESP_CALL_SET_SOUND_PATH");
			dbg("resp->err : [%d]", resp->err);

			telephony_call_complete_set_sound_path(dbus_info->interface_object, dbus_info->invocation, resp->err);
		} break;

		case TRESP_CALL_SET_SOUND_VOLUME_LEVEL: {
			struct tresp_call_sound_set_volume_level *resp = (struct tresp_call_sound_set_volume_level*)data;

			dbg("receive TRESP_CALL_SET_SOUND_VOLUME_LEVEL");
			dbg("resp->err : [%d]", resp->err);

			telephony_call_complete_set_volume(dbus_info->interface_object, dbus_info->invocation, resp->err);
		} break;

		case TRESP_CALL_GET_SOUND_VOLUME_LEVEL: {
			struct tresp_call_sound_get_volume_level *resp = (struct tresp_call_sound_get_volume_level*)data;
			GVariant *result = 0;
			GVariantBuilder b;

			dbg("receive TRESP_CALL_GET_SOUND_VOLUME_LEVEL");

			g_variant_builder_init(&b, G_VARIANT_TYPE("aa{sv}"));

			g_variant_builder_open(&b, G_VARIANT_TYPE("a{sv}"));

			dbg("resp->err : [%d]", resp->err);

			g_variant_builder_add(&b, "{sv}", "err", g_variant_new_int32(resp->err));

			if ( !resp->err ) {

				dbg("resp->record_num : [%d]", resp->record_num);

				for ( i=0; i<resp->record_num; i++ ) {
					dbg("resp->type : [%d]", resp->record[i].sound);
					dbg("resp->level : [%d]", resp->record[i].volume);

					g_variant_builder_add(&b, "{sv}", "type", g_variant_new_int32(resp->record[i].sound));
					g_variant_builder_add(&b, "{sv}", "level", g_variant_new_int32(resp->record[i].volume));
				} 

			}

			g_variant_builder_close(&b);

			result = g_variant_builder_end(&b);

			telephony_call_complete_get_volume(dbus_info->interface_object, dbus_info->invocation, resp->err, result );

			g_variant_unref(result);

		} break;

		case TRESP_CALL_MUTE: {
			struct tresp_call_mute *resp = (struct tresp_call_mute*)data;

			dbg("receive TRESP_CALL_MUTE");
			dbg("resp->err : [%d]", resp->err);

			telephony_call_complete_mute(dbus_info->interface_object, dbus_info->invocation, resp->err);
		} break;

		case TRESP_CALL_UNMUTE: {
			struct tresp_call_unmute *resp = (struct tresp_call_unmute*)data;

			dbg("receive TRESP_CALL_UNMUTE");
			dbg("resp->err : [%d]", resp->err);

			telephony_call_complete_unmute(dbus_info->interface_object, dbus_info->invocation, resp->err);
		} break;

		case TRESP_CALL_GET_MUTE_STATUS: {
			struct tresp_call_get_mute_status *resp = (struct tresp_call_get_mute_status*)data;

			dbg("receive TRESP_CALL_GET_MUTE_STATUS");
			dbg("resp->err : [%d]", resp->err);
			dbg("resp->status : [%d]", resp->status);

			telephony_call_complete_get_mute_status(dbus_info->interface_object, dbus_info->invocation, resp->err, resp->status );

		} break;

		case TRESP_CALL_SET_SOUND_RECORDING: {
			struct tresp_call_sound_set_recording *resp = (struct tresp_call_sound_set_recording*)data;
			telephony_call_complete_set_sound_recording(dbus_info->interface_object, dbus_info->invocation, resp->err );

		} break;

		case TRESP_CALL_SET_SOUND_EQUALIZATION: {
			struct tresp_call_sound_set_equalization *resp = (struct tresp_call_sound_set_equalization*)data;
			telephony_call_complete_set_sound_equalization(dbus_info->interface_object, dbus_info->invocation, resp->err );

		} break;

		case TRESP_CALL_SET_SOUND_NOISE_REDUCTION: {
			struct tresp_call_sound_set_noise_reduction *resp = (struct tresp_call_sound_set_noise_reduction*)data;
			telephony_call_complete_set_sound_noise_reduction(dbus_info->interface_object, dbus_info->invocation, resp->err );

		} break;

		default:
			dbg("not handled command[%d]", command);
		break;

	}

	return TRUE;
}
コード例 #9
0
static gboolean on_call_get_status_all(TelephonyCall *call, GDBusMethodInvocation *invocation, gpointer user_data )
{
	struct custom_data *ctx = user_data;
	TcorePlugin *plugin = 0;
	GSList *list = 0;
	CoreObject *o = 0;
	CallObject *co = 0;

	GVariant *gv = 0;
	GVariantBuilder b;

	gint call_id;
	gchar call_number[MAX_CALL_NUMBER_LEN];
	gint call_type;
	gboolean call_direction;
	gint call_status;
	gboolean call_multiparty_state;

	int len, i;

	plugin = tcore_server_find_plugin(ctx->server, TCORE_PLUGIN_DEFAULT);
	if ( !plugin ) {
		dbg("[ error ] plugin : 0");
		return FALSE;
	}

	list = tcore_plugin_get_core_objects_bytype(plugin, CORE_OBJECT_TYPE_CALL);
	if ( !list ) {
		dbg("[ error ] co_list : 0");
		return FALSE;
	}

	o = (CoreObject *)list->data;
	g_slist_free(list);

	g_variant_builder_init(&b, G_VARIANT_TYPE("aa{sv}"));

#define MAX_CALL_STATUS_NUM 7
	for ( i=0; i<MAX_CALL_STATUS_NUM; i++ ) {
		list = tcore_call_object_find_by_status( o, i );

		if ( list ) {

			GSList *tmp = 0;
			tmp = list;

			dbg("[ check ] there is a call on state (0x%x)", i);

			while ( tmp ) {

				co = (CallObject*)list->data;
				if ( !co ) {
					dbg("[ error ] call object : 0");
					tmp = tmp->next;
					continue;
				}

				call_id = tcore_call_object_get_id( co );
				len = tcore_call_object_get_number( co, call_number );
				if ( !len ) {
					dbg("[ check ] no number : (0x%d)", call_id);
				}

				call_type = tcore_call_object_get_type( co );
				call_direction = tcore_call_object_get_direction( co );

				if ( call_direction == TCORE_CALL_DIRECTION_OUTGOING ) {
					call_direction = TRUE;
				} else {
					call_direction = FALSE;
				}

				call_status = tcore_call_object_get_status( co );
				call_multiparty_state = tcore_call_object_get_multiparty_state( co );

				g_variant_builder_open(&b, G_VARIANT_TYPE("a{sv}"));
				g_variant_builder_add(&b, "{sv}", "call_id", g_variant_new_int32( call_id ));
				g_variant_builder_add(&b, "{sv}", "call_number", g_variant_new_string( call_number ));
				g_variant_builder_add(&b, "{sv}", "call_type", g_variant_new_int32( call_type ));
				g_variant_builder_add(&b, "{sv}", "call_direction", g_variant_new_boolean( call_direction ));
				g_variant_builder_add(&b, "{sv}", "call_state", g_variant_new_int32( call_status ));
				g_variant_builder_add(&b, "{sv}", "call_multiparty_state", g_variant_new_boolean( call_multiparty_state ));
				g_variant_builder_close(&b);

				tmp = g_slist_next( tmp );
			}

		} else {
			dbg("[ check ] there is no call on state (0x%x)", i);

		}

	}

	gv = g_variant_builder_end(&b);

	telephony_call_complete_get_status_all(call, invocation, gv);

	g_variant_unref(gv);

	return TRUE;
}
コード例 #10
0
static gboolean
writeback_dispatcher_writeback_file (TrackerMinerFS *fs,
                                     GFile          *file,
                                     GStrv           rdf_types,
                                     GPtrArray      *results,
                                     GCancellable   *cancellable,
                                     gpointer        user_data)
{
	TrackerWritebackDispatcher *self = user_data;
	TrackerWritebackDispatcherPrivate *priv;
	gchar *uri;
	guint i;
	GVariantBuilder builder;
	WritebackFileData *data = g_new (WritebackFileData, 1);

	priv = TRACKER_WRITEBACK_DISPATCHER_GET_PRIVATE (self);

	uri = g_file_get_uri (file);
	g_debug ("Performing write-back for '%s'", uri);

	g_variant_builder_init (&builder, G_VARIANT_TYPE ("(sasaas)"));

	g_variant_builder_add (&builder, "s", uri);

	g_variant_builder_open (&builder, G_VARIANT_TYPE ("as"));
	for (i = 0; rdf_types[i] != NULL; i++) {
		g_variant_builder_add (&builder, "s", rdf_types[i]);
	}
	g_variant_builder_close (&builder);

	g_variant_builder_open (&builder, G_VARIANT_TYPE ("aas"));

	for (i = 0; i< results->len; i++) {
		GStrv row = g_ptr_array_index (results, i);
		guint y;

		g_variant_builder_open (&builder, G_VARIANT_TYPE ("as"));
		for (y = 0; row[y] != NULL; y++) {
			g_variant_builder_add (&builder, "s", row[y]);
		}

		g_variant_builder_close (&builder);
	}

	g_variant_builder_close (&builder);

	data->retries = 0;
	data->retry_timeout = 0;
	data->self = self;
	g_object_weak_ref (G_OBJECT (data->self), self_weak_notify, data);
	data->fs = g_object_ref (fs);
	data->file = g_object_ref (file);
	data->results = g_ptr_array_ref (results);
	data->rdf_types = g_strdupv (rdf_types);
	data->cancellable = g_object_ref (cancellable);
	data->cancel_id = g_cancellable_connect (data->cancellable,
	                                         G_CALLBACK (writeback_cancel_remote_operation),
	                                         data, NULL);

	g_dbus_connection_call (priv->d_connection,
	                        TRACKER_WRITEBACK_SERVICE,
	                        TRACKER_WRITEBACK_PATH,
	                        TRACKER_WRITEBACK_INTERFACE,
	                        "PerformWriteback",
	                        g_variant_builder_end (&builder),
	                        NULL,
	                        G_DBUS_CALL_FLAGS_NONE,
	                        -1,
	                        cancellable,
	                        (GAsyncReadyCallback) writeback_file_finished,
	                        data);

	g_free (uri);

	return TRUE;
}