diff bfm-0.5.1/Makefile.BSD bfm-0.5.1-bsd/Makefile.BSD *** bfm-0.5.1/Makefile.BSD Thu Jan 1 09:00:00 1970 --- bfm-0.5.1-bsd/Makefile.BSD Sat Apr 10 17:47:54 2004 *************** *** 0 **** --- 1,60 ---- + # bubblemon configuration + EXTRA = -DENABLE_DUCK + EXTRA += -DENABLE_CPU + EXTRA += -DENABLE_MEMSCREEN + EXTRA += -DUPSIDE_DOWN_DUCK + EXTRA += -DENABLE_FISH + EXTRA += -DENABLE_TIME + + EXTRA += $(WMAN) + + # no user serviceable parts below + CC = gcc + + # optimization cflags + CFLAGS = -fPIC -I/usr/local/include -O3 -ansi -Wall `pkg-config gtk+-2.0 --cflags` ${EXTRA} + # profiling cflags + # CFLAGS = -ansi -Wall -pg -O3 `gtk-config --cflags` ${EXTRA} -DPRO + # test coverage cflags + # CFLAGS = -fprofile-arcs -ftest-coverage -Wall -ansi -g `gtk-config --cflags` ${EXTRA} -DPRO + + SRCS = fishmon.c bubblemon.c sys_bsd.c + OBJS = fishmon.o bubblemon.o sys_bsd.o + BUBBLEFISHYMON = bubblefishymon + + # Some stuffs for building gkrellm-bfm + GKRELLM_SRCS = gkrellm-bfm.c + GKRELLM_OBJS = gkrellm-bfm.o + GKRELLM_BFM = gkrellm-bfm.so + LDFLAGS = -shared + + STRIP = strip + + LIBS = `pkg-config gtk+-2.0 --libs` + PREFIX = /usr/X11R6 + VPATH = include + + all: bubblefishymon + + bubblefishymon: ${OBJS} + gcc ${CFLAGS} -o bubblefishymon ${OBJS} ${LIBS} + + clean: + rm -f bubblefishymon bubblemon.o *.o *.bb* *.gcov gmon.* *.da winglue.c bubblemon32 *.so win32.spec *~ *.gmon *.s *.core + + install: + install -c bubblefishymon ${PREFIX}/bin + + gkrellm: clean_obj + $(CC) -DGKRELLM_BFM $(CFLAGS) -c $(SRCS) $(GKRELLM_SRCS) + $(CC) $(LDFLAGS) -o $(GKRELLM_BFM) $(OBJS) $(GKRELLM_OBJS) + $(STRIP) $(GKRELLM_BFM) + + clean_obj: + rm -rf *.o + + + bubblemon.o: bubblemon.h ducks.h master.xpm sys_include.h digits.h \ + load_screen.h mem_screen.h + + sys_openbsd.o: bubblemon.h diff bfm-0.5.1/bubblemon.c bfm-0.5.1-bsd/bubblemon.c *** bfm-0.5.1/bubblemon.c Sat Dec 1 23:19:26 2001 --- bfm-0.5.1-bsd/bubblemon.c Sat Apr 10 17:46:12 2004 *************** *** 145,153 **** static void duck_set(int x, int y, int nr, int rev, int upsidedown); static void duck_swimmer(int posy); #endif - #ifdef __FreeBSD__ - extern int init_stuff(); /* defined in sys_freebsd.c */ - #endif /* local prototypes end *INDENT-ON* */ /* global variables */ --- 145,150 ---- *************** *** 500,510 **** /* zero data structure */ memset(&bm, 0, sizeof(bm)); - #ifdef __FreeBSD__ - if (init_stuff()) - exit(-1); - #endif - /* set default things, from Xresources or compiled-in defaults */ bubblemon_session_defaults(); --- 497,502 ---- *************** *** 688,695 **** attr.width = 64; attr.height = 64; ! // Pigeon ! // attr.title = "bubblemon"; attr.title = "bubblefishymon"; attr.event_mask = MASK; attr.wclass = GDK_INPUT_OUTPUT; --- 680,687 ---- attr.width = 64; attr.height = 64; ! /* Pigeon ! attr.title = "bubblemon"; */ attr.title = "bubblefishymon"; attr.event_mask = MASK; attr.wclass = GDK_INPUT_OUTPUT; *************** *** 764,771 **** #undef MASK } /* make_new_bubblemon_dockapp */ ! // Pigeon ! // Dirty, I moved these here so that I can use it somewhere else unsigned int real_waterlevel_min, real_waterlevel_max; /* --- 756,763 ---- #undef MASK } /* make_new_bubblemon_dockapp */ ! /* Pigeon ! Dirty, I moved these here so that I can use it somewhere else */ unsigned int real_waterlevel_min, real_waterlevel_max; /* diff bfm-0.5.1/fishmon.c bfm-0.5.1-bsd/fishmon.c *** bfm-0.5.1/fishmon.c Tue Nov 27 20:11:09 2001 --- bfm-0.5.1-bsd/fishmon.c Thu Apr 8 23:30:42 2004 *************** *** 283,290 **** bm.fishes[i].y++; } ! // Pigeon ! // Make sure the fish is in the water :) min_y = real_waterlevel_max + 3; if(bm.fishes[i].y <= min_y) --- 283,290 ---- bm.fishes[i].y++; } ! /* Pigeon ! Make sure the fish is in the water :) */ min_y = real_waterlevel_max + 3; if(bm.fishes[i].y <= min_y) *************** *** 620,626 **** for (i = 0; i < NRFISH; i++) { ! // No traffic, do nothing if (bm.fishes[i].speed == 0 && rx_speed == 0 && tx_speed == 0) { continue; --- 620,626 ---- for (i = 0; i < NRFISH; i++) { ! /* No traffic, do nothing */ if (bm.fishes[i].speed == 0 && rx_speed == 0 && tx_speed == 0) { continue; *************** *** 628,639 **** if(i < (NRFISH / 2)) { ! // tx traffic if(bm.fishes[i].tx < XMAX) { if(bm.fishes[i].speed < tx_speed) { ! // Slowly accelerate bm.fishes[i].speed += 1; } --- 628,639 ---- if(i < (NRFISH / 2)) { ! /* tx traffic */ if(bm.fishes[i].tx < XMAX) { if(bm.fishes[i].speed < tx_speed) { ! /* Slowly accelerate */ bm.fishes[i].speed += 1; } *************** *** 641,652 **** } else { ! // Done once, go back bm.fishes[i].tx = -18 - rand() % XMAX; bm.fishes[i].y = (rand() % (YMAX - 14)); if(tx_speed == 0) { ! // Stop the fish when it's at the end... bm.fishes[i].speed = 0; } else --- 641,652 ---- } else { ! /* Done once, go back */ bm.fishes[i].tx = -18 - rand() % XMAX; bm.fishes[i].y = (rand() % (YMAX - 14)); if(tx_speed == 0) { ! /* Stop the fish when it's at the end... */ bm.fishes[i].speed = 0; } else *************** *** 657,668 **** } else { ! // rx traffic if(bm.fishes[i].tx > -18) { if(bm.fishes[i].speed < rx_speed) { ! // Slowly accelerate bm.fishes[i].speed += 1; } bm.fishes[i].tx -= bm.fishes[i].speed; --- 657,668 ---- } else { ! /* rx traffic */ if(bm.fishes[i].tx > -18) { if(bm.fishes[i].speed < rx_speed) { ! /* Slowly accelerate */ bm.fishes[i].speed += 1; } bm.fishes[i].tx -= bm.fishes[i].speed; *************** *** 669,680 **** } else { ! // Done once, go back bm.fishes[i].tx = XMAX + rand() % XMAX; bm.fishes[i].y = (rand() % (YMAX - 14)); if(rx_speed == 0) { ! // Stop the fish when it's at the end... bm.fishes[i].speed = 0; } else --- 669,680 ---- } else { ! /* Done once, go back */ bm.fishes[i].tx = XMAX + rand() % XMAX; bm.fishes[i].y = (rand() % (YMAX - 14)); if(rx_speed == 0) { ! /* Stop the fish when it's at the end... */ bm.fishes[i].speed = 0; } else *************** *** 696,703 **** bm.fishes[i].y++; } ! // Pigeon ! // Make sure the fish is in the water :) min_y = real_waterlevel_max + 3; if(bm.fishes[i].y <= min_y) --- 696,703 ---- bm.fishes[i].y++; } ! /* Pigeon ! Make sure the fish is in the water :) */ min_y = real_waterlevel_max + 3; if(bm.fishes[i].y <= min_y) *************** *** 784,790 **** mdy = floor(-cos(psi) * 22 * 0.7) + 24; /* reflash the backbuffer / date / weekday */ ! // prepare_backbuffer(0); } } --- 784,790 ---- mdy = floor(-cos(psi) * 22 * 0.7) + 24; /* reflash the backbuffer / date / weekday */ ! /* prepare_backbuffer(0); */ } } diff bfm-0.5.1/include/bubblemon.h bfm-0.5.1-bsd/include/bubblemon.h *** bfm-0.5.1/include/bubblemon.h Thu Jul 12 21:07:53 2001 --- bfm-0.5.1-bsd/include/bubblemon.h Thu Apr 8 23:30:42 2004 *************** *** 52,58 **** #endif /* defined (uint64_t) */ #endif ! // Pigeon /* Don't need this for this hack typedef struct { int x; Horizontal coordinate --- 52,58 ---- #endif /* defined (uint64_t) */ #endif ! /* Pigeon */ /* Don't need this for this hack typedef struct { int x; Horizontal coordinate diff bfm-0.5.1/sys_bsd.c bfm-0.5.1-bsd/sys_bsd.c *** bfm-0.5.1/sys_bsd.c Thu Jan 1 09:00:00 1970 --- bfm-0.5.1-bsd/sys_bsd.c Sat Apr 10 18:18:40 2004 *************** *** 0 **** --- 1,311 ---- + /* BubbleMon dockapp 1.2 - FreeBSD specific code + * Copyright (C) 2004, Iwata + * Copyright (C) 2001, oleg dashevskii + * + * This program 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. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Street #330, Boston, MA 02111-1307, USA. + * + */ + + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #ifndef __FreeBSD__ + #include + #endif + #ifdef __FreeBSD__ + #include + #endif + #include + #include "include/bubblemon.h" + #include "include/sys_include.h" + + extern BubbleMonData bm; + /* Returns the current CPU load in percent */ + int system_cpu(void) + { + int loadPercentage; + int previous_total, previous_load; + int total, load; + unsigned long int cpu_time[CPUSTATES]; + int i; + int len = sizeof(cpu_time); + #ifdef __FreeBSD__ + if (sysctlbyname("kern.cp_time", &cpu_time, &len, NULL, 0) < 0) + return 0; + #else + int mib[2] = { CTL_KERN, KERN_CPTIME }; + + if (sysctl(mib, 2, &cpu_time, &len, NULL, 0) < 0) + return 0; + #endif + + load = cpu_time[CP_USER] + cpu_time[CP_SYS] + cpu_time[CP_NICE]; + total = load + cpu_time[CP_IDLE]; + + i = bm.loadIndex; + previous_load = bm.load[i]; + previous_total = bm.total[i]; + + bm.load[i] = load; + bm.total[i] = total; + bm.loadIndex = (i + 1) % bm.samples; + + if (previous_total == 0) + loadPercentage = 0; /* first time here */ + else + if (total == previous_total) + loadPercentage = 100; + else + loadPercentage = (100 * (load - previous_load)) / + (total - previous_total); + + return loadPercentage; + } + + int system_memory(void) + { + int mib[2]; + int len; + struct vmtotal vmtotal; + #ifndef __FreeBSD__ + struct uvmexp uvmexp; + + mib[0] = CTL_VM; + mib[1] = VM_UVMEXP; + len = sizeof(uvmexp); + if (sysctl(mib, 2, &uvmexp, &len, NULL, 0) < 0) + return 0; + #endif + + mib[0] = CTL_VM; + mib[1] = VM_METER; + len = sizeof(vmtotal); + if (sysctl(mib, 2, &vmtotal, &len, NULL, 0) < 0) + return 0; + + #ifndef __FreeBSD__ + #define pgtok(a) ((a) * ((int)uvmexp.pagesize >> 10)) + if (uvmexp.swpages < uvmexp.swpginuse) + return 0; + #endif + bm.mem_used = pgtok(vmtotal.t_avm); + bm.mem_max = pgtok(vmtotal.t_avm + vmtotal.t_free); + #ifndef __FreeBSD__ + bm.swap_used = pgtok(uvmexp.swpginuse); + bm.swap_max = pgtok(uvmexp.swpages); + #else + /* disabled */ + bm.swap_used = 0; + bm.swap_max = 1; + #endif + return 1; + } + + #ifdef ENABLE_MEMSCREEN + void system_loadavg(void) + { + static int avg_delay; + + if (avg_delay-- <= 0) { + struct loadavg loadinfo; + int i, mib[2]; + size_t size; + + mib[0] = CTL_VM; + mib[1] = VM_LOADAVG; + size = sizeof (loadinfo); + + if (sysctl(mib, 2, &loadinfo, &size, NULL, 0) >= 0) + for (i = 0; i < 3; i++) { + bm.loadavg[i].i = loadinfo.ldavg[i] / loadinfo.fscale; + bm.loadavg[i].f = ((loadinfo.ldavg[i] * 100 + + loadinfo.fscale / 2) / loadinfo.fscale) % 100; + } + + avg_delay = ROLLVALUE; + } + } + #endif /* ENABLE_MEMSCREEN */ + + #ifdef ENABLE_FISH + + /* from sys_linux.c */ + + #include + #include + #include + #include + + #define FISH_MAX_SPEED 8 + #define DIFF_MIN 10 + + /* The actual speed for the fish... */ + int tx_speed; + int rx_speed; + + u_int64_t tx_amount; + u_int64_t rx_amount; + + /* Store the last one to compare */ + u_int64_t last_tx_amount; + u_int64_t last_rx_amount; + + /* Store the max for scaling, too. */ + u_int64_t max_tx_diff = DIFF_MIN; + u_int64_t max_rx_diff = DIFF_MIN; + + + /* The cnt for scaling */ + int tx_cnt; + int rx_cnt; + int delay; + + extern int fish_traffic; + void get_traffic(void); + + int net_tx_speed(void) + { + get_traffic(); + return tx_speed; + } + + + int net_rx_speed(void) + { + get_traffic(); + return rx_speed; + } + + + void get_traffic(void) + { + struct ifaddrs *ifap, *ifa; + struct if_data *ifd; + u_int64_t diff; + + /* Have some delay in updating/sampling traffic... */ + if(delay++ < 5) { + return; + } + else { + delay = 0; + } + + if (getifaddrs(&ifap) < 0) + return; + + rx_amount = tx_amount = 0; + for (ifa = ifap; ifa; ifa = ifa->ifa_next) { + if (ifa->ifa_flags & IFF_UP) { + if (ifa->ifa_addr->sa_family != AF_LINK) + continue; + ifd = (struct if_data *)ifa->ifa_data; + /* ignore case */ + if (strncmp(ifa->ifa_name, "lo", 2) && + strncmp(ifa->ifa_name, "pflog", 5)) { + rx_amount += ifd->ifi_ibytes; + tx_amount += ifd->ifi_obytes; + } + } + } + freeifaddrs(ifap); + + /* Incoming traffic */ + if (rx_amount != last_rx_amount) { + if (last_rx_amount == 0) { + last_rx_amount = rx_amount; + } + diff = rx_amount - last_rx_amount; + last_rx_amount = rx_amount; + rx_speed = FISH_MAX_SPEED * diff / max_rx_diff; + if(rx_speed == 0) { + /* + At least, make it move a bit, cos we know there's + traffic + */ + rx_speed = 1; + } + /* + Do something to max rate, to do proper (hopefully) + scaling + */ + if (max_rx_diff < diff) { + max_rx_diff = diff; + } + else { + /* Slowly lower the scale */ + if(++rx_cnt > 5) { + max_rx_diff = diff; + if (max_rx_diff < DIFF_MIN) { + /* And don't scale it too low */ + max_rx_diff = DIFF_MIN; + } + rx_cnt = 0; + } + } + } + else + { + rx_speed = 0; + } + /* Outgoing traffic */ + if (tx_amount != last_tx_amount) { + if (last_tx_amount == 0) { + last_tx_amount = tx_amount; + } + diff = tx_amount - last_tx_amount; + last_tx_amount = tx_amount; + tx_speed= FISH_MAX_SPEED * diff / max_tx_diff; + if (tx_speed == 0) { + /* + At least, make it move a bit, cos we know there's + traffic + */ + tx_speed = 1; + } + + /* + Do something to max rate, to do proper (hopefully) + scaling + */ + if (max_tx_diff < diff) { + max_tx_diff = diff; + } + else { + /* Slowly lower the scale */ + if (++tx_cnt > 5) { + max_tx_diff = diff; + if (max_tx_diff < DIFF_MIN) { + /* And don't scale it too low */ + max_tx_diff = DIFF_MIN; + } + tx_cnt = 0; + } + } + } + else { + tx_speed = 0; + } + } + #endif /* ENABLE_FISH */ + + /* ex:set ts=8: */