PseudoTcpChannel *
pseudo_tcp_channel_new(int unreliable_socket,
                       int conn_id)
{
	PseudoTcpChannel *tcp = (PseudoTcpChannel *) malloc(sizeof(PseudoTcpChannel));
	memset(tcp, 0, sizeof(PseudoTcpChannel));
	
	if(socketpair(AF_UNIX, SOCK_STREAM, AF_UNSPEC, tcp->reliable_sockets) != 0) {
		free(tcp);
		return NULL;
	}

	PseudoTcpCallbacks callbacks;
	callbacks.user_data = tcp;
	callbacks.PseudoTcpOpened = opened;
	callbacks.PseudoTcpReadable = readable;
	callbacks.PseudoTcpWritable = writable;
	callbacks.PseudoTcpClosed = closed;
	callbacks.PseudoTcpWriteResult = needs_write;
	tcp->pseudo_tcp = pseudo_tcp_socket_new(conn_id, &callbacks);

	pseudo_tcp_socket_notify_mtu(tcp->pseudo_tcp, 1400);

	tcp->on_connected = signal_new();
	tcp->on_data_received = signal_new();
	tcp->on_closed = signal_new();

	return tcp;
}
void
signal_monitor_append_signal_path (SignalMonitor *m,
                                   SignalName     signal,
                                   GtkTreePath   *path)
{
  Signal *s;

  s = signal_new (signal, path);
  g_queue_push_head (m->queue, s);
}
static Signal *
signal_new_with_order (SignalName signal, GtkTreePath *path,
                       int *new_order, int len)
{
  Signal *s = signal_new (signal, path);

  s->new_order = new_order;
  s->len = len;

  return s;
}
Example #4
0
void
config_add_signal (struct config *config, int signal)
{
    struct signal **p = &config->signals;
    while (*p) {
	if ((*p)->signal == signal) {
	    return;
	}
	p = &((*p)->next);
    }

    *p = signal_new (config, signal);
}
Example #5
0
my_string_t* my_string_new(void)
{
	my_string_t* obj = (my_string_t *)calloc(1, sizeof(my_string_t));
	MEMORY_ALLOC_CHECK_RETURN(obj, NULL);

	obj->str_data = (char*)calloc(1, sizeof(char));
	obj->str_len = 0;
	obj->mem_size = 1;

	obj->update_signal = signal_new();

	return obj;
}
void
signal_monitor_append_signal (SignalMonitor *m,
                              SignalName     signal,
                              const gchar   *path_string)
{
  Signal *s;
  GtkTreePath *path;

  path = gtk_tree_path_new_from_string (path_string);

  s = signal_new (signal, path);
  g_queue_push_head (m->queue, s);

  gtk_tree_path_free (path);
}
Example #7
0
void
unique_lib_setup(lua_State *L)
{
    static const struct luaL_reg unique_lib[] =
    {
        LUA_CLASS_METHODS(unique)
        { "new", luaH_unique_new },
        { "send_message", luaH_unique_send_message },
        { "is_running", luaH_unique_is_running },
        { NULL, NULL }
    };

    /* create signals array */
    unique_class.signals = signal_new();

    /* export unique lib */
    luaH_openlib(L, "unique", unique_lib, unique_lib);
}
Example #8
0
void
init_lua(gchar **uris)
{
    gchar *uri;
    lua_State *L;

    /* init globalconf structs */
    globalconf.signals = signal_new();
    globalconf.windows = g_ptr_array_new();

    /* init lua */
    luaH_init();
    L = globalconf.L;

    /* push a table of the statup uris */
    lua_newtable(L);
    for (gint i = 0; uris && (uri = uris[i]); i++) {
        lua_pushstring(L, uri);
        lua_rawseti(L, -2, i + 1);
    }
    lua_setglobal(L, "uris");
}
Example #9
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);
}
Example #10
0
static GuiWidget *create_widget_list(GuiWidget *parent_widget, xmlNodePtr root)
{
	GuiWidget *widget = NULL, *first_widget = NULL;

	xmlNodePtr cur = XML_GET_CHILD(root);
	while(cur != NULL) {
		if ( xmlStrcmp(cur->name, WIDGET_STR) == 0 ) {
			xmlChar *widget_name  = xmlGetProp(cur, NAME_STR );
			xmlChar *classid      = xmlGetProp(cur, CLASS_STR);
			xmlChar *widget_style = xmlGetProp(cur, STYLE_STR);
//			printf("XmlParser: widget_name=%s\n",(char *)widget_name);

			widget = widget_new_child(parent_widget, (char *)widget_name, (char *)classid, (char *)widget_style);
			if (widget_name)  xmlFree(widget_name);
			if (classid)      xmlFree(classid);
			if (widget_style) xmlFree(widget_style);

			if (widget == NULL) goto next;
			if (first_widget == NULL) first_widget = widget;

			xmlNodePtr node = XML_GET_CHILD(cur);
			while (node != NULL) {
				if ( xmlStrcmp(node->name, PROPERTY_STR) == 0 ) {
					xmlChar *key   = xmlGetProp(node, NAME_STR);
					xmlChar *value = xmlGetProp(node, VALUE_STR);//xmlNodeGetContent(node);
					if (xmlStrcmp(key, (xmlChar*)"tabstop") == 0)
						widget->tabstop= atoidef((char *)value, 1);
					else
						widget_set_property(widget, (char *)key, (char *)value);
					if (key)   xmlFree(key);
					if (value) xmlFree(value);
				}
				else if (xmlStrcmp(node->name, SIGNAL_STR) == 0 ) {
					xmlChar *name    = xmlGetProp(node, NAME_STR);
					xmlChar *handler = xmlGetProp(node, HANDLER_STR);
					signal_new(widget, (char *)name, (char *)handler);
					if (name)    xmlFree(name);
					if (handler) xmlFree(handler);
				}
				else if (xmlStrcmp(node->name, CHILDREN_STR) == 0 )
					create_widget_list(widget, node);
				node = node->next;
			}
		}
		else if ( xmlStrcmp(cur->name, FILES_STR) == 0 ) {
			int i=0;

			gui->search_num = 0;

			xmlNodePtr node = XML_GET_CHILD(cur);
			while (node != NULL) {
				if (xmlStrcmp(node->name, SEARCH_STR) == 0)
					gui->search_num++;
				node = node->next;
			}

			gui->search_path = (char **)malloc(sizeof(char*) *gui->search_num + 1);
			node = XML_GET_CHILD(cur);
			while (node != NULL) {
				if (xmlStrcmp(node->name, SEARCH_STR) == 0)
					gui->search_path[i++] = strdup( (char *)xmlGetProp(node, PATH_STR) );
				node = node->next;
			}
			gui->search_path[i] = NULL;

			node = XML_GET_CHILD(cur);
			while (node != NULL) {
				if (xmlStrcmp(node->name, FONT_STR) == 0) {
					xmlChar *font_name = xmlGetProp(node, NAME_STR);
					xmlChar *file_name = xmlGetProp(node, FILE_STR);
					if (file_name && font_name)
						create_fontdesc((char *)font_name, (char *)file_name);
					if (file_name) xmlFree(file_name);
					if (font_name) xmlFree(font_name);
				}
				else if (xmlStrcmp(node->name, IMAGE_STR) == 0) {
					xmlChar *image_name = xmlGetProp(node, NAME_STR);
					xmlChar* file_name  = xmlGetProp(node, FILE_STR);
					if (file_name && image_name)
						create_imagedesc((char *)image_name, (char *)file_name);
					if (file_name)  xmlFree(file_name);
					if (image_name) xmlFree(image_name);
				}
				node = node->next;
			}
		}
		else if ( xmlStrcmp(cur->name, I18N_STR) == 0 ) {
			xmlNodePtr node = XML_GET_CHILD(cur);
			while (node != NULL) {
				GuiI18n *i18n;
				if (xmlStrcmp(node->name, LANGUAGE_STR) == 0) {
					xmlChar *language = xmlGetProp(node, NAME_STR);
					if (language) {
						i18n = i18n_add_language((char *)language);
						xmlFree(language);
						if (i18n) {
							xmlNodePtr text_node = XML_GET_CHILD(node);
							while (text_node != NULL) {
								if (xmlStrcmp(text_node->name, TRAN_STR) == 0) {
									xmlChar *key   = xmlGetProp(text_node, ID_STR);
									xmlChar *value = xmlNodeGetContent(text_node);
									i18n_add_tran(i18n, (char *)key, (char *)value);
									if (key)   xmlFree(key);
									if (value) xmlFree(value);
								}
								text_node = text_node->next;
							}
						}
					}
				}
				node = node->next;
			}
		}
		else if ( xmlStrcmp(cur->name, THEMES_STR) == 0) {
			xmlNodePtr node = XML_GET_CHILD(cur);
			while (node != NULL) {
				if (xmlStrcmp(node->name, THEME_STR) == 0) {
					Theme *theme = (Theme *)malloc(sizeof(Theme));
					if (theme == NULL) {
						printf("memory out\n");
						node = node->next;
						continue;
					}
					char *filename = (char *)xmlGetProp(node, FILE_STR);
					if (file_exists(filename) == -1) {
						char *oldfile = filename;
						filename = gui_search_file(filename);
						free(oldfile);
					}

					if (filename) {
						xmlChar *theme_name = xmlGetProp(node, NAME_STR);
						if (theme_load(theme, filename) == 0) {
							if (gui->current_theme == NULL)
								gui->current_theme = theme;
							hash_add(gui->theme_hash, (char *)theme_name, theme);
						}
						xmlFree(theme_name);
						free(filename);
					}
				}
				node = node->next;
			}
		}
next:
		cur = cur->next;
	}

	return first_widget;
}