Skip to content

Commit

Permalink
Put the status bar in its own seperate file.
Browse files Browse the repository at this point in the history
git-svn-id: https://subversion.cs.uiuc.edu/svn/bang/eoh2009@70 69d76c3e-0761-0410-948c-9895a8bb34fc
  • Loading branch information
nbysani2 committed Jan 27, 2009
1 parent 0fe9820 commit 9cc71ae
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 80 deletions.
6 changes: 4 additions & 2 deletions Makefile
Expand Up @@ -31,10 +31,12 @@ LSRC=src/base/bang-com$(SRCEXT) \
src/base/bang-routing$(SRCEXT)

AOBJS=preferences$(OBJEXT) \
main$(OBJEXT)
main$(OBJEXT) \
statusbar$(OBJEXT)

ASRC=src/app/preferences$(SRCEXT) \
src/app/main$(SRCEXT)
src/app/main$(SRCEXT) \
src/app/statusbar$(SRCEXT)

LIBRARIES=libbang.so $(MODULES)
MODULES=test-module.so matrix-mult-module.so
Expand Down
80 changes: 2 additions & 78 deletions src/app/main.c
Expand Up @@ -42,6 +42,7 @@
*/
#include"../base/bang.h"
#include"preferences.h"
#include"statusbar.h"
#include<stdio.h>
#include<stdlib.h>
#include<glib.h>
Expand All @@ -54,7 +55,6 @@ static GtkWidget *window;
static GtkWidget *vbox;
static GtkWidget *notebook;
static GtkWidget *peers_page_label;
static GtkWidget *statusbar;

static GtkWidget *menubar;

Expand All @@ -74,75 +74,6 @@ static GtkWidget *peers_item;
static GtkWidget *peersmenu;
static GtkWidget *connect_peer;

/**
* \param signal The signal from the BANG library.
* \param num_args The number of arguements of the signal
* \param args Different depending on what signal this function caught.
*
* \brief Updates the statusbar depending on what signals it catches.
*/
static void server_status(int signal, int num_args, void **args) {

gdk_threads_enter();
if (statusbar == NULL) {
gdk_threads_leave();
return;
}

guint context_id = gtk_statusbar_get_context_id(GTK_STATUSBAR(statusbar),"server_status");
gtk_statusbar_pop(GTK_STATUSBAR(statusbar),context_id);
if (signal == BANG_BIND_SUC) {
gtk_statusbar_push(GTK_STATUSBAR(statusbar),context_id,"!bang Machine has been bound.");
} else if (signal == BANG_BIND_FAIL){
gtk_statusbar_push(GTK_STATUSBAR(statusbar),context_id,"!bang Machine could not bind.");
gtk_widget_set_sensitive(ssserver,TRUE);
gtk_label_set_text(GTK_LABEL(gtk_bin_get_child(GTK_BIN(ssserver))),"Start Server");
} else if (signal == BANG_SERVER_STARTED) {
gtk_widget_set_sensitive(ssserver,TRUE);
gtk_label_set_text(GTK_LABEL(gtk_bin_get_child(GTK_BIN(ssserver))),"Stop Server");
gtk_statusbar_push(GTK_STATUSBAR(statusbar),context_id,"!bang Machine server started.");
} else {
gtk_widget_set_sensitive(ssserver,TRUE);
gtk_label_set_text(GTK_LABEL(gtk_bin_get_child(GTK_BIN(ssserver))),"Start Server");
gtk_statusbar_push(GTK_STATUSBAR(statusbar),context_id,"!bang Machine server stopped.");
}
/* It's recommended to flush before calling the leave function. */
gdk_flush();
gdk_threads_leave();

int i = 0;
for (i = 0; i < num_args; ++i) {
free(args[i]);
}
free(args);
}

/* bang callback, gtk needs to be locked */
static void client_con(int signal, int num_args, void **args) {

gdk_threads_enter();
if (statusbar == NULL) {
gdk_threads_leave();
return;
}

guint context_id = gtk_statusbar_get_context_id(GTK_STATUSBAR(statusbar),"peer_status");
gtk_statusbar_pop(GTK_STATUSBAR(statusbar),context_id);
if (signal == BANG_PEER_ADDED) {
gtk_statusbar_push(GTK_STATUSBAR(statusbar),context_id,"A peer has been added.");
} else {
gtk_statusbar_push(GTK_STATUSBAR(statusbar),context_id,"A peer has been removed.");
}
gdk_flush();
gdk_threads_leave();

int i = 0;
for (i = 0; i < num_args; ++i) {
free(args[i]);
}
free(args);
}

/**
* \param module The module to register.
*
Expand Down Expand Up @@ -213,12 +144,6 @@ static void destroy() {
int main(int argc, char **argv) {
/* Set up our library. */
BANG_init(&argc,argv);
BANG_install_sighandler(BANG_BIND_SUC,&server_status);
BANG_install_sighandler(BANG_BIND_FAIL,&server_status);
BANG_install_sighandler(BANG_SERVER_STARTED,&server_status);
BANG_install_sighandler(BANG_SERVER_STOPPED,&server_status);
BANG_install_sighandler(BANG_PEER_ADDED,&client_con);
BANG_install_sighandler(BANG_PEER_REMOVED,&client_con);

/* Note: gtk expects that as a process, you do not need to free its memory
So, it lets the operating system free all memory when the process closes. */
Expand All @@ -243,8 +168,7 @@ int main(int argc, char **argv) {
gtk_notebook_set_show_tabs(GTK_NOTEBOOK(notebook),TRUE);
gtk_notebook_set_scrollable(GTK_NOTEBOOK(notebook),TRUE);

/* Set up the statusbar */
statusbar = gtk_statusbar_new();
GtkWidget *statusbar = BMACHINE_setup_status_bar();

/* Set up the menubar */
menubar = gtk_menu_bar_new();
Expand Down

0 comments on commit 9cc71ae

Please sign in to comment.