/Users/craigcornelius/Projects/SPRING Mac Release 0.2/geometryreplicator.cpp

Go to the documentation of this file.
00001 #include "geometryreplicator.h"
00002 #include "glui.h"
00003 
00004 #include <iostream>
00005 
00006 using namespace std;
00007 
00008 int GeometryReplicator::debug = 0;
00009 
00010 GeometryReplicator::GeometryReplicator()
00011 {
00012   num_socks = 0;
00013 }
00014 
00015 GeometryReplicator::GeometryReplicator(char* machine_name)
00016 {
00017   Connect(machine_name);
00018 }
00019 
00020 GeometryReplicator::~GeometryReplicator()
00021 {
00022   for (int i=0; i<num_socks; i++) {
00023      if (!socks[i]) continue;
00024          delete socks[i];
00025          socks[i] = NULL;
00026   }
00027 }
00028 
00029 void GeometryReplicator::Connect(char* machine_name_in)
00030 {
00031   // create the connection (using switchboard port)
00032   Socket* s = new Socket(machine_name_in, Socket::tcp, 1200);  
00033 
00034   // if it didn't work, bail
00035   if (!s) return;
00036 
00037   // keep the connection
00038   socks[num_socks++] = s;
00039 
00040   // keep the name around for fun
00041   strncpy(machine_names[num_socks-1], machine_name_in, 80);
00042 
00043   // send the system info string to the switchboard
00044   char buf[256];
00045   sprintf(buf, "%c Spring: Geometry Replicator", 0xe0);
00046   SendMessage(buf, 256);
00047 }
00048 
00049 // assumes have already put the GR_CODE at beginning, then composed message
00050 void GeometryReplicator::SendMessage(char* buf, int size)
00051 {
00052   if (debug) 
00053           cerr << "GeometryReplicator::SendMessage(" << buf << ", " << size << ")\n";
00054 
00055   // send to each socket
00056   for (int i=0; i<num_socks; i++)
00057     socks[i]->BufferedSend(buf, size);
00058 }
00059 
00060 static GLUI_StaticText* ac = NULL;
00061 static char new_machine_name[300];
00062 void GeometryReplicator::Connect_CB(int gr_p_in)
00063 {
00064     GeometryReplicator* gr_p = (GeometryReplicator*)gr_p_in;
00065     
00066     // and do the connect
00067     gr_p->Connect(new_machine_name);
00068 
00069         // and update the current info
00070     char buf[80];
00071     if (gr_p->num_socks > 0) 
00072                 sprintf(buf, "Num Connections: %d", gr_p->num_socks);
00073         else sprintf(buf, "Not connected...");
00074     if (ac) ac->set_text(buf);
00075 }
00076 
00077 void GeometryReplicator::Menu()
00078 {
00079     extern int main_window_id;
00080     extern void Close(int);
00081     
00082     GLUI *glui = GLUI_Master.create_glui((const char*)"Geometry Replicator");
00083     GLUI_Panel* p = glui->add_panel("Current info");
00084 
00085         // put up header
00086     char buf[80];
00087     if (num_socks == 0) sprintf(buf, "Not connected...");
00088         else sprintf(buf, "Connected to: ");
00089     ac = glui->add_statictext_to_panel(p, buf);
00090     p->set_alignment(GLUI_ALIGN_LEFT);
00091 
00092         // put up list of machines we're connected to
00093         for (int i=0; i<num_socks; i++) {
00094            sprintf(buf, "    %s", machine_names[i]);
00095        ac = glui->add_statictext_to_panel(p, buf);
00096         }
00097     
00098     { GLUI_Panel* p = glui->add_panel("");
00099     GLUI_EditText* et1 = glui->add_edittext_to_panel(p, "Connect to:",
00100         GLUI_EDITTEXT_TEXT, new_machine_name);
00101     
00102     et1->set_text("biocomp.stanford.edu");
00103     
00104     et1->set_w(300); et1->set_h(20);
00105     
00106     glui->add_button_to_panel(p, "Connect", (int)this,
00107         (GLUI_Update_CB)Connect_CB);
00108     }
00109     
00110     glui->add_separator();
00111     { GLUI_Panel* pe = glui->add_panel("");
00112     glui->add_button_to_panel(pe, "Close", (int)glui,
00113         (GLUI_Update_CB)Close);
00114     }
00115     glui->set_main_gfx_window(main_window_id);
00116 }
00117 

Generated on Thu Aug 30 11:03:13 2007 for SPRING Mac by  doxygen 1.5.3