static void do_refresh (NAApplication *application) { struct timeval t; gettimeofday (&t, NULL); GList *proc_info = na_process_info_get_all (t); if (proc_info == NULL) return; GVariantBuilder *builder = g_variant_builder_new (G_VARIANT_TYPE_ARRAY); while (proc_info != NULL) { NAProcInfo *info = (NAProcInfo *)proc_info->data; g_variant_builder_add (builder, "(sidd)", info->name, info->pid, tokbps (info->recv), tokbps (info->sent)); proc_info = proc_info->next; } g_debug ("DBUS: Emitting signal on system bus"); g_dbus_connection_emit_signal (na_application_get_system_bus (application), NULL, NETWORK_ANALYZER_DBUS_OBJECT_PATH, NETWORK_ANALYZER_DBUS_IFACE, "UsageChanged", g_variant_new ("(a(sidd))", builder), NULL); g_variant_builder_unref (builder); }
/** Get the kb/s values for this process */ void getkbps (Process * curproc, float * recvd, float * sent) { u_int32_t sum_sent = 0, sum_recv = 0; /* walk though all this process's connections, and sum * them up */ ConnList * curconn = curproc->connections; ConnList * previous = NULL; while (curconn != NULL) { if (curconn->getVal()->getLastPacket() <= curtime.tv_sec - CONNTIMEOUT) { /* stalled connection, remove. */ ConnList * todelete = curconn; Connection * conn_todelete = curconn->getVal(); curconn = curconn->getNext(); if (todelete == curproc->connections) curproc->connections = curconn; if (previous != NULL) previous->setNext(curconn); delete (todelete); delete (conn_todelete); } else { u_int32_t sent = 0, recv = 0; curconn->getVal()->sumanddel(curtime, &recv, &sent); sum_sent += sent; sum_recv += recv; previous = curconn; curconn = curconn->getNext(); } } *recvd = tokbps(sum_recv); *sent = tokbps(sum_sent); }