CommunicationManager::CommunicationManager( QObject *parent, bool own_gobject ) : QGObject( G_OBJECT(inf_communication_manager_new()), parent, own_gobject ) { }
static void init_infinity (GeditCollaborationWindowHelper *helper) { InfGtkIo *io; InfCommunicationManager *communication_manager; InfXmppManager *xmpp_manager; InfCertificateCredentials *certificate_credentials; InfGtkBrowserModel *model_sort; io = inf_gtk_io_new (); communication_manager = inf_communication_manager_new (); xmpp_manager = inf_xmpp_manager_new (); certificate_credentials = inf_certificate_credentials_new (); helper->priv->io = INF_IO (io); helper->priv->certificate_credentials = certificate_credentials; helper->priv->browser_store = inf_gtk_browser_store_new (INF_IO (io), communication_manager); model_sort = INF_GTK_BROWSER_MODEL ( inf_gtk_browser_model_sort_new ( INF_GTK_BROWSER_MODEL (helper->priv->browser_store) ) ); gtk_tree_sortable_set_default_sort_func (GTK_TREE_SORTABLE (model_sort), compare_func, NULL, NULL); helper->priv->browser_view = inf_gtk_browser_view_new_with_model (model_sort); gtk_widget_show (helper->priv->browser_view); g_signal_connect_after (helper->priv->browser_store, "set-browser", G_CALLBACK (on_set_browser), helper); g_signal_connect (helper->priv->browser_view, "selection-changed", G_CALLBACK (on_selection_changed), helper); g_signal_connect (helper->priv->browser_view, "populate-popup", G_CALLBACK (on_populate_popup), helper); g_signal_connect (helper->priv->browser_view, "activate", G_CALLBACK (on_browser_activate), helper); #ifdef LIBINFINITY_HAVE_AVAHI init_infinity_discovery (helper, xmpp_manager); #endif init_bookmarks (helper); g_object_unref (communication_manager); g_object_unref (xmpp_manager); }
int main(int argc, char* argv[]) { InfTestBrowser test; InfIpAddress* address; InfCommunicationManager* manager; InfTcpConnection* tcp_conn; GError* error; gnutls_global_init(); g_type_init(); test.io = inf_standalone_io_new(); #ifndef G_OS_WIN32 test.input_fd = STDIN_FILENO; #endif address = inf_ip_address_new_loopback4(); error = NULL; tcp_conn = inf_tcp_connection_new_and_open(INF_IO(test.io), address, inf_protocol_get_default_port(), &error); inf_ip_address_free(address); if(tcp_conn == NULL) { fprintf(stderr, "Could not open TCP connection: %s\n", error->message); g_error_free(error); } else { test.conn = inf_xmpp_connection_new( tcp_conn, INF_XMPP_CONNECTION_CLIENT, NULL, "localhost", INF_XMPP_CONNECTION_SECURITY_BOTH_PREFER_TLS, NULL, NULL, NULL ); g_object_unref(G_OBJECT(tcp_conn)); manager = inf_communication_manager_new(); test.browser = INF_BROWSER( infc_browser_new( INF_IO(test.io), manager, INF_XML_CONNECTION(test.conn) ) ); g_signal_connect_after( G_OBJECT(test.browser), "notify::status", G_CALLBACK(inf_test_browser_notify_status_cb), &test ); g_signal_connect( G_OBJECT(test.browser), "error", G_CALLBACK(inf_test_browser_error_cb), &test ); inf_standalone_io_loop(test.io); g_object_unref(G_OBJECT(manager)); g_object_unref(G_OBJECT(test.browser)); /* TODO: Wait until the XMPP connection is in status closed */ g_object_unref(G_OBJECT(test.conn)); } g_object_unref(G_OBJECT(test.io)); return 0; }
static gboolean perform_test(guint max_total_log_size, InfTextChunk* initial, GSList* users, GSList* requests, GError** error) { InfTextBuffer* buffer; InfCommunicationManager* manager; InfIo* io; InfTextSession* session; InfAdoptedAlgorithm* algorithm; InfUserTable* user_table; InfTextUser* user; gchar* user_name; GSList* item; xmlNodePtr request; gboolean result; GError* local_error; guint verify_user_id; InfAdoptedUser* verify_user; guint verify_log_size; gint verify_can_undo; gint verify_can_redo; InfAdoptedRequestLog* log; guint log_size; buffer = INF_TEXT_BUFFER(inf_text_default_buffer_new("UTF-8")); inf_text_buffer_insert_chunk(buffer, 0, initial, NULL); manager = inf_communication_manager_new(); io = INF_IO(inf_standalone_io_new()); user_table = inf_user_table_new(); local_error = NULL; for(item = users; item != NULL; item = g_slist_next(item)) { user_name = g_strdup_printf("User_%u", GPOINTER_TO_UINT(item->data)); user = INF_TEXT_USER( g_object_new( INF_TEXT_TYPE_USER, "id", GPOINTER_TO_UINT(item->data), "name", user_name, "status", INF_USER_ACTIVE, "flags", 0, NULL ) ); g_free(user_name); inf_user_table_add_user(user_table, INF_USER(user)); g_object_unref(user); } session = INF_TEXT_SESSION( g_object_new( INF_TEXT_TYPE_SESSION, "communication-manager", manager, "buffer", buffer, "io", io, "user_table", user_table, "max-total-log-size", max_total_log_size, NULL ) ); algorithm = inf_adopted_session_get_algorithm(INF_ADOPTED_SESSION(session)); g_object_unref(io); g_object_unref(manager); g_object_unref(user_table); g_object_unref(buffer); for(item = requests; item != NULL; item = item->next) { request = (xmlNodePtr)item->data; if(strcmp((const char*)request->name, "request") == 0) { /* Request */ result = inf_communication_object_received( INF_COMMUNICATION_OBJECT(session), NULL, request, &local_error ); if(local_error != NULL) goto fail; } else { /* TODO: Make an extra function out of this: */ /* Verify */ result = inf_xml_util_get_attribute_uint_required( request, "user", &verify_user_id, &local_error ); if(result == FALSE) goto fail; verify_user = INF_ADOPTED_USER( inf_user_table_lookup_user_by_id(user_table, verify_user_id) ); if(verify_user == NULL) { g_set_error( error, inf_test_text_cleanup_error_quark(), INF_TEST_TEXT_CLEANUP_USER_UNAVAILABLE, "User ID '%u' not available", verify_user_id ); goto fail; } result = inf_xml_util_get_attribute_uint( request, "log-size", &verify_log_size, &local_error ); if(local_error) goto fail; if(result) { log = inf_adopted_user_get_request_log(INF_ADOPTED_USER(verify_user)); log_size = inf_adopted_request_log_get_end(log) - inf_adopted_request_log_get_begin(log); if(verify_log_size != log_size) { g_set_error( error, inf_test_text_cleanup_error_quark(), INF_TEST_TEXT_CLEANUP_VERIFY_FAILED, "Log size does not match; got %u, but expected %u", log_size, verify_log_size ); goto fail; } } result = inf_xml_util_get_attribute_int( request, "can-undo", &verify_can_undo, &local_error ); if(local_error) goto fail; if(result) { result = inf_adopted_algorithm_can_undo(algorithm, verify_user); if(result != verify_can_undo) { g_set_error( error, inf_test_text_cleanup_error_quark(), INF_TEST_TEXT_CLEANUP_VERIFY_FAILED, "can-undo does not match; got %d, but expected %d", (guint)result, verify_can_undo ); goto fail; } } result = inf_xml_util_get_attribute_int( request, "can-redo", &verify_can_redo, &local_error ); if(local_error) goto fail; if(result) { result = inf_adopted_algorithm_can_redo(algorithm, verify_user); if(result != verify_can_redo) { g_set_error( error, inf_test_text_cleanup_error_quark(), INF_TEST_TEXT_CLEANUP_VERIFY_FAILED, "can-redo does not match; got %d, but expected %d", (guint)result, verify_can_redo ); goto fail; } } } } g_object_unref(session); return TRUE; fail: g_object_unref(session); if(local_error) g_propagate_error(error, local_error); return FALSE; }
static void inf_test_mass_join_connect(InfTestMassJoin* massjoin, const char* hostname, guint port, const char* document, const char* username) { InfIpAddress* addr; InfTcpConnection* tcp; InfXmppConnection* xmpp; InfTestMassJoiner* joiner; InfXmlConnection* xml; GError* error; addr = inf_ip_address_new_from_string(hostname); tcp = inf_tcp_connection_new(massjoin->io, addr, port); xmpp = inf_xmpp_connection_new( tcp, INF_XMPP_CONNECTION_CLIENT, g_get_host_name(), hostname, INF_XMPP_CONNECTION_SECURITY_BOTH_PREFER_TLS, NULL, NULL, NULL ); joiner = g_slice_new(InfTestMassJoiner); joiner->communication_manager = inf_communication_manager_new(); joiner->browser = infc_browser_new( massjoin->io, joiner->communication_manager, INF_XML_CONNECTION(xmpp) ); joiner->session = NULL; joiner->document = g_strdup(document); joiner->username = g_strdup(username); g_object_unref(xmpp); g_object_unref(tcp); inf_ip_address_free(addr); massjoin->joiners = g_slist_prepend(massjoin->joiners, joiner); infc_browser_add_plugin(joiner->browser, &INF_TEST_MASS_JOIN_TEXT_PLUGIN); g_signal_connect( G_OBJECT(joiner->browser), "notify::status", G_CALLBACK(inf_test_mass_join_browser_notify_status_cb), massjoin ); error = NULL; xml = infc_browser_get_connection(joiner->browser); if(inf_xml_connection_open(xml, &error) == FALSE) { fprintf( stderr, "Joiner %s: Failed to connect to %s: %s\n", joiner->username, hostname, error->message ); g_error_free(error); massjoin->joiners = g_slist_remove(massjoin->joiners, joiner); if(massjoin->joiners == NULL) inf_standalone_io_loop_quit(INF_STANDALONE_IO(massjoin->io)); } }
GSList* item; xmlNodePtr request; gboolean result; InfTextChunk* test_chunk; gchar* first; gchar* second; gsize first_bytes; gsize second_bytes; GTimer* timer; buffer = INF_TEXT_BUFFER(inf_text_default_buffer_new("UTF-8")); inf_text_buffer_insert_chunk(buffer, 0, initial, NULL); manager = inf_communication_manager_new(); io = INF_IO(inf_standalone_io_new()); user_table = inf_user_table_new(); for(item = users; item != NULL; item = g_slist_next(item)) { user_name = g_strdup_printf("User_%u", GPOINTER_TO_UINT(item->data)); user = INF_TEXT_USER( g_object_new( INF_TEXT_TYPE_USER, "id", GPOINTER_TO_UINT(item->data), "name", user_name, "status", INF_USER_ACTIVE, "flags", 0, NULL