⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gta.c

📁 Path MPICH-V for MPICH the MPI Implementation
💻 C
字号:
/*  MPICH-V2  Copyright (C) 2002, 2003 Groupe Cluster et Grid, LRI, Universite de Paris Sud  This file is part of MPICH-V2.  MPICH-V2 is free software; you can redistribute it and/or modify  it under the terms of the GNU General Public License as published by  the Free Software Foundation; either version 2 of the License, or  (at your option) any later version.  MPICH-V2 is distributed in the hope that it will be useful,  but WITHOUT ANY WARRANTY; without even the implied warranty of  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the  GNU General Public License for more details.  You should have received a copy of the GNU General Public License  along with MPICH-V2; if not, write to the Free Software  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA  $Id: gta.c,v 1.1.1.1 2004/01/30 15:49:38 lemarini Exp $*/#include <stdlib.h>#include <sys/types.h>#include <sys/socket.h>#include <stdio.h>#include <netinet/in.h>#include <arpa/inet.h>#include <string.h>#include "gta.h"#define TXTPART 60static void gta_reset(GLogger *_gta){  Gta *gta = GTA(_gta);  int i;  for(i = 0; i < gta->nbvalues; i++)    gta->values[i] = 0;  gettimeofday(&gta->lastto, NULL);  gta->rsl = 0;}static void gta_data(GLogger *_gta, msg *m){  Gta *gta = GTA(_gta);  gta->rsl += m->mlen;}static gboolean gta_tick(gpointer _gta){  int i;  int mv;  struct timeval tv;  Gta *gta = GTA(_gta);  mv = 0;  for(i = gta->nbvalues-1; i>0; i--)    {      gta->values[i] = gta->values[i-1];      if(gta->values[i] > mv)	mv = gta->values[i];    }  gettimeofday(&tv, NULL);  gta->values[0] = (int) ( ((double)gta->rsl) / 			   ((double)(tv.tv_sec  - gta->lastto.tv_sec ) + 			    (double)(tv.tv_usec - gta->lastto.tv_usec)/100000.0)			 );  memcpy(&gta->lastto, &tv ,sizeof(tv));  gta->rsl = 0;  if(mv < gta->values[0])    mv = gta->values[0];   gta->maxvalue = mv;  gtk_widget_queue_draw(gta->darea);  return TRUE;}static void gta_class_init(GtaClass *class){  GLOGGER_CLASS(class)->on_reset = gta_reset;  GLOGGER_CLASS(class)->on_data  = gta_data;}static gboolean gta_delete(GtkWindow *w, GdkEvent *e, gpointer null){  Gta *gta = GTA(gtk_object_get_user_data(GTK_OBJECT(w)));  gtk_object_destroy( GTK_OBJECT(gta) );  g_source_remove(gta->to);  return FALSE;}static void gta_destroy(GtkObject *o, gpointer *null){  Gta *gta = GTA(o);  gtk_signal_emit_by_name(o, "remove");  gtk_widget_destroy(gta->window);}static gboolean gta_expose (GtkWidget *widget, GdkEventExpose *event, Gta *gta){  static GdkFont* f;  char txt[64];  static int th;  int i;  if(f == NULL)    {      f = gdk_font_load("-bitstream-charter-medium-r-normal--12-120-75-75-p-0-iso8859-1");      if(f == NULL)	{	  fprintf(stderr, "unable to load fond\n");	  f = (GdkFont *)-1;	  th = 12;	}      else	th = gdk_text_height(f, "ly", 2);    }  gdk_window_clear_area (widget->window,                         event->area.x, event->area.y,                         event->area.width, event->area.height);  gdk_gc_set_clip_rectangle (widget->style->fg_gc[widget->state],                             &event->area);  gdk_draw_line(widget->window, widget->style->fg_gc[widget->state],		TXTPART, th, TXTPART, widget->allocation.height-2);    for(i = widget->allocation.height-2; i>=th; i-= 3*th)    {      if(f && (f != (GdkFont*)-1))	{	  sprintf(txt, "%d o/s",		  (int)(gta->maxvalue * (double)(widget->allocation.height-2-i)/			((double)(widget->allocation.height-2-th))));	  gdk_draw_string(widget->window, f, widget->style->fg_gc[widget->state],			  TXTPART-2-gdk_text_width(f, txt, strlen(txt)), 			  i, txt);	}      gdk_draw_line(widget->window, widget->style->fg_gc[widget->state],		    TXTPART-1, i, TXTPART+1, i);    }    if(gta->maxvalue == 0)    gdk_draw_line(widget->window, widget->style->fg_gc[widget->state],		  TXTPART+1, widget->allocation.height-2, 		  TXTPART+gta->nbvalues-1, widget->allocation.height-2);  else    for(i = 0; i < gta->nbvalues; i++)      {	gdk_draw_line(widget->window, widget->style->fg_gc[widget->state],		      TXTPART+gta->nbvalues-i, widget->allocation.height-2, 		      TXTPART+gta->nbvalues-i,		      widget->allocation.height-2 - 		      (int)(((double)(widget->allocation.height - 4 - th)) * 			    ((double)gta->values[i])/((double)gta->maxvalue))		      );      }    gdk_gc_set_clip_rectangle (widget->style->fg_gc[widget->state],                             NULL);  return TRUE;}static gboolean gta_configure(GtkWidget *widget, GdkEventConfigure *event, Gta *gta){  int i;  if(widget->allocation.width-TXTPART != gta->nbvalues)    {      gta->values = (unsigned int*)realloc(gta->values, 					   sizeof(unsigned int)*(widget->allocation.width-TXTPART));      for(i = gta->nbvalues; i<widget->allocation.width-TXTPART; i++)	gta->values[i] = 0;      gta->nbvalues = widget->allocation.width-TXTPART;    }  return TRUE;}static void gta_init(Gta *gta){  gta->window = gtk_window_new(GTK_WINDOW_TOPLEVEL);  gtk_window_set_title(GTK_WINDOW(gta->window), "Trafic Analyser");  gtk_widget_show(gta->window);  gta->darea = gtk_drawing_area_new();     gtk_drawing_area_size(GTK_DRAWING_AREA(gta->darea), TXTPART+10, 100);  gtk_container_add(GTK_CONTAINER(gta->window), gta->darea);  gtk_widget_show(gta->darea);  gtk_signal_connect(GTK_OBJECT(gta->darea), "configure_event",		     GTK_SIGNAL_FUNC(gta_configure), gta);  gtk_signal_connect(GTK_OBJECT(gta->darea), "expose_event",		     GTK_SIGNAL_FUNC(gta_expose), gta);  gta->to = g_timeout_add(1000, gta_tick, gta);  gtk_object_set_user_data( GTK_OBJECT(gta->window), gta);  gtk_signal_connect(GTK_OBJECT(gta->window), "delete_event",		     GTK_SIGNAL_FUNC(gta_delete), NULL);  gtk_signal_connect(GTK_OBJECT(gta), "destroy",		     GTK_SIGNAL_FUNC(gta_destroy), NULL);  gta->nbvalues = 0;  gta->values   = NULL;  gta->maxvalue = 0;  gta->rsl      = 0;  gettimeofday( &gta->lastto, NULL );}guint gta_get_type(void){  static guint gta_type = 0;       if (!gta_type)    {      GtkTypeInfo gta_info =      {        "Gta",        sizeof (Gta),        sizeof (GtaClass),        (GtkClassInitFunc) gta_class_init,        (GtkObjectInitFunc) gta_init,        (GtkArgSetFunc) NULL,        (GtkArgGetFunc) NULL      };             gta_type = gtk_type_unique (glogger_get_type (), &gta_info);    }     return gta_type;}GtkObject *gta_new(struct _GLogd *logd){  Gta *gta = GTA( gtk_object_newv (gta_get_type(), 0, NULL) );  GLOGGER(gta)->logd = logd;  return GTK_OBJECT(gta);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -