static GValue * gegl_operation_context_add_value (GeglOperationContext *self, const gchar *property_name) { Property *property = NULL; GSList *found; found = g_slist_find_custom (self->property, property_name, lookup_property); if (found) { property = found->data; } if (property) { g_value_reset (&property->value); return &property->value; } property = property_new (property_name); self->property = g_slist_prepend (self->property, property); g_value_init (&property->value, GEGL_TYPE_BUFFER); return &property->value; }
static GValue * gegl_operation_context_add_value (GeglOperationContext *self, const gchar *property_name, GType proptype) { Property *property = NULL; GSList *found; found = g_slist_find_custom (self->property, property_name, lookup_property); if (found) { property = found->data; } if (property) { /* XXX: check that the existing one was of the right type */ g_value_reset (&property->value); return &property->value; } property = property_new (property_name); self->property = g_slist_prepend (self->property, property); g_value_init (&property->value, proptype); return &property->value; }
int pa_property_set(pa_core *c, const char *name, void *data) { pa_property *p; pa_assert(c); pa_assert(name); pa_assert(data); pa_assert(c->properties); if (pa_hashmap_get(c->properties, name)) return -1; p = property_new(name, data); pa_hashmap_put(c->properties, p->name, p); return 0; }
void test_output (void) { FILE * source; FILE * header; Node * node = NULL; Interface * interface = NULL; Method * method = NULL; Signal * signal = NULL; Argument * argument = NULL; Property * property = NULL; int ret; NihError * err; TEST_FUNCTION ("output"); source = tmpfile (); header = tmpfile (); /* Check that we can generate a valid source file and accompanying * header file for a node in proxy mode. */ TEST_FEATURE ("with proxy"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { node = node_new (NULL, NULL); interface = interface_new (node, "com.netsplit.Nih.Test"); interface->symbol = "test"; nih_list_add (&node->interfaces, &interface->entry); method = method_new (interface, "Poke"); method->symbol = "poke"; nih_list_add (&interface->methods, &method->entry); argument = argument_new (method, "address", "u", NIH_DBUS_ARG_IN); argument->symbol = "address"; nih_list_add (&method->arguments, &argument->entry); argument = argument_new (method, "value", "s", NIH_DBUS_ARG_IN); argument->symbol = "value"; nih_list_add (&method->arguments, &argument->entry); method = method_new (interface, "Peek"); method->symbol = "peek"; nih_list_add (&interface->methods, &method->entry); argument = argument_new (method, "address", "u", NIH_DBUS_ARG_IN); argument->symbol = "address"; nih_list_add (&method->arguments, &argument->entry); argument = argument_new (method, "value", "s", NIH_DBUS_ARG_OUT); argument->symbol = "value"; nih_list_add (&method->arguments, &argument->entry); method = method_new (interface, "IsValidAddress"); method->symbol = "is_valid_address"; nih_list_add (&interface->methods, &method->entry); argument = argument_new (method, "address", "u", NIH_DBUS_ARG_IN); argument->symbol = "address"; nih_list_add (&method->arguments, &argument->entry); signal = signal_new (interface, "Bounce"); signal->symbol = "bounce"; nih_list_add (&interface->signals, &signal->entry); argument = argument_new (signal, "height", "u", NIH_DBUS_ARG_OUT); argument->symbol = "height"; nih_list_add (&signal->arguments, &argument->entry); argument = argument_new (signal, "velocity", "i", NIH_DBUS_ARG_OUT); argument->symbol = "velocity"; nih_list_add (&signal->arguments, &argument->entry); signal = signal_new (interface, "Exploded"); signal->symbol = "exploded"; nih_list_add (&interface->signals, &signal->entry); property = property_new (interface, "colour", "s", NIH_DBUS_READWRITE); property->symbol = "colour"; nih_list_add (&interface->properties, &property->entry); property = property_new (interface, "size", "u", NIH_DBUS_READ); property->symbol = "size"; nih_list_add (&interface->properties, &property->entry); property = property_new (interface, "touch", "b", NIH_DBUS_WRITE); property->symbol = "touch"; nih_list_add (&interface->properties, &property->entry); interface = interface_new (node, "com.netsplit.Nih.Foo"); interface->symbol = "foo"; nih_list_add (&node->interfaces, &interface->entry); method = method_new (interface, "Bing"); method->symbol = "bing"; nih_list_add (&interface->methods, &method->entry); signal = signal_new (interface, "NewResult"); signal->symbol = "new_result"; nih_list_add (&interface->signals, &signal->entry); property = property_new (interface, "preferences", "(us)", NIH_DBUS_READWRITE); property->symbol = "preferences"; nih_list_add (&interface->properties, &property->entry); } ret = output ("test.c", fileno (source), "test.h", fileno (header), "my", node, FALSE); rewind (source); rewind (header); if (test_alloc_failed) { TEST_LT (ret, 0); err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); TEST_FILE_RESET (source); TEST_FILE_RESET (header); nih_free (node); continue; } TEST_EQ (ret, 0); TEST_EXPECTED_FILE (source, "test_output_proxy_standard.c"); TEST_EXPECTED_FILE (header, "test_output_proxy_standard.h"); nih_free (node); } /* Check that when there are no interfaces, a valid empty source * and header file are generated. */ TEST_FEATURE ("with proxy but no interfaces"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { node = node_new (NULL, NULL); } ret = output ("test.c", fileno (source), "test.h", fileno (header), "my", node, FALSE); rewind (source); rewind (header); if (test_alloc_failed) { TEST_LT (ret, 0); err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); TEST_FILE_RESET (source); TEST_FILE_RESET (header); nih_free (node); continue; } TEST_EQ (ret, 0); TEST_EXPECTED_FILE (source, "test_output_proxy_no_interfaces.c"); TEST_EXPECTED_FILE (header, "test_output_proxy_no_interfaces.h"); nih_free (node); } /* Check that we can generate a valid source file and accompanying * header file for a node in object mode. */ TEST_FEATURE ("with object"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { node = node_new (NULL, NULL); interface = interface_new (node, "com.netsplit.Nih.Test"); interface->symbol = "test"; nih_list_add (&node->interfaces, &interface->entry); method = method_new (interface, "Poke"); method->symbol = "poke"; nih_list_add (&interface->methods, &method->entry); argument = argument_new (method, "address", "u", NIH_DBUS_ARG_IN); argument->symbol = "address"; nih_list_add (&method->arguments, &argument->entry); argument = argument_new (method, "value", "s", NIH_DBUS_ARG_IN); argument->symbol = "value"; nih_list_add (&method->arguments, &argument->entry); method = method_new (interface, "Peek"); method->symbol = "peek"; method->async = TRUE; nih_list_add (&interface->methods, &method->entry); argument = argument_new (method, "address", "u", NIH_DBUS_ARG_IN); argument->symbol = "address"; nih_list_add (&method->arguments, &argument->entry); argument = argument_new (method, "value", "s", NIH_DBUS_ARG_OUT); argument->symbol = "value"; nih_list_add (&method->arguments, &argument->entry); method = method_new (interface, "IsValidAddress"); method->symbol = "is_valid_address"; nih_list_add (&interface->methods, &method->entry); argument = argument_new (method, "address", "u", NIH_DBUS_ARG_IN); argument->symbol = "address"; nih_list_add (&method->arguments, &argument->entry); argument = argument_new (method, "is_valid", "b", NIH_DBUS_ARG_OUT); argument->symbol = "is_valid"; nih_list_add (&method->arguments, &argument->entry); signal = signal_new (interface, "Bounce"); signal->symbol = "bounce"; nih_list_add (&interface->signals, &signal->entry); argument = argument_new (signal, "height", "u", NIH_DBUS_ARG_OUT); argument->symbol = "height"; nih_list_add (&signal->arguments, &argument->entry); argument = argument_new (signal, "velocity", "i", NIH_DBUS_ARG_OUT); argument->symbol = "velocity"; nih_list_add (&signal->arguments, &argument->entry); signal = signal_new (interface, "Exploded"); signal->symbol = "exploded"; nih_list_add (&interface->signals, &signal->entry); property = property_new (interface, "colour", "s", NIH_DBUS_READWRITE); property->symbol = "colour"; nih_list_add (&interface->properties, &property->entry); property = property_new (interface, "size", "u", NIH_DBUS_READ); property->symbol = "size"; nih_list_add (&interface->properties, &property->entry); property = property_new (interface, "touch", "b", NIH_DBUS_WRITE); property->symbol = "touch"; nih_list_add (&interface->properties, &property->entry); interface = interface_new (node, "com.netsplit.Nih.Foo"); interface->symbol = "foo"; nih_list_add (&node->interfaces, &interface->entry); method = method_new (interface, "Bing"); method->symbol = "bing"; nih_list_add (&interface->methods, &method->entry); signal = signal_new (interface, "NewResult"); signal->symbol = "new_result"; nih_list_add (&interface->signals, &signal->entry); property = property_new (interface, "preferences", "(us)", NIH_DBUS_READWRITE); property->symbol = "preferences"; nih_list_add (&interface->properties, &property->entry); } ret = output ("test.c", fileno (source), "test.h", fileno (header), "my", node, TRUE); rewind (source); rewind (header); if (test_alloc_failed) { TEST_LT (ret, 0); err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); TEST_FILE_RESET (source); TEST_FILE_RESET (header); nih_free (node); continue; } TEST_EQ (ret, 0); TEST_EXPECTED_FILE (source, "test_output_object_standard.c"); TEST_EXPECTED_FILE (header, "test_output_object_standard.h"); nih_free (node); } /* Check that when there are no interfaces, a valid empty source * and header file are generated. */ TEST_FEATURE ("with object but no interfaces"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { node = node_new (NULL, NULL); } ret = output ("test.c", fileno (source), "test.h", fileno (header), "my", node, TRUE); rewind (source); rewind (header); if (test_alloc_failed) { TEST_LT (ret, 0); err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); TEST_FILE_RESET (source); TEST_FILE_RESET (header); nih_free (node); continue; } TEST_EQ (ret, 0); TEST_EXPECTED_FILE (source, "test_output_object_no_interfaces.c"); TEST_EXPECTED_FILE (header, "test_output_object_no_interfaces.h"); nih_free (node); } fclose (source); fclose (header); }
int main (int argc, char *argv[]) { NihList prototypes; NihList typedefs; NihList structs; nih_local Interface *interface = NULL; nih_local Property * property = NULL; nih_local char * code = NULL; nih_local char * block = NULL; printf ("#include <dbus/dbus.h>\n" "\n" "#include <nih/macros.h>\n" "#include <nih/alloc.h>\n" "#include <nih/string.h>\n" "#include <nih/logging.h>\n" "#include <nih/error.h>\n" "\n" "#include <nih-dbus/dbus_error.h>\n" "#include <nih-dbus/dbus_message.h>\n" "#include <nih-dbus/dbus_object.h>\n" "#include <nih-dbus/dbus_pending_data.h>\n" "#include <nih-dbus/dbus_proxy.h>\n" "#include <nih-dbus/errors.h>\n" "\n" "#include \"tests/interface_code.h\"\n" "\n" "\n"); interface = interface_new (NULL, "com.netsplit.Nih.Test"); interface->symbol = NULL; property = property_new (interface, "name", "s", NIH_DBUS_READWRITE); property->symbol = nih_strdup (property, "name"); nih_list_add (&interface->properties, &property->entry); property = property_new (interface, "size", "u", NIH_DBUS_READWRITE); property->symbol = nih_strdup (property, "size"); nih_list_add (&interface->properties, &property->entry); nih_list_init (&prototypes); nih_list_init (&structs); interface->name = "com.netsplit.Nih.TestA"; code = interface_proxy_get_all_function (NULL, "my", interface, &prototypes, &structs); printf ("extern void my_com_netsplit_Nih_TestA_get_all_notify (DBusPendingCall *pending_call, " "NihDBusPendingData *pending_data);\n"); printf ("\n"); printf ("%s" "\n", code); nih_list_init (&prototypes); nih_list_init (&typedefs); nih_list_init (&structs); interface->name = "com.netsplit.Nih.Test"; code = interface_proxy_get_all_notify_function (NULL, "my", interface, &prototypes, &typedefs, &structs); printf ("%s", code); printf ("\n" "\n"); nih_list_init (&prototypes); nih_list_init (&structs); code = interface_proxy_get_all_sync_function (NULL, "my", interface, &prototypes, &structs); printf ("%s" "\n", code); return 0; }