From bc81829315f927d3f167ddca6c3b86a21fa759f7 Mon Sep 17 00:00:00 2001 From: Cary Sandvig Date: Thu, 16 Nov 2000 19:00:03 +0000 Subject: [PATCH] oops --- panda/src/gui/guiFrame.cxx | 2 + panda/src/testbed/Sources.pp | 18 +++++++ panda/src/testbed/deadrec_rec.cxx | 84 ++++++++++++++++++++++++++++++ panda/src/testbed/deadrec_send.cxx | 1 + 4 files changed, 105 insertions(+) diff --git a/panda/src/gui/guiFrame.cxx b/panda/src/gui/guiFrame.cxx index f9ec561eee..777b44073f 100644 --- a/panda/src/gui/guiFrame.cxx +++ b/panda/src/gui/guiFrame.cxx @@ -206,6 +206,8 @@ void GuiFrame::remove_item(GuiItem* item) { } // now get rid of the thing itself _items.erase(i); + this->recompute(); + item->unmanage(); } void GuiFrame::pack_item(GuiItem* item, Packing rel, GuiItem* to, float gap) { diff --git a/panda/src/testbed/Sources.pp b/panda/src/testbed/Sources.pp index 292e601e30..b7474d67da 100644 --- a/panda/src/testbed/Sources.pp +++ b/panda/src/testbed/Sources.pp @@ -140,3 +140,21 @@ #define LOCAL_LIBS $[LOCAL_LIBS] gui #end test_bin_target + +#begin test_bin_target + #define TARGET deadrec_rec + + #define SOURCES \ + deadrec_rec.cxx + + #define LOCAL_LIBS $[LOCAL_LIBS] net +#end test_bin_target + +#begin test_bin_target + #define TARGET deadrec_send + + #define SOURCES \ + deadrec_send.cxx + + #define LOCAL_LIBS $[LOCAL_LIBS] net +#end test_bin_target diff --git a/panda/src/testbed/deadrec_rec.cxx b/panda/src/testbed/deadrec_rec.cxx index ff83e479ce..269da6197d 100644 --- a/panda/src/testbed/deadrec_rec.cxx +++ b/panda/src/testbed/deadrec_rec.cxx @@ -5,6 +5,75 @@ #include "framework.h" +#include + +NotifyCategoryDecl(deadrec, EXPCL_MISC, EXPTP_MISC); +NotifyCategoryDef(deadrec, ""); + +Configure(deadrec); + +ConfigureFn(deadrec) { +} + +typedef set Clients; + +static PT_Node smiley; +static RenderRelation* my_arc; +static int hostport = deadrec.GetInt("deadrec-rec-port", 0xdead); +static thread* monitor; +static bool stop_monitoring; +QueuedConnectionListener* listener; +QueuedConnectionManager cm; +Clients clients; +QueuedConnectionReader* reader; + +static void* internal_monitor(void*) { + if (deadrec->is_debug()) + deadrec->debug() << "internal monitoring thread started" << endl; + while (!stop_monitoring) { + // check for new clients + while (listener->new_connection_available()) { + PT(Connection) rv; + NetAddress address; + PT(Connection) new_connection; + if (listener->get_new_connection(rv, address, new_connection)) { + if (deadrec_cat->is_debug()) + deadrec_cat->debug() << "Got connection from " << address << endl; + reader->add_connection(new_connection); + clients.insert(new_connection); + } + } + // check for reset clients + while (cm.reset_connection_available()) { + PT(Connection) connection; + if (cm.get_reset_connection(connection)) { + if (deadrec_cat->is_debug()) + deadrec_cat->debug() << "Lost connection from " + << connection->get_address() << endl; + clients.erase(connection); + cm.close_connection(connection); + } + } + // process all available datagrams + while (reader->data_available()) { + NetDatagram datagram; + if (reader->get_data(datagram)) { + if (deadrec_cat->is_debug()) + deadrec_cat->debug() << "Got datagram " << datagram << " from " + << datagram.get_address() << endl; + // unpack and deal with the datagram now + // DO THIS + // part of this includes logic on when to shutdown, I hope + } + } + // sleep for about 100 milliseconds + ipc_traits::sleep(0, 100000); + } + if (deadrec->is_debug()) + deadrec->debug() << "internal monitoring thread exiting" << endl; + return (void*)0L; +} + static void deadrec_setup(void) { static bool done = false; if (done) @@ -13,6 +82,21 @@ static void deadrec_setup(void) { smiley = ModelPool::load_model("smiley"); nassertv(smiley != (Node*)0L); my_arc = new RenderRelation(render, smiley); + // prepair to get a connection + PT(Connection) rendezvous = cm.open_TCP_server_rendezvous(hostport, 5); + if (rendezvous.is_null()) { + deadrec_cat->fatal() << "cannot get port " << hostport << endl; + exit(); + } + if (deadrec_cat->is_debug()) + deadrec_cat->debug() << "Listening for connections on port " << port + << endl; + listener = new QueuedConnectionListener(&cm, 0); + listener->add_connection(rendezvous); + reader = new QueuedConnectionReader(&cm, 1); + stop_monitoring = false; + monitor = thread::create(internal_monitor, (void*)0L, + thread::PRIORITY_NORMAL); } static void deadrec_keys(EventHandler& eh) { diff --git a/panda/src/testbed/deadrec_send.cxx b/panda/src/testbed/deadrec_send.cxx index 68118d1c7b..e31de2c978 100644 --- a/panda/src/testbed/deadrec_send.cxx +++ b/panda/src/testbed/deadrec_send.cxx @@ -48,6 +48,7 @@ static void deadrec_setup(void) { << c->get_address().get_port() << " and IP " << c->get_address() << endl; writer = new ConnectionWriter(&cm, 0); +} static void deadrec_keys(EventHandler& eh) { deadrec_setup();